ru-se.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

customizer-content-tpls.js (4388B)


      1 (function () {
      2     var __templates = {};
      3 
      4     var templateOptions = {
      5         evaluate: /<#([\s\S]+?)#>/g,
      6         interpolate: /\{\{\{([\s\S]+?)\}\}\}/g,
      7         escape: /\{\{([^\}]+?)\}\}(?!\})/g
      8         // variable:    'data'
      9     };
     10 
     11     function template(text) {
     12         text = text.split('<inline-script').join('<script');
     13         text = text.split('</inline-script').join('</script');
     14 
     15         return _.template(text, templateOptions);
     16     }
     17 
     18     function getCPTemplate(id) {
     19         var text = jQuery("#cp-content-templates-" + id)[0].innerHTML;
     20 
     21         return template(text);
     22     }
     23 
     24     window.CP_Customizer.addModule(function (CP_Customizer) {
     25         var contentTemplates = {
     26             text: getCPTemplate("text"),
     27             'text-with-checkbox': getCPTemplate("text-with-checkbox"),
     28             link: getCPTemplate("link"),
     29             image: getCPTemplate("image"),
     30             icon: getCPTemplate("icon"),
     31             list: getCPTemplate("list"),
     32             'linked-icon': getCPTemplate("linked-icon"),
     33             getCPScriptTemplate: getCPTemplate
     34         };
     35 
     36         CP_Customizer.jsTPL = _.extend(CP_Customizer.jsTPL, contentTemplates);
     37 
     38         CP_Customizer.jsTPL['select'] = template('' +
     39             '<li class="customize-control customize-control-text">' +
     40             '    <label>' +
     41             '        <span class="customize-control-title">{{{  label  }}}</span>' +
     42             '        <select type="text" id="{{{ id }}}">' +
     43             '            <# jQuery.each(choices,function(index,value){ #>' +
     44             '                <option value="{{{ value }}}"  ><# print(CP_Customizer.translateCompanionString(index)) #></option>' +
     45             '            <# }) #>' +
     46             '        </select>' +
     47             '        <script>' +
     48             '                jQuery("#{{ id }}").val("{{{ value }}}") ' +
     49             '        </script>' +
     50             '    </label>' +
     51             '</li>' +
     52             '');
     53 
     54 
     55         CP_Customizer.jsTPL['selectize'] = template('' +
     56             ' <li class="customize-control customize-control-text">' +
     57             '    <label>' +
     58             '        <span class="customize-control-title">{{{  label  }}}</span>' +
     59             '        <select {{ (data.multiple ? \'multiple\' : \'\') }} id="{{{ id }}}">' +
     60             '        <# var choices = _.isFunction(data.choices) ? data.choices() : data.choices #>' +
     61             '        <# _.each(choices, function(label, _v) { ' +
     62             '               var Vs = _.isArray(value) ? value: value.split(\',\').map(function(item){return item.trim()});' +
     63             '               var isSelected = (Vs.indexOf(_v) !== -1)' +
     64             '            #>' +
     65             '           <option {{ ( isSelected ? "selected=\'true\' ": "" ) }} value="{{{ _v }}}">' +
     66             '               {{{  label  }}}' +
     67             '            </option>' +
     68             '        <# }); #>' +
     69             '        </select>' +
     70             '    </label>' +
     71             '    <script>' +
     72             '        jQuery("#{{ id }}").selectize({' +
     73             '             maxItems: {{ (data.multiple ? "null" : "1") }},' +
     74             '             plugins: {{{ (data.multiple ? "[\'remove_button\']" : "[]") }}}' +
     75             '        })' +
     76             '    </script>' +
     77             '</li>' +
     78             '');
     79 
     80         CP_Customizer.jsTPL['selectize-remote'] = template('' +
     81             '<li class="customize-control customize-control-selectize-remote">' +
     82             '    <label>' +
     83             '        <span class="customize-control-title">{{{  label  }}}</span>' +
     84             '        <select id="{{{ id }}}"></select>' +
     85             '    </label>' +
     86             '</li>' +
     87             '');
     88 
     89 
     90         CP_Customizer.jsTPL['checkbox'] = template('' +
     91             '<li class="customize-control customize-control-checkbox">' +
     92             '    <span class="customize-control-title">{{{  label  }}}</span>' +
     93             '    <div style="clear: both">' +
     94             '       <label for="{{{ id }}}">\n' +
     95             '           <input  {{ (value?"checked=\'true\'":"") }} id="{{{ id }}}" type="checkbox">{{ text  }}' +
     96             '       </label>' +
     97             '  </div>' +
     98             '</li>' +
     99             '');
    100 
    101         CP_Customizer.jsTPL.compile = template;
    102     });
    103 })();