javascript - js functions in jquery plugin -
i looking improving js skills js , of how works little confused on how jquery plugins work.
i have started plugin. when standalone functions being called work's fine want plugin.
(function ( $ ) { $.fn.countdown = function( options ) { // easiest way have default options. var settings = $.extend({ // these defaults. dayselector : "", hourselector : "", minuteselector : "", secondselector : "", launchdate : new date("december 25, 2013 12:01:00"), procentagedone : 1, headercolor : 'yellow', progressfillcolor : 'green', description : {header:"header",text:"sample text."} }, options ); var secondsremaining = math.floor(settings.launchdate.gettime() / 1000) - math.floor(new date().gettime() / 1000); /* functions calls countdown*/ count(secondsremaining); updateprogress(settings.procentagedone); setheadercolor(settings.headercolor); setprogressfillcolor(settings.progressfillcolor); setprogressdescription(settings.description['header'], settings.description['text']); /* countdown functions */ var count = function(secondsremaining) { alert(secondsremaining) var days = math.floor(secondsremaining / 86400), hours = math.floor((secondsremaining - (days * 86400)) / 3600), minutes = math.floor((secondsremaining - (days * 86400) - (hours * 3600)) / 60), seconds = secondsremaining - (days * 86400) - (hours * 3600) - (minutes * 60); if(secondsremaining > 0) { if(days < 10) { days = '0' + days; } if(hours < 10) { hours = '0' + hours; } if(minutes < 10) { minutes = '0' + minutes; } if(seconds < 10) { seconds = '0' + seconds; } $('.days > .number').html(days); $('.hours > .number').html(hours); $('.minutes > .number').html(minutes); $('.seconds > .number').html(seconds); secondsremaining--; } else { if(secondsremaining == 0) {window.location.reload();} } window.settimeout(function() {countdown(secondsremaining); }, 1000); } var updateprogress = function (procent) { if(typeof procent !== "number") {procent = 0;} if(procent <= 7) { $('.progressbarfill').css({ width: '7%' }).find('.progressbarfillmiddle').html(procent + '%'); } else if(procent >= 100) { $('.progressbarfill').css({ width: '100%' }).find('.progressbarfillmiddle').html('100%'); } else { $('.progressbarfill').css({ width: procent + '%' }).find('.progressbarfillmiddle').html(procent + '%'); } } var setprogressdescription = function (header, text){ $('.progressdescriptionmiddle').find('.descriptionheader').html(header); $('.progressdescriptionmiddle').find('.descriptiontext').html(text); } var objectconverter = function (array) { var object = {}; for(var i=0; i<array.length; i++) { object[array[i]] = ''; } return object; } var setheadercolor = function (color) { color = color.tolowercase(); if(typeof color === "undefined") { color = 'yellow'; } if(color in objectconverter(['green', 'blue', 'yellow', 'purple', 'red', 'gray'])) { $('.header').attr('class', 'header').addclass(color); } } var setprogressfillcolor = function (color) { color = color.tolowercase(); if(typeof color === "undefined") { color = 'green'; } if(color in objectconverter(['green', 'blue', 'yellow', 'purple', 'red', 'gray'])) { $('.progressbarfill').attr('class', 'progressbarfill clear').addclass(color); } } }; }( jquery ));
and want call
$.countdown({ launchdate : new date("december 25, 2013 12:01:00"), procentagedone : 1, headercolor : 'yellow', progressfillcolor : 'green', description:{header:"header text", text:"this sample text."} });
but im unsure on how call function in plugin make work. please me out , clear thoughts on matter.
Comments
Post a Comment