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