public function Field($properties = array()) { $image = $this->getImage(); if (!$image) { return false; } FormExtraJquery::include_jquery(); if (self::config()->use_hammer) { FormExtraJquery::include_hammer(); } if (self::config()->use_mousewheel) { FormExtraJquery::include_mousewheel(); } Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/cropbox/jquery.cropbox.js'); Requirements::css(FORM_EXTRAS_PATH . '/javascript/cropbox/jquery.cropbox.css'); Requirements::customScript("jQuery( '.cropbox-field' ).each( function () {\n\t\t\tvar t = jQuery(this),\n\t\t\timage = t.find('img'),\n cropwidth = image.data('cropwidth'),\n cropheight = image.data('cropheight'),\n\t\t\tx = jQuery('[name=CropX]', t),\n y = jQuery('[name=CropY]', t),\n w = jQuery('[name=CropWidth]', t),\n h = jQuery('[name=CropHeight]', t)\n\t\t;\n\n image.cropbox( {width: cropwidth, height: cropheight, result: {cropX:x.val(), cropY:y.val(), cropW:w.val(), cropH:h.val()} })\n .on('cropbox', function( event, results, img ) {\n\t\t\t\tx.val(results.cropX);\n\t\t\t\ty.val(results.cropY);\n\t\t\t\tw.val(results.cropW);\n\t\t\t\th.val(results.cropH);\n })\n\t\t\t;\n } );", 'cropboxFieldInit'); return parent::Field($properties); }
public function Field($properties = array()) { FormExtraJquery::include_jquery(); $use_v3 = self::config()->use_v3; if ($use_v3) { Requirements::css(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2.css'); Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2.min.js'); // Locale support $lang = i18n::get_lang_from_locale(i18n::get_locale()); if ($lang != 'en') { Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v3/select2_locale_' . $lang . '.js'); } } else { // Locale support $lang = i18n::get_lang_from_locale(i18n::get_locale()); if ($lang != 'en') { Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v4/i18n/' . $lang . '.js'); } // Use full release Requirements::css(FORM_EXTRAS_PATH . '/javascript/select2-v4/css/select2.min.css'); FormExtraJquery::include_mousewheel(); Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/select2-v4/js/select2.full.min.js'); } // Build options $opts = array(); if ($this->allow_single_deselect) { if ($use_v3) { $opts['allowClear'] = $this->allow_single_deselect; } else { $opts['allow_clear'] = $this->allow_single_deselect; } } if ($this->allow_max_selected) { if ($use_v3) { $opts['maximumSelectionSize'] = $this->allow_max_selected; } else { $opts['maximumSelectionLength'] = $this->allow_max_selected; } } if ($this->tags) { if ($use_v3) { if (is_array($this->source)) { $source = array_values($this->source); } else { $source = array(); } // Tags is an array $opts['tags'] = $source; $opts['tokenSeparators'] = $this->token_separators; // Not compatible with select $this->multiple = false; $this->template = 'HiddenField'; } else { // Tags are calculated from options $opts['tags'] = $this->tags; $opts['token_separators'] = $this->token_separators; $opts['free_order'] = $this->free_order; } } if (self::config()->rtl && !$use_v3) { $opts['dir'] = 'rtl'; } if ($this->ajax) { $opts['ajax'] = $this->ajax; } if (FormExtraJquery::isAdminBackend()) { Requirements::customScript('var select2_' . $this->ID() . ' = ' . json_encode($opts)); Requirements::javascript(FORM_EXTRAS_PATH . '/javascript/Select2Field.js'); } else { Requirements::customScript('jQuery("#' . $this->ID() . '").select2(' . json_encode($opts) . ');'); } if ($use_v3) { // If you need to adjust the size, it's better to use the field container instead $this->setAttribute('style', 'width:100%'); } return parent::Field($properties); }