PageSourceSearch

https://www.protectourcare.org/wp-content/themes/salient-child/js/poc_create_device_group.js

js protectourcare.org collected 2026-10-02 06:43:36 UTC 12,577 bytes, 437 lines download raw bytes

1(function ($) {
2  ("use strict");
3
4  var nectarAdminStore = {
5    mouseX: 0,
6    mouseUp: false,
7    bindEvents: function () {
8      $(window).on("mousemove", function (e) {
9        nectarAdminStore.mouseX = e.clientX;
10      });
11      $(window).on("mouseup", function () {
12        nectarAdminStore.mouseUp = true;
13        $(".wpb_edit_form_elements .wpb_el_type_nectar_numerical")
14          .removeClass("scrubbing")
15          .removeClass("no-scrubbing");
16      });
17    },
18    init: function () {
19      this.bindEvents();
20    },
21  };
22
23  /* Constrained Inputs */
24  function ConstrainedInput(el) {
25    this.$el = el;
26
27    this.elements = [];
28    this.$elements = "";
29    this.className = false;
30    this.active = false;
31
32    this.createStyle();
33    this.getInitialSet();
34    this.trackActive();
35    this.constrainEvents();
36  }
37
38  ConstrainedInput.prototype.createStyle = function () {
39    this.$el
40      .parents(".vc_checkbox-label")
41      .wrapInner('<div class="constrained-cb"></div>');
42  };
43
44  ConstrainedInput.prototype.getInitialSet = function () {
45    var that = this;
46    var classes = this.$el[0].className.split(/\s+/);
47
48    // Store classname
49    $.each(classes, function (i, name) {
50      if (name.indexOf("constrain_group_") === 0) {
51        that.className = name;
52      }
53    });
54
55    // Store element set.
56    $(
57      '.wpb_edit_form_elements .vc_wrapper-param-type-nectar_numerical[class*="constrain_group"]'
58    ).each(function () {
59      if ($(this).hasClass(that.className)) {
60        that.elements.push($(this).find("input.wpb_vc_param_value"));
61      }
62    });
63
64    // Cache dom elements.
65    that.$elements = $(".wpb_edit_form_elements").find(
66      "." + that.className + " input.wpb_vc_param_value"
67    );
68  };
69
70  ConstrainedInput.prototype.trackActive = function () {
71    var that = this;
72
73    this.active = this.$el.prop("checked");
74
75    this.$el.on("change", function () {
76      // Store state.
77      that.active = $(this).prop("checked");
78
79      // Alter icon.
80      if (that.active == true) {
81        $(this).parents(".vc_checkbox-label").addClass("active");
82      } else {
83        $(this).parents(".vc_checkbox-label").removeClass("active");
84      }
85
86      // Trigger changes.
87      if (that.elements.length > 0) {
88        $.each(that.elements, function (i, element) {
89          if (that.active == true) {
90            element.addClass("constrained");
91          } else {
92            element.removeClass("constrained");
93          }
94          element.trigger("keyup");
95          element.trigger("change");
96        });
97      }
98    });
99
100    // Trigger on load.
101    this.$el.trigger("change");
102  };
103
104  ConstrainedInput.prototype.constrainEvents = function () {
105    if (this.className == false) {
106      return;
107    }
108
109    var that = this;
110
111    // Bind event.
112    $.each(this.elements, function (i, element) {
113      element.on("change, keyup", function () {
114        // Keep values in sync when constrain in active.
115        if (that.active) {
116          var val = $(this).val();
117          that.$elements.val(val).trigger("change");
118        }
119      });
120    });
121  };
122
123  function nectarCreateDeviceGroup($selector) {
124    // Hide tabbed on load.
125    $("body")
126      .find("." + $selector + ":not(.desktop)")
127      .hide();
128
129    var $title = $("body")
130      .find("." + $selector)
131      .find(".group-title")
132      .clone();
133
134    // Group Markup.
135    $("body")
136      .find("." + $selector)
137      .wrapAll(
138        '<div class="' +
139          $selector +
140          '-wrap nectar-device-group-wrap vc_column" />'
141      );
142
143    // Header Markup.
144    $("body")
145      .find("." + $selector)
146      .find(".group-title")
147      .hide();
148    $("." + $selector + "-wrap").before(
149      '<div class="' + $selector + '-header nectar-device-group-header" />'
150    );
151
152    var $header = $("." + $selector + "-header");
153    $header.append($title);
154    $header.append(
155      '<span class="device-selection"><i class="dashicons-before dashicons-desktop active" data-filter="desktop" title="Desktop"></i> <i class="dashicons-before dashicons-tablet" data-filter="tablet" title="Tablet"></i> <i class="dashicons-before dashicons-smartphone" data-filter="phone" title="Phone"></i></span>'
156    );
157  }
158
159  function deviceHighlightInUse($input) {
160    var $groupHeader = $input
161      .parents(".nectar-device-group-wrap")
162      .prev(".nectar-device-group-header");
163    var inUse = false;
164    var type = "select";
165
166    if ($input.is('input[type="text"]')) {
167      type = "text";
168    } else if ($input.is('input[type="hidden"]')) {
169      type = "hidden";
170    }
171
172    // Determine which icon is related
173    var iconSelector = "desktop";
174    if (
175      $input.parents('div[class*="vc_wrapper-param-type"].tablet').length > 0
176    ) {
177      iconSelector = "tablet";
178    } else if (
179      $input.parents('div[class*="vc_wrapper-param-type"].phone').length > 0
180    ) {
181      iconSelector = "phone";
182    }
183
184    $groupHeader
185      .find('i[data-filter="' + iconSelector + '"]')
186      .removeClass("in-use");
187
188    // Check each input in the group for value set.
189
190    //// Text inputs.
191    if (type == "text") {
192      $input
193        .parents(".nectar-device-group-wrap")
194        .find("." + iconSelector + ' input[type="text"]')
195        .each(function () {
196          if (
197            $(this).parents(".vc_wrapper-param-type-textfield").length > 0 &&
198            $(this).val().length
199          ) {
200            inUse = true;
201          } else if (
202            $(this).parents(".vc_wrapper-param-type-nectar_numerical").length >
203              0 &&
204            $(this).val().length
205          ) {
206            inUse = true;
207          }
208        });
209    }
210    // Hidden inputs (images)
211    else if (type == "hidden") {
212      $input
213        .parents(".nectar-device-group-wrap")
214        .find("." + iconSelector + ' input[type="hidden"]')
215        .each(function () {
216          if (
217            $(this).parents(".vc_wrapper-param-type-fws_image").length > 0 &&
218            $(this).val().length
219          ) {
220            inUse = true;
221          }
222        });
223    }
224    //// Selects.
225    else {
226      $input
227        .parents(".nectar-device-group-wrap")
228        .find("." + iconSelector + " select")
229        .each(function () {
230          if (
231            iconSelector != "desktop" &&
232            $(this).parents(".vc_wrapper-param-type-dropdown").length > 0 &&
233            $(this).val().length
234          ) {
235            if ($(this).val() != "inherit" && $(this).val() != "default") {
236              inUse = true;
237            }
238          } else if (
239            iconSelector == "desktop" &&
240            $(this).parents(".vc_wrapper-param-type-dropdown").length > 0 &&
241            $(this).val().length
242          ) {
243            if (
244              $(this).val() != "no-extra-padding" &&
245              $(this).val() != "default"
246            ) {
247              inUse = true;
248            }
249          }
250        });
251    }
252
253    // If using value in group, highlight icon.
254    if (inUse == true) {
255      $groupHeader
256        .find('i[data-filter="' + iconSelector + '"]')
257        .addClass("in-use");
258    }
259  }
260
261  function deviceGroupEvents() {
262    $(".nectar-device-group-header i").on("click", function () {
263      var filter = $(this).attr("data-filter");
264      var group = $(this)
265        .parents(".nectar-device-group-header")
266        .next(".nectar-device-group-wrap");
267
268      // Already active.
269      if ($(this).hasClass("active")) {
270        return;
271      }
272
273      // Active class.
274      $(this)
275        .parents(".nectar-device-group-header")
276        .find("i")
277        .removeClass("active");
278      $(this).addClass("active");
279
280      // Display Grouping.
281      group.find("> div").hide();
282      group.find("> div." + filter).fadeIn();
283
284      // Trigger resize.
285      if (group.find(".nectar_range_slider").length > 0) {
286        $(window).trigger("resize");
287      }
288    });
289
290    $(".nectar-device-group-header .device-selection i").each(function () {
291      var $group = $(this)
292        .parents(".nectar-device-group-header")
293        .next(".nectar-device-group-wrap");
294
295      // On change.
296      $group
297        .find('input[type="text"], select, input[type="hidden"]')
298        .on("change", function () {
299          deviceHighlightInUse($(this));
300        });
301
302      // Inital Load.
303      $group
304        .find('input[type="text"], select, input[type="hidden"]')
305        .each(function () {
306          deviceHighlightInUse($(this));
307        });
308    });
309  }
310
311  function nectarRangeSliders() {
312    /* Single Range */
313    var textContent = "textContent" in document ? "textContent" : "innerText";
314
315    function valueOutput(element) {
316      var value = element.value;
317      var output = $(element).parent().siblings(".output");
318      output = output.find(".number")[0];
319
320      output[textContent] = value;
321    }
322
323    $('input[type="range"].nectar-range-slider').rangeslider({
324      polyfill: false,
325      onInit: function () {
326        valueOutput(this.$element[0]);
327      },
328      onSlideEnd: function (position, value) {
329        this.$element.val(value);
330        var min = this.$element.attr("min");
331        var max = this.$element.attr("max");
332
333        // fix overflow on slider
334        if (value > max * 0.6) {
335          $(window).trigger("resize");
336        }
337      },
338    });
339
340    $("body").on("input", ".nectar-range-slider", function (e) {
341      valueOutput(e.target);
342    });
343  }
344
345  jQuery(document).ready(function ($) {
346    nectarAdminStore.init();
347
348    var constrainedInputs = [],
349      nectarNumericalInputs = [];
350    // elSettingsPostitionRefresh();
351
352    // On modal open.
353    $("#vc_ui-panel-edit-element").on("vcPanel.shown", function () {
354      var $shortcode =
355        $("#vc_ui-panel-edit-element[data-vc-shortcode]").length > 0
356          ? $("#vc_ui-panel-edit-element").attr("data-vc-shortcode")
357          : "";
358
359      if ("poc_single_image_custom_element" === $shortcode) {
360        nectarCreateDeviceGroup("image-margin-device-group");
361        $(
362          '[data-vc-shortcode="poc_single_image_custom_element"] [data-vc-shortcode-param-name="max_width"] select[name="max_width"]'
363        )
364          .on("change", function () {
365            if ($(this).val() != "custom") {
366              $(".image-custom-width-device-group-header").hide();
367            } else {
368              $(".image-custom-width-device-group-header").show();
369            }
370          })
371          .trigger("change");
372        deviceGroupEvents();
373      }
374
375      // Constrained values.
376      $(
377        '.wpb_edit_form_elements input[type="checkbox"][class*="constrain_group_"]'
378      ).each(function (i) {
379        constrainedInputs[i] = new ConstrainedInput($(this));
380      });
381
382      nectarRangeSliders();
383    }); // Modal open end.
384
385    // Dynamic el styling - front end page builder
386    $(window).on("load", function () {
387      if (
388        typeof window.vc_mode !== "undefined" &&
389        "admin_frontend_editor" === window.vc_mode
390      ) {
391        $(window).on(
392          "nectar_wpbakery_el_save nectar_wpbakery_template_add",
393          function () {
394            var page_content = window.vc.builder.getContent();
395
396            if (page_content.length > 0) {
397              $.ajax({
398                type: "POST",
399                url: window.ajaxurl,
400                data: {
401                  action: "nectar_frontend_builder_generate_styles",
402                  _vcnonce: window.vcAdminNonce,
403                  nectar_page_content: page_content,
404                },
405                success: function (response) {
406                  var style = document.createElement("style");
407
408                  style.type = "text/css";
409                  style.setAttribute("id", "salient-el-dynamic-ajax");
410                  if (style.styleSheet) {
411                    style.styleSheet.cssText = response;
412                  } else {
413                    style.appendChild(document.createTextNode(response));
414                  }
415
416                  // Clean up previous styles.
417                  var dynamicCSSLength = window.vc.frame_window
418                    .jQuery("body")
419                    .find('style[id="salient-el-dynamic-ajax"]').length;
420
421                  if (dynamicCSSLength > 2) {
422                    window.vc.frame_window
423                      .jQuery("body")
424                      .find('style[id="salient-el-dynamic-ajax"]:first')
425                      .remove();
426                  }
427
428                  window.vc.frame_window.jQuery("body").append(style);
429                }, // success
430              }); //ajax
431            }
432          }
433        );
434      } // on front end editor
435    }); // end dynamic el styling
436  });
437})(jQuery);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.