fl-theme-builder-layout-admin-edit.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742
  1. ( function( $ ) {
  2. /**
  3. * Handles logic for the theme layout admin edit interface.
  4. *
  5. * @class FLThemeBuilderLayoutAdminEdit
  6. * @since 1.0
  7. */
  8. FLThemeBuilderLayoutAdminEdit = {
  9. /**
  10. * Cache for location object data that is retrieved via AJAX.
  11. *
  12. * @since 1.0
  13. * @access private
  14. * @property {Object} _locationObjectCache
  15. */
  16. _locationObjectCache : {},
  17. /**
  18. * Store a copy of select2 here in case another plugin loads an
  19. * older version of it breaking ours.
  20. *
  21. * @since 1.1.3
  22. * @access private
  23. * @property {Function} _select2
  24. */
  25. _select2 : $.fn.select2,
  26. /**
  27. * Initializes the theme layout admin edit interface.
  28. *
  29. * @since 1.0
  30. * @access private
  31. * @method _init
  32. */
  33. _init: function()
  34. {
  35. this._bind();
  36. this._initNonce();
  37. this._initLayoutSettings();
  38. this._initLocationRules();
  39. this._initUserRules();
  40. this._initSelect2();
  41. },
  42. /**
  43. * Binds events for the theme layout admin edit interface.
  44. *
  45. * @since 1.0
  46. * @access private
  47. * @method _bind
  48. */
  49. _bind: function()
  50. {
  51. // General events
  52. $( '.fl-launch-builder, .fl-view-template' ).on( 'click', this._launchBuilderClicked );
  53. $( '.fl-mb-row-heading-help' ).tipTip();
  54. // Header events
  55. $( 'select[name="fl-theme-layout-settings[sticky]"]' ).on( 'change', this._stickyChanged );
  56. $( 'select[name="fl-theme-layout-settings[overlay]"]' ).on( 'change', this._overlayChanged );
  57. // Location events
  58. $( '.fl-theme-builder-saved-locations' ).delegate( '.fl-theme-builder-location', 'change', this._locationSelectChanged );
  59. $( '.fl-theme-builder-saved-locations' ).delegate( '.fl-theme-builder-remove-location', 'click', this._removeLocationClicked );
  60. $( '.fl-theme-builder-add-location.button' ).on( 'click', this._addLocationClicked );
  61. $( '.fl-theme-builder-add-exclusion.button' ).on( 'click', this._addExclusionClicked );
  62. // User events
  63. $( '.fl-theme-builder-saved-user-rules' ).delegate( '.fl-theme-builder-user-rule', 'change', this._userRuleSelectChanged );
  64. $( '.fl-theme-builder-add-user-rule.button' ).on( 'click', this._addUserRuleClicked );
  65. $( '.fl-theme-builder-saved-user-rules' ).delegate( '.fl-theme-builder-remove-user-rule', 'click', this._removeUserRuleClicked );
  66. },
  67. /**
  68. * Initializes the theme builder nonce.
  69. *
  70. * @since 1.0
  71. * @access private
  72. * @method _initNonce
  73. */
  74. _initNonce: function()
  75. {
  76. $( '#post' ).append( '<input type="hidden" name="fl-theme-builder-nonce" value="' + FLThemeBuilderConfig.nonce + '" />' );
  77. },
  78. /**
  79. * Init the layout settings based on type.
  80. *
  81. * @since 1.0
  82. * @access private
  83. * @method _initLayoutSettings
  84. */
  85. _initLayoutSettings: function()
  86. {
  87. var type = $( 'input[name=fl-theme-layout-type]' ).val(),
  88. sticky = $( '.fl-theme-layout-header-sticky' ),
  89. stickyOn = $( '.fl-theme-layout-header-sticky-on' ),
  90. shrink = $( '.fl-theme-layout-header-shrink' ),
  91. overlay = $( '.fl-theme-layout-header-overlay' ),
  92. overlayBg = $( '.fl-theme-layout-header-overlay-bg' ),
  93. hookRow = $( '.fl-theme-layout-hook-row' ),
  94. hook = $( 'select[name=fl-theme-layout-hook]' ),
  95. orderRow = $( '.fl-theme-layout-order-row' ),
  96. order = $( 'input[name=fl-theme-layout-order]' );
  97. if ( 'header' == type ) {
  98. sticky.show().find( 'select' ).trigger( 'change' );
  99. overlay.show().find( 'select' ).trigger( 'change' );
  100. } else {
  101. sticky.hide();
  102. stickyOn.hide();
  103. shrink.hide();
  104. overlay.hide();
  105. overlayBg.hide();
  106. }
  107. if ( 'part' == type ) {
  108. hookRow.show();
  109. orderRow.show();
  110. } else {
  111. hookRow.hide();
  112. hook.val( '' );
  113. orderRow.hide();
  114. order.val( '0' );
  115. }
  116. },
  117. /**
  118. * Initializes all location rule forms.
  119. *
  120. * @since 1.0
  121. * @access private
  122. * @method _initLocationRules
  123. */
  124. _initLocationRules: function()
  125. {
  126. var exclusions = $( '.fl-theme-builder-exclusion-rules' ),
  127. button = $( '.fl-theme-builder-add-exclusion' );
  128. $( '.fl-theme-builder-location-rules' ).each( this._initLocations );
  129. if ( FLThemeBuilderConfig.exclusions.saved.length > 0 ) {
  130. exclusions.show();
  131. button.hide();
  132. }
  133. },
  134. /**
  135. * Initializes rules for a location form.
  136. *
  137. * @since 1.0
  138. * @access private
  139. * @method _initLocations
  140. */
  141. _initLocations: function()
  142. {
  143. var wrap = $( this ),
  144. savedWrap = wrap.find( '.fl-theme-builder-saved-locations' ),
  145. template = wp.template( 'fl-theme-builder-saved-location' ),
  146. type = null,
  147. config = null,
  148. parts = null,
  149. locationWrap = null,
  150. locationSelect = null,
  151. location = null,
  152. locationType = null,
  153. objectSelect = null,
  154. data = null,
  155. id = null,
  156. i = 0;
  157. if ( wrap.hasClass( 'fl-theme-builder-exclusion-rules' ) ) {
  158. type = 'exclusion';
  159. config = FLThemeBuilderConfig.exclusions;
  160. }
  161. else {
  162. type = 'location';
  163. config = FLThemeBuilderConfig.locations;
  164. }
  165. if ( 0 === config.saved.length ) {
  166. savedWrap.append( template( { type : type } ) );
  167. if ( 'exclusion' == type ) {
  168. savedWrap.find( '.fl-theme-builder-remove-rule-button' ).show();
  169. }
  170. } else {
  171. for ( ; i < config.saved.length; i++ ) {
  172. savedWrap.append( template( { type : type } ) );
  173. parts = config.saved[ i ].split( ':' );
  174. locationWrap = wrap.find( '.fl-theme-builder-saved-location' ).last();
  175. locationSelect = locationWrap.find( '.fl-theme-builder-location' );
  176. objectSelect = locationWrap.find( '.fl-theme-builder-location-objects' );
  177. if ( 'post' == parts[0] || 'taxonomy' == parts[0] || 'tax_parent' == parts[0] ) {
  178. if ( parts.length <= 3 ) {
  179. location = parts[0] + ':' + parts[1];
  180. data = config[ parts[0] ][ parts[1] ];
  181. id = 3 === parts.length ? parts[2] : undefined;
  182. } else {
  183. location = parts[0] + ':' + parts[1] + ':' + parts[2] + ':' + parts[3];
  184. locationType = 'post' === parts[0] && 'ancestor' === parts[2] ? 'post' : parts[2];
  185. locationType = 'tax_parent' === parts[2] ? 'taxonomy' : locationType;
  186. data = config[ locationType ][ parts[3] ];
  187. id = 5 === parts.length ? parts[4] : undefined;
  188. }
  189. }
  190. else {
  191. location = parts[0] + ':' + parts[1];
  192. }
  193. locationWrap.find( '[data-location="' + location + '"]' ).prop( 'selected', true );
  194. if ( 'post' == parts[0] || 'taxonomy' == parts[0] || 'tax_parent' == parts[0] ) {
  195. FLThemeBuilderLayoutAdminEdit._showLocationObjectSelect( objectSelect.parent(), data, id );
  196. }
  197. }
  198. savedWrap.find( '.fl-theme-builder-remove-rule-button' ).show();
  199. }
  200. FLThemeBuilderLayoutAdminEdit._removeLocationOptions();
  201. FLThemeBuilderLayoutAdminEdit._removeLocationObjectOptions();
  202. },
  203. /**
  204. * Removes locations that aren't used for singular
  205. * or archive layouts.
  206. *
  207. * @since 1.0
  208. * @access private
  209. * @method _removeLocationOptions
  210. */
  211. _removeLocationOptions: function()
  212. {
  213. var type = $( 'input[name=fl-theme-layout-type]' ).val(),
  214. options = $( '.fl-theme-builder-location option' );
  215. if ( 'archive' == type ) {
  216. options.filter( '[data-location="general:site"]' ).remove();
  217. options.filter( '[data-location="general:single"]' ).remove();
  218. options.filter( '[data-location="general:404"]' ).remove();
  219. options.filter( '[data-type="post"]' ).remove();
  220. } else if ( 'singular' == type ) {
  221. options.filter( '[data-location="general:site"]' ).remove();
  222. options.filter( '[data-location="general:archive"]' ).remove();
  223. options.filter( '[data-location="general:author"]' ).remove();
  224. options.filter( '[data-location="general:date"]' ).remove();
  225. options.filter( '[data-location="general:search"]' ).remove();
  226. options.filter( '[data-location="general:404"]' ).remove();
  227. options.filter( '[data-type="archive"]' ).remove();
  228. options.filter( '[data-type="taxonomy"]' ).remove();
  229. } else if ( '404' == type ) {
  230. options.not( '[data-location="general:404"]' ).remove();
  231. $( '.fl-theme-builder-locations-form' ).hide();
  232. }
  233. if ( '404' != type ) {
  234. $( '.fl-theme-builder-locations-form' ).show();
  235. }
  236. $( '.fl-theme-builder-exclusion-rules option[data-location="general:site"]' ).remove();
  237. $( '.fl-theme-builder-location optgroup' ).filter( function() {
  238. return '' === $.trim( $( this ).text() );
  239. } ).remove();
  240. },
  241. /**
  242. * Removes location object options that don't make
  243. * sense in certain situations.
  244. *
  245. * @since 1.0
  246. * @access private
  247. * @method _removeLocationObjectOptions
  248. */
  249. _removeLocationObjectOptions: function()
  250. {
  251. $( '.fl-theme-builder-location-objects' ).each( function() {
  252. var select = $( this ),
  253. option = null,
  254. location = select.attr( 'data-location' );
  255. if ( /post:[a-zA-Z0-9_-]+:(post|ancestor|tax_parent):[a-zA-Z0-9_-]+$/.test( location ) ) {
  256. option = select.find( 'option' ).eq( 0 );
  257. if ( '' === option.attr( 'value' ) ) {
  258. option.remove();
  259. }
  260. }
  261. } );
  262. },
  263. /**
  264. * Shows or hides an additional select if necessary when
  265. * the location select is changed.
  266. *
  267. * @since 1.0
  268. * @access private
  269. * @method _locationSelectChanged
  270. */
  271. _locationSelectChanged: function()
  272. {
  273. var self = FLThemeBuilderLayoutAdminEdit,
  274. select = $( this ),
  275. wrap = select.closest( '.fl-theme-builder-location-rules' ),
  276. parent = select.parent(),
  277. locations = wrap.find( '.fl-theme-builder-saved-location' ),
  278. location = select.val(),
  279. locationString = '',
  280. remove = wrap.find( '.fl-theme-builder-saved-locations .fl-theme-builder-remove-rule-button' ),
  281. actionType = 'terms';
  282. if ( '' == location ) {
  283. parent.removeClass( 'fl-theme-builder-rule-objects-visible' );
  284. if ( 1 === locations.length ) {
  285. remove.hide();
  286. }
  287. } else {
  288. location = JSON.parse( location );
  289. locationString = location.type + ':' + location.id;
  290. if ( 'taxonomy' == location.type || 'post' == location.type ) {
  291. if ( typeof self._locationObjectCache[ locationString ] != 'undefined' ) {
  292. self._showLocationObjectSelect( parent, self._locationObjectCache[ locationString ] );
  293. } else {
  294. self._showRowLoading( select );
  295. if ( 'post' == location.type ) {
  296. if ( location.id.indexOf( ':taxonomy' ) > -1 ) {
  297. actionType = 'terms';
  298. location.id = location.id.split( ':taxonomy:' )[1];
  299. }
  300. else {
  301. actionType = 'posts';
  302. }
  303. if ( location.id.indexOf( ':tax_parent' ) > -1 ) {
  304. actionType = 'parent_terms';
  305. location.id = location.id.split( ':tax_parent:' )[1];
  306. }
  307. }
  308. $.post( ajaxurl, {
  309. action : 'fl_theme_builder_get_location_' + actionType,
  310. id : location.id,
  311. nonce : FLThemeBuilderConfig.nonce
  312. }, function( response ) {
  313. FLThemeBuilderLayoutAdminEdit._showLocationObjectSelect( parent, JSON.parse( response ) );
  314. } );
  315. }
  316. } else {
  317. parent.removeClass( 'fl-theme-builder-rule-objects-visible' );
  318. }
  319. remove.show();
  320. }
  321. },
  322. /**
  323. * Shows the location object select and populates
  324. * it with the provided data.
  325. *
  326. * @since 1.0
  327. * @access private
  328. * @method _showLocationObjectSelect
  329. * @param {Object} parent
  330. * @param {Object} data
  331. * @param {Number} id
  332. */
  333. _showLocationObjectSelect: function( parent, data, id )
  334. {
  335. var locationSelect = parent.find( '.fl-theme-builder-location' ),
  336. location = JSON.parse( locationSelect.val() ),
  337. locationString = location.type + ':' + location.id,
  338. objectSelect = parent.find( '.fl-theme-builder-location-objects' ),
  339. objectLocation = null,
  340. parent = objectSelect.parent(),
  341. allLabel = FLThemeBuilderConfig.strings.allObjects.replace( '%s', data.label ),
  342. options = '<option value="" data-location="' + locationString + '">' + allLabel + '</option>',
  343. selected = null,
  344. termLabel = '',
  345. i = 0;
  346. if ( null != data.objects ) {
  347. for ( ; i < data.objects.length; i++ ) {
  348. termLabel = data.objects[i].label ? data.objects[i].label : data.objects[i].name;
  349. objectLocation = ' data-location="' + locationString + ':' + data.objects[ i ].id + '"';
  350. selected = 'undefined' != typeof id && id == data.objects[ i ].id ? ' selected' : '';
  351. options += '<option value=\'' + JSON.stringify( data.objects[ i ] ).replace(/&quot;/g, '\\&quot;') + '\'' + selected + objectLocation + '>' + termLabel + '</option>';
  352. }
  353. }
  354. objectSelect.html( options );
  355. objectSelect.attr( 'data-location', locationString );
  356. objectSelect.attr( 'data-type', data.type );
  357. parent.addClass( 'fl-theme-builder-rule-objects-visible' );
  358. this._locationObjectCache[ locationString ] = data;
  359. FLThemeBuilderLayoutAdminEdit._hideRowLoading( locationSelect );
  360. if ( 'disabled' == objectSelect.find( 'option' ).eq( 0 ).attr( 'disabled' ) ) {
  361. objectSelect.find( 'option' ).eq( 1 ).prop( 'selected', true );
  362. }
  363. FLThemeBuilderLayoutAdminEdit._removeLocationObjectOptions();
  364. },
  365. /**
  366. * Adds a location select when the Add button is clicked.
  367. *
  368. * @since 1.0
  369. * @access private
  370. * @method _addLocationClicked
  371. * @param {Object} e
  372. */
  373. _addLocationClicked: function( e )
  374. {
  375. var self = FLThemeBuilderLayoutAdminEdit,
  376. wrap = $( this ).closest( '.fl-theme-builder-location-rules' ),
  377. savedWrap = wrap.find( '.fl-theme-builder-saved-locations' ),
  378. template = wp.template( 'fl-theme-builder-saved-location' ),
  379. type = wrap.hasClass( 'fl-theme-builder-exclusion-rules' ) ? 'exclusion' : 'location';
  380. savedWrap.append( template( { type : type } ) );
  381. savedWrap.find( '.fl-theme-builder-remove-rule-button' ).show();
  382. self._removeLocationOptions();
  383. self._initSelect2();
  384. },
  385. /**
  386. * Removes a location from the saved locations list.
  387. *
  388. * @since 1.0
  389. * @access private
  390. * @method _removeLocationClicked
  391. * @param {Object} e
  392. */
  393. _removeLocationClicked: function( e )
  394. {
  395. var button = $( e.target ),
  396. wrap = button.closest( '.fl-theme-builder-location-rules' ),
  397. parent = button.parents( '.fl-theme-builder-saved-location' ),
  398. select = parent.find( '.fl-theme-builder-location' ),
  399. locations = wrap.find( '.fl-theme-builder-saved-location' ),
  400. remove = wrap.find( '.fl-theme-builder-saved-locations .fl-theme-builder-remove-rule-button' ),
  401. isExclusion = button.closest( '.fl-theme-builder-exclusion-rules' ).length ? true : false;
  402. if ( locations.length > 1 ) {
  403. button.closest( '.fl-theme-builder-saved-location' ).remove();
  404. }
  405. if ( 1 === locations.length ) {
  406. select.val( '' ).parent().removeClass( 'fl-theme-builder-rule-objects-visible' );
  407. select.next( '.select2' ).find( '.select2-selection__rendered' ).html( FLThemeBuilderConfig.strings.choose );
  408. if ( ! isExclusion ) {
  409. remove.hide();
  410. }
  411. if ( isExclusion ) {
  412. $( '.fl-theme-builder-exclusion-rules' ).hide();
  413. $( '.fl-theme-builder-add-exclusion' ).show();
  414. }
  415. } else if ( ! isExclusion && 2 === locations.length && '' == wrap.find( '.fl-theme-builder-location' ).eq( 0 ).val() ) {
  416. remove.hide();
  417. }
  418. },
  419. /**
  420. * Shows the exclusion rule settings if they are hidden.
  421. *
  422. * @since 1.0
  423. * @access private
  424. * @method _addExclusionClicked
  425. * @param {Object} e
  426. */
  427. _addExclusionClicked: function( e )
  428. {
  429. var button = $( '.fl-theme-builder-add-exclusion' ),
  430. exclusions = $( '.fl-theme-builder-exclusion-rules' );
  431. button.hide();
  432. exclusions.show();
  433. FLThemeBuilderLayoutAdminEdit._initSelect2();
  434. },
  435. /**
  436. * Initializes user rules.
  437. *
  438. * @since 1.0
  439. * @access private
  440. * @method _initUserRules
  441. */
  442. _initUserRules: function()
  443. {
  444. var saved = FLThemeBuilderConfig.userRules,
  445. savedWrap = $( '.fl-theme-builder-saved-user-rules' ),
  446. template = wp.template( 'fl-theme-builder-saved-user-rule' ),
  447. ruleWrap = null,
  448. ruleSelect = null,
  449. selected = null,
  450. i = 0;
  451. if ( 0 === saved.length ) {
  452. savedWrap.append( template() );
  453. savedWrap.find( '[data-rule="general:all"]' ).prop( 'selected', true );
  454. return;
  455. }
  456. for ( ; i < saved.length; i++ ) {
  457. savedWrap.append( template() );
  458. parts = saved[ i ].split( ':' );
  459. ruleWrap = $( '.fl-theme-builder-saved-user-rule' ).last();
  460. ruleSelect = ruleWrap.find( '.fl-theme-builder-user-rule' );
  461. selected = ruleWrap.find( '[data-rule="' + parts[0] + ':' + parts[1] + '"]' );
  462. selected.prop( 'selected', true );
  463. }
  464. savedWrap.find( '.fl-theme-builder-remove-rule-button' ).show();
  465. },
  466. /**
  467. * Fires when a user rule select changes.
  468. *
  469. * @since 1.0
  470. * @access private
  471. * @method _userRuleSelectChanged
  472. * @param {Object} e
  473. */
  474. _userRuleSelectChanged: function( e )
  475. {
  476. var rule = $( e.target ).val(),
  477. rules = $( '.fl-theme-builder-saved-user-rule' ),
  478. remove = $( '.fl-theme-builder-saved-user-rules .fl-theme-builder-remove-rule-button' );
  479. if ( '' == rule ) {
  480. if ( 1 === rules.length ) {
  481. remove.hide();
  482. }
  483. } else {
  484. remove.show();
  485. }
  486. },
  487. /**
  488. * Adds a user rule when the Add button is clicked.
  489. *
  490. * @since 1.0
  491. * @access private
  492. * @method _addUserRuleClicked
  493. * @param {Object} e
  494. */
  495. _addUserRuleClicked: function( e )
  496. {
  497. var savedWrap = $( '.fl-theme-builder-saved-user-rules' ),
  498. template = wp.template( 'fl-theme-builder-saved-user-rule' );
  499. savedWrap.append( template() );
  500. savedWrap.find( '.fl-theme-builder-remove-rule-button' ).show();
  501. FLThemeBuilderLayoutAdminEdit._initSelect2();
  502. },
  503. /**
  504. * Removes a user rule from the saved user rules list.
  505. *
  506. * @since 1.0
  507. * @access private
  508. * @method _removeUserRuleClicked
  509. * @param {Object} e
  510. */
  511. _removeUserRuleClicked: function( e )
  512. {
  513. var button = $( e.target ),
  514. parent = button.parents( '.fl-theme-builder-saved-user-rule' ),
  515. select = parent.find( '.fl-theme-builder-user-rule' ),
  516. rules = $( '.fl-theme-builder-saved-user-rule' ),
  517. remove = $( '.fl-theme-builder-saved-user-rules .fl-theme-builder-remove-rule-button' );
  518. if ( rules.length > 1 ) {
  519. button.closest( '.fl-theme-builder-saved-user-rule' ).remove();
  520. }
  521. if ( 1 === rules.length ) {
  522. select.val( '' );
  523. select.next( '.select2' ).find( '.select2-selection__rendered' ).html( FLThemeBuilderConfig.strings.choose );
  524. remove.hide();
  525. } else if ( 2 === rules.length && '' == $( '.fl-theme-builder-user-rule' ).val() ) {
  526. remove.hide();
  527. }
  528. },
  529. /**
  530. * Initializes select2 select objects.
  531. *
  532. * @since 1.0.4
  533. * @access private
  534. * @method _initSelect2
  535. */
  536. _initSelect2: function()
  537. {
  538. var selects = $( '.fl-theme-builder-saved-rules select:not(.select2-init)' ),
  539. select2 = this._select2;
  540. selects.each( function() {
  541. var select = $( this ),
  542. config = {
  543. width: 'style'
  544. };
  545. select2.call( select, config );
  546. select.addClass( 'select2-init' );
  547. select.on( 'select2:open', function() {
  548. $( '.select2-search__field' ).attr( 'placeholder', FLThemeBuilderConfig.strings.search );
  549. } );
  550. } );
  551. },
  552. /**
  553. * Callback for when the button to launch the
  554. * builder is clicked.
  555. *
  556. * @since 1.0
  557. * @access private
  558. * @method _launchBuilderClicked
  559. */
  560. _launchBuilderClicked: function( e )
  561. {
  562. var form = $( 'form[name=post]' ),
  563. url = $( this ).attr( 'href' );
  564. form.append( '<input type="hidden" name="redirect" value="' + url + '" />' );
  565. form.submit();
  566. e.preventDefault();
  567. },
  568. /**
  569. * Callback for then the header sticky select is changed.
  570. *
  571. * @since 1.0
  572. * @access private
  573. * @method _stickyChanged
  574. */
  575. _stickyChanged: function()
  576. {
  577. $( '.fl-theme-layout-header-sticky-on' ).toggle( '1' == $(this).val());
  578. $( '.fl-theme-layout-header-shrink' ).toggle( '1' == $( this ).val() );
  579. },
  580. /**
  581. * Callback for then the header overlay select is changed.
  582. *
  583. * @since 1.0.2
  584. * @access private
  585. * @method _overlayChanged
  586. */
  587. _overlayChanged: function()
  588. {
  589. $( '.fl-theme-layout-header-overlay-bg' ).toggle( '1' == $( this ).val() );
  590. },
  591. /**
  592. * Shows the loading icon in the meta box header.
  593. *
  594. * @since 1.0
  595. * @access private
  596. * @method _showLoading
  597. */
  598. _showLoading: function()
  599. {
  600. var header = $( '#fl-theme-builder-settings h2.hndle span' );
  601. if ( ! header.find( '.spinner' ).length ) {
  602. header.append( '<span class="spinner"></span>' );
  603. }
  604. },
  605. /**
  606. * Hides the loading icon in the meta box header.
  607. *
  608. * @since 1.0
  609. * @access private
  610. * @method _hideLoading
  611. */
  612. _hideLoading: function()
  613. {
  614. $( '#fl-theme-builder-settings h2.hndle .spinner' ).remove();
  615. },
  616. /**
  617. * Shows the loading overlay for a meta box row.
  618. *
  619. * @since 1.0
  620. * @access private
  621. * @method _showRowLoading
  622. * @param {Object} ele
  623. */
  624. _showRowLoading: function( ele )
  625. {
  626. ele.closest( '.fl-mb-row-content' ).prepend( '<div class="fl-mb-loading"></div>' );
  627. },
  628. /**
  629. * Hides the loading overlay for a meta box row.
  630. *
  631. * @since 1.0
  632. * @access private
  633. * @method _hideRowLoading
  634. * @param {Object} ele
  635. */
  636. _hideRowLoading: function( ele )
  637. {
  638. ele.closest( '.fl-mb-row-content' ).find( '.fl-mb-loading' ).remove();
  639. }
  640. };
  641. // Initialize
  642. $( function() { FLThemeBuilderLayoutAdminEdit._init(); } );
  643. } )( jQuery );