Advertisement
Guest User

Untitled

a guest
Mar 26th, 2015
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.54 KB | None | 0 0
  1. jQuery(document).ready(function($) {
  2.  
  3. var timer = $.timer(function() {
  4.  
  5. modal_ajax.color_box_on_open = function() {
  6.  
  7. modal_ajax.color_box_on_complete = function () {
  8.  
  9. $('.splash_screen_buttons li').on('click', function() {
  10.  
  11. optional.data.button_pressed = 'tab';
  12.  
  13. optional.data.button_value = $(this).attr("id");
  14.  
  15. $("#colorbox").colorbox.close();
  16.  
  17. $("#kiosk").ajaxSubmit(optional);
  18.  
  19. });
  20.  
  21. };
  22.  
  23. $('#colorbox').addClass('full_screen_modal_splash_screen');
  24.  
  25. $('html, body').animate({scrollTop: $("#colorbox").offset({top:15}).top}, 1000);
  26.  
  27.  
  28.  
  29. };
  30.  
  31. modal_ajax.color_box_on_closed = function() {
  32.  
  33. $('#colorbox').removeClass('full_screen_modal_splash_screen');
  34. $('.splash_screen_buttons li').unbind();
  35.  
  36. };
  37.  
  38. modal_ajax.clean_up_yt_embeds = false;
  39.  
  40. modal_ajax.data.button_id = "splash_screen_modal";
  41.  
  42. modal_ajax.data.button_pressed = 'modal';
  43.  
  44. modal_ajax.data.button_value = '';
  45.  
  46. modal_ajax.color_box_width = '100%', modal_ajax.color_box_height = '100%';
  47.  
  48. $.ajax(modal_ajax);
  49.  
  50. });
  51.  
  52. timer.set({ time : 5000, autostart : true });
  53.  
  54. var button_pressed = 'tab';
  55.  
  56. var button_id = '1';
  57.  
  58. $(window).keydown(function(event) {// binds enter key to nothing, because we dont want it submitting the form
  59.  
  60. if (event.keyCode == 13) {
  61.  
  62. event.preventDefault();
  63.  
  64. }
  65.  
  66. });
  67.  
  68. var optional = {
  69.  
  70. url : kiosk_obj.ajaxurl,
  71. type : "POST",
  72. dataType : 'json',
  73. data : {
  74.  
  75. action : "kiosk_controller",
  76.  
  77. },
  78.  
  79. beforeSend : function() {
  80.  
  81. $('#loadingDiv').show();
  82.  
  83. },
  84.  
  85. success : function(data) {
  86.  
  87. $('#loadingDiv').hide();
  88.  
  89. $('.kiosk_outter_wrapper').empty();
  90.  
  91. $('.kiosk_outter_wrapper').html(data.results);
  92.  
  93. re_init();
  94.  
  95. },
  96. };
  97.  
  98. var color_box_width, color_box_height = 'Auto';
  99.  
  100. var modal_ajax = {
  101.  
  102. // Defaults. We need to be able to change parts of the object on the fly;
  103.  
  104. color_box_on_open: function(){},
  105. color_box_on_closed: function(){},
  106. color_box_on_complete: function(){},
  107. color_box_width:'Auto',
  108. color_box_height:'Auto',
  109.  
  110. clean_up_yt_embeds: true,
  111.  
  112. url : kiosk_obj.ajaxurl,
  113.  
  114. type : "POST",
  115.  
  116. dataType : 'json',
  117.  
  118. data : {
  119.  
  120. action : "modal_controller",
  121.  
  122. },
  123.  
  124. success : function(data) {
  125.  
  126. $.colorbox({
  127.  
  128. html : data.results,
  129.  
  130. width:this.color_box_width,
  131. height:this.color_box_height,
  132.  
  133. onComplete : function() {
  134.  
  135. if(modal_ajax.clean_up_yt_embeds) {
  136.  
  137. optimizeYouTubeEmbeds();
  138.  
  139. }
  140.  
  141. modal_ajax.color_box_on_complete();
  142.  
  143. },
  144.  
  145. onOpen : function() {
  146.  
  147. timer.reset();
  148.  
  149. timer.pause();
  150.  
  151. modal_ajax.color_box_on_open();
  152.  
  153. },
  154.  
  155. onClosed : function() {
  156.  
  157. timer.play();
  158.  
  159. modal_ajax.color_box_on_closed();
  160.  
  161. modal_ajax.color_box_on_open = function(){};
  162.  
  163. modal_ajax.color_box_on_closed = function(){};
  164.  
  165. modal_ajax.color_box_on_complete = function(){};
  166.  
  167. modal_ajax.color_box_width='auto';
  168.  
  169. modal_ajax.color_box_height = 'auto';
  170.  
  171. modal_ajax.clean_up_yt_embeds = true;
  172.  
  173. $("ul.exercise_modal_menu li.menu_button").unbind();
  174.  
  175. },
  176.  
  177. onCleanup : function() {
  178.  
  179. },
  180. });
  181.  
  182. },
  183. };
  184.  
  185. function color_box_binds() {// dynamically generated content, need to re-bind every call.
  186.  
  187. $('li.work_out_list.exercise_item').on('click', function(e) {
  188.  
  189. modal_ajax.data.button_id = 'exercise_item_modal';
  190.  
  191. modal_ajax.data.button_pressed = 'modal';
  192.  
  193. modal_ajax.data.button_value = $(this).attr("id");
  194.  
  195. modal_ajax.color_box_width, modal_ajax.color_box_height = 'auto';
  196.  
  197. modal_ajax.color_box_on_open = function() {
  198.  
  199. };
  200.  
  201. modal_ajax.color_box_on_closed = function() {
  202.  
  203. };
  204.  
  205. $.when($.ajax(modal_ajax)).then(function(data, textStatus, jqXHR) {
  206.  
  207. optimizeYouTubeEmbeds();
  208.  
  209. $('#modal_slider').bjqs({
  210. 'height' : 400,
  211. 'width' : 400,
  212. 'showcontrols' : true, // show next and prev controls
  213. 'showmarkers' : false, // Show individual slide markers
  214. 'responsive' : true
  215. });
  216.  
  217. var has_not_killed = true;
  218.  
  219. $("ul.exercise_modal_menu li.menu_button").on('click', function() {
  220.  
  221. $("ul.exercise_modal_menu li.menu_button").each(function() {
  222.  
  223. $(this).removeClass('active');
  224.  
  225. });
  226.  
  227. $(this).addClass('active');
  228.  
  229. // since we want a video to stop playing when the user leaves the tab, we check which tab we're in. If it's the video, we need to reset the
  230. // variable so when the video tab is left, it will effectively kill and "refresh" the video to put it back in its initial state.
  231. // since there's no need to re-"kill" it every time a non-video tab is clicked, we just do it once and then toggle the has_not_killed variable.
  232.  
  233. var toggle_which = $(this).attr('id');
  234.  
  235. if(toggle_which=='video') {
  236.  
  237. has_not_killed = true;
  238.  
  239. }
  240.  
  241. // Since we're using skipsers embed to make youtube video loading faster, which also insists on autoplaying them(so that when user clicks thumbnail
  242. // it will load AND play instead of just load the iframe in.
  243. // we need to strip the autoplay out of the url, since if we don't, after it re-injects the url into the iframe it autoplays it again
  244. // which is behavior we DONT want since the user wont be in the tab.
  245.  
  246. if((toggle_which!='video') && (has_not_killed==true)) {
  247.  
  248. has_not_killed = false;
  249.  
  250. var snah = $(".exercise_modal_video:eq(0) iframe");
  251.  
  252. var url = $(snah).attr("src");
  253.  
  254. if (typeof url!='undefined') {
  255.  
  256. var url = url.replace('?autoplay=1', '?autoplay=0');
  257.  
  258. }
  259.  
  260. $(snah).attr("src","");
  261.  
  262. $(snah).attr("src", url);
  263.  
  264. }
  265.  
  266. $('.exercise_modal_media_wrapper').children('#media_box').each(function() {
  267.  
  268. $(this).removeClass('show');
  269.  
  270. $(this).addClass("hide");
  271.  
  272. });
  273.  
  274. $('.exercise_modal_' + toggle_which).removeClass('hide');
  275.  
  276. $('.exercise_modal_' + toggle_which).fadeIn();
  277.  
  278. });
  279.  
  280. });
  281.  
  282. });
  283.  
  284. $(".exericse_full_view_images").colorbox({
  285. rel : 'exericse_full_view_images',
  286. transition : "none",
  287. width : "75%",
  288. height : "75%",
  289. onOpen : function() {
  290.  
  291. $("#colorbox").addClass("exercise_full_view_images_modal");
  292.  
  293. },
  294.  
  295. onClosed : function() {
  296.  
  297. $("#colorbox").removeClass("exercise_full_view_images_modal");
  298.  
  299. },
  300. });
  301.  
  302. }
  303.  
  304. function header_modal_binds() {//Only need to bind once, since this portion is never re-loaded.
  305.  
  306. $('.header button').on('click', function(e) {
  307.  
  308. modal_ajax.data.button_id = $(this).attr("id");
  309.  
  310. modal_ajax.data.button_pressed = $(this).attr("name");
  311.  
  312. modal_ajax.data.button_value = $(this).attr("value");
  313.  
  314. if (modal_ajax.data.button_id == 'feed_back_form') {
  315.  
  316. $.colorbox({
  317. inline : true,
  318. href : "#gf_contact_form",
  319. height: 'auto',
  320. width: 'auto',
  321. onOpen : function() {
  322.  
  323. timer.reset();
  324.  
  325. timer.pause();
  326.  
  327. $("#colorbox").addClass("contact_form_modal");
  328.  
  329. },
  330.  
  331. onClosed : function() {
  332.  
  333. $("#colorbox").removeClass("contact_form_modal");
  334.  
  335. timer.play();
  336.  
  337. }
  338. });
  339.  
  340. }
  341.  
  342. if (modal_ajax.data.button_pressed == 'view_swap') {
  343.  
  344. optional.data.button_pressed = $(this).attr("name");
  345.  
  346. optional.data.button_value = $(this).attr("value");
  347.  
  348. optional.data.button_id = $(this).attr("id");
  349.  
  350. toggle_search_mode_button();
  351.  
  352. $("#kiosk").ajaxSubmit(optional);
  353.  
  354. }
  355.  
  356. if ((modal_ajax.data.button_id != 'feed_back_form') && (modal_ajax.data.button_pressed != 'view_swap')) {
  357.  
  358. if(modal_ajax.data.button_id=='how_it_works') {
  359.  
  360. modal_ajax.color_box_width = ($(window).width()), modal_ajax.color_box_height = ($(window).height());
  361.  
  362. modal_ajax.color_box_on_complete = function() {
  363.  
  364. $('li.close_button').on('click', function(e) {
  365.  
  366. $("#colorbox").colorbox.close();
  367.  
  368. });
  369.  
  370. };
  371.  
  372. modal_ajax.color_box_on_open = function() {
  373.  
  374. $('#colorbox').addClass('full_screen_modal');
  375.  
  376. $('html, body').animate({scrollTop: $("#colorbox").offset({top:15}).top}, 1000);
  377.  
  378. };
  379.  
  380. modal_ajax.color_box_on_closed = function() {
  381.  
  382. $('#colorbox').removeClass('full_screen_modal');
  383.  
  384. };
  385.  
  386. }
  387.  
  388. $.ajax(modal_ajax);
  389.  
  390. }
  391.  
  392. });
  393.  
  394. }
  395.  
  396. function toggle_search_mode_button () {
  397.  
  398. $(".header_search_button_wrapper").find('button').each(function() {
  399.  
  400. $(this).toggleClass("show hide").fadeIn('200');
  401.  
  402. });
  403.  
  404. }
  405.  
  406. function re_init() {
  407.  
  408. color_box_binds();
  409.  
  410. timer.reset(true);
  411.  
  412. $('#kiosk button').on('click', function(e) {
  413.  
  414. e.preventDefault();
  415.  
  416. optional.data.button_pressed = $(this).attr("name")
  417.  
  418. optional.data.button_value = $(this).attr("value")
  419.  
  420. optional.data.button_id = $(this).attr("id")
  421.  
  422. if (optional.data.button_value == 'Full') {
  423.  
  424. $('.side_bar').fadeOut();
  425.  
  426. $('.content_layer_1').fadeOut();
  427.  
  428. $('.single_post_view').fadeOut();
  429.  
  430. }
  431.  
  432. if (optional.data.button_value == 'Short') {
  433.  
  434. //$('.content_layer_1').fadeIn();
  435. //$('.side_bar').fadeIn();
  436.  
  437. }
  438.  
  439. if(optional.data.button_pressed == 'view_swap') {
  440.  
  441. toggle_search_mode_button();
  442.  
  443. }
  444.  
  445. if (optional.data.button_pressed == 'Print') {
  446.  
  447. var onPrintFinished = function(printed) {
  448.  
  449. $("#print_area").empty();
  450.  
  451. }
  452.  
  453. modal_ajax.data.button_id = $(this).attr("id");
  454.  
  455. modal_ajax.data.button_pressed = 'print';
  456.  
  457. modal_ajax.data.button_value = $(this).attr("value");
  458.  
  459. var temp = modal_ajax.success;
  460. // we're temporarily changing the modal callback function.
  461.  
  462. modal_ajax.success = function(data) {
  463.  
  464. $('#print_area').append(data.results);
  465.  
  466. setTimeout(deferred_print, 500);
  467.  
  468. };
  469.  
  470. function deferred_print() {
  471.  
  472. onPrintFinished(window.print());
  473.  
  474. }
  475.  
  476.  
  477. $.ajax(modal_ajax)
  478.  
  479. modal_ajax.success = temp;
  480. // now we're changing it back.
  481.  
  482. }
  483.  
  484. if (optional.data.button_pressed != 'Print') {
  485.  
  486. $("#kiosk").ajaxSubmit(optional);
  487.  
  488. }
  489.  
  490. });
  491.  
  492. }
  493.  
  494. re_init();
  495.  
  496. header_modal_binds();
  497.  
  498. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement