Advertisement
Guest User

BBParser

a guest
Jun 26th, 2018
454
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 3.57 KB | None | 0 0
  1. /*
  2.  *  Application: Create New BBCode Tags
  3.  *  Date: 18/05/2018
  4.  *  Version: 1.321052018
  5.  *  Copyright (c) 2018 Daemon <bestskins.forumeiros.com>
  6.  *  This work is free. You can redistribute it and/or modify it
  7.  */
  8. (function() {
  9.     BBParser = {
  10.         initialize: function() {
  11.             $(function() {
  12.                 BBParser.setupBBParser();
  13.             });
  14.         },
  15.         add: [
  16.             /*
  17.             * Note: Add a comma at the end of each new entry
  18.             * '{option}' corresponds to the optional tag title, and '{content}' correspond to the text between the tags
  19.             */
  20.  
  21.             {
  22.                 tag: 'sucesso',
  23.                 close: true,
  24.                 replacement: '<div class="notice notice-success"><h5>{option}</h5><p>{content}</p></div>'
  25.             },
  26.  
  27.             {
  28.                 tag: 'aviso',
  29.                 close: true,
  30.                 replacement: '<div class="notice notice-warn"><h5>{option}</h5><p>{content}</p></div>'
  31.             },
  32.  
  33.             {
  34.                 tag: 'info',
  35.                 close: true,
  36.                 replacement: '<div class="notice notice-info"><h5>{option}</h5><p>{content}</p></div>'
  37.             },
  38.  
  39.             {
  40.                 tag: 'alerta',
  41.                 close: true,
  42.                 replacement: '<div class="notice notice-alert"><h5>{option}</h5><p>{content}</p></div>'
  43.             },
  44.  
  45.             {
  46.                 tag: 'guest',
  47.                 close: true,
  48.                 replacement: '<div class="guest">{content}</div>',
  49.                 replace: function(option, content) {
  50.                     if (_userdata.session_logged_in < 1) {
  51.                         return 'Você precisa estar conectado ao fórum para visualizar este conteúdo.';
  52.                         return content;
  53.                     }
  54.                 }
  55.             }
  56.  
  57.             // Note: Do not add a comma at the end of the last entry
  58.         ],
  59.         // Do not change anything down
  60.         validateTag: function(a) {
  61.             if (!/^\w+$/.test(a)) throw new RangeError("You added an invalid tag: " + a);
  62.         },
  63.         replacers: function(a, b, c) {
  64.             return (a || "").replace(/{option}/g, b || "").replace(/{content}/g, c || "");
  65.         },
  66.         optionReg: /.*?=("|'|)(.*?)\1\]/,
  67.         parsedContent: function(a, b, c) {
  68.             return a.replace(c ? RegExp("(\\[" + b.tag + "[^\\]]*\\])([\\s\\S]*?)\\[/" + b.tag + "]", "g" + (b.insensitive ? "i" : "")) : RegExp("\\[" + b.tag + "[^\\]]*\\]", "g" + (b.insensitive ? "i" : "")), function(d, e, f) {
  69.                 c || (e = d);
  70.                 e = BBParser.optionReg.test(e) ? e.replace(BBParser.optionReg, "$2") : b.defaultOption;
  71.                 if("undefined" !== typeof b.replace) {
  72.                     d = c ? b.replace(e, f) : b.replace(e);
  73.                     "string" === typeof d ? c ? f = d : e = d : d;
  74.                     "object" === typeof d && (e = d.option || e, f = d.content || f);
  75.                 }
  76.                 return BBParser.replacers(b.replacement, e, f);
  77.             });
  78.         },
  79.         setupBBParser: function() {
  80.             var postContent = $(".entry-content, .blog_message");
  81.             for (var i = 0, e;(e = postContent[i++]);) {
  82.                 for (var j in BBParser.add) {
  83.                     var item = BBParser.add[j];
  84.                     // Validating tag
  85.                     BBParser.validateTag(item.tag);
  86.                     e.innerHTML = BBParser.parsedContent(e.innerHTML, item, item.close);
  87.                 }
  88.             }
  89.         }
  90.     };
  91.     BBParser.initialize()
  92. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement