From 966225a44fde0acc19336e17fe70710cc27b79cd Mon Sep 17 00:00:00 2001 From: Jason Zhou Date: Sun, 16 Feb 2014 19:11:39 +0800 Subject: [PATCH] add demo --- Gruntfile.js | 16 ++ demo/calendar/images/icon.png | Bin 0 -> 776 bytes demo/calendar/images/weixin_icon.png | Bin 0 -> 4733 bytes demo/calendar/index.html | 69 ++++++ demo/calendar/js/calendar.js | 405 +++++++++++++++++++++++++++++++++++ demo/calendar/js/calendar.min.js | 10 + demo/calendar/style.css | 290 +++++++++++++++++++++++++ demo/calendar/style.min.css | 1 + package.json | 1 + 9 files changed, 792 insertions(+) create mode 100644 demo/calendar/images/icon.png create mode 100644 demo/calendar/images/weixin_icon.png create mode 100644 demo/calendar/index.html create mode 100644 demo/calendar/js/calendar.js create mode 100644 demo/calendar/js/calendar.min.js create mode 100644 demo/calendar/style.css create mode 100644 demo/calendar/style.min.css diff --git a/Gruntfile.js b/Gruntfile.js index 29d64a2..b338b90 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -16,14 +16,30 @@ module.exports = function(grunt) { src: '**/*.js', dest: 'hl_build/', ext: '.min.js' + }, + buildDemo: { + src: 'demo/calendar/js/calendar.js', + dest: 'demo/calendar/js/calendar.min.js' + } + }, + cssmin: { + options: { + keepSpecialComments: 0 + }, + compress: { + files:{ + 'demo/calendar/style.min.css' : ['demo/calendar/style.css'] + } } } }); // 加载包含 "uglify" 任务的插件。 grunt.loadNpmTasks('grunt-contrib-uglify'); + grunt.loadNpmTasks('grunt-contrib-cssmin'); // 默认被执行的任务列表。 grunt.registerTask('default', ['uglify']); grunt.registerTask('hl', ['uglify:buildhl']); + grunt.registerTask('demo', ['cssmin']); }; \ No newline at end of file diff --git a/demo/calendar/images/icon.png b/demo/calendar/images/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..bf64c029af6bd38269120c1e57c9a96ac2f07aad GIT binary patch literal 776 zcmV+j1NZ!iP)28Toe{0KsuJ?9B_xT&LF@i@)7)qnbum( zNfwMU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DonQ6LIm%8j5 zKkN&ej2j74MY2{L0#T90L$`xIAcD9Q-9=t7@vCt4pmsy{9Owt|ww!@MB77NKt>d8_ zQ97@$Gxj(4g7hnm%DP5B^IAgoX>&H1ybev)C8#kmN9IbOK#|*1w*EQ!KqkX%R?v@^ zk=Ia+qoEwSRpj>Enn=G=q50NO4(7?#8n$>LWf66#PbtZvJVW#}IO`Bt0%`B3*W>!e zBnb1obI(@4*l@rm;D`;r(3)+{!2EH|H1lXW@I0h_5aM&8ZZ<0&Clb~pe132r;gtEO zym;u{fQ04hXq3C66eAiV&P}2Fs1AX&AI-$ql3|;wI~P19i1jQ%5NIJY4nV|2PxofpzA3@y-f2TI}P92~};126J zz1l8;harKcTiyxGaL9k__&+Nud=!k&=J4;B17*PfOp zHnGy!T2Z0w6aF1p=c8%VS4@ltuThem74|~@-lg21NZx*SAr4U`7`qta4;<^2(<=m+ z6ouA?L`=K!WT8Lw&VFjk5B(RIAkX*Cy2X9OIC$ea^NpEMAqmk1myi!%J$#ID2UWEE zub?i$(#2}i!K=)Y);9X3Z$L%)!izmxW9*92WGnr>qXGu#J6=BFR0xzW-_p&#GSngW zM^J<-r15-H5O5(B*9LP;avtM{(yPuvCK)j&S)&VZg($FTyqQ%@!AWT6DZ)PaSEz%_ z;mDljCRD7~No{tL;B3Chj!{w##Rmk!*x_Cg@gv}_T>j3`V;}QPk(|qw&hSjtXF^r( zN9JIK1dHynPeHlY!3YRC{@qWLzdOsVP)AEgE8BmC4n-XDtdlmJ-`k{Z^i97*u1ZD| zmum?9rW*=9Pw#KYBTpsIrI4fV_5iIMEom3|4lUyD*4$g6vYiJu-a}XDhjELv_as11 L%TTjO!vXU@s9Ob5 literal 0 HcmV?d00001 diff --git a/demo/calendar/index.html b/demo/calendar/index.html new file mode 100644 index 0000000..450ae3d --- /dev/null +++ b/demo/calendar/index.html @@ -0,0 +1,69 @@ + + + + +小推万年历,简洁美观的手机日历(HTML5版) + + + + + + + + + + + +
+ +

