Advertisement
Guest User

Untitled

a guest
Dec 13th, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. <script type="text/javascript">
  3. var texttools = {
  4.         "[b]":       { "pattern": "[b]%s[/b]", "accesskey": "b" },
  5.         "[u]": { "pattern": "[u]%s[/u]", "accesskey": "u" },
  6.         "[i]":     { "pattern": "[i]%s[/i]", "accesskey": "i" },
  7.         "[s]":     { "pattern": "[s]%s[/s]", "accesskey": "s" },
  8.         "img":        { "pattern": "[img]%s[/img]", "accesskey": "k" },
  9.         "kolor":     { "pattern": "[color=%p]%s[/color]", "accesskey": "c", "prompt": "Wpisz nazwę koloru (red, #ff6, #ccff33, itp.)" },
  10.         "url":        { "pattern": "[url=%p]%s[/url]", "accesskey": "l", "prompt": "Wpisz adres URL (lub pozostaw puste jeśli go zaznaczyłeś)", "default": "http://" },
  11.         "cytat":      { "pattern": "[quote=%p]%s[/quote]", "accesskey": "c", "prompt": "Wpisz nick osoby, której tekst cytujesz (opcjonalne)" },
  12.         "kod":       { "pattern": "[code]%s[/code]", "accesskey": "o" },
  13.         "html":       { "pattern": "[html]%s[/html]", "accesskey": "h" },
  14.         "YT":       { "pattern": "[youtube]%s[/youtube]", "accesskey": "y" },
  15.     };
  16.     var userjs = "j2userjs125668";
  17.     var textarea = document.getElementsByTagName("textarea");
  18.     var form = null;
  19.     var submittedButt = null;
  20.     var operaAccessKeyHack = {};
  21.     for (var ita=0; ita<textarea.length; ita++) {
  22.         if (textarea[ita].getAttribute("name") == "req_message") {
  23.             textarea = textarea[ita];
  24.             form = getParent(textarea, "form");
  25.             tt = document.createElement("div");
  26.             tt.style.lineHeight= "2em";
  27. tt.id= "bbcode";
  28.             tt.appendChild(document.createTextNode("BBCode: "));
  29.             if (typeof opera != "undefined" && operaAccessKeyHack) {
  30.                 textarea.addEventListener("keypress", function(e) { if (e.altKey && e.ctrlKey && (butt = operaAccessKeyHack[e.keyCode])) { submittedButt = butt; butt.click(); } }, false);
  31.                 form.addEventListener("submit", function(e) {
  32.                     if (e.shiftKey || e.ctrlKey) {
  33.                         setTimeout(function() {
  34.                             submittedButt.removeAttribute("disabled");
  35.                             var click = document.createEvent("MouseEvents");
  36.                             click.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
  37.                             submittedButt.dispatchEvent(click);
  38.                         }, 100);
  39.                         e.cancelBubble = true;
  40.                         if (e.stopPropagation) e.stopPropagation();
  41.                         e.preventDefault();
  42.                         return false;
  43.                     } else {
  44.                         submittedButt = null;
  45.                         return true;
  46.                     }
  47.                 }, false);
  48.             }
  49.             for (tool in texttools) {
  50.                 if (texttools.hasOwnProperty(tool)) {
  51.                     tt.appendChild(createBBCodeButt(tool, function(e) {
  52.                         textarea.focus();
  53.                         var osel = [textarea.value.substring(textarea.selectionStart, textarea.selectionEnd), textarea.selectionStart, textarea.selectionEnd];
  54.                         var tool = this.textContent;
  55.                         var nsel = texttools[tool]["pattern"].replace(/%s/g, osel[0]);
  56.                         var p = null;
  57.                         if (texttools[tool]["pattern"].indexOf("=%p") != -1) {
  58.                             p = prompt(texttools[tool]["prompt"]?texttools[tool]["prompt"]:"Type parameter (%p) for \u201c"+nsel+"\u201d\u00a0:", texttools[tool]["default"]?texttools[tool]["default"]:"");
  59.                             nsel = nsel.replace(/=%p/g, p?"="+p:"");
  60.                         }
  61.                         textarea.value = textarea.value.substr(0, osel[1]) + nsel + textarea.value.substr(osel[2]);
  62.                         if (osel[1] != osel[2]) {
  63.                             textarea.selectionStart = osel[1];
  64.                             textarea.selectionEnd = osel[1] + nsel.length;
  65.                         } else {
  66.                             textarea.selectionStart = osel[1] + nsel.indexOf("[", 1);
  67.                             textarea.selectionEnd = textarea.selectionStart;
  68.                         }
  69.                     }, texttools[tool]["pattern"], texttools[tool]["accesskey"]));
  70.                     tt.appendChild(document.createTextNode(" "));
  71.                 }
  72.             }
  73.             textarea.parentNode.insertBefore(tt, textarea);
  74.             if (form != null) {
  75.                 var action = form.getAttribute("action");
  76.                 var tid = action.match(/^post\.php\?tid=([0-9]+)$/i);
  77.                 if (tid) {
  78.                     tid = tid[1];
  79.                     var stuff = document.createElement("span");
  80.                     form.setAttribute("action", "post.php?action=post&tid="+tid);
  81.                     form.setAttribute("id", "post");
  82.                     var preview = stuff.appendChild(createInput("submit", "preview", "Preview"));
  83.                     preview.setAttribute("accesskey", "p");
  84.                     var lbl = stuff.appendChild(document.createElement("label"));
  85.                     lbl.style.display = "inline";
  86.                     lbl.appendChild(createInput("checkbox", "subscribe", "1"));
  87.                     lbl.appendChild(document.createTextNode("Subskrybuj ten temat"));
  88.                     var ou = form.getElementsByTagName("p");
  89.                     if (ou.length>0) { ou = ou[ou.length-1]; }
  90.                     else { ou = form; }
  91.                     ou.appendChild(stuff);
  92.                 }
  93.                 var subs = form.getElementsByTagName("input");
  94.                 for (var sb=0; sb<subs.length; sb++) {/*opens in new window because of shift:/*/
  95.                     if (subs[sb].getAttribute("type") == "submit" && (accesskey = subs[sb].getAttribute("accesskey"))) {
  96.                         operaAccessKeyHack[accesskey.toLowerCase().charCodeAt(0)] = subs[sb];
  97.                         subs[sb].setAttribute("title", akey(accesskey));
  98.                     }
  99.                 }
  100.             }
  101.             break;
  102.         }
  103.     }
  104.     function akey(k) {
  105.         var t = "ALT+"+k.toUpperCase();
  106.         if (navigator.userAgent.match(/firefox/i)) { t = "ALT+SHIFT+"+k.toUpperCase(); }
  107.         else if (typeof opera != "undefined") { t = "CTRL+" + t; }
  108.         return t;
  109.     }
  110.     function getParent(obj, tag) {
  111.         var cur = obj;
  112.         if (cur.parentNode) {
  113.             cur = cur.parentNode;
  114.             if (cur.tagName == tag.toUpperCase()) {
  115.                 return cur;
  116.             } else {
  117.                 return getParent(cur, tag);
  118.             }
  119.         } else {
  120.             return null;
  121.         }
  122.     }
  123.     function createInput(type, name, value) {
  124.         var input = document.createElement("input");
  125.         input.setAttribute("type", type);
  126.         input.setAttribute("name", name);
  127.         input.setAttribute("value", value);
  128.         return input;
  129.     }
  130.     function createBBCodeButt(text, link, title, accesskey) {
  131.         var truc = document.createElement("span");
  132.         truc.style.whiteSpace = "nowrap";
  133.         truc.appendChild(document.createTextNode("\u00a0"));
  134.         var a = truc.appendChild(document.createElement("a"));
  135.         if (link && typeof link == "string") {
  136.             a.setAttribute("href", link);
  137.         }
  138.         else {
  139.             if (link && typeof link == "function") {
  140.                 a.addEventListener("click", link, false);
  141.             }
  142.             a.style.cursor = "pointer";
  143.         }
  144.         a.style.color = "blue";
  145.         a.style.background = "#F5F5F5";
  146.         a.style.padding = "2px 4px";
  147.         a.style.border = "1px outset grey";
  148.         a.style.textTransform = "uppercase";
  149.         if (title) { a.setAttribute("title", title); }
  150.         if (accesskey) {
  151.             a.setAttribute("accesskey", accesskey);
  152.             var key = akey(accesskey);
  153.             if (navigator.userAgent.match(/firefox/i)) { key += ":"; }
  154.             a.setAttribute("title", key+" \n" + a.getAttribute("title"));
  155.             if (typeof opera != "undefined" && operaAccessKeyHack) {
  156.                 operaAccessKeyHack[accesskey.toLowerCase().charCodeAt(0)] = a;
  157.             }
  158.         }
  159.         if (accesskey) {
  160.             var kpos = text.indexOf(accesskey);
  161.             a.appendChild(document.createTextNode(text.substr(0,kpos)));
  162.             a.appendChild(document.createElement("strong")).appendChild(document.createTextNode(text.charAt(kpos)));
  163.             a.appendChild(document.createTextNode(text.substr(kpos+1)));
  164.         }
  165.         else { a.appendChild(document.createTextNode(text)); }
  166.         return truc;
  167.     }
  168. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement