/********************************************* * common.js * ------------------------------------------- * @noConflict * - jQuery * @init * @plugin *********************************************/ /* ------------------------------------------- * @init ------------------------------------------- */ jQuery(function(){ if(typeof(jQuery.localtimer) !== "undefined"){ jQuery.localtimer(); } else { $.localtimer(); } }); /* ------------------------------------------- * @plugin ------------------------------------------- */ (function($){ $.localtimer = function(){ /* * vars */ var localTime = new Date(), localResult = { year: localTime.getFullYear(), month: localTime.getMonth()+1, days: localTime.getDate(), hours: localTime.getHours(), minuts: localTime.getMinutes(), Seconds: localTime.getSeconds() }, monthXX = localResult.month < 10? "0" + localResult.month:localResult.month, daysXX = localResult.days < 10? "0" + localResult.days:localResult.days, nowDate = parseInt(localResult.year + "" + monthXX + "" + daysXX), $elm = $(".js-local-timer"), startNmBase = "lt-start-", endNmBase = "lt-end-", isStart = false, isEnd = true; /* * setting */ if($elm.length === 0){ return false; } $elm.hide(); /* * function */ $elm.each(function(){ var self = $(this), classNm = self.attr("class").split(" "), startDate = classNm[1] === (""||undefined)? "": parseInt(classNm[1].replace(startNmBase,"")), endDate = classNm[2] === (""||undefined)? "": parseInt(classNm[2].replace(endNmBase,"")); // flags if(startDate <= nowDate || startDate === "" || isNaN(startDate)){ isStart = true; } if(endDate >= nowDate || endDate === "" || isNaN(endDate)){ isEnd = false; } // trigger switch(isStart && !isEnd){ case true: self.show(); break; case false: self.hide().remove(); break; default: break; } // initialize isStart = false; isEnd = true; }); }; })(jQuery);