PluginProbe
Customify / 2.5.1
Customify v2.5.1
2.10.9 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.7.1 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 1.5.6 1.5.7 1.6.0 1.6.0.1 1.6.5 1.7.0 1.7.1 All 77 releases
← All changes | js/jquery.cssUpdate.js +99 -89 2.10.9 → 2.5.1 View file →
@@ -1,113 +1,123 @@
1 1 /*
2 2 * cssUpdate - v1.0.0
3 3 */
4 +;(function ( $, window, document, undefined ) {
5 + var pluginName = "cssUpdate",
6 + defaults = {
7 + properties: ["color"],
8 + propertyValue: "pink",
9 + classes: "Null"
10 + };
4 11
5 -/** @namespace customify */
6 -window.customify = window.customify || parent.customify || {}
12 + // Plugin constructor
13 + function cssLiveUpdater ( element, options ) {
14 + this.element = element;
15 + this.settings = $.extend( {}, defaults, options );
16 + this._defaults = defaults;
17 + this._name = pluginName;
18 + this._cssproperties = CSSOM.parse($(this.element).html());
19 + this.init();
20 + }
7 21
8 -;(function ($, window, customify) {
9 - const pluginName = 'cssUpdate',
10 - defaults = {
11 - properties: ['color'],
12 - propertyValue: 'pink',
13 - classes: 'Null'
14 - }
15 22
16 - // Plugin constructor
17 - function cssLiveUpdater (element, options) {
18 - this.element = element
19 - this.settings = $.extend({}, defaults, options)
20 - this._defaults = defaults
21 - this._name = pluginName
22 - this._cssproperties = CSSOM.parse($(this.element).html())
23 - this.init()
24 - }
25 23
26 - cssLiveUpdater.prototype = {
27 - init: function () {
28 - this.changeProperties()
29 - },
24 + cssLiveUpdater.prototype = {
25 + init: function () {
26 + this.changeProperties();
27 + },
30 28
31 - update_plugin: function (options) {
32 - this.settings = $.extend({}, defaults, options)
33 - this.changeProperties()
34 - },
29 + update_plugin: function ( options ) {
30 + //this.element = element;
31 + this.settings = $.extend( {}, defaults, options );
32 + //this._defaults = defaults;
33 + //this._name = pluginName;
34 + //this._cssproperties = CSSOM.parse($(this.element).html());
35 + this.changeProperties();
36 + },
35 37
36 - changeProperties: function () {
38 + changeProperties: function () {
37 39
38 - const self = this,
39 - css = this._cssproperties.cssRules
40 + var self = this,
41 + css = this._cssproperties.cssRules;
40 42
41 - if (typeof css[0] !== 'undefined' && css[0].hasOwnProperty('media')) {
42 - // in this case we run a media query object
43 - $.each(css, function (key, media_query) {
44 - // simple object with css properties
45 - // change them with new ones
46 - $.each(media_query.cssRules, function (i, property) {
47 - const property_name = property.style[0]
48 - css[key].cssRules[i].style[property_name] = self.updateCssRule(property_name, self.settings, css[key].cssRules[i].selectorText)
49 - })
50 - })
43 + if ( typeof css[0] !== "undefined" && css[0].hasOwnProperty('media') ) {
44 + // in this case we run a media query object
45 + $.each(css, function( key, media_query ){
46 + // simple object with css properties
47 + // change them with new ones
48 + $.each(media_query.cssRules, function(i, property){
49 + var property_name = property.style[0];
50 + css[key].cssRules[i].style[property_name] = self.updateCssRule(property_name, self.settings, css[key].cssRules[i].selectorText);
51 + });
52 + });
51 53
52 - } else {
54 + } else {
53 55
54 - // simple object with css properties
55 - // change them with new ones
56 - $.each(css, function (i, property) {
57 - if (property.hasOwnProperty('style')) {
58 - const property_name = property.style[0]
59 - css[i].style[property_name] = self.updateCssRule(property_name, self.settings, css[i].selectorText)
60 - }
61 - })
62 - }
56 + // simple object with css properties
57 + // change them with new ones
58 + $.each(css, function(i, property){
59 + if ( property.hasOwnProperty( 'style' ) ) {
60 + var property_name = property.style[0];
61 + css[i].style[property_name] = self.updateCssRule(property_name, self.settings, css[i].selectorText);
62 + }
63 + });
64 + }
63 65
64 - //Insert the new properties into <style> tag
65 - $(this.element).html(this._cssproperties.toString())
66 - },
66 + $(window).trigger('resize');
67 67
68 - /**
69 - * Update one css properties by the given params
70 - * @param property_name
71 - * @param settings
72 - * @param selectorText
73 - * @returns {string}
74 - */
75 - updateCssRule: function (property_name, settings, selectorText) {
68 + //Insert the new properties into <style> tag
69 + $(this.element).html(this._cssproperties.toString());
70 + },
76 71
77 - const new_value = settings.propertyValue
78 - // if there is a negative property ... keep it negative
79 - const sign = settings['negative_value'] ? '-' : ''
72 + /**
73 + * Update one css properties by the given params
74 + * @param property_name
75 + * @param settings
76 + * @param selectorText
77 + * @returns {string}
78 + */
79 + updateCssRule: function(property_name, settings, selectorText){
80 80
81 - let unit = (typeof this.settings.unit !== 'undefined') ? this.settings.unit : ''
82 - // If the unit is empty (string, not boolean false) but the property should have a unit force 'px' as it
83 - if (unit === '' && customify.config.px_dependent_css_props.indexOf(property_name) !== -1) {
84 - unit = 'px'
85 - }
81 + var self = this,
82 + properties = settings.properties,
83 + new_value = settings.propertyValue,
84 + // if there is a negative property ... keep it negative
85 + sign = settings['negative_value'] ? '-' : '';
86 86
87 - if (typeof window[settings.properties.callback] === 'function') {
88 - window[settings.properties.callback](new_value, selectorText, property_name, unit)
89 - return ''
90 - }
87 + var unit = '';
91 88
92 - return sign + new_value + unit
93 - },
94 - }
89 + if ( typeof this.settings.unit !== 'undefined' ) {
90 + unit = this.settings.unit;
91 + }
95 92
96 - // Plugin wrapper
97 - $.fn[pluginName] = function (options) {
98 - this.each(function () {
93 + if ( unit === '' && customify_settings.px_dependent_css_props.indexOf(property_name) != -1 ) {
94 + unit = 'px';
95 + }
99 96
100 - const old_plugin = $(this).data('plugin_cssUpdate')
97 + if ( typeof window[settings.properties.callback] === "function" ) {
98 + window[settings.properties.callback](new_value, selectorText, property_name, unit);
99 + return '';
100 + }
101 101
102 - if (typeof old_plugin !== 'undefined') {
103 - old_plugin.update_plugin(options)
104 - } else {
105 - $.data(this, 'plugin_' + pluginName, new cssLiveUpdater(this, options))
106 - }
107 - })
102 + return sign + new_value + unit;
103 + },
104 + };
108 105
109 - // chain jQuery functions
110 - return this
111 - }
106 + // Plugin wrapper
107 + $.fn[ pluginName ] = function ( options ) {
108 + this.each(function() {
112 109
113 -})(jQuery, window, customify)
110 + var old_plugin = $(this).data( 'plugin_cssUpdate' );
111 +
112 + if ( typeof old_plugin !== 'undefined' ) {
113 + old_plugin.update_plugin( options );
114 + } else {
115 + $.data( this, "plugin_" + pluginName, new cssLiveUpdater( this, options ) );
116 + }
117 + });
118 +
119 + // chain jQuery functions
120 + return this;
121 + };
122 +
123 +})( jQuery, window, document );