Skip to content
Snippets Groups Projects
Commit 6cd491c1 authored by Chris Hallberg's avatar Chris Hallberg
Browse files

Merged in PR #655: Centralized JS initialization

Tried git merge --squash

Squashed commit of the following:

commit 3945fdb723deacf5050f1b5e33e224c9bb452815
Merge: 63ffa60 9f3fb74a
Author: Chris Hallberg <crhallberg@gmail.com>
Date:   Wed Mar 30 16:56:03 2016 -0400

    Merge remote-tracking branch 'origin/master' into vufind-register

commit 63ffa6043ef91e22a2657f91d8c6a7b68667a380
Author: Chris Hallberg <crhallberg@gmail.com>
Date:   Wed Mar 30 09:42:11 2016 -0400

    Closer adherence to the reveal module model.

commit 0ebb57e9e6a4d1909570ead6e4636a59f7a80e80
Author: Chris Hallberg <crhallberg@gmail.com>
Date:   Tue Mar 29 12:32:37 2016 -0400

    Register and init in VuFind.
parent 1b5a9829
Branches
Tags
No related merge requests found
/*global Cookies, VuFind */
VuFind.cart = (function() {
VuFind.register('cart', function() {
var _COOKIE = 'vufind_cart';
var _COOKIE_SOURCES = 'vufind_cart_src';
var _COOKIE_DELIM = "\t";
......@@ -165,6 +165,33 @@ VuFind.cart = (function() {
}
}
var init = function() {
// Record buttons
var $cartId = $('.cartId');
if($cartId.length > 0) {
$cartId.each(function() {
var cartId = this.value.split('|');
var currentId = cartId[1];
var currentSource = cartId[0];
var $parent = $(this).parent();
$parent.find('.cart-add.correct,.cart-remove.correct').removeClass('correct hidden');
$parent.find('.cart-add').click(function() {
addItem(currentId,currentSource);
$parent.find('.cart-add,.cart-remove').toggleClass('hidden');
});
$parent.find('.cart-remove').click(function() {
removeItem(currentId,currentSource);
$parent.find('.cart-add,.cart-remove').toggleClass('hidden');
});
});
} else {
// Search results
var $form = $('form[name="bulkActionForm"]');
_registerUpdate($form);
}
$("#updateCart, #bottom_updateCart").popover({content:'', html:true, trigger:'manual'});
};
// Reveal
return {
// Methods
......@@ -173,36 +200,10 @@ VuFind.cart = (function() {
getFullItems: getFullItems,
updateCount: updateCount,
setDomain: setDomain,
// Lightbox handler
// Setup
ready: function() {
// Record buttons
var $cartId = $('.cartId');
if($cartId.length > 0) {
$cartId.each(function() {
var cartId = this.value.split('|');
var currentId = cartId[1];
var currentSource = cartId[0];
var $parent = $(this).parent();
$parent.find('.cart-add.correct,.cart-remove.correct').removeClass('correct hidden');
$parent.find('.cart-add').click(function() {
addItem(currentId,currentSource);
$parent.find('.cart-add,.cart-remove').toggleClass('hidden');
});
$parent.find('.cart-remove').click(function() {
removeItem(currentId,currentSource);
$parent.find('.cart-add,.cart-remove').toggleClass('hidden');
});
});
} else {
// Search results
var $form = $('form[name="bulkActionForm"]');
_registerUpdate($form);
}
$("#updateCart, #bottom_updateCart").popover({content:'', html:true, trigger:'manual'});
}
// Init
init: init
};
})();
});
// Building an array and checking indexes prevents a race situation
// We want to prioritize empty over printing
......@@ -220,5 +221,3 @@ var cartFormHandler = function(event, data) {
}
document.addEventListener('VuFind.lightbox.closed', VuFind.cart.updateCount, false);
$(document).ready(VuFind.cart.ready);
......@@ -6,8 +6,19 @@ window.console = window.console || {log: function () {}};
var VuFind = (function() {
var defaultSearchBackend = null;
var path = null;
var _submodules = [];
var _translations = {};
var register = function(name, module) {
_submodules.push(name);
this[name] = 'function' == typeof module ? module() : module;
};
var init = function() {
for (var i=0; i<_submodules.length; i++) {
this[_submodules[i]].init();
}
};
var addTranslations = function(s) {
for (var i in s) {
_translations[i] = s[i];
......@@ -23,6 +34,8 @@ var VuFind = (function() {
path: path,
addTranslations: addTranslations,
init: init,
register: register,
translate: translate
};
})();
......@@ -226,6 +239,8 @@ function keyboardShortcuts() {
}
$(document).ready(function() {
// Start up all of our submodules
VuFind.init();
// Setup search autocomplete
setupAutocomplete();
// Off canvas
......
/*global $, document, CustomEvent, VuFind, window */
VuFind.lightbox = (function() {
VuFind.register('lightbox', function() {
// State
var _originalUrl = false;
var _currentUrl = false;
......@@ -293,6 +293,30 @@ VuFind.lightbox = (function() {
$('form[data-lightbox] [type=submit]').click(_storeClickedStatus);
};
var reset = function() {
_html(VuFind.translate('loading') + '...');
_originalUrl = false;
_currentUrl = false;
_lightboxTitle = '';
};
var init = function() {
_modal = $('#modal');
_modalBody = _modal.find('.modal-body');
_modal.on('hide.bs.modal', function() {
if (VuFind.lightbox.refreshOnClose) {
_refreshPage();
}
_emit('VuFind.lightbox.closing');
});
_modal.on('hidden.bs.modal', function() {
VuFind.lightbox.reset();
_emit('VuFind.lightbox.closed');
});
VuFind.modal = function(cmd) { _modal.modal(cmd); };
bind();
};
// Reveal
return {
// Properties
......@@ -304,32 +328,9 @@ VuFind.lightbox = (function() {
bind: bind,
flashMessage: flashMessage,
reload: reload,
reset: function() {
_html(VuFind.translate('loading') + '...');
_originalUrl = false;
_currentUrl = false;
_lightboxTitle = '';
},
// Ready
ready: function() {
_modal = $('#modal');
_modalBody = _modal.find('.modal-body');
_modal.on('hide.bs.modal', function() {
if (VuFind.lightbox.refreshOnClose) {
_refreshPage();
}
_emit('VuFind.lightbox.closing');
});
_modal.on('hidden.bs.modal', function() {
VuFind.lightbox.reset();
_emit('VuFind.lightbox.closed');
});
VuFind.modal = function(cmd) { _modal.modal(cmd); };
bind();
}
// Reset
reset: reset,
// Init
init: init
};
})();
$(document).ready(VuFind.lightbox.ready);
});
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