summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorportix <none@none>2012-12-04 16:51:05 +0100
committerportix <none@none>2012-12-04 16:51:05 +0100
commit11873fc658179f546b3ea4d66398d9ad6c3a51f5 (patch)
treea366598b02394314ecbe0aa074c0dc21b25a9a00 /scripts
parentbd1683913bc3b77aa73c68e3ed7bd1d0a5e1fb2b (diff)
downloaddwb-11873fc658179f546b3ea4d66398d9ad6c3a51f5.zip
Distinguish between GObject.connect and GObject.notify
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/dwb.js7
-rw-r--r--scripts/lib/util.js38
2 files changed, 44 insertions, 1 deletions
diff --git a/scripts/lib/dwb.js b/scripts/lib/dwb.js
index ef5597f3..92020fa0 100644
--- a/scripts/lib/dwb.js
+++ b/scripts/lib/dwb.js
@@ -90,6 +90,11 @@
configurable : true
}
});
- Object.defineProperty(WebKitWebView.prototype, "scrolledWindow", { get : function() { return this.parent; } , enumerable : true });
+ Object.defineProperty(GObject.prototype, "notify", {
+ value : function(name, callback, after)
+ {
+ return this.connect("notify::" + util.uncamelize(name), callback, after || false);
+ }
+ });
})();
Object.preventExtensions(this);
diff --git a/scripts/lib/util.js b/scripts/lib/util.js
index fe74bdaf..5bcdb6da 100644
--- a/scripts/lib/util.js
+++ b/scripts/lib/util.js
@@ -38,6 +38,44 @@
}
return null;
}
+ },
+ "uncamelize" :
+ {
+ value : function(text)
+ {
+ if (! text || text.length === 0)
+ return text;
+
+ var c = text.charAt(0);
+ var uncamelized = c == c.toUpperCase() ? c.toLowerCase() : c;
+ for (var i=1, l=text.length; i<l; ++i)
+ {
+ c = text.charAt(i);
+ uncamelized += c.toUpperCase() == c ? "-" + c.toLowerCase() : c;
+ }
+ return uncamelized;
+ }
+ },
+ "camelize" :
+ {
+ value : function(text)
+ {
+ if (! text || text.length === 0)
+ return text;
+
+ var camelized = "", c;
+ for (var i=0, l=text.length; i<l; ++i)
+ {
+ c = text.charAt(i);
+ if (c == "-" || c == "_") {
+ i++;
+ camelized += text.charAt(i).toUpperCase();
+ }
+ else
+ camelized += c;
+ }
+ return camelized;
+ }
}
});
Object.freeze(util);