web/data/cubicweb.compat.js
changeset 5698 5c8fa1650299
parent 5658 7b9553a9db65
child 5699 f4f6ee3af50b
equal deleted inserted replaced
5697:ec1ce7198ef4 5698:5c8fa1650299
   102         return node;
   102         return node;
   103     }
   103     }
   104 );
   104 );
   105 
   105 
   106 /**
   106 /**
   107  * .. function:: Deferred
       
   108  *
       
   109  * dummy ultra minimalist implementation on deferred for jQuery
       
   110  */
       
   111 function Deferred() {
       
   112     this.__init__(this);
       
   113 }
       
   114 
       
   115 jQuery.extend(Deferred.prototype, {
       
   116     __init__: function() {
       
   117         this._onSuccess = [];
       
   118         this._onFailure = [];
       
   119         this._req = null;
       
   120         this._result = null;
       
   121         this._error = null;
       
   122     },
       
   123 
       
   124     addCallback: function(callback) {
       
   125         if (this._req.readyState == 4) {
       
   126             if (this._result) {
       
   127                 var args = [this._result, this._req];
       
   128                 jQuery.merge(args, cw.utils.sliceList(arguments, 1));
       
   129                 callback.apply(null, args);
       
   130             }
       
   131         }
       
   132         else {
       
   133             this._onSuccess.push([callback, cw.utils.sliceList(arguments, 1)]);
       
   134         }
       
   135         return this;
       
   136     },
       
   137 
       
   138     addErrback: function(callback) {
       
   139         if (this._req.readyState == 4) {
       
   140             if (this._error) {
       
   141                 callback.apply(null, [this._error, this._req]);
       
   142             }
       
   143         }
       
   144         else {
       
   145             this._onFailure.push([callback, cw.utils.sliceList(arguments, 1)]);
       
   146         }
       
   147         return this;
       
   148     },
       
   149 
       
   150     success: function(result) {
       
   151         this._result = result;
       
   152         try {
       
   153             for (var i = 0; i < this._onSuccess.length; i++) {
       
   154                 var callback = this._onSuccess[i][0];
       
   155                 var args = [result, this._req];
       
   156                 jQuery.merge(args, this._onSuccess[i][1]);
       
   157                 callback.apply(null, args);
       
   158             }
       
   159         } catch(error) {
       
   160             this.error(this.xhr, null, error);
       
   161         }
       
   162     },
       
   163 
       
   164     error: function(xhr, status, error) {
       
   165         this._error = error;
       
   166         for (var i = 0; i < this._onFailure.length; i++) {
       
   167             var callback = this._onFailure[i][0];
       
   168             var args = [error, this._req];
       
   169             jQuery.merge(args, this._onFailure[i][1]);
       
   170             callback.apply(null, args);
       
   171         }
       
   172     }
       
   173 
       
   174 });
       
   175 
       
   176 /**
       
   177  * The only known usage of KEYS is in the tag cube. Once cubicweb-tag 1.7.0 is out,
   107  * The only known usage of KEYS is in the tag cube. Once cubicweb-tag 1.7.0 is out,
   178  * this current definition can be removed.
   108  * this current definition can be removed.
   179  */
   109  */
   180 var KEYS = {
   110 var KEYS = {
   181     KEY_ESC: 27,
   111     KEY_ESC: 27,