Commit a4dc90b3 authored by Jono Mingard's avatar Jono Mingard Committed by Jono Mingard

Remove unused and superfluous JavaScript (Bug #1323920)

Some of these files aren't loaded on any pages, some (ie. debug.js)
are no longer necessary with modern debugging tools, and some have
been replaced by Bootstrap functionality

behatnotneeded: should be functionally identical

Change-Id: I6d1b3874de5d42ccc00a8c0d2bb0e8bc162747d4
parent 2e02af9a
......@@ -445,7 +445,7 @@ function profileform_reply($form, $code, $message) {
}
$smarty = smarty(array('tabs'), array(), array(
$smarty = smarty(array(), array(), array(
'mahara' => array(
'cannotremovedefaultemail',
'emailtoolong',
......
......@@ -356,7 +356,7 @@ if (!get_config('productionmode')) {
$CFG->log_info_targets = LOG_TARGET_SCREEN | LOG_TARGET_ERRORLOG;
$CFG->log_warn_targets = LOG_TARGET_SCREEN | LOG_TARGET_ERRORLOG;
$CFG->log_environ_targets = LOG_TARGET_SCREEN | LOG_TARGET_ERRORLOG;
$CFG->developermode = DEVMODE_DEBUGJS | DEVMODE_DEBUGCSS | DEVMODE_UNPACKEDJS;
$CFG->developermode = DEVMODE_DEBUGCSS | DEVMODE_UNPACKEDJS;
$CFG->perftofoot = true;
$CFG->nocache = true;
}
......
/**
* Hooks in a stylesheet that is only loaded when javascript is enabled
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
/**
* debug.js - for developer use
*
* If you're developing for Mahara, you can put any javascript you want to use
* for debugging in here.
*
* This file will only be included if the configuration setting 'developermode'
* is enabled. You can enable this in config.php
* JS behaviour for the export UI
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
/*
* gives a nice, stable string representation for objects,
* ignoring any methods
*/
debugObject = function (obj) {
var keyValuePairs = [];
for (var k in obj) {
var v = obj[k];
if (typeof(v) != 'function') {
keyValuePairs.push([k, v]);
}
};
keyValuePairs.sort(compare);
log( "{" + map(
function (pair) {
return map(repr, pair).join(":");
},
keyValuePairs
).join(", ") + "}");
};
/*
* gives a nice, stable string representation for objects
*/
debugObjectAll = function (obj) {
var keyValuePairs = [];
for (var k in obj) {
var v = obj[k];
keyValuePairs.push([k, v]);
};
keyValuePairs.sort(compare);
log( "{" + map(
function (pair) {
return map(repr, pair).join(":");
},
keyValuePairs
).join(", ") + "}");
};
/**
* Javascript for moving things around with drag and drop
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
var MoveSources = {
sources: [],
register: function(movesource) {
if (this.sources.length === 0) {
var conn = MochiKit.Signal.connect;
this.eventmouseclick = conn(document, 'onclick', this, this.onClick);
this.eventKeypress = conn(document, 'onkeypress', this, this.keyPress);
}
this.sources.push(movesource);
},
activate: function(movesource) {
if (this.activeSource) {
this.activeSource.cancelMove();
}
this.activeSource = movesource;
},
deactivate: function(movesource) {
this.activeSource = null;
},
onClick: function(e) {
if (this.activeSource) {
this.activeSource.cancelMove();
}
},
keyPress: function(e) {
}
};
var MoveSource = function(element, options) {
var self = this;
var d = MochiKit.DOM;
self.element = d.getElement(element);
self.element.moveSource = self;
self.selectedClass = options.selectedClass;
self.acceptData = options.acceptData;
self.startMove = function(e) {
MochiKit.Signal.disconnect(self.onClick);
MochiKit.DOM.addElementClass(self.element, self.selectedClass);
MoveSources.activate(self);
MoveTargets.prepare(self);
self.onClick = MochiKit.Signal.connect(self.element, 'onclick', self, self.cancelMove);
if (e) {
e.stop();
}
};
self.cancelMove = function(e) {
MochiKit.Signal.disconnect(self.onClick);
MochiKit.DOM.removeElementClass(self.element, self.selectedClass);
MoveSources.deactivate(self);
MoveTargets.reset(self);
self.onClick = MochiKit.Signal.connect(self.element, 'onclick', self, self.startMove);
if (e) {
e.stop();
}
};
self.onClick = MochiKit.Signal.connect(self.element, 'onclick', self, self.startMove);
MoveSources.register(self);
};
var MoveTargets = {
targets: [],
register: function(movetarget) {
this.targets.push(movetarget);
},
prepare: function(movesource) {
MochiKit.Base.map(function (movetarget) {
if (movetarget.accepts(movesource)) {
movetarget.startAccept();
}
}, this.targets);
},
reset: function(movesource) {
MochiKit.Base.map(function (movetarget) {
if (movetarget.accepts(movesource)) {
movetarget.stopAccept();
}
}, this.targets);
}
};
var MoveTarget = function(element,options) {
var self = this;
var d = MochiKit.DOM;
self.element = d.getElement(element);
self.element.moveTarget = self;
self.activeClass = options.activeClass;
self.hoverClass = options.hoverClass;
self.ondrop = options.ondrop;
self.acceptData = options.acceptData;
self.acceptFunction = options.acceptFunction;
self.accepts = function(movesource) {
if (typeof(self.acceptFunction) == 'function') {
return self.acceptFunction(movesource.acceptData, self.acceptData);
}
return true;
};
self.onMove = function(e) {
if (typeof(self.ondrop) == 'function') {
self.ondrop(MoveSources.activeSource.element, self.element);
}
};
self.startAccept = function() {
var d = MochiKit.DOM;
var s = MochiKit.Signal;
d.addElementClass(self.element, self.activeClass);
self.mouseOver = s.connect(self.element, 'onmouseover', function () { d.addElementClass(self.element, self.hoverClass); } );
self.mouseOut = s.connect(self.element, 'onmouseout', function () { d.removeElementClass(self.element, self.hoverClass); } );
self.onClick = s.connect(self.element, 'onclick', self, self.onMove);
};
self.stopAccept = function() {
MochiKit.DOM.removeElementClass(self.element, self.activeClass);
MochiKit.DOM.removeElementClass(self.element, self.hoverClass);
MochiKit.Signal.disconnect(self.mouseOver);
MochiKit.Signal.disconnect(self.mouseOut);
MochiKit.Signal.disconnect(self.onClick);
};
MoveTargets.register(self);
};
/**
* Responsive design navigation
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*
*/
// MAIN NAV (dropdown nav option NOT selected)
// tests size of main nav against window size and adds class if window size is smaller
function responsiveNav(navTarget, wrapper) {
if (wrapper.length == 0) {
return;
}
var navWidth = 0;
navTarget.each(function() {
navWidth += $j(this).outerWidth();
});
// Use the media query from theme/default/style/style.css
var breakpoint = 768;
var loginboxorder = 1;
$j(window).bind('load resize orientationchange', function() {
// allow the login box be at top of page if present and screen size is small
if ($j('#sb-loginbox').length > 0) {
if ($j('#right-column').css('float') == 'none') {
if ($j('#sb-loginbox-wrapper').length == 0) {
$j('<div id="sb-loginbox-wrapper">').prependTo('#container');
}
loginboxorder = parseInt($j('#sb-loginbox').attr('class').toString().replace(/[^\d]/g, ''),10);
$j('#sb-loginbox').prependTo('#sb-loginbox-wrapper');
$j('#sb-loginbox-wrapper').addClass('rd-loginbox');
}
else {
if ($j('#right-column').children().length > 0) {
$j('#right-column').children(':eq(' + (loginboxorder - 1) + ')').before($j('#sb-loginbox'));
}
else {
$j('#sb-loginbox').prependTo('#right-column');
}
$j('#sb-loginbox-wrapper').removeClass('rd-loginbox');
}
}
// get window width
var windowWidth = $j(window).width();
var wrapperWidth = wrapper.width();
// test if nav item combined width is greater than window width, add class if it is and vice versa
if (windowWidth < breakpoint || wrapperWidth < navWidth) {
wrapper.addClass('rd-navmenu');
}
else if (windowWidth >= breakpoint || wrapperWidth >= navWidth) {
wrapper.removeClass('rd-navmenu');
}
});
}
$j(document).ready(function(){
$j('body').removeClass('no-js').addClass('js');
responsiveNav($j('#main-nav > ul > li'), $j('#top-wrapper'));
responsiveNav($j('.tabswrap li'), $j('.tabswrap'));
responsiveNav($j('#category-list li'), $j('#top-pane'));
responsiveNav($j('#main-nav-footer > ul > li'), $j('#footer'));
// adds expand when click on menu title in responsive menu
$j(".rd-nav-title a").click(function(event) {
  $j(".main-nav").toggleClass("nav-expand");
if ($j('.main-nav').hasClass('nav-expand')) {
$j('.main-nav ul').find('a').first().focus();
}
return false;
});
// adds expand when click on arrow to expand tabs
$j(".rd-tab-title a").click(function(event) {
   $j(".tabswrap").toggleClass("expand");
if ($j('.tabswrap').hasClass('expand')) {
$j('.tabswrap ul').find('a').first().focus();
}
return false;
});
// adds expand when click on menu title in responsive footer menu
// Why does this exist?
$j(".rd-nav-footer-title").click(function(event) {
  $j(".main-nav-footer").toggleClass("nav-footer-expand");
});
});
/**
* Javascript to change Pieforms fieldsets to tabs
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
/**
* 'Speeds up' the user search if the user has javascript enabled in their
* browser
*
* @package mahara
* @subpackage core
* @author Catalyst IT Ltd
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL version 3 or later
* @copyright For copyright information on Mahara, please see the README file distributed with this software.
*/
function UserSearch() {
var self = this;
this.init = function () {
self.rewriteInitials();
self.rewriteQueryButton();
self.rewritePaging();
self.params = {};
};
this.rewriteInitials = function() {
forEach(getElementsByTagAndClassName('span', 'first-initial', 'firstnamelist'), function(i) {
self.rewriteInitial('f', i);
});
forEach(getElementsByTagAndClassName('span', 'last-initial', 'lastnamelist'), function(i) {
self.rewriteInitial('l', i);
});
};
this.rewriteInitial = function(t, i) {
connect(i, 'onclick', partial(self.searchInitial, t));
};
this.searchInitial = function(initialtype, e) {
// Clear all search params except for the other initial
if (initialtype == 'f') {
if (self.params.l) {
self.params = {'l' : self.params.l};
} else {
self.params = {};
}
forEach(getElementsByTagAndClassName('span', 'selected', 'firstnamelist'), function (i) {
removeElementClass(i, 'selected');
});
} else if (initialtype == 'l') {
if (self.params.f) {
self.params = {'f' : self.params.f};
} else {
self.params = {};
}
forEach(getElementsByTagAndClassName('span', 'selected', 'lastnamelist'), function (i) {
removeElementClass(i, 'selected');
});
}
addElementClass(this, 'selected');
if (!hasElementClass(this, 'all')) {
self.params[initialtype] = scrapeText(this).replace(/\s+/g, '');
}
self.doSearch();
e.stop();
};
this.rewritePaging = function() {
forEach(getElementsByTagAndClassName('span', 'pagination', 'searchresults'), function(i) {
connect(i, 'onclick', self.changePage);
});
};
this.changePage = function(e) {
var children = getElementsByTagAndClassName('a', null, this);
if (children.length == 1) {
var linkparams = parseQueryString(getNodeAttribute(children[0], 'href'));
self.params.offset = linkparams.offset;
self.doSearch();
}
e.stop();
};
this.rewriteQueryButton = function() {
connect($('query-button'), 'onclick', self.newQuery);
};
this.newQuery = function(e) {
self.params = {};
self.params.query = $('query').value;
self.doSearch();
e.stop();
};
this.doSearch = function() {
self.params.action = 'search';
sendjsonrequest('search.json.php', self.params, 'POST', function(data) {
$('results').innerHTML = data.data;
self.rewritePaging();
});
};
addLoadEvent(self.init);
}
userSearch = new UserSearch();
......@@ -165,7 +165,7 @@ jQuery(function($j) {
$j('#feedbacktable').on('click', '.js-reply', null, function(e){
var replybutton = $j(this);
e.preventDefault();
setupCommentButton(replybutton);
......@@ -184,7 +184,7 @@ jQuery(function($j) {
$j('.js-add-comment-modal').on('click', function(e) {
var replyviewContent = $j('#comment_reply_parent').children();
e.preventDefault();
// Remove any previous "reply to" comment that was being displayed
replyviewContent.remove();
......
......@@ -125,8 +125,6 @@ $cfg->error_reporting = E_ALL & ~E_STRICT;
* @global int|bool $cfg->developermode Developer mode
* When set, the following things (among others) will happen:
*
* * 'debug.js' will be included on each page. You can edit this file to add
* debugging javascript at your discretion
* * 'debug.css' will be included on each page. You can edit this file to add
* debugging CSS at your discretion
* * the unpacked version of MochiKit will be used
......@@ -135,7 +133,7 @@ $cfg->error_reporting = E_ALL & ~E_STRICT;
* developing for Mahara
*/
$cfg->developermode = false;
// $cfg->developermode = DEVMODE_DEBUGJS | DEVMODE_DEBUGCSS | DEVMODE_UNPACKEDJS;
// $cfg->developermode = DEVMODE_DEBUGCSS | DEVMODE_UNPACKEDJS;
/**
* @global bool $cfg->sendemail Whether to send e-mail. If set to false, Mahara will not send any e-mail at
......
......@@ -38,12 +38,10 @@ define('LOG_LEVEL_INFO', 4);
define('LOG_LEVEL_WARN', 8);
// developermodes, also bitmaps
/** inlude debug.js */
define('DEVMODE_DEBUGJS', 1);
/** include debug.css */
define('DEVMODE_DEBUGCSS', 2);
define('DEVMODE_DEBUGCSS', 1);
/** include unpacked mochikit */
define('DEVMODE_UNPACKEDJS', 8);
define('DEVMODE_UNPACKEDJS', 2);
// more here.. start at 16 :)
/**#@-*/
......
......@@ -506,9 +506,6 @@ EOF;
$javascript_array[] = $jsroot . 'mahara.js';
$javascript_array[] = $jsroot . 'formchangechecker.js';
if (get_config('developermode') & DEVMODE_DEBUGJS) {
$javascript_array[] = $jsroot . 'debug.js';
}
foreach ($jsstrings['mahara'] as $section => $tags) {
foreach ($tags as $tag) {
......
......@@ -570,7 +570,7 @@ $designskinform = pieform(array(
));
$smarty = smarty(array('jquery', 'tabs'), array(), array(
$smarty = smarty(array(), array(), array(
'mahara' => array(
'tab',
'selected',
......
......@@ -51,7 +51,6 @@
<script type="application/javascript" src="{theme_url filename='js/dock.js'}?v={$CACHEVERSION}"></script>
<script type="application/javascript" src="{theme_url filename='js/theme.js'}?v={$CACHEVERSION}"></script>
<script type="application/javascript" src="{$WWWROOT}js/css.js?v={$CACHEVERSION}"></script>
<link rel="shortcut icon" href="{$WWWROOT}favicon.ico?v={$CACHEVERSION}" type="image/vnd.microsoft.icon">
<link rel="image_src" href="{$sitelogo}">
{if $ADDITIONALHTMLHEAD}{$ADDITIONALHTMLHEAD|safe}{/if}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment