Please check our Instructions to Authors and send your manuscripts to nifs.journal@gmail.com. Next issue: March 2025.
MediaWiki:Common.js/CoreObjects.js
Jump to navigation
Jump to search
Note: After publishing, you may have to bypass your browser's cache to see the changes.
- Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
- Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
- Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
- Opera: Press Ctrl-F5.
var Creator = {
createOptgroup: function(label, data) {
var g = document.createElement("optgroup");
g.label = label;
for (var i in data) {
g.appendChild( Creator.createOption(data[i], i) );
}
return g;
},
createOption: function(val, text) {
var o = document.createElement("option");
o.value = val;
o.appendChild( document.createTextNode(text) );
return o;
},
createRadios: function(name, data, checkedId) {
var w = document.createElement("div");
for (var id in data) {
w.appendChild( Creator.createRadio(
id, name, data[id][0], data[id][1], checkedId == id) );
}
return w;
},
createRadio: function(id, name, value, label, checked) {
var attrs = { "type" : "radio", "id" : id, "name" : name, "value" : value };
if (checked) attrs["checked"] = "checked";
var r = Creator.createElement("input", attrs);
var l = Creator.createLabel(id, label);
return Creator.createElement("div", {}, [r, l]);
},
createSubmit: function(value) {
var attrs = { "type" : "submit", "value" : value };
return Creator.createElement("input", attrs);
},
createButton: function(value) {
return Creator.createElement("button", {}, value);
},
createAnchor: function(url, text, title) {
var attrs = { "href" : url, "title" : title };
return Creator.createElement("a", attrs, text);
},
createImage: function(url, alt, title) {
var attrs = { "src" : url, "alt" : alt, "title" : title };
return Creator.createElement("img", attrs);
},
createHiddenField: function(name, value) {
var attrs = { "type" : "hidden", "name" : name, "value" : value };
return Creator.createElement("input", attrs);
},
createTextarea: function(id, name, value, rows, cols) {
var attrs = { "id" : id, "name" : name || id,
"rows" : rows || 3, "cols" : cols || 40 };
return Creator.createElement("textarea", attrs, value || "");
},
createLabel: function(htmlFor, text) {
var attrs = { "for" : htmlFor };
return Creator.createElement("label", attrs, text);
},
createElement: function(node, attrs, content) {
var e = document.createElement(node);
for (var attr in attrs) {
e.setAttribute(attr, attrs[attr]);
}
if (content instanceof Array) {
Creator.appendChildrenTo(e, content);
} else {
Creator.appendChildTo(e, content);
}
return e;
},
createInternUrl: function(page, action, args) {
page = encodeURI(page.replace(/ /g, "_"));
if ( typeof(action) == "undefined" || action === null ) {
return wgArticlePath.replace("$1", page);
}
var url = wgScript + "?title="+ page +"&action="+ action;
if ( typeof(args) == "undefined" || args === null ) {
return url;
}
for (var arg in args) {
url += "&" + arg + "=" + args[arg];
}
return url;
},
appendChildrenTo: function(parent, children) {
for (var i = 0; i < children.length; i++) {
parent = Creator.appendChildTo(parent, children[i]);
}
return parent;
},
appendChildTo: function(parent, child) {
if ( typeof(child) == "string" ) {
parent.appendChild( document.createTextNode(child) );
} else if ( child instanceof HTMLElement ) {
parent.appendChild(child);
}
return parent;
}
};
// from http://www.quirksmode.org/js/cookies.html
// escape(), unescape() methods added
var Cookie = {
create: function(name, value, days) {
var expires;
if (days) {
var date = new Date();
date.setTime(date.getTime() + (days*24*60*60*1000));
expires = "; expires=" + date.toGMTString();
} else {
expires = "";
}
document.cookie = Cookie.escape(name) + "=" + Cookie.escape(value)
+ expires + "; path=/";
},
read: function(name) {
var nameEQ = Cookie.escape(name) + "=";
var ca = document.cookie.split(';');
for (var i = 0; i < ca.length; i++) {
var c = ca[i];
while (c.charAt(0)==' ') {
c = c.substring(1, c.length);
}
if (c.indexOf(nameEQ) === 0) {
return Cookie.unescape(c.substring(nameEQ.length, c.length));
}
}
return null;
},
erase: function(name) {
Cookie.create(name, "", -1);
},
escape: function(v) {
return encodeURIComponent(v);
},
unescape: function(v) {
return decodeURIComponent(v);
}
};
var _lang_messages = {};
var _debug_lang = false;
function MessageLanguage() {
this.lang = DEFAULT_USER_LANGUAGE;
this.messages = new Object();
this.prefix = "";
this.addMessages = function(messages, code, prefix) {
if ( typeof this.messages[code] == "undefined" ) {
this.messages[code] = new Object();
}
var p = typeof prefix == "string" ? prefix : "";
for (var key in messages) {
if ( typeof key == "string" ) {
this.messages[code][p + key] = messages[key];
}
}
};
this.setLanguage = function(langCode) {
this.lang = langCode;
this.importMessages( this.lang );
};
this.setPrefix = function(prefix) {
this.prefix = prefix;
};
this.msg = function(key) {
key = this.prefix + key;
var msg = this.messages[this.lang] && this.messages[this.lang][key];
if ( typeof msg == "undefined" ) {
if ( _debug_lang ) alert(key + " го няма на "+this.lang);
msg = this.messages[FALLBACK_USER_LANGUAGE]
&& this.messages[FALLBACK_USER_LANGUAGE][key];
}
if ( typeof msg == "undefined" ) {
return "{"+ key +"}";
}
for (var i = 1; i < arguments.length; i++) {
msg = msg.replace("$"+i, arguments[i]);
}
return msg;
};
this.importMessages = function(lang) {
importScript("MediaWiki:Messages/" + lang + ".js");
};
}
var gLang = new MessageLanguage();
// import message files
gLang.setLanguage( wgUserLanguage );
var mainLangs = [ DEFAULT_USER_LANGUAGE, FALLBACK_USER_LANGUAGE ];
if ( ! inArray( wgUserLanguage, mainLangs ) ) {
gLang.importMessages( FALLBACK_USER_LANGUAGE );
}
// add messages on load
addOnloadHook( function() {
if ( typeof _lang_messages[ wgUserLanguage ] == "object" ) {
gLang.addMessages( _lang_messages[ wgUserLanguage ], wgUserLanguage );
}
if ( typeof _lang_messages[ FALLBACK_USER_LANGUAGE ] == "object" ) {
if ( ! inArray( wgUserLanguage, mainLangs ) ) {
gLang.addMessages( _lang_messages[ FALLBACK_USER_LANGUAGE ],
FALLBACK_USER_LANGUAGE );
}
}
});