/*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 */ /* * iframe之间函数调用 * * main frame中每个frame需要name和id,以便兼容多浏览器 * 如果需要提供给其他frame调用,则需要在body中加入 * * 调用例子:Frame.doFunction('main','goUrl','"'+url+'"');该frame调用id为main的兄弟frame的goUrl方法,参数为后面的 * 参数为字符串时需要加引号,否则传过去会被理解成一个未定义变量 */ var FrameCall = (function(){ var idName = "FrameCall"; var idNameAll = "#"+idName; var ie = !-[1,];//是否ie return{ apiOpen:function(){ var html = ''; $(html).prependTo('body'); }, //其他窗口调用该窗口函数,调用另一个frame的方法 api:function(){ var action = $(idNameAll).attr('action'); var value=$(idNameAll).attr('value'); if (action == 'get') {//获取变量 share.data('create_app_path',eval(value)); return; } var fun=action+'('+value+');';//拼装执行语句,字符串转换到代码 try{ eval(fun); } catch(e) {}; }, //该窗口调用顶层窗口的子窗口api,调用iframe框架的js函数.封装控制器。 top:function(iframe,action,value){ if (!window.parent.frames[iframe]) return; //var obj = window.top.frames[iframe].document; var obj = window.parent.frames[iframe].document; if(!obj) return; obj=obj.getElementById(idName); $(obj).attr("action",action); $(obj).attr("value",value); obj.click(); }, //该窗口调用父窗口的api child:function(iframe,action,value){ if (!window.frames[iframe]) return; var obj = window.frames[iframe].document; if(!obj) return; obj=obj.getElementById(idName); $(obj).attr("action",action); $(obj).attr("value",value); obj.click(); }, //该窗口调用父窗口的api father:function(action,value){ var obj=window.parent.document; obj=obj.getElementById(idName); $(obj).attr("action",action); $(obj).attr("value",value); obj.click(); }, //___自定义通用方法,可在页面定义更多提供给接口使用的api。 goUrl:function(url){ window.location.href=url; }, goRefresh:function(){ window.location.reload(); } } })(); $(document).ready(function() { FrameCall.apiOpen(); }); var time = function(){ var time = (new Date()).valueOf(); return time; } var urlEncode = encodeURIComponent; var urlDecode = decodeURIComponent; var urlEncode2 = function (str){ return urlEncode(urlEncode(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 share = { data: function (name, value) { var top = window.top, cache = top['_CACHE'] || {}; top['_CACHE'] = cache; return value !== undefined ? cache[name] = value : cache[name]; }, removeData: function (name) { var cache = window.top['_CACHE']; if (cache && cache[name]) delete cache[name]; } }; jQuery.easing.def="easeInOutCubic";//easeOutExpo,easeInOutExpo,easeInOutSine //cookie操作 var Cookie = (function(){ var cookie = {}; var _init = function(){ cookie = {};//初始化cookie var cookieArray=document.cookie.split("; "); for (var i=0;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),icon,color; switch(code){ case 100:delay = 3000;//加长时间 5s case true: case undefined: case 'succcess':color = '#5cb85c';icon = 'icon-ok';break; case 'info':color = '#519AF6';icon = 'icon-info';break; case 'warning':color = '#ed9c28';icon = 'icon-exclamation';break; case false: case 'error':delay = 1000;color = '#d9534f';icon = 'icon-remove';break; default:color = '';icon = '';break; } if (color != '') { self.css({'background':color,'color':'#fff'}); self.find('i').removeClass().addClass(icon); } if (msg != undefined) self.find('span').html(msg); $(tipsID).show().css({'left':($(window).width() - $(tipsID).innerWidth())/2}); return self; }; var tips = function(msg,code,offset_top){ if (typeof(msg) == 'object'){ code=msg.code;msg = msg.data; } if (offset_top == undefined) offset_top = 0; var self = _init(msg,code); self.stop(true,true) .css({'opacity':'0','top':offset_top-self.height()}) .show() .animate({opacity:opacity,top:offset_top},in_time,0) .delay(delay) .animate({opacity:0,top:'-='+(offset_top+self.height())},in_time,0,function(){ $(this).hide(); }); }; var loading = function(msg,code,offset_top){ if (typeof(msg) == 'object'){ code=msg.code;msg = msg.data; } if (offset_top == undefined) offset_top = 0; if (msg == undefined) msg = 'loading...' msg+= "   "; var self = _init(msg,code); self.stop(true,true) .css({'opacity':'0','top':offset_top-self.height()}) .animate({opacity:opacity,top:offset_top},in_time,0); }; var close = function(msg,code,offset_top){ if (typeof(msg) == 'object'){ try{ code=msg.code;msg = msg.data; }catch(e){ code=0;msg =''; }; } if (offset_top == undefined) offset_top = 0; var self = _init(msg,code); self.delay(delay) .show() .animate({ opacity:0, top:'-='+(offset_top+self.height())}, in_time,0,function(){ $(this).hide(); }); }; return{ tips:tips, loading:loading, close:close } })(); //通用遮罩层 var MaskView = (function(){ var opacity = 0.6; var animatetime = 250; var color ='#000'; var maskId = "#windowMaskView"; var maskContent = '#maskViewContent'; 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; $(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(event, delta, deltaX, deltaY){ var offset = delta>0?1:-1; offset = offset * Math.abs(delta/10); var o_w = parseInt($dom.width()), o_h=parseInt($dom.height()), w = o_w * (1+offset/6), h = o_h * (1+offset/6); if(w<=5 || h<=5) return; if(w>=10000 || h>=10000) return; // var top = ($(window).height() - h)/2; // var left = ($(window).width() - w)/2; var top = parseInt($content.css("top"))-(h-o_h)/2; var left = parseInt($content.css("left"))-(w-o_w)/2; $(maskContent+','+maskContent+' .image').stop(true) .animate({'width':w,'height':h,'top':top,'left':left},400); }); } var imageSize = function(){ var $dom = $(maskContent).find('.image'); if ($dom.length == 0) return; var image=new Image(); image.src = $dom.attr('src'); var percent = 0.7, w_width = $(window).width(), w_height= $(window).height(), m_width = image.width, m_height= image.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, resize:_resize, tips:tips, add:add, close:close } })(); //textarea自适应高度 (function($){ $.fn.autoTextarea = function(options) { var defaults={ minHeight:20, padding:0 }; var opts = $.extend({},defaults,options); var ie = !!window.attachEvent && !window.opera; $(this) .die("paste cut keydown keyup focus blur") .live("paste cut keydown keyup focus blur",function(){ if(!ie) this.style.height = options.minHeight+"px"; var height = this.scrollHeight-options.padding; if(height<=options.minHeight){ this.style.height = options.minHeight+"px"; }else{ this.style.height = height+"px"; } }); }; })(jQuery); //dom绑定enter事件 用于input (function($){ $.fn.extend({ keyEnter:function(callback){ $(this).die('keydown').live('keydown',function(e){ if (e.keyCode == 13 && callback){ callback(); } }); } }); })(jQuery); //dom绑定鼠标滚轮事件 (function($){ $.fn.extend({ mousewheel: function(fn){ var mousewheel = jQuery.browser.mozilla ? "DOMMouseScroll" : "mousewheel"; $(this).bind(mousewheel ,function(e){ e= window.event || e; var delta = e.wheelDelta ? (e.wheelDelta / 120) : (- e.detail / 3); fn.call(this,delta); return false; }); } }); })(jQuery); (function($){ $.tooltipsy = function (el, options) { this.options = options; this.$el = $(el); this.title = this.$el.attr('title') || ''; this.$el.attr('title', ''); this.random = parseInt(Math.random()*10000); this.ready = false; this.shown = false; this.width = 0; this.height = 0; this.delaytimer = null; this.$el.data("tooltipsy", this); this.init(); }; $.tooltipsy.prototype = { init: function () { var base = this, settings, $el = base.$el, el = $el[0]; base.settings = settings = $.extend({}, base.defaults, base.options); settings.delay = +settings.delay; if (typeof settings.content === 'function') { base.readify(); } if (settings.showEvent === settings.hideEvent && settings.showEvent === 'click') { $el.toggle(function (e) { if (settings.showEvent === 'click' && el.tagName == 'A') { e.preventDefault(); } if (settings.delay > 0) { base.delaytimer = window.setTimeout(function () { base.show(e); }, settings.delay); } else { base.show(e); } }, function (e) { if (settings.showEvent === 'click' && el.tagName == 'A') { e.preventDefault(); } window.clearTimeout(base.delaytimer); base.delaytimer = null; base.hide(e); }); } else { $el.bind(settings.showEvent, function (e) { if (settings.showEvent === 'click' && el.tagName == 'A') { e.preventDefault(); } base.delaytimer = window.setTimeout(function () { base.show(e); }, settings.delay || 0); }).bind(settings.hideEvent, function (e) { if (settings.showEvent === 'click' && el.tagName == 'A') { e.preventDefault(); } window.clearTimeout(base.delaytimer); base.delaytimer = null; base.hide(e); }); } }, show: function (e) { if (this.ready === false) { this.readify(); } var base = this, settings = base.settings, $tipsy = base.$tipsy, $el = base.$el, el = $el[0], offset = base.offset(el); if (base.shown === false) { if ((function (o) { var s = 0, k; for (k in o) { if (o.hasOwnProperty(k)) { s++; } } return s; })(settings.css) > 0) { base.$tip.css(settings.css); } base.width = $tipsy.outerWidth(); base.height = $tipsy.outerHeight(); } if (settings.alignTo === 'cursor' && e) { var tip_position = [e.clientX + settings.offset[0], e.clientY + settings.offset[1]]; if (tip_position[0] + base.width > $(window).width()) { var tip_css = {top: tip_position[1] + 'px', right: tip_position[0] + 'px', left: 'auto'}; } else { var tip_css = {top: tip_position[1] + 'px', left: tip_position[0] + 'px', right: 'auto'}; } } else { var tip_position = [ (function () { if (settings.offset[0] < 0) { return offset.left - Math.abs(settings.offset[0]) - base.width; } else if (settings.offset[0] === 0) { return offset.left - ((base.width - $el.outerWidth()) / 2); } else { return offset.left + $el.outerWidth() + settings.offset[0]; } })(), (function () { if (settings.offset[1] < 0) { return offset.top - Math.abs(settings.offset[1]) - base.height; } else if (settings.offset[1] === 0) { return offset.top - ((base.height - base.$el.outerHeight()) / 2); } else { return offset.top + base.$el.outerHeight() + settings.offset[1]; } })() ]; } $tipsy.css({top: tip_position[1] + 'px', left: tip_position[0] + 'px'}); base.settings.show(e, $tipsy.stop(true, true)); }, hide: function (e) { var base = this; if (base.ready === false) { return; } if (e && e.relatedTarget === base.$tip[0]) { base.$tip.bind('mouseleave', function (e) { if (e.relatedTarget === base.$el[0]) { return; } base.settings.hide(e, base.$tipsy.stop(true, true)); }); return; } base.settings.hide(e, base.$tipsy.stop(true, true)); }, readify: function () { this.ready = true; this.$tipsy = $('