-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathed.util.js
91 lines (74 loc) · 1.89 KB
/
ed.util.js
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
EUtil = {
getParameter : function (name) {
return mw.util.getParamValue(name);
},
getSection : function () {
return document.location.hash.replace('#', '');
},
isEditingSection : function () {
return $('input[name="wpSection"]').val() !== '';
},
getActiveLangCode : function () {
return EUi.activeLangCode;
},
getActiveLangId : function () {
return EUi.activeLangId;
},
executeFn : function (functionName, context) { /*, args */
var args = Array.prototype.slice.call(arguments, 2),
namespaces = functionName.split('.'),
func = namespaces.pop(),
i;
for (i = 0; i < namespaces.length; i += 1) {
context = context[namespaces[i]];
}
return context[func].apply(context, args);
},
focusArea : function (subs, atEnd) {
var elem = $('#ed_' + EUtil.getActiveLangId() + '_' + subs),
len;
elem.focus();
if (atEnd && elem[0]) {
if (elem[0].setSelectionRange) {
len = elem.val().length * 2;
elem[0].setSelectionRange(len, len);
} else {
elem.val(elem.val());
}
elem[0].scrollTop = 999999;
}
},
isEmpty : function (obj) {
var prop;
for (prop in obj) {
if (obj.hasOwnProperty(prop)) {
return false;
}
}
return true;
},
escapeHTML : function (html) {
return html.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>');
},
escapeJS : function (js) {
return js.replace(/\'/g, "\\'");
},
getUrl : function (langcode, page) {
return 'http://' + langcode + '.wiktionary.org/wiki/' + mw.util.wikiUrlencode(page);
}
};
$.fn.reverse = [].reverse;
if (!Array.prototype.indexOf) {
Array.prototype.indexOf = function (obj, start) {
var i, j;
for (i = (start || 0), j = this.length; i < j; i += 1) {
if (this[i] === obj) { return i; }
}
return -1;
};
}
String.prototype.endsWith = function (suffix) {
return this.indexOf(suffix, this.length - suffix.length) !== -1;
};
window.EFilesLoaded++;
window.ETryInit();