bindings
6 months ago
commands
2 weeks ago
pro
2 weeks ago
_acf-compatibility.js
1 year ago
_acf-condition-types.js
7 months ago
_acf-condition.js
1 year ago
_acf-conditions.js
1 year ago
_acf-field-accordion.js
6 months ago
_acf-field-button-group.js
7 months ago
_acf-field-checkbox.js
1 month ago
_acf-field-color-picker.js
7 months ago
_acf-field-date-picker.js
1 month ago
_acf-field-date-time-picker.js
1 month ago
_acf-field-file.js
1 month ago
_acf-field-google-map.js
6 months ago
_acf-field-icon-picker.js
1 month ago
_acf-field-image.js
1 month ago
_acf-field-link.js
1 year ago
_acf-field-oembed.js
1 month ago
_acf-field-page-link.js
1 year ago
_acf-field-post-object.js
1 year ago
_acf-field-radio.js
1 month ago
_acf-field-range.js
1 year ago
_acf-field-relationship.js
1 month ago
_acf-field-select.js
1 month ago
_acf-field-tab.js
3 weeks ago
_acf-field-taxonomy.js
7 months ago
_acf-field-time-picker.js
1 month ago
_acf-field-true-false.js
1 month ago
_acf-field-url.js
1 year ago
_acf-field-user.js
1 year ago
_acf-field-wysiwyg.js
1 month ago
_acf-field.js
1 year ago
_acf-fields.js
1 year ago
_acf-helpers.js
1 year ago
_acf-hooks.js
1 year ago
_acf-internal-post-type.js
7 months ago
_acf-media.js
2 weeks ago
_acf-modal.js
1 year ago
_acf-model.js
1 year ago
_acf-notice.js
7 months ago
_acf-panel.js
1 year ago
_acf-popup.js
7 months ago
_acf-postbox.js
1 year ago
_acf-screen.js
10 months ago
_acf-select2.js
1 year ago
_acf-tinymce.js
6 months ago
_acf-tooltip.js
10 months ago
_acf-unload.js
1 year ago
_acf-validation.js
1 month ago
_acf.js
7 months ago
_browse-fields-modal.js
7 months ago
_field-group-compatibility.js
1 year ago
_field-group-conditions.js
1 year ago
_field-group-field.js
3 months ago
_field-group-fields.js
10 months ago
_field-group-locations.js
1 year ago
_field-group-settings.js
1 year ago
_field-group.js
10 months ago
acf-escaped-html-notice.js
1 year ago
acf-field-group.js
1 year ago
acf-input.js
1 year ago
acf-internal-post-type.js
1 year ago
acf.js
1 year ago
_acf-condition.js
245 lines
| 1 | ( function ( $, undefined ) { |
| 2 | // vars |
| 3 | var storage = []; |
| 4 | |
| 5 | /** |
| 6 | * acf.Condition |
| 7 | * |
| 8 | * description |
| 9 | * |
| 10 | * @date 23/3/18 |
| 11 | * @since ACF 5.6.9 |
| 12 | * |
| 13 | * @param type $var Description. Default. |
| 14 | * @return type Description. |
| 15 | */ |
| 16 | |
| 17 | acf.Condition = acf.Model.extend( { |
| 18 | type: '', // used for model name |
| 19 | operator: '==', // rule operator |
| 20 | label: '', // label shown when editing fields |
| 21 | choiceType: 'input', // input, select |
| 22 | fieldTypes: [], // auto connect this conditions with these field types |
| 23 | |
| 24 | data: { |
| 25 | conditions: false, // the parent instance |
| 26 | field: false, // the field which we query against |
| 27 | rule: {}, // the rule [field, operator, value] |
| 28 | }, |
| 29 | |
| 30 | events: { |
| 31 | change: 'change', |
| 32 | keyup: 'change', |
| 33 | enableField: 'change', |
| 34 | disableField: 'change', |
| 35 | }, |
| 36 | |
| 37 | setup: function ( props ) { |
| 38 | $.extend( this.data, props ); |
| 39 | }, |
| 40 | |
| 41 | getEventTarget: function ( $el, event ) { |
| 42 | return $el || this.get( 'field' ).$el; |
| 43 | }, |
| 44 | |
| 45 | change: function ( e, $el ) { |
| 46 | this.get( 'conditions' ).change( e ); |
| 47 | }, |
| 48 | |
| 49 | match: function ( rule, field ) { |
| 50 | return false; |
| 51 | }, |
| 52 | |
| 53 | calculate: function () { |
| 54 | return this.match( this.get( 'rule' ), this.get( 'field' ) ); |
| 55 | }, |
| 56 | |
| 57 | choices: function ( field ) { |
| 58 | return '<input type="text" />'; |
| 59 | }, |
| 60 | } ); |
| 61 | |
| 62 | /** |
| 63 | * acf.newCondition |
| 64 | * |
| 65 | * description |
| 66 | * |
| 67 | * @date 1/2/18 |
| 68 | * @since ACF 5.6.5 |
| 69 | * |
| 70 | * @param type $var Description. Default. |
| 71 | * @return type Description. |
| 72 | */ |
| 73 | |
| 74 | acf.newCondition = function ( rule, conditions ) { |
| 75 | // currently setting up conditions for fieldX, this field is the 'target' |
| 76 | var target = conditions.get( 'field' ); |
| 77 | |
| 78 | // use the 'target' to find the 'trigger' field. |
| 79 | // - this field is used to setup the conditional logic events |
| 80 | var field = target.getField( rule.field ); |
| 81 | |
| 82 | // bail early if no target or no field (possible if field doesn't exist due to HTML error) |
| 83 | if ( ! target || ! field ) { |
| 84 | return false; |
| 85 | } |
| 86 | |
| 87 | // vars |
| 88 | var args = { |
| 89 | rule: rule, |
| 90 | target: target, |
| 91 | conditions: conditions, |
| 92 | field: field, |
| 93 | }; |
| 94 | |
| 95 | // vars |
| 96 | var fieldType = field.get( 'type' ); |
| 97 | var operator = rule.operator; |
| 98 | |
| 99 | // get available conditions |
| 100 | var conditionTypes = acf.getConditionTypes( { |
| 101 | fieldType: fieldType, |
| 102 | operator: operator, |
| 103 | } ); |
| 104 | |
| 105 | // instantiate |
| 106 | var model = conditionTypes[ 0 ] || acf.Condition; |
| 107 | |
| 108 | // instantiate |
| 109 | var condition = new model( args ); |
| 110 | |
| 111 | // return |
| 112 | return condition; |
| 113 | }; |
| 114 | |
| 115 | /** |
| 116 | * mid |
| 117 | * |
| 118 | * Calculates the model ID for a field type |
| 119 | * |
| 120 | * @date 15/12/17 |
| 121 | * @since ACF 5.6.5 |
| 122 | * |
| 123 | * @param string type |
| 124 | * @return string |
| 125 | */ |
| 126 | |
| 127 | var modelId = function ( type ) { |
| 128 | return acf.strPascalCase( type || '' ) + 'Condition'; |
| 129 | }; |
| 130 | |
| 131 | /** |
| 132 | * acf.registerConditionType |
| 133 | * |
| 134 | * description |
| 135 | * |
| 136 | * @date 1/2/18 |
| 137 | * @since ACF 5.6.5 |
| 138 | * |
| 139 | * @param type $var Description. Default. |
| 140 | * @return type Description. |
| 141 | */ |
| 142 | |
| 143 | acf.registerConditionType = function ( model ) { |
| 144 | // vars |
| 145 | var proto = model.prototype; |
| 146 | var type = proto.type; |
| 147 | var mid = modelId( type ); |
| 148 | |
| 149 | // store model |
| 150 | acf.models[ mid ] = model; |
| 151 | |
| 152 | // store reference |
| 153 | storage.push( type ); |
| 154 | }; |
| 155 | |
| 156 | /** |
| 157 | * acf.getConditionType |
| 158 | * |
| 159 | * description |
| 160 | * |
| 161 | * @date 1/2/18 |
| 162 | * @since ACF 5.6.5 |
| 163 | * |
| 164 | * @param type $var Description. Default. |
| 165 | * @return type Description. |
| 166 | */ |
| 167 | |
| 168 | acf.getConditionType = function ( type ) { |
| 169 | var mid = modelId( type ); |
| 170 | return acf.models[ mid ] || false; |
| 171 | }; |
| 172 | |
| 173 | /** |
| 174 | * acf.registerConditionForFieldType |
| 175 | * |
| 176 | * description |
| 177 | * |
| 178 | * @date 1/2/18 |
| 179 | * @since ACF 5.6.5 |
| 180 | * |
| 181 | * @param type $var Description. Default. |
| 182 | * @return type Description. |
| 183 | */ |
| 184 | |
| 185 | acf.registerConditionForFieldType = function ( conditionType, fieldType ) { |
| 186 | // get model |
| 187 | var model = acf.getConditionType( conditionType ); |
| 188 | |
| 189 | // append |
| 190 | if ( model ) { |
| 191 | model.prototype.fieldTypes.push( fieldType ); |
| 192 | } |
| 193 | }; |
| 194 | |
| 195 | /** |
| 196 | * acf.getConditionTypes |
| 197 | * |
| 198 | * description |
| 199 | * |
| 200 | * @date 1/2/18 |
| 201 | * @since ACF 5.6.5 |
| 202 | * |
| 203 | * @param type $var Description. Default. |
| 204 | * @return type Description. |
| 205 | */ |
| 206 | |
| 207 | acf.getConditionTypes = function ( args ) { |
| 208 | // defaults |
| 209 | args = acf.parseArgs( args, { |
| 210 | fieldType: '', |
| 211 | operator: '', |
| 212 | } ); |
| 213 | |
| 214 | // clone available types |
| 215 | var types = []; |
| 216 | |
| 217 | // loop |
| 218 | storage.map( function ( type ) { |
| 219 | // vars |
| 220 | var model = acf.getConditionType( type ); |
| 221 | var ProtoFieldTypes = model.prototype.fieldTypes; |
| 222 | var ProtoOperator = model.prototype.operator; |
| 223 | |
| 224 | // check fieldType |
| 225 | if ( |
| 226 | args.fieldType && |
| 227 | ProtoFieldTypes.indexOf( args.fieldType ) === -1 |
| 228 | ) { |
| 229 | return; |
| 230 | } |
| 231 | |
| 232 | // check operator |
| 233 | if ( args.operator && ProtoOperator !== args.operator ) { |
| 234 | return; |
| 235 | } |
| 236 | |
| 237 | // append |
| 238 | types.push( model ); |
| 239 | } ); |
| 240 | |
| 241 | // return |
| 242 | return types; |
| 243 | }; |
| 244 | } )( jQuery ); |
| 245 |