/*changed by warlee * @link http://www.kalcaddle.com/ * @author warlee | e-mail:kalcaddle@qq.com * @copyright warlee 2014.(Shanghai)Co.,Ltd * @license http://kalcaddle.com/tools/licenses/license.txt */ //return 时间戳到秒 var time = function(){ var time = (new Date()).valueOf(); return parseInt(time/1000); } //return 时间戳,含小数点;小数点部分为毫秒;date('Y/m/d H:i:s',time()) or date('Y/m/d H:i:s') var timeFloat = function(){ var time = (new Date()).valueOf(); return time/1000; } var urlEncode = encodeURIComponent; var urlDecode = decodeURIComponent; var UUID = function(){ return 'uuid_'+time()+'_'+Math.ceil(Math.random()*10000) } var round = function(val,point){//随机数 if (!point) point = 2; point = Math.pow(10,parseInt(point)); return Math.round(parseFloat(val)*point)/point; } var roundFromTo = function(from,to){//生成from到to的随机数;整数,包含to不包含from var react = to - from; return Math.ceil(Math.random()*react+from); } var md5 = function(str){ return CryptoJS.MD5(str).toString(); } var aesEncode = function(str,key){ return CryptoJS.AES.encrypt(str,key).toString(); } var aesDecode = function(str,key){ return CryptoJS.AES.decrypt(str,key).toString(CryptoJS.enc.Utf8); } var replaceAll = function(str, find, replace_to){ while (str.indexOf(find) >= 0){ str = str.replace(find, replace_to); } return str; } var ltrim = function (str,remove){ if (!str || str.length == 0) return ""; var i;remove = remove==undefined?' ':remove; while (str.substring(0,remove.length) == remove ) { str = str.substring(remove.length); } return str; } var rtrim = function (str,remove){ if (!str || str.length == 0) return ""; var i;remove = remove == undefined?' ' : remove; while (str.substring(str.length - remove.length) == remove ) { str = str.substring(0,str.length - remove.length); } return str; } var trim = function (str,remove){ if(remove == undefined){ return str.replace(/(^\s*)|(\s*$)/g,""); } return ltrim(rtrim(str,remove),remove); } var quoteHtml = function(str){ str = str.replace(/"/g,'"'); str = str.replace(/'/g,'''); return str; } var quoteEncode = function(str){ str = str.replace(/(['"])/g,'\\$1'); return str; } var canvasSupport = function() { return !!document.createElement('canvas').getContext; } var isWap = function(){ if(navigator.userAgent.match(/(iPhone|iPod|Android|ios)/i)){ return true; } return false; } //var obj1 = $.extend({}, obj);//浅拷贝 //var obj2 = $.extend(true, {}, obj);//深拷贝 Array.prototype.remove = function(from, to) { var rest = this.slice((to || from) + 1 || this.length); this.length = from < 0 ? this.length + from : from; return this.push.apply(this, rest); }; //跨框架数据共享; var KOD_NAMESPACE = 'kod'; var ShareData = { data: function (name, value) { var top = ShareData.frameTop(); var cache = top['_CACHE'] || {}; top['_CACHE'] = cache; if(name==undefined){ return cache; } return value !== undefined ? cache[name] = value : cache[name]; }, remove: function (name) { var top = ShareData.frameTop(); var cache = top['_CACHE']; if (cache && cache[name]) delete cache[name]; }, frameChild:function(frame,action){ if (!window.frames[frame]) return false; var that = window.frames[frame]; try { action(that); } catch (e) { console.trace(); } return that; }, frameTop:function(frame,action){//frame=='' 则parent;为空则获取;指定则从top找child var top = window; var testParent = function (page) { try { if(page.parent && page.parent.KOD_NAMESPACE){ return page.parent; }else{ return false; } } catch (e) { return false; } }; while(testParent(top)!==false && top!=testParent(top)){ top = testParent(top); } if (frame!='' && typeof(frame) != 'undefined') { if (!top.frames[frame]) return false; top = top.frames[frame]; } if(top == window){ return top;//自己则忽略事件调用,避免循环 } if (typeof (action) == 'function'){ try { action(top); } catch (e) { //console.trace(); } } return top; } }; jQuery.easing.def="easeInOutCubic";//easeOutExpo,easeInOutExpo,easeInOutSine //cookie操作 //titmeout 单位为天 var Cookie = (function(){ var data = {}; var _init = function(){ data = {};//初始化 var cookieArray=document.cookie.split("; "); for (var i=0;i= 100) // seems to be a harded maximum of 30 serialized objects? return '[Unknown]'; ++i; // so we know we aren't using the original object anymore return value; } } return jsonEncode(obj,censor(obj)); } //队列数据类;用于历史记录记录前进后退等;数据浏览器持久化 //eg: var historySearch = new Queen(10,'historySearch'); function Queen(maxLength,identify){ //数据读取与存储 var data = function(list){ if(!LocalData.support()){ return []; } if(list == undefined){ return LocalData.getConfig(identify); }else{ return LocalData.setConfig(identify,list); } } var queenList = data();//本地存储初始化 if(!queenList){ queenList = []; } var index = queenList.length - 1; var add = function(val){ index = queenList.length-1;//重置 if (val == '' || val == queenList[queenList.length - 1]){ return; } if (queenList.length - 1 >= maxLength) { queenList = queenList.slice(1 , queenList.length); } queenList.push(val); data(queenList); index = queenList.length - 1;//重置 }; var next = function(){ if (++index <= queenList.length - 1) { return queenList[index]; }else{ index = queenList.length; return ''; } } var back = function(){ if (--index >= 0) { return queenList[index]; }else{ index = 0; return queenList[0]; } } var last = function(){ return queenList[queenList.length - 1]; } var clear = function(){ index = 0; queenList = []; data(queenList); } return { add:add, back:back, next:next, last:last, clear:clear, list:function(){ return queenList; } } }; function download(data, strFileName, strMimeType) { var self = window, // this script is only for browsers anyway... defaultMime = "application/octet-stream", // this default mime also triggers iframe downloads mimeType = strMimeType || defaultMime, payload = data, url = !strFileName && !strMimeType && payload, anchor = document.createElement("a"), toString = function(a){return String(a);}, myBlob = (self.Blob || self.MozBlob || self.WebKitBlob || toString), fileName = strFileName || "download", blob, reader; myBlob= myBlob.call ? myBlob.bind(self) : Blob ; if(String(this)==="true"){ payload=[payload, mimeType]; mimeType=payload[0]; payload=payload[1]; } if(url && url.length< 2048){ fileName = url.split("/").pop().split("?")[0]; anchor.href = url; // assign href prop to temp anchor if(anchor.href.indexOf(url) !== -1){ // if the browser determines that it's a potentially valid url path: var ajax=new XMLHttpRequest(); ajax.open( "GET", url, true); ajax.responseType = 'blob'; ajax.onload= function(e){ download(e.target.response, fileName, defaultMime); }; setTimeout(function(){ ajax.send();}, 0); // allows setting custom ajax headers using the return: return ajax; } // end if valid url? } if(/^data\:[\w+\-]+\/[\w+\-]+[,;]/.test(payload)){ if(payload.length > (1024*1024*1.999) && myBlob !== toString ){ payload=dataUrlToBlob(payload); mimeType=payload.type || defaultMime; }else{ return navigator.msSaveBlob ? // IE10 can't do a[download], only Blobs: navigator.msSaveBlob(dataUrlToBlob(payload), fileName) : saveToData(payload) ; // everyone else can save dataURLs un-processed } }//end if dataURL passed? blob = payload instanceof myBlob ? payload : new myBlob([payload], {type: mimeType}) ; function dataUrlToBlob(strUrl) { var parts= strUrl.split(/[:;,]/), type= parts[1], decoder= parts[2] == "base64" ? atob : decodeURIComponent, binData= decoder( parts.pop() ), mx= binData.length, i= 0, uiArr= new Uint8Array(mx); for(i;i

