summaryrefslogtreecommitdiff
path: root/lib/scripts/compatibility.js
blob: ea52153c54d9a5b9d65bab12cbb992f7aa4289cc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
/**
 * Mark a JavaScript function as deprecated
 *
 * This will print a warning to the JavaScript console (if available) in
 * Firebug and Chrome and a stack trace (if available) to easily locate the
 * problematic function call.
 *
 * @param msg optional message to print
 */
function DEPRECATED(msg){
    if(!window.console) return;
    if(!msg) msg = '';

    var func;
    if(arguments.callee) func = arguments.callee.caller.name;
    if(func) func = ' '+func+'()';
    var line = 'DEPRECATED function call'+func+'. '+msg;

    if(console.warn){
        console.warn(line);
    }else{
        console.log(line);
    }

    if(console.trace) console.trace();
}

/**
 * Construct a wrapper function for deprecated function names
 *
 * This function returns a wrapper function which just calls DEPRECATED
 * and the new function.
 *
 * @param func    The new function
 * @param context Optional; The context (`this`) of the call
 */
function DEPRECATED_WRAP(func, context) {
    return function () {
        DEPRECATED();
        return func.apply(context || this, arguments);
    };
}

/**
 * Handy shortcut to document.getElementById
 *
 * This function was taken from the prototype library
 *
 * @link http://prototype.conio.net/
 */
function $() {
    DEPRECATED('Please use the JQuery() function instead.');

    var elements = new Array();

    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        if (typeof element == 'string')
            element = document.getElementById(element);

        if (arguments.length == 1)
            return element;

        elements.push(element);
    }

    return elements;
}




var index = {
    throbber_delay: dw_index.throbber_delay,
    toggle: DEPRECATED_WRAP(dw_index.toggle, dw_index),
    treeattach: DEPRECATED_WRAP(dw_index.treeattach, dw_index)
};

var ajax_quicksearch = {
    init: DEPRECATED_WRAP(dw_qsearch.init, dw_qsearch),
    clear_results: DEPRECATED_WRAP(dw_qsearch.clear_results, dw_qsearch),
    onCompletion: DEPRECATED_WRAP(dw_qsearch.onCompletion, dw_qsearch)
};

var linkwiz = {
    init: DEPRECATED_WRAP(dw_linkwiz.init, dw_linkwiz),
    onEntry: DEPRECATED_WRAP(dw_linkwiz.onEntry, dw_linkwiz),
    getResult: DEPRECATED_WRAP(dw_linkwiz.getResult, dw_linkwiz),
    select: DEPRECATED_WRAP(dw_linkwiz.select, dw_linkwiz),
    deselect: DEPRECATED_WRAP(dw_linkwiz.deselect, dw_linkwiz),
    onResultClick: DEPRECATED_WRAP(dw_linkwiz.onResultClick, dw_linkwiz),
    resultClick: DEPRECATED_WRAP(dw_linkwiz.resultClick, dw_linkwiz),
    insertLink: DEPRECATED_WRAP(dw_linkwiz.insertLink, dw_linkwiz),
    autocomplete: DEPRECATED_WRAP(dw_linkwiz.autocomplete, dw_linkwiz),
    autocomplete_exec: DEPRECATED_WRAP(dw_linkwiz.autocomplete_exec, dw_linkwiz),
    show: DEPRECATED_WRAP(dw_linkwiz.show, dw_linkwiz),
    hide: DEPRECATED_WRAP(dw_linkwiz.hide, dw_linkwiz),
    toggle: DEPRECATED_WRAP(dw_linkwiz.toggle, dw_linkwiz)
};

var locktimer = {
    init: DEPRECATED_WRAP(dw_locktimer.init, dw_locktimer),
    reset: DEPRECATED_WRAP(dw_locktimer.reset, dw_locktimer),
    warning: DEPRECATED_WRAP(dw_locktimer.warning, dw_locktimer),
    clear: DEPRECATED_WRAP(dw_locktimer.clear, dw_locktimer),
    refresh: DEPRECATED_WRAP(dw_locktimer.refresh, dw_locktimer),
    refreshed: DEPRECATED_WRAP(dw_locktimer.refreshed, dw_locktimer)
};

