home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Chip 2011 November
/
CHIP_2011_11.iso
/
Programy
/
Narzedzia
/
AIMP2
/
aimp_2.61.583.exe
/
$TEMP
/
YandexPackSetup.msi
/
fil21A2585F0D73A2DCED1C5DE16339BCF3
< prev
next >
Wrap
Text File
|
2010-07-12
|
9KB
|
308 lines
XB.UI.Behaviour = Base.extend({
name: "generic",
nodeName: "box",
constructor: function(comment, element, widgetInstanceId, builder) {
this.comment = comment;
this.element = element;
this.widgetInstanceId = widgetInstanceId;
this.builder = builder;
this.logger = XB._base.application.core.Log4Moz.repository.getLogger(XB._base.loggersRoot + ".UI.Behaviour");
this.namespaceURI = XB.UI.consts.STR_XUL_NS;
if (this.comment)
this.comment.behaviour = this;
this.attribute = { __proto__: null };
this.events = [];
this.on(this.comment, "DOMNodeInserted", this.onInserted, false, this);
this.on(this.comment, "DOMNodeRemoved", this.onRemoved, false, this);
},
destructor: function() {
},
readAttributes: function() {
var attributes = this.element.attributes;
for (var i = attributes.length; i--;) {
var attribute = attributes[i];
this.attribute[attribute.name] = attribute.value;
}
},
applyAttributes: function() {
var attribute = this.attribute;
for (var name in attribute) {
this.onAttribute({name: name, value: attribute[name]});
}
},
setAttribute: function(name, value, inherited) {
inherited = inherited || false;
if (inherited) {
if (this.attribute[name] != undefined)
return;
}
else
this.attribute[name] = value;
if (this.inheritAttributes && this.inheritAttributes[name])
this.inheritAttribute(name, value);
else
if (!inherited || (this.attribute[name] == undefined))
this.onAttribute({name: name, value: value, inherited: inherited});
},
getAttribute: function(name) {
return this.attribute[name];
},
inheritanceAttributesEx: function(heir, attributes) {
function intersect(a, b) {
var c = {},
i;
for (i in a)
if (b[i])
c[i] = 1;
return c;
}
if (!this.inheritAttributes)
return attributes;
attributes = intersect(attributes, this.inheritAttributes);
var empty = true;
for (let name in attributes) {
empty = false;
break;
}
if (empty)
return;
for (let name in attributes)
if (this.attribute[name] != undefined) {
heir.setAttribute(name, this.attribute[name], true);
delete attributes[name];
}
if (this.parent)
attributes = this.parent.inheritanceAttributesEx(heir, attributes);
return attributes;
},
inheritanceAttributes: function() {
try {
if (this.succeedAttributes && this.parent)
this.parent.inheritanceAttributesEx(this, this.succeedAttributes);
} catch(e) {
this.logger.error(e);
}
},
inheritAttribute: function(name, value) {
var heirs = this.heirs();
for each (var heir in heirs)
if (
(heir.succeedAttributes && heir.succeedAttributes[name]) ||
(heir.inheritAttributes && heir.inheritAttributes[name])
)
heir.setAttribute(name, value, true);
},
onAttribute: function() {
},
getWidgetContainer: function() {
if (this.node && this.node.parentNode && this.node.parentNode.isXBWidget)
return this.node.parentNode;
if (this.parent)
return this.parent.getWidgetContainer();
return null;
},
children: function() {
var children = [],
child = this.node.firstChild;
while(child) {
if ((child.nodeType == child.COMMENT_NODE) && child.behaviour)
children.push(child.behaviour);
child = child.nextSibling;
}
return children;
},
index: function() {
return this.parent.children().indexOf(this);
},
heirs: function() {
return this.children();
},
onInserted: function(event) {
if (event.eventPhase != event.AT_TARGET)
return;
if (this.deaf)
return;
this.readAttributes();
this.create();
this.append();
this.applyAttributes();
this.inheritanceAttributes();
this.build();
},
onRemoved: function(event) {
try {
if (event.eventPhase != event.AT_TARGET)
return;
if (this.deaf)
return;
this.destroy();
}
catch (e) {
this.logger.error(XB._base.application.core.Lib.misc.formatError(e));
this.logger.debug(e.stack);
}
},
create: function() {
this.logger.trace("Creating node " + this.nodeName);
this.document = this.comment.ownerDocument;
this.parent = this.comment.parentNode.behaviour;
this.node = this.document.createElementNS(this.namespaceURI, this.nodeName);
this.node.setAttribute("xb-name", this.name);
this.node.behaviour = this;
},
append: function() {
this.comment.parentNode.insertBefore(this.node, this.comment);
},
buildFake: function() {
this.fake = this.document.createElementNS(XB.UI.consts.STR_XUL_NS, "box");
this.builder.build(this.element, this.fake, this.widgetInstanceId);
},
build: function() {
this.builder.build(this.element, this.node, this.widgetInstanceId);
},
destroy: function() {
this.removeEventListeners();
this.builder.cleanNode(this.fake);
this.builder.cleanNode(this.node);
this.builder.removeNode(this.comment);
this.builder.removeNode(this.node);
if (this.comment)
delete this.comment.behaviour;
if (this.node)
delete this.node.behaviour;
delete this.node;
delete this.comment;
},
transform: function(to) {
var oldNode = this.node;
this.nodeName = to.toString();
this.create();
oldNode.parentNode.insertBefore(this.node, oldNode);
while (oldNode.childNodes.length > 0) {
var node = oldNode.childNodes[0];
if (node.behaviour)
node.behaviour.deaf = true;
this.node.appendChild(node);
if (node.behaviour)
node.behaviour.deaf = false;
}
oldNode.parentNode.removeChild(oldNode);
},
removeEventListeners: function() {
for (var i = this.events.length; i--;)
this.events[i].disable();
this.events = [];
},
on: function(node, type, listener, capture, context) {
if (!node)
return;
this.events.push(new XB.UI.EventListener(node, type, listener, capture, context));
}
});
XB.UI.Behaviour.IWithAction = XB.UI.Behaviour.extend({
create: function() {
this.base();
this.on(this.node, "command", this.onAction, false, this);
this.on(this.node, "click", this.onAction, false, this);
},
onAction: function(event) {
if (event.type == "click") {
if (!(event.button == 1 && (this._url || this._action)))
return;
}
event.stopPropagation();
event.preventDefault();
let eventInfo = {
type: event.type,
keys: {
shift: event.shiftKey,
meta: event.metaKey,
ctrl: event.ctrlKey
},
mouse: {
button: event.button
}
};
if (this._action)
this._action.run(eventInfo);
if (this._url)
this._url.navigate(eventInfo);
},
addAction: function (action) {
if ((action == null) && (typeof action.run !== "function"))
throw new TypeError("Wrong action behaviour interface");
this._action = action;
},
removeAction: function (action) {
if (this._action == action)
this._action = null;
},
addURL: function (url) {
if ((url == null) && (typeof url.navigate !== "function"))
throw new TypeError("Wrong url behaviour interface");
this._url = url;
},
removeURL: function (url) {
if (this._url == url)
this._url = null;
}
});