| @@ 2296-2411 (lines=116) @@ | ||
| 2293 | } |
|
| 2294 | }, |
|
| 2295 | ||
| 2296 | initKirkiControl: function() { |
|
| 2297 | ||
| 2298 | 'use strict'; |
|
| 2299 | ||
| 2300 | var control = this, |
|
| 2301 | limit, |
|
| 2302 | theNewRow; |
|
| 2303 | ||
| 2304 | // The current value set in Control Class (set in Kirki_Customize_Repeater_Control::to_json() function) |
|
| 2305 | var settingValue = this.params.value; |
|
| 2306 | ||
| 2307 | control.container.find( '.kirki-controls-loading-spinner' ).hide(); |
|
| 2308 | ||
| 2309 | // The hidden field that keeps the data saved (though we never update it) |
|
| 2310 | this.settingField = this.container.find( '[data-customize-setting-link]' ).first(); |
|
| 2311 | ||
| 2312 | // Set the field value for the first time, we'll fill it up later |
|
| 2313 | this.setValue( [], false ); |
|
| 2314 | ||
| 2315 | // The DIV that holds all the rows |
|
| 2316 | this.repeaterFieldsContainer = this.container.find( '.repeater-fields' ).first(); |
|
| 2317 | ||
| 2318 | // Set number of rows to 0 |
|
| 2319 | this.currentIndex = 0; |
|
| 2320 | ||
| 2321 | // Save the rows objects |
|
| 2322 | this.rows = []; |
|
| 2323 | ||
| 2324 | // Default limit choice |
|
| 2325 | limit = false; |
|
| 2326 | if ( ! _.isUndefined( this.params.choices.limit ) ) { |
|
| 2327 | limit = ( 0 >= this.params.choices.limit ) ? false : parseInt( this.params.choices.limit, 10 ); |
|
| 2328 | } |
|
| 2329 | ||
| 2330 | this.container.on( 'click', 'button.repeater-add', function( e ) { |
|
| 2331 | e.preventDefault(); |
|
| 2332 | if ( ! limit || control.currentIndex < limit ) { |
|
| 2333 | theNewRow = control.addRow(); |
|
| 2334 | theNewRow.toggleMinimize(); |
|
| 2335 | control.initColorPicker(); |
|
| 2336 | control.initSelect( theNewRow ); |
|
| 2337 | } else { |
|
| 2338 | jQuery( control.selector + ' .limit' ).addClass( 'highlight' ); |
|
| 2339 | } |
|
| 2340 | }); |
|
| 2341 | ||
| 2342 | this.container.on( 'click', '.repeater-row-remove', function() { |
|
| 2343 | control.currentIndex--; |
|
| 2344 | if ( ! limit || control.currentIndex < limit ) { |
|
| 2345 | jQuery( control.selector + ' .limit' ).removeClass( 'highlight' ); |
|
| 2346 | } |
|
| 2347 | }); |
|
| 2348 | ||
| 2349 | this.container.on( 'click keypress', '.repeater-field-image .upload-button,.repeater-field-cropped_image .upload-button,.repeater-field-upload .upload-button', function( e ) { |
|
| 2350 | e.preventDefault(); |
|
| 2351 | control.$thisButton = jQuery( this ); |
|
| 2352 | control.openFrame( e ); |
|
| 2353 | }); |
|
| 2354 | ||
| 2355 | this.container.on( 'click keypress', '.repeater-field-image .remove-button,.repeater-field-cropped_image .remove-button', function( e ) { |
|
| 2356 | e.preventDefault(); |
|
| 2357 | control.$thisButton = jQuery( this ); |
|
| 2358 | control.removeImage( e ); |
|
| 2359 | }); |
|
| 2360 | ||
| 2361 | this.container.on( 'click keypress', '.repeater-field-upload .remove-button', function( e ) { |
|
| 2362 | e.preventDefault(); |
|
| 2363 | control.$thisButton = jQuery( this ); |
|
| 2364 | control.removeFile( e ); |
|
| 2365 | }); |
|
| 2366 | ||
| 2367 | /** |
|
| 2368 | * Function that loads the Mustache template |
|
| 2369 | */ |
|
| 2370 | this.repeaterTemplate = _.memoize( function() { |
|
| 2371 | var compiled, |
|
| 2372 | /* |
|
| 2373 | * Underscore's default ERB-style templates are incompatible with PHP |
|
| 2374 | * when asp_tags is enabled, so WordPress uses Mustache-inspired templating syntax. |
|
| 2375 | * |
|
| 2376 | * @see trac ticket #22344. |
|
| 2377 | */ |
|
| 2378 | options = { |
|
| 2379 | evaluate: /<#([\s\S]+?)#>/g, |
|
| 2380 | interpolate: /\{\{\{([\s\S]+?)\}\}\}/g, |
|
| 2381 | escape: /\{\{([^\}]+?)\}\}(?!\})/g, |
|
| 2382 | variable: 'data' |
|
| 2383 | }; |
|
| 2384 | ||
| 2385 | return function( data ) { |
|
| 2386 | compiled = _.template( control.container.find( '.customize-control-repeater-content' ).first().html(), null, options ); |
|
| 2387 | return compiled( data ); |
|
| 2388 | }; |
|
| 2389 | }); |
|
| 2390 | ||
| 2391 | // When we load the control, the fields have not been filled up |
|
| 2392 | // This is the first time that we create all the rows |
|
| 2393 | if ( settingValue.length ) { |
|
| 2394 | _.each( settingValue, function( subValue ) { |
|
| 2395 | theNewRow = control.addRow( subValue ); |
|
| 2396 | control.initColorPicker(); |
|
| 2397 | control.initSelect( theNewRow, subValue ); |
|
| 2398 | }); |
|
| 2399 | } |
|
| 2400 | ||
| 2401 | // Once we have displayed the rows, we cleanup the values |
|
| 2402 | this.setValue( settingValue, true, true ); |
|
| 2403 | ||
| 2404 | this.repeaterFieldsContainer.sortable({ |
|
| 2405 | handle: '.repeater-row-header', |
|
| 2406 | update: function() { |
|
| 2407 | control.sort(); |
|
| 2408 | } |
|
| 2409 | }); |
|
| 2410 | ||
| 2411 | }, |
|
| 2412 | ||
| 2413 | /** |
|
| 2414 | * Open the media modal. |
|
| @@ 2255-2370 (lines=116) @@ | ||
| 2252 | } |
|
| 2253 | }, |
|
| 2254 | ||
| 2255 | initKirkiControl: function() { |
|
| 2256 | ||
| 2257 | 'use strict'; |
|
| 2258 | ||
| 2259 | var control = this, |
|
| 2260 | limit, |
|
| 2261 | theNewRow; |
|
| 2262 | ||
| 2263 | // The current value set in Control Class (set in Kirki_Customize_Repeater_Control::to_json() function) |
|
| 2264 | var settingValue = this.params.value; |
|
| 2265 | ||
| 2266 | control.container.find( '.kirki-controls-loading-spinner' ).hide(); |
|
| 2267 | ||
| 2268 | // The hidden field that keeps the data saved (though we never update it) |
|
| 2269 | this.settingField = this.container.find( '[data-customize-setting-link]' ).first(); |
|
| 2270 | ||
| 2271 | // Set the field value for the first time, we'll fill it up later |
|
| 2272 | this.setValue( [], false ); |
|
| 2273 | ||
| 2274 | // The DIV that holds all the rows |
|
| 2275 | this.repeaterFieldsContainer = this.container.find( '.repeater-fields' ).first(); |
|
| 2276 | ||
| 2277 | // Set number of rows to 0 |
|
| 2278 | this.currentIndex = 0; |
|
| 2279 | ||
| 2280 | // Save the rows objects |
|
| 2281 | this.rows = []; |
|
| 2282 | ||
| 2283 | // Default limit choice |
|
| 2284 | limit = false; |
|
| 2285 | if ( ! _.isUndefined( this.params.choices.limit ) ) { |
|
| 2286 | limit = ( 0 >= this.params.choices.limit ) ? false : parseInt( this.params.choices.limit, 10 ); |
|
| 2287 | } |
|
| 2288 | ||
| 2289 | this.container.on( 'click', 'button.repeater-add', function( e ) { |
|
| 2290 | e.preventDefault(); |
|
| 2291 | if ( ! limit || control.currentIndex < limit ) { |
|
| 2292 | theNewRow = control.addRow(); |
|
| 2293 | theNewRow.toggleMinimize(); |
|
| 2294 | control.initColorPicker(); |
|
| 2295 | control.initSelect( theNewRow ); |
|
| 2296 | } else { |
|
| 2297 | jQuery( control.selector + ' .limit' ).addClass( 'highlight' ); |
|
| 2298 | } |
|
| 2299 | }); |
|
| 2300 | ||
| 2301 | this.container.on( 'click', '.repeater-row-remove', function() { |
|
| 2302 | control.currentIndex--; |
|
| 2303 | if ( ! limit || control.currentIndex < limit ) { |
|
| 2304 | jQuery( control.selector + ' .limit' ).removeClass( 'highlight' ); |
|
| 2305 | } |
|
| 2306 | }); |
|
| 2307 | ||
| 2308 | this.container.on( 'click keypress', '.repeater-field-image .upload-button,.repeater-field-cropped_image .upload-button,.repeater-field-upload .upload-button', function( e ) { |
|
| 2309 | e.preventDefault(); |
|
| 2310 | control.$thisButton = jQuery( this ); |
|
| 2311 | control.openFrame( e ); |
|
| 2312 | }); |
|
| 2313 | ||
| 2314 | this.container.on( 'click keypress', '.repeater-field-image .remove-button,.repeater-field-cropped_image .remove-button', function( e ) { |
|
| 2315 | e.preventDefault(); |
|
| 2316 | control.$thisButton = jQuery( this ); |
|
| 2317 | control.removeImage( e ); |
|
| 2318 | }); |
|
| 2319 | ||
| 2320 | this.container.on( 'click keypress', '.repeater-field-upload .remove-button', function( e ) { |
|
| 2321 | e.preventDefault(); |
|
| 2322 | control.$thisButton = jQuery( this ); |
|
| 2323 | control.removeFile( e ); |
|
| 2324 | }); |
|
| 2325 | ||
| 2326 | /** |
|
| 2327 | * Function that loads the Mustache template |
|
| 2328 | */ |
|
| 2329 | this.repeaterTemplate = _.memoize( function() { |
|
| 2330 | var compiled, |
|
| 2331 | /* |
|
| 2332 | * Underscore's default ERB-style templates are incompatible with PHP |
|
| 2333 | * when asp_tags is enabled, so WordPress uses Mustache-inspired templating syntax. |
|
| 2334 | * |
|
| 2335 | * @see trac ticket #22344. |
|
| 2336 | */ |
|
| 2337 | options = { |
|
| 2338 | evaluate: /<#([\s\S]+?)#>/g, |
|
| 2339 | interpolate: /\{\{\{([\s\S]+?)\}\}\}/g, |
|
| 2340 | escape: /\{\{([^\}]+?)\}\}(?!\})/g, |
|
| 2341 | variable: 'data' |
|
| 2342 | }; |
|
| 2343 | ||
| 2344 | return function( data ) { |
|
| 2345 | compiled = _.template( control.container.find( '.customize-control-repeater-content' ).first().html(), null, options ); |
|
| 2346 | return compiled( data ); |
|
| 2347 | }; |
|
| 2348 | }); |
|
| 2349 | ||
| 2350 | // When we load the control, the fields have not been filled up |
|
| 2351 | // This is the first time that we create all the rows |
|
| 2352 | if ( settingValue.length ) { |
|
| 2353 | _.each( settingValue, function( subValue ) { |
|
| 2354 | theNewRow = control.addRow( subValue ); |
|
| 2355 | control.initColorPicker(); |
|
| 2356 | control.initSelect( theNewRow, subValue ); |
|
| 2357 | }); |
|
| 2358 | } |
|
| 2359 | ||
| 2360 | // Once we have displayed the rows, we cleanup the values |
|
| 2361 | this.setValue( settingValue, true, true ); |
|
| 2362 | ||
| 2363 | this.repeaterFieldsContainer.sortable({ |
|
| 2364 | handle: '.repeater-row-header', |
|
| 2365 | update: function() { |
|
| 2366 | control.sort(); |
|
| 2367 | } |
|
| 2368 | }); |
|
| 2369 | ||
| 2370 | }, |
|
| 2371 | ||
| 2372 | /** |
|
| 2373 | * Open the media modal. |
|