(function (a) { a.fn.ticker = function (c) { var e = a.extend({}, a.fn.ticker.defaults, c); var b = "#" + a(this).attr("id"); var d = a(this).get(0).tagName; return this.each(function () { var h = { position: 0, time: 0, distance: 0, newsArr: {}, play: true, paused: false, contentLoaded: false, dom: { contentID: "#ticker-content", titleID: "#ticker-title", titleElem: "#ticker-title SPAN", tickerID: "#ticker", wrapperID: "#ticker-wrapper", revealID: "#ticker-swipe", revealElem: "#ticker-swipe SPAN", controlsID: "#ticker-controls", prevID: "#prev", nextID: "#next", playPauseID: "#play-pause"} }; if (d != "UL" && d != "OL" && e.htmlFeed === true) { o("Cannot use <" + d.toLowerCase() + "> type of element for this plugin - must of type <ul> or <ol>"); return false } e.direction == "rtl" ? e.direction = "right" : e.direction = "left"; f(); function k(s) { var r = 0, q; for (q in s) { if (s.hasOwnProperty(q)) { r++ } } return r } function o(q) { if (e.debugMode) { if (window.console && window.console.log) { window.console.log(q) } else { alert(q) } } } function f() { a(h.dom.wrapperID).append('<div id="' + h.dom.tickerID.replace("#", "") + '"><div id="' + h.dom.titleID.replace("#", "") + '"><span><!-- --></span></div><div id="ticker-back"><p id="' + h.dom.contentID.replace("#", "") + '"></p><div id="' + h.dom.revealID.replace("#", "") + '"><span><!-- --></span></div></div><a id="ticker-link" href="/EGReporter/tabid/3677/Default.aspx"></a></div>'); a(h.dom.wrapperID).removeClass("no-js").addClass("has-js " + e.direction); a(h.dom.tickerElem + "," + h.dom.contentID).hide(); if (e.controls) { a(h.dom.controlsID).live("click mouseover mousedown mouseout mouseup", function (r) { var q = r.target.id; if (r.type == "click") { switch (q) { case h.dom.prevID.replace("#", ""): h.paused = true; a(h.dom.playPauseID).addClass("paused"); m(q); break; case h.dom.nextID.replace("#", ""): h.paused = true; a(h.dom.playPauseID).addClass("paused"); m(q); break; case h.dom.playPauseID.replace("#", ""): if (h.play == true) { h.paused = true; a(h.dom.playPauseID).addClass("paused"); i() } else { h.paused = false; a(h.dom.playPauseID).removeClass("paused"); n() } break } } else { if (r.type == "mouseover" && a("#" + q).hasClass("controls")) { a("#" + q).addClass("over") } else { if (r.type == "mousedown" && a("#" + q).hasClass("controls")) { a("#" + q).addClass("down") } else { if (r.type == "mouseup" && a("#" + q).hasClass("controls")) { a("#" + q).removeClass("down") } else { if (r.type == "mouseout" && a("#" + q).hasClass("controls")) { a("#" + q).removeClass("over") } } } } } }); a(h.dom.wrapperID).append('<ul id="' + h.dom.controlsID.replace("#", "") + '"><li id="' + h.dom.playPauseID.replace("#", "") + '" class="controls"></li><li id="' + h.dom.prevID.replace("#", "") + '" class="controls"></li><li id="' + h.dom.nextID.replace("#", "") + '" class="controls"></li></ul>') } if (e.displayType != "fade") { a(h.dom.contentID).mouseover(function () { if (h.paused == false) { i() } }).mouseout(function () { if (h.paused == false) { n() } }) } l() } function l() { if (h.contentLoaded == false) { if (e.ajaxFeed) { if (e.feedType == "xml") { a.ajax({ url: e.feedUrl, cache: false, dataType: e.feedType, async: true, success: function (u) { count = 0; for (var r = 0; r < u.childNodes.length; r++) { if (u.childNodes[r].nodeName == "rss") { xmlContent = u.childNodes[r] } } for (var s = 0; s < xmlContent.childNodes.length; s++) { if (xmlContent.childNodes[s].nodeName == "channel") { xmlChannel = xmlContent.childNodes[s] } } for (var q = 0; q < xmlChannel.childNodes.length; q++) { if (xmlChannel.childNodes[q].nodeName == "item") { xmlItems = xmlChannel.childNodes[q]; var v, t = false; for (var w = 0; w < xmlItems.childNodes.length; w++) { if (xmlItems.childNodes[w].nodeName == "title") { v = xmlItems.childNodes[w].lastChild.nodeValue } else { if (xmlItems.childNodes[w].nodeName == "link") { t = xmlItems.childNodes[w].lastChild.nodeValue } } if ((v !== false && v != "") && t !== false) { h.newsArr["item-" + count] = { type: e.titleText, content: '<a href="' + t + '">' + v + "</a>" }; count++; v = false; t = false } } } } if (k(h.newsArr < 1)) { o("Couldn't find any content from the XML feed for the ticker to use!"); return false } p(); h.contentLoaded = true } }) } else { o("Code Me!") } } else { if (e.htmlFeed) { if (a(b + " LI").length > 0) { a(b + " LI").each(function (q) { h.newsArr["item-" + q] = { type: e.titleText, content: a(this).html()} }); p() } else { o("Couldn't find HTML any content for the ticker to use!"); return false } } else { o("The ticker is set to not use any types of content! Check the settings for the ticker."); return false } } } } function p() { h.contentLoaded = true; a(h.dom.titleElem).html(h.newsArr["item-" + h.position].type); a(h.dom.contentID).html(h.newsArr["item-" + h.position].content); if (h.position == (k(h.newsArr) - 1)) { h.position = 0 } else { h.position++ } distance = a(h.dom.contentID).width(); time = distance / e.speed; g() } function g() { a(h.dom.contentID).css("opacity", "1"); if (h.play) { var q = a(h.dom.titleElem).width() + 0; a(h.dom.revealID).css(e.direction, q + "px"); if (e.displayType == "fade") { a(h.dom.revealID).hide(0, function () { a(h.dom.contentID).css(e.direction, q + "px").fadeIn(e.fadeInSpeed, j) }) } else { if (e.displayType == "scroll") { } else { a(h.dom.revealElem).show(0, function () { a(h.dom.contentID).css(e.direction, q + "px").show(); animationAction = e.direction == "right" ? { marginRight: distance + "px"} : { marginLeft: distance + "px" }; a(h.dom.revealID).css("margin-" + e.direction, "0px").delay(20).animate(animationAction, time, "linear", j) }) } } } else { return false } } function j() { if (h.play) { a(h.dom.contentID).delay(e.pauseOnItems).fadeOut(e.fadeOutSpeed); if (e.displayType == "fade") { a(h.dom.contentID).fadeOut(e.fadeOutSpeed, function () { a(h.dom.wrapperID).find(h.dom.revealElem + "," + h.dom.contentID).hide().end().find(h.dom.tickerID + "," + h.dom.revealID).show().end().find(h.dom.tickerID + "," + h.dom.revealID).removeAttr("style"); p() }) } else { a(h.dom.revealID).hide(0, function () { a(h.dom.contentID).fadeOut(e.fadeOutSpeed, function () { a(h.dom.wrapperID).find(h.dom.revealElem + "," + h.dom.contentID).hide().end().find(h.dom.tickerID + "," + h.dom.revealID).show().end().find(h.dom.tickerID + "," + h.dom.revealID).removeAttr("style"); p() }) }) } } else { a(h.dom.revealElem).hide() } } function i() { h.play = false; a(h.dom.tickerID + "," + h.dom.revealID + "," + h.dom.titleID + "," + h.dom.titleElem + "," + h.dom.revealElem + "," + h.dom.contentID).stop(true, true); a(h.dom.revealID + "," + h.dom.revealElem).hide(); a(h.dom.wrapperID).find(h.dom.titleID + "," + h.dom.titleElem).show().end().find(h.dom.contentID).show() } function n() { h.play = true; h.paused = false; j() } function m(q) { i(); switch (q) { case "prev": if (h.position == 0) { h.position = k(h.newsArr) - 2 } else { if (h.position == 1) { h.position = k(h.newsArr) - 1 } else { h.position = h.position - 2 } } a(h.dom.titleElem).html(h.newsArr["item-" + h.position].type); a(h.dom.contentID).html(h.newsArr["item-" + h.position].content); break; case "next": a(h.dom.titleElem).html(h.newsArr["item-" + h.position].type); a(h.dom.contentID).html(h.newsArr["item-" + h.position].content); break } if (h.position == (k(h.newsArr) - 1)) { h.position = 0 } else { h.position++ } } }) }; a.fn.ticker.defaults = { speed: 0.1, ajaxFeed: false, feedUrl: "", feedType: "xml", displayType: "reveal", htmlFeed: true, debugMode: true, controls: true, titleText: "Latest", direction: "ltr", pauseOnItems: 3000, fadeInSpeed: 600, fadeOutSpeed: 300} })(jQuery);
