Guest User

Untitled

a guest
Oct 3rd, 2014
436
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 152.82 KB | None | 0 0
  1. "use strict";
  2.  
  3. /* ----------------------------------------------------------------------------
  4. td_detect - browser detection object (instance)
  5. v1.1
  6. */
  7.  
  8. var td_detect = new function () {
  9.  
  10. //constructor
  11. this.is_ie8 = false;
  12. this.is_ie9 = false;
  13. this.is_ie10 = false;
  14. this.is_ie11 = false;
  15. this.is_ie = false;
  16. this.is_safary = false;
  17. this.is_chrome = false;
  18. this.is_ipad = false;
  19.  
  20. this.is_touch_device = false;
  21.  
  22. this.has_history = false;
  23.  
  24. this.is_phone_screen = false;
  25.  
  26. this.is_ios = false;
  27.  
  28. this.is_android = false;
  29.  
  30. // is touch device ?
  31. this.is_touch_device = !!('ontouchstart' in window);
  32.  
  33. this.is_mobile_device = false;
  34.  
  35. // detect ie8
  36. if (jQuery('html').is('.ie8')) {
  37. this.is_ie8 = true;
  38. this.is_ie = true;
  39. }
  40.  
  41.  
  42.  
  43. // detect ie9
  44. if (jQuery('html').is('.ie9')) {
  45. this.is_ie9 = true;
  46. this.is_ie = true;
  47. }
  48.  
  49. // detect ie10 - also adds the ie10 class //it also detects windows mobile IE as IE10
  50. if(navigator.userAgent.indexOf("MSIE 10.0") > -1){
  51. jQuery("html").addClass("ie10");
  52. this.is_ie10 = true;
  53. this.is_ie = true;
  54. //alert('10');
  55. }
  56.  
  57. //ie 11 check - also adds the ie11 class - it may detect ie on windows mobile
  58. if(!!navigator.userAgent.match(/Trident.*rv\:11\./)){
  59. jQuery("html").addClass("ie11");
  60. this.is_ie11 = true;
  61. //this.is_ie = true; //do not flag ie11 as is_ie
  62. //alert('11');
  63. }
  64.  
  65.  
  66. //do we have html5 history support?
  67. if (window.history && window.history.pushState) {
  68. this.has_history = true;
  69. }
  70.  
  71. //check for safary
  72. if (navigator.userAgent.indexOf('Safari') != -1 && navigator.userAgent.indexOf('Chrome') == -1) {
  73. this.is_safary = true;
  74. }
  75.  
  76. //chrome and chrome-ium check
  77. this.is_chrome = /chrom(e|ium)/.test(navigator.userAgent.toLowerCase());
  78.  
  79. this.is_ipad = navigator.userAgent.match(/iPad/i) != null;
  80.  
  81.  
  82.  
  83. this.is_ios = /(iPad|iPhone|iPod)/g.test( navigator.userAgent );
  84.  
  85.  
  86. //detect if we run on a mobile device - ipad included - used by the modal / scroll to @see scroll_into_view
  87. if( /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) ) {
  88. this.is_mobile_device = true;
  89. }
  90.  
  91. /**
  92. * function to check the phone screen
  93. * @see td_events
  94. * The jQuery windows width is not reliable cross browser!
  95. */
  96. this.run_is_phone_screen = function () {
  97. if ((jQuery(window).width() < 768 || jQuery(window).height() < 768) && this.is_ipad === false) {
  98. this.is_phone_screen = true;
  99.  
  100. } else {
  101. this.is_phone_screen = false;
  102. }
  103.  
  104. //console.log(this.is_phone_screen + ' ' + jQuery(window).width() + ' ' + jQuery(window).height());
  105. };
  106.  
  107.  
  108.  
  109. this.run_is_phone_screen();
  110.  
  111.  
  112. //test for android
  113. var user_agent = navigator.userAgent.toLowerCase();
  114. if(user_agent.indexOf("android") > -1) {
  115. this.is_android = true;
  116. }
  117.  
  118.  
  119.  
  120. };
  121.  
  122.  
  123.  
  124.  
  125. /* ----------------------------------------------------------------------------
  126. tagDiv magic cache
  127. v1.0
  128. */
  129. var td_local_cache = {
  130. data: {},
  131. remove: function (resurce_id) {
  132. delete td_local_cache.data[resurce_id];
  133. },
  134. exist: function (resurce_id) {
  135. return td_local_cache.data.hasOwnProperty(resurce_id) && td_local_cache.data[resurce_id] !== null;
  136. },
  137. get: function (resurce_id) {
  138. return td_local_cache.data[resurce_id];
  139. },
  140. set: function (resurce_id, cachedData) {
  141. td_local_cache.remove(resurce_id);
  142. td_local_cache.data[resurce_id] = cachedData;
  143. }
  144. };
  145.  
  146. /*
  147. td_util.js
  148. v1.1
  149. */
  150.  
  151. "use strict";
  152.  
  153.  
  154.  
  155. /* ----------------------------------------------------------------------------
  156. tagDiv utility class
  157. */
  158. var td_util = {
  159.  
  160.  
  161. /**
  162. * utility function, used by td_post_images.js
  163. * @param class_selector
  164. */
  165. image_move_class_to_figure: function (class_selector) {
  166. jQuery('figure .' + class_selector).each(function() {
  167. jQuery(this).parent().parent().addClass(class_selector);
  168. jQuery(this).removeClass(class_selector);
  169. });
  170. },
  171.  
  172.  
  173.  
  174. /**
  175. * safe function to read variables passed by the theme via the js buffer. If by some kind of error the variable is missing from the global scope, this function will return false
  176. * @param variable_name
  177. * @returns {*}
  178. */
  179. get_backend_var: function(variable_name) {
  180. if (typeof window[variable_name] === 'undefined') {
  181. return '';
  182. }
  183. return window[variable_name];
  184. },
  185.  
  186.  
  187.  
  188. /**
  189. * scrolls to a dom element
  190. * @param dom_element
  191. */
  192. scroll_to_element: function(dom_element, duration) {
  193. td_is_scrolling_animation = true;
  194. jQuery("html, body").stop();
  195.  
  196.  
  197. var dest;
  198.  
  199. //calculate destination place
  200. if (dom_element.offset().top > jQuery(document).height() - jQuery(window).height()) {
  201. dest = jQuery(document).height() - jQuery(window).height();
  202. } else {
  203. dest = dom_element.offset().top;
  204. }
  205. //go to destination
  206. jQuery("html, body").animate({ scrollTop: dest }, {
  207. duration: duration,
  208. easing:'easeInOutQuart',
  209. complete: function(){
  210. td_is_scrolling_animation = false;
  211. }
  212. }
  213. );
  214. },
  215.  
  216.  
  217. /**
  218. * scrolls to a dom element - the element will be close to the center of the screen
  219. * !!! compensates for long distances !!!
  220. */
  221. scroll_into_view: function (dom_element) {
  222.  
  223. if (td_detect.is_mobile_device === true) {
  224. return; //do not run on any mobile device
  225. }
  226.  
  227. td_is_scrolling_animation = true;
  228. jQuery("html, body").stop();
  229.  
  230.  
  231. var destination = dom_element.offset().top;
  232. destination = destination - 150;
  233.  
  234. var distance = Math.abs(jQuery(window).scrollTop() - destination);
  235. var computed_time = distance / 5;
  236. //console.log(distance + ' -> ' + computed_time + ' -> ' + (1100+computed_time));
  237.  
  238. //go to destination
  239. jQuery("html, body").animate({ scrollTop: destination }, {
  240. duration: 1100 + computed_time,
  241. easing:'easeInOutQuart',
  242. complete: function(){
  243. td_is_scrolling_animation = false;
  244. }
  245. }
  246. );
  247. },
  248.  
  249. /**
  250. * scrolls to a position
  251. * @param px_from_top - pixels from top
  252. */
  253. scroll_to_position: function(px_from_top, duration) {
  254. td_is_scrolling_animation = true;
  255. jQuery("html, body").stop();
  256.  
  257. //go to destination
  258. jQuery("html, body").animate({ scrollTop: px_from_top }, {
  259. duration: duration,
  260. easing:'easeInOutQuart',
  261. complete: function(){
  262. td_is_scrolling_animation = false;
  263. }
  264. }
  265. );
  266. },
  267. td_move_y: function td_move_Y (elm, value) {
  268. var translate = 'translate3d(0px,' + value + 'px, 0px)';
  269. elm.style['-webkit-transform'] = translate;
  270. elm.style['-moz-transform'] = translate;
  271. elm.style['-ms-transform'] = translate;
  272. elm.style['-o-transform'] = translate;
  273. elm.style.transform = translate;
  274. }
  275.  
  276.  
  277. };
  278.  
  279.  
  280. /**
  281. * Created by ra on 6/27/14.
  282. * copyright tagDiv 2014
  283. */
  284.  
  285.  
  286. var td_affix = {
  287.  
  288. //settings, obtained from ext
  289. menu_selector: '', //the affix menu (this element will get the td-affix)
  290. menu_wrap_selector: '', //the menu wrapper / placeholder
  291. tds_snap_menu: '', //the panel setting
  292.  
  293.  
  294. top_offset: 0, //how much the menu is moved from the original position when it's affixed
  295. menu_offset: 0, //used to hide the menu on scroll
  296. is_requestAnimationFrame_running:false, //prevent multiple calls to requestAnimationFrame
  297. is_menu_affix: false, //the current state of the menu, true if the menu is affix
  298. is_top_menu:false, //true when the menu is at the top of the screen (0px topScroll)
  299.  
  300. //menu offset boundaries - so we do not fire the animation event when the boundary is hit
  301. menu_offset_max_hit: false,
  302. menu_offset_min_hit: true,
  303.  
  304.  
  305. scroll_window_scrollTop_last: 0, //last scrollTop position, used to calculate the scroll direction
  306.  
  307. /**
  308. * run the affix, we use the menu wrap selector to compute the menu position from top
  309. *
  310. {
  311. menu_selector: '.td-header-main-menu',
  312. menu_wrap_selector: '.td-header-menu-wrap',
  313. tds_snap_menu: td_util.get_backend_var('tds_snap_menu')
  314. }
  315. */
  316. init : function init (atts) {
  317.  
  318. //read the settings
  319. td_affix.menu_selector = atts.menu_selector;
  320. td_affix.menu_wrap_selector = atts.menu_wrap_selector;
  321. td_affix.tds_snap_menu = atts.tds_snap_menu;
  322.  
  323. //the snap menu is disabled from the panel
  324. if (!td_affix.tds_snap_menu) {
  325. return;
  326. }
  327.  
  328. //compute on semi dom ready
  329. td_affix.compute_top();
  330.  
  331.  
  332. //recompute when all the page + logos are loaded
  333. jQuery(window).load(function() {
  334. td_affix.compute_top();
  335.  
  336. //recompute after 1 sec for retarded phones
  337. setTimeout(function(){
  338. td_affix.compute_top();
  339. }, 1000);
  340. });
  341.  
  342.  
  343.  
  344.  
  345. },
  346.  
  347. /**
  348. * called by td_events.js on scroll
  349. */
  350. td_events_scroll: function td_events_scroll(scrollTop) {
  351.  
  352. //do not run if we don't have a snap menu
  353. if (!td_affix.tds_snap_menu) {
  354. return;
  355. }
  356.  
  357.  
  358. /* ----------------------------------------------------------------------------
  359. scroll direction + delta (used by affix for now)
  360. to run thios code:
  361. - td_affix.tds_snap_menu != '' (from above)
  362. - td_affix.tds_snap_menu != 'snap'
  363. */
  364. if (td_affix.tds_snap_menu != 'snap') { //do not run on snap
  365. if ((td_affix.tds_snap_menu != 'smart_snap_mobile' || td_detect.is_phone_screen === true)) { // different from smart_snap_mobile or td_detect.is_phone_screen === true
  366. //console.log('rrr');
  367. var scroll_direction = '';
  368. var scrollDelta = 0;
  369.  
  370. //check the direction
  371. if (scrollTop != td_affix.scroll_window_scrollTop_last) { //compute direction only if we have different last scroll top
  372. // compute the direction of the scroll
  373. if (scrollTop > td_affix.scroll_window_scrollTop_last) {
  374. scroll_direction = 'down';
  375. } else {
  376. scroll_direction = 'up';
  377. }
  378. //calculate the scroll delta
  379. scrollDelta = Math.abs(scrollTop - td_affix.scroll_window_scrollTop_last);
  380. }
  381.  
  382. td_affix.scroll_window_scrollTop_last = scrollTop;
  383. }
  384. }
  385.  
  386. /* ---------------------------------------------------------------------------- */
  387.  
  388.  
  389.  
  390. //if the menu is in the affix state
  391. if (scrollTop > td_affix.top_offset || td_affix.is_top_menu === true) {
  392.  
  393. //get the menu element
  394. var td_affix_menu_element = jQuery(td_affix.menu_selector);
  395.  
  396. //turn affix on for it
  397. td_affix._affix_on(td_affix_menu_element);
  398.  
  399.  
  400. //if the menu is only with snap or we are on smart_snap_mobile + mobile, our job here in this function is done, return
  401. if (td_affix.tds_snap_menu == 'snap' || (td_affix.tds_snap_menu =='smart_snap_mobile' && td_detect.is_phone_screen === false)) {
  402. return;
  403. }
  404.  
  405. /* --- end simple snap --- */
  406.  
  407.  
  408. /* ----------------------------------------------------------------------------
  409. check scroll directions (we may also have scroll_direction = '', that's why we have to check for the specific state (up or down))
  410. */
  411.  
  412.  
  413.  
  414. // boundary check - to not run the position on each scroll event
  415. if ((td_affix.menu_offset_max_hit === false && scroll_direction=='down') || (td_affix.menu_offset_min_hit === false && scroll_direction=='up')) {
  416. //request animation frame
  417. if (td_affix.is_requestAnimationFrame_running === false) {
  418. window.requestAnimationFrame(function(){
  419.  
  420. var offset = 0;
  421.  
  422. if (scroll_direction == 'down') {
  423. //compute the offset
  424. offset = td_affix.menu_offset-scrollDelta;
  425. if (offset < -80) {
  426. offset = -80;
  427. }
  428. } else if (scroll_direction == 'up') {
  429. //compute the offset
  430. offset = td_affix.menu_offset+scrollDelta;
  431. if (offset > 0) {
  432. offset = 0;
  433. }
  434. }
  435.  
  436.  
  437. td_affix.is_requestAnimationFrame_running = true;
  438.  
  439. //move the menu
  440. td_util.td_move_y(td_affix_menu_element[0], offset);
  441. //td_affix_menu_element.css({top: (offset) + 'px'}); //legacy menu move code
  442.  
  443. //check boundaries
  444. if (offset == 0) {
  445. td_affix.menu_offset_min_hit = true;
  446. } else {
  447. td_affix.menu_offset_min_hit = false;
  448. }
  449.  
  450. if (offset == -80) {
  451. td_affix.menu_offset_max_hit = true;
  452. //also hide the menu when it's 100% out of view on ios - the safari header is transparent and we can see the menu
  453. if(td_detect.is_ios === true) {
  454. td_affix_menu_element.hide();
  455. }
  456. } else {
  457. td_affix.menu_offset_max_hit = false;
  458.  
  459. if(td_detect.is_ios === true) { //ios safari fix
  460. td_affix_menu_element.show();
  461. }
  462. }
  463.  
  464.  
  465. td_affix.is_requestAnimationFrame_running = false;
  466.  
  467.  
  468.  
  469.  
  470. td_affix.menu_offset = offset; //update the current offset of the menu
  471.  
  472.  
  473. },td_affix_menu_element[0]);
  474.  
  475. }
  476. //console.log(offset + ' ' + scroll_direction);
  477.  
  478. } //end boundary check
  479.  
  480.  
  481.  
  482. } else {
  483. td_affix._affix_off(jQuery(td_affix.menu_selector));
  484. }
  485.  
  486. },
  487.  
  488.  
  489. /**
  490. * calculates the affix point (the distance from the top when affix should be enabled)
  491. * @see td_affix.init()
  492. * @see td_events
  493. */
  494. compute_top: function compute_top() {
  495. td_affix.top_offset = jQuery(td_affix.menu_wrap_selector).offset().top;
  496.  
  497. //check to see if the menu is at the top of the screen
  498. if (td_affix.top_offset == 1) {
  499. //switch to affix - because the menu is at the top of the page
  500. //td_affix._affix_on(jQuery(td_affix.menu_selector));
  501. td_affix.is_top_menu = true;
  502. } else {
  503. //check to see the current top offset
  504. td_affix.is_top_menu = false;
  505.  
  506. }
  507. td_affix.td_events_scroll(jQuery(window).scrollTop());
  508.  
  509. //alert(td_affix.top_offset);
  510. //console.log('computed: ' + td_affix.top_offset);
  511. },
  512.  
  513.  
  514.  
  515. /**
  516. * turns affix on for the menu element
  517. * @param td_affix_menu_element
  518. * @private
  519. */
  520. _affix_on: function _affix_on(td_affix_menu_element) {
  521. if (td_affix.is_menu_affix === false) {
  522. //make the menu fixed
  523. td_affix_menu_element.addClass('td-affix');
  524.  
  525. //add body-td-affix class on body for header style 8 -> when scrolling down the window jumps 76px up when the menu is changing from header style 8 default to header style 8 affix
  526. jQuery('body').addClass('body-td-affix');
  527.  
  528. td_affix.is_menu_affix = true;
  529. }
  530. },
  531.  
  532.  
  533.  
  534. /**
  535. * Turns affix off for the menu element
  536. * @param td_affix_menu_element
  537. * @private
  538. */
  539. _affix_off: function _affix_on(td_affix_menu_element) {
  540. if (td_affix.is_menu_affix === true) {
  541. //make the menu normal
  542. jQuery(td_affix.menu_selector).removeClass('td-affix');
  543.  
  544. //remove body-td-affix class on body for header style 8 -> when scrolling down the window jumps 76px up when the menu is changing from header style 8 default to header style 8 affix
  545. jQuery('body').removeClass('body-td-affix');
  546.  
  547. td_affix.is_menu_affix = false;
  548.  
  549. //move the menu to 0 (ios seems to skip animation frames)
  550. td_util.td_move_y(td_affix_menu_element[0], 0);
  551.  
  552. if(td_detect.is_ios === true) {
  553. td_affix_menu_element.show();
  554. }
  555.  
  556. }
  557. }
  558.  
  559.  
  560.  
  561. };
  562.  
  563.  
  564.  
  565. /* ----------------------------------------------------------------------------
  566. Affix menu
  567. */
  568. td_affix.init({
  569. menu_selector: '.td-menu-background',
  570. menu_wrap_selector: '.td-menu-placeholder',
  571. tds_snap_menu: td_util.get_backend_var('tds_snap_menu')
  572. });
  573.  
  574.  
  575.  
  576.  
  577. /*
  578. tagDiv - 2014 - Newspaper WordPress theme v4.0
  579. Our portfolio: http://themeforest.net/user/tagDiv/portfolio
  580.  
  581. Thanks for using our theme! :)
  582. */
  583.  
  584.  
  585.  
  586.  
  587.  
  588. var td_is_slide_moving = false; //disable touch when the touch sliders are moving
  589.  
  590.  
  591.  
  592.  
  593. /* ----------------------------------------------------------------------------
  594. Menu script
  595. */
  596.  
  597. jQuery('#td-top-menu .sf-menu').supersubs({
  598. minWidth: 10, // minimum width of sub-menus in em units
  599. maxWidth: 40, // maximum width of sub-menus in em units
  600. extraWidth: 1 // extra width can ensure lines don't sometimes turn over
  601. });
  602.  
  603. if (td_detect.is_touch_device) {
  604. //touch
  605. jQuery('#td-top-menu .sf-menu').superfish({
  606. delay:300,
  607. speed:'fast',
  608. useClick:true
  609. });
  610. } else {
  611. //not touch
  612. jQuery('#td-top-menu .sf-menu').superfish({
  613. delay:500,
  614. speed:200,
  615. useClick:false
  616. });
  617. }
  618.  
  619. /* ----------------------------------------------------------------------------
  620. On load
  621. */
  622. jQuery().ready(function jQuery_ready() {
  623.  
  624.  
  625.  
  626. //resize all the videos if we have them
  627. td_resize_videos();
  628.  
  629.  
  630.  
  631.  
  632.  
  633.  
  634.  
  635.  
  636.  
  637. //put focus on search box in blog header
  638. jQuery('#search-button').click(function(){
  639. jQuery(this).delay(200).queue(function(){
  640. document.getElementById("td-header-search").focus();
  641. jQuery(this).dequeue();
  642. });
  643. });
  644.  
  645.  
  646. //retina images
  647. td_retina();
  648.  
  649. //colorbox
  650. jQuery('.td-featured-img').colorbox({
  651. maxWidth:"95%",
  652. maxHeight:"95%",
  653. fixed:true
  654. });
  655.  
  656.  
  657.  
  658.  
  659.  
  660. td_ajax_search();
  661.  
  662.  
  663. //srun the mobile menu on phones and on desktop (no ipad or big tablets with touch)
  664. if (td_detect.is_phone_screen || td_detect.is_touch_device === false) {
  665. //alert('mobile menu');
  666. td_mobile_menu2();
  667. }
  668.  
  669.  
  670.  
  671.  
  672.  
  673.  
  674.  
  675. td_fake_clicks();
  676.  
  677.  
  678.  
  679.  
  680.  
  681.  
  682.  
  683. //fake placeholder for ie
  684. jQuery('input, textarea').placeholder();
  685.  
  686.  
  687.  
  688. //more stories box
  689. td_more_articles_box.init();
  690.  
  691.  
  692.  
  693. if (td_detect.is_chrome === true || td_detect.is_ie10 || td_detect.is_ie11) {
  694. td_smooth_scroll();
  695. }
  696.  
  697.  
  698. setTimeout(function(){
  699. td_resize_page_sliders()
  700. }, 1500);
  701.  
  702. }); //end on load
  703.  
  704.  
  705. /**
  706. * windlow.load
  707. */
  708. jQuery(window).load(function() {
  709. td_resize_page_sliders();
  710. });
  711.  
  712.  
  713.  
  714. /* ----------------------------------------------------------------------------
  715. Scroll to top + animation stop
  716. */
  717.  
  718. var td_is_scrolling_animation = false;
  719. var td_mouse_wheel_or_touch_moved = false; //we want to know if the user stopped the animation via touch or mouse move
  720.  
  721. //stop the animation on mouse wheel
  722. jQuery(document).bind('mousewheel DOMMouseScroll MozMousePixelScroll', function(e){
  723. if (td_is_scrolling_animation === false) {
  724. return;
  725. } else {
  726. td_is_scrolling_animation = false;
  727. td_mouse_wheel_or_touch_moved = true;
  728.  
  729. jQuery("html, body").stop();
  730. }
  731. });
  732.  
  733. //stop the animation on touch
  734. if (document.addEventListener){
  735. document.addEventListener('touchmove', function(e) {
  736. if (td_is_scrolling_animation === false) {
  737. return;
  738. } else {
  739. td_is_scrolling_animation = false;
  740. td_mouse_wheel_or_touch_moved = true;
  741. jQuery("html, body").stop();
  742. }
  743. }, false);
  744. }
  745.  
  746. /**
  747. * called by td_events.js on scroll - back to top
  748. */
  749. var td_scroll_to_top_is_visible = false;
  750. function td_events_scroll_scroll_to_top(scrollTop) {
  751. if(td_is_scrolling_animation) { //do not fire the event on animations
  752. return;
  753. }
  754. if (scrollTop > 400) {
  755. if (td_scroll_to_top_is_visible === false) { //only add class if needed
  756. td_scroll_to_top_is_visible = true;
  757. jQuery('.td-scroll-up').addClass('td-scroll-up-visible');
  758. }
  759. } else {
  760. if (td_scroll_to_top_is_visible === true) { //only add class if needed
  761. td_scroll_to_top_is_visible = false;
  762. jQuery('.td-scroll-up').removeClass('td-scroll-up-visible');
  763. }
  764. }
  765. }
  766.  
  767.  
  768. jQuery('.td-scroll-up').click(function(){
  769. if(td_is_scrolling_animation) { //double check - because when we remove the class, the button is still visible for a while
  770. return;
  771. }
  772.  
  773. //hide the button
  774. td_scroll_to_top_is_visible = false;
  775. jQuery('.td-scroll-up').removeClass('td-scroll-up-visible');
  776.  
  777. //hide more articles box
  778. td_more_articles_box.is_box_visible = false;
  779. jQuery('.td-more-articles-box').removeClass('td-front-end-display-block');
  780.  
  781. //scroll to top
  782. td_util.scroll_to_position(0, 1200);
  783.  
  784. return false;
  785. });
  786.  
  787.  
  788. /**
  789. * More stories box
  790. */
  791. var td_more_articles_box = {
  792. is_box_visible:false,
  793. cookie:'',
  794. distance_from_top:400,
  795.  
  796. init: function init() {
  797.  
  798.  
  799. //read the cookie
  800. td_more_articles_box.cookie = td_read_site_cookie('td-cookie-more-articles');
  801.  
  802.  
  803. //setting distance from the top
  804. if(!isNaN(parseInt(tds_more_articles_on_post_pages_distance_from_top)) && isFinite(tds_more_articles_on_post_pages_distance_from_top) && parseInt(tds_more_articles_on_post_pages_distance_from_top) > 0){
  805. td_more_articles_box.distance_from_top = parseInt(tds_more_articles_on_post_pages_distance_from_top);
  806. } else {
  807. td_more_articles_box.distance_from_top = 400;
  808. }
  809.  
  810. //adding event to hide the box
  811. jQuery('.td-close-more-articles-box').click(function(){
  812.  
  813. //hiding the box
  814. jQuery('.td-more-articles-box').removeClass('td-front-end-display-block');
  815. jQuery('.td-more-articles-box').hide();
  816.  
  817. //cookie life
  818. if(!isNaN(parseInt(tds_more_articles_on_post_time_to_wait)) && isFinite(tds_more_articles_on_post_time_to_wait)){
  819. //setting cookie
  820. td_create_cookie('td-cookie-more-articles', 'hide-more-articles-box', parseInt(tds_more_articles_on_post_time_to_wait));
  821. }
  822. });
  823. },
  824.  
  825. /**
  826. * called by td_events.js on scroll
  827. */
  828. td_events_scroll: function td_events_scroll(scrollTop) {
  829.  
  830. if(td_is_scrolling_animation) { //do not fire the event on animations
  831. return;
  832. }
  833.  
  834. //check to see if it's enable form panel and also from cookie
  835. if(td_util.get_backend_var('tds_more_articles_on_post_enable') == "show" && td_more_articles_box.cookie != 'hide-more-articles-box') {
  836.  
  837. if (scrollTop > td_more_articles_box.distance_from_top ) {
  838. if (td_more_articles_box.is_box_visible === false) {
  839. jQuery('.td-more-articles-box').addClass('td-front-end-display-block');
  840. td_more_articles_box.is_box_visible = true;
  841. }
  842. } else {
  843. if (td_more_articles_box.is_box_visible === true) {
  844. jQuery('.td-more-articles-box').removeClass('td-front-end-display-block');
  845. td_more_articles_box.is_box_visible = false;
  846. }
  847. }
  848. }
  849. }
  850. };
  851.  
  852.  
  853.  
  854. //click on a div -> go to a url
  855. function td_fake_clicks() {
  856. jQuery('.td-fake-click').click(function(){
  857. window.location = jQuery(this).data("fake-click");
  858. });
  859. }
  860.  
  861.  
  862.  
  863.  
  864. var td_resize_timer_id;
  865. jQuery(window).resize(function() {
  866. clearTimeout(td_resize_timer_id);
  867. td_resize_timer_id = setTimeout(td_done_resizing, 500);
  868.  
  869. });
  870.  
  871. function td_done_resizing(){
  872. td_resize_videos();
  873. }
  874.  
  875.  
  876.  
  877. /* ----------------------------------------------------------------------------
  878. Resize the videos
  879. */
  880. function td_resize_videos() {
  881. //youtube in content
  882. jQuery(document).find('iframe[src*="youtube.com"]').each(function() {
  883.  
  884. if(jQuery(this).parent().hasClass("td_wrapper_playlist_player_youtube")) {
  885. //do nothing for playlist player youtube
  886. } else {
  887. var td_video = jQuery(this);
  888. td_video.attr('width', '100%');
  889. var td_video_width = td_video.width();
  890. td_video.css('height', td_video_width * 0.6, 'important');
  891. }
  892. });
  893.  
  894.  
  895. //vimeo in content
  896. jQuery(document).find('iframe[src*="vimeo.com"]').each(function() {
  897.  
  898. if(jQuery(this).parent().hasClass("td_wrapper_playlist_player_vimeo")) {
  899. //do nothing for playlist player vimeo
  900. } else {
  901. var td_video = jQuery(this);
  902. td_video.attr('width', '100%');
  903. var td_video_width = td_video.width();
  904. td_video.css('height', td_video_width * 0.6, 'important');
  905. }
  906. })
  907.  
  908.  
  909. //daily motion in content
  910. jQuery(document).find('iframe[src*="dailymotion.com"]').each(function() {
  911. var td_video = jQuery(this);
  912. td_video.attr('width', '100%');
  913. var td_video_width = td_video.width();
  914. td_video.css('height', td_video_width * 0.6, 'important');
  915. })
  916. }
  917.  
  918.  
  919.  
  920.  
  921. /* ----------------------------------------------------------------------------
  922. Ajax search
  923. */
  924. var td_aj_search_cur_sel = 0;
  925. var td_aj_search_results = 0;
  926. var td_aj_first_down_up = true;
  927. function td_ajax_search() {
  928.  
  929.  
  930.  
  931.  
  932. jQuery('#td-header-search').keydown(function(event) {
  933.  
  934. //console.log(event.keyCode);
  935.  
  936.  
  937. if ((event.which && event.which == 39) || (event.keyCode && event.keyCode == 39) || (event.which && event.which == 37) || (event.keyCode && event.keyCode == 37)) {
  938. //do nothing on left and right arrows
  939. td_aj_search_input_focus();
  940. return;
  941. }
  942.  
  943. if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
  944.  
  945. //redirectSearch('q');
  946. var td_aj_cur_element = jQuery('.td-aj-cur-element');
  947. if (td_aj_cur_element.length > 0) {
  948. //alert('ra');
  949. var td_go_to_url = td_aj_cur_element.find('.entry-title a').attr('href');
  950. window.location = td_go_to_url;
  951. } else {
  952. jQuery(this).parent().parent().submit();
  953. }
  954.  
  955. return false; //redirect for search on enter
  956. } else {
  957.  
  958. if ((event.which && event.which == 40) || (event.keyCode && event.keyCode == 40)) {
  959. // down
  960. td_aj_search_move_prompt_down();
  961. return false; //disable the envent
  962.  
  963. } else if((event.which && event.which == 38) || (event.keyCode && event.keyCode == 38)) {
  964. //up
  965. td_aj_search_move_prompt_up();
  966. return false; //disable the envent
  967. } else {
  968.  
  969. //for backspace we have to check if the search query is empty and if so, clear the list
  970. if ((event.which && event.which == 8) || (event.keyCode && event.keyCode == 8)) {
  971. //if we have just one character left, that means it will be deleted now and we also have to clear the search results list
  972. var search_query = jQuery(this).val();
  973. if (search_query.length == 1) {
  974. jQuery('#td-aj-search').empty();
  975. }
  976.  
  977. }
  978.  
  979. //various keys
  980. td_aj_search_input_focus();
  981. setTimeout("td_ajax_search_do_request()",100);
  982. }
  983. return true;
  984. }
  985.  
  986. });
  987.  
  988.  
  989.  
  990. }
  991.  
  992. //moves the select up
  993. function td_aj_search_move_prompt_up() {
  994.  
  995.  
  996. if (td_aj_first_down_up === true) {
  997. td_aj_first_down_up = false;
  998. if (td_aj_search_cur_sel === 0) {
  999. td_aj_search_cur_sel = td_aj_search_results - 1;
  1000. } else {
  1001. td_aj_search_cur_sel--;
  1002. }
  1003. } else {
  1004. if (td_aj_search_cur_sel === 0) {
  1005. td_aj_search_cur_sel = td_aj_search_results;
  1006. } else {
  1007. td_aj_search_cur_sel--;
  1008. }
  1009. }
  1010.  
  1011.  
  1012. jQuery('.td_mod_aj_search').removeClass('td-aj-cur-element');
  1013.  
  1014.  
  1015.  
  1016. if (td_aj_search_cur_sel > td_aj_search_results -1) {
  1017. //the input is selected
  1018. jQuery('.td-search-form').fadeTo(100, 1);
  1019. } else {
  1020. td_aj_search_input_remove_focus();
  1021. jQuery('.td_mod_aj_search').eq(td_aj_search_cur_sel).addClass('td-aj-cur-element');
  1022. }
  1023.  
  1024.  
  1025.  
  1026. }
  1027.  
  1028. //moves the select prompt down
  1029. function td_aj_search_move_prompt_down() {
  1030.  
  1031. if (td_aj_first_down_up === true) {
  1032. td_aj_first_down_up = false;
  1033. } else {
  1034. if (td_aj_search_cur_sel === td_aj_search_results) {
  1035. td_aj_search_cur_sel = 0;
  1036. } else {
  1037. td_aj_search_cur_sel++;
  1038. }
  1039. }
  1040.  
  1041.  
  1042. jQuery('.td_mod_aj_search').removeClass('td-aj-cur-element');
  1043.  
  1044. if (td_aj_search_cur_sel > td_aj_search_results - 1 ) {
  1045. //the input is selected
  1046. jQuery('.td-search-form').fadeTo(100, 1);
  1047. } else {
  1048. td_aj_search_input_remove_focus();
  1049. jQuery('.td_mod_aj_search').eq(td_aj_search_cur_sel).addClass('td-aj-cur-element');
  1050. }
  1051.  
  1052.  
  1053. }
  1054.  
  1055.  
  1056. // puts the focus on the input box
  1057. function td_aj_search_input_focus() {
  1058. td_aj_search_cur_sel = 0;
  1059. td_aj_first_down_up = true;
  1060. jQuery('.td-search-form').fadeTo(100, 1);
  1061. jQuery('.td_mod_aj_search').removeClass('td-aj-cur-element');
  1062. }
  1063.  
  1064. //removes the focus from the input box
  1065. function td_aj_search_input_remove_focus() {
  1066. if (td_aj_search_results !== 0) {
  1067. jQuery('.td-search-form').css('opacity', 0.5);
  1068. }
  1069. }
  1070.  
  1071. //makes an ajax request
  1072. function td_ajax_search_do_request() {
  1073.  
  1074. if (jQuery('#td-header-search').val() == '') {
  1075. td_aj_search_input_focus();
  1076. return;
  1077. }
  1078.  
  1079.  
  1080. var search_query = jQuery('#td-header-search').val();
  1081.  
  1082.  
  1083. //do we have a cache hit
  1084. if (td_local_cache.exist(search_query)) {
  1085. td_ajax_search_process_request(td_local_cache.get(search_query));
  1086. return; //cache HIT
  1087. }
  1088.  
  1089.  
  1090. //fk no cache hit - do the real request
  1091.  
  1092.  
  1093.  
  1094. jQuery.ajax({
  1095. type: 'POST',
  1096. url: td_ajax_url,
  1097. data: {
  1098. action: 'td_ajax_search',
  1099. td_string: search_query
  1100. },
  1101. success: function(data, textStatus, XMLHttpRequest){
  1102. td_local_cache.set(search_query, data);
  1103. td_ajax_search_process_request(data);
  1104. },
  1105. error: function(MLHttpRequest, textStatus, errorThrown){
  1106. //console.log(errorThrown);
  1107. }
  1108. });
  1109. }
  1110.  
  1111. function td_ajax_search_process_request(data) {
  1112. var current_query = jQuery('#td-header-search').val();
  1113.  
  1114. //the search is empty - drop results
  1115. if (current_query == '') {
  1116. jQuery('#td-aj-search').empty();
  1117. return;
  1118. }
  1119.  
  1120. var td_data_object = jQuery.parseJSON(data); //get the data object
  1121. //drop the result - it's from a old query
  1122. if (td_data_object.td_search_query !== current_query) {
  1123. return;
  1124. }
  1125.  
  1126. //reset the current selection and total posts
  1127. td_aj_search_cur_sel = 0;
  1128. td_aj_search_results = td_data_object.td_total_in_list;
  1129. td_aj_first_down_up = true;
  1130.  
  1131.  
  1132. //update the query
  1133. jQuery('#td-aj-search').html(td_data_object.td_data);
  1134.  
  1135. /*
  1136. td_data_object.td_data
  1137. td_data_object.td_total_results
  1138. td_data_object.td_total_in_list
  1139. */
  1140. }
  1141.  
  1142.  
  1143.  
  1144.  
  1145.  
  1146.  
  1147. function td_mobile_menu2() {
  1148. //return;
  1149. //alert('mobile menu');
  1150. //******************************************************************
  1151. //MOBILE MENU new
  1152.  
  1153. // helper functions
  1154.  
  1155. var trim = function(str)
  1156. {
  1157. return str.trim ? str.trim() : str.replace(/^\s+|\s+$/g,'');
  1158. };
  1159.  
  1160. var hasClass = function(el, cn)
  1161. {
  1162. return (' ' + el.className + ' ').indexOf(' ' + cn + ' ') !== -1;
  1163. };
  1164.  
  1165. var addClass = function(el, cn)
  1166. {
  1167. if (!hasClass(el, cn)) {
  1168. el.className = (el.className === '') ? cn : el.className + ' ' + cn;
  1169. }
  1170. };
  1171.  
  1172. var removeClass = function(el, cn)
  1173. {
  1174. el.className = trim((' ' + el.className + ' ').replace(' ' + cn + ' ', ' '));
  1175. };
  1176.  
  1177. var hasParent = function(el, id)
  1178. {
  1179. if (el) {
  1180. do {
  1181. if (el.id === id) {
  1182. return true;
  1183. }
  1184. if (el.nodeType === 9) {
  1185. break;
  1186. }
  1187. }
  1188. while((el = el.parentNode));
  1189. }
  1190. return false;
  1191. };
  1192.  
  1193. // normalize vendor prefixes
  1194.  
  1195. var doc = document.documentElement;
  1196.  
  1197. var transform_prop = window.Modernizr.prefixed('transform'),
  1198. transition_prop = window.Modernizr.prefixed('transition'),
  1199. transition_end = (function() {
  1200. var props = {
  1201. 'WebkitTransition' : 'webkitTransitionEnd',
  1202. 'MozTransition' : 'transitionend',
  1203. 'OTransition' : 'oTransitionEnd otransitionend',
  1204. 'msTransition' : 'MSTransitionEnd',
  1205. 'transition' : 'transitionend'
  1206. };
  1207. return props.hasOwnProperty(transition_prop) ? props[transition_prop] : false;
  1208. })();
  1209.  
  1210. window.App = (function()
  1211. {
  1212.  
  1213. var _init = false;
  1214. var app = { };
  1215.  
  1216. var inner_nav_td = document.getElementById('inner-wrap');
  1217. var nav_open = false;
  1218. var nav_class = 'js-nav';
  1219.  
  1220. //console.log(inner_nav_td);
  1221. app.init = function()
  1222. {
  1223. if (_init) {
  1224. return;
  1225. }
  1226. _init = true;
  1227.  
  1228. var closeNavEnd = function(e)
  1229. {
  1230. if (e && e.target === inner_nav_td) {
  1231. document.removeEventListener(transition_end, closeNavEnd, false);
  1232. }
  1233. nav_open = false;
  1234. };
  1235.  
  1236. app.closeNav =function()
  1237. {
  1238. if (nav_open) {
  1239. // close navigation after transition or immediately
  1240. //console.log(inner_nav_td);
  1241.  
  1242. jQuery('#inner-wrap').css('minHeight', 'auto');
  1243. var duration = (transition_end && transition_prop) ? parseFloat(window.getComputedStyle(inner_nav_td, '')[transition_prop + 'Duration']) : 0;
  1244. if (duration > 0) {
  1245. document.addEventListener(transition_end, closeNavEnd, false);
  1246. } else {
  1247. closeNavEnd(null);
  1248. }
  1249. }
  1250. removeClass(doc, nav_class);
  1251. };
  1252.  
  1253. app.openNav = function()
  1254. {
  1255. if (nav_open) {
  1256. return;
  1257. }
  1258.  
  1259.  
  1260. //var td_cur_innerwrap_height = jQuery('#inner-wrap').height();
  1261.  
  1262. // if (td_cur_innerwrap_height != td_cur_mobile_nav_height) {
  1263. //
  1264. // }
  1265. // alert(td_cur_mobile_nav_height);
  1266. var td_cur_mobile_nav_height = jQuery('.td-menu-animate').height();
  1267. jQuery('#inner-wrap').css('minHeight', td_cur_mobile_nav_height);
  1268. addClass(doc, nav_class);
  1269.  
  1270.  
  1271. /*
  1272. jQuery(this).delay(1000).queue(function(){
  1273. if (td_detect.is_phone_screen) {
  1274. jQuery("html, body").animate({ scrollTop: 0 }, {
  1275. duration: 1000,
  1276. easing:'easeInOutQuart',
  1277. complete: function(){
  1278. td_is_scrolling_animation = false;
  1279. }
  1280. }
  1281. );
  1282. }
  1283.  
  1284. jQuery(this).dequeue();
  1285. });
  1286. */
  1287.  
  1288.  
  1289. nav_open = true;
  1290. };
  1291.  
  1292. app.toggleNav = function(e)
  1293. {
  1294.  
  1295. if (nav_open && hasClass(doc, nav_class)) {
  1296. app.closeNav();
  1297. } else {
  1298. app.openNav();
  1299. }
  1300. if (e) {
  1301. e.preventDefault();
  1302. }
  1303. };
  1304.  
  1305. // open nav with main "nav" button
  1306. //document.getElementById('nav-open-btn').addEventListener('click', app.toggleNav, false);
  1307.  
  1308. jQuery('#td-top-mobile-toggle a, .td-mobile-close a').click(function(){
  1309. app.toggleNav();
  1310. });
  1311.  
  1312.  
  1313.  
  1314.  
  1315. // close nav with main "close" button
  1316. //document.getElementById('nav-close-btn').addEventListener('click', app.toggleNav, false);
  1317.  
  1318.  
  1319.  
  1320. addClass(doc, 'js-ready');
  1321.  
  1322. };
  1323.  
  1324. return app;
  1325.  
  1326. })();
  1327.  
  1328. if (window.addEventListener) {
  1329. window.addEventListener('DOMContentLoaded', window.App.init, false);
  1330. }
  1331.  
  1332.  
  1333.  
  1334.  
  1335.  
  1336.  
  1337.  
  1338. }
  1339.  
  1340.  
  1341.  
  1342.  
  1343. /* ----------------------------------------------------------------------------
  1344. Slider callbacks
  1345. */
  1346. function slideStartedMoving(args) {
  1347. td_is_slide_moving = true; //used on touch screens + mobile menu 2
  1348. }
  1349.  
  1350. function slideContentComplete(args) {
  1351. td_is_slide_moving = false;
  1352. if(!args.slideChanged) return false;
  1353. jQuery(args.currentSlideObject).parent().find('.slide-info-wrap').removeClass('slide-wrap-active');
  1354. jQuery(args.currentSlideObject).children('.slide-info-wrap').addClass('slide-wrap-active');
  1355. }
  1356.  
  1357. function slideContentLoaded(args) {
  1358. if(!args.slideChanged) return false;
  1359. // console.log('loaded');
  1360. jQuery(args.currentSlideObject).parent().find('.slide-info-wrap').removeClass('slide-wrap-active');
  1361. jQuery(args.currentSlideObject).children('.slide-info-wrap').addClass('slide-wrap-active');
  1362. }
  1363.  
  1364.  
  1365.  
  1366.  
  1367. /* ----------------------------------------------------------------------------
  1368. Add retina support
  1369. */
  1370.  
  1371. function td_retina() {
  1372. if (window.devicePixelRatio > 1) {
  1373. jQuery('.td-retina').each(function(i) {
  1374. var lowres = jQuery(this).attr('src');
  1375. var highres = lowres.replace(".png", "@2x.png");
  1376. highres = highres.replace(".jpg", "@2x.jpg");
  1377. jQuery(this).attr('src', highres);
  1378.  
  1379. });
  1380.  
  1381.  
  1382. //custom logo support
  1383. jQuery('.td-retina-data').each(function(i) {
  1384. jQuery(this).attr('src', jQuery(this).data('retina'));
  1385. //fix logo aligment on retina devices
  1386. jQuery(this).addClass('td-retina-version');
  1387. });
  1388.  
  1389. }
  1390. }
  1391.  
  1392. /*
  1393. jQuery('body').click(function(e){
  1394. if(! jQuery(e.target).hasClass('custom-background')){
  1395. alert('clicked on something that has not the class theDIV');
  1396. }
  1397.  
  1398. });*/
  1399.  
  1400. //click only on BACKGROUND, for devices that don't have touch (ex: phone, tablets)
  1401. if(!td_detect.is_touch_device && td_ad_background_click_link != '') {
  1402.  
  1403. //var ev = ev || window.event;
  1404. //var target = ev.target || ev.srcElement;
  1405. jQuery('body').click(function(event) {
  1406.  
  1407. //getting the target element that the user clicks - for W3C and MSIE
  1408. var target = (event.target) ? event.target : event.srcElement;
  1409.  
  1410. //only if the background has background image
  1411. if(jQuery('body').hasClass('td-boxed-layout')) {
  1412. if(target.id == 'inner-wrap' || target.className == 'td-header-menu-wrap' || target.className == 'td-header-bg' || target.className == 'td-menu-background affix-top') {
  1413.  
  1414. //open the link ad page
  1415. if(td_ad_background_click_target == '_blank') {
  1416. //open in a new window
  1417. window.open(td_ad_background_click_link)
  1418. } else {
  1419. //open in the same window
  1420. location.href = td_ad_background_click_link;
  1421. }
  1422. }
  1423. }
  1424.  
  1425. //e.stopPropagation();
  1426. //stopBubble(event);
  1427. });
  1428. }
  1429.  
  1430.  
  1431. function stopBubble(e){
  1432. if(e && e.stopPropagation) {
  1433. e.stopPropagation();
  1434. } else {
  1435. window.event.cancelBubble=true;
  1436. }
  1437. }
  1438.  
  1439.  
  1440.  
  1441. /**
  1442. * reading cookies
  1443. * @param name
  1444. * @returns {*}
  1445. */
  1446. function td_read_site_cookie(name) {
  1447. var nameEQ = escape(name) + "=";
  1448. var ca = document.cookie.split(';');
  1449. for (var i = 0; i < ca.length; i++) {
  1450. var c = ca[i];
  1451. while (c.charAt(0) == ' ') c = c.substring(1, c.length);
  1452. if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
  1453. }
  1454. return null;
  1455. }
  1456.  
  1457.  
  1458. /**
  1459. *
  1460. * @param td_time_cookie_array
  1461. *
  1462. * @param[0]: name of the cookie
  1463. * @param[1]: value of the cookie
  1464. * @param[2]: expiration time
  1465. */
  1466. function td_set_cookies_life(td_time_cookie_array) {
  1467. var expiry = new Date();
  1468. expiry.setTime(expiry.getTime() + td_time_cookie_array[2]);
  1469.  
  1470. // Date()'s toGMTSting() method will format the date correctly for a cookie
  1471. document.cookie = td_time_cookie_array[0] + "=" + td_time_cookie_array[1] + "; expires=" + expiry.toGMTString() + "; path=/";
  1472. }
  1473.  
  1474.  
  1475.  
  1476. //get page width
  1477. function td_get_page_width() {
  1478. var x = 0;
  1479.  
  1480. if (self.innerHeight) {
  1481. x = self.innerWidth;
  1482.  
  1483. } else if (document.documentElement && document.documentElement.clientHeight) {
  1484. x = document.documentElement.clientWidth;
  1485.  
  1486. } else if (document.body) {
  1487. x = document.body.clientWidth;
  1488. }
  1489.  
  1490. return x;
  1491. }
  1492.  
  1493.  
  1494.  
  1495. //function to resize the height of the slide
  1496. function td_resize_slide(args) {
  1497. if(td_get_page_width() < 768) {
  1498. var slide_displayd = args.currentSlideNumber;
  1499.  
  1500.  
  1501. //console.log(args.sliderObject[0]);
  1502. //console.log(args.data.obj[0]);
  1503.  
  1504. var current_slider = jQuery(args.data.obj[0]).attr("id");
  1505.  
  1506. if(td_detect.is_ie8 === false) {
  1507. jQuery("#" + current_slider).css("overflow", "none");
  1508. jQuery("#" + current_slider + " .item").css("overflow", "visible");
  1509. }
  1510.  
  1511.  
  1512.  
  1513. var setHeight = 0;
  1514. setHeight = jQuery("#" + current_slider + "_item_" + slide_displayd).outerHeight(true);
  1515.  
  1516.  
  1517. jQuery("#" + current_slider + ", #" + current_slider + " .slider").css({
  1518. height: setHeight
  1519. });
  1520. }
  1521. }
  1522.  
  1523.  
  1524. //function to resize the height of the slide with jQuery.each() function
  1525. function td_resize_page_sliders() {
  1526. jQuery(document).find('.iosSlider.td_block_big_grid').each(function() {
  1527. var current_slider = jQuery(this).attr("id");
  1528.  
  1529. if(!td_detect.is_ie8) {
  1530. jQuery("#" + current_slider).css("overflow", "none");
  1531. jQuery("#" + current_slider + " .item").css("overflow", "visible");
  1532. }
  1533.  
  1534. var setHeight = 0;
  1535. setHeight = jQuery("#" + current_slider + "_item_1").outerHeight(true);
  1536.  
  1537. jQuery("#" + current_slider + ", #" + current_slider + " .slider").css({
  1538. height: setHeight
  1539. });
  1540. });
  1541. }
  1542.  
  1543. var td_loading_box = {
  1544.  
  1545. //array_colors: ['#ffffff', '#fafafa', '#ececec', '#dddddd', '#bfbfbf', '#9a9a9a', '#7e7e7e', '#636363'],//whiter -> darker
  1546.  
  1547. array_colors_temp: ['rgba(99, 99, 99, 0)', 'rgba(99, 99, 99, 0.05)', 'rgba(99, 99, 99, 0.08)', 'rgba(99, 99, 99, 0.2)', 'rgba(99, 99, 99, 0.3)', 'rgba(99, 99, 99, 0.5)', 'rgba(99, 99, 99, 0.6)', 'rgba(99, 99, 99, 1)'],//whiter -> darker
  1548.  
  1549. array_colors: [],
  1550.  
  1551. status_animation: 'stop',
  1552.  
  1553. //stop loading box
  1554. stop : function stop () {
  1555. td_loading_box.status_animation = 'stop';
  1556. //jQuery('.td-loader-gif').html("");
  1557. },
  1558.  
  1559.  
  1560. //init loading box
  1561. init : function init (color) {
  1562.  
  1563. var td_color_reg_exp = /^#[a-zA-Z0-9]{3,6}$/;
  1564. if(color && td_color_reg_exp.test(color)) {
  1565.  
  1566. var col_rgba = td_loading_box.hexToRgb(color);
  1567.  
  1568. var rgba_string = "rgba(" + col_rgba.r + ", " + col_rgba.g + ", " + col_rgba.b + ", ";
  1569.  
  1570. td_loading_box.array_colors[7] = rgba_string + " 1)";
  1571. td_loading_box.array_colors[6] = rgba_string + " 0.6)";
  1572. td_loading_box.array_colors[5] = rgba_string + " 0.5)";
  1573. td_loading_box.array_colors[4] = rgba_string + " 0.3)";
  1574. td_loading_box.array_colors[3] = rgba_string + " 0.2)";
  1575. td_loading_box.array_colors[2] = rgba_string + " 0.08)";
  1576. td_loading_box.array_colors[1] = rgba_string + " 0.05)";
  1577. td_loading_box.array_colors[0] = rgba_string + " 0)";
  1578.  
  1579. } else {
  1580. //default array
  1581. td_loading_box.array_colors = td_loading_box.array_colors_temp.slice(0);
  1582.  
  1583. }
  1584.  
  1585. if(td_loading_box.status_animation == 'stop') {
  1586. td_loading_box.status_animation = 'display';
  1587. this.render();
  1588. }
  1589. },
  1590.  
  1591.  
  1592. //create the animation
  1593. render: function render (color) {
  1594.  
  1595. //call the animation_display function
  1596. td_loading_box.animation_display('<div class="td-lb-box td-lb-box-1" style="background-color:' + td_loading_box.array_colors[0] + '"></div><div class="td-lb-box td-lb-box-2" style="background-color:' + td_loading_box.array_colors[1] + '"></div><div class="td-lb-box td-lb-box-3" style="background-color:' + td_loading_box.array_colors[2] + '"></div><div class="td-lb-box td-lb-box-4" style="background-color:' + td_loading_box.array_colors[3] + '"></div><div class="td-lb-box td-lb-box-5" style="background-color:' + td_loading_box.array_colors[4] + '"></div><div class="td-lb-box td-lb-box-6" style="background-color:' + td_loading_box.array_colors[5] + '"></div><div class="td-lb-box td-lb-box-7" style="background-color:' + td_loading_box.array_colors[6] + '"></div><div class="td-lb-box td-lb-box-8" style="background-color:' + td_loading_box.array_colors[7] + '"></div>');
  1597.  
  1598. //direction right
  1599. var temp_color_array = [td_loading_box.array_colors[0], td_loading_box.array_colors[1], td_loading_box.array_colors[2], td_loading_box.array_colors[3], td_loading_box.array_colors[4], td_loading_box.array_colors[5], td_loading_box.array_colors[6], td_loading_box.array_colors[7]];
  1600.  
  1601. td_loading_box.array_colors[0] = temp_color_array[7];
  1602. td_loading_box.array_colors[1] = temp_color_array[0];
  1603. td_loading_box.array_colors[2] = temp_color_array[1];
  1604. td_loading_box.array_colors[3] = temp_color_array[2];
  1605. td_loading_box.array_colors[4] = temp_color_array[3];
  1606. td_loading_box.array_colors[5] = temp_color_array[4];
  1607. td_loading_box.array_colors[6] = temp_color_array[5];
  1608. td_loading_box.array_colors[7] = temp_color_array[6];
  1609.  
  1610. if(td_loading_box.status_animation == 'display') {
  1611.  
  1612.  
  1613. setTimeout(td_loading_box.render, 40);
  1614. } else {
  1615. td_loading_box.animation_display('');
  1616. }
  1617. },
  1618.  
  1619.  
  1620. //display the animation
  1621. animation_display: function animation_display (animation_str) {
  1622. jQuery('.td-loader-gif').html(animation_str);
  1623. },
  1624.  
  1625.  
  1626. //converts hex to rgba
  1627. hexToRgb: function hexToRgb(hex) {
  1628. var result = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
  1629.  
  1630. return result ? {
  1631. r: parseInt(result[1], 16),
  1632. g: parseInt(result[2], 16),
  1633. b: parseInt(result[3], 16)
  1634. } : null;
  1635. }
  1636. }//td_loading_box.init();//td_loading_box.stop();
  1637.  
  1638. "use strict";
  1639.  
  1640. /* ----------------------------------------------------------------------------
  1641. blocks.js
  1642. --------------------------------------------------------------------------- */
  1643.  
  1644.  
  1645.  
  1646. /* ----------------------------------------------------------------------------
  1647. On load
  1648. */
  1649. jQuery().ready(function() {
  1650. td_on_ready_ajax_blocks();
  1651. });
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657. function td_on_ready_ajax_blocks() {
  1658.  
  1659.  
  1660. /* ----------------------------------------------------------------------------
  1661. AJAX pagination next
  1662. */
  1663. jQuery(".td-ajax-next-page").click(function(event){
  1664. event.preventDefault();
  1665.  
  1666. var current_block_obj = td_getBlockObjById(jQuery(this).data('td_block_id'));
  1667.  
  1668. if(jQuery(this).hasClass('ajax-page-disabled') || current_block_obj.is_ajax_running === true) {
  1669. return;
  1670. }
  1671.  
  1672. current_block_obj.is_ajax_running = true; // ajax is running and we're wayting for a reply from server
  1673.  
  1674. current_block_obj.td_current_page++;
  1675. td_ajax_do_block_request(current_block_obj, 'next');
  1676. });
  1677.  
  1678.  
  1679. /* ----------------------------------------------------------------------------
  1680. AJAX pagination prev
  1681. */
  1682. jQuery(".td_ajax-prev-page").click(function(event){
  1683. event.preventDefault();
  1684.  
  1685. var current_block_obj = td_getBlockObjById(jQuery(this).data('td_block_id'));
  1686.  
  1687. if(jQuery(this).hasClass('ajax-page-disabled') || current_block_obj.is_ajax_running === true) {
  1688. return;
  1689. }
  1690.  
  1691. current_block_obj.is_ajax_running = true; // ajax is running and we're wayting for a reply from server
  1692.  
  1693. current_block_obj.td_current_page--;
  1694. td_ajax_do_block_request(current_block_obj, 'back');
  1695. });
  1696.  
  1697.  
  1698. /* ----------------------------------------------------------------------------
  1699. AJAX pagination load more
  1700. */
  1701. jQuery(".td_ajax_load_more").click(function(event){
  1702. event.preventDefault();
  1703. if(jQuery(this).hasClass('ajax-page-disabled')) {
  1704. return;
  1705. }
  1706.  
  1707. var current_block_obj = td_getBlockObjById(jQuery(this).data('td_block_id'));
  1708.  
  1709. current_block_obj.td_current_page++;
  1710. td_ajax_do_block_request(current_block_obj, 'load_more');
  1711. });
  1712.  
  1713.  
  1714. /* ----------------------------------------------------------------------------
  1715. AJAX pagination infinite load
  1716. */
  1717. /*
  1718. jQuery('.td_ajax_infinite').waypoint(function(direction) {
  1719. if (direction === 'down') {
  1720. //console.log('loading');
  1721. var current_block_obj = td_getBlockObjById(jQuery(this).data('td_block_id'));
  1722.  
  1723. current_block_obj.td_current_page++;
  1724. td_ajax_do_block_request(current_block_obj, 'infinite_load');
  1725. }
  1726.  
  1727. }, { offset: '110%' });
  1728.  
  1729. */
  1730.  
  1731.  
  1732.  
  1733. /* ----------------------------------------------------------------------------
  1734. AJAX sub cat filter
  1735. */
  1736. jQuery(".ajax-sub-cat").click(function(event){ //click on an ajax category filter
  1737. event.preventDefault();
  1738.  
  1739.  
  1740. //get the current block id
  1741. var current_block_id = jQuery(this).data('td_block_id');
  1742.  
  1743.  
  1744. //destroy any iossliders to avoid bugs
  1745. jQuery('#' + current_block_id).find('.iosSlider').iosSlider('destroy');
  1746.  
  1747. //get current block
  1748. var current_block_obj = td_getBlockObjById(current_block_id);
  1749.  
  1750. //change cur cat
  1751. current_block_obj.td_cur_cat = jQuery(this).data('cat_id');
  1752.  
  1753. current_block_obj.td_current_page = 1;
  1754.  
  1755.  
  1756. //console.log(current_block_obj);
  1757.  
  1758. //do request
  1759. td_ajax_do_block_request(current_block_obj, 'pull_down');
  1760. });
  1761.  
  1762.  
  1763.  
  1764.  
  1765. /* ----------------------------------------------------------------------------
  1766. AJAX MEGA MENU
  1767. */
  1768.  
  1769.  
  1770.  
  1771. var td_mega_menu_last_link = '';
  1772.  
  1773. //it used to hook the mega menu categories
  1774. function td_ajax_sub_cat_mega_run(event) {
  1775.  
  1776. if (td_mega_menu_last_link != jQuery(this).attr('href')) {
  1777. event.preventDefault();
  1778. td_mega_menu_last_link = jQuery(this).attr('href');
  1779. } else {
  1780. td_mega_menu_last_link = '';
  1781. }
  1782.  
  1783.  
  1784. //get the current block id
  1785. var current_block_id = jQuery(this).data('td_block_id');
  1786.  
  1787. //get current block
  1788. var current_block_obj = td_getBlockObjById(current_block_id);
  1789.  
  1790.  
  1791. //change cur cat
  1792. current_block_obj.td_cur_cat = jQuery(this).data('cat_id');
  1793.  
  1794. current_block_obj.td_current_page = 1;
  1795.  
  1796. //do request - no append, no animation
  1797. td_ajax_do_block_request(current_block_obj, 'pull_down');
  1798. }
  1799.  
  1800. //on touch devices use click
  1801. if (td_detect.is_touch_device) {
  1802. jQuery(".ajax-sub-cat-mega").click(td_ajax_sub_cat_mega_run);
  1803. } else {
  1804. jQuery(".ajax-sub-cat-mega").hover(td_ajax_sub_cat_mega_run, function (event) {} );
  1805. }
  1806.  
  1807.  
  1808. } // end td_on_ready_ajax_blocks()
  1809.  
  1810.  
  1811.  
  1812. /**
  1813. * makes a ajax block request
  1814. * @param current_block_obj
  1815. * @param td_user_action - append the return content?
  1816. * @returns {string}
  1817. */
  1818. function td_ajax_do_block_request(current_block_obj, td_user_action) {
  1819.  
  1820. //console.log(current_block_obj);
  1821.  
  1822. //search the cache
  1823. var current_block_obj_signature = JSON.stringify(current_block_obj);
  1824. if (td_local_cache.exist(current_block_obj_signature)) {
  1825. //do the animation with cache hit = true
  1826. td_block_ajax_loading_start(current_block_obj, true, td_user_action);
  1827. td_ajax_block_process_response(td_local_cache.get(current_block_obj_signature), td_user_action);
  1828. return 'cache_hit'; //cache HIT
  1829. }
  1830.  
  1831.  
  1832. //cache miss - we make a full request! - cache hit - false
  1833. td_block_ajax_loading_start(current_block_obj, false, td_user_action);
  1834.  
  1835.  
  1836. var request_data = {
  1837. action: 'td_ajax_block',
  1838. td_atts: current_block_obj.atts,
  1839. td_cur_cat:current_block_obj.td_cur_cat,
  1840. td_block_id:current_block_obj.id,
  1841. td_column_number:current_block_obj.td_column_number,
  1842. td_current_page:current_block_obj.td_current_page,
  1843. block_type:current_block_obj.block_type,
  1844. td_user_action:current_block_obj.td_user_action
  1845. };
  1846.  
  1847. //console.log(request_data);
  1848.  
  1849. jQuery.ajax({
  1850. type: 'POST',
  1851. url: td_ajax_url,
  1852. cache:true,
  1853. data: request_data,
  1854. success: function(data, textStatus, XMLHttpRequest){
  1855. td_local_cache.set(current_block_obj_signature, data);
  1856. td_ajax_block_process_response(data, td_user_action);
  1857. },
  1858. error: function(MLHttpRequest, textStatus, errorThrown){
  1859. //console.log(errorThrown);
  1860. }
  1861. });
  1862. }
  1863.  
  1864.  
  1865. /**
  1866. * process the response from the ajax query (it also processes the responses stored in the cache)
  1867. * @param data
  1868. * @param td_user_action
  1869. */
  1870. function td_ajax_block_process_response(data, td_user_action) {
  1871.  
  1872. //read the server response
  1873. var td_reply_obj = jQuery.parseJSON(data); //get the data object
  1874.  
  1875.  
  1876. //console.log(td_reply_obj);
  1877. /*
  1878. td_data_object.td_block_id
  1879. td_data_object.td_data
  1880. td_data_object.td_cur_cat
  1881. */
  1882.  
  1883. jQuery('.sub-cat-' + td_reply_obj.td_block_id).removeClass('cur-sub-cat');
  1884. jQuery('#sub-cat-' + td_reply_obj.td_block_id + '-' + td_reply_obj.td_cur_cat).addClass('cur-sub-cat');
  1885.  
  1886.  
  1887. //load the content (in place or append)
  1888. if (td_user_action == 'load_more' || td_user_action == 'infinite_load') {
  1889. jQuery(td_reply_obj.td_data).addClass('animated_xxlong').appendTo('#' + td_reply_obj.td_block_id).addClass('fadeIn');
  1890. //jQuery(td_reply_obj.td_data).hide().appendTo('#' + td_reply_obj.td_block_id).fadeIn(1500); //we need long times :|
  1891. } else {
  1892. jQuery('#' + td_reply_obj.td_block_id).html(td_reply_obj.td_data); //in place
  1893. }
  1894.  
  1895.  
  1896. //hide or show prev
  1897. if (td_reply_obj.td_hide_prev === true) {
  1898. jQuery('#prev-page-' + td_reply_obj.td_block_id).addClass('ajax-page-disabled');
  1899. } else {
  1900. jQuery('#prev-page-' + td_reply_obj.td_block_id).removeClass('ajax-page-disabled');
  1901. }
  1902.  
  1903. //hide or show next
  1904. if (td_reply_obj.td_hide_next === true) {
  1905. jQuery('#next-page-' + td_reply_obj.td_block_id).addClass('ajax-page-disabled');
  1906. } else {
  1907. jQuery('#next-page-' + td_reply_obj.td_block_id).removeClass('ajax-page-disabled');
  1908. }
  1909.  
  1910.  
  1911. var current_block_obj = td_getBlockObjById(td_reply_obj.td_block_id);
  1912. if (current_block_obj.block_type === 'slide') {
  1913. //make the first slide active (to have caption)
  1914. jQuery('#' + td_reply_obj.td_block_id + ' .slide-wrap-active-first').addClass('slide-wrap-active');
  1915. }
  1916.  
  1917. current_block_obj.is_ajax_running = false; // finish the loading for this block
  1918.  
  1919.  
  1920. //loading effects
  1921. td_block_ajax_loading_end(td_reply_obj, current_block_obj, td_user_action);
  1922. }
  1923.  
  1924.  
  1925. /**
  1926. * loading start
  1927. * @param current_block_obj
  1928. * @param cache_hit
  1929. * @param td_user_action - the request type / infinite_load ?
  1930. */
  1931. function td_block_ajax_loading_start(current_block_obj, cache_hit, td_user_action) {
  1932.  
  1933. //get the element
  1934. var el_cur_td_block_inner = jQuery('#' + current_block_obj.id);
  1935.  
  1936. //remove the loader
  1937. jQuery('.td-loader-gif').remove(); //remove any remaining loaders
  1938.  
  1939. //remove animation classes
  1940. el_cur_td_block_inner.removeClass('fadeInRight fadeInLeft fadeInDown fadeInUp animated fadeIn');
  1941.  
  1942. //add overflow + fixed height
  1943. el_cur_td_block_inner.addClass('td_block_inner_overflow');
  1944. var td_tmp_block_height = el_cur_td_block_inner.height();
  1945. el_cur_td_block_inner.css('height', td_tmp_block_height);
  1946.  
  1947.  
  1948. //show the loader only if it's needed
  1949. if (cache_hit === true) {
  1950. el_cur_td_block_inner.stop();
  1951. } else {
  1952.  
  1953. if (td_user_action == 'load_more') {
  1954. // on load more
  1955. el_cur_td_block_inner.parent().append('<div class="td-loader-gif td-loader-gif-bottom td-loader-animation-start"></div>');
  1956. td_loading_box.init(current_block_obj.header_color ? current_block_obj.header_color : tds_theme_color_site_wide); //init the loading box
  1957. setTimeout(function(){
  1958. jQuery('.td-loader-gif').removeClass('td-loader-animation-start');
  1959. jQuery('.td-loader-gif').addClass('td-loader-animation-mid');
  1960. },50);
  1961.  
  1962.  
  1963. } else if (td_user_action != 'infinite_load') {
  1964. // anything else except infinite load
  1965.  
  1966. el_cur_td_block_inner.parent().append('<div class="td-loader-gif td-loader-animation-start"></div>');
  1967. td_loading_box.init(current_block_obj.header_color ? current_block_obj.header_color : tds_theme_color_site_wide); //init the loading box
  1968. setTimeout(function(){
  1969. jQuery('.td-loader-gif').removeClass('td-loader-animation-start');
  1970. jQuery('.td-loader-gif').addClass('td-loader-animation-mid');
  1971. },50);
  1972.  
  1973.  
  1974. el_cur_td_block_inner.stop();
  1975. el_cur_td_block_inner.fadeTo('500',0.1, 'easeInOutCubic');
  1976. }
  1977.  
  1978.  
  1979. }
  1980.  
  1981.  
  1982.  
  1983. //auto height => fixed height
  1984. var td_tmp_block_height = el_cur_td_block_inner.height();
  1985. el_cur_td_block_inner.css('height', td_tmp_block_height);
  1986.  
  1987.  
  1988.  
  1989. }
  1990.  
  1991.  
  1992. /**
  1993. * we have a reply from the ajax request
  1994. * @param td_reply_obj - the reply object that we got from the server, it's useful with infinite load
  1995. * @param current_block_obj
  1996. * @param td_user_action - infinite_load next back etc... what the user did to trigger the ajax call
  1997. */
  1998. function td_block_ajax_loading_end(td_reply_obj, current_block_obj, td_user_action) {
  1999.  
  2000. // remove the loader
  2001. jQuery('.td-loader-gif').removeClass('td-loader-animation-mid');
  2002. jQuery('.td-loader-gif').addClass('td-loader-animation-end');
  2003. setTimeout(function(){
  2004. jQuery('.td-loader-gif').remove();
  2005. //stop the loading box
  2006. td_loading_box.stop();
  2007. },400);
  2008.  
  2009.  
  2010.  
  2011.  
  2012. //get the current inner
  2013. var el_cur_td_block_inner = jQuery('#' + current_block_obj.id);
  2014.  
  2015.  
  2016. el_cur_td_block_inner.stop();
  2017.  
  2018.  
  2019.  
  2020. switch(td_user_action) {
  2021. case 'next':
  2022. el_cur_td_block_inner.addClass('animated fadeInRight');
  2023. break;
  2024. case 'back':
  2025. el_cur_td_block_inner.addClass('animated fadeInLeft');
  2026. break;
  2027.  
  2028. case 'pull_down':
  2029. el_cur_td_block_inner.addClass('animated fadeInDown');
  2030. break;
  2031.  
  2032. case 'mega_menu':
  2033. el_cur_td_block_inner.addClass('animated fadeInUp');
  2034. break;
  2035.  
  2036.  
  2037. case 'load_more':
  2038. //el_cur_td_block_inner.addClass('animated fadeIn');
  2039. break;
  2040.  
  2041.  
  2042. case 'infinite_load':
  2043. setTimeout(function(){
  2044. //refresh waypoints for infinit scroll td_infinite_loader
  2045. td_infinite_loader.compute_top_distances();
  2046. if (td_reply_obj.td_data != '') {
  2047. td_infinite_loader.enable_is_visible_callback(current_block_obj.id);
  2048. }
  2049. }, 500);
  2050.  
  2051.  
  2052. setTimeout(function(){
  2053. td_infinite_loader.compute_top_distances();
  2054. // load next page only if we have new data comming from the last ajax request
  2055. }, 1000);
  2056.  
  2057. setTimeout(function(){
  2058. td_infinite_loader.compute_top_distances();
  2059. }, 1500);
  2060. break;
  2061. }
  2062.  
  2063. if (td_detect.is_ie9 || td_detect.is_ie8) {
  2064. el_cur_td_block_inner.css('opacity', 1);
  2065. }
  2066.  
  2067. setTimeout(function(){
  2068. jQuery('.td_block_inner_overflow').removeClass('td_block_inner_overflow');
  2069. el_cur_td_block_inner.css('height', 'auto');
  2070. },300);
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077. //td_infinite_loader.
  2078. }
  2079.  
  2080.  
  2081. /**
  2082. * search by block _id
  2083. * @param myID - block id
  2084. * @returns {number} the index
  2085. */
  2086. function td_getBlockIndex(myID) {
  2087. var cnt = 0;
  2088. var tmpReturn = 0;
  2089. jQuery.each(td_blocks, function(index, td_block) {
  2090. if (td_block.id === myID) {
  2091. tmpReturn = cnt;
  2092. return false; //brake jquery each
  2093. } else {
  2094. cnt++;
  2095. }
  2096. });
  2097. return tmpReturn;
  2098. }
  2099.  
  2100. /**
  2101. * gets the block object using a block ID
  2102. * @param myID
  2103. * @returns {*} block object
  2104. */
  2105. function td_getBlockObjById(myID) {
  2106. return td_blocks[td_getBlockIndex(myID)];
  2107. }
  2108.  
  2109.  
  2110.  
  2111. /*
  2112. * Sprite3D.js - v2.0.2
  2113. * https://github.com/boblemarin/Sprite3D.js
  2114. *
  2115. * Copyright (c) 2010 boblemarin [email protected] http://www.minimal.be
  2116. *
  2117. * Permission is hereby granted, free of charge, to any person
  2118. * obtaining a copy of this software and associated documentation
  2119. * files (the "Software"), to deal in the Software without
  2120. * restriction, including without limitation the rights to use,
  2121. * copy, modify, merge, publish, distribute, sublicense, and/or sell
  2122. * copies of the Software, and to permit persons to whom the
  2123. * Software is furnished to do so, subject to the following
  2124. * conditions:
  2125. *
  2126. * The above copyright notice and this permission notice shall be
  2127. * included in all copies or substantial portions of the Software.
  2128. *
  2129. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  2130. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
  2131. * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  2132. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
  2133. * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
  2134. * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  2135. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  2136. * OTHER DEALINGS IN THE SOFTWARE.
  2137. */
  2138.  
  2139.  
  2140. /*
  2141. Modified by tagDiv 2014 - modifications are Copyright tagDiv
  2142. */
  2143.  
  2144.  
  2145. "use strict";
  2146.  
  2147. var Sprite3D = Sprite3D || {
  2148.  
  2149.  
  2150. /********* [PUBLIC STATIC] isSupported() ***********/
  2151. /*
  2152. returns: Boolean
  2153. This method is automatically called when we create the first element,
  2154. but you can call it earlier if you want to provide an alternative content
  2155. to unsupported browsers.
  2156. */
  2157. isSupported: function(){
  2158. // init if needed
  2159. if ( !this._isInit ) this._init();
  2160. // return support value
  2161. return this._isSupported;
  2162. },
  2163.  
  2164. /********* [PUBLIC STATIC] stage() ***********/
  2165. /*
  2166. Creates a root container for your 3D content.
  2167.  
  2168. Usage 1 :
  2169. Sprite3D.stage()
  2170.  
  2171. Creates and returns a new <div> element that is added to the page.
  2172. The stage is centered, so the position (0,0,0) is in the center of the window.
  2173. This is the easiest and most common way to start a project
  2174.  
  2175. Usage 2 :
  2176. Sprite3D.stage( document.querySelector("#myContainer") )
  2177.  
  2178. Uses an existing HTML element as root container. The element is only tweaked a bit,
  2179. adjusting a few transform-related CSS properties, as well as setting the CSS "position"
  2180. property to "relative" if it is "static".
  2181. This method gives you more freedom, but more responsabilities :)
  2182.  
  2183. */
  2184. stage: function(element) {
  2185. // init if needed
  2186. if ( !this._isInit ) this._init();
  2187. // tweak or create root element
  2188. var c,s;
  2189. if (element){
  2190. c = element;
  2191. s = element.style;
  2192. if(s.position === "static" ) s.position = "relative";
  2193. } else {
  2194. c = document.createElement("div");
  2195. s = c.style;
  2196. s[this._browserPrefix+"PerspectiveOrigin"] = "0 0";
  2197. s[this._browserPrefix+"TransformOrigin"] = "0 0";
  2198. s.position = "absolute";
  2199. s.top = "50%";
  2200. s.left = "50%";
  2201. s.margin = "0px";
  2202. s.padding = "0px";
  2203. document.body.appendChild(c);
  2204. }
  2205. s[this._browserPrefix+"Perspective"] = "800px";
  2206. s[this._browserPrefix+"Transform"] = "translateZ(0px)";
  2207. c = this.create(c);
  2208. // fix for the glitch problems under Safari6 / Mountain Lion
  2209. // (root container must NOT have its transform-style property set to "preserve-3d")
  2210. s[this._browserPrefix+"TransformStyle"] = "flat";
  2211. // end fix
  2212. return c;
  2213. },
  2214.  
  2215. /********* [PUBLIC STATIC] create() ***********/
  2216. /*
  2217. Creates a new Sprite3D element
  2218.  
  2219. Usage 1 :
  2220. Sprite3D.create()
  2221.  
  2222. Creates a <div> element and turn it into a
  2223.  
  2224. Usage 2 :
  2225. Sprite3D.create( document.querySelector("#myElement") )
  2226.  
  2227. Usage 3 :
  2228. Sprite3D.create( "#id" )
  2229. Sprite3D.create( "id" )
  2230.  
  2231. Usage 4 :
  2232. Sprite3D.create( ".class" )
  2233. Sprite3D.create( ".class1 class2" )
  2234.  
  2235. */
  2236. create: function(element){
  2237. // init Sprite3D if needed
  2238. if ( !this._isInit ) this._init();
  2239.  
  2240. // create or tweak html element
  2241. if ( arguments.length === 0 ) {
  2242. element = document.createElement("div");
  2243. element.style.margin = "0px";
  2244. element.style.padding = "0px";
  2245. element.style.position = "absolute";
  2246. } else if ( typeof(element) === "string" ) {
  2247. var str = element;
  2248. element = document.createElement("div");
  2249. element.style.margin = "0px";
  2250. element.style.padding = "0px";
  2251. element.style.position = "absolute";
  2252. this._handleStringArgument(element,str);
  2253. } else if ( element.style.position == "static" ) {
  2254. element.style.position = "relative";
  2255. }
  2256. element.style[ this._browserPrefix + "TransformStyle" ] = "preserve-3d";
  2257. element.style[ this._transformProperty ] = "translateZ(0px)";
  2258.  
  2259. // extend element with 3D methods
  2260. for(var prop in this._props) {
  2261. if (this._props.hasOwnProperty(prop)){
  2262. element[prop] = this._props[prop];
  2263. }
  2264. }
  2265.  
  2266. // add private properties
  2267. element._string = [
  2268. "translate3d(", 0, "px,", 0, "px,", 0, "px) ",
  2269. "rotateX(", 0, "deg) ",
  2270. "rotateY(", 0, "deg) ",
  2271. "rotateZ(", 0, "deg) ",
  2272. "scale3d(", 1, ", ", 1, ", ", 1, ") "
  2273. ];
  2274. element._positions = [
  2275. 1, 3, 5, // x, y, z
  2276. 8, 11, 14, // rotationX, rotationY, rotationZ
  2277. 17, 19, 21 // scaleX, scaleY, scaleZ
  2278. ];
  2279. element._ox = 0;
  2280. element._oy = 0;
  2281. element._oz = 0;
  2282.  
  2283. // return
  2284. return element;
  2285. },
  2286.  
  2287. /********* [PUBLIC STATIC] box() ***********/
  2288. box: function(width,height,depth,idOrClassName) {
  2289. // init if needed
  2290. if ( !this._isInit ) this._init();
  2291.  
  2292. // create container element
  2293. var box = this.create();
  2294.  
  2295. if ( arguments.length === 1 ) {
  2296. height = width;
  2297. depth = width;
  2298. } else if ( arguments.length === 2 && typeof(arguments[1]) === "string" ) {
  2299. this._handleStringArgument(box,arguments[1]);
  2300. height = width;
  2301. depth = width;
  2302. } else if ( idOrClassName && typeof(idOrClassName) === "string" ) {
  2303. this._handleStringArgument(box,idOrClassName);
  2304. }
  2305.  
  2306. // add faces
  2307. var hwidth = width*.5,
  2308. hheight = height*.5,
  2309. hdepth = depth*.5;
  2310.  
  2311. box.appendChild( Sprite3D.create(".front").position( -hwidth, -hheight, hdepth).size(width,height).update() );
  2312. box.appendChild( Sprite3D.create(".back").position( -hwidth, -hheight, -hdepth).size(width,height).rotationY(180).update() );
  2313. box.appendChild( Sprite3D.create(".left").position( -hwidth-hdepth, -hheight, 0).size(depth,height).rotationY(-90).update() );
  2314. box.appendChild( Sprite3D.create(".right").position( hwidth-hdepth, -hheight, 0).size(depth,height).rotationY(90).update() );
  2315. box.appendChild( Sprite3D.create(".bottom").position( -hwidth, hheight-hdepth, 0).size(width,depth).rotationX(-90).update() );
  2316. box.appendChild( Sprite3D.create(".top").position( -hwidth, -hheight-hdepth, 0).size(width,depth).rotationX(90).update() );
  2317.  
  2318. return box;
  2319. },
  2320.  
  2321. /********* [PUBLIC STATIC] prefix() ***********/
  2322. prefix: function(cssPropertyName) {
  2323. return Sprite3D._browserPrefix + cssPropertyName;
  2324. },
  2325.  
  2326. /********* [PRIVATE STATIC] library's global properties ***********/
  2327. _isInit: false,
  2328. _isSupported: false,
  2329. _browserPrefix: "webkit",
  2330. _transformProperty: "webkitTransform",
  2331.  
  2332. /********* [PRIVATE STATIC] _init() ***********/
  2333. _init: function(){
  2334. var d = document.createElement("div"),
  2335. prefixes = ["", "webkit", "Moz", "O", "ms" ],
  2336. n = prefixes.length, i;
  2337.  
  2338. Sprite3D._isInit = true;
  2339. // check for 3D transforms
  2340. for( i = 0; i < n; i++ ) {
  2341. if ( ( prefixes[i] + "Perspective" ) in d.style ) {
  2342. Sprite3D._transformProperty = prefixes[i] + "Transform";
  2343. Sprite3D._isSupported = true;
  2344. Sprite3D._browserPrefix = prefixes[i];
  2345. if ( i==2 ) Sprite3D._props.update = Sprite3D._props.updateJoin;
  2346. //console.log( "Sprite3D found support for 3D transforms using prefix: " + prefixes[i] );
  2347. return true;
  2348. }
  2349. }
  2350.  
  2351. // no transform support
  2352. alert("Sorry, but your browser does not support CSS 3D transfroms.");
  2353. return false;
  2354. },
  2355.  
  2356. /********* [PRIVATE STATIC] _handleStringArgument() ***********/
  2357. _handleStringArgument: function( element, str ){
  2358. switch( str[0] ) {
  2359. case ".":
  2360. element.className = str.substr(1);
  2361. break;
  2362. case "#":
  2363. element.id = str.substr(1);
  2364. break;
  2365. default:
  2366. element.id = str;
  2367. break;
  2368. }
  2369. },
  2370.  
  2371. /********* Sprite3D objects properties ***********/
  2372. _props: {
  2373.  
  2374. /////////////////////////////////////////////
  2375. //////////// Position / absolute ////////////
  2376. /////////////////////////////////////////////
  2377. x : function(px) {
  2378. if ( arguments.length ) {
  2379. this._string[this._positions[0]] = px - this._ox;
  2380. return this;
  2381. } else {
  2382. return this._string[this._positions[0]] + this._ox;
  2383. }
  2384. },
  2385. y : function(py) {
  2386. if ( arguments.length ) {
  2387. this._string[this._positions[1]] = py - this._oy;
  2388. return this;
  2389. } else {
  2390. return this._string[this._positions[1]] + this._oy;
  2391. }
  2392. },
  2393. z : function(pz) {
  2394. if ( arguments.length ) {
  2395. this._string[this._positions[2]] = pz - this._oz;
  2396. return this;
  2397. } else {
  2398. return this._string[this._positions[2]] + this._oz;
  2399. }
  2400. },
  2401. position : function( px, py, pz) {
  2402. this._string[this._positions[0]] = px - this._ox;
  2403. this._string[this._positions[1]] = py - this._oy;
  2404. if ( arguments.length >= 3 ) this._string[this._positions[2]] = pz - this._oz;
  2405. return this;
  2406. },
  2407.  
  2408. /////////////////////////////////////////////
  2409. //////////// Position / relative ////////////
  2410. /////////////////////////////////////////////
  2411. move : function(px,py,pz) {
  2412. this._string[this._positions[0]] += px;
  2413. this._string[this._positions[1]] += py;
  2414. if ( arguments.length >= 3 ) this._string[this._positions[2]] += pz;
  2415. return this;
  2416. },
  2417.  
  2418. /////////////////////////////////////////////
  2419. //////////// Rotation / absolute ////////////
  2420. /////////////////////////////////////////////
  2421. rotationX : function(rx) {
  2422. if ( arguments.length ) {
  2423. this._string[this._positions[3]] = rx;
  2424. return this;
  2425. } else {
  2426. return this._string[this._positions[3]];
  2427. }
  2428. },
  2429. rotationY : function(ry) {
  2430. if ( arguments.length ) {
  2431. this._string[this._positions[4]] = ry;
  2432. return this;
  2433. } else {
  2434. return this._string[this._positions[4]];
  2435. }
  2436. },
  2437. rotationZ : function(rz) {
  2438. if ( arguments.length ) {
  2439. this._string[this._positions[5]] = rz;
  2440. return this;
  2441. } else {
  2442. return this._string[this._positions[5]];
  2443. }
  2444. },
  2445. rotation : function(rx,ry,rz) {
  2446. this._string[this._positions[3]] = rx;
  2447. this._string[this._positions[4]] = ry;
  2448. this._string[this._positions[5]] = rz;
  2449. return this;
  2450. },
  2451.  
  2452. /////////////////////////////////////////////
  2453. //////////// Rotation / relative ////////////
  2454. /////////////////////////////////////////////
  2455. rotate : function(rx,ry,rz) {
  2456. this._string[this._positions[3]] += rx;
  2457. this._string[this._positions[4]] += ry;
  2458. this._string[this._positions[5]] += rz;
  2459. return this;
  2460. },
  2461.  
  2462. /////////////////////////////////////////////
  2463. ///////////////// Scale //////////////////
  2464. /////////////////////////////////////////////
  2465. scaleX : function(sx) {
  2466. if ( arguments.length ) {
  2467. this._string[this._positions[6]] = sx;
  2468. return this;
  2469. } else {
  2470. return this._string[this._positions[6]];
  2471. }
  2472. },
  2473. scaleY : function(sy) {
  2474. if ( arguments.length ) {
  2475. this._string[this._positions[7]] = sy;
  2476. return this;
  2477. } else {
  2478. return this._string[this._positions[7]];
  2479. }
  2480. },
  2481. scaleZ : function(sz) {
  2482. if ( arguments.length ) {
  2483. this._string[this._positions[8]] = sz;
  2484. return this;
  2485. } else {
  2486. return this._string[this._positions[8]];
  2487. }
  2488. },
  2489. scale : function(sx,sy,sz) {
  2490. switch(arguments.length){
  2491. case 0:
  2492. return this._string[this._positions[6]];
  2493. case 1:
  2494. this._string[this._positions[6]] = sx;
  2495. this._string[this._positions[7]] = sx;
  2496. this._string[this._positions[8]] = sx;
  2497. return this;
  2498. case 2:
  2499. this._string[this._positions[6]] = sx;
  2500. this._string[this._positions[7]] = sy;
  2501. //this._string[this._positions[8]] = 1;
  2502. return this;
  2503. case 3:
  2504. this._string[this._positions[6]] = sx;
  2505. this._string[this._positions[7]] = sy;
  2506. this._string[this._positions[8]] = sz;
  2507. return this;
  2508. }
  2509. return this;
  2510. },
  2511.  
  2512. /////////////////////////////////////////////
  2513. ///////////////// Origin //////////////////
  2514. /////////////////////////////////////////////
  2515. origin : function(ox,oy,oz) {
  2516. // failed attempt at auto-centering the registration point of the object
  2517. if ( typeof(ox) === "string" ) {
  2518. /*
  2519. switch(ox){
  2520. case "center":
  2521. this._string[this._positions[0]] = -this.offsetWidth>>1;
  2522. this._string[this._positions[1]] = -this.offsetHeight>>1;
  2523. debugger
  2524. console.log("centering");
  2525. break;
  2526. }
  2527. */
  2528. var cs = window.getComputedStyle(this,null);
  2529. console.log(cs);
  2530. console.log("w:"+ cs.getPropertyValue("width") + " || h: " + cs.height );
  2531. } else {
  2532. if (arguments.length<3) oz = 0;
  2533. this._string[this._positions[0]] += this._ox - ox;
  2534. this._string[this._positions[1]] += this._oy - oy;
  2535. this._string[this._positions[2]] += this._oz - oz;
  2536. this._ox = ox;
  2537. this._oy = oy;
  2538. this._oz = oz;
  2539. }
  2540. return this;
  2541. },
  2542.  
  2543. /////////////////////////////////////////////
  2544. //////////// Transform Origin /////////////
  2545. /////////////////////////////////////////////
  2546. transformOrigin : function(tx,ty) {
  2547. this.style[ Sprite3D._browserPrefix + "TransformOrigin" ] = (Number(tx)?tx+"px":tx) + " " + (Number(ty)?ty+"px":ty);
  2548. return this;
  2549. },
  2550.  
  2551. /////////////////////////////////////////////
  2552. //////////// Transform String /////////////
  2553. /////////////////////////////////////////////
  2554. transformString : function(s) {
  2555. var parts = s.toLowerCase().split(" "),
  2556. numParts = parts.length,
  2557. i = 0,
  2558. strings = [],
  2559. positions = [ 0,0,0, 0,0,0, 0,0,0 ],
  2560. n = 0;
  2561.  
  2562. for(i;i<numParts;i++){
  2563. switch( parts[i] ){
  2564. case "p":
  2565. case "position":
  2566. case "translate":
  2567. // todo: use rx ry rz (regPoint) when re-defining transform order
  2568. n = strings.push( "translate3d(", this._string[this._positions[0]], "px,", this._string[this._positions[1]], "px,", this._string[this._positions[2]], "px) " );
  2569. positions[0] = n-6;
  2570. positions[1] = n-4;
  2571. positions[2] = n-2;
  2572. break;
  2573. case "rx":
  2574. case "rotatex":
  2575. case "rotationx":
  2576. n = strings.push( "rotateX(", this._string[this._positions[3]], "deg) " );
  2577. positions[3] = n-2;
  2578. break;
  2579. case "ry" :
  2580. case "rotatey":
  2581. case "rotationy":
  2582. n = strings.push( "rotateY(", this._string[this._positions[4]], "deg) " );
  2583. positions[4] = n-2;
  2584. break;
  2585. case "rz":
  2586. case "rotatez":
  2587. case "rotationz":
  2588. n = strings.push( "rotateZ(", this._string[this._positions[5]], "deg) " );
  2589. positions[5] = n-2;
  2590. break;
  2591. case "s":
  2592. case "scale":
  2593. n = strings.push( "scale3d(", this._string[this._positions[6]], ",", this._string[this._positions[7]], ",", this._string[this._positions[8]], ") " );
  2594. positions[6] = n-6;
  2595. positions[7] = n-4;
  2596. positions[8] = n-2;
  2597. break;
  2598. }
  2599. }
  2600.  
  2601. this._string = strings;
  2602. this._positions = positions;
  2603.  
  2604. return this;
  2605. },
  2606.  
  2607. /////////////////////////////////////////////
  2608. ///////////////// Update //////////////////
  2609. /////////////////////////////////////////////
  2610. updateJoin : function(){
  2611. this.style[Sprite3D._transformProperty] = this._string.join("");
  2612. return this;
  2613. },
  2614.  
  2615. update : function(){
  2616. var s = "";
  2617. this._string.every( function(value){ s += value; return true; } );
  2618. this.style[Sprite3D._transformProperty] = s;
  2619. return this;
  2620. },
  2621.  
  2622. /////////////////////////////////////////////
  2623. //////////// Helper Functions //////////////
  2624. /////////////////////////////////////////////
  2625.  
  2626. //////////// Perspective helper function ////////////
  2627. perspective : function(value) {
  2628. switch(arguments.length) {
  2629. case 0:
  2630. return this.style[Sprite3D._browserPrefix + "Perspective"];
  2631.  
  2632. case 1:
  2633. this.style[Sprite3D._browserPrefix + "Perspective"] = (typeof(value)==="string")?value:value+"px";
  2634. return this;
  2635. }
  2636. },
  2637.  
  2638. //////////// CSS helper function ////////////
  2639. css : function(name, value) {
  2640. switch(arguments.length) {
  2641. case 0:
  2642. return this.style;
  2643. case 1:
  2644. return this.style[name];
  2645. case 2:
  2646. this.style[name] = value;
  2647. return this;
  2648. case 3:
  2649. this.style[Sprite3D._browserPrefix + name] = value;
  2650. return this;
  2651. }
  2652. },
  2653.  
  2654. //////////// Class names helper functions ////////////
  2655. addClass : function(name) {
  2656. this.classList.add(name);
  2657. return this;
  2658. },
  2659.  
  2660. removeClass : function(name) {
  2661. this.classList.remove(name);
  2662. return this;
  2663. },
  2664.  
  2665. //////////// HTML helper function ////////////
  2666. html : function(value) {
  2667. if (arguments.length){
  2668. this.innerHTML = value;
  2669. return this;
  2670. }else{
  2671. return this.innerHTML;
  2672. }
  2673. return this;
  2674. },
  2675.  
  2676. //////////// SIZE helper function ////////////
  2677. size: function(width, height){
  2678. this.style.width = Number(width)?width+"px":width;
  2679. this.style.height = Number(height)?height+"px":height;
  2680. return this;
  2681. },
  2682.  
  2683. //////////// BIND helper function ////////////
  2684. bind: function(events){
  2685. if(typeof(events)==="object"){
  2686. for( var i in events ){
  2687. this.addEventListener( i, events[i], false );
  2688. }
  2689. } else if(arguments.length===2) {
  2690. this.addEventListener( arguments[0], arguments[1], false );
  2691. } else if(arguments.length===3) {
  2692. this.addEventListener( arguments[0], arguments[1], arguments[2] );
  2693. }
  2694. return this;
  2695. },
  2696.  
  2697. //////////// UNBIND helper function ////////////
  2698. unbind: function(events){
  2699. if(typeof(events)==="object"){
  2700. for( var i in events ){
  2701. this.removeEventListener( i, events[i], false );
  2702. }
  2703. } else if(arguments.length===2) {
  2704. this.removeEventListener( arguments[0], arguments[1], false );
  2705. }
  2706. return this;
  2707. },
  2708.  
  2709. //////////// Spritesheet helper functions ////////////
  2710. tileWidth: 0,
  2711. tileHeight: 0,
  2712. tileSize : function(width, height) {
  2713. this.tileWidth = width;
  2714. this.tileHeight = height;
  2715. return this;
  2716. },
  2717. tilePosition : function(tilePosX, tilePosY) {
  2718. this.style.backgroundPosition = "-" + (tilePosX * this.tileWidth) + "px -" + (tilePosY * this.tileHeight) + "px";
  2719. return this;
  2720. },
  2721.  
  2722. //////////// Generic setter for chaining ////////////
  2723. set : function(name, value) {
  2724. this[name] = value;
  2725. return this;
  2726. }
  2727.  
  2728. }
  2729. };
  2730.  
  2731. /**
  2732. * td_events.js - handles the events that requiere throttling
  2733. * Created by ra on 6/27/14.
  2734. * v1.1
  2735. */
  2736.  
  2737. var td_events = {
  2738.  
  2739. //the events - we have timers that look at the variables and fire the event if the flag is true
  2740. scroll_event_slow_run: false,
  2741. scroll_event_medium_run: false,
  2742. resize_event_run: false, //when true, fire up the resize event
  2743.  
  2744.  
  2745.  
  2746. scroll_window_scrollTop: 0, //used to store the scrollTop
  2747.  
  2748. init: function init() {
  2749.  
  2750. jQuery(window).scroll(function() {
  2751. td_events.scroll_event_slow_run = true;
  2752. td_events.scroll_event_medium_run = true;
  2753.  
  2754. //read the scroll top
  2755. td_events.scroll_window_scrollTop = jQuery(window).scrollTop();
  2756.  
  2757. /* ----------------------------------------------------------------------------
  2758. Run affix menu event
  2759. */
  2760. td_affix.td_events_scroll(td_events.scroll_window_scrollTop); //main menu
  2761. });
  2762.  
  2763.  
  2764. jQuery(window).resize(function() {
  2765. td_events.resize_event_run = true;
  2766. });
  2767.  
  2768.  
  2769.  
  2770. //medium resolution timer for rest?
  2771. setInterval(function() {
  2772. //scroll event
  2773. if (td_events.scroll_event_medium_run) {
  2774. td_events.scroll_event_medium_run = false;
  2775. //compute events for the infinite scroll
  2776. td_infinite_loader.compute_events();
  2777. }
  2778. }, 100);
  2779.  
  2780.  
  2781.  
  2782. //low resolution timer for rest?
  2783. setInterval(function() {
  2784. //scroll event
  2785. if (td_events.scroll_event_slow_run) {
  2786. td_events.scroll_event_slow_run = false;
  2787.  
  2788. //back to top
  2789. td_events_scroll_scroll_to_top(td_events.scroll_window_scrollTop);
  2790.  
  2791. //more articles box
  2792. td_more_articles_box.td_events_scroll(td_events.scroll_window_scrollTop);
  2793.  
  2794.  
  2795. }
  2796.  
  2797. //resize event
  2798. if (td_events.resize_event_run) {
  2799. td_events.resize_event_run = false;
  2800. td_affix.compute_top();
  2801. td_detect.run_is_phone_screen();
  2802. }
  2803. }, 500);
  2804.  
  2805. }
  2806.  
  2807.  
  2808.  
  2809. }
  2810.  
  2811. td_events.init();
  2812.  
  2813. "use strict";
  2814.  
  2815. /* ----------------------------------------------------------------------------
  2816. td_post_images.js
  2817. --------------------------------------------------------------------------- */
  2818.  
  2819.  
  2820.  
  2821. /* ----------------------------------------------------------------------------
  2822. On load
  2823. */
  2824. jQuery().ready(function() {
  2825. //handles the modal images
  2826. td_modal_image();
  2827.  
  2828. //move classes from post images to figure - td-post-image-full etc
  2829. //td_util.image_move_class_to_figure('td-post-image-full');
  2830. //td_util.image_move_class_to_figure('td-post-image-right');
  2831. //td_util.image_move_class_to_figure('td-post-image-left');
  2832.  
  2833.  
  2834.  
  2835.  
  2836. });
  2837.  
  2838.  
  2839.  
  2840.  
  2841.  
  2842.  
  2843.  
  2844.  
  2845.  
  2846. var td_modal_image_last_el = '';
  2847.  
  2848. // handles modal images for: Featured images, inline image, inline image with caption, galleries
  2849. function td_modal_image() {
  2850.  
  2851. //fix wordpress figure + figcaption (we move the figcaption in the data-caption attribute of the link)
  2852. jQuery('figure.wp-caption').each(function() {
  2853. var caption_text = jQuery(this).children('figcaption').html();
  2854. jQuery(this).children('a').data('caption', caption_text);
  2855. });
  2856.  
  2857. //move td-modal-image class to the parent a from the image. We can only add this class to the image via word press media editor
  2858. jQuery('.td-modal-image').each(function() {
  2859. jQuery(this).parent().addClass('td-modal-image');
  2860. jQuery(this).removeClass('td-modal-image');
  2861. });
  2862.  
  2863.  
  2864.  
  2865. //popup on modal images in articles
  2866. jQuery('article').magnificPopup({
  2867. type:'image',
  2868. delegate: ".td-modal-image",
  2869. gallery:{
  2870. enabled:true
  2871. },
  2872. image: {
  2873. tError: "<a href=\'%url%\'>The image #%curr%</a> could not be loaded.",
  2874. titleSrc: function(item) {//console.log(item.el);
  2875. //alert(jQuery(item.el).data("caption"));
  2876. var td_current_caption = jQuery(item.el).data('caption');
  2877. if (typeof td_current_caption != "undefined") {
  2878. return td_current_caption;
  2879. } else {
  2880. return '';
  2881. }
  2882.  
  2883.  
  2884. }
  2885. },
  2886. zoom: {
  2887. enabled: true,
  2888. duration: 300,
  2889. opener: function(element) {
  2890. return element.find("img");
  2891. }
  2892. },
  2893. callbacks: {
  2894. change: function(item) {
  2895. td_modal_image_last_el = item.el;
  2896. //setTimeout(function(){
  2897. td_util.scroll_into_view(item.el);
  2898. //}, 100);
  2899.  
  2900. },
  2901. beforeClose: function() {
  2902. td_util.scroll_into_view(td_modal_image_last_el);
  2903. }
  2904.  
  2905. }
  2906.  
  2907.  
  2908.  
  2909. });
  2910.  
  2911.  
  2912.  
  2913.  
  2914.  
  2915. //gallery popup
  2916. //detect jetpack carousel and disable the theme popup
  2917. if (typeof jetpackCarouselStrings === 'undefined') {
  2918.  
  2919. // copy gallery caption from figcaption to data-caption attribute of the link to the full image, in this way the modal can read the caption
  2920. jQuery('figure.gallery-item').each(function() {
  2921. var caption_text = jQuery(this).children('figcaption').html();
  2922. jQuery(this).find('a').data('caption', caption_text);
  2923. });
  2924.  
  2925.  
  2926.  
  2927. //jquery tiled gallery
  2928. jQuery('.tiled-gallery').magnificPopup({
  2929. type:'image',
  2930. delegate: "a",
  2931. gallery:{
  2932. enabled:true
  2933. },
  2934. image: {
  2935. tError: "<a href=\'%url%\'>The image #%curr%</a> could not be loaded.",
  2936. titleSrc: function(item) {//console.log(item.el);
  2937. var td_current_caption = jQuery(item.el).parent().find('.tiled-gallery-caption').text();
  2938. if (typeof td_current_caption != "undefined") {
  2939. return td_current_caption;
  2940. } else {
  2941. return '';
  2942. }
  2943. }
  2944. },
  2945. zoom: {
  2946. enabled: true,
  2947. duration: 300,
  2948. opener: function(element) {
  2949. return element.find("img");
  2950. }
  2951. },
  2952. callbacks: {
  2953. change: function(item) {
  2954. td_modal_image_last_el = item.el;
  2955. td_util.scroll_into_view(item.el);
  2956. },
  2957. beforeClose: function() {
  2958. td_util.scroll_into_view(td_modal_image_last_el);
  2959. }
  2960.  
  2961. }
  2962. });
  2963.  
  2964. }
  2965.  
  2966. } //end modal
  2967.  
  2968. /**
  2969. * Created by ra on 7/9/14.
  2970. */
  2971.  
  2972.  
  2973. /*
  2974. * tagDiv mods:
  2975. * - added the td-backstrach class
  2976. * - changed the backstretch.after event so that it dosn't wait for fade
  2977. */
  2978.  
  2979. /*
  2980. * Backstretch
  2981. * http://srobbin.com/jquery-plugins/backstretch/
  2982. *
  2983. * Copyright (c) 2013 Scott Robbin
  2984. * Licensed under the MIT license.
  2985. */
  2986.  
  2987. ;(function ($, window, undefined) {
  2988. 'use strict';
  2989.  
  2990. /* PLUGIN DEFINITION
  2991. * ========================= */
  2992.  
  2993. $.fn.backstretch = function (images, options) {
  2994. // We need at least one image or method name
  2995. if (images === undefined || images.length === 0) {
  2996. $.error("No images were supplied for Backstretch");
  2997. }
  2998.  
  2999. /*
  3000. * Scroll the page one pixel to get the right window height on iOS
  3001. * Pretty harmless for everyone else
  3002. */
  3003. if ($(window).scrollTop() === 0 ) {
  3004. window.scrollTo(0, 0);
  3005. }
  3006.  
  3007. return this.each(function () {
  3008. var $this = $(this)
  3009. , obj = $this.data('backstretch');
  3010.  
  3011. // Do we already have an instance attached to this element?
  3012. if (obj) {
  3013.  
  3014. // Is this a method they're trying to execute?
  3015. if (typeof images == 'string' && typeof obj[images] == 'function') {
  3016. // Call the method
  3017. obj[images](options);
  3018.  
  3019. // No need to do anything further
  3020. return;
  3021. }
  3022.  
  3023. // Merge the old options with the new
  3024. options = $.extend(obj.options, options);
  3025.  
  3026. // Remove the old instance
  3027. obj.destroy(true);
  3028. }
  3029.  
  3030. obj = new Backstretch(this, images, options);
  3031. $this.data('backstretch', obj);
  3032. });
  3033. };
  3034.  
  3035. // If no element is supplied, we'll attach to body
  3036. $.backstretch = function (images, options) {
  3037. // Return the instance
  3038. return $('body')
  3039. .backstretch(images, options)
  3040. .data('backstretch');
  3041. };
  3042.  
  3043. // Custom selector
  3044. $.expr[':'].backstretch = function(elem) {
  3045. return $(elem).data('backstretch') !== undefined;
  3046. };
  3047.  
  3048. /* DEFAULTS
  3049. * ========================= */
  3050.  
  3051. $.fn.backstretch.defaults = {
  3052. centeredX: true // Should we center the image on the X axis?
  3053. , centeredY: true // Should we center the image on the Y axis?
  3054. , duration: 5000 // Amount of time in between slides (if slideshow)
  3055. , fade: 0 // Speed of fade transition between slides
  3056. };
  3057.  
  3058. /* STYLES
  3059. *
  3060. * Baked-in styles that we'll apply to our elements.
  3061. * In an effort to keep the plugin simple, these are not exposed as options.
  3062. * That said, anyone can override these in their own stylesheet.
  3063. * ========================= */
  3064. var styles = {
  3065. wrap: {
  3066. left: 0
  3067. , top: 0
  3068. , overflow: 'hidden'
  3069. , margin: 0
  3070. , padding: 0
  3071. , height: '100%'
  3072. , width: '100%'
  3073. , zIndex: -999999
  3074. }
  3075. , img: {
  3076. position: 'absolute'
  3077. , display: 'none'
  3078. , margin: 0
  3079. , padding: 0
  3080. , border: 'none'
  3081. , width: 'auto'
  3082. , height: 'auto'
  3083. , maxHeight: 'none'
  3084. , maxWidth: 'none'
  3085. , zIndex: -999999
  3086. }
  3087. };
  3088.  
  3089. /* CLASS DEFINITION
  3090. * ========================= */
  3091. var Backstretch = function (container, images, options) {
  3092. this.options = $.extend({}, $.fn.backstretch.defaults, options || {});
  3093.  
  3094. /* In its simplest form, we allow Backstretch to be called on an image path.
  3095. * e.g. $.backstretch('/path/to/image.jpg')
  3096. * So, we need to turn this back into an array.
  3097. */
  3098. this.images = $.isArray(images) ? images : [images];
  3099.  
  3100. // Preload images
  3101. $.each(this.images, function () {
  3102. $('<img />')[0].src = this;
  3103. });
  3104.  
  3105. // Convenience reference to know if the container is body.
  3106. this.isBody = container === document.body;
  3107.  
  3108. /* We're keeping track of a few different elements
  3109. *
  3110. * Container: the element that Backstretch was called on.
  3111. * Wrap: a DIV that we place the image into, so we can hide the overflow.
  3112. * Root: Convenience reference to help calculate the correct height.
  3113. */
  3114. this.$container = $(container);
  3115. this.$root = this.isBody ? supportsFixedPosition ? $(window) : $(document) : this.$container;
  3116.  
  3117. // Don't create a new wrap if one already exists (from a previous instance of Backstretch)
  3118. var $existing = this.$container.children(".backstretch").first();
  3119. this.$wrap = $existing.length ? $existing : $('<div class="backstretch"></div>').css(styles.wrap).appendTo(this.$container);
  3120.  
  3121. // Non-body elements need some style adjustments
  3122. if (!this.isBody) {
  3123. // If the container is statically positioned, we need to make it relative,
  3124. // and if no zIndex is defined, we should set it to zero.
  3125. var position = this.$container.css('position')
  3126. , zIndex = this.$container.css('zIndex');
  3127.  
  3128. this.$container.css({
  3129. position: position === 'static' ? 'relative' : position
  3130. , zIndex: zIndex === 'auto' ? 0 : zIndex
  3131. , background: 'none'
  3132. });
  3133.  
  3134. // Needs a higher z-index
  3135. this.$wrap.css({zIndex: -999998});
  3136. }
  3137.  
  3138. // Fixed or absolute positioning?
  3139. this.$wrap.css({
  3140. position: this.isBody && supportsFixedPosition ? 'fixed' : 'absolute'
  3141. });
  3142.  
  3143. // Set the first image
  3144. this.index = 0;
  3145. this.show(this.index);
  3146.  
  3147. // Listen for resize
  3148. $(window).on('resize.backstretch', $.proxy(this.resize, this))
  3149. .on('orientationchange.backstretch', $.proxy(function () {
  3150. // Need to do this in order to get the right window height
  3151. if (this.isBody && window.pageYOffset === 0) {
  3152. window.scrollTo(0, 1);
  3153. this.resize();
  3154. }
  3155. }, this));
  3156. };
  3157.  
  3158. /* PUBLIC METHODS
  3159. * ========================= */
  3160. Backstretch.prototype = {
  3161. resize: function () {
  3162. try {
  3163. var bgCSS = {left: 0, top: 0}
  3164. , rootWidth = this.isBody ? this.$root.width() : this.$root.innerWidth()
  3165. , bgWidth = rootWidth
  3166. , rootHeight = this.isBody ? ( window.innerHeight ? window.innerHeight : this.$root.height() ) : this.$root.innerHeight()
  3167. , bgHeight = bgWidth / this.$img.data('ratio')
  3168. , bgOffset;
  3169.  
  3170. // Make adjustments based on image ratio
  3171. if (bgHeight >= rootHeight) {
  3172. bgOffset = (bgHeight - rootHeight) / 2;
  3173. if(this.options.centeredY) {
  3174. bgCSS.top = '-' + bgOffset + 'px';
  3175. }
  3176. } else {
  3177. bgHeight = rootHeight;
  3178. bgWidth = bgHeight * this.$img.data('ratio');
  3179. bgOffset = (bgWidth - rootWidth) / 2;
  3180. if(this.options.centeredX) {
  3181. bgCSS.left = '-' + bgOffset + 'px';
  3182. }
  3183. }
  3184.  
  3185. this.$wrap.css({width: rootWidth, height: rootHeight})
  3186. .find('img:not(.deleteable)').css({width: bgWidth, height: bgHeight}).css(bgCSS);
  3187. } catch(err) {
  3188. // IE7 seems to trigger resize before the image is loaded.
  3189. // This try/catch block is a hack to let it fail gracefully.
  3190. }
  3191.  
  3192. return this;
  3193. }
  3194.  
  3195. // Show the slide at a certain position
  3196. , show: function (newIndex) {
  3197.  
  3198. // Validate index
  3199. if (Math.abs(newIndex) > this.images.length - 1) {
  3200. return;
  3201. }
  3202.  
  3203. // Vars
  3204. var self = this
  3205. , oldImage = self.$wrap.find('img').addClass('deleteable')
  3206. , evtOptions = { relatedTarget: self.$container[0] };
  3207.  
  3208. // Trigger the "before" event
  3209. self.$container.trigger($.Event('backstretch.before', evtOptions), [self, newIndex]);
  3210.  
  3211. // Set the new index
  3212. this.index = newIndex;
  3213.  
  3214. // Pause the slideshow
  3215. clearInterval(self.interval);
  3216.  
  3217. // New image
  3218. self.$img = $('<img />')
  3219. .css(styles.img)
  3220. .addClass('td-backstretch')
  3221. .bind('load', function (e) {
  3222. var imgWidth = this.width || $(e.target).width()
  3223. , imgHeight = this.height || $(e.target).height();
  3224.  
  3225. // Save the ratio
  3226. $(this).data('ratio', imgWidth / imgHeight);
  3227.  
  3228. // Show the image, then delete the old one
  3229. // "speed" option has been deprecated, but we want backwards compatibilty
  3230. $(this).fadeIn(self.options.speed || self.options.fade, function () {
  3231. oldImage.remove();
  3232.  
  3233. // Resume the slideshow
  3234. if (!self.paused) {
  3235. self.cycle();
  3236. }
  3237.  
  3238.  
  3239. });
  3240.  
  3241. // Trigger the "after" and "show" events
  3242. // "show" is being deprecated
  3243. $(['after', 'show']).each(function () {
  3244. self.$container.trigger($.Event('backstretch.' + this, evtOptions), [self, newIndex]);
  3245. });
  3246.  
  3247. // Resize
  3248. self.resize();
  3249. })
  3250. .appendTo(self.$wrap);
  3251.  
  3252. // Hack for IE img onload event
  3253. self.$img.attr('src', self.images[newIndex]);
  3254. return self;
  3255. }
  3256.  
  3257. , next: function () {
  3258. // Next slide
  3259. return this.show(this.index < this.images.length - 1 ? this.index + 1 : 0);
  3260. }
  3261.  
  3262. , prev: function () {
  3263. // Previous slide
  3264. return this.show(this.index === 0 ? this.images.length - 1 : this.index - 1);
  3265. }
  3266.  
  3267. , pause: function () {
  3268. // Pause the slideshow
  3269. this.paused = true;
  3270. return this;
  3271. }
  3272.  
  3273. , resume: function () {
  3274. // Resume the slideshow
  3275. this.paused = false;
  3276. this.next();
  3277. return this;
  3278. }
  3279.  
  3280. , cycle: function () {
  3281. // Start/resume the slideshow
  3282. if(this.images.length > 1) {
  3283. // Clear the interval, just in case
  3284. clearInterval(this.interval);
  3285.  
  3286. this.interval = setInterval($.proxy(function () {
  3287. // Check for paused slideshow
  3288. if (!this.paused) {
  3289. this.next();
  3290. }
  3291. }, this), this.options.duration);
  3292. }
  3293. return this;
  3294. }
  3295.  
  3296. , destroy: function (preserveBackground) {
  3297. // Stop the resize events
  3298. $(window).off('resize.backstretch orientationchange.backstretch');
  3299.  
  3300. // Clear the interval
  3301. clearInterval(this.interval);
  3302.  
  3303. // Remove Backstretch
  3304. if(!preserveBackground) {
  3305. this.$wrap.remove();
  3306. }
  3307. this.$container.removeData('backstretch');
  3308. }
  3309. };
  3310.  
  3311. /* SUPPORTS FIXED POSITION?
  3312. *
  3313. * Based on code from jQuery Mobile 1.1.0
  3314. * http://jquerymobile.com/
  3315. *
  3316. * In a nutshell, we need to figure out if fixed positioning is supported.
  3317. * Unfortunately, this is very difficult to do on iOS, and usually involves
  3318. * injecting content, scrolling the page, etc.. It's ugly.
  3319. * jQuery Mobile uses this workaround. It's not ideal, but works.
  3320. *
  3321. * Modified to detect IE6
  3322. * ========================= */
  3323.  
  3324. var supportsFixedPosition = (function () {
  3325. var ua = navigator.userAgent
  3326. , platform = navigator.platform
  3327. // Rendering engine is Webkit, and capture major version
  3328. , wkmatch = ua.match( /AppleWebKit\/([0-9]+)/ )
  3329. , wkversion = !!wkmatch && wkmatch[ 1 ]
  3330. , ffmatch = ua.match( /Fennec\/([0-9]+)/ )
  3331. , ffversion = !!ffmatch && ffmatch[ 1 ]
  3332. , operammobilematch = ua.match( /Opera Mobi\/([0-9]+)/ )
  3333. , omversion = !!operammobilematch && operammobilematch[ 1 ]
  3334. , iematch = ua.match( /MSIE ([0-9]+)/ )
  3335. , ieversion = !!iematch && iematch[ 1 ];
  3336.  
  3337. return !(
  3338. // iOS 4.3 and older : Platform is iPhone/Pad/Touch and Webkit version is less than 534 (ios5)
  3339. ((platform.indexOf( "iPhone" ) > -1 || platform.indexOf( "iPad" ) > -1 || platform.indexOf( "iPod" ) > -1 ) && wkversion && wkversion < 534) ||
  3340.  
  3341. // Opera Mini
  3342. (window.operamini && ({}).toString.call( window.operamini ) === "[object OperaMini]") ||
  3343. (operammobilematch && omversion < 7458) ||
  3344.  
  3345. //Android lte 2.1: Platform is Android and Webkit version is less than 533 (Android 2.2)
  3346. (ua.indexOf( "Android" ) > -1 && wkversion && wkversion < 533) ||
  3347.  
  3348. // Firefox Mobile before 6.0 -
  3349. (ffversion && ffversion < 6) ||
  3350.  
  3351. // WebOS less than 3
  3352. ("palmGetResource" in window && wkversion && wkversion < 534) ||
  3353.  
  3354. // MeeGo
  3355. (ua.indexOf( "MeeGo" ) > -1 && ua.indexOf( "NokiaBrowser/8.5.0" ) > -1) ||
  3356.  
  3357. // IE6
  3358. (ieversion && ieversion <= 6)
  3359. );
  3360. }());
  3361.  
  3362. }(jQuery, window));
  3363.  
  3364. /**
  3365. * Created by ra on 7/8/14.
  3366. */
  3367.  
  3368. jQuery().ready(function() {
  3369.  
  3370.  
  3371.  
  3372.  
  3373. jQuery(window).on("backstretch.after", function (e, instance, index) {
  3374. td_template_single_1();
  3375. });
  3376. });
  3377.  
  3378.  
  3379. /**
  3380. * make td-post-template-6 title move down and blurry
  3381. */
  3382. function td_template_single_1() {
  3383. //run only on a post with template 6 on it
  3384. if(jQuery("#td-full-screen-header-image").length > 0) {
  3385.  
  3386.  
  3387. //define all the variables - for better performance ?
  3388. //var td_parallax_el = document.getElementById('td_parallax_header_6');
  3389.  
  3390. var td_parallax_bg_el = jQuery(".td-backstretch")[0];
  3391.  
  3392.  
  3393. //console.log(td_parallax_bg_el);
  3394. var scroll_from_top = '';
  3395. var distance_from_bottom;
  3396.  
  3397. //attach the animation tick on scroll
  3398. jQuery(window).scroll(function(){
  3399. // with each scroll event request an animation frame (we have a polyfill for animation frame)
  3400. // the requestAnimationFrame is called only once and after that we wait
  3401. td_request_tick();
  3402. });
  3403. }
  3404.  
  3405.  
  3406. var td_animation_running = false; //if the tick is running, we set this to true
  3407.  
  3408. function td_request_tick() {
  3409. if (td_animation_running === false) {
  3410. window.requestAnimationFrame(td_do_animation);
  3411. }
  3412. td_animation_running = true;
  3413. }
  3414.  
  3415. /**
  3416. * the animation loop
  3417. */
  3418. function td_do_animation() {
  3419. scroll_from_top = jQuery(document).scrollTop();
  3420. if (scroll_from_top <= 950) { //stop the animation after scroll from top
  3421.  
  3422. var blur_value = 1 - (scroll_from_top / 800); // @todo trebuie verificata formula??
  3423. if (td_detect.is_ie8 === true) {
  3424. blur_value = 1;
  3425. }
  3426.  
  3427.  
  3428. blur_value = Math.round(blur_value * 100) / 100;
  3429.  
  3430. //opacity
  3431. //td_parallax_el.style.opacity = blur_value;
  3432.  
  3433. //move the bg
  3434. var parallax_move = -Math.round(scroll_from_top / 4);
  3435. td_move_Y(td_parallax_bg_el,-parallax_move);
  3436.  
  3437.  
  3438. //move the title + cat
  3439. distance_from_bottom = -Math.round(scroll_from_top / 8);
  3440. //td_move_Y(td_parallax_el,-distance_from_bottom);
  3441. //td_parallax_el.style.bottom = distance_from_bottom + "px"; //un accelerated version
  3442.  
  3443.  
  3444. }
  3445.  
  3446. td_animation_running = false;
  3447. }
  3448.  
  3449.  
  3450. function td_move_Y (elm, value) {
  3451. var translate = 'translate3d(0px,' + value + 'px, 0px)';
  3452. elm.style['-webkit-transform'] = translate;
  3453. elm.style['-moz-transform'] = translate;
  3454. elm.style['-ms-transform'] = translate;
  3455. elm.style['-o-transform'] = translate;
  3456. elm.style.transform = translate;
  3457. }
  3458.  
  3459. }
  3460.  
  3461. /*
  3462. td_util.js
  3463. v1.1
  3464. */
  3465.  
  3466. "use strict";
  3467.  
  3468.  
  3469. /* ----------------------------------------------------------------------------
  3470. On load
  3471. */
  3472. jQuery().ready(function() {
  3473.  
  3474. /**
  3475. * Modal window js code
  3476. */
  3477. jQuery('.td-login-modal-js').magnificPopup({
  3478. type: 'inline',
  3479. preloader: false,
  3480. focus: '#name',
  3481. removalDelay: 500,
  3482.  
  3483. // When elemened is focused, some mobile browsers in some cases zoom in
  3484. // It looks not nice, so we disable it:
  3485. callbacks: {
  3486. beforeOpen: function() {
  3487.  
  3488.  
  3489. this.st.mainClass = this.st.el.attr('data-effect');
  3490.  
  3491.  
  3492. //empty all fields
  3493. td_modala_empty_all_fields();
  3494.  
  3495. //empty error display div
  3496. td_modala_empty_err_div();
  3497.  
  3498. if(jQuery(window).width() < 700) {
  3499. this.st.focus = false;
  3500. } else {
  3501. if (td_detect.is_ie === false) {
  3502. //do not focus on ie 10
  3503. this.st.focus = '#login_email';
  3504. }
  3505.  
  3506. }
  3507. },
  3508.  
  3509. beforeClose: function() {
  3510. }
  3511. }
  3512. });
  3513.  
  3514.  
  3515. //login
  3516. jQuery('#login-link').on( "click", function() {
  3517. //hides or shows the divs with inputs
  3518. show_hide_content_modala([['#td-login-div', 1], ['#td-register-div', 0], ['#td-forgot-pass-div', 0]]);
  3519.  
  3520. //moves focus on the tab
  3521. modala_swich_tabs([['#login-link', 1], ['#register-link', 0]]);
  3522.  
  3523. if(jQuery(window).width() > 700 && td_detect.is_ie === false) {
  3524. jQuery('#login_email').focus();
  3525. }
  3526.  
  3527. //empty all fields
  3528. //td_modala_empty_all_fields();
  3529.  
  3530. //empty error display div
  3531. td_modala_empty_err_div();
  3532. });
  3533. //login button
  3534. jQuery('#login_button').on( "click", function() {
  3535. handle_login_for_modal_window();
  3536. });
  3537. //enter key on #login_pass
  3538. jQuery('#login_pass').keydown(function(event) {
  3539. if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
  3540. handle_login_for_modal_window();
  3541. }
  3542. });
  3543.  
  3544. //register
  3545. jQuery('#register-link').on( "click", function() {
  3546. //hides or shows the divs with inputs
  3547. show_hide_content_modala([['#td-login-div', 0], ['#td-register-div', 1], ['#td-forgot-pass-div', 0]]);
  3548.  
  3549. //moves focus on the tab
  3550. modala_swich_tabs([['#login-link', 0], ['#register-link', 1]]);
  3551.  
  3552. if(jQuery(window).width() > 700 && td_detect.is_ie === false) {
  3553. jQuery('#register_email').focus();
  3554. }
  3555.  
  3556. //empty all fields
  3557. //td_modala_empty_all_fields();
  3558.  
  3559. //empty error display div
  3560. td_modala_empty_err_div();
  3561. });
  3562. //register button
  3563. jQuery('#register_button').on( "click", function() {
  3564. handle_register_for_modal_window();
  3565. });
  3566. //enter key on #register_user
  3567. jQuery('#register_user').keydown(function(event) {
  3568. if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
  3569. handle_register_for_modal_window();
  3570. }
  3571. });
  3572.  
  3573. //forgot pass
  3574. jQuery('#forgot-pass-link').on( "click", function() {
  3575. //hides or shows the divs with inputs
  3576. show_hide_content_modala([['#td-login-div', 0], ['#td-register-div', 0], ['#td-forgot-pass-div', 1]]);
  3577.  
  3578. //moves focus on the tab
  3579. modala_swich_tabs([['#login-link', 0], ['#register-link', 0]]);
  3580.  
  3581. if(jQuery(window).width() > 700 && td_detect.is_ie === false) {
  3582. jQuery('#forgot_email').focus();
  3583. }
  3584.  
  3585. //empty all fields
  3586. //td_modala_empty_all_fields();
  3587.  
  3588. //empty error display div
  3589. td_modala_empty_err_div();
  3590. });
  3591. //forgot button
  3592. jQuery('#forgot_button').on( "click", function() {
  3593. handle_forgot_password_for_modal_window();
  3594. });
  3595. //enter key on #forgot_email
  3596. jQuery('#forgot_email').keydown(function(event) {
  3597. if ((event.which && event.which == 13) || (event.keyCode && event.keyCode == 13)) {
  3598. handle_forgot_password_for_modal_window();
  3599. }
  3600. });
  3601.  
  3602.  
  3603. });//end jquery ready
  3604.  
  3605.  
  3606.  
  3607. //patern to check emails
  3608. var td_mod_pattern_email = /^[a-zA-Z0-9][a-zA-Z0-9_\.-]{0,}[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9_\.-]{0,}[a-z0-9][\.][a-z0-9]{2,4}$/;
  3609.  
  3610. /**
  3611. * handle all request made from login tab
  3612. */
  3613. function handle_login_for_modal_window() {
  3614. var login_email = jQuery('#login_email').val();
  3615. var login_pass = jQuery('#login_pass').val();
  3616.  
  3617. if(login_email && login_pass){
  3618. //empty error display div
  3619. //td_modala_empty_err_div();
  3620.  
  3621. modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
  3622. jQuery('.td_display_err').show();
  3623. td_modala_write_err_div(td_please_wait);
  3624.  
  3625. //call ajax for log in
  3626. td_modala_call_ajax('td_mod_login', login_email, '', login_pass);
  3627. } else {
  3628. jQuery('.td_display_err').show();
  3629. td_modala_write_err_div(td_email_user_pass_incorrect);
  3630. }
  3631. }
  3632.  
  3633. /**
  3634. * handle all request made from register tab
  3635. */
  3636. function handle_register_for_modal_window() {
  3637. var register_email = jQuery('#register_email').val();
  3638. var register_user = jQuery('#register_user').val();
  3639.  
  3640. if(td_mod_pattern_email.test(register_email) && register_user){
  3641. //empty error display div
  3642. //td_modala_empty_err_div();
  3643.  
  3644. modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
  3645. jQuery('.td_display_err').show();
  3646. td_modala_write_err_div(td_please_wait);
  3647.  
  3648. //call ajax
  3649. td_modala_call_ajax('td_mod_register', register_email, register_user, '');
  3650. } else {
  3651. jQuery('.td_display_err').show();
  3652. td_modala_write_err_div(td_email_user_incorrect);
  3653. }
  3654. }
  3655.  
  3656. /**
  3657. * handle all request made from forgot password tab
  3658. */
  3659. function handle_forgot_password_for_modal_window() {
  3660. var forgot_email = jQuery('#forgot_email').val();
  3661.  
  3662. if(td_mod_pattern_email.test(forgot_email)){
  3663. //empty error display div
  3664. //td_modala_empty_err_div();
  3665.  
  3666. modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
  3667. jQuery('.td_display_err').show();
  3668. td_modala_write_err_div(td_please_wait);
  3669.  
  3670. //call ajax
  3671. td_modala_call_ajax('td_mod_remember_pass', forgot_email, '', '');
  3672. } else {
  3673. jQuery('.td_display_err').show();
  3674. td_modala_write_err_div(td_email_incorrect);
  3675. }
  3676. }
  3677.  
  3678. /**
  3679. * swhich the div's acordingly to the user action (Log In, Register, Remember Password)
  3680. *
  3681. * ids_array : array of ids that have to be showed or hidden
  3682. */
  3683. function show_hide_content_modala(ids_array) {
  3684. var length = ids_array.length;
  3685.  
  3686. for (var i = 0; i < length; i++) {
  3687. var element_id = ids_array[i][0];
  3688. var element_visibility = ids_array[i][1];
  3689.  
  3690. if (element_visibility == 1) {
  3691. jQuery(element_id).removeClass('td-dispaly-none').addClass('td-dispaly-block');
  3692. } else {
  3693. jQuery(element_id).removeClass('td-dispaly-block').addClass('td-dispaly-none');
  3694. }
  3695. }
  3696. }
  3697.  
  3698.  
  3699. /**
  3700. * swhich the tab's acordingly to the user action (Log In, Register, Remember Password)
  3701. *
  3702. * ids_array : array of ids that have to be focus on or unfocus
  3703. */
  3704. function modala_swich_tabs(ids_array) {
  3705. var length = ids_array.length;
  3706.  
  3707. for (var i = 0; i < length; i++) {
  3708. var element_id = ids_array[i][0];
  3709. var element_visibility = ids_array[i][1];
  3710.  
  3711. if (element_visibility == 1) {
  3712. jQuery(element_id).addClass('td_login_tab_focus');
  3713. } else {
  3714. jQuery(element_id).removeClass('td_login_tab_focus');
  3715. }
  3716. }
  3717. }
  3718.  
  3719.  
  3720. /**
  3721. * adds or remove a class from an html object
  3722. *
  3723. * param : array with object identifier (id - # or class - .)
  3724. * ex: ['.class_indetifier', 1, 'class_to_add'] or ['.class_indetifier', 0, 'class_to_remove']
  3725. */
  3726. function modala_add_remove_class(param) {
  3727.  
  3728. //add class
  3729. if (param[1] == 1) {
  3730. jQuery(param[0]).addClass(param[2]);
  3731.  
  3732. //remove class
  3733. } else {
  3734. jQuery(param[0]).removeClass(param[2]);
  3735. }
  3736. }
  3737.  
  3738.  
  3739. /**
  3740. * empty the error div
  3741. */
  3742. function td_modala_empty_err_div() {
  3743. jQuery('.td_display_err').html('');
  3744. jQuery('.td_display_err').hide();
  3745. }
  3746.  
  3747.  
  3748. /**
  3749. * write text to error div
  3750. */
  3751. function td_modala_write_err_div(message) {
  3752. jQuery('.td_display_err').html(message);
  3753. }
  3754.  
  3755. /**
  3756. * empty all fields in modal window
  3757. */
  3758. function td_modala_empty_all_fields() {
  3759. //login fields
  3760. jQuery('#login_email').val('');
  3761. jQuery('#login_pass').val('');
  3762.  
  3763. //register fields
  3764. jQuery('#register_email').val('');
  3765. jQuery('#register_user').val('');
  3766.  
  3767. //forgot pass
  3768. jQuery('#forgot_email').val('');
  3769. }
  3770.  
  3771.  
  3772. /**
  3773. * call to server from modal window
  3774. *
  3775. * @param $action : what action (log in, register, forgot email)
  3776. * @param $email : the email beening sent
  3777. * @param $user : the user name beening sent
  3778. */
  3779. function td_modala_call_ajax(sent_action, sent_email, sent_user, sent_pass) {
  3780. jQuery.ajax({
  3781. type: 'POST',
  3782. url: td_ajax_url,
  3783. data: {
  3784. action: sent_action,
  3785. email: sent_email,
  3786. user: sent_user,
  3787. pass: sent_pass
  3788. },
  3789. success: function(data, textStatus, XMLHttpRequest){
  3790. var td_data_object = jQuery.parseJSON(data); //get the data object
  3791.  
  3792. //check the response from server
  3793. switch(td_data_object[0]) {
  3794. case 'login':
  3795. if(td_data_object[1] == 1) {
  3796. location.reload(true);
  3797. } else {
  3798. modala_add_remove_class(['.td_display_err', 0, 'td_display_msg_ok']);
  3799. jQuery('.td_display_err').show();
  3800. td_modala_write_err_div(td_data_object[2]);
  3801. }
  3802. break;
  3803.  
  3804. case 'register':
  3805. if(td_data_object[1] == 1) {
  3806. modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
  3807. jQuery('.td_display_err').show();
  3808. } else {
  3809. modala_add_remove_class(['.td_display_err', 0, "td_display_msg_ok"]);
  3810. jQuery('.td_display_err').show();
  3811. }
  3812. td_modala_write_err_div(td_data_object[2]);
  3813. break;
  3814.  
  3815. case 'remember_pass':
  3816. if(td_data_object[1] == 1) {
  3817. modala_add_remove_class(['.td_display_err', 1, "td_display_msg_ok"]);
  3818. jQuery('.td_display_err').show();
  3819. } else {
  3820. modala_add_remove_class(['.td_display_err', 0, "td_display_msg_ok"]);
  3821. jQuery('.td_display_err').show();
  3822. }
  3823. td_modala_write_err_div(td_data_object[2]);
  3824. break;
  3825.  
  3826. }
  3827.  
  3828.  
  3829. },
  3830. error: function(MLHttpRequest, textStatus, errorThrown){
  3831. //console.log(errorThrown);
  3832. }
  3833. });
  3834. }
  3835.  
  3836. /* ----------------------------------------------------------------------------
  3837. tagDiv live css compiler ( 2013 )
  3838. - this script is used on our demo site to customize the theme live
  3839. - not used on production sites
  3840. */
  3841.  
  3842.  
  3843. var td_style_buffer =
  3844. '<style> /* @theme_color */ .category .entry-content, .tag .entry-content, .td_quote_box { -webkit-transition: border-color 1s ease-in-out; -moz-transition: border-color 1s ease-in-out; -o-transition: border-color 1s ease-in-out; transition: border-color 1s ease-in-out; border-color: @theme_color; } .block-title a, .block-title span, .td-tags a:hover, .td-scroll-up-visible, .td-scroll-up, .sf-menu ul .current-menu-item > a, .sf-menu ul a:hover, .sf-menu ul .sfHover > a, .td-rating-bar-wrap div, .iosSlider .slide-meta-cat, .sf-menu ul .current-menu-ancestor > a, .td-404-sub-sub-title a, .widget_tag_cloud .tagcloud a:hover, .td-mobile-close a, ul.td-category a, .td_social .td_social_type .td_social_button a, .dropcap { -webkit-transition: background-color 1s ease-in-out; -moz-transition: background-color 1s ease-in-out; -o-transition: background-color 1s ease-in-out; transition: background-color 1s ease-in-out; background-color: @theme_color; } .block-title, .sf-menu li a:hover, .sf-menu .sfHover a, .sf-menu .current-menu-ancestor a, .header-search-wrap .dropdown-menu, .sf-menu > .current-menu-item > a, .ui-tabs-nav { -webkit-transition: border-color 1s ease-in-out; -moz-transition: border-color 1s ease-in-out; -o-transition: border-color 1s ease-in-out; transition: border-color 1s ease-in-out; border-color: @theme_color; } .author-box-wrap .td-author-name a, blockquote p, .page-nav a:hover, .widget_pages .current_page_item a, .widget_calendar td a, .widget_categories .current-cat > a, .widget_pages .current_page_parent > a, .td_pull_quote p { -webkit-transition: color 1s ease-in-out; -moz-transition: color 1s ease-in-out; -o-transition: color 1s ease-in-out; transition: color 1s ease-in-out; color: @theme_color; } .page-nav .current { -webkit-transition: background-color 1s ease-in-out; -moz-transition: background-color 1s ease-in-out; -o-transition: background-color 1s ease-in-out; transition: background-color 1s ease-in-out; background-color: @theme_color; border-color: @theme_color; } .wpb_btn-inverse, .ui-tabs-nav .ui-tabs-active a, .post .wpb_btn-danger, .form-submit input, .wpcf7-submit { -webkit-transition: background-color 1s ease-in-out; -moz-transition: background-color 1s ease-in-out; -o-transition: background-color 1s ease-in-out; transition: background-color 1s ease-in-out; background-color: @theme_color !important; } .header-search-wrap .dropdown-menu:before { -webkit-transition: border-color 1s ease-in-out; -moz-transition: border-color 1s ease-in-out; -o-transition: border-color 1s ease-in-out; transition: border-color 1s ease-in-out; border-color: transparent transparent @theme_color; } .td-mobile-content .current-menu-item > a, .td-mobile-content a:hover { -webkit-transition: color 1s ease-in-out; -moz-transition: color 1s ease-in-out; -o-transition: color 1s ease-in-out; transition: color 1s ease-in-out; color: @theme_color !important; } /* @slider_text */ .td-sbig-title-wrap .td-sbig-title, .td-slide-item-sec .td-sbig-title-wrap { -webkit-transition: background-color 1s ease-in-out; -moz-transition: background-color 1s ease-in-out; -o-transition: background-color 1s ease-in-out; transition: background-color 1s ease-in-out; background-color: @slider_text; } /* @select_color */ ::-moz-selection { background: @select_color; color: #fff; } ::selection { background: @select_color; color: #fff; } /* @link_color */ a, .widget_recent_comments .recentcomments .url { -webkit-transition: color 1s ease-in-out; -moz-transition: color 1s ease-in-out; -o-transition: color 1s ease-in-out; transition: color 1s ease-in-out; color: @link_color; } .cur-sub-cat { -webkit-transition: color 1s ease-in-out; -moz-transition: color 1s ease-in-out; -o-transition: color 1s ease-in-out; transition: color 1s ease-in-out; color:@link_color !important; } /* @link_hover_color */ a:hover, .widget_recent_comments .recentcomments .url:hover { -webkit-transition: color 1s ease-in-out; -moz-transition: color 1s ease-in-out; -o-transition: color 1s ease-in-out; transition: color 1s ease-in-out; color: @link_hover_color; } </style>';
  3845.  
  3846.  
  3847. var td_bg_boxed_imgs = [
  3848. 'http://demo.tagdiv.com/newspaper/bg_images/1.jpg',
  3849. 'http://demo.tagdiv.com/newspaper/bg_images/2.jpg',
  3850. 'http://demo.tagdiv.com/newspaper/bg_images/3.jpg'
  3851. ];
  3852.  
  3853.  
  3854. var td_current_panel_stat = td_read_cookie('td_show_panel');
  3855. if (td_current_panel_stat == 'show' || td_current_panel_stat == null) {
  3856. jQuery('.td-theme-settings-small').addClass('td-theme-settings-no-transition');
  3857. jQuery('.td-theme-settings-small').removeClass('td-theme-settings-small');
  3858. }
  3859.  
  3860.  
  3861.  
  3862.  
  3863. /* ----------------------------------------------------------------------------
  3864. On load
  3865. */
  3866. jQuery().ready(function() {
  3867.  
  3868. //hide panel
  3869. jQuery("#td-theme-set-hide").click(function(event){
  3870. event.preventDefault();
  3871. event.stopPropagation();
  3872. //hide
  3873. td_create_cookie('td_show_panel', 'hide', 1);
  3874. jQuery('#td-theme-settings').removeClass('td-theme-settings-no-transition');
  3875. jQuery('#td-theme-settings').addClass('td-theme-settings-small');
  3876.  
  3877.  
  3878. jQuery('.td-set-theme-style-link').removeClass('fadeInLeft');
  3879.  
  3880. });
  3881.  
  3882.  
  3883.  
  3884.  
  3885.  
  3886. //show panel
  3887. jQuery("#td-theme-settings").click(function(){
  3888. if (jQuery(this).hasClass('td-theme-settings-small')) {
  3889.  
  3890. jQuery('.td-set-theme-style-link').addClass('animated_xlong fadeInLeft');
  3891.  
  3892. //show full
  3893. td_create_cookie('td_show_panel', 'show', 1);
  3894. jQuery('.td-theme-settings-small').removeClass('td-theme-settings-small');
  3895. }
  3896. });
  3897.  
  3898.  
  3899.  
  3900.  
  3901.  
  3902. }); //end on load
  3903.  
  3904.  
  3905.  
  3906.  
  3907.  
  3908.  
  3909. /* ----------------------------------------------------------------------------
  3910. Support functions
  3911. */
  3912. //add trim for ie8
  3913. if (!String.prototype.trim) {
  3914. String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
  3915. }
  3916.  
  3917.  
  3918. function td_create_cookie(name, value, days) {
  3919. if (days) {
  3920. var date = new Date();
  3921. date.setTime(date.getTime() + (days * 24 * 60 * 60 * 1000));
  3922. var expires = "; expires=" + date.toGMTString();
  3923. } else var expires = "";
  3924. document.cookie = escape(name) + "=" + escape(value) + expires + "; path=/";
  3925.  
  3926. }
  3927.  
  3928. function td_read_cookie(name) {
  3929. var nameEQ = escape(name) + "=";
  3930. var ca = document.cookie.split(';');
  3931. for (var i = 0; i < ca.length; i++) {
  3932. var c = ca[i];
  3933. while (c.charAt(0) == ' ') c = c.substring(1, c.length);
  3934. if (c.indexOf(nameEQ) == 0) return unescape(c.substring(nameEQ.length, c.length));
  3935. }
  3936. return null;
  3937. }
  3938.  
  3939.  
  3940.  
  3941.  
  3942.  
  3943.  
  3944. /* ----------------------------------------------------------------------------
  3945. live css compiler @tagDiv 2013
  3946. */
  3947.  
  3948. //the settings object
  3949. function td_customizer_setting () {
  3950. this.name = '';
  3951. this.value = '';
  3952. }
  3953.  
  3954. //the sections object
  3955. function td_customizer_css_section() {
  3956. this.name = '';
  3957. this.raw_css = '';
  3958. this.compiled_css = '';
  3959. }
  3960.  
  3961. //css parser class
  3962. function td_custom_css_parser(raw_css) {
  3963. this.raw_css = raw_css;
  3964. this.settings = [];
  3965. this.css_sections = [];
  3966. this.style_element_id = '';
  3967. this.compiled_css = ''; //compiled css
  3968. }
  3969.  
  3970. //load the settings
  3971. td_custom_css_parser.prototype.load_setting_raw = function(name, value){
  3972. if (this.get_css_section(name) === false) {
  3973. var new_setting = new td_customizer_setting();
  3974. new_setting.name = name;
  3975. new_setting.value = value;
  3976. this.settings.push(new_setting);
  3977. } else {
  3978. this.update_setting_value(name, value);
  3979. }
  3980. };
  3981.  
  3982. //split the css in sections
  3983. td_custom_css_parser.prototype.split_into_sections = function(){
  3984. //remove style wrapping
  3985. this.raw_css = this.raw_css.replace(/<style>/gi,'');
  3986. this.raw_css = this.raw_css.replace(/<\/style>/gi,'');
  3987.  
  3988. this.raw_css = this.raw_css.trim();
  3989.  
  3990. //explode the sections
  3991. var css_splits = this.raw_css.split('/*');
  3992.  
  3993. var containing_class = this;
  3994. jQuery.each(css_splits, function(index, css_split) {
  3995. var css_split_parts = css_split.split('*/');
  3996. if (typeof css_split_parts[0] !== "undefined" && typeof css_split_parts[1] !== "undefined") {
  3997. var new_css_section = new td_customizer_css_section();
  3998. new_css_section.name = css_split_parts[0].trim();
  3999. new_css_section.raw_css = css_split_parts[1].trim();
  4000. containing_class.css_sections.push(new_css_section);
  4001. }
  4002. });
  4003. };
  4004.  
  4005.  
  4006. //get setting value
  4007. td_custom_css_parser.prototype.get_setting_value = function(name){
  4008. var tmpReturn = false;
  4009. jQuery.each(this.settings, function(index, setting) {
  4010. if (setting.name === name) {
  4011. tmpReturn = setting.value;
  4012. return false; //brake jquery each
  4013. }
  4014. });
  4015. return tmpReturn;
  4016. };
  4017.  
  4018. //get setting value
  4019. td_custom_css_parser.prototype.update_setting_value = function(name, value){
  4020. jQuery.each(this.settings, function(index, setting) {
  4021. if (setting.name === name) {
  4022. setting.value = value;
  4023. return false; //brake jquery each
  4024. }
  4025. });
  4026. };
  4027.  
  4028.  
  4029. //get css section
  4030. td_custom_css_parser.prototype.get_css_section = function(name){
  4031. var tmpReturn = false;
  4032. jQuery.each(this.settings, function(index, setting) {
  4033. if (setting.name === name) {
  4034. tmpReturn = setting.value;
  4035. return false; //brake jquery each
  4036. }
  4037. });
  4038. return tmpReturn;
  4039. };
  4040.  
  4041. //compile each section
  4042. td_custom_css_parser.prototype.compile_sections = function(){
  4043. if (typeof this.css_sections !== "undefined" && typeof this.settings !== "undefined") {
  4044. var containing_class = this;
  4045. //console.log('start');
  4046.  
  4047. jQuery.each(this.css_sections, function(index, section) {
  4048. jQuery.each(containing_class.settings, function(index, setting) {
  4049. section.raw_css = str_replace("@" + setting.name, setting.value, section.raw_css);
  4050. });
  4051. });
  4052. }
  4053. };
  4054.  
  4055. //compile the css
  4056. td_custom_css_parser.prototype.compile_css = function(){
  4057.  
  4058. this.split_into_sections();
  4059. this.compile_sections();
  4060.  
  4061. var buffy = '';
  4062. var containing_class = this;
  4063.  
  4064. jQuery.each(this.css_sections, function(index, section) {
  4065. if (section.raw_css !== '' && containing_class.get_setting_value(str_replace("@", '', section.name)) !== false) {
  4066. buffy = buffy + section.raw_css;
  4067. }
  4068. });
  4069.  
  4070. this.compiled_css = buffy;
  4071. //alert(buffy);
  4072. };
  4073.  
  4074.  
  4075. //inject css
  4076. td_custom_css_parser.prototype.inject_css = function(){
  4077.  
  4078.  
  4079. var td_style = document.createElement('style');
  4080. td_style.type = 'text/css';
  4081. td_style.innerHTML = this.compiled_css;
  4082. td_style.setAttribute("id", "td_style_inject");
  4083. if (this.style_element_id === '') {
  4084. //new element
  4085.  
  4086.  
  4087. jQuery('body').append(td_style);
  4088. this.style_element_id = 'td_style_inject';
  4089. } else {
  4090. //update old
  4091. jQuery('#td_style_inject').replaceWith(td_style);
  4092. }
  4093. };
  4094.  
  4095.  
  4096.  
  4097.  
  4098.  
  4099.  
  4100.  
  4101. /*
  4102. var td_custom_css_parser = new td_custom_css_parser(td_style_buffer);
  4103. td_custom_css_parser.load_setting_raw('header_color', 'red');
  4104. td_custom_css_parser.load_setting_raw('header_line_color', 'blue');
  4105.  
  4106.  
  4107. td_custom_css_parser.load_setting_raw('link_color', 'pink');
  4108.  
  4109. //td_custom_css_parser.compile_css();
  4110. //td_custom_css_parser.inject_css();
  4111.  
  4112.  
  4113. td_custom_css_parser.load_setting_raw('header_color', 'white');
  4114. td_custom_css_parser.load_setting_raw('header_line_color', 'gray');
  4115. */
  4116. //td_custom_css_parser.compile_css();
  4117. //td_custom_css_parser.inject_css();
  4118.  
  4119.  
  4120.  
  4121. //alert(td_custom_css_parser.get_setting_value('link_color'));
  4122.  
  4123.  
  4124. //console.log(td_custom_css_parser.settings);
  4125. //console.log(td_custom_css_parser.css_sections);
  4126.  
  4127.  
  4128. //td_custom_css_parser.load_setting_raw('test');
  4129.  
  4130.  
  4131.  
  4132. var pad = function(num, totalChars) {
  4133. var pad = '0';
  4134. num = num + '';
  4135. while (num.length < totalChars) {
  4136. num = pad + num;
  4137. }
  4138. return num;
  4139. };
  4140.  
  4141. // Ratio is between 0 and 1
  4142. var changeColor = function(color, ratio, darker) {
  4143. // Trim trailing/leading whitespace
  4144. color = color.replace(/^\s*|\s*$/, '');
  4145.  
  4146. // Expand three-digit hex
  4147. color = color.replace(
  4148. /^#?([a-f0-9])([a-f0-9])([a-f0-9])$/i,
  4149. '#$1$1$2$2$3$3'
  4150. );
  4151.  
  4152. // Calculate ratio
  4153. var difference = Math.round(ratio * 256) * (darker ? -1 : 1),
  4154. // Determine if input is RGB(A)
  4155. rgb = color.match(new RegExp('^rgba?\\(\\s*' +
  4156. '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' +
  4157. '\\s*,\\s*' +
  4158. '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' +
  4159. '\\s*,\\s*' +
  4160. '(\\d|[1-9]\\d|1\\d{2}|2[0-4][0-9]|25[0-5])' +
  4161. '(?:\\s*,\\s*' +
  4162. '(0|1|0?\\.\\d+))?' +
  4163. '\\s*\\)$'
  4164. , 'i')),
  4165. alpha = !!rgb && rgb[4] != null ? rgb[4] : null,
  4166.  
  4167. // Convert hex to decimal
  4168. decimal = !!rgb? [rgb[1], rgb[2], rgb[3]] : color.replace(
  4169. /^#?([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])([a-f0-9][a-f0-9])/i,
  4170. function() {
  4171. return parseInt(arguments[1], 16) + ',' +
  4172. parseInt(arguments[2], 16) + ',' +
  4173. parseInt(arguments[3], 16);
  4174. }
  4175. ).split(/,/),
  4176. returnValue;
  4177.  
  4178. // Return RGB(A)
  4179. return !!rgb ?
  4180. 'rgb' + (alpha !== null ? 'a' : '') + '(' +
  4181. Math[darker ? 'max' : 'min'](
  4182. parseInt(decimal[0], 10) + difference, darker ? 0 : 255
  4183. ) + ', ' +
  4184. Math[darker ? 'max' : 'min'](
  4185. parseInt(decimal[1], 10) + difference, darker ? 0 : 255
  4186. ) + ', ' +
  4187. Math[darker ? 'max' : 'min'](
  4188. parseInt(decimal[2], 10) + difference, darker ? 0 : 255
  4189. ) +
  4190. (alpha !== null ? ', ' + alpha : '') +
  4191. ')' :
  4192. // Return hex
  4193. [
  4194. '#',
  4195. pad(Math[darker ? 'max' : 'min'](
  4196. parseInt(decimal[0], 10) + difference, darker ? 0 : 255
  4197. ).toString(16), 2),
  4198. pad(Math[darker ? 'max' : 'min'](
  4199. parseInt(decimal[1], 10) + difference, darker ? 0 : 255
  4200. ).toString(16), 2),
  4201. pad(Math[darker ? 'max' : 'min'](
  4202. parseInt(decimal[2], 10) + difference, darker ? 0 : 255
  4203. ).toString(16), 2)
  4204. ].join('');
  4205. };
  4206. var lighterColor = function(color, ratio) {
  4207. return changeColor(color, ratio, false);
  4208. };
  4209. var darkerColor = function(color, ratio) {
  4210. return changeColor(color, ratio, true);
  4211. };
  4212.  
  4213.  
  4214.  
  4215.  
  4216.  
  4217.  
  4218.  
  4219.  
  4220.  
  4221. function td_convert_hex(hex,opacity){
  4222. var hex = hex.replace('#','');
  4223. var r = parseInt(hex.substring(0,2), 16);
  4224. var g = parseInt(hex.substring(2,4), 16);
  4225. var b = parseInt(hex.substring(4,6), 16);
  4226.  
  4227. var result = 'rgba('+r+','+g+','+b+','+opacity/100+')';
  4228. return result;
  4229. }
  4230.  
  4231. function str_replace (search, replace, subject, count) {
  4232. // http://kevin.vanzonneveld.net
  4233. // + original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  4234. // + improved by: Gabriel Paderni
  4235. // + improved by: Philip Peterson
  4236. // + improved by: Simon Willison (http://simonwillison.net)
  4237. // + revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
  4238. // + bugfixed by: Anton Ongson
  4239. // + input by: Onno Marsman
  4240. // + improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  4241. // + tweaked by: Onno Marsman
  4242. // + input by: Brett Zamir (http://brett-zamir.me)
  4243. // + bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
  4244. // + input by: Oleg Eremeev
  4245. // + improved by: Brett Zamir (http://brett-zamir.me)
  4246. // + bugfixed by: Oleg Eremeev
  4247. // % note 1: The count parameter must be passed as a string in order
  4248. // % note 1: to find a global variable in which the result will be given
  4249. // * example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
  4250. // * returns 1: 'Kevin.van.Zonneveld'
  4251. // * example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
  4252. // * returns 2: 'hemmo, mars'
  4253. var i = 0,
  4254. j = 0,
  4255. temp = '',
  4256. repl = '',
  4257. sl = 0,
  4258. fl = 0,
  4259. f = [].concat(search),
  4260. r = [].concat(replace),
  4261. s = subject,
  4262. ra = Object.prototype.toString.call(r) === '[object Array]',
  4263. sa = Object.prototype.toString.call(s) === '[object Array]';
  4264. s = [].concat(s);
  4265. if (count) {
  4266. this.window[count] = 0;
  4267. }
  4268.  
  4269. for (i = 0, sl = s.length; i < sl; i++) {
  4270. if (s[i] === '') {
  4271. continue;
  4272. }
  4273. for (j = 0, fl = f.length; j < fl; j++) {
  4274. temp = s[i] + '';
  4275. repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
  4276. s[i] = (temp).split(f[j]).join(repl);
  4277. if (count && s[i] !== temp) {
  4278. this.window[count] += (temp.length - s[i].length) / f[j].length;
  4279. }
  4280. }
  4281. }
  4282. return sa ? s : s[0];
  4283. }
  4284.  
  4285. 'use strict';
  4286. /**
  4287. * updates the view counter thru ajax
  4288. */
  4289. var td_ajax_count = {
  4290.  
  4291. td_get_views_counts_ajax : function td_get_views_counts_ajax (page_type, array_ids) {
  4292.  
  4293. //what function to call based on page type
  4294. var page_type_action = 'td_ajax_get_views';//page_type = page
  4295. if(page_type == "post") {
  4296. page_type_action = 'td_ajax_update_views';
  4297. }
  4298.  
  4299. jQuery.ajax({
  4300. type: 'POST',
  4301. url: td_ajax_url,
  4302. cache:true,
  4303.  
  4304. data: {
  4305. action: page_type_action,
  4306. td_post_ids: array_ids
  4307. },
  4308. success: function(data, textStatus, XMLHttpRequest){
  4309. var td_ajax_post_counts = jQuery.parseJSON(data);//get the return dara
  4310.  
  4311. //check the return var to be object
  4312. if (td_ajax_post_counts instanceof Object) {
  4313. //alert('value is Object!');
  4314.  
  4315. //itinerate thru the object
  4316. jQuery.each(td_ajax_post_counts, function(id_post, value) {
  4317. //alert(id_post + ": " + value);
  4318.  
  4319. //this is the count placeholder in witch we write the post count
  4320. var current_post_count = ".td-nr-views-" + id_post;
  4321.  
  4322. jQuery(current_post_count).html(value);
  4323. //console.log(current_post_count + ': ' + value);
  4324. });
  4325. }
  4326. },
  4327. error: function(MLHttpRequest, textStatus, errorThrown){
  4328. //console.log(errorThrown);
  4329. }
  4330. });
  4331.  
  4332. }
  4333. };
  4334.  
  4335. /*
  4336. td_video_playlist.js
  4337. v1.1
  4338. */
  4339.  
  4340. "use strict";
  4341. // jQuery(window).load(function() {//
  4342. jQuery().ready(function() {
  4343.  
  4344. //click on a youtube movie
  4345. jQuery('.td_click_video_youtube').click(function(){
  4346.  
  4347. //this flag is check to see if to start the movie
  4348. td_youtube_player.td_playlist_video_autoplay_youtube = 1;
  4349.  
  4350. //add pause to playlist control
  4351. td_playlist_general_functions.td_playlist_add_play_control('.td_youtube_control');
  4352.  
  4353. //create and play the clicked video
  4354. var td_youtube_video = jQuery(this).attr("id").substring(3);
  4355. if(td_youtube_video != '') {
  4356. td_youtube_player.playVideo(td_youtube_video);
  4357. }
  4358. });
  4359.  
  4360.  
  4361.  
  4362. //click on youtube play control
  4363. jQuery('.td_youtube_control').click(function(){
  4364.  
  4365. //click to play
  4366. if(jQuery(this).hasClass('td-sp-video-play')){
  4367. //this is to enable video playing
  4368. td_youtube_player.td_playlist_video_autoplay_youtube = 1;
  4369.  
  4370. //play the video
  4371. td_youtube_player.td_playlist_youtube_play_video();
  4372.  
  4373. } else {
  4374.  
  4375. //put pause to the player
  4376. td_youtube_player.td_playlist_youtube_pause_video();
  4377. }
  4378. });
  4379.  
  4380.  
  4381.  
  4382. //check for youtube wrapper and add api code to create the player
  4383. if(jQuery('.td_wrapper_playlist_player_youtube').length > 0) {
  4384.  
  4385. if(jQuery('.td_wrapper_playlist_player_youtube').data("autoplay") == "1") {
  4386. td_youtube_player.td_playlist_video_autoplay_youtube = 1;
  4387. }
  4388.  
  4389. var first_video = jQuery('.td_wrapper_playlist_player_youtube').data('first-video');
  4390.  
  4391. if(first_video != '') {
  4392. td_youtube_player.td_playlist_id_youtube_video_running = first_video;
  4393.  
  4394. td_youtube_player.playVideo(first_video);
  4395. }
  4396. }
  4397.  
  4398.  
  4399.  
  4400. //check autoplay vimeo
  4401. if(jQuery('.td_wrapper_playlist_player_vimeo').data("autoplay") == "1") {
  4402. td_vimeo_playlist_obj.td_playlist_video_autoplay_vimeo = 1;
  4403. }
  4404.  
  4405. //click on a vimeo
  4406. jQuery('.td_click_video_vimeo').click(function(){
  4407.  
  4408. //this flag is check to see if to start the movie
  4409. td_vimeo_playlist_obj.td_playlist_video_autoplay_vimeo = 1;
  4410.  
  4411. //add pause to playlist control
  4412. td_playlist_general_functions.td_playlist_add_play_control('.td_vimeo_control');
  4413.  
  4414. //create and play the clicked video
  4415. td_vimeo_playlist_obj.create_player(jQuery(this).attr("id").substring(3));
  4416. });
  4417.  
  4418.  
  4419.  
  4420.  
  4421.  
  4422. //check for vimeo wrapper and add api code to create the player
  4423. if(jQuery('.td_wrapper_playlist_player_vimeo').length > 0) {
  4424.  
  4425. //add play to playlist control
  4426. td_playlist_general_functions.td_playlist_add_play_control('.td_vimeo_control');
  4427.  
  4428. //create the iframe with the video
  4429. td_vimeo_playlist_obj.create_player(jQuery('.td_wrapper_playlist_player_vimeo').data("first-video"));
  4430. }
  4431.  
  4432.  
  4433.  
  4434.  
  4435. //click on youtube play control
  4436. jQuery('.td_vimeo_control').click(function(){
  4437.  
  4438. //click to play
  4439. if(jQuery(this).hasClass('td-sp-video-play')){
  4440. //this is to enable video playing
  4441. td_vimeo_playlist_obj.td_playlist_video_autoplay_vimeo = 1;
  4442.  
  4443. //play the video
  4444. td_vimeo_playlist_obj.td_playlisty_player_vimeo.api("play");
  4445.  
  4446. } else {
  4447.  
  4448. //put pause to the player
  4449. td_vimeo_playlist_obj.td_playlisty_player_vimeo.api("pause");
  4450. }
  4451. });
  4452.  
  4453. });
  4454.  
  4455.  
  4456. var td_youtube_player = {
  4457. td_yt_player: '',
  4458.  
  4459. td_player_container: 'player_youtube',
  4460.  
  4461. td_playlist_video_autoplay_youtube: 0,
  4462.  
  4463. td_playlist_id_youtube_video_running: '',
  4464.  
  4465.  
  4466. playVideo: function(videoId) {
  4467. if (typeof(YT) == 'undefined' || typeof(YT.Player) == 'undefined') {
  4468. window.onYouTubePlayerAPIReady = function() {
  4469. td_youtube_player.loadPlayer(td_youtube_player.td_player_container, videoId);
  4470. };
  4471. jQuery.getScript('//www.youtube.com/player_api');
  4472. } else {
  4473. td_youtube_player.loadPlayer(td_youtube_player.td_player_container, videoId);
  4474. }
  4475. },
  4476.  
  4477.  
  4478. loadPlayer: function(container, videoId) {
  4479. //container is here in case we need to add multiple players on page
  4480. td_youtube_player.td_playlist_id_youtube_video_running = videoId;
  4481.  
  4482. var current_video_name = td_youtube_list_ids['td_' + td_youtube_player.td_playlist_id_youtube_video_running]['title'];
  4483. var current_video_time = td_youtube_list_ids['td_' + td_youtube_player.td_playlist_id_youtube_video_running]['time'];
  4484.  
  4485. //remove focus from all videos from playlist
  4486. td_playlist_general_functions.td_video_playlist_remove_focused('.td_click_video_youtube');
  4487.  
  4488. //add focus class on current playing video
  4489. jQuery('#td_' + videoId).addClass('td_video_currently_playing');
  4490.  
  4491. //ading the current video playing title and time to the control area
  4492. jQuery('#td_current_video_play_title_youtube').html(current_video_name);
  4493. jQuery('#td_current_video_play_time_youtube').html(current_video_time);
  4494.  
  4495. td_youtube_player.td_yt_player = '';
  4496. jQuery(".td_wrapper_playlist_player_youtube").html("<div id="+ td_youtube_player.td_player_container +"></div>");
  4497.  
  4498. td_youtube_player.td_yt_player = new YT.Player(container, {//window.myPlayer = new YT.Player(container, {
  4499. playerVars: {
  4500. //modestbranding: 1,
  4501. //rel: 0,
  4502. //showinfo: 0,
  4503. autoplay: td_youtube_player.td_playlist_video_autoplay_youtube
  4504. },
  4505. height: '100%',
  4506. width: '100%',
  4507. videoId: videoId,
  4508. events: {
  4509. 'onReady': td_youtube_player.onPlayerReady,
  4510. 'onStateChange': td_youtube_player.onPlayerStateChange
  4511. }
  4512. });
  4513. },
  4514.  
  4515.  
  4516. onPlayerStateChange: function onPlayerStateChange(event) {
  4517. if (event.data == YT.PlayerState.PLAYING) {
  4518.  
  4519. //add pause to playlist control
  4520. td_playlist_general_functions.td_playlist_add_pause_control('.td_youtube_control');
  4521.  
  4522. } else if (event.data == YT.PlayerState.ENDED) {
  4523. //video_events_js.on_stop('youtube');
  4524.  
  4525. //add play to playlist control
  4526. td_playlist_general_functions.td_playlist_add_play_control('.td_youtube_control');
  4527.  
  4528. //if a video has ended then make auto play = 1; This is the case when the user set autoplay = 0 but start watching videos
  4529. td_youtube_player.td_playlist_video_autoplay_youtube = 1;
  4530.  
  4531. //get the next video
  4532. var next_video_id = td_playlist_general_functions.td_playlist_choose_next_video([td_youtube_list_ids, td_youtube_player.td_playlist_id_youtube_video_running]);
  4533. if(next_video_id != '') {
  4534. td_youtube_player.playVideo(next_video_id);
  4535. }
  4536.  
  4537. } else if (YT.PlayerState.PAUSED) {
  4538. //add play to playlist control
  4539. td_playlist_general_functions.td_playlist_add_play_control('.td_youtube_control');
  4540. }
  4541. },
  4542.  
  4543. td_playlist_youtube_stopVideo: function td_playlist_youtube_stopVideo() {
  4544. td_youtube_player.td_yt_player.stopVideo();
  4545. },
  4546.  
  4547. td_playlist_youtube_play_video: function td_playlist_youtube_play_video() {
  4548. if(td_detect.is_mobile_device) {
  4549. //alert('mobile');
  4550. } else {
  4551. td_youtube_player.td_yt_player.playVideo();
  4552. }
  4553. },
  4554.  
  4555. td_playlist_youtube_pause_video: function td_playlist_youtube_pause_video() {
  4556. td_youtube_player.td_yt_player.pauseVideo();
  4557. }
  4558. };
  4559.  
  4560.  
  4561.  
  4562.  
  4563.  
  4564. //VIMEO
  4565. var td_vimeo_playlist_obj = {
  4566.  
  4567. current_video_playing : '',
  4568.  
  4569. td_playlisty_player_vimeo: '',//a copy of the vimeo player : needed when playing or pausing the vimeo pleyer from the playlist control
  4570.  
  4571. td_playlist_video_autoplay_vimeo: '',//autoplay
  4572.  
  4573. create_player: function (video_id){
  4574. if(video_id != '') {
  4575.  
  4576. var vimeo_iframe_autoplay = '';
  4577.  
  4578. this.current_video_playing = video_id;
  4579.  
  4580. //remove focus class
  4581. td_playlist_general_functions.td_video_playlist_remove_focused('.td_click_video_vimeo');
  4582.  
  4583. //add focus clas on play movie
  4584. jQuery('#td_' + video_id).addClass('td_video_currently_playing');
  4585.  
  4586. //put movie data to control box
  4587. this.put_movie_data_to_control_box(video_id);
  4588.  
  4589. //check autoplay
  4590. if(this.td_playlist_video_autoplay_vimeo != 0) {
  4591. vimeo_iframe_autoplay = '&autoplay=1';
  4592. }
  4593.  
  4594.  
  4595. jQuery('.td_wrapper_playlist_player_vimeo').html('');
  4596. jQuery('.td_wrapper_playlist_player_vimeo').html('<iframe id="player_vimeo_1" src="//player.vimeo.com/video/' + video_id + '?api=1&player_id=player_vimeo_1' + vimeo_iframe_autoplay + '" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>');//width="100%" height="100%"
  4597.  
  4598. this.create_vimeo_object_player(jQuery);
  4599. }
  4600.  
  4601. },
  4602.  
  4603. put_movie_data_to_control_box: function (video_id){
  4604. jQuery('#td_current_video_play_title_vimeo').html(td_vimeo_list_ids['td_' + video_id]['title']);
  4605. jQuery('#td_current_video_play_time_vimeo').html(td_vimeo_list_ids['td_' + video_id]['time']);
  4606. },
  4607.  
  4608. create_vimeo_object_player : function ($) {
  4609. var iframe = '';
  4610. var player = '';
  4611.  
  4612. iframe = $('#player_vimeo_1')[0];
  4613. player = $f(iframe)
  4614.  
  4615. //a copy of the vimeo player : needed when playing or pausing the vimeo pleyer from the playlist control
  4616. this.td_playlisty_player_vimeo = player;
  4617.  
  4618. // When the player is ready, add listeners for pause, finish, and playProgress
  4619. player.addEvent('ready', function() {
  4620. //status.text('ready');
  4621.  
  4622. player.addEvent('play', td_vimeo_playlist_obj.onPlay);
  4623. player.addEvent('pause', td_vimeo_playlist_obj.onPause);
  4624. player.addEvent('finish', td_vimeo_playlist_obj.onFinish);
  4625. player.addEvent('playProgress', td_vimeo_playlist_obj.onPlayProgress);
  4626. });
  4627. },
  4628.  
  4629. onPlay : function onPlay(id) {
  4630. td_playlist_general_functions.td_playlist_add_pause_control('.td_vimeo_control');
  4631.  
  4632. td_vimeo_playlist_obj.td_playlist_video_autoplay_vimeo = 1;
  4633. },
  4634.  
  4635. onPause : function onPause(id) {
  4636. td_playlist_general_functions.td_playlist_add_play_control('.td_vimeo_control');
  4637. },
  4638.  
  4639. onFinish : function onFinish(id) {
  4640. //status.text('finished');
  4641.  
  4642. //add play to playlist control
  4643. td_playlist_general_functions.td_playlist_add_play_control('.td_vimeo_control');
  4644.  
  4645. //if a video has ended then make auto play = 1; This is the case when the user set autoplay = 0 but start watching videos
  4646. td_vimeo_playlist_obj.td_playlist_video_autoplay_vimeo = 1;
  4647.  
  4648. if(td_detect.is_mobile_device && td_detect.is_android) {
  4649. //alert('is android');
  4650. } else {
  4651.  
  4652. //get the next video
  4653. var next_video_id = td_playlist_general_functions.td_playlist_choose_next_video([td_vimeo_list_ids, td_vimeo_playlist_obj.current_video_playing]);
  4654. if(next_video_id != '') {
  4655. td_vimeo_playlist_obj.create_player(next_video_id);
  4656. }
  4657. }
  4658. },
  4659.  
  4660. onPlayProgress : function onPlayProgress(data, id) {
  4661. //status.text(data.seconds + 's played');
  4662. }
  4663. };
  4664.  
  4665.  
  4666. //this object holds some functions used by both the youtube and vimeo
  4667. var td_playlist_general_functions = {
  4668. td_video_playlist_remove_focused: function td_video_playlist_remove_focused(obj_class) {
  4669. //remove focus class
  4670. jQuery( obj_class).each(function(){
  4671. jQuery(this).removeClass('td_video_currently_playing');
  4672. });
  4673. },
  4674.  
  4675.  
  4676. /*
  4677. parram_array = array [
  4678. video_list,
  4679. current_video_id_playing
  4680. ]
  4681. */
  4682. td_playlist_choose_next_video: function td_playlist_choose_next_video(parram_array){
  4683. //alert('get next');
  4684.  
  4685. var video_list = parram_array[0];
  4686. var current_video_id_playing = 'td_' + parram_array[1];
  4687.  
  4688. //get next video id
  4689. var next_video_id = '';
  4690. var found_current = '';
  4691. for(var video in video_list){
  4692. if(found_current == 'found') {
  4693. next_video_id = video;
  4694. found_current = '';
  4695. break;//found , now exit
  4696. }
  4697. if(video == current_video_id_playing) {
  4698. found_current = 'found';
  4699. }
  4700. }
  4701.  
  4702. //play the next video
  4703. if(next_video_id != '') {
  4704.  
  4705. //remove 'td_' from the beginning of the string if necessary
  4706. if(next_video_id.substring(0, 3) == 'td_') {
  4707. next_video_id = next_video_id.substring(3);
  4708. }
  4709.  
  4710. return next_video_id;
  4711. }
  4712.  
  4713. return '';
  4714. },
  4715.  
  4716.  
  4717.  
  4718. //add pause button playlist control
  4719. td_playlist_add_pause_control: function td_playlist_add_pause_control(wrapper_class){
  4720. jQuery(wrapper_class).removeClass('td-sp-video-play').addClass('td-sp-video-pause');
  4721. },
  4722.  
  4723. //add play button playlist control
  4724. td_playlist_add_play_control: function td_playlist_add_play_control(wrapper_class){
  4725. jQuery(wrapper_class).removeClass('td-sp-video-pause').addClass('td-sp-video-play');
  4726. }
  4727. }
  4728.  
  4729. /**
  4730. * Infinite loader v1.0 by Radu O. / tagDiv
  4731. */
  4732. "use strict";
  4733.  
  4734. /**
  4735. * - register and keep track of dom elements
  4736. * - calculate position from the top of each element
  4737. * - monitor on scroll event
  4738. * - if one or more of the dom elements is visible
  4739. * - fire the callback for that dom element! only ONCE
  4740. */
  4741.  
  4742.  
  4743. var td_infinite_loader = {
  4744.  
  4745. has_items: false, // this class will only work when this flag is true. If we don't have any items, all the calculations on scroll will be disabled by this flag
  4746.  
  4747. items: [], //the array that has all the items
  4748.  
  4749. // one item object (instantiable)
  4750. item: function() {
  4751. this.uid=''; //an unique id for this item
  4752. this.jquery_obj = ''; //find the item easly for animation ??
  4753. this.bottom_top = 0; //distance from the bottom of the dom element to top
  4754. this.is_visible_callback_enabled = true;
  4755. this.is_visible_callback = function () { //callback when the item's bottom is visible :)
  4756.  
  4757. };
  4758. },
  4759.  
  4760. add_item: function(item) {
  4761. td_infinite_loader.has_items = true; //put the flag that we have items
  4762. td_infinite_loader.items.push(item);
  4763. },
  4764.  
  4765.  
  4766. /**
  4767. * foreach element from items, compute the distances from the top
  4768. * - this is done only on load or when the page is resized
  4769. */
  4770. compute_top_distances: function compute_top_distances() {
  4771.  
  4772. //check the flag to see if we have any items
  4773. if (td_infinite_loader.has_items === false) {
  4774. return;
  4775. }
  4776.  
  4777. jQuery.each(td_infinite_loader.items, function(index, v_event) {
  4778. var top_top = td_infinite_loader.items[index].jquery_obj.offset().top;
  4779. //top of document to bottom of element
  4780. td_infinite_loader.items[index].bottom_top = top_top + td_infinite_loader.items[index].jquery_obj.height();
  4781. });
  4782.  
  4783. //also calculate the events
  4784. td_infinite_loader.compute_events();
  4785.  
  4786. },
  4787.  
  4788.  
  4789. /**
  4790. * calculate if we have to fire an event like is_visible_callback()
  4791. * - this is done on scroll and on resize!
  4792. */
  4793. compute_events: function compute_events() {
  4794. //check the flag to see if we have any items
  4795. if (td_infinite_loader.has_items === false) {
  4796. return;
  4797. }
  4798.  
  4799. var top_to_viewport_bottom = jQuery(window).height() + jQuery(window).scrollTop();
  4800.  
  4801.  
  4802. jQuery.each(td_infinite_loader.items, function(index, item) {
  4803. if (td_infinite_loader.items[index].bottom_top < top_to_viewport_bottom + 400) {
  4804.  
  4805. //check to see if we can call the callback again
  4806. if (td_infinite_loader.items[index].is_visible_callback_enabled === true) {
  4807. td_infinite_loader.items[index].is_visible_callback_enabled = false;
  4808. //the call
  4809. td_infinite_loader.items[index].is_visible_callback();
  4810. }
  4811. }
  4812.  
  4813.  
  4814. });
  4815. },
  4816.  
  4817.  
  4818. /**
  4819. * enables the is_visible_callback - it is called by td_blocks.js only when a block receives an infinite loading ajax reply
  4820. * @param $item_uid - an unique id of the item, usually is the block id!
  4821. * @see td_block_ajax_loading_end
  4822. */
  4823. enable_is_visible_callback: function enable_is_visible_callback($item_uid) {
  4824. jQuery.each(td_infinite_loader.items, function(index, item) {
  4825. if (item.uid === $item_uid) {
  4826. td_infinite_loader.items[index].is_visible_callback_enabled = true;
  4827. return false; //brake jquery each
  4828. }
  4829. });
  4830. }
  4831.  
  4832. };
  4833.  
  4834.  
  4835.  
  4836.  
  4837.  
  4838.  
  4839. /**
  4840. * we are using td_ajax_infinite to know when to trigger a block loading
  4841. */
  4842. jQuery('.td_ajax_infinite').each(function() {
  4843.  
  4844. // create a new infinite loader item
  4845. var td_infinite_loader_item = new td_infinite_loader.item();
  4846.  
  4847. td_infinite_loader_item.jquery_obj = jQuery(this);
  4848. td_infinite_loader_item.uid = jQuery(this).data('td_block_id');
  4849. td_infinite_loader_item.is_visible_callback = function () { // the is_visible callback is called when we have to pull new content up because the element is visible
  4850. // get the current block object
  4851. var current_block_obj = td_getBlockObjById(td_infinite_loader_item.jquery_obj.data('td_block_id'));
  4852.  
  4853.  
  4854. // if we don't have a infinite stop limit or if we have one we dint' hit it yet
  4855. if (current_block_obj.ajax_pagination_infinite_stop == '' || current_block_obj.td_current_page < (parseInt(current_block_obj.ajax_pagination_infinite_stop) + 1)) {
  4856.  
  4857. // get the block data and increment the pagination
  4858. current_block_obj.td_current_page++;
  4859. td_ajax_do_block_request(current_block_obj, 'infinite_load');
  4860.  
  4861. } else {
  4862.  
  4863. //show the load more button
  4864. setTimeout(function(){
  4865. jQuery('#infinite-lm-' + current_block_obj.id).show();
  4866. }, 400);
  4867.  
  4868. }
  4869.  
  4870.  
  4871.  
  4872.  
  4873. };
  4874. td_infinite_loader.add_item(td_infinite_loader_item);
  4875. });
  4876.  
  4877.  
  4878. //compute to
  4879. jQuery(window).load(function() {
  4880. td_infinite_loader.compute_top_distances();
  4881. });
  4882.  
  4883. jQuery().ready(function() {
  4884. td_infinite_loader.compute_top_distances();
  4885. });
Advertisement
Add Comment
Please, Sign In to add comment