mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
1 line
11 KiB
JavaScript
1 line
11 KiB
JavaScript
define([],function(){var a=Backbone.View.extend({options:{frame:{cols:6,rows:3},rows:1000,cell:130,margin:5,scroll:5,top_min:40,frame_max:9,visible:true,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(c){var b=this;if(c){this.options=_.defaults(c,this.options)}this.visible=this.options.visible;this.top=this.top_max=this.options.top_min;this.setElement(this._template());$(this.el).append(this._template_background());$(this.el).append(this._template_menu());$(this.el_main).append($(this.el));var d="#frame-shadow";$(this.el).append(this._template_shadow(d.substring(1)));this.frame_shadow={id:d,screen_location:{},grid_location:{},grid_rank:null,grid_lock:false};this._frame_resize(this.frame_shadow,{width:0,height:0});this.frame_list[d]=this.frame_shadow;this._panel_refresh();if(!this.visible){this.hide()}else{this.show()}var b=this;$(window).resize(function(){if(b.visible){b._panel_refresh()}})},add:function(b){var e={title:"",content:null,target:"",type:null};if(b){b=_.defaults(b,e)}else{b=e}if(!b.content){return}if(this.frame_counter>=this.options.frame_max){alert("You have reached the maximum number of allowed frames ("+this.options.frame_max+").");return}var c="#frame-"+(this.frame_counter_id++);if($(c).length!==0){alert("This frame already exists. This page might contain multiple frame managers.");return}this.top=this.options.top_min;var d=null;if(b.type=="url"){d=$(this._template_frame_url(c.substring(1),b.title,b.content))}else{d=$(this._template_frame(c.substring(1),b.title));d.find(".f-content").append(b.content)}$(this.el).append(d);var f={id:c,screen_location:{},grid_location:{},grid_rank:null,grid_lock:false};b.width=this._to_pixel_coord("width",this.options.frame.cols);b.height=this._to_pixel_coord("height",this.options.frame.rows);this.frame_z=parseInt($(f.id).css("z-index"));this.frame_list[c]=f;this.frame_counter++;this._frame_resize(f,{width:b.width,height:b.height});this._frame_insert(f,{top:0,left:0},true);if(!this.visible){this.show()}},show:function(){this.visible=true;this.$el.find(".frame").fadeIn("fast");this.$el.find(this.frame_shadow.id).hide();this.$el.find(".frame-background").show();this._panel_refresh();this._menu_refresh()},hide:function(){if(this.event.type!==null){return}this.visible=false;this.$el.find(".frame").fadeOut("fast");this.$el.find(".frame-background").hide();this.$el.find(".frame-menu").hide();this._menu_refresh()},length:function(){return this.frame_counter},setOnChange:function(b){this.options.onchange=b},event:{type:null,target:null,xy:null},events:{mousemove:"_event_frame_mouse_move",mouseup:"_event_frame_mouse_up",mouseleave:"_event_frame_mouse_up",mousewheel:"_event_panel_scroll",DOMMouseScroll:"_event_panel_scroll","mousedown .frame":"_event_frame_mouse_down","mousedown .frame-background":"_event_hide","mousedown .frame-scroll-up":"_event_panel_scroll_up","mousedown .frame-scroll-down":"_event_panel_scroll_down","mousedown .f-close":"_event_frame_close","mousedown .f-pin":"_event_frame_lock"},_event_frame_mouse_down:function(b){if(this.event.type!==null){return}if($(b.target).hasClass("f-header")||$(b.target).hasClass("f-title")){this.event.type="drag"}if($(b.target).hasClass("f-resize")){this.event.type="resize"}if(this.event.type===null){return}b.preventDefault();this.event.target=this._frame_identify(b.target);if(this.event.target.grid_lock){this.event.type=null;return}this.event.xy={x:b.originalEvent.pageX,y:b.originalEvent.pageY};this._frame_drag_start(this.event.target)},_event_frame_mouse_move:function(h){if(this.event.type!="drag"&&this.event.type!="resize"){return}var f={x:h.originalEvent.pageX,y:h.originalEvent.pageY};var c={x:f.x-this.event.xy.x,y:f.y-this.event.xy.y};this.event.xy=f;var g=this._frame_screen(this.event.target);if(this.event.type=="resize"){g.width+=c.x;g.height+=c.y;var d=this.options.cell-this.options.margin-1;g.width=Math.max(g.width,d);g.height=Math.max(g.height,d);this._frame_resize(this.event.target,g);g.width=this._to_grid_coord("width",g.width)+1;g.height=this._to_grid_coord("height",g.height)+1;g.width=this._to_pixel_coord("width",g.width);g.height=this._to_pixel_coord("height",g.height);this._frame_resize(this.frame_shadow,g);this._frame_insert(this.frame_shadow,{top:this._to_grid_coord("top",g.top),left:this._to_grid_coord("left",g.left)})}if(this.event.type=="drag"){g.left+=c.x;g.top+=c.y;this._frame_offset(this.event.target,g);var b={top:this._to_grid_coord("top",g.top),left:this._to_grid_coord("left",g.left)};if(b.left!==0){b.left++}this._frame_insert(this.frame_shadow,b)}},_event_frame_mouse_up:function(b){if(this.event.type!="drag"&&this.event.type!="resize"){return}this._frame_drag_stop(this.event.target);this.event.type=null},_event_frame_close:function(c){if(this.event.type!==null){return}c.preventDefault();var d=this._frame_identify(c.target);var b=this;$(d.id).fadeOut("fast",function(){$(d.id).remove();delete b.frame_list[d.id];b.frame_counter--;b._panel_refresh(true);b._panel_animation_complete();if(b.visible&&b.frame_counter==0){b.hide()}})},_event_frame_lock:function(b){if(this.event.type!==null){return}b.preventDefault();var c=this._frame_identify(b.target);if(c.grid_lock){c.grid_lock=false;$(c.id).find(".f-pin").removeClass("toggle");$(c.id).find(".f-header").removeClass("f-not-allowed");$(c.id).find(".f-title").removeClass("f-not-allowed");$(c.id).find(".f-resize").show();$(c.id).find(".f-close").show()}else{c.grid_lock=true;$(c.id).find(".f-pin").addClass("toggle");$(c.id).find(".f-header").addClass("f-not-allowed");$(c.id).find(".f-title").addClass("f-not-allowed");$(c.id).find(".f-resize").hide();$(c.id).find(".f-close").hide()}},_event_hide:function(b){if(this.event.type!==null){return}this.hide()},_event_panel_scroll:function(b){if(this.event.type!==null||!this.visible){return}b.preventDefault();var c=b.originalEvent.detail?b.originalEvent.detail:b.originalEvent.wheelDelta/-3;this._panel_scroll(c)},_event_panel_scroll_up:function(b){if(this.event.type!==null){return}b.preventDefault();this._panel_scroll(-this.options.scroll)},_event_panel_scroll_down:function(b){if(this.event.type!==null){return}b.preventDefault();this._panel_scroll(this.options.scroll)},_frame_identify:function(b){return this.frame_list["#"+$(b).closest(".frame").attr("id")]},_frame_drag_start:function(c){this._frame_focus(c,true);var b=this._frame_screen(c);this._frame_resize(this.frame_shadow,b);this._frame_grid(this.frame_shadow,c.grid_location);c.grid_location=null;$(this.frame_shadow.id).show();$(".f-cover").show()},_frame_drag_stop:function(c){this._frame_focus(c,false);var b=this._frame_screen(this.frame_shadow);this._frame_resize(c,b);this._frame_grid(c,this.frame_shadow.grid_location,true);this.frame_shadow.grid_location=null;$(this.frame_shadow.id).hide();$(".f-cover").hide();this._panel_animation_complete()},_to_grid_coord:function(d,c){var b=(d=="width"||d=="height")?1:-1;if(d=="top"){c-=this.top}return parseInt((c+b*this.options.margin)/this.options.cell,10)},_to_pixel_coord:function(d,e){var b=(d=="width"||d=="height")?1:-1;var c=(e*this.options.cell)-b*this.options.margin;if(d=="top"){c+=this.top}return c},_to_grid:function(b){return{top:this._to_grid_coord("top",b.top),left:this._to_grid_coord("left",b.left),width:this._to_grid_coord("width",b.width),height:this._to_grid_coord("height",b.height)}},_to_pixel:function(b){return{top:this._to_pixel_coord("top",b.top),left:this._to_pixel_coord("left",b.left),width:this._to_pixel_coord("width",b.width),height:this._to_pixel_coord("height",b.height)}},_is_collision:function(d){function b(g,f){return !(g.left>f.left+f.width-1||g.left+g.width-1<f.left||g.top>f.top+f.height-1||g.top+g.height-1<f.top)}for(var c in this.frame_list){var e=this.frame_list[c];if(e.grid_location===null){continue}if(b(d,e.grid_location)){return true}}return false},_location_rank:function(b){return(b.top*this.cols)+b.left},_menu_refresh:function(){if(this.visible){if(this.top==this.options.top_min){$(".frame-scroll-up").hide()}else{$(".frame-scroll-up").show()}if(this.top==this.top_max){$(".frame-scroll-down").hide()}else{$(".frame-scroll-down").show()}}if(this.options.onchange){this.options.onchange()}},_panel_animation_complete:function(){var b=this;$(".frame").promise().done(function(){b._panel_scroll(0,true)})},_panel_refresh:function(b){this.cols=parseInt($(window).width()/this.options.cell,10)+1;this._frame_insert(null,null,b)},_panel_scroll:function(g,b){var d=this.top-this.options.scroll*g;d=Math.max(d,this.top_max);d=Math.min(d,this.options.top_min);if(this.top!=d){for(var c in this.frame_list){var f=this.frame_list[c];if(f.grid_location!==null){var e={top:f.screen_location.top-(this.top-d),left:f.screen_location.left};this._frame_offset(f,e,b)}}this.top=d}this._menu_refresh()},_frame_insert:function(h,b,d){var c=[];if(h){h.grid_location=null;c.push([h,this._location_rank(b)])}var e=null;for(e in this.frame_list){var g=this.frame_list[e];if(g.grid_location!==null&&!g.grid_lock){g.grid_location=null;c.push([g,g.grid_rank])}}c.sort(function(k,f){var m=k[1];var l=f[1];return m<l?-1:(m>l?1:0)});for(e=0;e<c.length;e++){this._frame_place(c[e][0],d)}this.top_max=0;for(var e in this.frame_list){var h=this.frame_list[e];if(h.grid_location!==null){this.top_max=Math.max(this.top_max,h.grid_location.top+h.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._menu_refresh()},_frame_place:function(h,c){h.grid_location=null;var f=this._to_grid(this._frame_screen(h));var b=false;for(var e=0;e<this.options.rows;e++){for(var d=0;d<Math.max(1,this.cols-f.width);d++){f.top=e;f.left=d;if(!this._is_collision(f)){b=true;break}}if(b){break}}if(b){this._frame_grid(h,f,c)}else{console.log("Grid dimensions exceeded.")}},_frame_focus:function(d,b){var c=this.frame_z+(b?1:0);$(d.id).css("z-index",c)},_frame_offset:function(e,d,c){e.screen_location.left=d.left;e.screen_location.top=d.top;if(c){this._frame_focus(e,true);var b=this;$(e.id).animate({top:d.top,left:d.left},"fast",function(){b._frame_focus(e,false)})}else{$(e.id).css({top:d.top,left:d.left})}},_frame_resize:function(c,b){$(c.id).css({width:b.width,height:b.height});c.screen_location.width=b.width;c.screen_location.height=b.height},_frame_grid:function(d,b,c){d.grid_location=b;this._frame_offset(d,this._to_pixel(b),c);d.grid_rank=this._location_rank(b)},_frame_screen:function(c){var b=c.screen_location;return{top:b.top,left:b.left,width:b.width,height:b.height}},_template:function(){return'<div class="galaxy-frame"></div>'},_template_frame:function(c,b){if(!b){b=""}return'<div id="'+c+'" 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-resize-full"></span></div>'},_template_frame_url:function(e,d,b){if(b.indexOf("?")==-1){b+="?"}else{b+="&"}b+="widget=True";var c=$(this._template_frame(e,d));c.find(".f-content").append('<iframe scrolling="auto" class="f-iframe" src="'+b+'"></iframe>');return c},_template_shadow:function(b){return'<div id="'+b+'" class="frame-shadow corner"></div>'},_template_background:function(){return'<div class="frame-background"></div>'},_template_menu: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}}); |