ru-se.com

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

gradient-control.js (2365B)


      1 (function (root, $) {
      2     wp.customize.controlConstructor['gradient-control'] = wp.customize.Control.extend({
      3 
      4         ready: function () {
      5 
      6             'use strict';
      7 
      8             var control = this;
      9 
     10 
     11             var val = this.getValue();
     12 
     13             this.container.on('click', 'button, .webgradient-icon-preview .webgradient', function () {
     14                 Materialis.openMediaCustomFrame(
     15                     wp.media.cp.extendFrameWithWebGradients({
     16                         filter : function (icon) {
     17                             return icon.get("parsed") !== false;
     18                         }
     19                     }),
     20                     "cp_web_gradients",
     21                     materialis_customize_settings.l10n.selectGradient,
     22                     true,
     23                     function (attachement) {
     24                         if (attachement && attachement[0]) {
     25                             var toSet = attachement[0].parsed;
     26                             if (control.params.choices && control.params.choices['opacity']) {
     27                                 toSet.colors = toSet.colors.map(function (colorData) {
     28                                     var _color = tinycolor(colorData.color);
     29                                     _color.setAlpha(control.params.choices['opacity']);
     30                                     colorData.color = _color.toRgbString();
     31                                     return colorData;
     32                                 });
     33                             }
     34                             control.setValue(toSet);
     35                         }
     36                     }
     37                 )
     38             });
     39 
     40         },
     41 
     42         getValue: function () {
     43             'use strict';
     44 
     45             // The setting is saved in JSON
     46 
     47             var value = [];
     48 
     49             if (_.isString(this.setting.get())) {
     50                 value = JSON.parse(this.setting.get());
     51             } else {
     52                 value = this.setting.get();
     53             }
     54 
     55             return value;
     56         },
     57 
     58         setValue: function (value, silent) {
     59             this.setting.set(JSON.stringify(value));
     60             this.update(value);
     61         },
     62 
     63         update: function(value) {
     64             this.container.find('.webgradient-icon-preview > div.webgradient').attr('style', "background:" + Materialis.Utils.getGradientString(value.colors, value.angle));
     65         }
     66 
     67     });
     68 
     69 })(window, jQuery);