/**
* portal - jQuery EasyUI
*
* Licensed under the GPL:
* http://www.gnu.org/licenses/gpl.txt
*
* Copyright 2010-2012 stworthy [ stworthy@gmail.com ]
*
* Dependencies:
* draggable
* panel
*
*/
(function($){
/**
* initialize the portal
*/
function init(target){
$(target).addClass('portal');
var table = $('
').appendTo(target);
var tr = table.find('tr');
var columnWidths = [];
var totalWidth = 0;
$(target).children('div:first').addClass('portal-column-left');
$(target).children('div:last').addClass('portal-column-right');
$(target).find('>div').each(function(){ // each column panel
var column = $(this);
totalWidth += column.outerWidth();
columnWidths.push(column.outerWidth());
var td = $(' | ').appendTo(tr)
column.addClass('portal-column').appendTo(td);
column.find('>div').each(function(){ // each portal panel
var p = $(this).addClass('portal-p').panel({
doSize:false,
cls:'portal-panel'
});
makeDraggable(target, p);
});
});
for(var i=0; itable').outerHeight() > t.height();
var width = t.width();
var columnWidths = $.data(target, 'portal').columnWidths;
var leftWidth = 0;
// calculate and set every column size
for(var i=0; idiv.panel-header>div.panel-title',
proxy:function(source){
var p = $('proxy
').insertAfter(source);
p.width($(source).width());
p.height($(source).height());
p.html($(source).html());
p.find('div.portal-p').removeClass('portal-p');
return p;
},
onBeforeDrag:function(e){
e.data.startTop = $(this).position().top + $(target).scrollTop();
},
onStartDrag:function(e){
$(this).hide();
spacer = $('').insertAfter(this);
setSpacerSize($(this).outerWidth(), $(this).outerHeight());
},
onDrag:function(e){
var p = findPanel(e, this);
if (p){
if (p.pos == 'up'){
spacer.insertBefore(p.target);
} else {
spacer.insertAfter(p.target);
}
setSpacerSize($(p.target).outerWidth());
} else {
var c = findColumn(e);
if (c){
if (c.find('div.portal-spacer').length == 0){
spacer.appendTo(c);
setSize(target);
setSpacerSize(c.width());
}
}
}
},
onStopDrag:function(e){
$(this).css('position', 'static');
$(this).show();
spacer.hide();
$(this).insertAfter(spacer);
spacer.remove();
setSize(target);
panel.panel('move');
var opts = $.data(target, 'portal').options;
opts.onStateChange.call(target);
}
});
/**
* find which panel the cursor is over
*/
function findPanel(e, source){
var result = null;
$(target).find('div.portal-p').each(function(){
var pal = $(this).panel('panel');
if (pal[0] != source){
var pos = pal.offset();
if (e.pageX > pos.left && e.pageX < pos.left + pal.outerWidth()
&& e.pageY > pos.top && e.pageY < pos.top + pal.outerHeight()){
if (e.pageY > pos.top + pal.outerHeight() / 2){
result = {
target:pal,
pos:'down'
};
} else {
result = {
target:pal,
pos:'up'
}
}
}
}
});
return result;
}
/**
* find which portal column the cursor is over
*/
function findColumn(e){
var result = null;
$(target).find('div.portal-column').each(function(){
var pal = $(this);
var pos = pal.offset();
if (e.pageX > pos.left && e.pageX < pos.left + pal.outerWidth()){
result = pal;
}
});
return result;
}
/**
* set the spacer size
*/
function setSpacerSize(width, height){
spacer._outerWidth(width);
if (height){
spacer._outerHeight(height);
}
}
}
$.fn.portal = function(options, param){
if (typeof options == 'string'){
return $.fn.portal.methods[options](this, param);
}
options = options || {};
return this.each(function(){
var state = $.data(this, 'portal');
if (state){
$.extend(state.options, options);
} else {
state = $.data(this, 'portal', {
options: $.extend({}, $.fn.portal.defaults, $.fn.portal.parseOptions(this), options),
columnWidths: init(this)
});
}
if (state.options.border){
$(this).removeClass('portal-noborder');
} else {
$(this).addClass('portal-noborder');
}
setSize(this);
});
};
$.fn.portal.methods = {
options: function(jq){
return $.data(jq[0], 'portal').options;
},
resize: function(jq, param){
return jq.each(function(){
if (param){
var opts = $.data(this, 'portal').options;
if (param.width) opts.width = param.width;
if (param.height) opts.height = param.height;
}
setSize(this);
});
},
getPanels: function(jq, columnIndex){
var c = jq; // the panel container
if (columnIndex >= 0){
c = jq.find('div.portal-column:eq(' + columnIndex + ')');
}
var panels = [];
c.find('div.portal-p').each(function(){
panels.push($(this));
});
return panels;
},
add: function(jq, param){ // param: {panel,columnIndex}
return jq.each(function(){
var c = $(this).find('div.portal-column:eq(' + param.columnIndex + ')');
var p = param.panel.addClass('portal-p');
p.panel('panel').addClass('portal-panel').appendTo(c);
makeDraggable(this, p);
p.panel('resize', {width:c.width()});
});
},
remove: function(jq, panel){
return jq.each(function(){
var panels = $(this).portal('getPanels');
for(var i=0; i