/*changed by warlee * @link http://kodcloud.com/ * @author warlee | e-mail:kodcloud@qq.com * @copyright warlee 2014.(Shanghai)Co.,Ltd * @license http://kodcloud.com/tools/license/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 = function(str){ try { return decodeURIComponent(str); } catch (e) { return str; } }; 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 (typeof(str) != 'string') 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);//深拷贝 $.objClone = function(obj){ return $.extend(true, {}, obj); } //跨框架数据共享; 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 /** * 通知中心[观察者模式] * * Hook.bind('test',function(a){console.log('a2'+a,this);}); * Hook.once('test',console.log); * Hook.trigger('test',123,3,4,5); * Hook.trigger('test',456,234,234,22); * */ var Hook = function(){} var Hook = (function(){ // {'kodReady':[{action:action,once:false},{action:action,once:true}]} var eventList = {}; var debug = false; return { debug:function(type){ debug = type; }, get:function(key){ if(key) { return eventList[key]; }else{ return eventList; } }, bind:function(key,action,once){ debug && console.trace('bind',arguments); once = once?true:false; var actionArr = key.split(','); for (var i = 0; i < actionArr.length; i++) { var current = actionArr[i]; if(!eventList[current]){ eventList[current] = []; } if(!$.isArray(action)){ action = [action]; } for (var j = 0; j < action.length; j++) { eventList[current].push({ "action":action[j], "once":once }); } } return this; }, unbind:function(key){ delete eventList[key]; return this; }, once:function(key,action){ this.bind(key,action,true); return this; }, trigger:function(){ debug && console.info('trigger',arguments); var key = Array.prototype.shift.apply(arguments); var arr = eventList[key]; var newArr = []; if(!arr) return; var result = false; for (var i = 0; i < arr.length; i++) { var item = arr[i]; debug && console.info('trigger',item); if(!item.once){ newArr.push(item); } try{ var current = item['action'].apply(this,arguments); if(current !== undefined){ result = current; } }catch(e){ console.error(e,key); } } eventList[key] = newArr; return result; } } })(); //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= unit[key]){ return (size/unit[key]).toFixed(pointNum)+key; } } }; var strSortChina = function(a,b){ var arr = '0123456789零一二三四五六七八九十百千万壹贰叁肆伍陆柒捌玖拾佰仟万';// for (var i=0;ibIndex){ return 1; }else if(aIndexb.charAt(i)){ return 1; }else if(a.charAt(i)111,bbb>aaa; bbb(1).txt>bbb(0).txt [bbb(100).txt>bbb(55).txt] //https://github.com/overset/javascript-natural-sort/blob/master/speed-tests.html var strSort = function(a,b){ if(a==undefined || b==undefined){ return 0; } if(typeof(a) == "number" && typeof(b) == "number"){ return a>b?1:(a==b?0:-1); } var re = /([0-9\.]+)/g, // /(-?[0-9\.]+)/g, 负数 2016-11-09 2016-11-10歧义 x = a.toString().toLowerCase() || '', y = b.toString().toLowerCase() || '', nC = String.fromCharCode(0), xN = x.replace( re, nC + '$1' + nC ).split(nC), yN = y.replace( re, nC + '$1' + nC ).split(nC), xD = (new Date(x)).getTime(), yD = xD ? (new Date(y)).getTime() : null; if ( yD ){//时间戳排序 if ( xD < yD ){ return -1; }else if ( xD > yD ){ return 1; } } for( var cLoc = 0, numS = Math.max(xN.length, yN.length); cLoc < numS; cLoc++ ) { oFxNcL = parseFloat(xN[cLoc]) || xN[cLoc]; oFyNcL = parseFloat(yN[cLoc]) || yN[cLoc]; if(oFxNcL== oFyNcL){ continue; } if(typeof(oFxNcL) == 'string' && typeof(oFyNcL)== 'string'){ //自定义字符大小顺序 var resultCurrent = strSortChina(oFxNcL,oFyNcL); if(resultCurrent!=0){ return resultCurrent; } }else{ if (oFxNcL < oFyNcL){ return -1; }else if (oFxNcL > oFyNcL){ return 1; } } } return 0; } return { fileSize:fileSize, strSort:strSort, pathThis:pathThis } })(); //是否在数组中。 var inArray = function(arr,value) { for (var i=0,l = arr.length ; 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}, inTime,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},inTime,0); setTimeout(function(){ self.animate({opacity:0,top:-self.height()},inTime,0,function(){ self.remove(); }); },delay); }; var pop = function(msg){ var tipsIDname = 'messageTipsPop'; var $self = $("#"+tipsIDname); if ($self.length ==0) { var html='
'; $('body').append(html); $self = $("#"+tipsIDname); } $self.find('.tips-msg').html(msg); $self.css({ 'left':($(window).width() - $self.innerWidth())/2, 'top':($(window).height() - $self.innerHeight())/2 }); var animateTime = 150; $self.stop(true,true) .fadeIn(animateTime) .animate({opacity:0.4},animateTime,0) .delay(delay) .animate({opacity:0},animateTime,0,function(){ $self.remove(); }); }; var loading = function(msg,code){ if (typeof(msg) == 'object'){ code=msg.code; msg = msg.data; } if (msg == undefined) msg = _.get(window,'LNG.loading','loading...'); msg+= "   "; var self = _init(true,msg,code); self.stop(true,true) .css({'opacity':'0','top':-self.height()}) .animate({opacity:1,top:0},inTime,0); }; var close = function(msg,code){ if (typeof(msg) == 'object'){ try{ code=msg.code;msg = msg.data; if(code && typeof(msg) != 'string'){ msg = "Success!"; if(window.LNG && LNG.success){ msg = LNG['success']; } } }catch(e){ code=0;msg =''; }; } var self = _init(true,msg,code); setTimeout(function(){ self.stop(true,true).animate({opacity:0,top:- self.height()},inTime,'linear',function(){ self.remove(); }); },delay); // $(self).stop(true,true) // .show() // .delay(delay) // .animate({opacity:0,top:- self.height()},inTime,'linear',function(){ // self.remove(); // }); }; return{ tips:tips, pop:pop, loading:loading, close:close } })(); var Title = (function(){ var oldTitle = document.title; var reset = function(){ document.title = oldTitle; } var set = function(msg){ document.title = msg + ' ' +oldTitle; } return { reset:reset, set:set } })(); //获取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.staticPath; } 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+' .image').stop(false) .animate({'width':w,'height':h,'top':top,'left':left},100); }); } var imageSize = function(){ var $dom = $(maskContent).find('.image'); if ($dom.length == 0) return; $dom.load(function(){ if (this.complete || this.readyState == "complete") { 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.exists = function(){ return $(this).length >0; } $.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); $(this).trigger('input'); }); }); return this; } //自动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,isStopPP) { this.each(function(){ var isDraging = false; var mouseFirstX = 0; var mouseFirstY = 0; var offsetX = 0; var offsetY = 0; var $that = $(this); if(isWap()){ //移动端拖拽支持 $that.unbind('mousedown').on('touchstart',function(e){ dragStart(e); }).unbind('touchmove').on('touchmove',function(e){ dragMove(e); }).unbind('touchend').on('touchend',function(e){ dragEnd(e); stopPP(e); return false; }); }else{ $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(isStopPP){//指定不冒泡才停止向上冒泡。split拖拽调整宽度,父窗口拖拽框选防止冒泡 stopPP(e);return false; } //stopPP(e);return false;//跨iframe导致事件屏蔽问题 }); } var getEvent = function(e){ if( e.originalEvent && e.originalEvent.targetTouches){ return e.originalEvent.targetTouches[0]; } return e; } var dragStart = function(e){ var mouse = getEvent(e); isDraging = true; mouseFirstX = mouse.pageX; mouseFirstY = mouse.pageY; offsetX = 0; offsetY = 0; if (typeof(obj["start"]) == 'function'){ obj["start"](e,$that); } }; var dragMove = function(e){ if (!isDraging) return true; if (typeof(obj["move"]) == 'function'){ var mouse = getEvent(e); offsetX = mouse.pageX - mouseFirstX; offsetY = mouse.pageY - mouseFirstY; obj["move"](offsetX,offsetY,e,$that); } }; var dragEnd = function(e){ if (!isDraging) return false; isDraging = false; if (typeof(obj["end"]) == 'function'){ //var mouse = getEvent(e); obj["end"](offsetX,offsetY,e,$that); } }; }); }; })(jQuery); (function($){ $.getUrlParam = function(name,url){ if(!url) url = window.location.href; var urlParam = $.parseUrl(url); if(!name){ return urlParam; } return urlParam.params[name];//unescape }; $.parseUrl = function(url){ if(!url){ url = window.location.href; } var a = document.createElement('a'); a.href = url; var result = { 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('/') }; result.url = result.protocol + '://' + result.host + result.path + result.query; return result; } //选择器,目标含有特殊字符的预处理 //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)); } } $.addStyle = function(cssText){ var head = document.getElementsByTagName('head')[0] ||document.documentElement; var id = 'add-style-css-text'; var element = $('#'+id).get(0); if(!element){ element = document.createElement('style'); element.id = 'add-style-css-text'; element.type="text/css"; head.appendChild(element); } if (element.styleSheet!== undefined) { 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); } } //是否为ie ie6~11 $.isIE = function(){ return !!(window.ActiveXObject || "ActiveXObject" in window); } $.isIE8 = function(){ if($.isIE && parseInt($.browser.version) <=8 ){ return true; } return false; } $.supportCss3 = function(style){ if(!style) style = 'box-shadow'; var prefix = ['webkit', 'Moz', 'ms', 'o'], i, humpString = [], htmlStyle = document.documentElement.style, _toHumb = function (string) { return string.replace(/-(\w)/g, function ($0, $1) { return $1.toUpperCase(); }); }; for (i in prefix){ humpString.push(_toHumb(prefix[i] + '-' + style)); } humpString.push(_toHumb(style)); for (i in humpString){ if (humpString[i] in htmlStyle) return true; } return false; } //打印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 = $("