admin
1 month ago
builder
1 month ago
stripe
1 month ago
admin.js
1 month ago
checkout-fields-manager.js
1 month ago
checkout.js
1 month ago
clipboard.min.js
1 month ago
content-control.js
1 month ago
create-form.js
1 month ago
frontend.js
1 month ago
frontend.min.js
1 month ago
index.php
1 month ago
jcarousel.min.js
1 month ago
jquery.blockUI.js
1 month ago
mailoptin.js
1 month ago
member-directory.js
1 month ago
member-directory.min.js
1 month ago
pp-wp-editor.js
1 month ago
content-control.js
327 lines
| 1 | (function ($) { |
| 2 | |
| 3 | var cr = { |
| 4 | orRuleTemplate: wp.template('ppress-cr-or-rule'), |
| 5 | orExemptTemplate: wp.template('ppress-cr-or-exempt'), |
| 6 | andRuleTemplate: wp.template('ppress-cr-and-rule'), |
| 7 | unlinkedAndRuleBadge: wp.template('ppress-cr-unlinked-and-rule-badge'), |
| 8 | linkedAndRuleBadge: wp.template('ppress-cr-linked-and-rule-badge') |
| 9 | }; |
| 10 | |
| 11 | cr.uiBlock = function () { |
| 12 | $('#ppress-content-protection-content').block({ |
| 13 | message: '<span class="spinner" style="visibility:visible;float:none;"></span>', |
| 14 | css: {border: '0', backgroundColor: 'transparent'}, |
| 15 | overlayCSS: { |
| 16 | backgroundColor: '#fff', |
| 17 | opacity: 0.9 |
| 18 | } |
| 19 | }); |
| 20 | }; |
| 21 | |
| 22 | cr.uiUnBlock = function () { |
| 23 | $('#ppress-content-protection-content').unblock(); |
| 24 | }; |
| 25 | |
| 26 | cr.uiExemptBlock = function () { |
| 27 | $('#ppress-content-protection-excludes').block({ |
| 28 | message: '<span class="spinner" style="visibility:visible;float:none;"></span>', |
| 29 | css: {border: '0', backgroundColor: 'transparent'}, |
| 30 | overlayCSS: { |
| 31 | backgroundColor: '#fff', |
| 32 | opacity: 0.9 |
| 33 | } |
| 34 | }); |
| 35 | }; |
| 36 | |
| 37 | cr.uiExemptUnBlock = function () { |
| 38 | $('#ppress-content-protection-excludes').unblock(); |
| 39 | }; |
| 40 | |
| 41 | cr.select2Init = function (isContentExempt = false) { |
| 42 | if (isContentExempt) { |
| 43 | $('.pp-content-protection-excludes .facetList .facet').each(function (index, element) { |
| 44 | var selected_condition, select2options, fieldType, parent = $(element); |
| 45 | |
| 46 | $('.ppress-cr-select2', parent).each(function (index2, element2) { |
| 47 | if ($(element2).hasClass("select2-hidden-accessible") === false) { |
| 48 | selected_condition = $('.ppress-content-condition-exempt-rule-name', parent).val(); |
| 49 | select2options = typeof ppress_cr_conditions[selected_condition]['field'] ? ppress_cr_conditions[selected_condition]['field'] : {}; |
| 50 | fieldType = typeof select2options['type'] !== "undefined" ? select2options['type'] : ''; |
| 51 | if (_.contains(['postselect', 'taxonomyselect'], fieldType)) { |
| 52 | select2options = _.extend(select2options, { |
| 53 | ajax: { |
| 54 | url: ajaxurl, |
| 55 | delay: 250, |
| 56 | cache: true, |
| 57 | data: function (params) { |
| 58 | return { |
| 59 | search: params.term, |
| 60 | nonce: ppress_cr_nonce, |
| 61 | action: 'ppress_cr_object_search', |
| 62 | object_type: fieldType === 'postselect' ? 'post_type' : 'taxonomy', |
| 63 | object_key: select2options.type === 'postselect' ? select2options.post_type : select2options.taxonomy |
| 64 | }; |
| 65 | } |
| 66 | } |
| 67 | }); |
| 68 | } |
| 69 | |
| 70 | $(element2).select2(select2options); |
| 71 | } |
| 72 | }) |
| 73 | }); |
| 74 | } else { |
| 75 | $('.pp-content-protection-content-box .facetList .facet').each(function (index, element) { |
| 76 | |
| 77 | var selected_condition, select2options, fieldType, parent = $(element); |
| 78 | |
| 79 | $('.ppress-cr-select2', parent).each(function (index2, element2) { |
| 80 | if ($(element2).hasClass("select2-hidden-accessible") === false) { |
| 81 | selected_condition = $('.ppress-content-condition-rule-name', parent).val(); |
| 82 | select2options = typeof ppress_cr_conditions[selected_condition]['field'] ? ppress_cr_conditions[selected_condition]['field'] : {}; |
| 83 | fieldType = typeof select2options['type'] !== "undefined" ? select2options['type'] : ''; |
| 84 | if (_.contains(['postselect', 'taxonomyselect'], fieldType)) { |
| 85 | select2options = _.extend(select2options, { |
| 86 | ajax: { |
| 87 | url: ajaxurl, |
| 88 | delay: 250, |
| 89 | cache: true, |
| 90 | data: function (params) { |
| 91 | return { |
| 92 | search: params.term, |
| 93 | nonce: ppress_cr_nonce, |
| 94 | action: 'ppress_cr_object_search', |
| 95 | object_type: fieldType === 'postselect' ? 'post_type' : 'taxonomy', |
| 96 | object_key: select2options.type === 'postselect' ? select2options.post_type : select2options.taxonomy |
| 97 | }; |
| 98 | } |
| 99 | } |
| 100 | }); |
| 101 | } |
| 102 | |
| 103 | $(element2).select2(select2options); |
| 104 | } |
| 105 | }) |
| 106 | }); |
| 107 | } |
| 108 | $('#pp-cc-access-membership-plans').select2(); |
| 109 | |
| 110 | $('#pp-cc-access-wp-users').select2({ |
| 111 | ajax: { |
| 112 | url: ajaxurl, |
| 113 | delay: 250, |
| 114 | cache: true, |
| 115 | data: function (params) { |
| 116 | return { |
| 117 | search: params.term, |
| 118 | nonce: ppress_cr_nonce, |
| 119 | action: 'ppress_cr_object_search', |
| 120 | object_type: 'wp_users', |
| 121 | }; |
| 122 | } |
| 123 | }, |
| 124 | minimumInputLength: 2 |
| 125 | }); |
| 126 | }; |
| 127 | |
| 128 | cr.generateUniqueID = function () { |
| 129 | return Math.random().toString(36).substring(2) + Date.now().toString(36); |
| 130 | }; |
| 131 | |
| 132 | cr.addOrRule = function () { |
| 133 | $(document).on('click', '#ppress-content-protection-content .addFacet', function () { |
| 134 | $(this).trigger('blur'); |
| 135 | var parent = $(this).parents('.condAction'); |
| 136 | parent.find('.facetList').append( |
| 137 | cr.orRuleTemplate({ |
| 138 | facetListId: parent.data('facet-list'), |
| 139 | facetId: cr.generateUniqueID() |
| 140 | }) |
| 141 | ); |
| 142 | }); |
| 143 | |
| 144 | $(document).on('click', '#ppress-content-protection-excludes .addFacet', function () { |
| 145 | $(this).trigger('blur'); |
| 146 | var parent = $(this).parents('.condAction'); |
| 147 | parent.find('.facetList').append( |
| 148 | cr.orExemptTemplate({ |
| 149 | facetListId: parent.data('facet-list'), |
| 150 | facetId: cr.generateUniqueID() |
| 151 | }) |
| 152 | ); |
| 153 | }); |
| 154 | }; |
| 155 | |
| 156 | cr.addAndRule = function () { |
| 157 | $(document).on('click', '#ppress-content-protection-content .addCondition', function () { |
| 158 | $(this).trigger('blur'); |
| 159 | $('#ppress-content-protection-content .workflowConditions').append( |
| 160 | cr.andRuleTemplate({ |
| 161 | facetListId: cr.generateUniqueID(), |
| 162 | facetId: cr.generateUniqueID() |
| 163 | }) |
| 164 | ); |
| 165 | |
| 166 | $(this).parents('.and').replaceWith(cr.unlinkedAndRuleBadge()); |
| 167 | }); |
| 168 | }; |
| 169 | |
| 170 | cr.deleteOrRule = function () { |
| 171 | $(document).on('click', '#ppress-content-protection-content .removeFacet', function () { |
| 172 | $(this).trigger('blur'); |
| 173 | var andRuleWrapper = $(this).parents('.condAction').parent(), |
| 174 | rule_wrapper = $(this).parents('.facetList').find('.facet'); |
| 175 | |
| 176 | if (rule_wrapper.length === 1) { |
| 177 | |
| 178 | if ($('#ppress-content-protection-content .condAction').length === 1) { |
| 179 | rule_wrapper.find('.ppress-cr-rule-values').html(''); |
| 180 | rule_wrapper.find('.ppress-content-condition-rule-name').val(''); |
| 181 | return false; |
| 182 | } |
| 183 | |
| 184 | andRuleWrapper.remove(); |
| 185 | |
| 186 | $('p.and').eq(-1).replaceWith(cr.linkedAndRuleBadge()); |
| 187 | return; |
| 188 | } |
| 189 | |
| 190 | $(this).parents('.facet').remove(); |
| 191 | }); |
| 192 | |
| 193 | $(document).on('click', '#ppress-content-protection-excludes .removeFacet', function () { |
| 194 | $(this).trigger('blur'); |
| 195 | var andRuleWrapper = $(this).parents('.condAction').parent(), |
| 196 | rule_wrapper = $(this).parents('.facetList').find('.facet'); |
| 197 | |
| 198 | if (rule_wrapper.length === 1) { |
| 199 | |
| 200 | if ($('#ppress-content-protection-excludes .condAction').length === 1) { |
| 201 | rule_wrapper.find('.ppress-cr-rule-values').html(''); |
| 202 | rule_wrapper.find('.ppress-content-condition-exempt-rule-name').val(''); |
| 203 | return false; |
| 204 | } |
| 205 | |
| 206 | andRuleWrapper.remove(); |
| 207 | |
| 208 | $('p.and').eq(-1).replaceWith(cr.linkedAndRuleBadge()); |
| 209 | return; |
| 210 | } |
| 211 | |
| 212 | $(this).parents('.facet').remove(); |
| 213 | }); |
| 214 | }; |
| 215 | |
| 216 | cr.getConditionValueField = function () { |
| 217 | $(document).on('change', '.ppress-content-condition-rule-name', function () { |
| 218 | |
| 219 | var cr_rule_value_container = $(this).parents('.facet').find('.ppress-cr-rule-values'), |
| 220 | selected_condition = this.value; |
| 221 | |
| 222 | cr_rule_value_container.html(''); |
| 223 | |
| 224 | if (selected_condition === "") return false; |
| 225 | |
| 226 | var ajaxData = { |
| 227 | 'action': 'ppress_content_condition_field', |
| 228 | 'condition_id': this.value, |
| 229 | 'nonce': ppress_cr_nonce |
| 230 | }, |
| 231 | facetId = $(this).parents('.facet').data('facet'), |
| 232 | facetListId = $(this).parents('.condAction').data('facet-list'); |
| 233 | |
| 234 | if (typeof facetId !== "undefined") { |
| 235 | ajaxData.facetId = facetId; |
| 236 | } |
| 237 | |
| 238 | if (typeof facetListId !== "undefined") { |
| 239 | ajaxData.facetListId = facetListId; |
| 240 | } |
| 241 | |
| 242 | try { |
| 243 | ajaxData.field_type = ppress_cr_conditions[selected_condition]['field']['type']; |
| 244 | } catch (e) { |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | cr.uiBlock(); |
| 249 | |
| 250 | $.post(ajaxurl, ajaxData, function (response) { |
| 251 | |
| 252 | if ('success' in response && response.success === true) { |
| 253 | cr_rule_value_container.append(response.data); |
| 254 | $(document).trigger('ppress_cr_field_added', selected_condition) |
| 255 | } |
| 256 | |
| 257 | cr.uiUnBlock(); |
| 258 | } |
| 259 | ); |
| 260 | }); |
| 261 | |
| 262 | $(document).on('change', '.ppress-content-condition-exempt-rule-name', function () { |
| 263 | |
| 264 | var cr_rule_value_container = $(this).parents('.facet').find('.ppress-cr-rule-values'), |
| 265 | selected_condition = this.value; |
| 266 | |
| 267 | cr_rule_value_container.html(''); |
| 268 | |
| 269 | if (selected_condition === "") return false; |
| 270 | |
| 271 | var ajaxData = { |
| 272 | 'action': 'ppress_exempt_content_condition_field', |
| 273 | 'condition_id': this.value, |
| 274 | 'nonce': ppress_cr_nonce |
| 275 | }, |
| 276 | facetId = $(this).parents('.facet').data('facet'), |
| 277 | facetListId = $(this).parents('.condAction').data('facet-list'); |
| 278 | |
| 279 | if (typeof facetId !== "undefined") { |
| 280 | ajaxData.facetId = facetId; |
| 281 | } |
| 282 | |
| 283 | if (typeof facetListId !== "undefined") { |
| 284 | ajaxData.facetListId = facetListId; |
| 285 | } |
| 286 | |
| 287 | try { |
| 288 | ajaxData.field_type = ppress_cr_conditions[selected_condition]['field']['type']; |
| 289 | } catch (e) { |
| 290 | return false; |
| 291 | } |
| 292 | |
| 293 | cr.uiExemptBlock(); |
| 294 | |
| 295 | $.post(ajaxurl, ajaxData, function (response) { |
| 296 | |
| 297 | if ('success' in response && response.success === true) { |
| 298 | cr_rule_value_container.append(response.data); |
| 299 | $(document).trigger('ppress_cr_field_added_exempt', selected_condition) |
| 300 | } |
| 301 | |
| 302 | cr.uiExemptUnBlock(); |
| 303 | } |
| 304 | ); |
| 305 | }) |
| 306 | }; |
| 307 | |
| 308 | cr.EventsListener = function () { |
| 309 | $(document).on('ppress_cr_field_added', function () { |
| 310 | cr.select2Init(); |
| 311 | }); |
| 312 | $(document).on('ppress_cr_field_added_exempt', function () { |
| 313 | cr.select2Init(true); |
| 314 | }); |
| 315 | }; |
| 316 | |
| 317 | $(function () { |
| 318 | cr.select2Init(); |
| 319 | cr.select2Init(true); |
| 320 | cr.addOrRule(); |
| 321 | cr.addAndRule(); |
| 322 | cr.deleteOrRule(); |
| 323 | cr.getConditionValueField(); |
| 324 | cr.EventsListener(); |
| 325 | }); |
| 326 | |
| 327 | })(jQuery); |