aboutsummaryrefslogtreecommitdiff
path: root/includes/js/dojox/dtl/contrib
diff options
context:
space:
mode:
authormensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
committermensonge <mensonge@b3834d28-1941-0410-a4f8-b48e95affb8f>2008-11-13 09:49:11 +0000
commite44a7e37b6c7b5961adaffc62b9042b8d442938e (patch)
tree95b67c356e93163467db2451f2b8cce84ed5d582 /includes/js/dojox/dtl/contrib
parenta62b9742ee5e28bcec6872d88f50f25b820914f6 (diff)
downloadsemanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.gz
semanticscuttle-e44a7e37b6c7b5961adaffc62b9042b8d442938e.tar.bz2
New feature: basic Ajax suggestion for tags and implementation of Dojo toolkit
git-svn-id: https://semanticscuttle.svn.sourceforge.net/svnroot/semanticscuttle/trunk@151 b3834d28-1941-0410-a4f8-b48e95affb8f
Diffstat (limited to 'includes/js/dojox/dtl/contrib')
-rw-r--r--includes/js/dojox/dtl/contrib/data.js89
-rw-r--r--includes/js/dojox/dtl/contrib/dijit.js220
-rw-r--r--includes/js/dojox/dtl/contrib/html.js107
-rw-r--r--includes/js/dojox/dtl/contrib/objects.js15
4 files changed, 431 insertions, 0 deletions
diff --git a/includes/js/dojox/dtl/contrib/data.js b/includes/js/dojox/dtl/contrib/data.js
new file mode 100644
index 0000000..5ca3aa7
--- /dev/null
+++ b/includes/js/dojox/dtl/contrib/data.js
@@ -0,0 +1,89 @@
+if(!dojo._hasResource["dojox.dtl.contrib.data"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.dtl.contrib.data"] = true;
+dojo.provide("dojox.dtl.contrib.data");
+dojo.require("dojox.dtl._base");
+
+(function(){
+ var dd = dojox.dtl;
+ var ddcd = dd.contrib.data;
+
+ ddcd._BoundItem = dojo.extend(function(item, store){
+ this.item = item;
+ this.store = store;
+ },
+ {
+ get: function(key){
+ var store = this.store;
+ var item = this.item;
+
+ if(key == "getLabel"){
+ return store.getLabel(item);
+ }else if(key == "getAttributes"){
+ return store.getAttributes(item);
+ }else if(key == "getIdentity"){
+ if(store.getIdentity){
+ return store.getIdentity(item);
+ }
+ return "Store has no identity API";
+ }else{
+ if(store.hasAttribute(item, key)){
+ var value = store.getValue(item, key);
+ return (dojo.isObject(value) && store.isItem(value)) ? new ddcd._BoundItem(value, store) : value;
+ }else if(key.slice(-1) == "s" && store.hasAttribute(item, key.slice(0, -1))){
+ return dojo.map(store.getValues(item, key.slice(0, -1)), function(value){
+ return (dojo.isObject(value) && store.isItem(value)) ? new ddcd._BoundItem(value, store) : value;
+ });
+ }
+ }
+ }
+ });
+
+ ddcd.BindDataNode = dojo.extend(function(items, store, alias){
+ this.items = new dd._Filter(items);
+ this.store = new dd._Filter(store);
+ this.alias = alias;
+ },
+ {
+ render: function(context, buffer){
+ var items = this.items.resolve(context);
+ var store = this.store.resolve(context);
+ if(!store){
+ throw new Error("data_bind didn't receive a store");
+ }
+
+ var list = [];
+ if(items){
+ for(var i = 0, item; item = items[i]; i++){
+ list.push(new ddcd._BoundItem(item, store));
+ }
+ }
+
+ context[this.alias] = list;
+ return buffer;
+ },
+ unrender: function(context, buffer){
+ return buffer;
+ },
+ clone: function(){
+ return this;
+ }
+ });
+
+ dojo.mixin(ddcd, {
+ bind_data: function(parser, text){
+ var parts = dd.text.pySplit(text);
+
+ if(parts[2] != 'to' || parts[4] != 'as' || !parts[5]){
+ throw new Error("data_bind expects the format: 'data_bind items to store as varName'");
+ }
+
+ return new ddcd.BindDataNode(parts[1], parts[3], parts[5]);
+ }
+ });
+
+ dd.register.tags("dojox.dtl.contrib", {
+ "data": ["bind_data"]
+ });
+})();
+
+}
diff --git a/includes/js/dojox/dtl/contrib/dijit.js b/includes/js/dojox/dtl/contrib/dijit.js
new file mode 100644
index 0000000..41caf33
--- /dev/null
+++ b/includes/js/dojox/dtl/contrib/dijit.js
@@ -0,0 +1,220 @@
+if(!dojo._hasResource["dojox.dtl.contrib.dijit"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.dtl.contrib.dijit"] = true;
+dojo.provide("dojox.dtl.contrib.dijit");
+
+dojo.require("dojox.dtl.html");
+dojo.require("dojo.parser");
+
+(function(){
+ var dd = dojox.dtl;
+ var ddcd = dd.contrib.dijit;
+
+ ddcd.AttachNode = dojo.extend(function(keys, object){
+ this._keys = keys;
+ this._object = object;
+ },
+ {
+ render: function(context, buffer){
+ if(!this._rendered){
+ this._rendered = true;
+ for(var i=0, key; key = this._keys[i]; i++){
+ context.getThis()[key] = this._object || buffer.getParent();
+ }
+ }
+ return buffer;
+ },
+ unrender: function(context, buffer){
+ if(this._rendered){
+ this._rendered = false;
+ for(var i=0, key; key = this._keys[i]; i++){
+ if(context.getThis()[key] === (this._object || buffer.getParent())){
+ delete context.getThis()[key];
+ }
+ }
+ }
+ return buffer;
+ },
+ clone: function(buffer){
+ return new this.constructor(this._keys, this._object);
+ }
+ });
+
+ ddcd.EventNode = dojo.extend(function(command, obj){
+ this._command = command;
+
+ var type, events = command.split(/\s*,\s*/);
+ var trim = dojo.trim;
+ var types = [];
+ var fns = [];
+ while(type = events.pop()){
+ if(type){
+ var fn = null;
+ if(type.indexOf(":") != -1){
+ // oh, if only JS had tuple assignment
+ var funcNameArr = type.split(":");
+ type = trim(funcNameArr[0]);
+ fn = trim(funcNameArr[1]);
+ }else{
+ type = trim(type);
+ }
+ if(!fn){
+ fn = type;
+ }
+ types.push(type);
+ fns.push(fn);
+ }
+ }
+
+ this._types = types;
+ this._fns = fns;
+ this._object = obj;
+ this._rendered = [];
+ },
+ {
+ // _clear: Boolean
+ // Make sure we kill the actual tags (onclick problems, etc)
+ _clear: false,
+ render: function(context, buffer){
+ for(var i = 0, type; type = this._types[i]; i++){
+ if(!this._clear && !this._object){
+ buffer.getParent()[type] = null;
+ }
+ var fn = this._fns[i];
+ var args;
+ if(fn.indexOf(" ") != -1){
+ if(this._rendered[i]){
+ dojo.disconnect(this._rendered[i]);
+ this._rendered[i] = false;
+ }
+ args = dojo.map(fn.split(" ").slice(1), function(item){
+ return new dd._Filter(item).resolve(context);
+ });
+ fn = fn[0];
+ }
+ if(!this._rendered[i]){
+ if(!this._object){
+ this._rendered[i] = buffer.addEvent(context, type, fn, args);
+ }else{
+ this._rendered[i] = dojo.connect(this._object, type, context.getThis(), fn);
+ }
+ }
+ }
+ this._clear = true;
+
+ return buffer;
+ },
+ unrender: function(context, buffer){
+ while(this._rendered.length){
+ dojo.disconnect(this._rendered.pop());
+ }
+ return buffer;
+ },
+ clone: function(){
+ return new this.constructor(this._command, this._object);
+ }
+ });
+
+ function cloneNode(n1){
+ var n2 = n1.cloneNode(true);
+ if(dojo.isIE){
+ dojo.query("script", n2).forEach("item.text = this[index].text;", dojo.query("script", n1));
+ }
+ return n2;
+ }
+
+ ddcd.DojoTypeNode = dojo.extend(function(node, parsed){
+ this._node = node;
+ this._parsed = parsed;
+
+ var events = node.getAttribute("dojoAttachEvent");
+ if(events){
+ this._events = new ddcd.EventNode(dojo.trim(events));
+ }
+ var attach = node.getAttribute("dojoAttachPoint");
+ if(attach){
+ this._attach = new ddcd.AttachNode(dojo.trim(attach).split(/\s*,\s*/));
+ }
+
+ if (!parsed){
+ this._dijit = dojo.parser.instantiate([cloneNode(node)])[0];
+ }else{
+ node = cloneNode(node);
+ var old = ddcd.widgetsInTemplate;
+ ddcd.widgetsInTemplate = false;
+ this._template = new dd.HtmlTemplate(node);
+ ddcd.widgetsInTemplate = old;
+ }
+ },
+ {
+ render: function(context, buffer){
+ if(this._parsed){
+ var _buffer = new dd.HtmlBuffer();
+ this._template.render(context, _buffer);
+ var root = cloneNode(_buffer.getRootNode());
+ var div = document.createElement("div");
+ div.appendChild(root);
+ var rendered = div.innerHTML;
+ div.removeChild(root);
+ if(rendered != this._rendered){
+ this._rendered = rendered;
+ if(this._dijit){
+ this._dijit.destroyRecursive();
+ }
+ this._dijit = dojo.parser.instantiate([root])[0];
+ }
+ }
+
+ var node = this._dijit.domNode;
+
+ if(this._events){
+ this._events._object = this._dijit;
+ this._events.render(context, buffer);
+ }
+ if(this._attach){
+ this._attach._object = this._dijit;
+ this._attach.render(context, buffer);
+ }
+
+ return buffer.concat(node);
+ },
+ unrender: function(context, buffer){
+ return buffer.remove(this._dijit.domNode);
+ },
+ clone: function(){
+ return new this.constructor(this._node, this._parsed);
+ }
+ });
+
+ dojo.mixin(ddcd, {
+ widgetsInTemplate: true,
+ dojoAttachPoint: function(parser, text){
+ return new ddcd.AttachNode(dojo.trim(text).slice(16).split(/\s*,\s*/));
+ },
+ dojoAttachEvent: function(parser, text){
+ return new ddcd.EventNode(text.slice(16));
+ },
+ dojoType: function(parser, text){
+ if(ddcd.widgetsInTemplate){
+ var node = parser.swallowNode();
+ var parsed = false;
+ if(text.slice(-7) == " parsed"){
+ parsed = true;
+ node.setAttribute("dojoType", dojo.trim(text).slice(0, -7));
+ }
+ return new ddcd.DojoTypeNode(node, parsed);
+ }
+ return dd._noOpNode;
+ },
+ on: function(parser, text){
+ // summary: Associates an event type to a function (on the current widget) by name
+ var parts = text.split(" ");
+ return new ddcd.EventNode(parts[0] + ":" + parts.slice(1).join(" "));
+ }
+ });
+
+ dd.register.tags("dojox.dtl.contrib", {
+ "dijit": ["attr:dojoType", "attr:dojoAttachPoint", ["attr:attach", "dojoAttachPoint"], "attr:dojoAttachEvent", [/(attr:)?on(click|key(up))/i, "on"]]
+ });
+})();
+
+}
diff --git a/includes/js/dojox/dtl/contrib/html.js b/includes/js/dojox/dtl/contrib/html.js
new file mode 100644
index 0000000..260bbe2
--- /dev/null
+++ b/includes/js/dojox/dtl/contrib/html.js
@@ -0,0 +1,107 @@
+if(!dojo._hasResource["dojox.dtl.contrib.html"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.dtl.contrib.html"] = true;
+dojo.provide("dojox.dtl.contrib.html");
+
+dojo.require("dojox.dtl.html");
+
+(function(){
+ var dd = dojox.dtl;
+ var ddch = dd.contrib.html;
+
+ ddch.HtmlNode = dojo.extend(function(name){
+ this.contents = new dd._Filter(name);
+ this._div = document.createElement("div");
+ this._lasts = [];
+ },
+ {
+ render: function(context, buffer){
+ var text = this.contents.resolve(context);
+ if(text){
+ text = text.replace(/<(\/?script)/ig, '&lt;$1').replace(/\bon[a-z]+\s*=/ig, '');
+ if(this._rendered && this._last != text){
+ buffer = this.unrender(context, buffer);
+ }
+ this._last = text;
+
+ // This can get reset in the above tag
+ if(!this._rendered){
+ this._rendered = true;
+ var div = this._div;
+ div.innerHTML = text;
+ var children = div.childNodes;
+ while(children.length){
+ var removed = div.removeChild(children[0]);
+ this._lasts.push(removed);
+ buffer = buffer.concat(removed);
+ }
+ }
+ }
+
+ return buffer;
+ },
+ unrender: function(context, buffer){
+ if(this._rendered){
+ this._rendered = false;
+ this._last = "";
+ for(var i = 0, node; node = this._lasts[i++];){
+ buffer = buffer.remove(node);
+ dojo._destroyElement(node);
+ }
+ this._lasts = [];
+ }
+ return buffer;
+ },
+ clone: function(buffer){
+ return new this.constructor(this.contents.getExpression());
+ }
+ });
+
+ ddch.StyleNode = dojo.extend(function(styles){
+ this.contents = {};
+ this._styles = styles;
+ for(var key in styles){
+ this.contents[key] = new dd.Template(styles[key]);
+ }
+ },
+ {
+ render: function(context, buffer){
+ for(var key in this.contents){
+ dojo.style(buffer.getParent(), key, this.contents[key].render(context));
+ }
+ return buffer;
+ },
+ unrender: function(context, buffer){
+ return buffer;
+ },
+ clone: function(buffer){
+ return new this.constructor(this._styles);
+ }
+ });
+
+ dojo.mixin(ddch, {
+ html: function(parser, text){
+ var parts = text.split(" ", 2);
+ return new ddch.HtmlNode(parts[1]);
+ },
+ tstyle: function(parser, text){
+ var styles = {};
+ text = text.replace(/^tstyle\s+/, "");
+ var rules = text.split(/\s*;\s*/g);
+ for(var i = 0, rule; rule = rules[i]; i++){
+ var parts = rule.split(/\s*:\s*/g);
+ var key = parts[0];
+ var value = parts[1];
+ if(value.indexOf("{{") == 0){
+ styles[key] = value;
+ }
+ }
+ return new ddch.StyleNode(styles);
+ }
+ });
+
+ dd.register.tags("dojox.dtl.contrib", {
+ "html": ["html", "attr:tstyle"]
+ });
+})();
+
+}
diff --git a/includes/js/dojox/dtl/contrib/objects.js b/includes/js/dojox/dtl/contrib/objects.js
new file mode 100644
index 0000000..d29c0df
--- /dev/null
+++ b/includes/js/dojox/dtl/contrib/objects.js
@@ -0,0 +1,15 @@
+if(!dojo._hasResource["dojox.dtl.contrib.objects"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
+dojo._hasResource["dojox.dtl.contrib.objects"] = true;
+dojo.provide("dojox.dtl.contrib.objects");
+
+dojo.mixin(dojox.dtl.contrib.objects, {
+ key: function(value, arg){
+ return value[arg];
+ }
+});
+
+dojox.dtl.register.filters("dojox.dtl.contrib", {
+ "objects": ["key"]
+});
+
+}