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/ */ //  situvn = { 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"); ts.each(function(i, e) {               var t = $(e), to = t.find(".toggle"), st = !0;                to.click(function { var tr = t.find("tr"); tr.each(function(i, e) {                       if (i === 0) return;                        $(e).css({display:st ? "none" : ""});                   }); st = !st; to.text(st ? "Ẩn" : "Hiện"); });           });        };        $(document).bind("DOMNodeInserted", function(e) {toggle(e.srcElement);}); toggle(document); } }

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