+ +
+ +
+
+
周日
+
周一
+
周二
+
周三
+
周四
+
周五
+
周六
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
+
+ +
+
+
宜
+ +
+ +
+
忌
+ +
+
+
+
+
+ + + + + + + diff --git a/demo/calendar/js/calendar.js b/demo/calendar/js/calendar.js new file mode 100644 index 0000000..a9a4732 --- /dev/null +++ b/demo/calendar/js/calendar.js @@ -0,0 +1,405 @@ +window.HuangLi = window.HuangLi || {}; + +(function () { + var mobile = { + platform: '', + version: 0, + Android: function () { + return this.platform === 'Android'; + }, + iOS: function () { + return this.platform === 'iOS'; + }, + init: function () { + var ua = navigator.userAgent; + if (ua.match(/Android/i)) { + this.platform = 'Android'; + this.version = parseFloat(ua.slice(ua.indexOf("Android") + 8)); + } + else if (ua.match(/iPhone|iPad|iPod/i)) { + this.platform = 'iOS'; + this.version = parseFloat(ua.slice(ua.indexOf("OS") + 3)); + } + } + }; + mobile.init(); + this.mobile = mobile; +} ()); + +(function() { + /** + * 动态加载js文件 + * @param {string} url js文件的url地址 + * @param {Function} callback 加载完成后的回调函数 + */ + var _getScript = function(url, callback) { + var head = document.getElementsByTagName('head')[0], + js = document.createElement('script'); + + js.setAttribute('type', 'text/javascript'); + js.setAttribute('src', url); + + head.appendChild(js); + + //执行回调 + var callbackFn = function(){ + if(typeof callback === 'function'){ + callback(); + } + }; + + if (document.all) { //IE + js.onreadystatechange = function() { + if (js.readyState == 'loaded' || js.readyState == 'complete') { + callbackFn(); + } + } + } else { + js.onload = function() { + callbackFn(); + } + } + } + + //如果使用的是zepto,就添加扩展函数 + if(Zepto){ + $.getScript = _getScript; + } +})(); + + +(function () { + var Footprint = function () {}; + // Default template settings, uses ASP/PHP/JSP delimiters, change the + // following template settings to use alternative delimiters. + var templateSettings = { + evaluate : /<%([\s\S]+?)%>/g, + interpolate : /<%=([\s\S]+?)%>/g + }; + + // JavaScript micro-templating, similar to John Resig's implementation. + // Underscore templating handles arbitrary delimiters, preserves whitespace, + // and correctly escapes quotes within interpolated code. + Footprint.compile = function(str, settings) { + var c = settings || templateSettings; + var tmpl = 'var __p=[],print=function(){__p.push.apply(__p,arguments);};' + + 'with(obj||{}){__p.push(\'' + + str.replace(/\\/g, '\\\\') + .replace(/'/g, "\\'") + .replace(c.interpolate, function(match, code) { + return "'," + code.replace(/\\'/g, "'") + ",'"; + }) + .replace(c.evaluate || null, function(match, code) { + return "');" + code.replace(/\\'/g, "'") + .replace(/[\r\n\t]/g, ' ') + "__p.push('"; + }) + .replace(/\r/g, '\\r') + .replace(/\n/g, '\\n') + .replace(/\t/g, '\\t') + + "');}return __p.join('');"; + return new Function('obj', tmpl); + }; + + // Preserves template method for compatible with legacy call. + Footprint.template = function (str, data) { + var compilied = Footprint.compile(str); + return compilied(data); + }; + + if (typeof exports !== "undefined") { + exports.Footprint = Footprint; + } else { + window.Footprint = Footprint; + } + + //如果使用的是zepto,就添加扩展函数 + if(Zepto){ + $.template = Footprint.template; + } +}()); + +var Calendar = (function(){ + var hlurl = 'http://cdn.tuijs.com/js/'; + var hlMinYear = 2008; + var hlMaxYear = 2020; + var minYear = 1891;//最小年限 + var maxYear = 2100;//最大年限 + var itemTemp = [ + '
', + ' <%=iconText%>', + ' <%=day%>', + ' <%=lunar%>', + '
' + ]; + + var now = new Date(); + var current = null; + var DATA = null; + var panel = [0,1]; //当前显示面板panel[0] + var pageWidth = 0; //设备宽度 + var slideIng = false; //是否滑动中 + var timer = -1; + + var formateDayD4 = function(month,day){ + month = month+1; + month = month<10 ? '0'+month : month; + day = day<10 ? '0'+day : day; + return 'd'+month+day; + }; + + function formatDate(){ + if(!current)return ''; + var year = current.year; + var month = current.month; + var day = current.day; + month = month<10 ? '0'+month : month; + day = day<10 ? '0'+day : day; + return year+'-'+month+'-'+day; + }; + + function setCurrentByNow(year,month,day,pos){ + current = { + year : year || now.getFullYear(), + month : month || now.getMonth()+1, + day : day || now.getDate(), + pos : pos || 0 + }; + }; + + //黄历 + function getHL(){ + if(HuangLi['y'+current.year]){ //该年已有黄历数据 + var hl = HuangLi['y'+current.year][formateDayD4(current.month,current.day)]; + showHL(hl); + }else if(current.year>=hlMinYear && current.year<=hlMaxYear){ + $.getScript(hlurl+'hl'+current.year+'.min.js',function(){ + var hl = HuangLi['y'+current.year][formateDayD4(current.month,current.day)]; + showHL(hl); + }); + } + } + function showHL(hl){ + if(hl){ + $('.hl_y_content').html(hl.y); + $('.hl_j_content').html(hl.j); + $('.date_hl').show(); + }else{ + $('.date_hl').hide(); + } + }; + + function showInfo(_this){ + var currentLunar = LunarCalendar.solarToLunar(current.year,current.month,current.day); + var weekday = new Date(current.year,current.month-1,current.day).getDay(); + var weekList = ['日','一','二','三','四','五','六']; + $('#toolbar h1').html(formatDate()); + $('.date_lunar_info').html('农历'+currentLunar.lunarMonthName+currentLunar.lunarDayName+' 星期'+weekList[weekday]); + $('.date_gan_zhi').html(currentLunar.GanZhiYear+'年['+currentLunar.zodiac+'年] '+currentLunar.GanZhiMonth+'月 '+currentLunar.GanZhiDay+'日'); + + var fetv = []; + if(currentLunar.term) fetv.push(currentLunar.term); + if(currentLunar.lunarFestival) fetv.push(currentLunar.lunarFestival); + if(currentLunar.solarFestival) fetv.push(currentLunar.solarFestival.split(' ')); + $('.date_fetv').html(fetv.length>0 ? '节假日纪念日:'+fetv.join(',') : ''); + + //当前日期 + if(_this){ + _this.attr('class','date_item date_current'); + } + + //拉取黄历 + getHL(); + }; + + //恢复指定日期的状态信息 + function resetInfo(){ + //今天 + var oldObj = $('#date_list_'+panel[0]).find('.date_item').eq(current.pos); + if(now.getFullYear()==current.year && now.getMonth()+1==current.month && now.getDate()==current.day){ + oldObj.attr('class','date_item date_today'); + }else{ + oldObj.attr('class','date_item'); + } + }; + + function showDate(){ + DATA = LunarCalendar.calendar(current.year,current.month,true); + + var dateHtml = ''; + var temp = itemTemp.join(''); + + for(var i=0;i=DATA.firstDay+DATA.monthDays){ //非本月日期 + itemCls = ' date_other'; + } + extendObj.itemCls = itemCls; + + var lunar = itemData.lunarDayName; + //以下判断根据优先级 + if(itemData.solarFestival) lunar = itemData.solarFestival; + if(itemData.lunarFestival) lunar = itemData.lunarFestival; + if(itemData.term) lunar = itemData.term; + extendObj.lunar = lunar; + + $.extend(itemData,extendObj); + + dateHtml += $.template(temp,itemData); + + if(i%7==6){//某行尾列 + dateHtml+=''; + }; + }; + + $('#date_list_'+panel[0]).html(dateHtml); + + showInfo(); + }; + + //切换月份,可指定 + function pageDate(offset,_year,_month,_day){ + var year,month,day; + if(_year && _month){ //直接指定 + year = _year; + month = _month; + }else{ + if(current.month+offset<1){ //上一年 + year = current.year-1; + month = 12; + }else if(current.month+offset>12){ //下一年 + year = current.year+1; + month = 1; + }else{ + year = current.year; + month = current.month+offset; + } + } + day = _day ? _day : (current.day > LunarCalendar.getSolarMonthDays[month-1] ? LunarCalendar.getSolarMonthDays[month-1] : current.day); + if(yearmaxYear)return; //超过范围 + + setCurrentByNow(year,month,day); + changePanel(); + showDate(); + + slide(offset); + }; + function changePanel(){ + var first = panel.shift(); + panel.push(first); + }; + //滑动 + function slide(offset){ + timer && clearTimeout(timer); + setSlidePos({time:0,pos:0}); + $('#date_list_'+panel[0]).css({left:offset * pageWidth}); //将要显示 + $('#date_list_'+panel[1]).css({left:0}); //当前显示 + + if(offset>0){//左滑 + timer = setTimeout(function(){ + setSlidePos({time:300,pos:pageWidth * -1}); + },50); + }else{ //右滑 + timer = setTimeout(function(){ + setSlidePos({time:300,pos:pageWidth}); + },50); + } + }; + function setSlidePos(opt){ + var slide = $('.date_slide')[0]; + slide.style.webkitTransitionDuration = opt.time+'ms'; + setTranslate(slide,opt.pos); + }; + function setTranslate(obj,pos){ + if(mobile.platform=='iOS'){//iOS下启用3d加速,安卓下有BUG,使用2d + obj.style.webkitTransform = 'translate3d('+pos+'px,0px,0px)'; + }else{ + obj.style.webkitTransform = 'translate('+pos+'px,0px)'; + } + }; + + function addEvent(){ //base hammer.js + $('.date_list').hammer().on('tap','.date_item',function(){ + var index = $(this).attr('data-index'); + index = parseInt(index,10); + var itemData = DATA.monthData[index]; + + if(index=DATA.firstDay+DATA.monthDays){//下一个月 + pageDate(1,itemData.year,itemData.month,itemData.day); + }else{ + resetInfo(); + setCurrentByNow(itemData.year,itemData.month,itemData.day,index); + showInfo($(this)); + } + }); + + $('.today').hammer().on('tap',function(event){ + pageDate(1,now.getFullYear(),now.getMonth()+1,now.getDate()); + return false; + }); + + $('.slide_wrap').hammer().on('swipeleft',function(event){ + pageDate(1); + event.preventDefault(); + event.gesture.preventDefault(); + return false; + }); + + $('.slide_wrap').hammer().on('swiperight',function(event){ + pageDate(-1); + event.preventDefault(); + event.gesture.preventDefault(); + return false; + }); + }; + + function initPageElm(){ + pageWidth = $(document).width(); + var panelElm0 = $('.date_list').eq(0); + var panelElm1 = $('.date_list').eq(1); + panelElm0.css('width',pageWidth); + panelElm1.css({'width':pageWidth,'left':pageWidth}); + if(mobile.platform=='iOS'){//iOS启用3d,同时将子元素也设置一下,防止BUG + setTranslate(panelElm0[0],0); + setTranslate(panelElm0[1],0); + } + }; + + function init(){ + initPageElm(); + addEvent(); + setCurrentByNow(); + showDate(); + }; + + return { + init : init + }; +})(); + +$(function(){ + Calendar.init(); +}); \ No newline at end of file diff --git a/demo/calendar/js/calendar.min.js b/demo/calendar/js/calendar.min.js new file mode 100644 index 0000000..2ef1e44 --- /dev/null +++ b/demo/calendar/js/calendar.min.js @@ -0,0 +1,10 @@ +/** + * 农历(阴历)万年历 + * LunarCalendar;NPM NAME:lunar-calendar + * vervison : v0.1.4 + * Github : https://github.com/zzyss86/LunarCalendar + * HomePage : http://www.tuijs.com/ + * Author : JasonZhou + * Email : zzyss86@qq.com + */ +window.HuangLi=window.HuangLi||{},function(){var a={platform:"",version:0,Android:function(){return"Android"===this.platform},iOS:function(){return"iOS"===this.platform},init:function(){var a=navigator.userAgent;a.match(/Android/i)?(this.platform="Android",this.version=parseFloat(a.slice(a.indexOf("Android")+8))):a.match(/iPhone|iPad|iPod/i)&&(this.platform="iOS",this.version=parseFloat(a.slice(a.indexOf("OS")+3)))}};a.init(),this.mobile=a}(),function(){var a=function(a,b){var c=document.getElementsByTagName("head")[0],d=document.createElement("script");d.setAttribute("type","text/javascript"),d.setAttribute("src",a),c.appendChild(d);var e=function(){"function"==typeof b&&b()};document.all?d.onreadystatechange=function(){("loaded"==d.readyState||"complete"==d.readyState)&&e()}:d.onload=function(){e()}};Zepto&&($.getScript=a)}(),function(){var a=function(){},b={evaluate:/<%([\s\S]+?)%>/g,interpolate:/<%=([\s\S]+?)%>/g};a.compile=function(a,c){var d=c||b,e="var __p=[],print=function(){__p.push.apply(__p,arguments);};with(obj||{}){__p.push('"+a.replace(/\\/g,"\\\\").replace(/'/g,"\\'").replace(d.interpolate,function(a,b){return"',"+b.replace(/\\'/g,"'")+",'"}).replace(d.evaluate||null,function(a,b){return"');"+b.replace(/\\'/g,"'").replace(/[\r\n\t]/g," ")+"__p.push('"}).replace(/\r/g,"\\r").replace(/\n/g,"\\n").replace(/\t/g,"\\t")+"');}return __p.join('');";return new Function("obj",e)},a.template=function(b,c){var d=a.compile(b);return d(c)},"undefined"!=typeof exports?exports.Footprint=a:window.Footprint=a,Zepto&&($.template=a.template)}();var Calendar=function(){function a(){if(!w)return"";var a=w.year,b=w.month,c=w.day;return b=10>b?"0"+b:b,c=10>c?"0"+c:c,a+"-"+b+"-"+c}function b(a,b,c,d){w={year:a||v.getFullYear(),month:b||v.getMonth()+1,day:c||v.getDate(),pos:d||0}}function c(){if(HuangLi["y"+w.year]){var a=HuangLi["y"+w.year][B(w.month,w.day)];d(a)}else w.year>=q&&w.year<=r&&$.getScript(p+"hl"+w.year+".min.js",function(){var a=HuangLi["y"+w.year][B(w.month,w.day)];d(a)})}function d(a){a?($(".hl_y_content").html(a.y),$(".hl_j_content").html(a.j),$(".date_hl").show()):$(".date_hl").hide()}function e(b){var d=LunarCalendar.solarToLunar(w.year,w.month,w.day),e=new Date(w.year,w.month-1,w.day).getDay(),f=["日","一","二","三","四","五","六"];$("#toolbar h1").html(a()),$(".date_lunar_info").html("农历"+d.lunarMonthName+d.lunarDayName+" 星期"+f[e]),$(".date_gan_zhi").html(d.GanZhiYear+"年["+d.zodiac+"年] "+d.GanZhiMonth+"月 "+d.GanZhiDay+"日");var g=[];d.term&&g.push(d.term),d.lunarFestival&&g.push(d.lunarFestival),d.solarFestival&&g.push(d.solarFestival.split(" ")),$(".date_fetv").html(g.length>0?"节假日纪念日:"+g.join(","):""),b&&b.attr("class","date_item date_current"),c()}function f(){var a=$("#date_list_"+y[0]).find(".date_item").eq(w.pos);v.getFullYear()==w.year&&v.getMonth()+1==w.month&&v.getDate()==w.day?a.attr("class","date_item date_today"):a.attr("class","date_item")}function g(){x=LunarCalendar.calendar(w.year,w.month,!0);for(var a="",b=u.join(""),c=0;c');var f={index:c,itemCls:"",iconCls:d.worktime?1==d.worktime?" worktime":" holiday":"",iconText:d.worktime?1==d.worktime?"班":"休":"",fetvCls:d.lunarFestival||d.term?" lunar_fetv":d.solarFestival?" solar_fetv":"",lunar:""},g="";v.getFullYear()==d.year&&v.getMonth()+1==d.month&&v.getDate()==d.day&&(g=" date_today"),w.year==d.year&&w.month==d.month&&w.day==d.day&&(g=" date_current",w.pos=c),(c=x.firstDay+x.monthDays)&&(g=" date_other"),f.itemCls=g;var h=d.lunarDayName;d.solarFestival&&(h=d.solarFestival),d.lunarFestival&&(h=d.lunarFestival),d.term&&(h=d.term),f.lunar=h,$.extend(d,f),a+=$.template(b,d),c%7==6&&(a+="")}$("#date_list_"+y[0]).html(a),e()}function h(a,c,d,e){var f,h,k;c&&d?(f=c,h=d):w.month+a<1?(f=w.year-1,h=12):w.month+a>12?(f=w.year+1,h=1):(f=w.year,h=w.month+a),k=e?e:w.day>LunarCalendar.getSolarMonthDays[h-1]?LunarCalendar.getSolarMonthDays[h-1]:w.day,s>f||f>t||(b(f,h,k),i(),g(),j(a))}function i(){var a=y.shift();y.push(a)}function j(a){A&&clearTimeout(A),k({time:0,pos:0}),$("#date_list_"+y[0]).css({left:a*z}),$("#date_list_"+y[1]).css({left:0}),A=a>0?setTimeout(function(){k({time:300,pos:-1*z})},50):setTimeout(function(){k({time:300,pos:z})},50)}function k(a){var b=$(".date_slide")[0];b.style.webkitTransitionDuration=a.time+"ms",l(b,a.pos)}function l(a,b){a.style.webkitTransform="iOS"==mobile.platform?"translate3d("+b+"px,0px,0px)":"translate("+b+"px,0px)"}function m(){$(".date_list").hammer().on("tap",".date_item",function(){var a=$(this).attr("data-index");a=parseInt(a,10);var c=x.monthData[a];a=x.firstDay+x.monthDays?h(1,c.year,c.month,c.day):(f(),b(c.year,c.month,c.day,a),e($(this)))}),$(".today").hammer().on("tap",function(){return h(1,v.getFullYear(),v.getMonth()+1,v.getDate()),!1}),$(".slide_wrap").hammer().on("swipeleft",function(a){return h(1),a.preventDefault(),a.gesture.preventDefault(),!1}),$(".slide_wrap").hammer().on("swiperight",function(a){return h(-1),a.preventDefault(),a.gesture.preventDefault(),!1})}function n(){z=$(document).width();var a=$(".date_list").eq(0),b=$(".date_list").eq(1);a.css("width",z),b.css({width:z,left:z}),"iOS"==mobile.platform&&(l(a[0],0),l(a[1],0))}function o(){n(),m(),b(),g()}var p="http://cdn.tuijs.com/js/",q=2008,r=2020,s=1891,t=2100,u=['
',' <%=iconText%>',' <%=day%>',' <%=lunar%>',"
"],v=new Date,w=null,x=null,y=[0,1],z=0,A=-1,B=function(a,b){return a+=1,a=10>a?"0"+a:a,b=10>b?"0"+b:b,"d"+a+b};return{init:o}}();$(function(){Calendar.init()}); \ No newline at end of file diff --git a/demo/calendar/style.css b/demo/calendar/style.css new file mode 100644 index 0000000..f133ba1 --- /dev/null +++ b/demo/calendar/style.css @@ -0,0 +1,290 @@ +@charset "utf-8"; +/* CSS Document */ +body { + font-family: "Helvetica Neue", Helvetica, STHeiTi, sans-serif; + word-wrap:break-word; +} +body,div,dl,dt,dd,ul,ol,li,h1,h2,h3,h4,h5,h6,pre,form,fieldset,input,textarea,p,blockquote,th,td,figure,time { + margin:0; + padding:0; + -webkit-text-size-adjust:none +} +table { + border-collapse:collapse; + border-spacing:0 +} +fieldset,img { + border:0 +} +address,caption,cite,code,dfn,em,strong,th,var { + font-style:normal; + font-weight:normal +} +ol,ul,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 +} +section,aside,article,nav { + display:block +} +a{ + color:#246183; + text-decoration:none +} +html { + font-size:100%; + -webkit-text-size-adjust:100%; + -ms-text-size-adjust:100% +} +body { + margin:0; + font-size:14px; + line-height:1.231; + height:100%; + width:100%; + background:#e8e8e8; + padding-bottom:30px; +} +input,button { + -webkit-tap-highlight-color:rgba(0,0,0,0) +} +input,input:focus,select:focus { + border:none; + outline:none; + background-color:#fff +} +.org{ color: #ee4e00;} +.blue{ color: #1a3181;} +.red{ color:#F00;} +.rred{ color:#aa0112;} +.green{ color:#090;} +.hide{ display:none;} +.show{ display:block;} + +.icon{ background:url(http://cdn.tuijs.com/upload/icon.png) no-repeat; width:36px; height:36px; display:block;} +.icon_set{ background-position:0 -64px;} + +.toolbar{ + overflow:hidden; + width:100%; + position:relative; + left:0px; + top:0px; + z-index:999; + height: 46px; + background-image: -webkit-gradient(linear,center top,center bottom,from(#df481a), to(#c82713)); + background-color:#d33716; + border-bottom:1px solid #ec6624; + display: -webkit-box; + display: box; +} +.toolbar h1{ + margin:5px 0 0 10px; + height:36px; + line-height:36px; + font-size:22px; + color:#FFF; + text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); + font-weight:bold; + -webkit-box-flex: 2; + box-flex: 2; +} +.toolbar .icon_calendar{ + margin:5px 0 0 10px; +} +.toolbar .action{ + margin:5px 10px; + display:block; + height:36px; + line-height:36px; + font-size:20px; + text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); + font-weight:bold; + color:#FFF; + text-align:right; + -webkit-box-flex: 1; + box-flex: 1; +} +.toolbar .action .today{ + color:#FFF; +} + +.wrapper{ + width:100%; +} +.slide_wrap{ + width:100%; + height:320px; + overflow:hidden; +} +.date_slide{ + position:relative; + left:0px; + top:0px; + transform-origin:0 0; + -webkit-transform-origin:0 0; + /*-webkit-animation-timing-function: ease-in-out; + -webkit-transition-duration: 300ms;*/ +} +.date_list{ + font-family: "Courier New", "Helvetica Neue", Helvetica, STHeiTi, sans-serif; + position:absolute; + top:0px; + left:0px; + -webkit-transform-origin:0 0; +} +.date_row{ + display: -webkit-box; + display: box; + width:100%; +} +.date_row .date_item{ + -webkit-box-flex: 1; + box-flex: 1; + border-color:#cecece; + border-style:solid; + border-width:0 1px 1px 0; + color:#5b5b5b; + position:relative; + text-align:right; + overflow:hidden; + width: 0%; + padding:6px 5px; + height:40px; +} +.date_item:last-child{ + border-right:none; +} +.date_item .date_day{ + font-size:20px; + display:block; +} +.date_item .date_lunar{ + height:16px; + line-height:16px; + font-size:12px; + color:#8a8a8a; + display:block; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; + word-wrap: normal; +} +.date_item .lunar_fetv{ + color:#14a700; +} +.date_item .solar_fetv{ + color:#d43111; +} +.date_item .date_icon{ + position:absolute; + left:0px; + top:0px; + padding:2px 3px; + color:#FFF; + font-size:12px; + display:none; +} +.date_item .holiday{ + background-color:#cd3a37; + border:1px solid #a82220; + display:block; +} +.date_item .worktime{ + background-color:#289ac9; + border:1px solid #87c7e2; + display:block; +} +.date_row .date_today{ + background-color:#b8bdbf; + color:#FFF; +} +.date_row .date_today .date_lunar{ + color:#FFF; +} +.date_row .date_current{ + background-color:#c82713; + color:#FFF; +} +.date_row .date_current .date_lunar{ + color:#FFF; +} +.date_row .date_other{ + opacity:0.4; +} +.date_week .date_item{ + line-height:30px; + height:30px; + border-right:none; + text-align:center; + font-size:16px; + padding:0px; +} + +/*指定日期详情*/ +.date_info{ + padding:10px; +} +.date_lunar_info{ + color:#d96b6b; + font-size:24px; + line-height:38px; + text-align:center; +} +.date_fetv{ + color:#666666; + line-height:22px; + font-size:16px; + margin-bottom:5px; +} +.date_gan_zhi{ + line-height:30px; + background-color:#e68383; + text-align:center; + color:#FFF; + font-size:16px; +} +.date_hl{ + display:none; +} +.date_hl_item{ + margin-top:5px; + line-height:24px; +} +.circle { + width: 24px; + height: 24px; + background-color: transparent; + border: 1px #14a700 solid; + -webkit-border-radius: 13px; + text-align:center; + line-height:26px; + font-size:16px; + display:inline-block; + margin-right:5px; +} +.hl_y{ + color:#14a700; +} +.hl_j{ + color:#d43111; + border: 1px #d43111 solid; +} +.hl_y_content{ + color:#14a700; +} +.hl_j_content{ + color:#d43111; +} \ No newline at end of file diff --git a/demo/calendar/style.min.css b/demo/calendar/style.min.css new file mode 100644 index 0000000..ced7014 --- /dev/null +++ b/demo/calendar/style.min.css @@ -0,0 +1 @@ +@charset "utf-8";body{font-family:"Helvetica Neue",Helvetica,STHeiTi,sans-serif;word-wrap:break-word}blockquote,body,dd,div,dl,dt,fieldset,figure,form,h1,h2,h3,h4,h5,h6,input,li,ol,p,pre,td,textarea,th,time,ul{margin:0;padding:0;-webkit-text-size-adjust:none}table{border-collapse:collapse;border-spacing:0}fieldset,img{border:0}address,caption,cite,code,dfn,em,strong,th,var{font-style:normal;font-weight:400}li,ol,ul{list-style:none}caption,th{text-align:left}h1,h2,h3,h4,h5,h6{font-size:100%;font-weight:400}q:after,q:before{content:''}abbr,acronym{border:0}article,aside,nav,section{display:block}a{color:#246183;text-decoration:none}html{font-size:100%;-webkit-text-size-adjust:100%;-ms-text-size-adjust:100%}body{margin:0;font-size:14px;line-height:1.231;height:100%;width:100%;background:#e8e8e8;padding-bottom:30px}button,input{-webkit-tap-highlight-color:rgba(0,0,0,0)}input,input:focus,select:focus{border:0;outline:0;background-color:#fff}.org{color:#ee4e00}.blue{color:#1a3181}.red{color:red}.rred{color:#aa0112}.green{color:#090}.hide{display:none}.show{display:block}.icon{background:url(http://cdn.tuijs.com/upload/icon.png) no-repeat;width:36px;height:36px;display:block}.icon_set{background-position:0 -64px}.toolbar{overflow:hidden;width:100%;position:relative;left:0;top:0;z-index:999;height:46px;background-image:-webkit-gradient(linear,center top,center bottom,from(#df481a),to(#c82713));background-color:#d33716;border-bottom:1px solid #ec6624;display:-webkit-box;display:box}.toolbar h1{margin:5px 0 0 10px;height:36px;line-height:36px;font-size:22px;color:#FFF;text-shadow:0 1px 0 rgba(0,0,0,.3);font-weight:700;-webkit-box-flex:2;box-flex:2}.toolbar .icon_calendar{margin:5px 0 0 10px}.toolbar .action{margin:5px 10px;display:block;height:36px;line-height:36px;font-size:20px;text-shadow:0 1px 0 rgba(0,0,0,.3);font-weight:700;color:#FFF;text-align:right;-webkit-box-flex:1;box-flex:1}.toolbar .action .today{color:#FFF}.wrapper{width:100%}.slide_wrap{width:100%;height:320px;overflow:hidden}.date_slide{position:relative;left:0;top:0;transform-origin:0 0;-webkit-transform-origin:0 0}.date_list{font-family:"Courier New","Helvetica Neue",Helvetica,STHeiTi,sans-serif;position:absolute;top:0;left:0;-webkit-transform-origin:0 0}.date_row{display:-webkit-box;display:box;width:100%}.date_row .date_item{-webkit-box-flex:1;box-flex:1;border-color:#cecece;border-style:solid;border-width:0 1px 1px 0;color:#5b5b5b;position:relative;text-align:right;overflow:hidden;width:0;padding:6px 5px;height:40px}.date_item:last-child{border-right:0}.date_item .date_day{font-size:20px;display:block}.date_item .date_lunar{height:16px;line-height:16px;font-size:12px;color:#8a8a8a;display:block;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;word-wrap:normal}.date_item .lunar_fetv{color:#14a700}.date_item .solar_fetv{color:#d43111}.date_item .date_icon{position:absolute;left:0;top:0;padding:2px 3px;color:#FFF;font-size:12px;display:none}.date_item .holiday{background-color:#cd3a37;border:1px solid #a82220;display:block}.date_item .worktime{background-color:#289ac9;border:1px solid #87c7e2;display:block}.date_row .date_today{background-color:#b8bdbf;color:#FFF}.date_row .date_today .date_lunar{color:#FFF}.date_row .date_current{background-color:#c82713;color:#FFF}.date_row .date_current .date_lunar{color:#FFF}.date_row .date_other{opacity:.4}.date_week .date_item{line-height:30px;height:30px;border-right:0;text-align:center;font-size:16px;padding:0}.date_info{padding:10px}.date_lunar_info{color:#d96b6b;font-size:24px;line-height:38px;text-align:center}.date_fetv{color:#666;line-height:22px;font-size:16px;margin-bottom:5px}.date_gan_zhi{line-height:30px;background-color:#e68383;text-align:center;color:#FFF;font-size:16px}.date_hl{display:none}.date_hl_item{margin-top:5px;line-height:24px}.circle{width:24px;height:24px;background-color:transparent;border:1px #14a700 solid;-webkit-border-radius:13px;text-align:center;line-height:26px;font-size:16px;display:inline-block;margin-right:5px}.hl_y{color:#14a700}.hl_j{color:#d43111;border:1px #d43111 solid}.hl_y_content{color:#14a700}.hl_j_content{color:#d43111} \ No newline at end of file diff --git a/package.json b/package.json index c00004b..65cf452 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "devDependencies": { "grunt": "0.4.2", "grunt-contrib-uglify" : "0.3.2", + "grunt-contrib-cssmin": "0.7.0", "mocha": "*", "expect.js": "*" }, -- 2.7.4