/** * desc: 辅助方法 * author: wangyang * date: 2015-04-11 */ define(['config'], function(config) { return { //根据系统调用不同的函数 osProxy: function(fn) { var os = ''; if (config.isIOS) { os = 'ios'; } else if (config.isAndroid) { os = 'android'; } else if (config.isWX) { os = 'wx'; } else if (config.isChubao) { os = 'cb' } if (!!fn[os]) { return fn[os].call(); } else { // console.log(os + '-没有定义方法'); return false; } }, //动态载入样式 includeStyleElement: function(styles, styleId) { if (document.getElementById(styleId)) { return false; } var style = document.createElement('style'); style.id = styleId; (document.getElementsByTagName('head')[0] || document.body).appendChild(style); if (style.styleSheet) { //for ie style.styleSheet.cssText = styles; } else {//for w3c style.appendChild(document.createTextNode(styles)); } }, //获取当前的日期字符串 getDateStr: function(options) { var defaultOptions = { date: new Date(), separator: '' }; var finalOptions = $.extend(true, defaultOptions, options); var year = finalOptions.date.getFullYear(); var month = finalOptions.date.getMonth() + 1; if (month < 10) { month = '0' + month; } var day = finalOptions.date.getDate(); if (day < 10) { day = '0' + day; } return year + finalOptions.separator + month + finalOptions.separator + day; }, //返回倒计时字符串 formatCountDown: function(left_value) { var hour, minite, second; hour = parseInt(left_value / 3600); left_value -= 3600 * hour; minite = parseInt(left_value / 60); second = left_value - 60 * minite; if (minite < 10) { minite = '0' + minite; } if (second < 10) { second = '0' + second; } return hour + ' : ' + minite + ' : ' + second; } } })