fl-builder-ui-pinned.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. ( function( $ ) {
  2. /**
  3. * Helper for pinning the builder UI to the
  4. * sides of the browser window.
  5. *
  6. * @since 2.0
  7. * @class PinnedUI
  8. */
  9. var PinnedUI = {
  10. /**
  11. * @since 2.0
  12. * @method init
  13. */
  14. init: function() {
  15. this.initPanel();
  16. this.pinOrUnpin();
  17. this.bind();
  18. },
  19. /**
  20. * @since 2.0
  21. * @method bind
  22. */
  23. bind: function() {
  24. var win = $( window ),
  25. body = $( 'body' );
  26. win.on( 'resize', _.throttle( this.windowResize.bind( this ), 250 ) );
  27. body.delegate( '.fl-builder-ui-pinned-collapse', 'click', this.collapse );
  28. body.delegate( '.fl-builder--content-library-panel .fl-builder--tabs', 'click', this.closeLightboxOnPanelClick );
  29. FLBuilder.addHook( 'didShowLightbox', this.pinLightboxOnOpen.bind( this ) );
  30. FLBuilder.addHook( 'didHideAllLightboxes', this.pinnedLightboxClosed.bind( this ) );
  31. FLBuilder.addHook( 'endEditingSession', this.hide.bind( this ) );
  32. FLBuilder.addHook( 'didHideEditingUI', this.hide.bind( this ) );
  33. FLBuilder.addHook( 'publishButtonClicked', this.hide.bind( this ) );
  34. FLBuilder.addHook( 'restartEditingSession', this.show.bind( this ) );
  35. FLBuilder.addHook( 'didShowEditingUI', this.show.bind( this ) );
  36. FLBuilder.addHook( 'didShowLightbox', this.uncollapse.bind(this) );
  37. FLBuilder.addHook( 'willShowContentPanel', this.uncollapse.bind(this) );
  38. FLBuilder.addHook( 'willShowContentPanel', this.closeLightboxOnPanelClick.bind(this) );
  39. },
  40. /**
  41. * Checks to see if the UI is currently pinned or not.
  42. *
  43. * @since 2.0
  44. * @method isPinned
  45. * @return {Boolean}
  46. */
  47. isPinned: function() {
  48. return $( '.fl-builder--content-library-panel' ).hasClass( 'fl-builder-ui-pinned' );
  49. },
  50. /**
  51. * Pins the UI.
  52. *
  53. * @since 2.0
  54. * @method pin
  55. * @param {String} position
  56. * @param {Boolean} savePosition
  57. */
  58. pin: function( position, savePosition ) {
  59. this.pinPanel( position );
  60. this.pinLightboxes();
  61. if ( savePosition ) {
  62. this.savePosition();
  63. }
  64. FLBuilder._resizeLayout();
  65. FLBuilder.triggerHook( 'didPinContentPanel' );
  66. },
  67. /**
  68. * Unpins the UI.
  69. *
  70. * @since 2.0
  71. * @method unpin
  72. * @param {Boolean} savePosition
  73. */
  74. unpin: function( savePosition ) {
  75. this.unpinLightboxes();
  76. this.unpinPanel();
  77. if ( savePosition ) {
  78. this.savePosition();
  79. }
  80. FLBuilder._resizeLayout();
  81. FLBuilder.triggerHook( 'didUnpinContentPanel' );
  82. },
  83. /**
  84. * Pins or unpins the UI based on the window size.
  85. *
  86. * @since 2.0
  87. * @method pinOrUnpin
  88. */
  89. pinOrUnpin: function()
  90. {
  91. var panel = $( '.fl-builder--content-library-panel' ),
  92. pinned = this.isPinned();
  93. if ( panel.hasClass( 'fl-builder-ui-pinned-hidden' ) ) {
  94. return;
  95. } else if ( window.innerWidth <= 500 ) {
  96. if ( pinned ) {
  97. this.unpin( false );
  98. }
  99. this.disableDragAndResize();
  100. } else {
  101. if ( ! pinned ) {
  102. this.restorePosition();
  103. }
  104. this.enableDragAndResize();
  105. }
  106. },
  107. /**
  108. * Shows the pinned UI if it has been hidden.
  109. *
  110. * @since 2.0
  111. * @method show
  112. */
  113. show: function()
  114. {
  115. var panel = $( '.fl-builder--content-library-panel' );
  116. if ( panel.hasClass( 'fl-builder-ui-pinned-hidden' ) ) {
  117. panel.removeClass( 'fl-builder-ui-pinned-hidden' );
  118. panel.show();
  119. this.restorePosition();
  120. }
  121. },
  122. /**
  123. * Hides pinned lightboxes without unpinning them.
  124. *
  125. * @since 2.0
  126. * @method hide
  127. */
  128. hide: function()
  129. {
  130. var body = $( 'body' ),
  131. panel = $( '.fl-builder--content-library-panel' );
  132. if ( this.isPinned() ) {
  133. this.uncollapse();
  134. panel.addClass( 'fl-builder-ui-pinned-hidden' );
  135. panel.hide();
  136. body.css( 'margin', '' );
  137. FLBuilder._resizeLayout();
  138. }
  139. },
  140. /**
  141. * Collapse all pinned UI elements.
  142. *
  143. * @since 2.0
  144. * @method collapse
  145. */
  146. collapse: function()
  147. {
  148. var button = $( this ).find('i:visible'),
  149. body = $( 'body' ),
  150. toggle = button.data( 'toggle' ),
  151. position = button.data( 'position' ),
  152. panel = $( '.fl-builder--content-library-panel' ),
  153. width = panel.outerWidth();
  154. if ( 'hide' === toggle ) {
  155. panel.css( position, '-' + width + 'px' );
  156. body.css( 'margin-' + position, '' );
  157. body.addClass( 'fl-builder-ui-pinned-is-collapsed' );
  158. } else {
  159. panel.css( position, '0px' );
  160. body.css( 'margin-' + position, width + 'px' );
  161. body.removeClass( 'fl-builder-ui-pinned-is-collapsed' );
  162. }
  163. },
  164. /**
  165. * Uncollapse all pinned UI elements.
  166. *
  167. * @since 2.0
  168. * @method uncollapse
  169. */
  170. uncollapse: function()
  171. {
  172. if ( this.isCollapsed() ) {
  173. $( '.fl-builder-ui-pinned-collapse:visible' ).trigger( 'click' );
  174. }
  175. },
  176. /**
  177. * Return whether or not the panel is currently collapsed
  178. *
  179. * @since 2.0
  180. * @method isCollapsed
  181. */
  182. isCollapsed: function() {
  183. return $('body').hasClass('fl-builder-ui-pinned-is-collapsed');
  184. },
  185. /**
  186. * Initializes pinning for the main content panel.
  187. *
  188. * @since 2.0
  189. * @method initPanel
  190. */
  191. initPanel: function() {
  192. var panel = $( '.fl-builder--content-library-panel' );
  193. panel.draggable( {
  194. cursor : 'move',
  195. handle : '.fl-builder--tabs',
  196. cancel : '.fl-builder--tabs button',
  197. scroll : false,
  198. drag : this.drag.bind( this ),
  199. stop : this.dragStop.bind( this ),
  200. start : this.dragStart.bind( this ),
  201. } ).resizable( {
  202. handles : 'e, w',
  203. minHeight : 400,
  204. minWidth : 380,
  205. maxWidth : 500,
  206. start : this.resizeStart.bind( this ),
  207. stop : this.resizeStop.bind( this )
  208. } );
  209. panel.addClass( 'fl-builder-ui-pinned-container' );
  210. panel.find( '.ui-resizable-e, .ui-resizable-w' ).hide();
  211. },
  212. /**
  213. * Pins the main content panel.
  214. *
  215. * @since 2.0
  216. * @method pinPanel
  217. * @param {String} position
  218. */
  219. pinPanel: function( position ) {
  220. var panel = $( '.fl-builder--content-library-panel' ),
  221. width = panel.outerWidth(),
  222. body = $( 'body' ),
  223. preview = $( '.fl-responsive-preview, .fl-responsive-preview-mask' ),
  224. content = $( FLBuilder._contentClass ).parentsUntil( 'body' ).last();
  225. body.addClass( 'fl-builder-ui-is-pinned fl-builder-ui-is-pinned-' + position );
  226. body.addClass( 'fl-builder-content-panel-is-showing' );
  227. body.css( 'margin-' + position, width + 'px' );
  228. preview.css( 'margin-' + position, width + 'px' );
  229. content.addClass( 'fl-builder-ui-pinned-content-transform' );
  230. panel.addClass( 'fl-builder-ui-pinned fl-builder-ui-pinned-' + position );
  231. panel.find( '.ui-resizable-' + ( 'left' === position ? 'e' : 'w' ) ).show();
  232. panel.on( 'resize', _.throttle( this.resize.bind( this ), 250 ) );
  233. panel.attr( 'style', '' );
  234. FLBuilder.ContentPanel.isShowing = true;
  235. },
  236. /**
  237. * Unpins the main content panel.
  238. *
  239. * @since 2.0
  240. * @method unpinPanel
  241. */
  242. unpinPanel: function() {
  243. var panel = $( '.fl-builder--content-library-panel' ),
  244. tab = panel.find( '.fl-builder--panel-content .is-showing' ).data( 'tab' ),
  245. body = $( 'body' ),
  246. preview = $( '.fl-responsive-preview, .fl-responsive-preview-mask' ),
  247. content = $( FLBuilder._contentClass ).parentsUntil( 'body' ).last();
  248. body.css( 'margin-left', '' );
  249. body.css( 'margin-right', '' );
  250. body.removeClass( 'fl-builder-ui-is-pinned' );
  251. body.removeClass( 'fl-builder-ui-is-pinned-left' );
  252. body.removeClass( 'fl-builder-ui-is-pinned-right' );
  253. preview.css( 'margin-left', '' );
  254. preview.css( 'margin-right', '' );
  255. content.removeClass( 'fl-lightbox-content-transform' );
  256. panel.removeClass( 'fl-builder-ui-pinned' );
  257. panel.removeClass( 'fl-builder-ui-pinned-left' );
  258. panel.removeClass( 'fl-builder-ui-pinned-right' );
  259. panel.find( '.ui-resizable-handle' ).hide();
  260. panel.off( 'resize' );
  261. panel.attr( 'style', '' );
  262. panel.find( '.fl-builder--tabs [data-tab=' + tab + ']' ).addClass( 'is-showing' );
  263. },
  264. /**
  265. * Pins all open lightboxes.
  266. *
  267. * @since 2.0
  268. * @method pinLightboxes
  269. */
  270. pinLightboxes: function() {
  271. var self = this;
  272. $( '.fl-lightbox-resizable' ).each( function() {
  273. self.pinLightbox( $( this ) );
  274. } );
  275. FLBuilder._reinitEditorFields();
  276. },
  277. /**
  278. * Pins a single lightbox.
  279. *
  280. * @since 2.0
  281. * @method pinLightbox
  282. * @param {Object} lightbox
  283. */
  284. pinLightbox: function( lightbox ) {
  285. var panel = $( '.fl-builder--content-library-panel' ),
  286. wrapper = lightbox.closest( '.fl-lightbox-wrap' );
  287. if ( ! wrapper.closest( '.fl-builder-ui-pinned' ).length ) {
  288. panel.append( wrapper );
  289. lightbox.attr( 'style', '' );
  290. lightbox.draggable( 'disable' );
  291. lightbox.resizable( 'disable' );
  292. }
  293. if ( lightbox.is( ':visible' ) ) {
  294. panel.find( '.fl-builder--tabs .is-showing' ).removeClass( 'is-showing' );
  295. }
  296. },
  297. /**
  298. * Pins a lightbox when it opens if it's not already pinned.
  299. *
  300. * @since 2.0
  301. * @method pinLightboxOnOpen
  302. * @param {Object} e
  303. * @param {FLLightbox} boxObject
  304. */
  305. pinLightboxOnOpen: function( e, boxObject ) {
  306. var lightbox = boxObject._node.find( '.fl-lightbox-resizable' );
  307. if ( ! lightbox.length ) {
  308. return;
  309. }
  310. if ( ! lightbox.hasClass( 'fl-builder-ui-pinning-initialized' ) ) {
  311. lightbox.draggable( 'option', 'start', this.dragStart.bind( this ) );
  312. lightbox.draggable( 'option', 'drag', this.drag.bind( this ) );
  313. lightbox.draggable( 'option', 'stop', this.dragStop.bind( this ) );
  314. lightbox.addClass( 'fl-builder-ui-pinning-initialized' );
  315. }
  316. if ( this.isPinned() ) {
  317. this.pinLightbox( lightbox );
  318. }
  319. FLBuilder.addHook( 'responsive-editing-switched', this.resize );
  320. },
  321. /**
  322. * Handles a pinned lightbox closing.
  323. *
  324. * @since 2.0
  325. * @method pinnedLightboxClosed
  326. */
  327. pinnedLightboxClosed: function() {
  328. var panel = $( '.fl-builder--content-library-panel' )
  329. tab = null;
  330. if ( this.isPinned() ) {
  331. tab = panel.find( '.fl-builder--panel-content .is-showing' ).data( 'tab' );
  332. panel.find( '.fl-builder--tabs [data-tab=' + tab + ']' ).addClass( 'is-showing' );
  333. }
  334. $( '.fl-lightbox' ).removeClass( 'fl-lightbox-prevent-animation' );
  335. },
  336. /**
  337. * Unpins all pinned lightboxes.
  338. *
  339. * @since 2.0
  340. * @method unpinLightboxes
  341. */
  342. unpinLightboxes: function() {
  343. var body = $( 'body' ),
  344. panel = $( '.fl-builder--content-library-panel' );
  345. panel.find( '.fl-lightbox-wrap' ).each( function() {
  346. var wrapper = $( this ),
  347. lightbox = wrapper.find( '.fl-lightbox' ),
  348. top = 0,
  349. left = 0,
  350. right = 0;
  351. lightbox.draggable( 'enable' );
  352. lightbox.resizable( 'enable' );
  353. lightbox.find( '.ui-resizable-handle' ).show();
  354. body.append( wrapper );
  355. if ( lightbox.is( ':visible' ) ) {
  356. top = parseInt( panel.css( 'top' ) ) - parseInt( wrapper.css( 'top' ) ) - parseInt( wrapper.css( 'padding-top' ) );
  357. left = parseInt( panel.css( 'left' ) ) - parseInt( wrapper.css( 'padding-left' ) );
  358. right = parseInt( panel.css( 'right' ) ) - parseInt( wrapper.css( 'padding-right' ) );
  359. lightbox.css( 'top', ( top < 0 ? 0 : top ) + 'px' );
  360. lightbox.css( ( FLBuilderConfig.isRtl ? 'right' : 'left' ), ( FLBuilderConfig.isRtl ? right : left ) + 'px' );
  361. lightbox.addClass( 'fl-lightbox-prevent-animation' );
  362. body.removeClass( 'fl-builder-content-panel-is-showing' );
  363. FLBuilder.ContentPanel.isShowing = false;
  364. } else {
  365. lightbox.css( {
  366. top : '25px',
  367. left : '25px',
  368. } );
  369. }
  370. } );
  371. FLBuilder._reinitEditorFields();
  372. },
  373. /**
  374. * Closes lightboxes when a panel tab is clicked.
  375. *
  376. * @since 2.0
  377. * @method closeLightboxOnPanelClick
  378. */
  379. closeLightboxOnPanelClick: function() {
  380. FLBuilder._triggerSettingsSave( false, true );
  381. },
  382. /**
  383. * Unpins if pinned when the window is resized down to a
  384. * small device size.
  385. *
  386. * @since 2.0
  387. * @method windowResize
  388. */
  389. windowResize: function()
  390. {
  391. this.pinOrUnpin();
  392. },
  393. /**
  394. * Callback for when content panel resize starts.
  395. *
  396. * @since 2.0
  397. * @method resizeStart
  398. */
  399. resizeStart: function()
  400. {
  401. $( 'body' ).addClass( 'fl-builder-resizable-is-resizing' );
  402. FLBuilder._destroyOverlayEvents();
  403. FLBuilder._removeAllOverlays();
  404. },
  405. /**
  406. * Callback for when content panel resizes.
  407. *
  408. * @since 2.0
  409. * @method resize
  410. */
  411. resize: function()
  412. {
  413. var body = $( 'body' ),
  414. preview = $( '.fl-responsive-preview, .fl-responsive-preview-mask' ),
  415. panel = $( '.fl-builder--content-library-panel' ),
  416. width = panel.outerWidth();
  417. if ( panel.hasClass( 'fl-builder-ui-pinned-left' ) ) {
  418. body.css( 'margin-left', width + 'px' );
  419. preview.css( 'margin-left', width + 'px' );
  420. } else if ( panel.hasClass( 'fl-builder-ui-pinned-right' ) ) {
  421. body.css( 'margin-right', width + 'px' );
  422. preview.css( 'margin-right', width + 'px' );
  423. }
  424. },
  425. /**
  426. * Callback for when content panel resize stops.
  427. *
  428. * @since 2.0
  429. * @method resizeStop
  430. */
  431. resizeStop: function()
  432. {
  433. $( 'body' ).removeClass( 'fl-builder-resizable-is-resizing' );
  434. FLBuilder._bindOverlayEvents();
  435. FLBuilder._resizeLayout();
  436. this.savePosition();
  437. },
  438. /**
  439. * Callback for when content panel drag starts.
  440. *
  441. * @since 2.0
  442. * @method dragStart
  443. */
  444. dragStart: function( e, ui )
  445. {
  446. var body = $( 'body' ),
  447. target = $( e.target ),
  448. actions = $( '.fl-builder-bar-actions' );
  449. if ( ! $( '.fl-lightbox-resizable:visible' ).length ) {
  450. actions.addClass( 'fl-builder-content-panel-pin-zone' );
  451. }
  452. body.addClass( 'fl-builder-draggable-is-dragging' );
  453. body.append( '<div class="fl-builder-ui-pin-zone fl-builder-ui-pin-zone-left"></div>' );
  454. body.append( '<div class="fl-builder-ui-pin-zone fl-builder-ui-pin-zone-right"></div>' );
  455. FLBuilder._destroyOverlayEvents();
  456. },
  457. /**
  458. * Callback for when content panel is dragged.
  459. *
  460. * @since 2.0
  461. * @method drag
  462. */
  463. drag: function( e, ui )
  464. {
  465. var body = $( 'body' ),
  466. preview = $( '.fl-responsive-preview' ),
  467. win = $( window ),
  468. winWidth = preview.length ? preview.width() : win.width(),
  469. scrollTop = win.scrollTop(),
  470. panel = $( '.fl-builder--content-library-panel' ),
  471. offsetTop = panel.offset().top,
  472. actions = $( '.fl-builder-bar-actions' ),
  473. target = $( e.target );
  474. if ( target.hasClass( 'fl-builder--content-library-panel' ) ) {
  475. if ( e.clientX < winWidth - 75 && offsetTop - scrollTop < 46 ) {
  476. actions.addClass( 'fl-builder-content-panel-pin-zone-hover' );
  477. } else {
  478. actions.removeClass( 'fl-builder-content-panel-pin-zone-hover' );
  479. }
  480. }
  481. if ( target.hasClass( 'fl-builder-ui-pinned' ) ) {
  482. this.unpinPanel();
  483. } else if ( e.clientX < 75 ) {
  484. body.addClass( 'fl-builder-ui-show-pin-zone fl-builder-ui-show-pin-zone-left' );
  485. } else if ( e.clientX > winWidth - 75 ) {
  486. body.addClass( 'fl-builder-ui-show-pin-zone fl-builder-ui-show-pin-zone-right' );
  487. } else {
  488. body.removeClass( 'fl-builder-ui-show-pin-zone' );
  489. body.removeClass( 'fl-builder-ui-show-pin-zone-left' );
  490. body.removeClass( 'fl-builder-ui-show-pin-zone-right' );
  491. }
  492. },
  493. /**
  494. * Callback for when content panel drag stops.
  495. *
  496. * @since 2.0
  497. * @method dragStop
  498. */
  499. dragStop: function( e, ui )
  500. {
  501. var win = $( window ),
  502. body = $( 'body' ),
  503. actions = $( '.fl-builder-bar-actions' ),
  504. zones = $( '.fl-builder-ui-pin-zone' ),
  505. panel = $( '.fl-builder--content-library-panel' ),
  506. lightbox = $( '.fl-lightbox-resizable:visible' ),
  507. target = $( e.target );
  508. body.removeClass( 'fl-builder-draggable-is-dragging' );
  509. actions.removeClass( 'fl-builder-content-panel-pin-zone' );
  510. actions.removeClass( 'fl-builder-content-panel-pin-zone-hover' );
  511. zones.remove();
  512. if ( lightbox.length && parseInt( lightbox.css( 'top' ) ) < 0 ) {
  513. lightbox.css( 'top', '0' );
  514. }
  515. if ( body.hasClass( 'fl-builder-ui-show-pin-zone' ) ) {
  516. if ( body.hasClass( 'fl-builder-ui-show-pin-zone-left' ) ) {
  517. this.pin( 'left', true );
  518. } else {
  519. this.pin( 'right', true );
  520. }
  521. body.removeClass( 'fl-builder-ui-show-pin-zone' );
  522. body.removeClass( 'fl-builder-ui-show-pin-zone-left' );
  523. body.removeClass( 'fl-builder-ui-show-pin-zone-right' );
  524. } else if( panel.find( '.fl-lightbox' ).length ) {
  525. this.unpin( true );
  526. if ( 'module' === FLBuilderConfig.userTemplateType || FLBuilderConfig.simpleUi ) {
  527. panel.hide();
  528. }
  529. } else {
  530. panel.attr( 'style', '' );
  531. this.savePosition();
  532. }
  533. FLBuilder._bindOverlayEvents();
  534. },
  535. /**
  536. * Disables draggable and resizable.
  537. *
  538. * @since 2.0
  539. * @method disableDragAndResize
  540. */
  541. disableDragAndResize: function() {
  542. var panel = $( '.fl-builder--content-library-panel' ),
  543. lightboxes = $( '.fl-lightbox-resizable' );
  544. panel.draggable( 'disable' );
  545. panel.resizable( 'disable' );
  546. lightboxes.draggable( 'disable' );
  547. lightboxes.resizable( 'disable' );
  548. },
  549. /**
  550. * Enables draggable and resizable.
  551. *
  552. * @since 2.0
  553. * @method enableDragAndResize
  554. */
  555. enableDragAndResize: function() {
  556. var panel = $( '.fl-builder--content-library-panel' ),
  557. lightboxes = $( '.fl-lightbox-resizable:not(.fl-lightbox-width-full)' );
  558. panel.draggable( 'enable' );
  559. panel.resizable( 'enable' );
  560. if ( ! this.isPinned() ) {
  561. lightboxes.draggable( 'enable' );
  562. lightboxes.resizable( 'enable' );
  563. }
  564. },
  565. /**
  566. * Save the position data for the pinned UI.
  567. *
  568. * @since 2.0
  569. * @method savePosition
  570. */
  571. savePosition: function()
  572. {
  573. var panel = $( '.fl-builder--content-library-panel' ),
  574. lightbox = $( '.fl-lightbox-resizable:visible' ),
  575. data = {
  576. pinned: {
  577. width : panel.outerWidth(),
  578. position : null
  579. }
  580. };
  581. if ( panel.hasClass( 'fl-builder-ui-pinned-left' ) ) {
  582. data.pinned.position = 'left';
  583. } else if ( panel.hasClass( 'fl-builder-ui-pinned-right' ) ) {
  584. data.pinned.position = 'right';
  585. } else if ( lightbox.length ) {
  586. data.lightbox = {
  587. width : lightbox.width(),
  588. height : lightbox.height(),
  589. top : parseInt( lightbox.css( 'top' ) ) < 0 ? '0px' : lightbox.css( 'top' ),
  590. left : lightbox.css( 'left' )
  591. };
  592. }
  593. FLBuilderConfig.userSettings.pinned = data.pinned;
  594. if ( data.lightbox ) {
  595. FLBuilderConfig.userSettings.lightbox = data.lightbox;
  596. }
  597. FLBuilder.ajax( {
  598. action : 'save_pinned_ui_position',
  599. data : data
  600. } );
  601. },
  602. /**
  603. * Restores the pinned UI position for the current user.
  604. *
  605. * @since 2.0
  606. * @method restorePosition
  607. */
  608. restorePosition: function()
  609. {
  610. var panel = $( '.fl-builder--content-library-panel' ),
  611. settings = FLBuilderConfig.userSettings.pinned;
  612. if ( settings && settings.position ) {
  613. panel.css( 'width', settings.width + 'px' );
  614. this.pin( settings.position, false );
  615. panel.css( 'width', settings.width + 'px' );
  616. }
  617. },
  618. };
  619. $( function() {
  620. PinnedUI.init();
  621. } );
  622. } )( jQuery );