jquery.easywidgets.min.js
上传用户:jhh8446530
上传日期:2016-01-28
资源大小:116k
文件大小:8k
源码类别:
Ajax
开发平台:
JavaScript
- /**
- * Easy Widgets jQuery plugin 1.0 (beta)
- *
- * David Esperalta - http://www.bitacora.davidesperalta.com/
- */
- (function(b){b.fn.EasyWidgets=function(l){var p=0;var f=new Array();var v=b.extend(true,b.fn.EasyWidgets.defaults,l);b(v.selectors.editbox).hide();var k='<span class="'+v.selectors.menuLinks.replace(/./,"")+'"></span>';b(k).appendTo(v.selectors.handle,this);b(v.selectors.widget).each(function(){p++;var i="";var C=b(this);var y=C.attr("id");var B=C.find(v.selectors.menuLinks);var w=C.find(v.selectors.content);var s=(y&&v.behaviour.useCookies&&b.cookie);if(y){f[p]=y}if(s&&b.cookie(v.cookies.positionName)){i=b.cookie(v.cookies.positionName);if(i.indexOf(y)!=-1){var j=i.match(y+"=(.*)");if(j){C.appendTo("#"+j[1])}}}if(s&&b.cookie(v.cookies.closeName)){i=b.cookie(v.cookies.closeName);if(i.indexOf(y)!=-1){C.hide()}}var z="";if(C.hasClass(v.options.collapsable)){if(C.hasClass(v.options.collapse)){z=a(v.i18n.extendText,v.i18n.extendTitle,v.selectors.collapseLink);w.hide()}else{z=a(v.i18n.collapseText,v.i18n.collapseTitle,v.selectors.collapseLink)}if(s){i=b.cookie(v.cookies.collapseName);if(i){if(i.indexOf(y)!=-1){z=a(v.i18n.extendText,v.i18n.extendTitle,v.selectors.collapseLink);w.hide()}}}b(z).mousedown(function(D){D.stopPropagation()}).click(function(){var K=b(this);var F=true;var H=true;var J=K.parents(v.selectors.widget);var G=J.attr("id");var E=J.find(v.selectors.content);var I=E.css("display")!="none";var L=G&&v.behaviour.useCookies&&b.cookie;K.blur();if(I){if(v.callbacks.onCollapseQuery!=null){H=v.callbacks.onCollapseQuery(K,J)}if(H){E.hide();K.html(v.i18n.extendText);K.attr("title",v.i18n.extendTitle);if(L){var D=b.cookie(v.cookies.collapseName);if(!D){D=G}else{if(D.indexOf(G)==-1){D=D+","+G}}b.cookie(v.cookies.collapseName,D,{path:v.cookies.path,secure:v.cookies.secure,domain:v.cookies.domain,expires:v.cookies.expires})}if(v.callbacks.onCollapse!=null){v.callbacks.onCollapse(K,J)}}}else{if(v.callbacks.onExtendQuery!=null){F=v.callbacks.onExtendQuery(K,J)}if(F){K.html(v.i18n.collapseText);K.attr("title",v.i18n.collapseTitle);E.show();if(L){D=b.cookie(v.cookies.collapseName);if(D.indexOf(G)!=-1){D=D.replace(","+G,"");D=D.replace(G+",","");D=D.replace(G,"")}b.cookie(v.cookies.collapseName,D,{path:v.cookies.path,secure:v.cookies.secure,domain:v.cookies.domain,expires:v.cookies.expires})}if(v.callbacks.onExtend!=null){v.callbacks.onExtend(K,J)}}}return false}).appendTo(b(B,this))}var x="";if(C.hasClass(v.options.editable)){x=a(v.i18n.editText,v.i18n.editTitle,v.selectors.editLink);C.find(v.selectors.closeEdit).click(function(H){var F=b(this);var G=F.parents(v.selectors.widget);var D=G.find(v.selectors.editLink);var E=G.find(v.selectors.editbox);F.blur();E.hide();D.html(v.i18n.editText);D.attr("title",v.i18n.editTitle);return false});b(x).mousedown(function(D){D.stopPropagation()}).click(function(){var D=true;var E=true;var G=b(this);var I=G.parents(v.selectors.widget);var F=I.find(v.selectors.editbox);var H=F.css("display")!="none";G.blur();if(H){if(v.callbacks.onCancelEditQuery!=null){E=v.callbacks.onCancelEditQuery(G,I)}if(E){F.hide();G.html(v.i18n.editText);G.attr("title",v.i18n.editTitle);if(v.callbacks.onCancelEdit!=null){v.callbacks.onCancelEdit(G,I)}}}else{if(v.callbacks.onEditQuery!=null){D=v.callbacks.onEditQuery(G,I)}if(D){G.html(v.i18n.cancelEditText);G.attr("title",v.i18n.cancelEditTitle);F.show();if(v.callbacks.onEdit!=null){v.callbacks.onEdit(G,I)}}}return false}).appendTo(b(B,this))}var A="";if(C.hasClass(v.options.removable)){A=a(v.i18n.closeText,v.i18n.closeTitle,v.selectors.closeLink);b(A).mousedown(function(D){D.stopPropagation()}).click(function(){var H=true;var E=b(this);var F=E.parents(v.selectors.widget);var D=F.attr("id");var I=(D&&v.behaviour.useCookies&&b.cookie);E.blur();if(v.callbacks.onCloseQuery!=null){H=v.callbacks.onCloseQuery(E,F)}if(H){if(!F.hasClass(v.options.closeConfirm)||confirm(v.i18n.confirmMsg)){if(I){var G=b.cookie(v.cookies.closeName);if(!G){G=D}else{if(G.indexOf(D)==-1){G=G+","+D}}b.cookie(v.cookies.closeName,G,{path:v.cookies.path,secure:v.cookies.secure,domain:v.cookies.domain,expires:v.cookies.expires})}F.hide();if(v.callbacks.onClose!=null){v.callbacks.onClose(E,F)}}}return false}).appendTo(b(B,this))}});var h=null;h=(function(){var i="";b(v.selectors.widget).each(function(j){if(!b(this).hasClass(v.options.movable)){if(!this.id){this.id="widget-without-id-"+j}i+="#"+this.id+","}});return b("> "+v.selectors.container+":not("+i+")",v.selectors.columns)})();h.find(v.selectors.handle).css({cursor:"move"}).mousedown(function(i){var j=b(this);h.css({width:""});j.parent().css({width:j.parent().width()+"px"})}).mouseup(function(){var i=b(this);if(!i.parent().hasClass("dragging")){i.parent().css({width:""})}else{b(v.selectors.columns).sortable("disable")}});b(v.selectors.columns).sortable({items:h,containment:"document",forcePlaceholderSize:true,handle:v.selectors.handle,delay:v.behaviour.dragDelay,revert:v.behaviour.dragRevert,opacity:v.behaviour.dragOpacity,connectWith:b(v.selectors.columns),placeholder:v.selectors.placeHolder,start:function(j,i){b(i.helper).addClass("dragging")},stop:function(x,w){b(w.item).css({width:""}).removeClass("dragging");b(v.selectors.columns).sortable("enable");var s=w.item[0].id;var z=w.element[0].id;var i=w.item[0].parentNode.id;var j=s&&v.behaviour.useCookies&&b.cookie;if(j&&z!=i){var y=b.cookie(v.cookies.positionName);if(!y){y=s+"="+i}else{y=y.replace(","+s+"="+z,"");y=y.replace(s+"="+z+",","");y=y.replace(s+"="+z,"");if(b.trim(y)==""){y+=s+"="+i}else{y+=","+s+"="+i}}b.cookie(v.cookies.positionName,y,{path:v.cookies.path,secure:v.cookies.secure,domain:v.cookies.domain,expires:v.cookies.expires})}if(v.callbacks.onDragStop!=null){v.callbacks.onDragStop(x,w)}return true}});var q=v.behaviour.useCookies&&(f.length>0);if(q){var n=0;var m=0;var u=new Array(v.cookies.closeName,v.cookies.positionName,v.cookies.collapseName);var t=u.length;for(n=0;n<t;n++){if(b.cookie(u[n])){var e="";var c=b.cookie(u[n]).split(",");var g=c.length;for(m=0;m<g;m++){var o="";var r="";if(u[n]==v.cookies.positionName){var d=c[m].split("=");if(d.length==2){o=d[0];r=d[1]}}else{o=c[m]}o=b.trim(o);if(b.inArray(o,f)!=-1){if(u[n]==v.cookies.positionName){if(b.trim(e)==""){e+=o+"="+r}else{e+=","+o+"="+r}}else{if(b.trim(e)==""){e+=o}else{e+=","+o}}}b.cookie(u[n],e,{path:v.cookies.path,secure:v.cookies.secure,domain:v.cookies.domain,expires:v.cookies.expires})}}}}};b.fn.EasyWidgets.defaults={behaviour:{dragDelay:100,dragRevert:100,dragOpacity:0.8,useCookies:false},cookies:{path:"",domain:"",expires:90,secure:false,closeName:"easywidgets-close",positionName:"easywidgets-position",collapseName:"easywidgets-collapse"},options:{movable:"movable",editable:"editable",collapse:"collapse",removable:"removable",collapsable:"collapsable",closeConfirm:"closeconfirm"},callbacks:{onEdit:null,onClose:null,onExtend:null,onDragStop:null,onCollapse:null,onEditQuery:null,onCloseQuery:null,onCancelEdit:null,onExtendQuery:null,onCollapseQuery:null,onCancelEditQuery:null},selectors:{container:"div",widget:".widget",handle:".widget-head",menuLinks:".widget-menu-links",columns:".widget-column",editbox:".widget-editbox",content:".widget-content",closeEdit:".widget-close-editbox",editLink:".widget-editlink",closeLink:".widget-closelink",placeHolder:"widget-placeholder",collapseLink:".widget-collapselink"},i18n:{editText:"Edit",closeText:"Close",extendText:"Extend",collapseText:"Collapse",cancelEditText:"Cancel",editTitle:"Edit this widget",closeTitle:"Close this widget",confirmMsg:"Remove this widget?",cancelEditTitle:"Cancel edition",extendTitle:"Extend this widget",collapseTitle:"Collapse this widget"}};function a(f,e,d){var c='<a href="#" title="TITLE" class="CLASS">TEXT</a>';c=c.replace(/TEXT/g,f);c=c.replace(/TITLE/g,e);c=c.replace(/CLASS/g,d.replace(/./,""));return c}})(jQuery);