Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Application: Create New BBCode Tags
- * Date: 18/05/2018
- * Version: 1.321052018
- * Copyright (c) 2018 Daemon <bestskins.forumeiros.com>
- * This work is free. You can redistribute it and/or modify it
- */
- (function() {
- BBParser = {
- initialize: function() {
- $(function() {
- BBParser.setupBBParser();
- });
- },
- add: [
- /*
- * Note: Add a comma at the end of each new entry
- * '{option}' corresponds to the optional tag title, and '{content}' correspond to the text between the tags
- */
- {
- tag: 'sucesso',
- close: true,
- replacement: '<div class="notice notice-success"><h5>{option}</h5><p>{content}</p></div>'
- },
- {
- tag: 'aviso',
- close: true,
- replacement: '<div class="notice notice-warn"><h5>{option}</h5><p>{content}</p></div>'
- },
- {
- tag: 'info',
- close: true,
- replacement: '<div class="notice notice-info"><h5>{option}</h5><p>{content}</p></div>'
- },
- {
- tag: 'alerta',
- close: true,
- replacement: '<div class="notice notice-alert"><h5>{option}</h5><p>{content}</p></div>'
- },
- {
- tag: 'guest',
- close: true,
- replacement: '<div class="guest">{content}</div>',
- replace: function(option, content) {
- if (_userdata.session_logged_in < 1) {
- return 'Você precisa estar conectado ao fórum para visualizar este conteúdo.';
- return content;
- }
- }
- }
- // Note: Do not add a comma at the end of the last entry
- ],
- // Do not change anything down
- validateTag: function(a) {
- if (!/^\w+$/.test(a)) throw new RangeError("You added an invalid tag: " + a);
- },
- replacers: function(a, b, c) {
- return (a || "").replace(/{option}/g, b || "").replace(/{content}/g, c || "");
- },
- optionReg: /.*?=("|'|)(.*?)\1\]/,
- parsedContent: function(a, b, c) {
- 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) {
- c || (e = d);
- e = BBParser.optionReg.test(e) ? e.replace(BBParser.optionReg, "$2") : b.defaultOption;
- if("undefined" !== typeof b.replace) {
- d = c ? b.replace(e, f) : b.replace(e);
- "string" === typeof d ? c ? f = d : e = d : d;
- "object" === typeof d && (e = d.option || e, f = d.content || f);
- }
- return BBParser.replacers(b.replacement, e, f);
- });
- },
- setupBBParser: function() {
- var postContent = $(".entry-content, .blog_message");
- for (var i = 0, e;(e = postContent[i++]);) {
- for (var j in BBParser.add) {
- var item = BBParser.add[j];
- // Validating tag
- BBParser.validateTag(item.tag);
- e.innerHTML = BBParser.parsedContent(e.innerHTML, item, item.close);
- }
- }
- }
- };
- BBParser.initialize()
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement