fl-theme-builder-frontend-edit.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. ( function( $ ) {
  2. /**
  3. * Handles frontend editing UI logic for the builder.
  4. *
  5. * @class FLThemeBuilderFrontendEdit
  6. * @since 1.0
  7. */
  8. var FLThemeBuilderFrontendEdit = {
  9. /**
  10. * Initialize.
  11. *
  12. * @since 1.0
  13. * @access private
  14. * @method _init
  15. */
  16. _init: function()
  17. {
  18. this._bind();
  19. this._maybeShowOverrideWarning();
  20. },
  21. /**
  22. * Bind events.
  23. *
  24. * @since 1.0
  25. * @access private
  26. * @method _bind
  27. */
  28. _bind: function()
  29. {
  30. $( '.fl-builder-content:not(.fl-builder-content-primary)' ).on( 'mouseenter', this._partMouseenter );
  31. $( '.fl-builder-content:not(.fl-builder-content-primary)' ).on( 'mouseleave', this._partMouseleave );
  32. FLBuilder.addHook( 'showThemerOverrideSettings', this._showOverrideSettingsClicked.bind( this ) );
  33. },
  34. /**
  35. * Shows a confirmation dialog warning the user if they are about
  36. * to override a theme layout with a standard builder layout.
  37. *
  38. * @since 1.0
  39. * @access private
  40. * @method _maybeShowOverrideWarning
  41. */
  42. _maybeShowOverrideWarning: function()
  43. {
  44. var enabled = FLBuilderConfig.builderEnabled,
  45. postType = FLBuilderConfig.postType,
  46. layouts = FLThemeBuilderConfig.layouts,
  47. strings = FLThemeBuilderConfig.strings,
  48. editMode = FLThemeBuilderConfig.editMode;
  49. if ( ! enabled && 'fl-theme-layout' != postType && 'undefined' != typeof layouts.singular && ! editMode ) {
  50. this._showOverrideSettings( true );
  51. }
  52. },
  53. /**
  54. * @since 1.4
  55. * @access private
  56. * @method _showOverrideSettingsClicked
  57. */
  58. _showOverrideSettingsClicked: function()
  59. {
  60. this._showOverrideSettings();
  61. },
  62. /**
  63. * @since 1.4
  64. * @access private
  65. * @method _showOverrideSettings
  66. */
  67. _showOverrideSettings: function( goBack )
  68. {
  69. var strings = FLThemeBuilderConfig.strings;
  70. var lightbox = new FLLightbox( {
  71. className: 'fl-builder-confirm-lightbox fl-builder-alert-lightbox',
  72. destroyOnClose: true
  73. } );
  74. var html = '<div class="fl-lightbox-message">' + strings.overrideWarning + '</div>';
  75. html += '<div class="fl-lightbox-footer">';
  76. html += '<span class="fl-builder-override-layout fl-builder-button fl-builder-button-large">' + strings.overrideWarningLayout + '</span>';
  77. html += '<span class="fl-builder-override-content fl-builder-button fl-builder-button-large">' + strings.overrideWarningContent + '</span>';
  78. html += '<span class="fl-builder-override-cancel fl-builder-button fl-builder-button-large fl-builder-button-primary">' + strings.overrideWarningCancel + '</span>';
  79. html += '</div>';
  80. lightbox.open( html );
  81. lightbox._node.find( '.fl-builder-override-layout' ).on( 'click', function() {
  82. FLBuilder.showAjaxLoader();
  83. FLLightbox.closeParent( this );
  84. FLBuilder.ajax( {
  85. action: 'disable_content_building_for_post'
  86. } );
  87. window.parent.location.reload();
  88. } );
  89. lightbox._node.find( '.fl-builder-override-content' ).on( 'click', function() {
  90. FLBuilder.showAjaxLoader();
  91. FLLightbox.closeParent( this );
  92. FLBuilder.ajax( {
  93. action: 'enable_content_building_for_post'
  94. } );
  95. window.parent.location.reload();
  96. } );
  97. lightbox._node.find( '.fl-builder-override-cancel' ).on( 'click', function() {
  98. FLLightbox.closeParent( this );
  99. if ( goBack ) {
  100. FLBuilder.showAjaxLoader();
  101. window.parent.location.href = FLThemeBuilderConfig.adminEditURL;
  102. }
  103. } );
  104. FLBuilder.MainMenu.hide();
  105. },
  106. /**
  107. * Shows the edit overlay when the mouse enters a
  108. * header, footer or part.
  109. *
  110. * @since 1.0
  111. * @access private
  112. * @method _partMouseenter
  113. */
  114. _partMouseenter: function()
  115. {
  116. // TODO
  117. },
  118. /**
  119. * Removes the edit overlay when the mouse leaves a
  120. * header, footer or part.
  121. *
  122. * @since 1.0
  123. * @access private
  124. * @method _partMouseleave
  125. */
  126. _partMouseleave: function()
  127. {
  128. // TODO
  129. }
  130. };
  131. // Initialize
  132. $( function() { FLThemeBuilderFrontendEdit._init(); } );
  133. } )( jQuery );