diff --git a/css/style.css b/css/style.css new file mode 100644 index 0000000..bab32ad --- /dev/null +++ b/css/style.css @@ -0,0 +1,17 @@ + +body{font:13px/1.231 arial,helvetica,clean,sans-serif;*font-size:small;*font:x-small}select,input,textarea,button{font:99% arial,helvetica,clean,sans-serif}table{font-size:inherit;font:100%}pre,code,kbd,samp,tt{font-family:monospace;*font-size:108%;line-height:100%}/* +Copyright (c) 2011, Yahoo! Inc. All rights reserved. +Code licensed under the BSD License: +http://developer.yahoo.com/yui/license.html +version: 2.9.0 +*/ +html{color:#000;background:#FFF}body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,code,form,fieldset,legend,input,button,textarea,select,p,blockquote,th,td{margin:0;padding:0}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,button,caption,cite,code,dfn,em,input,optgroup,option,select,strong,textarea,th,var{font:inherit}del,ins{text-decoration:none}li{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:normal}q:before,q:after{content:''}abbr,acronym{border:0;font-variant:normal}sup{vertical-align:baseline}sub{vertical-align:baseline}legend{color:#000} + +/*clearfix*/ +.clearfix{zoom:1;} +.clearfix:after{content:'.';display:block;clear:both;visibility:hidden;height:0;font-size:0;} + +/*newsticker*/ +.newsticker{background:#efefe;border-radius:5px;color:#402726;cursor:default;font-family:verdana;font-weight:bold;overflow:hidden;padding:7px 10px 0 10px;width:730px;height:23px;} +.newsticker:hover{background:#ff9e9a;} +.newsticker ul li{width:730px;height:30px;overflow:hidden;white-space:nowrap;display:none;} \ No newline at end of file diff --git a/src/jquery.newsfader.js b/src/jquery.newsfader.js index a0a65be..35b58bf 100644 --- a/src/jquery.newsfader.js +++ b/src/jquery.newsfader.js @@ -6,33 +6,62 @@ * Licensed under the MIT license. */ -(function($) { - // Collection method. - $.fn.newsfader = function() { - return this.each(function(i) { - // Do something awesome to each selected element. - $(this).html('awesome' + i); - }); - }; - - // Static method. - $.newsfader = function(options) { - // Override default options with passed-in options. - options = $.extend({}, $.newsfader.options, options); - // Return something awesome. - return 'awesome' + options.punctuation; - }; - // Static method default options. - $.newsfader.options = { - punctuation: '.' - }; +(function($) { + $.fn.dropdown = function(opts) { + // default configuration + var config = $.extend({}, { + fadeInTime: 800, + fadeOutTime: 800, + interval: 5600 + }, opts); + // main function + function init(obj) { + var dNewsticker = obj; + var dFrame = dNewsticker.find('.js-frame'); + var dItem = dFrame.find('.js-item'); + var dCurrent; + var stop = false; - // Custom selector. - $.expr[':'].newsfader = function(elem) { - // Is this element awesome? - return $(elem).text().indexOf('awesome') !== -1; + dItem.eq(0).addClass('current'); + dItem.eq(0).show(); + + var move = setInterval(function(){ + if(!stop){ + dCurrent = dFrame.find('.current'); + dCurrent.fadeOut(config.fadeOutTime, function(){ + if(dCurrent.next().length !== 0){ + dCurrent.removeClass('current'); + dCurrent.next().addClass('current'); + dCurrent.next().fadeIn(config.fadeInTime); + } + else{ + dCurrent.removeClass('current'); + dItem.eq(0).addClass('current'); + dItem.eq(0).fadeIn(config.fadeInTime); + } + }); + } + }, config.interval); + + dNewsticker.on('mouseover mouseout', function(e){ + if(e.type == 'mouseover'){ + stop = true; + } + else{ + stop = false; + } + }); + } + // initialize every element + this.each(function() { + init($(this)); + }); + return this; }; - -}(jQuery)); + // start + $(function() { + $('.js-newsticker').dropdown(); + }); +})(jQuery); \ No newline at end of file diff --git a/test/newsfader.html b/test/newsfader.html index 2bd9942..5d6b148 100644 --- a/test/newsfader.html +++ b/test/newsfader.html @@ -11,17 +11,28 @@ + +
-
- lame test markup - normal test markup - awesome test markup +
+
+
+ +
diff --git a/test/newsfader_test.js b/test/newsfader_test.js index ae98b36..83d5877 100644 --- a/test/newsfader_test.js +++ b/test/newsfader_test.js @@ -33,30 +33,5 @@ strictEqual(this.elems.newsfader(), this.elems, 'should be chainable'); }); - test('is awesome', function() { - expect(1); - strictEqual(this.elems.newsfader().text(), 'awesome0awesome1awesome2', 'should be awesome'); - }); - - module('jQuery.newsfader'); - - test('is awesome', function() { - expect(2); - strictEqual($.newsfader(), 'awesome.', 'should be awesome'); - strictEqual($.newsfader({punctuation: '!'}), 'awesome!', 'should be thoroughly awesome'); - }); - - module(':newsfader selector', { - // This will run before each test in this module. - setup: function() { - this.elems = $('#qunit-fixture').children(); - } - }); - - test('is awesome', function() { - expect(1); - // Use deepEqual & .get() when comparing jQuery objects. - deepEqual(this.elems.filter(':newsfader').get(), this.elems.last().get(), 'knows awesome when it sees it'); - }); }(jQuery));