'+ '×
' $('body').append(html); $(tipsID).show().css({'left':($(window).width() - $(tipsID).innerWidth())/2}); $(window).bind('resize',function(){ if ($(tipsID).css('display') =="none") return; self.stop(true,true) $(tipsID).css({'left':($(window).width() - $(tipsID).width()) / 2}); }); $(tipsID).find('.tips_close').click(function(){ $(tipsID).animate({opacity:0}, in_time,0,function(){ $(this).hide(); }); }); } var self = $(tipsID),theType; switch(code){// success/warning/info/error case 100:delay = 2000;//加长时间 5s case true: case undefined: case 'success':theType = 'success';break; case 'info':theType = 'info';break; case 'warning':theType = 'warning';break; case false: case 'error':theType = 'error';delay = 2000;break; default:theType = 'info';break; } self.removeClass().addClass('tips_box '+theType); if (msg != undefined) self.find('.tips-msg p').html(msg); $(tipsID).show().css({'left':($(window).width() - $(tipsID).innerWidth())/2}); return self; }; var tips = function(msg,code){ if (msg && typeof(msg) == 'object'){ code = msg.code; msg = msg.data; } var self = _init(false,msg,code); self.stop(true,true) .css({opacity:0,'top':-self.height()}) .show() .animate({opacity:1,top:0},in_time,0) .delay(delay) .animate({opacity:0,top:-self.height()},in_time,0,function(){ self.remove(); }); }; var loading = function(msg,code){ if (typeof(msg) == 'object'){ code=msg.code; msg = msg.data; } if (msg == undefined) msg = 'loading...'; msg+= "   "; var self = _init(true,msg,code); self.stop(true,true) .css({'opacity':'0','top':-self.height()}) .animate({opacity:1,top:0},in_time,0); }; var close = function(msg,code){ if (typeof(msg) == 'object'){ try{ code=msg.code;msg = msg.data; if(code && typeof(msg) != 'string'){ msg = "Success!"; } }catch(e){ code=0;msg =''; }; } var self = _init(true,msg,code); self.delay(delay) .show() .animate({ opacity:0, top:-self.height() }, in_time,0,function(){ self.remove(); }); }; return{ tips:tips, loading:loading, close:close } })(); //获取keys var objectKeys = function(obj){ var keys = []; for(var p in obj){ if(obj.hasOwnProperty(p)){ keys.push(p); } } return keys; } //获取values var objectValues = function(obj){ var values = []; for(var p in obj){ keys.push(obj[p]); } return values; } var $sizeInt = function($obj){ var str = $obj+''; var theSize = parseInt(str.replace('px','')); if (isNaN(theSize)) { return 0; }else{ return theSize; } } //点击水波效果;按钮 var loadRipple = function(search_arr,ignore_arr){ var UUID = function(){ var time = (new Date()).valueOf(); return 'uuid_'+parseInt(time/1000)+'_'+Math.ceil(Math.random()*10000) } var getTarget = function($target){ for (var i = 0; i < search_arr.length; i++) { var se = search_arr[i]; if( se.substr(0,1) == '#'){ if($target.attr('id') == se.substr(1) ){ return $target; }else if($target.parent(se).length!=0){ return $($target.parents(se)[0]); } }else if( se.substr(0,1) == '.'){ if($target.hasClass(se.substr(1)) ){ return $target; }else if($target.parents(se).length!=0){ return $($target.parents(se)[0]); } }else{ if($target.is(se)){ return $target; }else if($target.parents(se).length!=0){ return $($target.parents(se)[0]); } } } return ''; } var isIgnore = function($target){ for (var i = 0; i < ignore_arr.length; i++) { var select = ignore_arr[i]; if($target.closest(select).length !=0){//从当前想上查找 return true; } } return false; } if (typeof(Worker) == "undefined" || $.browser.msie && $.browser.version<=10) { //ie 10不支持 但支持worker return;//不支持html5 css3 } //|| $(e.target).parents(".aui_state_focus").length!=0 $('body').on('mousedown', function (e) { var $target= getTarget($(e.target)); if($target=='' || isIgnore($target)){ return; } var uuid = 'ripple_'+UUID(); var father = $target;//$(this) $target var circle_width = $target.outerWidth(); $('
').appendTo(father); if($target.outerWidth()<$target.outerHeight()){ circle_width = $target.outerHeight(); } circle_width = circle_width>150?150:circle_width; circle_width = circle_width<50?50:circle_width; var $ripp = $('#'+uuid).css({ left: 0, top: 0, 'border-radius':$target.css("border-radius"), width: $target.innerWidth(), height:$target.innerHeight() }); var position = $ripp.parent().css('position'); if(position != 'absolute' && position != 'fixed'){//父元素为绝对定位则不设置相对定位 $ripp.parent().css('position','relative'); } $('#'+uuid+' .ripple').css({ 'background':$target.css('color'), "margin-left":e.pageX - circle_width/2 - $target.offset().left, "margin-top": e.pageY - circle_width/2 - $target.offset().top, "width": circle_width, "height":circle_width }); var animateTime = 700; setTimeout(function(){ $ripp.find('.ripple').css('transform',"scale(2.5)"); },animateTime); $(this).one('mouseup',function(){ $ripp.animate({'opacity':0},400,function(){ $ripp.remove(); }); }); }); } //通用遮罩层 var MaskView = (function(){ var opacity = 0.7; var color ='#000'; var animatetime = 250; var maskId = "#windowMaskView"; var maskContent = '#maskViewContent'; var staticPath = "./static/"; if(typeof(G) != "undefined"){ staticPath = G.static_path; } var add = function(content,t_opacity,t_color,time){ if (t_opacity != undefined) opacity == t_opacity; if (t_color != undefined) color == t_color; if (time != undefined) animatetime == time; if ($(maskId).length == 0) { var html ='
'; $('body').append(html); $(maskId).bind('click',close); $(maskContent).bind('click',function(e){ e.stopPropagation(); }); $(window).unbind('resize').bind('resize',_resize); } $(maskContent).html(content).fadeIn(animatetime);_resize(); $(maskId).hide().fadeIn(animatetime); }; var _resize = function(){ var $content = $(maskContent); $content.css({'width':'auto','height':'auto'}).css({ top:($(window).height()-$content.height())/2, left:($(window).width()-$content.width())/2}); imageSize(); } var tips = function(msg){ add("
"+msg+"
"); } var image = function(url){ add(""+ ""); var $content = $(maskContent) var $dom = $content.find('.image'); var dragFlag = false,E; var old_left,old_top; $('#maskViewContent .kod_image_view_loading').fadeIn(300); $('#maskViewContent .kod_image_view').load(function(){ $('#maskViewContent .kod_image_view_loading').stop(true).fadeOut(500, function() { $(this).remove(); }); _resize(); $(this).css('opacity',1.0).addClass('animated-500 dialogShow'); }); $(document).bind({ mousedown:function(e){ if (!$(e.target).hasClass('image')) return; dragFlag = true; $dom.css('cursor','move'); stopPP(e);E = e; old_top = parseInt($content.css('top').replace('px','')); old_left = parseInt($content.css('left').replace('px','')); }, mousemove:function(e){ if (!dragFlag) return; $content.css({ 'left':old_left+(e.clientX-E.clientX), 'top':old_top+(e.clientY-E.clientY) }); }, mouseup:function(){ dragFlag = false; $dom.css('cursor','default'); }, keydown:function(e){ if ($(maskId).length > 0 && e.keyCode == 27){ MaskView.close(); stopPP(e); } } }); $('#windowMaskView,#maskViewContent img').mousewheel(function(delta){ var offset = delta>0?1:-1; offset = offset * Math.abs(delta/3); var o_w = parseInt($dom.width()), o_h=parseInt($dom.height()), w = o_w * (1+offset/5), h = o_h * (1+offset/5); if(w<=20 || h<=20) return; if(w>=10000 || h>=10000) return; var top = parseInt($content.css("top"))-(h-o_h)/2; var left = parseInt($content.css("left"))-(w-o_w)/2; $(maskContent+','+maskContent+' .image').stop(false) .animate({'width':w,'height':h,'top':top,'left':left},200); }); } var imageSize = function(){ var $dom = $(maskContent).find('.image'); if ($dom.length == 0) return; $dom.load(function(){ if (this.complete || this.readyState == "complete") { console.log(this,this.width,this.height); var percent = 0.7, w_width = $(window).width(), w_height= $(window).height(), m_width = this.width, m_height= this.height, width,height; if (m_width >= w_width*percent){ width = w_width*percent; height= m_height/m_width * width; }else{ width = m_width; height= m_height; } $dom.css({'width':width,'height':height}); var $content = $(maskContent); $content.css({'width':'auto','height':'auto'}).css({ top:($(window).height()-$content.height())/2, left:($(window).width()-$content.width())/2}); } }); } var close = function(){ $(maskId).fadeOut(animatetime); if ($(maskContent).find('.image').length!=0) { $(maskContent+','+maskContent+' .image').animate({ 'width':0, 'height':0, 'top':$(window).height()/2, 'left':$(window).width()/2 },animatetime*1.3,0,function(){ $(maskContent).hide(); _resize(); }); }else{ $(maskContent).fadeOut(animatetime); } }; return{ image:image, tips:tips, close:close } })(); //textarea自适应高度 (function($){ $.fn.displayWidth = function(){//文本宽度 var text = $(this).text() || $(this).val(); var html = ""+text+""; var $html = $(html); $html.appendTo('body'); var size = $html.get(0).offsetWidth; $html.remove(); return size; } $.fn.autoTextarea = function(options) { var defaults={ minHeight:34, padding:0 }; var opts = $.extend({},defaults,options); var ie = !!window.attachEvent && !window.opera; var resetHeight = function(that){ if($(that).is('input')){//input则自动调节宽度 $(that).css('width',$(that).displayWidth()+20); return; } if(!ie) that.style.height = opts.minHeight+"px"; var height = that.scrollHeight-opts.padding; if(height<=opts.minHeight){ that.style.height = opts.minHeight+"px"; }else{ that.style.height = height+"px"; } } this.each(function(){ $(this).die("paste cut keydown keyup focus blur change") .live("paste cut keydown keyup focus blur change",function(){ resetHeight(this); }); resetHeight(this); }); }; //长按 $.fn.longPress = function(callback,time){ if(time == undefined) time = 2000; $(this).die('mousedown').live('mousedown', function() { var timer = setTimeout(function() { callback(this); },time); $(this).data('longPressTimer',timer); }).die('mouseup').live('mouseup', function(){ clearTimeout($(this).data('longPressTimer')); }).die('mouseout').live('mouseout', function(){ clearTimeout($(this).data('longPressTimer')); }); } $.fn.inputChange = function(callback){ this.each(function(){ $(this).on('input propertychange change blur', function() { if($(this).prop('comStart')) return; // 中文输入过程中不截断 var value = $(this).val(); callback(this,value); }).on('compositionstart', function(){ $(this).prop('comStart', true); }).on('compositionend', function(){ $(this).prop('comStart', false); }); return this; }); } $("#area_id").on('input propertychange change blur', function() { if($(this).prop('comStart')) return; // 中文输入过程中不截断 var value = $(this).val(); console.log("change:"+value); }).on('compositionstart', function(){ $(this).prop('comStart', true); }).on('compositionend', function(){ $(this).prop('comStart', false); }); //自动focus,并移动光标到指定位置,默认移到最后 $.fn.textFocus=function(index){ var range,len,index=index===undefined?0:parseInt(v); if($(this).is(':focus')){ return; } var thatDom = $(this).get(0); index = (index==undefined?this.value.length:parseInt(index)); if($.browser.msie){ var range=thatDom.createTextRange(); index===0?range.collapse(false):range.move("character",index); range.select(); }else{ thatDom.setSelectionRange(index,0); } this.focus(); return this; }; //选中input内文本段,并移动光标到最后 $.fn.textSelect=function(from,to){ if($(this).length == 0 || $(this).is(':focus')){ return; } var thatDom = $(this).get(0); from = (from==undefined?0:parseInt(from)); to = (to==undefined? $(this).val().length:parseInt(to)); if($.browser.msie){ var range=thatDom.createTextRange(); range.moveEnd('character',to); range.moveStart('character',from); range.select(); }else{ thatDom.setSelectionRange(from,to-from); } this.focus(); return this; }; })(jQuery); //拖动事件 (function($){ $.fn.drag = function(obj,is_stopPP) { this.each(function(){ var isDraging = false; var mouseFirstX = 0; var mouseFirstY = 0; var $that = $(this); $that.die('mousedown').live('mousedown',function(e){ if (e.which != 1) return true; dragStart(e); if($that.setCapture) $that.setCapture(); $(document).mousemove(function(e) {dragMove(e);}); $(document).one('mouseup',function(e) { dragEnd(e); if($that.releaseCapture) {$that.releaseCapture();} stopPP(e); return false; }); if(is_stopPP){//指定不冒泡才停止向上冒泡。split拖拽调整宽度,父窗口拖拽框选防止冒泡 stopPP(e);return false; } //stopPP(e);return false;//跨iframe导致事件屏蔽问题 }); var dragStart = function(e){ isDraging = true; mouseFirstX = e.pageX; mouseFirstY = e.pageY; if (typeof(obj["start"]) == 'function'){ obj["start"](e,$that); } }; var dragMove = function(e){ if (!isDraging) return true; if (typeof(obj["move"]) == 'function'){ obj["move"](e.pageX-mouseFirstX,e.pageY-mouseFirstY,e,$that); } }; var dragEnd = function(e){ if (!isDraging) return false; isDraging = false; if (typeof(obj["end"]) == 'function'){ obj["end"](e.pageX-mouseFirstX,e.pageY-mouseFirstY,e,$that); } }; }); }; })(jQuery); (function($){ $.getUrlParam = function(name,url){ if(!url) url = window.location.href; var urlParam = $.parseUrl(url); return urlParam.params[name];//unescape }; $.parseUrl = function(url){ var a = document.createElement('a'); a.href = url; return { source: url, protocol: a.protocol.replace(':', ''), host: a.hostname, port: a.port, query: a.search, params: (function() { var ret = {}, seg = a.search.replace(/^\?/, '').split('&'), len = seg.length, i = 0, s; for (; i < len; i++) { if (!seg[i]) { continue; } s = seg[i].split('='); ret[s[0]] = s[1]; } return ret; })(), file: (a.pathname.match(/\/([^\/?#]+)$/i) || [, ''])[1], hash: a.hash.replace('#', ''), path: a.pathname.replace(/^([^\/])/, '/$1'), relative: (a.href.match(/tps?:\/\/[^\/]+(.+)/) || [, ''])[1], segments: a.pathname.replace(/^\//, '').split('/') }; } //选择器,目标含有特殊字符的预处理 //http://stackoverflow.com/questions/2786538/need-to-escape-a-special-character-in-a-jquery-selector-string $.escape = function(str) { if(!str){ return str; } return str.replace(/[ !"#$%&'()*+,.\/:;<=>?@[\\\]^`{|}~]/g, "\\$&"); }; $.setStyle = function(cssText,id){ var head = document.getElementsByTagName('head')[0] ||document.documentElement; var element = document.getElementById(id); $(element).remove(); element = document.createElement('style'); id && (element.id = id); element.type="text/css"; head.appendChild(element); if (element.styleSheet!== undefined) { // IE http://support.microsoft.com/kb/262161 if (document.getElementsByTagName('style').length > 31) { throw new Error('Exceed the maximal count of style tags in IE') } element.styleSheet.cssText = cssText }else { element.appendChild(document.createTextNode(cssText)); } } // 进指定字符串通过浏览器下载 $.htmlDownload = function(str,name){ if(!/Trident|MSIE/.test(navigator.userAgent)){//html5 支持保存文件 // http://danml.com/download.html download(str, name, "text/html") }else{//ie 下载 var ifr = document.createElement('iframe'); ifr.style.display = 'none'; ifr.src = str; document.body.appendChild(ifr); ifr.contentWindow.document.execCommand('SaveAs', false, name); document.body.removeChild(ifr); } } //打印html $.htmlPrint = function(html){ html = "
"+html+"
"; if ($.browser.opera) { var tab = window.open("","print-preview"); doc.open(); var doc = tab.document; var paWindow = tab; }else{ var $iframe = $("