mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-08 06:55:46 +01:00
added action:page.load hook
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
var ajaxify = {};
|
"use strict";
|
||||||
|
|
||||||
|
var ajaxify = {};
|
||||||
|
|
||||||
(function ($) {
|
(function ($) {
|
||||||
/*global app, templates, utils*/
|
/*global app, templates, utils*/
|
||||||
@@ -23,8 +24,9 @@ var ajaxify = {};
|
|||||||
|
|
||||||
window.onpopstate = function (event) {
|
window.onpopstate = function (event) {
|
||||||
// "quiet": If set to true, will not call pushState
|
// "quiet": If set to true, will not call pushState
|
||||||
if (event !== null && event.state && event.state.url !== undefined)
|
if (event !== null && event.state && event.state.url !== undefined) {
|
||||||
ajaxify.go(event.state.url, null, null, true);
|
ajaxify.go(event.state.url, null, null, true);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
var pagination;
|
var pagination;
|
||||||
@@ -35,7 +37,10 @@ var ajaxify = {};
|
|||||||
app.enter_room('global');
|
app.enter_room('global');
|
||||||
|
|
||||||
pagination = pagination || document.getElementById('pagination');
|
pagination = pagination || document.getElementById('pagination');
|
||||||
if (pagination) pagination.parentNode.style.display = 'none';
|
if (pagination) {
|
||||||
|
pagination.parentNode.style.display = 'none';
|
||||||
|
}
|
||||||
|
|
||||||
window.onscroll = null;
|
window.onscroll = null;
|
||||||
// end
|
// end
|
||||||
|
|
||||||
@@ -65,8 +70,20 @@ var ajaxify = {};
|
|||||||
if (quiet !== true) {
|
if (quiet !== true) {
|
||||||
if (window.history && window.history.pushState) {
|
if (window.history && window.history.pushState) {
|
||||||
window.history.pushState({
|
window.history.pushState({
|
||||||
"url": url
|
url: url
|
||||||
}, url, RELATIVE_PATH + "/" + url);
|
}, url, RELATIVE_PATH + '/' + url);
|
||||||
|
|
||||||
|
$.ajax(RELATIVE_PATH + '/plugins/fireHook', {
|
||||||
|
type: 'PUT',
|
||||||
|
data: {
|
||||||
|
_csrf: $('#csrf_token').val(),
|
||||||
|
hook: 'page.load',
|
||||||
|
args: {
|
||||||
|
template: tpl_url,
|
||||||
|
url: '/' + url
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -78,7 +95,9 @@ var ajaxify = {};
|
|||||||
templates.load_template(function () {
|
templates.load_template(function () {
|
||||||
exec_body_scripts(content);
|
exec_body_scripts(content);
|
||||||
require(['forum/' + tpl_url], function(script) {
|
require(['forum/' + tpl_url], function(script) {
|
||||||
if (script && script.init) script.init();
|
if (script && script.init) {
|
||||||
|
script.init();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
@@ -88,10 +107,13 @@ var ajaxify = {};
|
|||||||
app.process_page();
|
app.process_page();
|
||||||
|
|
||||||
jQuery('#content, #footer').stop(true, true).fadeIn(200, function () {
|
jQuery('#content, #footer').stop(true, true).fadeIn(200, function () {
|
||||||
if (window.location.hash)
|
if (window.location.hash) {
|
||||||
hash = window.location.hash;
|
hash = window.location.hash;
|
||||||
if (hash)
|
}
|
||||||
|
|
||||||
|
if (hash) {
|
||||||
app.scrollToPost(hash.substr(1));
|
app.scrollToPost(hash.substr(1));
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
utils.refreshTitle(url);
|
utils.refreshTitle(url);
|
||||||
@@ -105,23 +127,27 @@ var ajaxify = {};
|
|||||||
};
|
};
|
||||||
|
|
||||||
$('document').ready(function () {
|
$('document').ready(function () {
|
||||||
if (!window.history || !window.history.pushState) return; // no ajaxification for old browsers
|
if (!window.history || !window.history.pushState) {
|
||||||
|
return; // no ajaxification for old browsers
|
||||||
|
}
|
||||||
|
|
||||||
content = content || document.getElementById('content');
|
content = content || document.getElementById('content');
|
||||||
|
|
||||||
// Enhancing all anchors to ajaxify...
|
// Enhancing all anchors to ajaxify...
|
||||||
$(document.body).on('click', 'a', function (e) {
|
$(document.body).on('click', 'a', function (e) {
|
||||||
function hrefEmpty(href) {
|
function hrefEmpty(href) {
|
||||||
return href == 'javascript:;' || href == window.location.href + "#" || href.slice(-1) === "#";
|
return href === 'javascript:;' || href === window.location.href + "#" || href.slice(-1) === "#";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hrefEmpty(this.href) || this.target !== '' || this.protocol === 'javascript:')
|
if (hrefEmpty(this.href) || this.target !== '' || this.protocol === 'javascript:') {
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if(!window.location.pathname.match(/\/(403|404)$/g))
|
if(!window.location.pathname.match(/\/(403|404)$/g)) {
|
||||||
app.previousUrl = window.location.href;
|
app.previousUrl = window.location.href;
|
||||||
|
}
|
||||||
|
|
||||||
if (this.getAttribute('data-ajaxify') == 'false') {
|
if (this.getAttribute('data-ajaxify') === 'false') {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,28 @@
|
|||||||
|
"use strict";
|
||||||
|
|
||||||
var nconf = require('nconf'),
|
var nconf = require('nconf'),
|
||||||
path = require('path'),
|
path = require('path'),
|
||||||
fs = require('fs'),
|
fs = require('fs'),
|
||||||
Plugins = require('../plugins'),
|
Plugins = require('../plugins'),
|
||||||
|
|
||||||
PluginRoutes = function(app) {
|
PluginRoutes = function(app) {
|
||||||
|
app.get('/plugins/fireHook', function(req, res) {
|
||||||
|
// GET = filter
|
||||||
|
Plugins.fireHook('filter:' + req.query.hook, req.query.args, function(err, returnData) {
|
||||||
|
if (typeof returnData === 'object') {
|
||||||
|
res.json(200, returnData);
|
||||||
|
} else {
|
||||||
|
res.send(200, returnData);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
app.put('/plugins/fireHook', function(req, res) {
|
||||||
|
// PUT = action
|
||||||
|
Plugins.fireHook('action:' + req.body.hook, req.body.args);
|
||||||
|
res.send(200);
|
||||||
|
});
|
||||||
|
|
||||||
// Static Assets
|
// Static Assets
|
||||||
app.get('/plugins/:id/*', function(req, res) {
|
app.get('/plugins/:id/*', function(req, res) {
|
||||||
var relPath = req.url.replace('/plugins/' + req.params.id, '');
|
var relPath = req.url.replace('/plugins/' + req.params.id, '');
|
||||||
@@ -15,7 +34,7 @@ var nconf = require('nconf'),
|
|||||||
} else {
|
} else {
|
||||||
res.redirect('/404');
|
res.redirect('/404');
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
} else {
|
} else {
|
||||||
res.redirect('/404');
|
res.redirect('/404');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user