PluginProbe
Boxzilla – WordPress Popup Builder / 3.1.17
Boxzilla – WordPress Popup Builder v3.1.17
3.4.11 3.4.10 3.4.9 3.4.3 3.4.4 3.4.5 3.4.6 3.4.7 3.4.8 trunk 3.0 3.0.1 3.0.2 3.0.3 3.1 3.1.1 3.1.10 3.1.11 3.1.12 3.1.13 3.1.14 3.1.15 3.1.16 3.1.17 3.1.18 All 72 releases
boxzilla / assets / browserify / admin / _admin.js

_admin.js in Boxzilla – WordPress Popup Builder 3.1.17, at assets/browserify/admin/_admin.js

149 lines 5.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 'use strict';
3
4 var $ = window.jQuery;
5 var Option = require('./_option.js');
6 var optionControls = document.getElementById('boxzilla-box-options-controls');
7 var $optionControls = $(optionControls);
8 var tnLoggedIn = document.createTextNode(' logged in');
9
10 // sanity check, are we on the correct page?
11 if ($optionControls.length === 0) {
12 return;
13 }
14
15 var EventEmitter = require('wolfy87-eventemitter');
16 var events = new EventEmitter();
17 var Designer = require('./_designer.js')($, Option, events);
18 var rowTemplate = wp.template('rule-row-template');
19 var i18n = boxzilla_i18n;
20
21 // events
22 $optionControls.on('click', ".boxzilla-add-rule", addRuleFields);
23 $optionControls.on('click', ".boxzilla-remove-rule", removeRule);
24 $optionControls.on('change', ".boxzilla-rule-condition", setContextualHelpers);
25 $optionControls.find('.boxzilla-auto-show-trigger').on('change', toggleTriggerOptions);
26
27 $(window).load(function () {
28 if (typeof(window.tinyMCE) === "undefined") {
29 document.getElementById('notice-notinymce').style.display = '';
30 }
31 });
32
33 // call contextual helper method for each row
34 $('.boxzilla-rule-row').each(setContextualHelpers);
35
36 function toggleTriggerOptions() {
37 $optionControls.find('.boxzilla-trigger-options').toggle(this.value !== '');
38 }
39
40 function removeRule() {
41 $(this).parents('tr').remove();
42 }
43
44 function setContextualHelpers() {
45 var context = ( this.tagName.toLowerCase() === "tr" ) ? this : $(this).parents('tr').get(0);
46 var condition = context.querySelector('.boxzilla-rule-condition').value;
47 var valueInput = context.querySelector('.boxzilla-rule-value');
48 var qualifierInput = context.querySelector('.boxzilla-rule-qualifier');
49 var betterInput = valueInput.cloneNode(true);
50 var $betterInput = $(betterInput);
51
52 // remove previously added helpers
53 $(context.querySelectorAll('.boxzilla-helper')).remove();
54
55 // prepare better input
56 betterInput.removeAttribute('name');
57 betterInput.className = betterInput.className + ' boxzilla-helper';
58 valueInput.parentNode.insertBefore(betterInput, valueInput.nextSibling);
59 $betterInput.change(function () {
60 valueInput.value = this.value;
61 });
62
63 betterInput.style.display = '';
64 valueInput.style.display = 'none';
65 qualifierInput.style.display = '';
66 if (tnLoggedIn.parentNode) {
67 tnLoggedIn.parentNode.removeChild(tnLoggedIn);
68 }
69
70 // change placeholder for textual help
71 switch (condition) {
72 default:
73 betterInput.placeholder = i18n.enterCommaSeparatedValues;
74 break;
75
76 case '':
77 case 'everywhere':
78 qualifierInput.value = '1';
79 valueInput.value = '';
80 betterInput.style.display = 'none';
81 qualifierInput.style.display = 'none';
82 break;
83
84 case 'is_single':
85 case 'is_post':
86 betterInput.placeholder = i18n.enterCommaSeparatedPosts;
87 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post", {
88 multiple: true,
89 multipleSep: ","
90 });
91 break;
92
93 case 'is_page':
94 betterInput.placeholder = i18n.enterCommaSeparatedPages;
95 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=page", {
96 multiple: true,
97 multipleSep: ","
98 });
99 break;
100
101 case 'is_post_type':
102 betterInput.placeholder = i18n.enterCommaSeparatedPostTypes;
103 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_type", {
104 multiple: true,
105 multipleSep: ","
106 });
107 break;
108
109 case 'is_url':
110 betterInput.placeholder = i18n.enterCommaSeparatedRelativeUrls;
111 break;
112
113 case 'is_post_in_category':
114 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=category", {
115 multiple: true,
116 multipleSep: ","
117 });
118 break;
119
120 case 'is_post_with_tag':
121 $betterInput.suggest(ajaxurl + "?action=boxzilla_autocomplete&type=post_tag", {
122 multiple: true,
123 multipleSep: ","
124 });
125 break;
126
127 case 'is_user_logged_in':
128 betterInput.style.display = 'none';
129 valueInput.parentNode.insertBefore(tnLoggedIn, valueInput.nextSibling);
130 break;
131
132 }
133 }
134
135 function addRuleFields() {
136 var data = {
137 'key': optionControls.querySelectorAll('.boxzilla-rule-row').length
138 };
139 var html = rowTemplate(data);
140 $(document.getElementById('boxzilla-box-rules')).after(html);
141 return false;
142 }
143
144 module.exports = {
145 'Designer': Designer,
146 'Option': Option,
147 'events': events
148 };
149 })();