6 // prevent a console.log from blowing things up if we are on a browser that
 
   8 if (typeof console === 'undefined') {
 
  10   console.log = console.info = console.warn = console.error = function(){};
 
  16   var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
 
  17   this.Class = function(){};
 
  18   Class.extend = function(prop) {
 
  19     var _super = this.prototype;
 
  21     var prototype = new this();
 
  23     for (var name in prop) {
 
  24       prototype[name] = typeof prop[name] == "function" &&
 
  25         typeof _super[name] == "function" && fnTest.test(prop[name]) ?
 
  28             var tmp = this._super;
 
  29             this._super = _super[name];
 
  30             var ret = fn.apply(this, arguments);       
 
  34         })(name, prop[name]) :
 
  38       if ( !initializing && this.init )
 
  39         this.init.apply(this, arguments);
 
  41     Class.prototype = prototype;
 
  42     Class.constructor = Class;
 
  43     Class.extend = arguments.callee;   
 
  50   this.render_template = function render_template(str, data){
 
  51     // Figure out if we're getting a template, or if we need to
 
  52     // load the template - and be sure to cache the result.
 
  53     var fn = !/^[\d\s-_]/.test(str) ?
 
  54       cache[str] = cache[str] ||
 
  55         render_template(document.getElementById(str).innerHTML) :
 
  57       // Generate a reusable function that will serve as a template
 
  58       // generator (and which will be cached).
 
  60         "var p=[],print=function(){p.push.apply(p,arguments);};" +
 
  62         // Introduce the data as local variables using with(){}
 
  63         "with(obj){p.push('" +
 
  65         // Convert the template into pure JavaScript
 
  67           .replace(/[\r\t\n]/g, " ")
 
  68           .split("<%").join("\t")
 
  69           .replace(/((^|%>)[^\t]*)'/g, "$1\r")
 
  70           .replace(/\t=(.*?)%>/g, "',$1,'")
 
  71           .split("\t").join("');")
 
  72           .split("%>").join("p.push('")
 
  73           .split("\r").join("\\'")
 
  74       + "');}return p.join('');");
 
  76       // Provide some basic currying to the user
 
  77     return data ? fn( data ) : fn;
 
  83   var slice = Array.prototype.slice;
 
  85   function update(array, args) {
 
  86     var arrayLength = array.length, length = args.length;
 
  87     while (length--) array[arrayLength + length] = args[length];
 
  91   function merge(array, args) {
 
  92     array = slice.call(array, 0);
 
  93     return update(array, args);
 
  96   Function.prototype.bind = function(context) {
 
  97     if (arguments.length < 2 && typeof arguments[0] === 'undefined') {
 
 101     var args = slice.call(arguments, 1);
 
 103       var a = merge(args, arguments);
 
 104       return __method.apply(context, a);
 
 111 var Editor = Editor || {};
 
 113 // Obiekt implementujÄ…cy wzorzec KVC/KVO
 
 114 Editor.Object = Class.extend({
 
 115   _className: 'Editor.Object',
 
 120     this._observers = {};
 
 123   description: function() {
 
 124     return this._className + '(guid = ' + this.guid() + ')';
 
 127   addObserver: function(observer, property, callback) {
 
 128     // console.log('Add observer', observer.description(), 'to', this.description(), '[', property, ']');
 
 129     if (!this._observers[property]) {
 
 130       this._observers[property] = {}
 
 132     this._observers[property][observer.guid()] = callback;
 
 136   removeObserver: function(observer, property) {
 
 138       for (var property in this._observers) {
 
 139         this.removeObserver(observer, property)
 
 142       // console.log('Remove observer', observer.description(), 'from', this.description(), '[', property, ']');
 
 143       delete this._observers[property][observer.guid()];
 
 148   notifyObservers: function(property) {
 
 149     var currentValue = this[property];
 
 150     for (var guid in this._observers[property]) {
 
 151       // console.log(this._observers[property][guid]);
 
 152       // console.log('Notifying', guid, 'of', this.description(), '[', property, ']');
 
 153       this._observers[property][guid](property, currentValue, this);
 
 160       this._guid = ('editor-' + Editor.Object._lastGuid++);
 
 165   get: function(property) {
 
 166     return this[property];
 
 169   set: function(property, value) {
 
 170     if (this[property] != value) {
 
 171       this[property] = value;
 
 172       this.notifyObservers(property);
 
 177   dispose: function() {
 
 178     delete this._observers;
 
 182 Editor.Object._lastGuid = 0;