mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
2 lines
11 KiB
JavaScript
2 lines
11 KiB
JavaScript
define([],function(){var a=Backbone.View.extend({options:{frame:{cols:6,rows:3},rows:1e3,cell:130,margin:5,scroll:5,top_min:40,frame_max:9,visible:!0,onchange:null},cols:0,top:0,top_max:0,frame_z:0,frame_counter:0,frame_counter_id:0,frame_list:[],frame_shadow:null,visible:null,initialize:function(a){var b=this;a&&(this.options=_.defaults(a,this.options)),this.visible=this.options.visible,this.top=this.top_max=this.options.top_min,this.setElement(this._template()),$(this.el).append(this._templateBackground()),$(this.el).append(this._templateMenu()),$(this.el_main).append($(this.el));var c="#frame-shadow";$(this.el).append(this._templateShadow(c.substring(1))),this.frame_shadow={id:c,screen_location:{},grid_location:{},grid_rank:null,grid_lock:!1},this._frameResize(this.frame_shadow,{width:0,height:0}),this.frame_list[c]=this.frame_shadow,this._panelRefresh(),this.visible?this.show():this.hide();var b=this;$(window).resize(function(){b.visible&&b._panelRefresh()})},add:function(a){var b={title:"",content:null,target:"",type:null};if(a=a?_.defaults(a,b):b,a.content){if(this.frame_counter>=this.options.frame_max)return void alert("You have reached the maximum number of allowed frames ("+this.options.frame_max+").");var c="#frame-"+this.frame_counter_id++;if(0!==$(c).length)return void alert("This frame already exists. This page might contain multiple frame managers.");this.top=this.options.top_min;var d=null;if("url"===a.type)d=$(this._templateFrameUrl(c.substring(1),a.title,a.content));else if("other"===a.type){d=$(this._templateFrame(c.substring(1),a.title));var e=d.find(".f-content");_.isFunction(a.content)?a.content(e):e.append(a.content)}$(this.el).append(d);var f={id:c,screen_location:{},grid_location:{},grid_rank:null,grid_lock:!1};a.width=this._toPixelCoord("width",this.options.frame.cols),a.height=this._toPixelCoord("height",this.options.frame.rows),this.frame_z=parseInt($(f.id).css("z-index")),this.frame_list[c]=f,this.frame_counter++,this._frameResize(f,{width:a.width,height:a.height}),this._frameInsert(f,{top:0,left:0},!0),this.visible||this.show()}},show:function(){this.visible=!0,this.$el.find(".frame").fadeIn("fast"),this.$el.find(this.frame_shadow.id).hide(),this.$el.find(".frame-background").show(),this._panelRefresh(),this._menuRefresh()},hide:function(){null===this.event.type&&(this.visible=!1,this.$el.find(".frame").fadeOut("fast"),this.$el.find(".frame-background").hide(),this.$el.find(".frame-menu").hide(),this._menuRefresh())},length:function(){return this.frame_counter},setOnChange:function(a){this.options.onchange=a},event:{type:null,target:null,xy:null},events:{mousemove:"_eventFrameMouseMove",mouseup:"_eventFrameMouseUp",mouseleave:"_eventFrameMouseUp",mousewheel:"_eventPanelScroll",DOMMouseScroll:"_eventPanelScroll","mousedown .frame":"_eventFrameMouseDown","mousedown .frame-background":"_eventHide","mousedown .frame-scroll-up":"_eventPanelScroll_up","mousedown .frame-scroll-down":"_eventPanelScroll_down","mousedown .f-close":"_eventFrameClose","mousedown .f-pin":"_eventFrameLock"},_eventFrameMouseDown:function(a){if(null===this.event.type&&(($(a.target).hasClass("f-header")||$(a.target).hasClass("f-title"))&&(this.event.type="drag"),$(a.target).hasClass("f-resize")&&(this.event.type="resize"),null!==this.event.type)){if(a.preventDefault(),this.event.target=this._frameIdentify(a.target),this.event.target.grid_lock)return void(this.event.type=null);this.event.xy={x:a.originalEvent.pageX,y:a.originalEvent.pageY},this._frameDragStart(this.event.target)}},_eventFrameMouseMove:function(a){if("drag"==this.event.type||"resize"==this.event.type){var b={x:a.originalEvent.pageX,y:a.originalEvent.pageY},c={x:b.x-this.event.xy.x,y:b.y-this.event.xy.y};this.event.xy=b;var d=this._frameScreen(this.event.target);if("resize"==this.event.type){d.width+=c.x,d.height+=c.y;var e=this.options.cell-this.options.margin-1;d.width=Math.max(d.width,e),d.height=Math.max(d.height,e),this._frameResize(this.event.target,d),d.width=this._toGridCoord("width",d.width)+1,d.height=this._toGridCoord("height",d.height)+1,d.width=this._toPixelCoord("width",d.width),d.height=this._toPixelCoord("height",d.height),this._frameResize(this.frame_shadow,d),this._frameInsert(this.frame_shadow,{top:this._toGridCoord("top",d.top),left:this._toGridCoord("left",d.left)})}if("drag"==this.event.type){d.left+=c.x,d.top+=c.y,this._frameOffset(this.event.target,d);var f={top:this._toGridCoord("top",d.top),left:this._toGridCoord("left",d.left)};0!==f.left&&f.left++,this._frameInsert(this.frame_shadow,f)}}},_eventFrameMouseUp:function(){("drag"==this.event.type||"resize"==this.event.type)&&(this._frameDragStop(this.event.target),this.event.type=null)},_eventFrameClose:function(a){if(null===this.event.type){a.preventDefault();var b=this._frameIdentify(a.target),c=this;$(b.id).fadeOut("fast",function(){$(b.id).remove(),delete c.frame_list[b.id],c.frame_counter--,c._panelRefresh(!0),c._panelAnimationComplete(),c.visible&&0==c.frame_counter&&c.hide()})}},_eventFrameLock:function(a){if(null===this.event.type){a.preventDefault();var b=this._frameIdentify(a.target);b.grid_lock?(b.grid_lock=!1,$(b.id).find(".f-pin").removeClass("toggle"),$(b.id).find(".f-header").removeClass("f-not-allowed"),$(b.id).find(".f-title").removeClass("f-not-allowed"),$(b.id).find(".f-resize").show(),$(b.id).find(".f-close").show()):(b.grid_lock=!0,$(b.id).find(".f-pin").addClass("toggle"),$(b.id).find(".f-header").addClass("f-not-allowed"),$(b.id).find(".f-title").addClass("f-not-allowed"),$(b.id).find(".f-resize").hide(),$(b.id).find(".f-close").hide())}},_eventHide:function(){null===this.event.type&&this.hide()},_eventPanelScroll:function(a){if(null===this.event.type&&this.visible){var b=$(a.srcElement).parents(".frame");if(0!==b.length)return void a.stopPropagation();a.preventDefault();var c=a.originalEvent.detail?a.originalEvent.detail:a.originalEvent.wheelDelta/-3;this._panelScroll(c)}},_eventPanelScroll_up:function(a){null===this.event.type&&(a.preventDefault(),this._panelScroll(-this.options.scroll))},_eventPanelScroll_down:function(a){null===this.event.type&&(a.preventDefault(),this._panelScroll(this.options.scroll))},_frameIdentify:function(a){return this.frame_list["#"+$(a).closest(".frame").attr("id")]},_frameDragStart:function(a){this._frameFocus(a,!0);var b=this._frameScreen(a);this._frameResize(this.frame_shadow,b),this._frameGrid(this.frame_shadow,a.grid_location),a.grid_location=null,$(this.frame_shadow.id).show(),$(".f-cover").show()},_frameDragStop:function(a){this._frameFocus(a,!1);var b=this._frameScreen(this.frame_shadow);this._frameResize(a,b),this._frameGrid(a,this.frame_shadow.grid_location,!0),this.frame_shadow.grid_location=null,$(this.frame_shadow.id).hide(),$(".f-cover").hide(),this._panelAnimationComplete()},_toGridCoord:function(a,b){var c="width"==a||"height"==a?1:-1;return"top"==a&&(b-=this.top),parseInt((b+c*this.options.margin)/this.options.cell,10)},_toPixelCoord:function(a,b){var c="width"==a||"height"==a?1:-1,d=b*this.options.cell-c*this.options.margin;return"top"==a&&(d+=this.top),d},_toGrid:function(a){return{top:this._toGridCoord("top",a.top),left:this._toGridCoord("left",a.left),width:this._toGridCoord("width",a.width),height:this._toGridCoord("height",a.height)}},_toPixel:function(a){return{top:this._toPixelCoord("top",a.top),left:this._toPixelCoord("left",a.left),width:this._toPixelCoord("width",a.width),height:this._toPixelCoord("height",a.height)}},_isCollision:function(a){function b(a,b){return!(a.left>b.left+b.width-1||a.left+a.width-1<b.left||a.top>b.top+b.height-1||a.top+a.height-1<b.top)}for(var c in this.frame_list){var d=this.frame_list[c];if(null!==d.grid_location&&b(a,d.grid_location))return!0}return!1},_locationRank:function(a){return a.top*this.cols+a.left},_menuRefresh:function(){this.visible&&(this.top==this.options.top_min?$(".frame-scroll-up").hide():$(".frame-scroll-up").show(),this.top==this.top_max?$(".frame-scroll-down").hide():$(".frame-scroll-down").show()),this.options.onchange&&this.options.onchange()},_panelAnimationComplete:function(){var a=this;$(".frame").promise().done(function(){a._panelScroll(0,!0)})},_panelRefresh:function(a){this.cols=parseInt($(window).width()/this.options.cell,10)+1,this._frameInsert(null,null,a)},_panelScroll:function(a,b){var c=this.top-this.options.scroll*a;if(c=Math.max(c,this.top_max),c=Math.min(c,this.options.top_min),this.top!=c){for(var d in this.frame_list){var e=this.frame_list[d];if(null!==e.grid_location){var f={top:e.screen_location.top-(this.top-c),left:e.screen_location.left};this._frameOffset(e,f,b)}}this.top=c}this._menuRefresh()},_frameInsert:function(a,b,c){var d=[];a&&(a.grid_location=null,d.push([a,this._locationRank(b)]));var e=null;for(e in this.frame_list){var f=this.frame_list[e];null===f.grid_location||f.grid_lock||(f.grid_location=null,d.push([f,f.grid_rank]))}for(d.sort(function(a,b){var c=a[1],d=b[1];return d>c?-1:c>d?1:0}),e=0;e<d.length;e++)this._framePlace(d[e][0],c);this.top_max=0;for(var e in this.frame_list){var a=this.frame_list[e];null!==a.grid_location&&(this.top_max=Math.max(this.top_max,a.grid_location.top+a.grid_location.height))}this.top_max=$(window).height()-this.top_max*this.options.cell-2*this.options.margin,this.top_max=Math.min(this.top_max,this.options.top_min),this._menuRefresh()},_framePlace:function(a,b){a.grid_location=null;for(var c=this._toGrid(this._frameScreen(a)),d=!1,e=0;e<this.options.rows;e++){for(var f=0;f<Math.max(1,this.cols-c.width);f++)if(c.top=e,c.left=f,!this._isCollision(c)){d=!0;break}if(d)break}d?this._frameGrid(a,c,b):console.log("Grid dimensions exceeded.")},_frameFocus:function(a,b){var c=this.frame_z+(b?1:0);$(a.id).css("z-index",c)},_frameOffset:function(a,b,c){if(a.screen_location.left=b.left,a.screen_location.top=b.top,c){this._frameFocus(a,!0);var d=this;$(a.id).animate({top:b.top,left:b.left},"fast",function(){d._frameFocus(a,!1)})}else $(a.id).css({top:b.top,left:b.left})},_frameResize:function(a,b){$(a.id).css({width:b.width,height:b.height}),a.screen_location.width=b.width,a.screen_location.height=b.height},_frameGrid:function(a,b,c){a.grid_location=b,this._frameOffset(a,this._toPixel(b),c),a.grid_rank=this._locationRank(b)},_frameScreen:function(a){var b=a.screen_location;return{top:b.top,left:b.left,width:b.width,height:b.height}},_template:function(){return'<div class="galaxy-frame"></div>'},_templateFrame:function(a,b){return b||(b=""),'<div id="'+a+'" class="frame corner"><div class="f-header corner"><span class="f-title">'+b+'</span><span class="f-icon f-close fa fa-trash-o"></span><span class="f-icon f-pin fa fa-thumb-tack"></span></div><div class="f-content"><div class="f-cover"></div></div><span class="f-resize f-icon corner fa fa-expand"></span></div>'},_templateFrameUrl:function(a,b,c){c+=-1==c.indexOf("?")?"?":"&",c+="widget=True";var d=$(this._templateFrame(a,b));return d.find(".f-content").append('<iframe scrolling="auto" class="f-iframe" src="'+c+'"></iframe>'),d},_templateShadow:function(a){return'<div id="'+a+'" class="frame-shadow corner"></div>'},_templateBackground:function(){return'<div class="frame-background"></div>'},_templateMenu:function(){return'<div class="frame-scroll-up frame-menu fa fa-chevron-up fa-2x"></div><div class="frame-scroll-down frame-menu fa fa-chevron-down fa-2x"></div>'}});return{View:a}});
|
|
//# sourceMappingURL=../../../maps/mvc/ui/ui-frames.js.map
|