コード例 #1
0
 /**
  * @param array $params
  */
 public function __construct(array $params)
 {
     $this->fonts[__("Custom...", AI1EC_PLUGIN_NAME)] = self::CUSTOM_FONT;
     $select = Ai1ec_Helper_Factory::create_select_instance($params['id']);
     $select->add_class('ai1ec_font');
     parent::__construct($params);
     $this->renderable = $this->set_up_renderable($select);
 }
コード例 #2
0
 /**
  * @param string $type
  * @param array $params
  * @return Ai1ec_Less_Variable
  */
 public static function create_less_variable($type, array $params)
 {
     switch ($type) {
         case 'color':
             $bootstrap_colorpicker = Ai1ec_Helper_Factory::create_bootstrap_colorpicker_instance($params['value'], $params['id']);
             return new Ai1ec_Less_Variable_Color($params, $bootstrap_colorpicker);
             break;
         case 'font':
             $select = Ai1ec_Helper_Factory::create_select_instance($params['id']);
             return new Ai1ec_Less_Variable_Font($params, $select);
             break;
     }
 }
コード例 #3
0
 /**
  * Creates a multiselect for use with Select2 widget.
  *
  * @return Ai1ec_Html_Element
  */
 public static function create_select2_multiselect(array $args, array $options, array $view_args = null)
 {
     // if no data is present and we are in the frontend, return a blank element.
     if (empty($options) && null !== $view_args) {
         return self::create_blank_html_element();
     }
     $ai1ec_events_helper = Ai1ec_Events_Helper::get_instance();
     static $cached_flips = array();
     $select2 = Ai1ec_Helper_Factory::create_select_instance($args['id'], $args['name']);
     $use_id = isset($args['use_id']);
     foreach ($options as $term) {
         $option_arguments = array();
         $color = false;
         if ($args['type'] === 'category') {
             $color = $ai1ec_events_helper->get_category_color($term->term_id);
         }
         if ($color) {
             $option_arguments["data-color"] = $color;
         }
         if (null !== $view_args) {
             // create the href for ajax loading
             $href = self::create_href_helper_instance($view_args, $args['type']);
             $href->set_term_id($term->term_id);
             $option_arguments["data-href"] = $href->generate_href();
             // check if the option is selected
             $type_to_check = '';
             // first let's check the correct type
             switch ($args['type']) {
                 case 'category':
                     $type_to_check = 'cat_ids';
                     break;
                 case 'tag':
                     $type_to_check = 'tag_ids';
                     break;
                 case 'author':
                     $type_to_check = 'auth_ids';
                     break;
             }
             // let's flip the array. Just once for performance sake,
             // the categories doesn't change in the same request
             if (!isset($cached_flips[$type_to_check])) {
                 $cached_flips[$type_to_check] = array_flip($view_args[$type_to_check]);
             }
             if (isset($cached_flips[$type_to_check][$term->term_id])) {
                 $option_arguments["selected"] = 'selected';
             }
         }
         if (true === $use_id) {
             $select2->add_option($term->name, $term->term_id, $option_arguments);
         } else {
             $select2->add_option($term->name, $term->name, $option_arguments);
         }
     }
     $select2->set_attribute("multiple", "multiple");
     $select2->set_attribute("data-placeholder", $args['placeholder']);
     $select2->add_class('ai1ec-select2-multiselect-selector span12');
     $container = Ai1ec_Helper_Factory::create_generic_html_tag('div');
     if (isset($args['type'])) {
         $container->add_class('ai1ec-' . $args['type'] . '-filter');
     }
     $container->add_renderable_children($select2);
     return $container;
 }