mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-07 22:45:46 +01:00
formatting - core client side
This commit is contained in:
@@ -12,7 +12,7 @@ var ajaxify = {};
|
||||
|
||||
var events = [];
|
||||
ajaxify.register_events = function(new_page_events) {
|
||||
for (var i = 0, ii = events.length; i<ii; i++) {
|
||||
for (var i = 0, ii = events.length; i < ii; i++) {
|
||||
socket.removeAllListeners(events[i]); // optimize this to user removeListener(event, listener) instead.
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ var ajaxify = {};
|
||||
|
||||
var hash = window.location.hash;
|
||||
|
||||
if(url.indexOf(RELATIVE_PATH.slice(1)) !== -1) {
|
||||
if (url.indexOf(RELATIVE_PATH.slice(1)) !== -1) {
|
||||
url = url.slice(RELATIVE_PATH.length);
|
||||
}
|
||||
|
||||
var tpl_url = templates.get_custom_map(url.split('?')[0]);
|
||||
|
||||
if (tpl_url == false && !templates[url]) {
|
||||
if(url === '' || url === '/') {
|
||||
if (url === '' || url === '/') {
|
||||
tpl_url = 'home';
|
||||
} else {
|
||||
tpl_url = url.split('/')[0].split('?')[0];
|
||||
@@ -79,9 +79,9 @@ var ajaxify = {};
|
||||
app.process_page();
|
||||
|
||||
jQuery('#content, #footer').stop(true, true).fadeIn(200, function() {
|
||||
if(window.location.hash)
|
||||
if (window.location.hash)
|
||||
hash = window.location.hash;
|
||||
if(hash)
|
||||
if (hash)
|
||||
app.scrollToPost(hash.substr(1));
|
||||
});
|
||||
|
||||
@@ -107,9 +107,9 @@ var ajaxify = {};
|
||||
return href == 'javascript:;' || href == window.location.href + "#" || href.slice(-1) === "#";
|
||||
}
|
||||
|
||||
if(hrefEmpty(this.href)) return;
|
||||
if (hrefEmpty(this.href)) return;
|
||||
|
||||
var url = this.href.replace(rootUrl +'/', '');
|
||||
var url = this.href.replace(rootUrl + '/', '');
|
||||
|
||||
if (this.target !== '') return;
|
||||
|
||||
@@ -130,7 +130,7 @@ var ajaxify = {};
|
||||
};
|
||||
|
||||
function evalScript(elem) {
|
||||
var data = (elem.text || elem.textContent || elem.innerHTML || "" ),
|
||||
var data = (elem.text || elem.textContent || elem.innerHTML || ""),
|
||||
head = document.getElementsByTagName("head")[0] ||
|
||||
document.documentElement,
|
||||
script = document.createElement("script");
|
||||
@@ -138,7 +138,7 @@ var ajaxify = {};
|
||||
script.type = "text/javascript";
|
||||
try {
|
||||
script.appendChild(document.createTextNode(data));
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
script.text = data;
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ var ajaxify = {};
|
||||
|
||||
for (i = 0; children_nodes[i]; i++) {
|
||||
child = children_nodes[i];
|
||||
if (nodeName(child, "script" ) &&
|
||||
if (nodeName(child, "script") &&
|
||||
(!child.type || child.type.toLowerCase() === "text/javascript")) {
|
||||
scripts.push(child);
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
|
||||
|
||||
(function (module) {
|
||||
(function(module) {
|
||||
|
||||
var config = {},
|
||||
templates,
|
||||
@@ -105,7 +103,7 @@
|
||||
templates.getTemplateNameFromUrl = function(url) {
|
||||
var parts = url.split('?')[0].split('/');
|
||||
|
||||
for(var i=0; i<parts.length; ++i) {
|
||||
for (var i = 0; i < parts.length; ++i) {
|
||||
if (templates.is_available(parts[i])) {
|
||||
return parts[i];
|
||||
}
|
||||
@@ -124,7 +122,7 @@
|
||||
|
||||
var trimmed = api_url;
|
||||
|
||||
if(!tpl_url) {
|
||||
if (!tpl_url) {
|
||||
tpl_url = templates.getTemplateNameFromUrl(api_url);
|
||||
}
|
||||
|
||||
@@ -160,7 +158,7 @@
|
||||
|
||||
jQuery.get(API_URL + api_url, function(data) {
|
||||
|
||||
if(!data) {
|
||||
if (!data) {
|
||||
ajaxify.go('404');
|
||||
return;
|
||||
}
|
||||
@@ -177,7 +175,7 @@
|
||||
function parse_template() {
|
||||
if (!templates[tpl_url] || !template_data) return;
|
||||
|
||||
if(typeof global !== "undefined")
|
||||
if (typeof global !== "undefined")
|
||||
template_data['relative_path'] = nconf.get('relative_path');
|
||||
else
|
||||
template_data['relative_path'] = RELATIVE_PATH;
|
||||
@@ -187,7 +185,7 @@
|
||||
jQuery('#content [template-variable]').each(function(index, element) {
|
||||
var value = null;
|
||||
|
||||
switch(element.getAttribute('template-type')) {
|
||||
switch (element.getAttribute('template-type')) {
|
||||
case 'boolean':
|
||||
value = (element.value === 'true' || element.value === '1') ? true : false;
|
||||
break;
|
||||
@@ -252,7 +250,8 @@
|
||||
return template.replace(regex, block);
|
||||
}
|
||||
|
||||
var template = this.html, regex, block;
|
||||
var template = this.html,
|
||||
regex, block;
|
||||
|
||||
return (function parse(data, namespace, template) {
|
||||
if (!data || data.length == 0) {
|
||||
@@ -267,14 +266,16 @@
|
||||
namespace += d + '.';
|
||||
|
||||
var regex = makeRegex(d),
|
||||
block = getBlock(regex, namespace.substring(0, namespace.length-1), template);
|
||||
block = getBlock(regex, namespace.substring(0, namespace.length - 1), template);
|
||||
|
||||
if (block == null) {
|
||||
namespace = namespace.replace(d + '.', '');
|
||||
continue;
|
||||
}
|
||||
|
||||
var numblocks = data[d].length - 1, i = 0, result = "";
|
||||
var numblocks = data[d].length - 1,
|
||||
i = 0,
|
||||
result = "";
|
||||
|
||||
do {
|
||||
result += parse(data[d][i], namespace, block);
|
||||
@@ -312,7 +313,8 @@
|
||||
templates.init();
|
||||
}
|
||||
|
||||
})('undefined' === typeof module ? {module:{exports:{}}} : module)
|
||||
|
||||
|
||||
|
||||
})('undefined' === typeof module ? {
|
||||
module: {
|
||||
exports: {}
|
||||
}
|
||||
} : module)
|
||||
@@ -1,4 +1,4 @@
|
||||
(function (module) {
|
||||
(function(module) {
|
||||
|
||||
var utils, fs;
|
||||
|
||||
@@ -10,7 +10,8 @@
|
||||
module.exports = utils = {
|
||||
generateUUID: function() {
|
||||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
|
||||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8);
|
||||
var r = Math.random() * 16 | 0,
|
||||
v = c == 'x' ? r : (r & 0x3 | 0x8);
|
||||
return v.toString(16);
|
||||
});
|
||||
},
|
||||
@@ -74,7 +75,7 @@
|
||||
// remove accents, swap ñ for n, etc
|
||||
var from = "àáäâèéëêìíïîıòóöôùúüûñçşğ·/_,:;";
|
||||
var to = "aaaaeeeeiiiiioooouuuuncsg------";
|
||||
for (var i=0, l=from.length ; i<l ; i++) {
|
||||
for (var i = 0, l = from.length; i < l; i++) {
|
||||
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
|
||||
}
|
||||
|
||||
@@ -106,7 +107,7 @@
|
||||
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
|
||||
commentsAndPhpTags = /<!--[\s\S]*?-->|<\?(?:php)?[\s\S]*?\?>/gi;
|
||||
|
||||
return input.replace(commentsAndPhpTags, '').replace(tags, function ($0, $1) {
|
||||
return input.replace(commentsAndPhpTags, '').replace(tags, function($0, $1) {
|
||||
return allowed.indexOf('<' + $1.toLowerCase() + '>') > -1 ? $0 : '';
|
||||
});
|
||||
},
|
||||
@@ -114,10 +115,10 @@
|
||||
buildMetaTags: function(tagsArr) {
|
||||
var tags = '',
|
||||
tag;
|
||||
for(var x=0,numTags=tagsArr.length;x<numTags;x++) {
|
||||
for (var x = 0, numTags = tagsArr.length; x < numTags; x++) {
|
||||
if (tags.length > 0) tags += "\n\t";
|
||||
tag = '<meta';
|
||||
for(y in tagsArr[x]) {
|
||||
for (y in tagsArr[x]) {
|
||||
tag += ' ' + y + '="' + tagsArr[x][y] + '"';
|
||||
}
|
||||
tag += ' />';
|
||||
@@ -150,8 +151,7 @@
|
||||
badge
|
||||
.removeClass('badge-inverse')
|
||||
.addClass('badge-important')
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
badge
|
||||
.removeClass('badge-important')
|
||||
.addClass('badge-inverse')
|
||||
@@ -167,19 +167,27 @@
|
||||
|
||||
|
||||
if (!String.prototype.trim) {
|
||||
String.prototype.trim=function(){return this.replace(/^\s+|\s+$/g, '');};
|
||||
String.prototype.trim = function() {
|
||||
return this.replace(/^\s+|\s+$/g, '');
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.ltrim) {
|
||||
String.prototype.ltrim=function(){return this.replace(/^\s+/,'');};
|
||||
String.prototype.ltrim = function() {
|
||||
return this.replace(/^\s+/, '');
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.rtrim) {
|
||||
String.prototype.rtrim=function(){return this.replace(/\s+$/,'');};
|
||||
String.prototype.rtrim = function() {
|
||||
return this.replace(/\s+$/, '');
|
||||
};
|
||||
}
|
||||
|
||||
if (!String.prototype.fulltrim) {
|
||||
String.prototype.fulltrim=function(){return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g,'').replace(/\s+/g,' ');};
|
||||
String.prototype.fulltrim = function() {
|
||||
return this.replace(/(?:(?:^|\n)\s+|\s+(?:$|\n))/g, '').replace(/\s+/g, ' ');
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -187,4 +195,8 @@
|
||||
window.utils = module.exports;
|
||||
}
|
||||
|
||||
})('undefined' === typeof module ? {module:{exports:{}}} : module)
|
||||
})('undefined' === typeof module ? {
|
||||
module: {
|
||||
exports: {}
|
||||
}
|
||||
} : module)
|
||||
Reference in New Issue
Block a user