diff --git a/scripts/jquery.bootstrap.newsbox.js b/scripts/jquery.bootstrap.newsbox.js index 8816472..15dc0b2 100644 --- a/scripts/jquery.bootstrap.newsbox.js +++ b/scripts/jquery.bootstrap.newsbox.js @@ -1,4 +1,4 @@ -/* +/* * jQuery Bootstrap News Box v1.0.1 * * Copyright 2014, Dragan Mitrovic @@ -213,7 +213,7 @@ if (typeof Object.create !== 'function') { self.animationStarted = true; - var html = '<' + self.newsTagName + ' style="display:none;" class="' + self.newsClassName + '">' + $(self.$elem).find(self.newsTagName).last().html() + '' + self.newsTagName + '>'; + var html = $(self.$elem).find(self.newsTagName).last().clone(true); $(self.$elem).prepend(html); $(self.$elem).find(self.newsTagName).first().slideDown(self.options.animationSpeed, function(){ $(self.$elem).find(self.newsTagName).last().remove(); @@ -223,14 +223,6 @@ if (typeof Object.create !== 'function') { self.animationStarted = false; self.onReset(self.isHovered); }); - - $(self.elem).find('.'+self.newsClassName).on('mouseenter', function(){ - self.onReset(true); - }); - - $(self.elem).find('.'+self.newsClassName).on('mouseout', function(){ - self.onReset(false); - }); }, onNext: function() { @@ -242,10 +234,9 @@ if (typeof Object.create !== 'function') { self.animationStarted = true; - var html = '<' + self.newsTagName + ' style="display:none;" class=' + self.newsClassName + '>' + $(self.$elem).find(self.newsTagName).first().html() + '' + self.newsTagName + '>'; - $(self.$elem).append(html); - $(self.$elem).find(self.newsTagName).first().slideUp(self.options.animationSpeed, function(){ + var html = $(this).clone(true); + $(self.$elem).append(html); $(this).remove(); }); @@ -253,14 +244,6 @@ if (typeof Object.create !== 'function') { self.animationStarted = false; self.onReset(self.isHovered); }); - - $(self.elem).find('.'+self.newsClassName).on('mouseenter', function(){ - self.onReset(true); - }); - - $(self.elem).find('.'+self.newsClassName).on('mouseout', function(){ - self.onReset(false); - }); } }; diff --git a/scripts/jquery.bootstrap.newsbox.min.js b/scripts/jquery.bootstrap.newsbox.min.js index 2be1b7d..a0bf488 100644 --- a/scripts/jquery.bootstrap.newsbox.min.js +++ b/scripts/jquery.bootstrap.newsbox.min.js @@ -1,9 +1,12 @@ -/* -* jQuery Bootstrap News Box v1.0.1 -* -* Copyright 2014, Dragan Mitrovic -* email: gagi270683@gmail.com -* Free to use and abuse under the MIT license. -* http://www.opensource.org/licenses/mit-license.php -*/ -if (typeof Object.create !== "function") { Object.create = function (e) { function t() { } t.prototype = e; return new t } } (function (e, t, n, r) { var i = { init: function (t, n) { var r = this; r.elem = n; r.$elem = e(n); r.newsTagName = r.$elem.find(":first-child").prop("tagName"); r.newsClassName = r.$elem.find(":first-child").attr("class"); r.timer = null; r.resizeTimer = null; r.animationStarted = false; r.isHovered = false; if (typeof t === "string") { if (console) { console.error("String property override is not supported") } throw "String property override is not supported" } else { r.options = e.extend({}, e.fn.bootstrapNews.options, t); r.prepareLayout(); if (r.options.autoplay) { r.animate() } if (r.options.navigation) { r.buildNavigation() } if (typeof r.options.onToDo === "function") { r.options.onToDo.apply(r, arguments) } } }, prepareLayout: function () { var n = this; e(n.elem).find("." + n.newsClassName).on("mouseenter", function () { n.onReset(true) }); e(n.elem).find("." + n.newsClassName).on("mouseout", function () { n.onReset(false) }); e.map(n.$elem.find(n.newsTagName), function (t, r) { if (r > n.options.newsPerPage - 1) { e(t).hide() } else { e(t).show() } }); if (n.$elem.find(n.newsTagName).length < n.options.newsPerPage) { n.options.newsPerPage = n.$elem.find(n.newsTagName).length } var r = 0; e.map(n.$elem.find(n.newsTagName), function (t, i) { if (i < n.options.newsPerPage) { r = parseInt(r) + parseInt(e(t).height()) + 10 } }); e(n.elem).css({ "overflow-y": "hidden", height: r }); e(t).resize(function () { if (n.resizeTimer !== null) { clearTimeout(n.resizeTimer) } n.resizeTimer = setTimeout(function () { n.prepareLayout() }, 200) }) }, findPanelObject: function () { var e = this.$elem; while (e.parent() !== r) { e = e.parent(); if (e.parent().hasClass("panel")) { return e.parent() } } return r }, buildNavigation: function () { var t = this.findPanelObject(); if (t) { var n = '
'; var r = e(t).find(".panel-footer")[0]; if (r) { e(r).append(n) } else { e(t).append('") } var i = this; e(t).find(".prev").on("click", function (e) { e.preventDefault(); i.onPrev() }); e(t).find(".next").on("click", function (e) { e.preventDefault(); i.onNext() }) } }, onStop: function () { }, onPause: function () { var e = this; e.isHovered = true; if (this.options.autoplay && e.timer) { clearTimeout(e.timer) } }, onReset: function (e) { var t = this; if (t.timer) { clearTimeout(t.timer) } if (t.options.autoplay) { t.isHovered = e; t.animate() } }, animate: function () { var e = this; e.timer = setTimeout(function () { if (!e.options.pauseOnHover) { e.isHovered = false } if (!e.isHovered) { if (e.options.direction === "up") { e.onNext() } else { e.onPrev() } } }, e.options.newsTickerInterval) }, onPrev: function () { var t = this; if (t.animationStarted) { return false } t.animationStarted = true; var n = "<" + t.newsTagName + ' style="display:none;" class="' + t.newsClassName + '">' + e(t.$elem).find(t.newsTagName).last().html() + "" + t.newsTagName + ">"; e(t.$elem).prepend(n); e(t.$elem).find(t.newsTagName).first().slideDown(t.options.animationSpeed, function () { e(t.$elem).find(t.newsTagName).last().remove() }); e(t.$elem).find(t.newsTagName + ":nth-child(" + parseInt(t.options.newsPerPage + 1) + ")").slideUp(t.options.animationSpeed, function () { t.animationStarted = false; t.onReset(t.isHovered) }); e(t.elem).find("." + t.newsClassName).on("mouseenter", function () { t.onReset(true) }); e(t.elem).find("." + t.newsClassName).on("mouseout", function () { t.onReset(false) }) }, onNext: function () { var t = this; if (t.animationStarted) { return false } t.animationStarted = true; var n = "<" + t.newsTagName + ' style="display:none;" class=' + t.newsClassName + ">" + e(t.$elem).find(t.newsTagName).first().html() + "" + t.newsTagName + ">"; e(t.$elem).append(n); e(t.$elem).find(t.newsTagName).first().slideUp(t.options.animationSpeed, function () { e(this).remove() }); e(t.$elem).find(t.newsTagName + ":nth-child(" + parseInt(t.options.newsPerPage + 1) + ")").slideDown(t.options.animationSpeed, function () { t.animationStarted = false; t.onReset(t.isHovered) }); e(t.elem).find("." + t.newsClassName).on("mouseenter", function () { t.onReset(true) }); e(t.elem).find("." + t.newsClassName).on("mouseout", function () { t.onReset(false) }) } }; e.fn.bootstrapNews = function (e) { return this.each(function () { var t = Object.create(i); t.init(e, this) }) }; e.fn.bootstrapNews.options = { newsPerPage: 4, navigation: true, autoplay: true, direction: "up", animationSpeed: "normal", newsTickerInterval: 4e3, pauseOnHover: true, onStop: null, onPause: null, onReset: null, onPrev: null, onNext: null, onToDo: null} })(jQuery, window, document) \ No newline at end of file +if(typeof Object.create!=='function'){Object.create=function(obj){function F(){};F.prototype=obj;return new F()}}(function($,w,d,undefined){var NewsBox={init:function(options,elem){var self=this;self.elem=elem;self.$elem=$(elem);self.newsTagName=self.$elem.find(":first-child").prop('tagName');self.newsClassName=self.$elem.find(":first-child").attr('class');self.timer=null;self.resizeTimer=null;self.animationStarted=!1;self.isHovered=!1;if(typeof options==='string'){if(console){console.error("String property override is not supported")} +throw("String property override is not supported")}else{self.options=$.extend({},$.fn.bootstrapNews.options,options);self.prepareLayout();if(self.options.autoplay){self.animate()} +if(self.options.navigation){self.buildNavigation()} +if(typeof self.options.onToDo==='function'){self.options.onToDo.apply(self,arguments)}}},prepareLayout:function(){var self=this;$(self.elem).find('.'+self.newsClassName).on('mouseenter',function(){self.onReset(!0)});$(self.elem).find('.'+self.newsClassName).on('mouseout',function(){self.onReset(!1)});$.map(self.$elem.find(self.newsTagName),function(newsItem,index){if(index>self.options.newsPerPage-1){$(newsItem).hide()}else{$(newsItem).show()}});if(self.$elem.find(self.newsTagName).length