templates-preview.js 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* =========================================================
  2. * templates-preview.js v1.0.0
  3. * =========================================================
  4. * Copyright 2015 WPBakery
  5. *
  6. * WPBakery Page Builder template preview
  7. * ========================================================= */
  8. /* global vc */
  9. (function ( $ ) {
  10. 'use strict';
  11. if ( window.vc && vc.visualComposerView ) {
  12. // unset Draggable
  13. window.vc.visualComposerView.prototype.setDraggable = function () {
  14. };
  15. // unset Sortable
  16. window.vc.visualComposerView.prototype.setSortable = function () {
  17. };
  18. // unset Sortable
  19. window.vc.visualComposerView.prototype.setSorting = function () {
  20. };
  21. // unset save
  22. window.vc.visualComposerView.prototype.save = function () {
  23. };
  24. // unset controls checks for scroll
  25. window.vc.visualComposerView.prototype.navOnScroll = function () {
  26. };
  27. window.vc.visualComposerView.prototype.addElement = function ( e ) {
  28. if ( e && e.preventDefault ) {
  29. e.preventDefault();
  30. }
  31. };
  32. window.vc.visualComposerView.prototype.addTextBlock = function ( e ) {
  33. if ( e && e.preventDefault ) {
  34. e.preventDefault();
  35. }
  36. };
  37. window.vc.shortcode_view.prototype.events = {};
  38. window.vc.shortcode_view.prototype.editElement = function ( e ) {
  39. if ( e && e.preventDefault ) {
  40. e.preventDefault();
  41. }
  42. };
  43. window.vc.shortcode_view.prototype.clone = function ( e ) {
  44. if ( e && e.preventDefault ) {
  45. e.preventDefault();
  46. }
  47. };
  48. window.vc.shortcode_view.prototype.addElement = function ( e ) {
  49. if ( e && e.preventDefault ) {
  50. e.preventDefault();
  51. }
  52. };
  53. window.vc.shortcode_view.prototype.deleteShortcode = function ( e ) {
  54. if ( e && e.preventDefault ) {
  55. e.preventDefault();
  56. }
  57. };
  58. window.vc.shortcode_view.prototype.setEmpty = function () {
  59. };
  60. window.vc.visualComposerView.prototype.events = {};
  61. //vc.shortcode_view.prototype.designHelpersSelector = '[data-js-handler-design-helper]';
  62. // update backend getView
  63. window.vc.visualComposerView.prototype.getView = function ( model ) {
  64. var view;
  65. if ( _.isObject( vc.map[ model.get( 'shortcode' ) ] ) && _.isString( vc.map[ model.get( 'shortcode' ) ].js_view ) && vc.map[ model.get( 'shortcode' ) ].js_view.length && !_.isUndefined(
  66. window[ window.vc.map[ model.get( 'shortcode' ) ].js_view ] ) ) {
  67. try {
  68. var viewConstructor = window[ window.vc.map[ model.get( 'shortcode' ) ].js_view ];
  69. viewConstructor.prototype.events = {};
  70. viewConstructor.prototype.setSortable = function () {
  71. };
  72. viewConstructor.prototype.setSorting = function () {
  73. };
  74. viewConstructor.prototype.setDropable = function () {
  75. };
  76. viewConstructor.prototype.editElement = function ( e ) {
  77. if ( e && e.preventDefault ) {
  78. e.preventDefault();
  79. }
  80. };
  81. viewConstructor.prototype.clone = function ( e ) {
  82. if ( e && e.preventDefault ) {
  83. e.preventDefault();
  84. }
  85. };
  86. viewConstructor.prototype.addElement = function ( e ) {
  87. if ( e && e.preventDefault ) {
  88. e.preventDefault();
  89. }
  90. };
  91. viewConstructor.prototype.deleteShortcode = function ( e ) {
  92. if ( e && e.preventDefault ) {
  93. e.preventDefault();
  94. }
  95. };
  96. viewConstructor.prototype.setEmpty = function () {
  97. };
  98. viewConstructor.prototype.events = {};
  99. // viewConstructor.prototype.designHelpersSelector = '[data-js-handler-design-helper]';
  100. view = new viewConstructor( { model: model } );
  101. } catch ( err ) {
  102. if ( window.console && window.console.warn ) {
  103. window.console.warn( 'template preview getView error', err );
  104. }
  105. }
  106. } else {
  107. window.vc.shortcode_view.prototype.events = {};
  108. view = new vc.shortcode_view( { model: model } );
  109. }
  110. model.set( { view: view } );
  111. return view;
  112. };
  113. }
  114. if ( window.VcGitemView ) {
  115. window.VcGitemView.prototype.setDropable = function () {
  116. };
  117. window.VcGitemView.prototype.setDraggable = function () {
  118. };
  119. window.VcGitemView.prototype.setDraggableC = function () {
  120. };
  121. }
  122. if ( window.vc && window.vc.events ) {
  123. window.vc.events.on( 'shortcodeView:ready', function ( view ) {
  124. if ( window.VcGitemView ) {
  125. view.$el.find( '.vc_control-btn.vc_element-name.vc_element-move .vc_btn-content' ).attr( 'style', 'cursor:pointer !important;' + 'padding-left: 10px !important;' );
  126. view.$el.find( '.vc_control-btn.vc_element-name.vc_element-move .vc_btn-content .vc-c-icon-dragndrop' ).hide();
  127. if ( 'vc_gitem' === view.model.get( 'shortcode' ) ) {
  128. view.$el.find( '.vc_gitem-add-c-col:not(.vc_zone-added)' ).remove();
  129. }
  130. }
  131. if ( view.$el ) {
  132. // remove TTA section append
  133. view.$el.find( '.vc_tta-section-append' ).remove();
  134. // remove old TTA tour append
  135. view.$el.find( '.add_tab_block' ).remove();
  136. view.$el.find( '.tab_controls' ).remove();
  137. // remove single image "add-image" link
  138. view.$el.find( '.column_edit_trigger' ).remove();
  139. }
  140. } );
  141. }
  142. window.vc.visualComposerView.prototype.initializeAccessPolicy = function () {
  143. this.accessPolicy = {
  144. be_editor: true,
  145. fe_editor: false,
  146. classic_editor: false
  147. };
  148. };
  149. window.vc.events.on( 'app.addAll', function () {
  150. if ( parent && parent.vc ) {
  151. parent.vc.templates_panel_view.setTemplatePreviewSize();
  152. }
  153. } );
  154. $( window ).on( 'resize', function () {
  155. parent.vc.templates_panel_view.setTemplatePreviewSize();
  156. } );
  157. })( window.jQuery );