var media_manager = {
    // treeattach, selectorattach, confirmattach are munched together into
    // dw_mediamanager.init
    attachoptions: DEPRECATED_WRAP(dw_mediamanager.attachoptions, dw_mediamanager),
    togglekeepopen: function (event, cb) {
        DEPRECATED('Use dw_mediamanager.toggleOption instead');
        return dw_mediamanager.toggleOption.call(cb, 'keepopen');
    },
    togglehide: function (event, cb) {
        DEPRECATED('Use dw_mediamanager.toggleOption instead');
        return dw_mediamanager.toggleOption.call(cb, 'hide');
    },
    updatehide: DEPRECATED_WRAP(dw_mediamanager.updatehide, dw_mediamanager),
    select: function (event, link) {
        DEPRECATED('Use dw_mediamanager.select instead');
        return dw_mediamanager.select.call(link, event);
    },
    initpopup: DEPRECATED_WRAP(dw_mediamanager.initpopup, dw_mediamanager),
    insert: DEPRECATED_WRAP(dw_mediamanager.insert, dw_mediamanager),
    list: function (event, link) {
        DEPRECATED('Use dw_mediamanager.list instead');
        return dw_mediamanager.list.call(link, event);
    },
    // toggle is handled by dw_tree
    suggest: DEPRECATED_WRAP(dw_mediamanager.suggest, dw_mediamanager),
    initFlashUpload: DEPRECATED_WRAP(dw_mediamanager.initFlashUpload, dw_mediamanager),
    closePopup: function () {
        DEPRECATED();
        dw_mediamanager.$popup.dialog('close');
    },
    setalign: function (event, cb) {
        DEPRECATED('Use dw_mediamanager.setOpt instead');
        return dw_mediamanager.setOpt.call(this, 'align', event);
    },
    setlink: function (event, cb) {
        DEPRECATED('Use dw_mediamanager.setOpt instead');
        return dw_mediamanager.setOpt.call(this, 'link', event);
    },
    setsize: function (event, cb) {
        DEPRECATED('Use dw_mediamanager.setOpt instead');
        return dw_mediamanager.setOpt.call(this, 'size', event);
    },
    outSet: function (id) {
        DEPRECATED();
        return jQuery(id).removeClass('selected');
    },
    inSet: function (id) {
        DEPRECATED();
        return jQuery(id).addClass('selected');
    }
};

initSizeCtl = DEPRECATED_WRAP(dw_editor.initSizeCtl);
sizeCtl = DEPRECATED_WRAP(dw_editor.sizeCtl);
toggleWrap = DEPRECATED_WRAP(dw_editor.toggleWrap);
setWrap = DEPRECATED_WRAP(dw_editor.setWrap);

function findPosX(object){
    DEPRECATED('Use jQuery.position() instead');
    return jQuery(object).position().left;
}

function findPosY(object){
    DEPRECATED('Use jQuery.position() instead');
    return jQuery(object).position().top;
}

function getElementsByClass(searchClass,node,tag){
    DEPRECATED('Use jQuery() instead');
    if(node == null) node = document;
    if(typeof tag === 'undefined') tag = '';
    return jQuery(node).find(tag+'.'+searchClass).toArray();
}

function prependChild(parent,element) {
    DEPRECATED('Use jQuery.prepend() instead');
    jQuery(parent).prepend(element);
}

function addEvent(element, type, handler) {
    DEPRECATED('Use jQuery.bind() instead. Note that jQuery’s behaviour' +
               ' when a handler returns false differs from addEvent’s');
    jQuery(element).bind(type,{},function (e) {
        // returning false in an addEvent event handler did not prevent
        // bubbling but just canceled handlers on this node and prevented
        // default behavior, so wrap the handler call and mimic that behavior.
        //
        // Refer to jQuery.event.handle().
        var ret = handler.apply(this, Array.prototype.slice.call(arguments, 0));
        if (typeof ret !== 'undefined') {
            if ( ret !== false ) {
                return ret;
            }
            // What jQuery does.
            e.result = ret;
            e.preventDefault();
            // Not what jQuery does. This would be: event.stopPropagation();
            // Hack it so that immediate propagation (other event handlers on
            // this element) appears stopped without stopping the actual
            // propagation (bubbling)
            e.isImmediatePropagationStopped = function () { return true; };
        }
    });
}

