viewing paste Unknown #6648 | Javascript

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
/* == IMG */
myParser.addRule({
    appliesToHTML:  function(el){return el.tagName.toLowerCase() == "img" ;},
    toBBContent:    function(el){return "[img="+el.src+"]";},
    appliesToBB:    function(el){return el.data.tag.toLowerCase() == "img"; },
    toHTMLContent:  function(el){ if ( el.data.params.img == undefined ) { return ''; } var _src = ( ! el.data.params.img.match(/^http/) ) ? 'http://' + el.data.params.img : el.data.params.img; return "<img src=\"" + _src + "\">"; }
});
 
/* URL */
myParser.addRule( { appliesToHTML:function(el) { return (el.tagName.toLowerCase() == "a" && typeof el.href !== "undefined");},
                    toBBStart:    function(el) { var _href = el.readAttribute('href'); return "[url="+ ( el.href.indexOf(" " ) >= 0 ? "\"" + _href + "\"" : _href ) +"]"; },
                    toBBEnd:      function(el) { return "[/url]"; },
                    appliesToBB:  function(el) { return el.data.tag.toLowerCase() == "url"; },
                    toHTMLStart:  function(el) { return '<a href="' + ( el.data.params.url ? el.data.params.url : el.children[0] ) + '">'; },
                    toHTMLEnd:    '</a>'
} );
 
Viewed 1044 times, submitted by Guest.