fl-builder-tour.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. (function( $ ) {
  2. /**
  3. * Logic for the builder's help tour.
  4. *
  5. * @class FLBuilderTour
  6. * @since 1.4.9
  7. */
  8. FLBuilderTour = {
  9. /**
  10. * A reference to the Bootstrap Tour object.
  11. *
  12. * @since 1.4.9
  13. * @access private
  14. * @property {Tour} _tour
  15. */
  16. _tour: null,
  17. /**
  18. * Starts the tour or restarts it if it
  19. * has already run.
  20. *
  21. * @since 1.4.9
  22. * @method start
  23. */
  24. start: function()
  25. {
  26. if ( ! FLBuilderTour._tour ) {
  27. FLBuilderTour._tour = new Tour( FLBuilderTour._config() );
  28. FLBuilderTour._tour.init();
  29. }
  30. else {
  31. FLBuilderTour._tour.restart();
  32. }
  33. // Save existing settings first if any exist. Don't proceed if it fails.
  34. if ( ! FLBuilder._triggerSettingsSave( false, true ) ) {
  35. return;
  36. }
  37. FLBuilderTour._tour.start();
  38. },
  39. /**
  40. * Returns a config object for the tour.
  41. *
  42. * @since 1.4.9
  43. * @access private
  44. * @method _config
  45. * @return {Object}
  46. */
  47. _config: function()
  48. {
  49. var config = {
  50. storage : false,
  51. onStart : FLBuilderTour._onStart,
  52. onPrev : FLBuilderTour._onPrev,
  53. onNext : FLBuilderTour._onNext,
  54. onEnd : FLBuilderTour._onEnd,
  55. template : '<div class="popover" role="tooltip"> <i class="fas fa-times" data-role="end"></i> <div class="arrow"></div> <h3 class="popover-title"></h3> <div class="popover-content"></div> <div class="popover-navigation clearfix"> <button class="fl-builder-button fl-builder-button-primary fl-builder-tour-next" data-role="next">' + FLBuilderStrings.tourNext + '</button> </div> </div>',
  56. steps : [
  57. {
  58. animation : false,
  59. element : '.fl-builder--content-library-panel',
  60. placement : 'left',
  61. title : FLBuilderStrings.tourTemplatesTitle,
  62. content : FLBuilderStrings.tourTemplates,
  63. onShow : function() {
  64. FLBuilder.ContentPanel.show('templates');
  65. },
  66. },
  67. {
  68. animation : false,
  69. element : '.fl-builder--content-library-panel',
  70. placement : 'left',
  71. title : FLBuilderStrings.tourAddRowsTitle,
  72. content : FLBuilderStrings.tourAddRows,
  73. onShow : function() {
  74. FLBuilder.ContentPanel.show('rows');
  75. }
  76. },
  77. {
  78. animation : false,
  79. element : '.fl-builder--content-library-panel',
  80. placement : 'left',
  81. title : FLBuilderStrings.tourAddContentTitle,
  82. content : FLBuilderStrings.tourAddContent,
  83. onShow : function() {
  84. FLBuilder.ContentPanel.show('modules');
  85. }
  86. },
  87. {
  88. animation : false,
  89. element : '.fl-row:first-of-type',
  90. placement : 'top',
  91. title : FLBuilderStrings.tourEditContentTitle,
  92. content : FLBuilderStrings.tourEditContent,
  93. onShow : function() {
  94. FLBuilderTour._dimSection( '.fl-builder-bar' );
  95. FLBuilder._closePanel();
  96. $( '.fl-row' ).eq( 0 ).trigger( 'mouseenter' );
  97. $( '.fl-module' ).eq( 0 ).trigger( 'mouseenter' );
  98. }
  99. },
  100. {
  101. animation : false,
  102. element : '.fl-row:first-of-type .fl-module-overlay .fl-block-overlay-actions',
  103. placement : 'top',
  104. title : FLBuilderStrings.tourEditContentTitle,
  105. content : FLBuilderStrings.tourEditContent2,
  106. onShow : function() {
  107. FLBuilderTour._dimSection( '.fl-builder-bar' );
  108. FLBuilder._closePanel();
  109. $( '.fl-row' ).eq( 0 ).trigger( 'mouseenter' );
  110. $( '.fl-module' ).eq( 0 ).trigger( 'mouseenter' );
  111. }
  112. },
  113. {
  114. animation : false,
  115. element : '.fl-builder-content-panel-button',
  116. placement : 'bottom',
  117. title : FLBuilderStrings.tourAddContentButtonTitle,
  118. content : FLBuilderStrings.tourAddContentButton,
  119. onShow : function() {
  120. FLBuilderTour._dimSection( 'body' );
  121. $( '.fl-row' ).eq( 0 ).trigger( 'mouseleave' );
  122. $( '.fl-module' ).eq( 0 ).trigger( 'mouseleave' );
  123. }
  124. },
  125. {
  126. animation : false,
  127. element : '.fl-builder-templates-button',
  128. placement : 'bottom',
  129. title : FLBuilderStrings.tourTemplatesButtonTitle,
  130. content : FLBuilderStrings.tourTemplatesButton,
  131. onShow : function() {
  132. FLBuilderTour._dimSection( 'body' );
  133. }
  134. },
  135. {
  136. animation : false,
  137. element : '.fl-builder-tools-button',
  138. placement : 'bottom',
  139. title : FLBuilderStrings.tourToolsButtonTitle,
  140. content : FLBuilderStrings.tourToolsButton,
  141. onShow : function() {
  142. FLBuilderTour._dimSection( 'body' );
  143. }
  144. },
  145. {
  146. animation : false,
  147. element : '.fl-builder-done-button',
  148. placement : 'bottom',
  149. title : FLBuilderStrings.tourDoneButtonTitle,
  150. content : FLBuilderStrings.tourDoneButton,
  151. onShow : function() {
  152. FLBuilderTour._dimSection( 'body' );
  153. }
  154. },
  155. {
  156. animation : false,
  157. orphan : true,
  158. backdrop : true,
  159. title : FLBuilderStrings.tourFinishedTitle,
  160. content : FLBuilderStrings.tourFinished,
  161. template : '<div class="popover" role="tooltip"> <div class="arrow"></div> <i class="fas fa-times" data-role="end"></i> <h3 class="popover-title"></h3> <div class="popover-content"></div> <div class="popover-navigation clearfix"> <button class="fl-builder-button fl-builder-button-primary fl-builder-tour-next" data-role="end">' + FLBuilderStrings.tourEnd + '</button> </div> </div>',
  162. }
  163. ]
  164. };
  165. // Remove the first step if no templates.
  166. if( FLBuilderConfig.lite ) {
  167. config.steps.shift();
  168. }
  169. else if ( 'disabled' == FLBuilderConfig.enabledTemplates ) {
  170. config.steps.shift();
  171. }
  172. else if ( 'fl-builder-template' == FLBuilderConfig.postType ) {
  173. config.steps.shift();
  174. }
  175. return config;
  176. },
  177. /**
  178. * Callback for when the tour starts.
  179. *
  180. * @since 1.4.9
  181. * @access private
  182. * @method _onStart
  183. */
  184. _onStart: function()
  185. {
  186. var body = $( 'body' );
  187. body.scrollTop(0);
  188. body.append( '<div class="fl-builder-tour-mask"></div>' );
  189. if ( 0 === $( '.fl-row' ).length && 'module' != FLBuilderConfig.userTemplateType ) {
  190. $( '.fl-builder-content' ).append( '<div class="fl-builder-tour-demo-content fl-row fl-row-fixed-width fl-row-bg-none"> <div class="fl-row-content-wrap"> <div class="fl-row-content fl-row-fixed-width fl-node-content"> <div class="fl-col-group"> <div class="fl-col" style="width:100%"> <div class="fl-col-content fl-node-content"> <div class="fl-module fl-module-rich-text" data-type="rich-text" data-name="Text Editor"> <div class="fl-module-content fl-node-content"> <div class="fl-rich-text"> <p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pellentesque ut lorem non cursus. Sed mauris nunc, porttitor iaculis lorem a, sollicitudin lacinia sapien. Proin euismod orci lacus, et sollicitudin leo posuere ac. In hac habitasse platea dictumst. Maecenas elit magna, consequat in turpis suscipit, ultrices rhoncus arcu. Phasellus finibus sapien nec elit tempus venenatis. Maecenas tincidunt sapien non libero maximus, in aliquam felis tincidunt. Mauris mollis ultricies facilisis. Duis condimentum dignissim tortor sit amet facilisis. Aenean gravida lacus eu risus molestie egestas. Donec ut dolor dictum, fringilla metus malesuada, viverra nunc. Maecenas ut purus ac justo aliquet lacinia. Cras vestibulum elementum tincidunt. Maecenas mattis tortor neque, consectetur dignissim neque tempor nec.</p></div> </div> </div> </div> </div> </div> </div> </div> </div>' );
  191. FLBuilder._setupEmptyLayout();
  192. FLBuilder._highlightEmptyCols();
  193. }
  194. },
  195. /**
  196. * Callback for when the tour is navigated
  197. * to the previous step.
  198. *
  199. * @since 1.4.9
  200. * @access private
  201. * @method _onPrev
  202. */
  203. _onPrev: function()
  204. {
  205. $( '.fl-builder-tour-dimmed' ).remove();
  206. },
  207. /**
  208. * Callback for when the tour is navigated
  209. * to the next step.
  210. *
  211. * @since 1.4.9
  212. * @access private
  213. * @method _onNext
  214. */
  215. _onNext: function()
  216. {
  217. $( '.fl-builder-tour-dimmed' ).remove();
  218. },
  219. /**
  220. * Callback for when the tour ends.
  221. *
  222. * @since 1.4.9
  223. * @access private
  224. * @method _onEnd
  225. */
  226. _onEnd: function()
  227. {
  228. $( 'body' ).off( 'fl-builder.template-selector-loaded' );
  229. $( '.fl-builder-tour-mask' ).remove();
  230. $( '.fl-builder-tour-dimmed' ).remove();
  231. $( '.fl-builder-tour-demo-content' ).remove();
  232. FLBuilder._setupEmptyLayout();
  233. FLBuilder._highlightEmptyCols();
  234. FLBuilder._showPanel();
  235. FLBuilder._initTemplateSelector();
  236. },
  237. /**
  238. * Dims a section of the page.
  239. *
  240. * @since 1.4.9
  241. * @access private
  242. * @method _dimSection
  243. * @param {String} selector A CSS selector for the section to dim.
  244. */
  245. _dimSection: function( selector )
  246. {
  247. $( selector ).find( '.fl-builder-tour-dimmed' ).remove();
  248. $( selector ).append( '<div class="fl-builder-tour-dimmed"></div>' );
  249. }
  250. };
  251. })( jQuery );