(function($){var methods={init:function(options){return this.each(function(){var settings={id:"",type:"scroll",scroll_direction:"left",scroll_speed:10,scroll_pause:0,scroll_spacing:40,scroll_units:10,scroll_init:0,scroll_init_delay:2,scroll_loop:1,rotate_type:"fade",auto_rotate:0,rotate_delay:10,rotate_pause:0,rotate_speed:10,rotate_ease:"easeOutExpo",nav_reverse:0,disable_touchswipe:0,offset:20,before_change:function(){},after_change:function(){},after_load:function(){},};var vars={id:settings.id,tick_count:0,previous_tick:0,current_tick:0,next_tick:0,reverse:0,running:0,paused:0,};if(options){$.extend(settings,options);} var $container=$(this),$ticker=$container.find(".mtphr-dnt-tick-contents"),$nav_prev=$container.find(".mtphr-dnt-nav-prev"),$nav_next=$container.find(".mtphr-dnt-nav-next"),$nav_controls=$container.find(".mtphr-dnt-control-links"),$play_pause=$container.find(".mtphr-dnt-play-pause"),ticker_width=$ticker.outerWidth(true),ticker_height=0,ticks=[],ticker_scroll,ticker_scroll_resize=true,rotator_delay,rotate_adjustment=settings.rotate_type,after_change_timeout,init_timeout,init_loop=true,scroll_percent=0.13;$ticker.data("ditty:vars",vars);function mtphr_dnt_init(){vars.tick_count=$ticker.find(".mtphr-dnt-tick").length;if(vars.tick_count>0){if(settings.type==="scroll"){mtphr_dnt_scroll_setup();}else if(settings.type==="rotate"){mtphr_dnt_rotator_setup();}} settings.after_load.call($container,$ticker);$container.trigger("mtphr_dnt_after_load_single",[vars,ticks]);$("body").trigger("mtphr_dnt_after_load",[$container,vars,ticks]);} function mtphr_dnt_scroll_set_height(){$ticker.find(".mtphr-dnt-tick").each(function(){if($(this).height()>ticker_height){ticker_height=$(this).height();} if(settings.scroll_direction==="up"||settings.scroll_direction==="down"){$(this).css("height","auto");}});$ticker.css("height",ticker_height+"px");} function mtphr_dnt_scroll_setup(){var $first=$ticker.find(".mtphr-dnt-tick:first");if($first.attr("style")){var style=$first.attr("style");var style_array=style.split("width:");ticker_scroll_resize=style_array.length>1?false:true;} ticks=[];mtphr_dnt_scroll_set_height();if($ticker.find("img").length){$ticker.imagesLoaded(function(){mtphr_dnt_scroll_set_height();$ticker.find(".mtphr-dnt-tick").each(function(){$(this).show();var tick=[{headline:$(this)}];ticks.push(tick);});mtphr_dnt_scroll_reset_ticks();mtphr_dnt_scroll_loop();});}else{mtphr_dnt_scroll_set_height();$ticker.find(".mtphr-dnt-tick").each(function(){$(this).show();var tick=[{headline:$(this)}];ticks.push(tick);});mtphr_dnt_scroll_reset_ticks();mtphr_dnt_scroll_loop();} $ticker.on({mouseenter:function(){if(settings.scroll_pause){mtphr_dnt_scroll_pause();}},mouseleave:function(){if(settings.scroll_pause&&!vars.paused){mtphr_dnt_scroll_play();}},});$ticker.find("a").on("click",function(){if(settings.scroll_pause&&!vars.paused){mtphr_dnt_scroll_play();}});} function mtphr_dnt_scroll_pause(){clearTimeout(init_timeout);cancelAnimationFrame(ticker_scroll);} function mtphr_dnt_scroll_play(){mtphr_dnt_scroll_loop();} function mtphr_dnt_scroll_loop(){clearTimeout(init_timeout);cancelAnimationFrame(ticker_scroll);function dnt_scroll_run(){for(var i=0;iticker_width+settings.offset){pos=mtphr_dnt_scroll_check_current(i);}else if(pos>settings.scroll_spacing){mtphr_dnt_scroll_check_next(i);} return pos;} function mtphr_dnt_scroll_up(i){var pos=parseFloat(ticks[i][0].position-settings.scroll_speed*scroll_percent);if(pos<-(ticks[i][0].headline.height()+settings.offset)){pos=mtphr_dnt_scroll_check_current(i);}else if(posticker_height+settings.offset){pos=mtphr_dnt_scroll_check_current(i);}else if(pos>settings.scroll_spacing){mtphr_dnt_scroll_check_next(i);} return pos;} function mtphr_dnt_scroll_check_current(i){if(vars.tick_count>1){ticks[i][0].visible=false;} if(vars.tick_count===i+1){$container.trigger("mtphr_dnt_scroll_complete",[vars,ticks]);$("body").trigger("mtphr_dnt_scroll_complete",[$container,vars,ticks,]);} return"reset";} function mtphr_dnt_set_scroll_vars(i){if(ticks[i][0].visible===false){vars.previous_tick=parseInt(i-1);if(vars.previous_tick<0){vars.previous_tick=parseInt(vars.tick_count-1);} vars.current_tick=i;vars.next_tick=parseInt(i+1);if(vars.next_tick>=vars.tick_count){vars.next_tick=0;}}} function mtphr_dnt_scroll_check_next(i){if(i===vars.tick_count-1){if(settings.scroll_loop){mtphr_dnt_set_scroll_vars(0);ticks[0][0].visible=true;}}else{mtphr_dnt_set_scroll_vars(parseInt(i+1));ticks[i+1][0].visible=true;}} function mtphr_dnt_scroll_resize_ticks(){for(var i=0;i0){position=position-ticks[i][0].width;$tick.css("transform","translateX( "+position+"px )");ticks[i][0].position=position;ticks[i][0].visible=true;position=position-settings.scroll_spacing;} break;case"up":if(position0){$tick.css("transform","translateY( "+position+"px )");$tick.stop(true,true).css("top",position+"px");ticks[i][0].position=position;ticks[i][0].visible=true;position=position-settings.scroll_spacing;} break;}}}} function mtphr_dnt_rotator_play(){mtphr_dnt_rotator_delay();} function mtphr_dnt_rotator_pause(){clearInterval(rotator_delay);} function mtphr_dnt_rotator_setup(){$ticker.find(".mtphr-dnt-tick").each(function(){ticks.push($(this));$(this).imagesLoaded(function(){mtphr_dnt_rotator_resize_ticks();});});mtphr_dnt_rotator_resize_ticks();$ticker.find(".mtphr-dnt-tick").show();switch(settings.rotate_type){case"fade":mtphr_dnt_rotator_fade_init($ticker,ticks,parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_left":mtphr_dnt_rotator_slide_left_init($ticker,ticks,parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_right":mtphr_dnt_rotator_slide_right_init($ticker,ticks,parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_down":mtphr_dnt_rotator_slide_down_init($ticker,ticks,parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_up":mtphr_dnt_rotator_slide_up_init($ticker,ticks,parseInt(settings.rotate_speed*100),settings.rotate_ease);break;} mtphr_dnt_rotator_update_links(0);if(settings.auto_rotate){mtphr_dnt_rotator_play();} $ticker.on({mouseenter:function(){if(settings.auto_rotate&&settings.rotate_pause&&!vars.running){mtphr_dnt_rotator_pause();}},mouseleave:function(){if(settings.auto_rotate&&settings.rotate_pause&&!vars.running&&!vars.paused){mtphr_dnt_rotator_play();}},});$ticker.find("a").on("click",function(){if(settings.auto_rotate&&settings.rotate_pause&&!vars.running&&!vars.paused){mtphr_dnt_rotator_play();}});} function mtphr_dnt_rotator_delay(){mtphr_dnt_rotator_pause();rotator_delay=setInterval(function(){var new_tick=parseInt(vars.current_tick+1);if(new_tick===vars.tick_count){new_tick=0;} mtphr_dnt_rotator_update(new_tick);},parseInt(settings.rotate_delay*1000));} function mtphr_dnt_rotator_update(new_tick){if(vars.current_tick!==new_tick){if(settings.auto_rotate){mtphr_dnt_rotator_pause();} vars.next_tick=new_tick;settings.before_change.call($container,$ticker);$container.trigger("mtphr_dnt_before_change_single",[vars,ticks]);$("body").trigger("mtphr_dnt_before_change",[$container,vars,ticks,]);vars.running=1;mtphr_dnt_rotator_out(new_tick);mtphr_dnt_rotator_in(new_tick);vars.previous_tick=vars.current_tick;vars.current_tick=new_tick;after_change_timeout=setTimeout(function(){settings.after_change.call($container,$ticker);$container.trigger("mtphr_dnt_after_change_single",[vars,ticks,]);$("body").trigger("mtphr_dnt_after_change",[$container,vars,ticks,]);rotate_adjustment=settings.rotate_type;vars.reverse=0;vars.running=0;if(settings.auto_rotate&&!vars.paused){mtphr_dnt_rotator_delay();}},parseInt(settings.rotate_speed*100));}} function mtphr_dnt_rotator_update_links(new_tick){if($nav_controls){$nav_controls.children("a").removeClass("active");$nav_controls.children('a[href="'+new_tick+'"]').addClass("active");}} function mtphr_dnt_rotator_in(new_tick){mtphr_dnt_rotator_update_links(new_tick);switch(rotate_adjustment){case"fade":mtphr_dnt_rotator_fade_in($ticker,$(ticks[new_tick]),$(ticks[vars.current_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_left":mtphr_dnt_rotator_slide_left_in($ticker,$(ticks[new_tick]),$(ticks[vars.current_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_right":mtphr_dnt_rotator_slide_right_in($ticker,$(ticks[new_tick]),$(ticks[vars.current_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_down":mtphr_dnt_rotator_slide_down_in($ticker,$(ticks[new_tick]),$(ticks[vars.current_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_up":mtphr_dnt_rotator_slide_up_in($ticker,$(ticks[new_tick]),$(ticks[vars.current_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;}} function mtphr_dnt_rotator_out(new_tick){switch(rotate_adjustment){case"fade":mtphr_dnt_rotator_fade_out($ticker,$(ticks[vars.current_tick]),$(ticks[new_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_left":mtphr_dnt_rotator_slide_left_out($ticker,$(ticks[vars.current_tick]),$(ticks[new_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_right":mtphr_dnt_rotator_slide_right_out($ticker,$(ticks[vars.current_tick]),$(ticks[new_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_down":mtphr_dnt_rotator_slide_down_out($ticker,$(ticks[vars.current_tick]),$(ticks[new_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;case"slide_up":mtphr_dnt_rotator_slide_up_out($ticker,$(ticks[vars.current_tick]),$(ticks[new_tick]),parseInt(settings.rotate_speed*100),settings.rotate_ease);break;}} function mtphr_dnt_rotator_resize_ticks(){for(var i=0;i=0){if(settings.type==="scroll"){mtphr_dnt_scroll_resize_ticks();}else if(settings.type==="rotate"){mtphr_dnt_rotator_resize_ticks();}}});$container.on("mtphr_dnt_replace_ticks",function(e,ticks,delay){clearTimeout(init_timeout);cancelAnimationFrame(ticker_scroll);$container.find(".mtphr-dnt-tick").remove();ticks.each(function(){$ticker.append($(this));});setTimeout(function(){mtphr_dnt_init();},delay);});if($container.width()===0){var loop_mtphr_dnt_init_timer=true;setTimeout(function dnt_init_check(){if($container.width()>10){loop_mtphr_dnt_init_timer=false;ticker_width=$ticker.outerWidth(true);mtphr_dnt_init();} if(loop_mtphr_dnt_init_timer){setTimeout(dnt_init_check,100);}},100);}else{mtphr_dnt_init();}});},};$.fn.ditty_news_ticker=function(method){if(methods[method]){return methods[method].apply(this,Array.prototype.slice.call(arguments,1));}else if(typeof method==="object"||!method){return methods.init.apply(this,arguments);}else{throw new Error("Method "+method+" does not exist in ditty_news_ticker");}};})(jQuery);