<?php

class Rtgc_vimeo_video extends Abstract_rtgc_callback
{
    const LINK = 'https://player.vimeo.com/video/%s';

    public function column($value = '')
    {
        return '<iframe src="' . sprintf(self::LINK, $value) . '" width="200" height="100" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>';
    }

    public function field($name = '', $value = NULL)
    {
        $ci = &get_instance();

        $ci->js_css->add_js_string("$(function(){
            $('.vimeo_input').change(function(){
                code = $(this).val().replace('https://vimeo.com/', '');
                link = '" . self::LINK . "';
                parent = $(this).parent();
                $(this).val(code);
                parent.find('iframe').attr('src', link.replace('%s', code));
            });
        });");

        $input = '<input class="vimeo_input" type="text" name="' . $name . '" value="' . $value . '" placeholder="' . $ci->lang->line('Enter vimeo share link') . '" />';

        return $this->column($value) . '<br />' . $input;
    }

}