# customify/2.10.1/js/jquery.cssUpdate.js

Customify, version 2.10.1. 102 lines.

- Page: https://pluginprobe.com/plugins/customify/2.10.1/code/js/jquery.cssUpdate.js
- Raw: https://pluginprobe.com/plugins/customify/2.10.1/raw/js/jquery.cssUpdate.js
- Modified: 2020-04-27T15:18:30+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/customify/2.10.1/code/js/jquery.cssUpdate.js#L10-L20`.

```javascript
/*
 *  cssUpdate - v1.1.0
 */

/** @namespace customify */
window.customify = window.customify || parent.customify || {}

;(function ($, window, customify) {
  const pluginName = 'cssUpdate',
    defaults = {
      properties: ['color'],
      propertyValue: 'pink',
      classes: 'Null'
    }

  // Plugin constructor
  function cssLiveUpdater (element, options) {
    this.element = element
    this.settings = $.extend({}, defaults, options)
    this._defaults = defaults
    this._name = pluginName
    this._cssproperties = CSSOM.parse($(this.element).html())
    this.init()
  }

  cssLiveUpdater.prototype = {
    init: function () {
      this.changeProperties()
    },

    changeProperties: function () {

      const self = this,
        css = this._cssproperties.cssRules

      if (typeof css[0] !== 'undefined' && css[0].hasOwnProperty('media')) {
        // in this case we run a media query object
        $.each(css, function (key, media_query) {
          // simple object with css properties
          // change them with new ones
          $.each(media_query.cssRules, function (i, property) {
            const property_name = property.style[0]
            css[key].cssRules[i].style[property_name] = self.updateCssRule(property_name, self.settings, css[key].cssRules[i].selectorText)
          })
        })

      } else {

        // simple object with css properties
        // change them with new ones
        $.each(css, function (i, property) {
          if (property.hasOwnProperty('style')) {
            const property_name = property.style[0]
            css[i].style[property_name] = self.updateCssRule(property_name, self.settings, css[i].selectorText)
          }
        })
      }

      //Insert the new properties into <style> tag
      $(this.element).html(this._cssproperties.toString())
    },

    /**
     * Update one css properties by the given params
     * @param property_name
     * @param settings
     * @param selectorText
     * @returns {string}
     */
    updateCssRule: function (property_name, settings, selectorText) {

      const new_value = settings.propertyValue
      // if there is a negative property ... keep it negative
      const sign = settings['negative_value'] ? '-' : ''

      let unit = (typeof this.settings.unit !== 'undefined') ? this.settings.unit : ''
      // If the unit is empty (string, not boolean false) but the property should have a unit force 'px' as it
      if (unit === '' && customify.config.px_dependent_css_props.indexOf(property_name) !== -1) {
        unit = 'px'
      }

      if (typeof window[settings.properties.callback] === 'function') {
        window[settings.properties.callback](new_value, selectorText, property_name, unit)
        return ''
      }

      return sign + new_value + unit
    },
  }

  // Plugin wrapper
  $.fn[pluginName] = function (options) {
    this.each(function () {
      $.data(this, 'plugin_' + pluginName, new cssLiveUpdater(this, options))
    })

    // chain jQuery functions
    return this
  }

})(jQuery, window, customify)

```