function removeEvent(element, type, handler) {
    DEPRECATED('Use jQuery.unbind() instead.');
    jQuery(element).unbind(type,handler);
}

function addInitEvent(func) {
    DEPRECATED('Use jQuery(<function>) instead');
    jQuery(func);
}


function jsEscape(text){
    DEPRECATED('Insert text through jQuery.text() instead of escaping on your own');
    var re=new RegExp("\\\\","g");
    text=text.replace(re,"\\\\");
    re=new RegExp("'","g");
    text=text.replace(re,"\\'");
    re=new RegExp('"',"g");
    text=text.replace(re,'&quot;');
    re=new RegExp("\\\\\\\\n","g");
    text=text.replace(re,"\\n");
    return text;
}

/**
 * Simple function to check if a global var is defined
 *
 * @author Kae Verens
 * @link http://verens.com/archives/2005/07/25/isset-for-javascript/#comment-2835
 */
function isset(varname){
    DEPRECATED("Use `typeof var !== 'undefined'` instead");
    return(typeof(window[varname])!='undefined');
}

/**
 * Checks if property is undefined
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isUndefined (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `typeof var === 'undefined'` instead");
    return (typeof prop == 'undefined');
}

/**
 * Checks if property is function
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isFunction (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `typeof var === 'function'` instead");
    return (typeof prop == 'function');
}
/**
 * Checks if property is string
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isString (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `typeof var === 'string'` instead");
    return (typeof prop == 'string');
}

/**
 * Checks if property is number
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isNumber (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `typeof var === 'number'` instead");
    return (typeof prop == 'number');
}

/**
 * Checks if property is the calculable number
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isNumeric (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `typeof var === 'number' && !isNaN(var) && isFinite(var)` instead");
    return isNumber(prop)&&!isNaN(prop)&&isFinite(prop);
}

/**
 * Checks if property is array
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isArray (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `var instanceof Array` instead");
    return (prop instanceof Array);
}

/**
 *  Checks if property is regexp
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isRegExp (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `var instanceof RegExp` instead");
    return (prop instanceof RegExp);
}

/**
 * Checks if property is a boolean value
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isBoolean (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `typeof var === 'boolean'` instead");
    return ('boolean' == typeof prop);
}

/**
 * Checks if property is a scalar value (value that could be used as the hash key)
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isScalar (prop /* :Object */) /* :Boolean */ {
    DEPRECATED("Use `typeof var === 'string' || (typeof var === 'number' &&" +
               " !isNaN(var) && isFinite(var))` instead");
    return isNumeric(prop)||isString(prop);
}

/**
 * Checks if property is empty
 *
 * @param {Object} prop value to check
 * @return {Boolean} true if matched
 * @scope public
 * @author Ilya Lebedev <ilya@lebedev.net>
 */
function isEmpty (prop /* :Object */) /* :Boolean */ {
    DEPRECATED();
    var i;
    if (isBoolean(prop)) {
        return false;
    } else if (isRegExp(prop) && new RegExp("").toString() == prop.toString()) {
        return true;
    } else if (isString(prop) || isNumber(prop)) {
        return !prop;
    } else if (Boolean(prop) && false != prop) {
        for (i in prop) {
            if(prop.hasOwnProperty(i)) {
                return false;
            }
        }
    }
    return true;
}

/**
 * Get the computed style of a node.
 *
 * @link https://acidmartin.wordpress.com/2008/08/26/style-get-any-css-property-value-of-an-object/
 * @link http://svn.dojotoolkit.org/src/dojo/trunk/_base/html.js
 */
function gcs(node){
    DEPRECATED('Use jQuery(node).style() instead');
    if(node.currentStyle){
        return node.currentStyle;
    }else{
        return node.ownerDocument.defaultView.getComputedStyle(node, null);
    }
}

/**
 * Until 2011-05-25 "Rincewind", a code intended to fix some Safari issue
 * always declared the global _timer. plugin:sortablejs relies on _timer
 * being declared.
 */
var _timer;