formatting - core client side

v1.18.x
psychobunny 12 years ago
parent 828d937dec
commit dc41c6bc0d

@ -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,16 +130,16 @@ var ajaxify = {};
};
function evalScript(elem) {
var data = (elem.text || elem.textContent || elem.innerHTML || "" ),
head = document.getElementsByTagName("head")[0] ||
document.documentElement,
var data = (elem.text || elem.textContent || elem.innerHTML || ""),
head = document.getElementsByTagName("head")[0] ||
document.documentElement,
script = document.createElement("script");
script.type = "text/javascript";
try {
script.appendChild(document.createTextNode(data));
} catch(e) {
script.text = data;
script.appendChild(document.createTextNode(data));
} catch (e) {
script.text = data;
}
if (elem.src) {
@ -159,8 +159,8 @@ var ajaxify = {};
for (i = 0; children_nodes[i]; i++) {
child = children_nodes[i];
if (nodeName(child, "script" ) &&
(!child.type || child.type.toLowerCase() === "text/javascript")) {
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,17 +185,17 @@
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;
case 'int': // Intentional fall-through
break;
case 'int': // Intentional fall-through
case 'integer':
value = parseInt(element.value);
break;
break;
default:
value = element.value;
break;
break;
}
templates.set(element.getAttribute('template-variable'), value);
@ -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);
});
},
@ -43,7 +44,7 @@
},
relativeTime: function(timestamp, min) {
var now = +new Date(),
var now = +new Date(),
difference = now - Math.floor(parseFloat(timestamp));
difference = Math.floor(difference / 1000);
@ -73,14 +74,14 @@
// remove accents, swap ñ for n, etc
var from = "àáäâèéëêìíïîıòóöôùúüûñçşğ·/_,:;";
var to = "aaaaeeeeiiiiioooouuuuncsg------";
for (var i=0, l=from.length ; i<l ; i++) {
var to = "aaaaeeeeiiiiioooouuuuncsg------";
for (var i = 0, l = from.length; i < l; i++) {
str = str.replace(new RegExp(from.charAt(i), 'g'), to.charAt(i));
}
str = str.replace(/[^a-z0-9 -]/g, '') // remove invalid chars
.replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-'); // collapse dashes
.replace(/\s+/g, '-') // collapse whitespace and replace by -
.replace(/-+/g, '-'); // collapse dashes
return str;
},
@ -103,21 +104,21 @@
// Blatently stolen from: http://phpjs.org/functions/strip_tags/
'strip_tags': function(input, allowed) {
allowed = (((allowed || "") + "").toLowerCase().match(/<[a-z][a-z0-9]*>/g) || []).join(''); // making sure the allowed arg is a string containing only tags in lowercase (<a><b><c>)
var tags = /<\/?([a-z][a-z0-9]*)\b[^>]*>/gi,
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 : '';
});
},
buildMetaTags: function(tagsArr) {
var tags = '',
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 += ' />';
@ -130,14 +131,14 @@
refreshTitle: function(url) {
if (!url) {
var a = document.createElement('a');
var a = document.createElement('a');
a.href = document.location;
url = a.pathname.slice(1);
}
var notificationIcon;
socket.emit('api:meta.buildTitle', url, function(title, numNotifications) {
document.title = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title;
document.title = (numNotifications > 0 ? '(' + numNotifications + ') ' : '') + title;
notificationIcon = notificationIcon || document.querySelector('.notifications a i');
if (numNotifications > 0 && notificationIcon) notificationIcon.className = 'icon-circle active';
});
@ -150,8 +151,7 @@
badge
.removeClass('badge-inverse')
.addClass('badge-important')
}
else {
} else {
badge
.removeClass('badge-important')
.addClass('badge-inverse')
@ -160,26 +160,34 @@
},
isRelativeUrl: function(url) {
var firstChar = url.slice(0, 1);
var firstChar = url.slice(0, 1);
return (firstChar === '.' || firstChar === '/');
}
}
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)
Loading…
Cancel
Save