Skip to content

Node.js based forum software built for the modern web

removed admin/footer.js, moved code to admin.js instead

psychobunnydcd47f7ec52f
diff --git a/public/src/admin.js b/public/src/admin.js
index 51eceb961c..fba077dced 100644
--- a/public/src/admin.js
+++ b/public/src/admin.js
@@ -1,9 +1,11 @@
"use strict";
-/*global app, socket, Mousetrap*/
+/*global define, app, ajaxify, socket, Mousetrap, Hammer, RELATIVE_PATH*/
var admin = {};
(function() {
+ admin.searchIndex = null;
+
admin.enableColorPicker = function(inputEl, callback) {
(inputEl instanceof jQuery ? inputEl : $(inputEl)).each(function() {
var $this = $(this);
@@ -23,9 +25,21 @@ var admin = {};
});
};
- $(function() {
+ $(document).ready(function() {
setupMenu();
setupKeybindings();
+
+ if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
+ getSearchIndex();
+ } else {
+ activateMobile();
+ }
+
+ $(window).on('action:ajaxify.end', function(ev, data) {
+ var url = data.url;
+
+ selectMenuItem(data.url);
+ });
});
socket.emit('admin.config.get', function(err, config) {
@@ -81,4 +95,160 @@ var admin = {};
return false;
});
}
+
+
+ function activateMobile() {
+ $('.admin').addClass('mobile');
+ $('#main-menu').addClass('transitioning');
+
+ Hammer(document.body).on('swiperight', function(e) {
+ $('#main-menu').addClass('open');
+ });
+
+ Hammer(document.body).on('swipeleft', function(e) {
+ $('#main-menu').removeClass('open');
+ });
+
+ Hammer($('#main-menu')[0]).on('swiperight', function(e) {
+ $('#main-menu').addClass('open');
+ });
+
+ Hammer($('#main-menu')[0]).on('swipeleft', function(e) {
+ $('#main-menu').removeClass('open');
+ });
+
+ $(window).on('scroll', function() {
+ $('#main-menu').height($(window).height() + 20);
+ });
+ }
+
+ function selectMenuItem(url) {
+ $('#main-menu .nav-list > li').removeClass('active').each(function() {
+ var menu = $(this),
+ category = menu.parents('.sidebar-nav'),
+ href = menu.children('a').attr('href');
+
+ if (href && href.slice(1).indexOf(url) !== -1) {
+ category.addClass('open');
+ menu.addClass('active');
+ modifyBreadcrumb(category.find('.nav-header').text(), menu.text());
+ return false;
+ }
+ });
+ }
+
+ function modifyBreadcrumb() {
+ var caret = ' <i class="fa fa-angle-right"></i> ';
+
+ $('#breadcrumbs').html(caret + Array.prototype.slice.call(arguments).join(caret));
+ }
+
+ function getSearchIndex() {
+ $.getJSON(RELATIVE_PATH + '/templates/indexed.json', function (data) {
+ admin.searchIndex = data;
+ for (var file in admin.searchIndex) {
+ if (admin.searchIndex.hasOwnProperty(file)) {
+ admin.searchIndex[file] = admin.searchIndex[file].replace(/<img/g, '<none'); // can't think of a better solution, see #2153
+ admin.searchIndex[file] = $('<div class="search-container">' + admin.searchIndex[file] + '</div>');
+ admin.searchIndex[file].find('script').remove();
+
+ admin.searchIndex[file] = admin.searchIndex[file].text().toLowerCase().replace(/[ |\r|\n]+/g, ' ');
+ }
+ }
+
+ delete admin.searchIndex['/admin/header.tpl'];
+ delete admin.searchIndex['/admin/footer.tpl'];
+
+ setupACPSearch();
+ });
+ }
+
+ function setupACPSearch() {
+ var menu = $('#acp-search .dropdown-menu'),
+ routes = [],
+ input = $('#acp-search input'),
+ firstResult = null;
+
+ input.on('keyup', function() {
+ $('#acp-search .dropdown').addClass('open');
+ });
+
+ $('#acp-search').parents('form').on('submit', function(ev) {
+ var input = $(this).find('input'),
+ href = firstResult ? firstResult : RELATIVE_PATH + '/search/' + input.val();
+
+ ajaxify.go(href.replace(/^\//, ''));
+
+ setTimeout(function() {
+ $('#acp-search .dropdown').removeClass('open');
+ $(input).blur();
+ }, 150);
+
+ ev.preventDefault();
+ return false;
+ });
+
+ $('.sidebar-nav a').each(function(idx, link) {
+ routes.push($(link).attr('href'));
+ });
+
+ input.on('blur', function() {
+ $(this).val('').attr('placeholder', '/');
+ });
+
+ input.on('keyup focus', function() {
+ var $input = $(this),
+ value = $input.val().toLowerCase(),
+ menuItems = $('#acp-search .dropdown-menu').html('');
+
+ function toUpperCase(txt){
+ return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
+ }
+
+ $input.attr('placeholder', '');
+
+ firstResult = null;
+
+ if (value.length >= 3) {
+ for (var file in admin.searchIndex) {
+ if (admin.searchIndex.hasOwnProperty(file)) {
+ var position = admin.searchIndex[file].indexOf(value);
+
+ if (position !== -1) {
+ var href = file.replace('.tpl', ''),
+ title = href.replace(/^\/admin\//, '').split('/'),
+ description = admin.searchIndex[file].substring(Math.max(0, position - 25), Math.min(admin.searchIndex[file].length - 1, position + 25))
+ .replace(value, '<span class="search-match">' + value + '</span>');
+
+ for (var t in title) {
+ if (title.hasOwnProperty(t)) {
+ title[t] = title[t]
+ .replace('-', ' ')
+ .replace(/\w\S*/g, toUpperCase);
+ }
+ }
+
+ title = title.join(' > ');
+ href = RELATIVE_PATH + href;
+ firstResult = firstResult ? firstResult : href;
+
+ if ($.inArray(href, routes) !== -1) {
+ menuItems.append('<li role="presentation"><a role="menuitem" href="' + href + '">' + title + '<br /><small><code>...' + description + '...</code></small></a></li>');
+ }
+ }
+ }
+ }
+
+ if (menuItems.html() !== '') {
+ menuItems.append('<li role="presentation" class="divider"></li>');
+ }
+ }
+
+ if (value.length > 0) {
+ menuItems.append('<li role="presentation"><a role="menuitem" href="' + RELATIVE_PATH + '/search/' + value + '">Search the forum for <strong>' + value + '</strong></a></li>');
+ } else {
+ menuItems.append('<li role="presentation"><a role="menuitem" href="#">Start typing to see results...</a></li>');
+ }
+ });
+ }
}());
\ No newline at end of file
diff --git a/public/src/admin/footer.js b/public/src/admin/footer.js
deleted file mode 100644
index dd0846d636..0000000000
--- a/public/src/admin/footer.js
+++ /dev/null
@@ -1,175 +0,0 @@
-"use strict";
-/*global define, app, socket, Hammer, RELATIVE_PATH */
-
-define('admin/footer', ['admin/settings'], function(Settings) {
- var acpIndex;
-
- $(document).ready(function() {
- if(!/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
- getSearchIndex();
- } else {
- activateMobile();
- }
-
- $(window).on('action:ajaxify.end', function(ev, data) {
- var url = data.url;
-
- selectMenuItem(data.url);
- });
- });
-
- function activateMobile() {
- $('.admin').addClass('mobile');
- $('#main-menu').addClass('transitioning');
-
- Hammer(document.body).on('swiperight', function(e) {
- $('#main-menu').addClass('open');
- });
-
- Hammer(document.body).on('swipeleft', function(e) {
- $('#main-menu').removeClass('open');
- });
-
- Hammer($('#main-menu')[0]).on('swiperight', function(e) {
- $('#main-menu').addClass('open');
- });
-
- Hammer($('#main-menu')[0]).on('swipeleft', function(e) {
- $('#main-menu').removeClass('open');
- });
-
- $(window).on('scroll', function() {
- $('#main-menu').height($(window).height() + 20);
- });
- }
-
- function selectMenuItem(url) {
- $('#main-menu .nav-list > li').removeClass('active').each(function() {
- var menu = $(this),
- category = menu.parents('.sidebar-nav'),
- href = menu.children('a').attr('href');
-
- if (href && href.slice(1).indexOf(url) !== -1) {
- category.addClass('open');
- menu.addClass('active');
- modifyBreadcrumb(category.find('.nav-header').text(), menu.text());
- return false;
- }
- });
- }
-
- function modifyBreadcrumb() {
- var caret = ' <i class="fa fa-angle-right"></i> ';
-
- $('#breadcrumbs').html(caret + Array.prototype.slice.call(arguments).join(caret));
- }
-
- function getSearchIndex() {
- $.getJSON(RELATIVE_PATH + '/templates/indexed.json', function (data) {
- acpIndex = data;
- for (var file in acpIndex) {
- if (acpIndex.hasOwnProperty(file)) {
- acpIndex[file] = acpIndex[file].replace(/<img/g, '<none'); // can't think of a better solution, see #2153
- acpIndex[file] = $('<div class="search-container">' + acpIndex[file] + '</div>');
- acpIndex[file].find('script').remove();
-
- acpIndex[file] = acpIndex[file].text().toLowerCase().replace(/[ |\r|\n]+/g, ' ');
- }
- }
-
- delete acpIndex['/admin/header.tpl'];
- delete acpIndex['/admin/footer.tpl'];
-
- setupACPSearch();
- });
- }
-
- function setupACPSearch() {
- var menu = $('#acp-search .dropdown-menu'),
- routes = [],
- input = $('#acp-search input'),
- firstResult = null;
-
- input.on('keyup', function() {
- $('#acp-search .dropdown').addClass('open');
- });
-
- $('#acp-search').parents('form').on('submit', function(ev) {
- var input = $(this).find('input'),
- href = firstResult ? firstResult : RELATIVE_PATH + '/search/' + input.val();
-
- ajaxify.go(href.replace(/^\//, ''));
-
- setTimeout(function() {
- $('#acp-search .dropdown').removeClass('open');
- $(input).blur();
- }, 150);
-
- ev.preventDefault();
- return false;
- });
-
- $('.sidebar-nav a').each(function(idx, link) {
- routes.push($(link).attr('href'));
- });
-
- input.on('blur', function() {
- $(this).val('').attr('placeholder', '/');
- });
-
- input.on('keyup focus', function() {
- var $input = $(this),
- value = $input.val().toLowerCase(),
- menuItems = $('#acp-search .dropdown-menu').html('');
-
- function toUpperCase(txt){
- return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
- }
-
- $input.attr('placeholder', '');
-
- firstResult = null;
-
- if (value.length >= 3) {
- for (var file in acpIndex) {
- if (acpIndex.hasOwnProperty(file)) {
- var position = acpIndex[file].indexOf(value);
-
- if (position !== -1) {
- var href = file.replace('.tpl', ''),
- title = href.replace(/^\/admin\//, '').split('/'),
- description = acpIndex[file].substring(Math.max(0, position - 25), Math.min(acpIndex[file].length - 1, position + 25))
- .replace(value, '<span class="search-match">' + value + '</span>');
-
- for (var t in title) {
- if (title.hasOwnProperty(t)) {
- title[t] = title[t]
- .replace('-', ' ')
- .replace(/\w\S*/g, toUpperCase);
- }
- }
-
- title = title.join(' > ');
- href = RELATIVE_PATH + href;
- firstResult = firstResult ? firstResult : href;
-
- if ($.inArray(href, routes) !== -1) {
- menuItems.append('<li role="presentation"><a role="menuitem" href="' + href + '">' + title + '<br /><small><code>...' + description + '...</code></small></a></li>');
- }
- }
- }
- }
-
- if (menuItems.html() !== '') {
- menuItems.append('<li role="presentation" class="divider"></li>');
- }
- }
-
- if (value.length > 0) {
- menuItems.append('<li role="presentation"><a role="menuitem" href="' + RELATIVE_PATH + '/search/' + value + '">Search the forum for <strong>' + value + '</strong></a></li>');
- } else {
- menuItems.append('<li role="presentation"><a role="menuitem" href="#">Start typing to see results...</a></li>');
- }
- });
- }
-});
\ No newline at end of file
diff --git a/src/views/admin/footer.tpl b/src/views/admin/footer.tpl
index 03f801603c..394d4499b5 100644
--- a/src/views/admin/footer.tpl
+++ b/src/views/admin/footer.tpl
@@ -46,10 +46,5 @@
<div id="footer" class="container" style="padding-top: 50px; display:none;">
<footer class="footer">Copyright &copy; 2014 <a target="_blank" href="http://www.nodebb.com">NodeBB</a> by <a target="_blank" href="https://github.com/psychobunny">psychobunny</a>, <a href="https://github.com/julianlam" target="_blank">julianlam</a>, <a href="https://github.com/barisusakli" target="_blank">barisusakli</a> from <a target="_blank" href="http://www.designcreateplay.com">designcreateplay</a></footer>
</div>
-
-<script type="text/javascript">
- require(['admin/footer']);
-</script>
-
</body>
</html>
\ No newline at end of file