User:SITUVN/jvs

/** * SITUVN's functions * http://community.wikia.com/wiki/User:SITUVN/jvs * SITUVN' JavaScript * @author: SITUVN (http://community.wikia.com/wiki/User:SITUVN) * @License: CC-BY-SA - http://creativecommons.org/licenses/by-sa/3.0/ */ //  importScriptPage('User:SITUVN/jvs/lang', 'c'); var situvn = { strings: { en: { SHOW: "show", HIDE: "hide" },       vi: { SHOW: "hiện", HIDE: "ẩn" }   },    languageCode: mw.config.get("wgPageContentLanguage"), loadLanguage: function (d) { if (!d && typeof situvnStrings === "object") d = situvnStrings; if (typeof d === "object") { if (typeof situvn.strings !== "object") situvn.strings = {}; for (var p in d) { if (typeof d[p] === "object") { if (typeof situvn.strings[p] !== "object") situvn.strings[p] = {}; for (var pp in d[p]) { situvn.strings[p][pp] = d[p][pp]; }               }            }        }        situvn.lang = situvn.strings[situvn.languageCode]; if (!situvn.lang) situvn.lang = strings["en"]; },   allowScript: false, htmlTag : "html-tag-", loopWikiParameter : function(text, from, to, search, join) { if (!text) return null; if (!from) from = 0; if (!to) to = 10; if (!search) search = "XYZYX"; if (!join) join = "\r\n"; if (!String.prototype.replaceAll) { String.prototype.replaceAll = function(a, b) { var r = this; while(r.search(a) != -1) { r = r.replace(a, b); }               return r;            } }       a = ""; for (i = from; i <= to; i++) { a += text.replaceAll(search, i) + join; }       return a;    }, getFileDirectLink : function(name, server) { var r, url = '/index.php?action=ajax&rs=EditPageLayoutAjax&title='; if(typeof server == "string"){ if(server.indexOf('://') == -1) url = 'http://' + server + '.wikia.com' + url; else url = server + url; }       $.ajax({            url: url,            async: false,            data: "page=SpecialCustomEditPage&method=preview&summary=&content=[[Media:" + name + "]]&section=",            cache: false,            contentType: 'application/x-www-form-urlencoded; charset=UTF-8',            processData: true,            type: 'POST',            success: function(data){                r = $(data.html).find("a.internal").attr("href");            }        }); return r;   }, replaceDataTag : function (query, tag) { $(query).each(function {           var This = $(this),            e = $(document.createElement(tag));            for (i in This.data) {                e.attr(i, This.data(i));            }            This.replaceWith(e);        }); },   replaceDataTagAll : function(pre) { if (!pre) return; var tag; while((tag = $("div[class^='" + pre + "']").first).length) { try { var cls = tag.attr("class"); var tagName = cls.substring(pre.length); if (!situvn.allowScript && tagName.toLowerCase == "script") return; var e = $(document.createElement(tagName)); for (i in tag.data) { e.attr(i, tag.data(i)); }               e.html(tag.html); tag.replaceWith(e); } catch (e) { }       }    },    toggleNavbox : function { var toggle = function(e) { var ts = $(e).find("table.navigate-box .toggle"); var tgl = function(to) { to = $(to); var tr = to.parents("table.navigate-box").find("tr"); var d = to.data("show"); var st = 0; if (d) { var x = parseInt(d); if (isNaN(x)) { d = d.toLowerCase; x = d == "true" ? 1 : 0;                   }                    st = x ? 1 : 0;               }                tr.each(function(i, e) {                    e = $(e);                    if (i === 0 || e.find("th").length > 0) return;                    e.css({display: st ? "" : "none"});               }); st = st ? 0 : 1;               to.text(st ? situvn.lang.SHOW : situvn.lang.HIDE); to.data("show", st); };           ts.each(function(i, e) {                var to = $(e);                if (to.data("done") === "1") return;                to.click(function { tgl(this); });               tgl(to);                to.data("done", "1");            }); };       $(document).bind("DOMNodeInserted", function(e) {toggle(e.srcElement);}); toggle(document); } }; situvn.loadLanguage;

$(document).ready(function {   situvn.replaceDataTagAll(situvn.htmlTag);    situvn.toggleNavbox; });