builder
4 years ago
admin.js
5 years ago
clipboard.min.js
5 years ago
content-control.js
5 years ago
create-form.js
5 years ago
frontend.js
5 years ago
frontend.min.js
4 years ago
index.php
5 years ago
jcarousel.min.js
5 years ago
jquery.blockUI.js
5 years ago
mailoptin.js
5 years ago
member-directory.js
5 years ago
member-directory.min.js
4 years ago
pp-wp-editor.js
5 years ago
shortcakeui.js
5 years ago
content-control.js
178 lines
| 1 | (function ($) { |
| 2 | |
| 3 | var cr = { |
| 4 | orRuleTemplate: wp.template('ppress-cr-or-rule'), |
| 5 | andRuleTemplate: wp.template('ppress-cr-and-rule'), |
| 6 | unlinkedAndRuleBadge: wp.template('ppress-cr-unlinked-and-rule-badge'), |
| 7 | linkedAndRuleBadge: wp.template('ppress-cr-linked-and-rule-badge') |
| 8 | }; |
| 9 | |
| 10 | cr.uiBlock = function () { |
| 11 | $('#ppress-content-protection-content').block({ |
| 12 | message: '<span class="spinner" style="visibility:visible;float:none;"></span>', |
| 13 | css: {border: '0', backgroundColor: 'transparent'}, |
| 14 | overlayCSS: { |
| 15 | backgroundColor: '#fff', |
| 16 | opacity: 0.9 |
| 17 | } |
| 18 | }); |
| 19 | }; |
| 20 | |
| 21 | cr.uiUnBlock = function () { |
| 22 | $('#ppress-content-protection-content').unblock(); |
| 23 | }; |
| 24 | |
| 25 | cr.select2Init = function () { |
| 26 | $('.facetList .facet').each(function (index, element) { |
| 27 | |
| 28 | var selected_condition, select2options, fieldType, parent = $(element); |
| 29 | |
| 30 | $('.ppress-cr-select2', parent).each(function (index2, element2) { |
| 31 | if ($(element2).hasClass("select2-hidden-accessible") === false) { |
| 32 | selected_condition = $('.ppress-content-condition-rule-name', parent).val(); |
| 33 | select2options = typeof ppress_cr_conditions[selected_condition]['field'] ? ppress_cr_conditions[selected_condition]['field'] : {}; |
| 34 | fieldType = typeof select2options['type'] !== "undefined" ? select2options['type'] : ''; |
| 35 | if (_.contains(['postselect', 'taxonomyselect'], fieldType)) { |
| 36 | select2options = _.extend(select2options, { |
| 37 | ajax: { |
| 38 | url: ajaxurl, |
| 39 | delay: 250, |
| 40 | cache: true, |
| 41 | data: function (params) { |
| 42 | return { |
| 43 | search: params.term, |
| 44 | nonce: ppress_cr_nonce, |
| 45 | action: 'ppress_cr_object_search', |
| 46 | object_type: fieldType === 'postselect' ? 'post_type' : 'taxonomy', |
| 47 | object_key: select2options.type === 'postselect' ? select2options.post_type : select2options.taxonomy |
| 48 | }; |
| 49 | } |
| 50 | } |
| 51 | }); |
| 52 | } |
| 53 | |
| 54 | $(element2).select2(select2options); |
| 55 | } |
| 56 | }) |
| 57 | }) |
| 58 | }; |
| 59 | |
| 60 | cr.generateUniqueID = function () { |
| 61 | return Math.random().toString(36).substring(2) + Date.now().toString(36); |
| 62 | }; |
| 63 | |
| 64 | cr.addOrRule = function () { |
| 65 | $(document).on('click', '#ppress-content-protection-content .addFacet', function () { |
| 66 | $(this).blur(); |
| 67 | var parent = $(this).parents('.condAction'); |
| 68 | parent.find('.facetList').append( |
| 69 | cr.orRuleTemplate({ |
| 70 | facetListId: parent.data('facet-list'), |
| 71 | facetId: cr.generateUniqueID() |
| 72 | }) |
| 73 | ); |
| 74 | }); |
| 75 | }; |
| 76 | |
| 77 | cr.addAndRule = function () { |
| 78 | $(document).on('click', '#ppress-content-protection-content .addCondition', function () { |
| 79 | $(this).blur(); |
| 80 | $('#workflowConditions').append( |
| 81 | cr.andRuleTemplate({ |
| 82 | facetListId: cr.generateUniqueID(), |
| 83 | facetId: cr.generateUniqueID() |
| 84 | }) |
| 85 | ); |
| 86 | |
| 87 | $(this).parents('.and').replaceWith(cr.unlinkedAndRuleBadge()); |
| 88 | }); |
| 89 | }; |
| 90 | |
| 91 | cr.deleteOrRule = function () { |
| 92 | $(document).on('click', '#ppress-content-protection-content .removeFacet', function () { |
| 93 | $(this).blur(); |
| 94 | var andRuleWrapper = $(this).parents('.condAction').parent(), |
| 95 | rule_wrapper = $(this).parents('.facetList').find('.facet'); |
| 96 | |
| 97 | if (rule_wrapper.length === 1) { |
| 98 | |
| 99 | if ($('#ppress-content-protection-content .condAction').length === 1) { |
| 100 | rule_wrapper.find('.ppress-cr-rule-values').html(''); |
| 101 | rule_wrapper.find('.ppress-content-condition-rule-name').val(''); |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | andRuleWrapper.remove(); |
| 106 | |
| 107 | $('p.and').eq(-1).replaceWith(cr.linkedAndRuleBadge()); |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | $(this).parents('.facet').remove(); |
| 112 | }); |
| 113 | }; |
| 114 | |
| 115 | cr.getConditionValueField = function () { |
| 116 | |
| 117 | $(document).on('change', '.ppress-content-condition-rule-name', function () { |
| 118 | |
| 119 | var cr_rule_value_container = $(this).parents('.facet').find('.ppress-cr-rule-values'), |
| 120 | selected_condition = this.value; |
| 121 | |
| 122 | cr_rule_value_container.html(''); |
| 123 | |
| 124 | if (selected_condition === "") return false; |
| 125 | |
| 126 | var ajaxData = { |
| 127 | 'action': 'ppress_content_condition_field', |
| 128 | 'condition_id': this.value, |
| 129 | 'nonce': ppress_cr_nonce |
| 130 | }, |
| 131 | facetId = $(this).parents('.facet').data('facet'), |
| 132 | facetListId = $(this).parents('.condAction').data('facet-list'); |
| 133 | |
| 134 | if (typeof facetId !== "undefined") { |
| 135 | ajaxData.facetId = facetId; |
| 136 | } |
| 137 | |
| 138 | if (typeof facetListId !== "undefined") { |
| 139 | ajaxData.facetListId = facetListId; |
| 140 | } |
| 141 | |
| 142 | try { |
| 143 | ajaxData.field_type = ppress_cr_conditions[selected_condition]['field']['type']; |
| 144 | } catch (e) { |
| 145 | return false; |
| 146 | } |
| 147 | |
| 148 | cr.uiBlock(); |
| 149 | |
| 150 | $.post(ajaxurl, ajaxData, function (response) { |
| 151 | |
| 152 | if ('success' in response && response.success === true) { |
| 153 | cr_rule_value_container.append(response.data); |
| 154 | $(document).trigger('ppress_cr_field_added', selected_condition) |
| 155 | } |
| 156 | |
| 157 | cr.uiUnBlock(); |
| 158 | } |
| 159 | ); |
| 160 | }) |
| 161 | }; |
| 162 | |
| 163 | cr.EventsListener = function () { |
| 164 | $(document).on('ppress_cr_field_added', function () { |
| 165 | cr.select2Init(); |
| 166 | }); |
| 167 | }; |
| 168 | |
| 169 | $(function () { |
| 170 | cr.select2Init(); |
| 171 | cr.addOrRule(); |
| 172 | cr.addAndRule(); |
| 173 | cr.deleteOrRule(); |
| 174 | cr.getConditionValueField(); |
| 175 | cr.EventsListener(); |
| 176 | }); |
| 177 | |
| 178 | })(jQuery); |