pane.js
Summary
No overview generated for 'pane.js'
Zapatec.Pane = function(objArgs){
this.config = {};
if(arguments.length == 0){
objArgs = {};
}
this.widgetType = "pane";
this.ready = false;
this.loading = false;
this.prepared = false;
Zapatec.Utils.createProperty(this, "container", null);
Zapatec.Utils.createProperty(this, "contentElement", null);
Zapatec.Utils.createProperty(this, "iframeDocument", null);
Zapatec.Pane.SUPERconstructor.call(this, objArgs);
}
Zapatec.Pane.id = "Zapatec.Pane";
Zapatec.inherit(Zapatec.Pane, Zapatec.Widget);
Zapatec.Pane.prototype.init = function(objArgs){
Zapatec.Utils.createProperty(this.config, "parent", document.body);
this.config.theme = null;
this.config.width = null;
this.config.height = null;
this.config.containerType = "div";
this.config.sourceType = null;
this.config.source = null;
this.config.autoContentWidth = false;
this.config.autoContentHeight = false;
this.config.onlyInit = false;
this.config.showLoadingIndicator = true;
this.config.overflow = "auto";
this.config.id = null;
Zapatec.Pane.SUPERclass.init.call(this, objArgs);
if(this.config.containerType == null){
this.config.containerType = "div";
}
if (!this.config.onlyInit) {
this.create(this.config.width, this.config.height);
}
var self = this;
function update() {
if (self.loader) {
self.loader.update();
}
}
this.addEventListener("fetchSourceStart", update);
this.addEventListener("fetchSourceEnd", update);
}
Zapatec.Pane.prototype.prepareHtml = function() {
if(this.config.containerType.toLowerCase() == 'iframe'){
var iframe = document.createElement("iframe");
iframe.src = Zapatec.zapatecPath + "pane_files/blank.html#" + this.id;
this.container = iframe;
iframe = null;
} else if(this.config.containerType.toLowerCase() == 'div'){
this.container = document.createElement("div");
if (this.config.id) {
this.container.id = this.config.id;
}
this.contentElement = this.container;
} else if (this.config.parent && this.config.parent.nodeType == 1) {
this.container = this.config.parent;
this.contentElement = this.container;
}
this.prepared = true;
};
Zapatec.Pane.prototype.create = function(width, height) {
if (!this.prepared) {
this.prepareHtml();
}
if (!(this.config.parent = Zapatec.Widget.getElementById(this.config.parent))) {
Zapatec.Log({description: "No reference to parent element."});
return null;
}
if (this.config.parent.requestParentFor && !(this.config.parent = this.config.parent.requestParentFor(this))) {
Zapatec.Log({description: "No reference to parent element after request to the Parent Widget!"});
return null;
}
if (this.config.containerType.toLowerCase() == 'div' ||
this.config.containerType.toLowerCase() == 'iframe') {
this.ready = false;
this.config.parent.appendChild(this.container);
if (this.config.containerType.toLowerCase() != 'iframe') {
this.initPane();
}
} else if (this.config.containerType.toLowerCase() == 'current') {
this.container = this.config.parent;
this.contentElement = this.container;
this.initPane();
} else {
Zapatec.Log({description: "Unknown container type: " + this.config.containerType + ". Possible values: iframe|div"})
}
Zapatec.Utils.addClass(this.container, this.getClassName({prefix: "zpPane"}));
if (width || this.config.width) {
this.setWidth(width || this.config.width);
}
if (height || this.config.height) {
this.setHeight(height || this.config.height);
}
this.getContainer().style.display = "block";
this.setPaneContent();
};
Zapatec.Pane.prototype.initPane = function(){
if(this.config.containerType.toLowerCase() == 'iframe'){
var doc = null;
var sameDomain = true;
var url = this.getContainer().src;
var anchorEl = document.createElement("a");
var protocolSeparatorPos = url.indexOf("://");
if (protocolSeparatorPos != -1) {
var domainSeparatorPos = url.indexOf("/", protocolSeparatorPos + 3);
var domain = url.substring(
(protocolSeparatorPos > 0 ? protocolSeparatorPos + 3 : 0),
(domainSeparatorPos > 0 ? domainSeparatorPos : url.length)
);
if (domain != window.location.host) {
sameDomain = false;
}
}
if (sameDomain) {
if(this.container.contentDocument != null){
doc = this.container.contentDocument;
} else if(this.container.contentWindow && this.container.contentWindow.document != null){
doc = this.container.contentWindow.document;
}
var self = this;
anchorEl.href = url;
url = anchorEl.href;
if (doc == null || doc.body == null || (Zapatec.is_gecko && url != this.container.contentWindow.location.href)) {
setTimeout(function(){self.initPane()}, 50);
return false;
}
this.iframeDocument = doc;
this.contentElement = doc.body;
if (typeof this.container.contentWindow.Zapatec != "object" && typeof this.container.contentWindow.Zapatec != "function") {
this.container.contentWindow.Zapatec = {};
this.container.contentWindow.Zapatec.windowLoaded = typeof(doc.readyState) != 'undefined' ?
(
doc.readyState == 'loaded' ||
doc.readyState == 'complete'
) :
doc.getElementsByTagName != null && typeof(doc.getElementsByTagName('body')[0]) != 'undefined'
;
Zapatec.Utils.addEvent(this.container.contentWindow, "load", function() {self.container.contentWindow.Zapatec.windowLoaded = true;});
}
if (!this.container.contentWindow.Zapatec || !this.container.contentWindow.Zapatec.windowLoaded) {
setTimeout(function(){self.initPane()}, 50);
return false;
}
doc = null;
}
}
if (this.config.overflow) {
this.getContainer().style.overflow = this.config.overflow;
}
this.ready = true;
this.fireEvent("onReady", this);
this.hideIndicator();
this.loading = false;
this.removeEvent("onReady");
}
Zapatec.Pane.prototype.getContainer = function(){
return this.container;
}
Zapatec.Pane.prototype.getIframeDocument = function(){
return this.iframeDocument;
}
Zapatec.Pane.prototype.getContentElement = function() {
return this.contentElement;
}
Zapatec.Pane.prototype.isReady = function(){
return this.ready;
}
Zapatec.Pane.prototype.loadDataJson = function(objSource){
return objSource != null ? this.setContent(objSource.content) : null;
}
Zapatec.Pane.prototype.setContent = function(content){
if(!this.isReady()){
var self = this;
setTimeout(function(){self.setContent(content)}, 50);
return null;
}
this.loading = false;
if (!this.getContentElement()) {
this.hideIndicator();
return false;
}
if(content === null){
this.hideIndicator();
return null;
} else {
if (this.config.containerType.toLowerCase() != "iframe") {
var oldOverflow = this.getContainer().style.overflow;
if (this.config.autoContentWidth) {
this.getContainer().style.overflow = "visible";
this.getContainer().style.width = "auto";
}
if (this.config.autoContentHeight) {
this.getContainer().style.overflow = "visible";
this.getContainer().style.height = "auto";
}
}
if(typeof(content) == 'string'){
Zapatec.Transport.setInnerHtml({container : this.getContentElement(), html : content});
} else {
try{
if ((Zapatec.is_ie || Zapatec.is_opera) && this.config.containerType.toLowerCase() == "iframe") {
Zapatec.Transport.setInnerHtml({container : this.getContentElement(), html : content.outerHTML});
} else {
if (content.parentNode != this.getContentElement()) {
this.getContentElement().innerHTML = "";
this.getContentElement().appendChild(content);
}
}
} catch(ex){
this.hideIndicator();
return null;
}
}
if (this.config.containerType.toLowerCase() != "iframe") {
var newWidth = this.getWidth();
var newHeight = this.getHeight();
} else {
var newWidth = this.getContentElement().scrollWidth + 5;
var newHeight = this.getContentElement().scrollHeight + 5;
}
if (typeof oldOverflow != "undefined") this.getContainer().style.overflow = oldOverflow;
if (this.config.autoContentWidth) {
this.setWidth(newWidth);
}
if (this.config.autoContentHeight) {
this.setHeight(newHeight);
}
}
this.fireEvent("contentLoaded", this);
this.hideIndicator();
return true;
}
Zapatec.Pane.prototype.loadDataHtml = Zapatec.Pane.prototype.loadDataXml = Zapatec.Pane.prototype.setContent;
Zapatec.Pane.prototype.loadDataHtmlText = function(content) {
this.setContent(content);
};
Zapatec.Pane.prototype.setWidth = function(width){
var self = this;
this.fireWhenReady(function() {
self.getContainer().style.width = width + "px";
if (self.getContainer().offsetWidth != width) {
var newWidth = width - (self.getContainer().offsetWidth - width);
if (newWidth < 0) newWidth = 0;
self.getContainer().style.width = newWidth + "px";
}
});
}
Zapatec.Pane.prototype.getWidth = function(){
return this.getContainer().offsetWidth;
}
Zapatec.Pane.prototype.setHeight = function(height){
var self = this;
this.fireWhenReady(function() {
self.getContainer().style.height = height + "px";
if (self.getContainer().offsetHeight != height) {
var newHeight = height - (self.getContainer().offsetHeight - height);
if (newHeight < 0) newHeight = 0;
self.getContainer().style.height = newHeight + "px";
}
});
}
Zapatec.Pane.prototype.getHeight = function(){
return this.getContainer().offsetHeight;
}
Zapatec.Pane.prototype.removeBorder = function() {
if (this.config.containerType.toLowerCase() != "iframe") {
return false;
}
var self = this;
this.fireWhenReady(function() {
if (!Zapatec.is_ie) {
self.getContainer().style.border = "none";
} else {
if (self.getContentElement()) {
self.getContentElement().style.border = "none";
}
}
});
};
Zapatec.Pane.prototype.setPaneContent = function(content, type) {
if (!content && content !== "") {
content = this.config.source;
}
if (!type) {
type = this.config.sourceType;
}
this.config.source = content;
this.config.sourceType = type;
var self = this;
if (this.config.showLoadingIndicator) {
this.showIndicator();
this.loading = true;
}
if (this.config.containerType.toLowerCase() == "iframe" && type == "html/url") {
this.ready = false;
this.fireWhenReady(function() {
if (self.getContentElement()) {
try {
var newWidth = self.getContentElement().scrollWidth;
var newHeight = self.getContentElement().scrollHeight;
if (self.config.autoContentWidth) {
self.setWidth(newWidth);
}
if (self.config.autoContentHeight) {
self.setHeight(newHeight);
}
} catch(e) {}
}
self.fireEvent("contentLoaded", self);
if (self.events["contentLoaded"]) {
self.events["contentLoaded"].listeners = [];
}
});
this.getContainer().src = content;
setTimeout(function(){self.initPane()}, 50);
return true;
}
if (this.config.containerType.toLowerCase() == "iframe" && this.getContainer().src.indexOf((Zapatec.zapatecPath + "pane_files/blank.html#" + this.id).replace(/\.\.\
this.ready = false;
this.getContainer().src = Zapatec.zapatecPath + "pane_files/blank.html#" + this.id;
}
this.loadData();
return true;
};
Zapatec.Pane.prototype.show = function() {
this.getContainer().style.display = "";
if (this.loading) {
this.showIndicator();
}
};
Zapatec.Pane.prototype.hide = function() {
this.getContainer().style.display = "none";
if (this.loading) {
this.hideIndicator();
}
};
Zapatec.Pane.prototype.showIndicator = function(message) {
if (Zapatec.Indicator) {
this.hideIndicator();
if (!this.loader) {
this.loader = new Zapatec.Indicator({
container: this.container,
themePath: Zapatec.zapatecPath + "../zpextra/themes/indicator/"
});
}
this.loader.start(message || 'loading');
}
};
Zapatec.Pane.prototype.hideIndicator = function() {
if (this.loader && this.loader.isActive()) {
this.loader.stop();
}
};
Zapatec.Pane.prototype.fireWhenReady = function(func) {
if (!this.isReady()) {
this.addEventListener("onReady", func);
} else {
func.call(this, this);
}
}
Zapatec.Pane.prototype.destroy = function(){
this.hideIndicator();
this.config.parent = null;
this.contentElement = null;
this.iframeDocument = null;
if(Zapatec.is_ie && this.config.containerType.toLowerCase() == 'iframe'){
this.container.src = "javascript:void(0)";
}
if (this.container.outerHTML) {
this.container.outerHTML = "";
} else {
Zapatec.Utils.destroy(this.container);
}
this.container = null;
this.ready = false;
this.prepared = false;
}
Documentation generated by
JSDoc on Thu Aug 16 12:18:39 2007