8 var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
9 this.Class = function(){};
10 Class.extend = function(prop) {
11 var _super = this.prototype;
13 var prototype = new this();
15 for (var name in prop) {
16 prototype[name] = typeof prop[name] == "function" &&
17 typeof _super[name] == "function" && fnTest.test(prop[name]) ?
20 var tmp = this._super;
21 this._super = _super[name];
22 var ret = fn.apply(this, arguments);
26 })(name, prop[name]) :
30 if ( !initializing && this.init )
31 this.init.apply(this, arguments);
33 Class.prototype = prototype;
34 Class.constructor = Class;
35 Class.extend = arguments.callee;
42 this.render_template = function render_template(str, data){
43 // Figure out if we're getting a template, or if we need to
44 // load the template - and be sure to cache the result.
45 var fn = !/^[\d\s-_]/.test(str) ?
46 cache[str] = cache[str] ||
47 render_template(document.getElementById(str).innerHTML) :
49 // Generate a reusable function that will serve as a template
50 // generator (and which will be cached).
52 "var p=[],print=function(){p.push.apply(p,arguments);};" +
54 // Introduce the data as local variables using with(){}
55 "with(obj){p.push('" +
57 // Convert the template into pure JavaScript
59 .replace(/[\r\t\n]/g, " ")
60 .split("<%").join("\t")
61 .replace(/((^|%>)[^\t]*)'/g, "$1\r")
62 .replace(/\t=(.*?)%>/g, "',$1,'")
63 .split("\t").join("');")
64 .split("%>").join("p.push('")
65 .split("\r").join("\\'")
66 + "');}return p.join('');");
68 // Provide some basic currying to the user
69 return data ? fn( data ) : fn;
75 var slice = Array.prototype.slice;
77 function update(array, args) {
78 var arrayLength = array.length, length = args.length;
79 while (length--) array[arrayLength + length] = args[length];
83 function merge(array, args) {
84 array = slice.call(array, 0);
85 return update(array, args);
88 Function.prototype.bind = function(context) {
89 if (arguments.length < 2 && typeof arguments[0] === 'undefined') {
93 var args = slice.call(arguments, 1);
95 var a = merge(args, arguments);
96 return __method.apply(context, a);
103 var Editor = Editor || {};
105 // Obiekt implementujący wzorzec KVC/KVO
106 Editor.Object = Class.extend({
107 _className: 'Editor.Object',
112 this._observers = {};
115 description: function() {
116 return this._className + '(guid = ' + this.guid() + ')';
119 addObserver: function(observer, property, callback) {
120 // console.log('Add observer', observer.description(), 'to', this.description(), '[', property, ']');
121 if (!this._observers[property]) {
122 this._observers[property] = {}
124 this._observers[property][observer.guid()] = callback;
128 removeObserver: function(observer, property) {
130 for (var property in this._observers) {
131 this.removeObserver(observer, property)
134 // console.log('Remove observer', observer.description(), 'from', this.description(), '[', property, ']');
135 delete this._observers[property][observer.guid()];
140 notifyObservers: function(property) {
141 var currentValue = this[property];
142 for (var guid in this._observers[property]) {
143 // console.log(this._observers[property][guid]);
144 // console.log('Notifying', guid, 'of', this.description(), '[', property, ']');
145 this._observers[property][guid](property, currentValue, this);
152 this._guid = ('editor-' + Editor.Object._lastGuid++);
157 get: function(property) {
158 return this[property];
161 set: function(property, value) {
162 if (this[property] != value) {
163 this[property] = value;
164 this.notifyObservers(property);
169 dispose: function() {
170 delete this._observers;
174 Editor.Object._lastGuid = 0;