PluginProbe
Customify / 2.6.0
Customify v2.6.0
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
customify / js / jquery.cssUpdate.js

jquery.cssUpdate.js in Customify 2.6.0, at js/jquery.cssUpdate.js

122 lines 3.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 /*
2 * cssUpdate - v1.0.0
3 */
4 ;(function ( $, window, document, undefined ) {
5 var pluginName = "cssUpdate",
6 defaults = {
7 properties: ["color"],
8 propertyValue: "pink",
9 classes: "Null"
10 };
11
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 }
21
22
23
24 cssLiveUpdater.prototype = {
25 init: function () {
26 this.changeProperties();
27 },
28
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 },
37
38 changeProperties: function () {
39
40 var self = this,
41 css = this._cssproperties.cssRules;
42
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 });
53
54 } else {
55
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 }
65
66 //Insert the new properties into <style> tag
67 $(this.element).html(this._cssproperties.toString());
68 },
69
70 /**
71 * Update one css properties by the given params
72 * @param property_name
73 * @param settings
74 * @param selectorText
75 * @returns {string}
76 */
77 updateCssRule: function(property_name, settings, selectorText){
78
79 var self = this,
80 properties = settings.properties,
81 new_value = settings.propertyValue,
82 // if there is a negative property ... keep it negative
83 sign = settings['negative_value'] ? '-' : '';
84
85 var unit = '';
86
87 if ( typeof this.settings.unit !== 'undefined' ) {
88 unit = this.settings.unit;
89 }
90
91 if ( unit === '' && customify_settings.px_dependent_css_props.indexOf(property_name) != -1 ) {
92 unit = 'px';
93 }
94
95 if ( typeof window[settings.properties.callback] === "function" ) {
96 window[settings.properties.callback](new_value, selectorText, property_name, unit);
97 return '';
98 }
99
100 return sign + new_value + unit;
101 },
102 };
103
104 // Plugin wrapper
105 $.fn[ pluginName ] = function ( options ) {
106 this.each(function() {
107
108 var old_plugin = $(this).data( 'plugin_cssUpdate' );
109
110 if ( typeof old_plugin !== 'undefined' ) {
111 old_plugin.update_plugin( options );
112 } else {
113 $.data( this, "plugin_" + pluginName, new cssLiveUpdater( this, options ) );
114 }
115 });
116
117 // chain jQuery functions
118 return this;
119 };
120
121 })( jQuery, window, document );
122