This is a Hitskin.com skin preview
Install the skin • Return to the skin page
[FOORUM] Hashtag ja mention süsteem
Lehekülg 1, lehekülgi kokku 1 • Share
- Tonight
- Liitus : 19/02/2012
Postitusi : 18000
Twitteri-taoline hashtag ning mention süsteem on veebimaailmas väga populaarne ning paljud foorumiomanikud soovivad seda ka enda foorumisse. Seepärast otsustasin teiega jagada koode, mis mulle kunagi lahkelt valmistati.
Loo uus Javascript ning märgi In all the pages.
- Kood:
$(function(){
var p = $('.post .content'); //get the posts
for(var i = 0, post; (post = p[ i++ ]); ) {
var codes = post.getElementsByTagName('code'), store = [];
for(var j = 0, c; (c = codes[j++]); ) {
store.push(c.innerHTML);
c.innerHTML = '';
}
post.innerHTML = LGBB.parse( post.innerHTML ); //swap the innerhtml of the post, for the LGBB parsed innerhtml.
for(var s, j = 0; (s = store[j]); ) codes[j++].innerHTML = s;
}
});
Nüüd asume süsteemi juurde. Loo taaskord uus Javascript ning märgi In all the pages.
- Kood:
(function(){"LGBB, a Javascript BBCode parser and API. Copyright \u00a9 by AvacWeb 2011-2013. All Rights Reserved. Use of this script is not allowed without this entire copyright notice in place. No Distribution without authors consent.";var f={expando:"{LGBB:"+(new Date).getMilliseconds()+"}",bbcodes:{},basics:[],attrReg:/.*?=("|'|)(.*?)\1\]/,parseTag:function(a,b,d){for(var g=b.insensitive?"i":"",c="\\["+b.tag+"[^\\]]*?\\]",h="\\[\\/"+b.tag+"\\]",g=d?RegExp("("+c+")(?!.*"+c+")((?:.|[\\r\\n])*?)"+h,g):RegExp(c,g),j=[];g.test(a);)a=a.replace(g,function(a,e,c){d||(e=a);e=f.attrReg.test(e)?e.replace(f.attrReg,"$2"):b.defaultAttr;if(b.validate&&!(d?b.validate.call(b,c,e):b.validate.call(b,e)))return j.push(a),f.expando;b.replace&&(a=d?b.replace.call(b,c,e):b.replace(e),"string"===typeof a?d?c=a:e=a:a&&"object"===typeof a&&(c=a.content||c,e=a.attr||e));return f.swapReplacers(b.replacement,c,e)});for(g=0;c=j[g++];)a=a.replace(f.expando,c);return a},swapReplacers:function(a,b,d){return(a||"").replace(/{CONTENT}/g,b||"").replace(/{ATTR}/g,d||"")},parse:function(a){var b=f.bbcodes,d=f.basics;f.expando="{LGBB:"+(new Date).getMilliseconds()+"}";for(var g=0,c;c=d[g++];){var h=c[0];if("string"===typeof h&&-1===c[1].indexOf(h))for(;-1!==a.indexOf(h);)a=a.replace(h,c[1]);else a=a.replace(h,c[1])}for(var j in b)if(b.hasOwnProperty(j)&&(d=b[j])&&d.replacement&&d.tag)try{a=f.parseTag(a,d,d.close)}catch(k){console.log("LGBB: Error parsing "+d.tag+" tag.",k)}return a},add:function(a,b){if(!/^\w+$/.test(a))throw new Exception("Invalid LGBB tag name: "+a);b.tag||(b.tag=a);"close"in b||(b.close=!1);f.bbcodes[a]=b;return this},addSwap:function(a,b){f.basics.push([a,b]);return this}};window.LGBB=f})();
LGBB.addSwap(/(\W)@([^\s<\n]+)/g, '$1@<a href="/profile?mode=viewprofile&u=$2">$2</a>');
LGBB.addSwap(/(\W)#(?![^<]+>)([^\s<\n]+)/g, function(m, pre, word) {
return pre + '#<a href="/search?mode=searchbox&search_keywords=' + encodeURIComponent(word) + '">' + word + '</a>';
});
- Kood:
LGBB.addSwap(/(\W)@([^\s<\n]+)/g, '$1@<a href="/profile?mode=viewprofile&u=$2">$2</a>');
LGBB.addSwap(/(\W)#(?![^<]+>)([^\s<\n]+)/g, function(m, pre, word) {
return pre + '#<a href="/search?mode=searchbox&search_keywords=' + encodeURIComponent(word) + '">' + word + '</a>';
});
Soovid vestluses osaleda?
Selleks logi sisse või tee endale kasutaja.
Lehekülg 1, lehekülgi kokku 1
Permissions in this forum:
Sa ei saa vastata siinsetele teemadele