vc.js 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. window.VcSliderRevolution = vc.shortcode_view.extend({
  2. initialize: function() {
  3. return window.VcSliderRevolution.__super__.initialize.call(this);
  4. },
  5. render: function () {
  6. rs_cur_vc_obj = this;
  7. var params = this.model.get('params');
  8. if(vc.add_element_block_view.$el.is(':visible')){ //hack to check if we just loaded the page or if we rendered it because of adding a new Slider element
  9. rs_vc_show_overlay(params);
  10. }
  11. return window.VcSliderRevolution.__super__.render.call(this);
  12. },
  13. editElement: function() {
  14. rs_cur_vc_obj = this;
  15. var params = this.model.get('params');
  16. rs_vc_show_overlay(params);
  17. return false;
  18. }
  19. });
  20. if(typeof(window.InlineShortcodeView) !== 'undefined'){
  21. var rs_show_frontend_overlay = false;
  22. jQuery(window).on('vc_build',function(){
  23. vc.add_element_block_view.$el.find('[data-element="rev_slider"]').click(function(){ rs_show_frontend_overlay = true; });
  24. });
  25. window.InlineShortcodeView_rev_slider = window.InlineShortcodeView.extend({
  26. render: function() {
  27. rs_cur_vc_obj = this;
  28. var params = this.model.get('params');
  29. if(rs_show_frontend_overlay){
  30. rs_vc_show_overlay(params);
  31. }
  32. window.InlineShortcodeView_rev_slider.__super__.render.call(this);
  33. return this;
  34. },
  35. update: function(model) {
  36. rs_show_frontend_overlay = false;
  37. // same function as backend changedShortcodeParams
  38. window.InlineShortcodeView_rev_slider.__super__.update.call(this,model);
  39. return this;
  40. },
  41. edit: function( e ) {
  42. rs_cur_vc_obj = this;
  43. var params = this.model.get('params');
  44. rs_vc_show_overlay(params);
  45. return false;
  46. }
  47. });
  48. }
  49. function rs_vc_show_overlay(params){
  50. if ( rs_cur_vc_obj !== false && rs_cur_vc_obj.model.get('cloned') === true){
  51. //set cloned to false, so that the edit button will work. Then return as this is at the process where the element gets cloned
  52. rs_cur_vc_obj.model.save('cloned', false);
  53. return; //do not show edit if we cloned
  54. }
  55. revslider_tiny_reset_all();
  56. revslider_is_vc = true; //set for the saving that we are visual composer
  57. jQuery('.wpb-element-edit-modal').hide(); //hide the normal VC window and use own (old vc version)
  58. jQuery('#vc_properties-panel').hide(); //hide the normal VC window and use own (new vc version)
  59. var revslider_vc_variables = {};
  60. revslider_vc_variables['alias'] = (typeof(params.alias) !== 'undefined') ? params.alias : '';
  61. revslider_vc_variables['order'] = (typeof(params.order) !== 'undefined') ? params.order : ''; //.replace(/\'/g, '"')
  62. jQuery('#revslider-tiny-dialog-step-1').show();
  63. jQuery('#revslider-tiny-dialog-step-1-5').hide();
  64. jQuery('#revslider-tiny-mce-dialog').dialog({
  65. id : 'revslider-tiny-mce-dialog',
  66. width : 900,
  67. height : 600,
  68. resizable: false
  69. });
  70. if(revslider_vc_variables['alias'] !== ''){ //only slider with alias
  71. jQuery('select[name="revslider-existing-slider"] option').each(function(){
  72. if(jQuery(this).val() == revslider_vc_variables['alias']){
  73. jQuery(this).attr('selected', true);
  74. var slid = jQuery(this).data('sliderid');
  75. jQuery('#slider_list_item_'+slid).addClass('selected');
  76. jQuery('#revslider-existing-slider option:selected').change();
  77. }
  78. });
  79. if(revslider_vc_variables['order'] != ''){
  80. jQuery('#revslider-tiny-dialog-step-1').hide();
  81. jQuery('#revslider-tiny-dialog-step-1-5').show();
  82. var rs_raw_construct = wp.template( "rs-modify-slide-wrap" );
  83. var sel = jQuery('#revslider-existing-slider option:selected');
  84. jQuery('.rs-mod-slides-wrapper').html(''); //reset HTML
  85. //check if array or string
  86. if(!Array.isArray(revslider_vc_variables['order'])){
  87. revslider_vc_variables['order'] = revslider_vc_variables['order'].split(',');
  88. }
  89. if(typeof(rev_sliders_info) !== 'undefined'){
  90. for(var key in rev_sliders_info){
  91. if(key == sel.data('sliderid')){
  92. var my_entry = new Object();
  93. my_entry = jQuery.extend(true,{},my_entry, rev_sliders_info[key]);
  94. var my_entries = [];
  95. var act_slide = -1;
  96. for(var okey in revslider_vc_variables['order']){
  97. for(var sl in my_entry){
  98. if(my_entry[sl]['slider_type'] == 'hero'){
  99. if(revslider_vc_variables['order'][okey] == my_entry[sl]['id']){
  100. act_slide = my_entry[sl]['id'];
  101. }
  102. }else{
  103. break;
  104. }
  105. }
  106. }
  107. for(var okey in revslider_vc_variables['order']){
  108. for(var sl in my_entry){ //add all found slides, empty the old ones first
  109. if(my_entry[sl]['slider_type'] == 'hero'){
  110. my_entry[sl]['active_slide'] = act_slide;
  111. }
  112. if(revslider_vc_variables['order'][okey] == my_entry[sl]['id']){
  113. my_entry[sl]['mstate'] = 'published';
  114. my_entry[sl]['state'] = 'published';
  115. my_entries.push(my_entry[sl]);
  116. break;
  117. }
  118. }
  119. }
  120. for(var slm in my_entry){
  121. if(my_entry[slm]['mstate'] == undefined){
  122. my_entry[slm]['state'] = 'unpublished';
  123. if(my_entry[slm]['slider_type'] == 'hero'){
  124. my_entry[sl]['active_slide'] = act_slide;
  125. }
  126. my_entries.push(my_entry[slm]);
  127. }
  128. }
  129. for(var ekey in my_entries){
  130. var content = rs_raw_construct(my_entries[ekey]);
  131. jQuery('.rs-mod-slides-wrapper').append(content);
  132. }
  133. }
  134. }
  135. }
  136. }
  137. }else{ }
  138. }