From b7e8e7cc5b73c1234cf1aaaa827724ad8e1f6703 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Tue, 4 Jun 2013 22:39:14 -0400 Subject: [PATCH 1/7] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index f5b673f..07a5b12 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,9 @@ The jQuery virtual stack plugin Check out the [Project Page](http://librarylab.law.harvard.edu/stackview/demo) for more information. +## Getting Started +Download [jquery.stackview.min.js](./lib/jquery.stackview.min.js) + ## Development A single concatenated and minified `jquery.stackview.min.js` file containing Stack View and all its dependencies is located in `/lib`. Developers making changes to the project should do so in `/src/js` and compile the minified file by running `make js`. If any files in `/src` are added or renamed, they should be added to this list of source files in `Makefile`. From fb71eba4d87c859a2d43dc3b27f74e82c6ec1c76 Mon Sep 17 00:00:00 2001 From: Seth Woodworth Date: Thu, 25 Jul 2013 11:16:37 -0400 Subject: [PATCH 2/7] 'vim :retab :whitespaceify' automatic commit --- src/js/jquery.easing.1.3.js | 324 +++---- src/js/jquery.stackview.base.js | 1116 ++++++++++++------------- src/js/jquery.stackview.infinite.js | 78 +- src/js/jquery.stackview.ministack.js | 56 +- src/js/jquery.stackview.navigation.js | 124 +-- src/js/jquery.stackview.stackcache.js | 24 +- src/js/jquery.stackview.templates.js | 60 +- src/js/microtemplating.js | 52 +- src/scss/_book.scss | 114 +-- src/scss/_heatmap.scss | 236 +++--- src/scss/_ministack.scss | 72 +- src/scss/_mixins.scss | 118 +-- src/scss/_navigation.scss | 96 +-- src/scss/_serial.scss | 78 +- src/scss/_soundrecording.scss | 136 +-- src/scss/_videofilm.scss | 124 +-- src/scss/_webpage.scss | 118 +-- src/scss/jquery.stackview.scss | 248 +++--- 18 files changed, 1587 insertions(+), 1587 deletions(-) diff --git a/src/js/jquery.easing.1.3.js b/src/js/jquery.easing.1.3.js index ef74321..d6bac68 100644 --- a/src/js/jquery.easing.1.3.js +++ b/src/js/jquery.easing.1.3.js @@ -5,33 +5,33 @@ * to offer multiple easing options * * TERMS OF USE - jQuery Easing - * - * Open source under the BSD License. - * + * + * Open source under the BSD License. + * * Copyright © 2008 George McGinley Smith * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list of + * + * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * - * Neither the name of the author nor the names of contributors may be used to endorse + * + * Neither the name of the author nor the names of contributors may be used to endorse * or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. * */ @@ -40,166 +40,166 @@ jQuery.easing['jswing'] = jQuery.easing['swing']; jQuery.extend( jQuery.easing, { - def: 'easeOutQuad', - swing: function (x, t, b, c, d) { - //alert(jQuery.easing.default); - return jQuery.easing[jQuery.easing.def](x, t, b, c, d); - }, - easeInQuad: function (x, t, b, c, d) { - return c*(t/=d)*t + b; - }, - easeOutQuad: function (x, t, b, c, d) { - return -c *(t/=d)*(t-2) + b; - }, - easeInOutQuad: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t + b; - return -c/2 * ((--t)*(t-2) - 1) + b; - }, - easeInCubic: function (x, t, b, c, d) { - return c*(t/=d)*t*t + b; - }, - easeOutCubic: function (x, t, b, c, d) { - return c*((t=t/d-1)*t*t + 1) + b; - }, - easeInOutCubic: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t + b; - return c/2*((t-=2)*t*t + 2) + b; - }, - easeInQuart: function (x, t, b, c, d) { - return c*(t/=d)*t*t*t + b; - }, - easeOutQuart: function (x, t, b, c, d) { - return -c * ((t=t/d-1)*t*t*t - 1) + b; - }, - easeInOutQuart: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t*t + b; - return -c/2 * ((t-=2)*t*t*t - 2) + b; - }, - easeInQuint: function (x, t, b, c, d) { - return c*(t/=d)*t*t*t*t + b; - }, - easeOutQuint: function (x, t, b, c, d) { - return c*((t=t/d-1)*t*t*t*t + 1) + b; - }, - easeInOutQuint: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; - return c/2*((t-=2)*t*t*t*t + 2) + b; - }, - easeInSine: function (x, t, b, c, d) { - return -c * Math.cos(t/d * (Math.PI/2)) + c + b; - }, - easeOutSine: function (x, t, b, c, d) { - return c * Math.sin(t/d * (Math.PI/2)) + b; - }, - easeInOutSine: function (x, t, b, c, d) { - return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; - }, - easeInExpo: function (x, t, b, c, d) { - return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; - }, - easeOutExpo: function (x, t, b, c, d) { - return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; - }, - easeInOutExpo: function (x, t, b, c, d) { - if (t==0) return b; - if (t==d) return b+c; - if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; - return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; - }, - easeInCirc: function (x, t, b, c, d) { - return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; - }, - easeOutCirc: function (x, t, b, c, d) { - return c * Math.sqrt(1 - (t=t/d-1)*t) + b; - }, - easeInOutCirc: function (x, t, b, c, d) { - if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; - return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; - }, - easeInElastic: function (x, t, b, c, d) { - var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); - return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; - }, - easeOutElastic: function (x, t, b, c, d) { - var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); - return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; - }, - easeInOutElastic: function (x, t, b, c, d) { - var s=1.70158;var p=0;var a=c; - if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); - if (a < Math.abs(c)) { a=c; var s=p/4; } - else var s = p/(2*Math.PI) * Math.asin (c/a); - if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; - return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; - }, - easeInBack: function (x, t, b, c, d, s) { - if (s == undefined) s = 1.70158; - return c*(t/=d)*t*((s+1)*t - s) + b; - }, - easeOutBack: function (x, t, b, c, d, s) { - if (s == undefined) s = 1.70158; - return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; - }, - easeInOutBack: function (x, t, b, c, d, s) { - if (s == undefined) s = 1.70158; - if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; - return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; - }, - easeInBounce: function (x, t, b, c, d) { - return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b; - }, - easeOutBounce: function (x, t, b, c, d) { - if ((t/=d) < (1/2.75)) { - return c*(7.5625*t*t) + b; - } else if (t < (2/2.75)) { - return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; - } else if (t < (2.5/2.75)) { - return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; - } else { - return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; - } - }, - easeInOutBounce: function (x, t, b, c, d) { - if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b; - return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b; - } + def: 'easeOutQuad', + swing: function (x, t, b, c, d) { + //alert(jQuery.easing.default); + return jQuery.easing[jQuery.easing.def](x, t, b, c, d); + }, + easeInQuad: function (x, t, b, c, d) { + return c*(t/=d)*t + b; + }, + easeOutQuad: function (x, t, b, c, d) { + return -c *(t/=d)*(t-2) + b; + }, + easeInOutQuad: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t + b; + return -c/2 * ((--t)*(t-2) - 1) + b; + }, + easeInCubic: function (x, t, b, c, d) { + return c*(t/=d)*t*t + b; + }, + easeOutCubic: function (x, t, b, c, d) { + return c*((t=t/d-1)*t*t + 1) + b; + }, + easeInOutCubic: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t + b; + return c/2*((t-=2)*t*t + 2) + b; + }, + easeInQuart: function (x, t, b, c, d) { + return c*(t/=d)*t*t*t + b; + }, + easeOutQuart: function (x, t, b, c, d) { + return -c * ((t=t/d-1)*t*t*t - 1) + b; + }, + easeInOutQuart: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t*t + b; + return -c/2 * ((t-=2)*t*t*t - 2) + b; + }, + easeInQuint: function (x, t, b, c, d) { + return c*(t/=d)*t*t*t*t + b; + }, + easeOutQuint: function (x, t, b, c, d) { + return c*((t=t/d-1)*t*t*t*t + 1) + b; + }, + easeInOutQuint: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; + return c/2*((t-=2)*t*t*t*t + 2) + b; + }, + easeInSine: function (x, t, b, c, d) { + return -c * Math.cos(t/d * (Math.PI/2)) + c + b; + }, + easeOutSine: function (x, t, b, c, d) { + return c * Math.sin(t/d * (Math.PI/2)) + b; + }, + easeInOutSine: function (x, t, b, c, d) { + return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; + }, + easeInExpo: function (x, t, b, c, d) { + return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; + }, + easeOutExpo: function (x, t, b, c, d) { + return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; + }, + easeInOutExpo: function (x, t, b, c, d) { + if (t==0) return b; + if (t==d) return b+c; + if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; + return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; + }, + easeInCirc: function (x, t, b, c, d) { + return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; + }, + easeOutCirc: function (x, t, b, c, d) { + return c * Math.sqrt(1 - (t=t/d-1)*t) + b; + }, + easeInOutCirc: function (x, t, b, c, d) { + if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; + return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; + }, + easeInElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + }, + easeOutElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; + }, + easeInOutElastic: function (x, t, b, c, d) { + var s=1.70158;var p=0;var a=c; + if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); + if (a < Math.abs(c)) { a=c; var s=p/4; } + else var s = p/(2*Math.PI) * Math.asin (c/a); + if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; + return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; + }, + easeInBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + return c*(t/=d)*t*((s+1)*t - s) + b; + }, + easeOutBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; + }, + easeInOutBack: function (x, t, b, c, d, s) { + if (s == undefined) s = 1.70158; + if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; + return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; + }, + easeInBounce: function (x, t, b, c, d) { + return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b; + }, + easeOutBounce: function (x, t, b, c, d) { + if ((t/=d) < (1/2.75)) { + return c*(7.5625*t*t) + b; + } else if (t < (2/2.75)) { + return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; + } else if (t < (2.5/2.75)) { + return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; + } else { + return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; + } + }, + easeInOutBounce: function (x, t, b, c, d) { + if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b; + return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b; + } }); /* * * TERMS OF USE - EASING EQUATIONS - * - * Open source under the BSD License. - * + * + * Open source under the BSD License. + * * Copyright © 2001 Robert Penner * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, + * + * Redistribution and use in source and binary forms, with or without modification, * are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright notice, this list of + * + * Redistributions of source code must retain the above copyright notice, this list of * conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials + * Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials * provided with the distribution. - * - * Neither the name of the author nor the names of contributors may be used to endorse + * + * Neither the name of the author nor the names of contributors may be used to endorse * or promote products derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE - * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED + * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED - * OF THE POSSIBILITY OF SUCH DAMAGE. + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED + * OF THE POSSIBILITY OF SUCH DAMAGE. * - */ \ No newline at end of file + */ diff --git a/src/js/jquery.stackview.base.js b/src/js/jquery.stackview.base.js index 9d0c3c3..fa8e2f1 100644 --- a/src/js/jquery.stackview.base.js +++ b/src/js/jquery.stackview.base.js @@ -1,561 +1,561 @@ /*! - Stack View - The jQuery virtual stack plugin - by The Harvard Library Innovation Lab - - Dual licensed under MIT and GPL. + Stack View - The jQuery virtual stack plugin + by The Harvard Library Innovation Lab + + Dual licensed under MIT and GPL. */ (function($, window, document, undefined) { - var events, - plugin = 'stackView', - StackView, - types = {}; - - events = { - init: 'stackview.init', - item_added: 'stackview.itemadded', - item_removed: 'stackview.itemremoved', - page_load: 'stackview.pageload' - }; - - /* - #get_type - */ - var get_type = function(item) { - var type; - - $.each(types, function(key, val) { - if (val.match(item)) { - type = val; - return false; - } - }); - - return type; - }; - - /* - #render_items(StackView, array [, jQuery]) - Private - - Takes a StackView instance, an array of result items, and an optional - jQuery object. Renders a DOM element for each of the items and - appends it to the stack's item list. If [placeholder] is passed in the - items take the its spot in the DOM. - */ - var render_items = function(stack, docs, $placeholder) { - var action = $placeholder ? 'before' : 'append', - $pivot = $placeholder ? - $placeholder : - stack.$element.find(stack.options.selectors.item_list); - - $.each(docs, function(i, item) { - var type = get_type(item), - $item; - - if (type == null) { - return true; - } - - $item = $(tmpl(type.template, type.adapter(item, stack.options))); - $item.data('stackviewItem', item); - $pivot[action]($item); - }); - - if ($placeholder) { - $placeholder.remove(); - } - - }; - - /* - #calculate_params(StackView) - Private - - Takes a StackView instance and returns the parameters for the next page. - If the Stack uses loc_sort_order, this adjusts the query for that case. - Returns a plain object with key:value params to be used by $.param. - */ - var calculate_params = function(stack) { - var opts = stack.options, - params; - - params = { - start: stack.page * stack.options.items_per_page, - limit: stack.options.items_per_page, - search_type: stack.options.search_type, - query: stack.options.query - }; - - if (params.search_type === 'loc_sort_order') { - params.start = 0; - - if (stack.page === 0) { - stack.loc = { - low: opts.id - Math.floor(opts.items_per_page / 2), - high: opts.id + Math.floor(opts.items_per_page / 2) - }; - params.query = [ - '[', - stack.loc.low, - '%20TO%20', - stack.loc.high, - ']' - ].join(''); - } - else if (stack.direction === 'down') { - params.query = [ - '[', - stack.loc.high + 1, - '%20TO%20', - stack.loc.high + opts.items_per_page + 1, - ']' - ].join(''); - stack.loc.high = stack.loc.high + opts.items_per_page + 1; - } - else if (stack.direction === 'up') { - params.query = [ - '[', - stack.loc.low - opts.items_per_page - 1, - '%20TO%20', - stack.loc.low - 1, - ']' - ].join(''); - stack.loc.low = stack.loc.low - opts.items_per_page - 1; - } - } - - return params; - }; - - /* - #fetch_page(StackView, function) - Private - - Takes a StackView instance and a callback function. Retrieves the - next page according to the URL and other options of the StackView - instance. When the page is finished fetching, the callback is - invoked, passing in the array of items. - */ - var fetch_page = function(stack, callback) { - var params = calculate_params(stack), - querystring = $.param(params), - cachedResult; - - stack.page++; - cachedResult = window.stackCache.get(stack.options.url + querystring); - - if (cachedResult) { - callback(cachedResult); - } - else { - $.ajax({ - url: stack.options.url, - data: querystring, - dataType: stack.options.jsonp ? 'jsonp' : 'json', - success: function(data) { - window.stackCache.set( - stack.options.url + params, - data, - stack.options.cache_ttl - ); - callback(data); - } - }); - } - }; - - - - - /* StackView constructor, set up instance properties and call init. */ - StackView = function(elem, opts) { - this.element = elem; - this.$element = $(elem); - this.options = $.extend({}, StackView.defaults, opts); - this.page = 0; - this.finished = { - up: false, - down: false - }; - this.loc = { - low: null, - high: null - }; - this.direction = 'down'; - this.init(); - }; - - /* Static properties and functions */ - $.extend(true, StackView, { - - /* - The default options for a StackView instance. - - cache_ttl - How long a request will stay in cache. - - data - An alternative to URL, used for static data. Accepts a typical - URL response object or a simple array of item objects. - - id - When using a search type of loc_sort_order, this is the id of - the item that the search centers around. - - items_per_page - The number of items to request each page. - - jsonp - If true, the URL will expect a JSONP request. callback=? will be - added to the request parameters. - - query - The query passed to the script at URL. Passed as the - query parameter. - - ribbon - The text of the ribbon at the top of the stack. - - search_type - The type of search to be performed by the script at URL. This is - passed to the script as the search_type parameter. - - selectors - A number of selectors that are frequently used by the code to - identify key structures. - - item - A single item in the stack. - - item_list - Container around all of the stack items. - - ribbon - The text ribbon at the top of the stack. - - url - The URL to send requests to for item data. - */ - defaults: { - cache_ttl: 60, - data: '', - id: null, - items_per_page: 10, - jsonp: false, - query: '', - ribbon: 'Stack View', - search_type: 'keyword', - selectors: { - item: '.stack-item', - item_list: '.stack-items', - ribbon: '.ribbon' - }, - url: 'basic.json' - }, - - /* - StackView.get_heat(number) - - Takes a value between 0 and 100 and returns a number to be used with - heat classes to indicate popularity. - */ - utils: { - get_heat: function(scaled_value) { - return scaled_value === 100 ? 10 : Math.floor(scaled_value / 10) + 1; - } - }, - - /* - StackView.register_type(object) - - Registers an item type to be used by the stack. A Type object - has the following properties: - - name: string - A unique, identifying name of the item type. - - match: function(obj) -> obj - A function that takes a stack item and returns true if the - item matches this type. Example: - - match: function(item) { return item.type === 'book' } - - adapter: function(obj, obj) -> obj - This function allows the user to make transformations to the - item data before rendering it to the template. It takes as - parameters a raw item that matches the match function and the - options from the StackView instance. It should return an object - to render against "template." If no changes to the raw data need - to be made, the simplest value for this can be: - - adapter: function(item) { return item; } - - template: string - A microtemplating template to render for this type in the stack. - Receives as its data the return value from "adapter." - - */ - register_type: function(obj) { - types[obj.name] = obj; - }, - - /* - StackView.get_types() - - Returns the hash of item types. - */ - get_types: function() { - return types; - } - }); - - /* - StackView public methods - */ - $.extend(true, StackView.prototype, { - - /* - #init() - - Sets up the initial states of a stack. Including: - - Creating the HTML skeleton. - - Binding zIndex ordering to the pageload event. - - Loading the first page. - - Firing the init event. - */ - init: function() { - var that = this; - - this.$element - .html(tmpl(StackView.templates.scaffold, { - ribbon: this.options.ribbon - })) - .addClass('stackview') - .bind(events.page_load, function() { - that.zIndex(); - }); - - this.$element.data('stackviewObject', this); - this.$element.trigger(events.init); - this.next_page(); - }, - - /* - #next_page() - - Loads the next page of stack items. If we've already hit the - last page, this function does nothing. - */ - next_page: function() { - var $placeholder = $(tmpl(StackView.templates.placeholder, {})), - that = this, - opts = this.options; - - if (this.finished.down) { - return; - } - - this.direction = 'down'; - if (opts.data) { - render_items(this, opts.data.docs ? opts.data.docs : opts.data); - this.finished.down = true; - this.$element.trigger(events.page_load, [opts.data]); - } - else if (opts.url) { - this.$element - .find(opts.selectors.item_list) - .append($placeholder); - fetch_page(this, function(data) { - render_items(that, data.docs, $placeholder); - if (parseInt(data.start, 10) === -1) { - that.finished.down = true; - } - that.$element.trigger(events.page_load, [data]); - }); - } - }, - - /* - #prev_page() - - Loads the previous page of stack items. If we've already hit the - first page this function does nothing. This function only works - for stacks using the loc_sort_order search type. - */ - prev_page: function() { - var $placeholder = $(tmpl(StackView.templates.placeholder, {})), - opts = this.options, - that = this, - $oldMarker = that.$element.find(opts.selectors.item).first(); - - if (opts.search_type !== 'loc_sort_order' || this.finished.up) { - return; - } - - this.direction = 'up'; - this.$element.find(opts.selectors.item_list).prepend($placeholder); - fetch_page(this, function(data) { - var oldTop = $oldMarker.position().top; - - render_items(that, data.docs, $placeholder); - if (that.page > 1) { - that.$element.find(opts.selectors.item_list).animate({ - 'scrollTop': '+=' + ($oldMarker.position().top - oldTop) - }, 0); - } - if (parseInt(data.start, 10) === -1) { - that.finished.up = true; - } - that.$element.trigger(events.page_load, [data]); - }); - }, - - /* - #add([number,] object) - - Adds the specified item object to the stack, at the given index if - provided or at the end (bottom) of the stack if index is not given. - */ - add: function() { - var $items = this.$element.find(this.options.selectors.item), - index, item, type, action, $pivot, $item; - - if (typeof(arguments[0]) === 'number') { - index = arguments[0]; - item = arguments[1]; - } - else { - index = $items.length; - item = arguments[0]; - } - - if (index > $items.length || index < 0) { - return; - } - else if (index === $items.length) { - $pivot = $items.last(); - action = 'after'; - } - else { - $pivot = $items.eq(index); - action = 'before'; - } - - type = get_type(item); - if (type == null) { - return; - } - $item = $(tmpl(type.template, type.adapter(item, this.options))); - - $item.data('stackviewItem', item); - $pivot[action]($item); - this.zIndex(); - this.$element.trigger(events.item_added); - }, - - /* - #remove(number | object) - - If a number is given, it removes the item at that index. If an - object is given, this method finds the element that represents that - item and removes it. - */ - remove: function(arg) { - var $items = this.$element.find(this.options.selectors.item), - $found, data, index; - - if (typeof(arg) === 'number') { - $found = $items.eq(arg); - } - else if (arg.nodeType || arg.jquery){ - $found = $(arg); - } - else { - $items.each(function(i, el) { - var $el = $(el); - - if ($el.data('stackviewItem') === arg) { - $found = $el; - return false; - } - }); - } - - if ($found == null || !$found.length) { - return; - } - - $found.detach(); - data = $found.data('stackviewItem'); - this.$element.trigger(events.item_removed, [data]); - return $found; - }, - - - /* - #getData() - - Returns an array of all the item objects currently in the stack. - */ - getData: function() { - var data = []; - - this.$element.find(this.options.selectors.item).each(function() { - data.push($(this).data('stackviewItem')); - }); - - return data; - }, - - /* - #zIndex(boolean) - - Reverses the natural flow order of the stack items by giving those - earlier in the source (higher on the stack) a higher z-index. If - passed true, it will instead assign z-indexes in normal flow order. - */ - zIndex: function(reverse) { - var $items = this.$element.find(this.options.selectors.item), - length = $items.length, - i = 0, - z = reverse ? 0 : $items.length - 1; - - while (i < length) { - $items.eq(i).css('z-index', z); - z = z + (reverse ? 1 : -1); - i++; - } - } - }); - - /* - If .stackView has not been called on an element, the first call will - initialize the plugin. Subsequent calls expect a method from the - StackView class. Any method that returns undefined is assumed to - chain. If the method returns a value, only the value from the first - element in the jQuery set will be returned, the same as other getters - in jQuery. - */ - $.fn[plugin] = function(method) { - var response, - args = Array.prototype.slice.call(arguments, 1); - - this.each(function(i, el) { - var $el = $(el), - obj = $el.data('stackviewObject'); - - if (!obj) { - new StackView(el, method); - } - else if (obj[method]) { - var methodResponse = obj[method].apply(obj, args); - - if (response === undefined && methodResponse !== undefined) { - response = methodResponse; - } - } - }); - - return response === undefined ? this : response; - }; - - /* Expose the StackView class for extension */ - window.StackView = StackView; -})(jQuery, window, document); \ No newline at end of file + var events, + plugin = 'stackView', + StackView, + types = {}; + + events = { + init: 'stackview.init', + item_added: 'stackview.itemadded', + item_removed: 'stackview.itemremoved', + page_load: 'stackview.pageload' + }; + + /* + #get_type + */ + var get_type = function(item) { + var type; + + $.each(types, function(key, val) { + if (val.match(item)) { + type = val; + return false; + } + }); + + return type; + }; + + /* + #render_items(StackView, array [, jQuery]) - Private + + Takes a StackView instance, an array of result items, and an optional + jQuery object. Renders a DOM element for each of the items and + appends it to the stack's item list. If [placeholder] is passed in the + items take the its spot in the DOM. + */ + var render_items = function(stack, docs, $placeholder) { + var action = $placeholder ? 'before' : 'append', + $pivot = $placeholder ? + $placeholder : + stack.$element.find(stack.options.selectors.item_list); + + $.each(docs, function(i, item) { + var type = get_type(item), + $item; + + if (type == null) { + return true; + } + + $item = $(tmpl(type.template, type.adapter(item, stack.options))); + $item.data('stackviewItem', item); + $pivot[action]($item); + }); + + if ($placeholder) { + $placeholder.remove(); + } + + }; + + /* + #calculate_params(StackView) - Private + + Takes a StackView instance and returns the parameters for the next page. + If the Stack uses loc_sort_order, this adjusts the query for that case. + Returns a plain object with key:value params to be used by $.param. + */ + var calculate_params = function(stack) { + var opts = stack.options, + params; + + params = { + start: stack.page * stack.options.items_per_page, + limit: stack.options.items_per_page, + search_type: stack.options.search_type, + query: stack.options.query + }; + + if (params.search_type === 'loc_sort_order') { + params.start = 0; + + if (stack.page === 0) { + stack.loc = { + low: opts.id - Math.floor(opts.items_per_page / 2), + high: opts.id + Math.floor(opts.items_per_page / 2) + }; + params.query = [ + '[', + stack.loc.low, + '%20TO%20', + stack.loc.high, + ']' + ].join(''); + } + else if (stack.direction === 'down') { + params.query = [ + '[', + stack.loc.high + 1, + '%20TO%20', + stack.loc.high + opts.items_per_page + 1, + ']' + ].join(''); + stack.loc.high = stack.loc.high + opts.items_per_page + 1; + } + else if (stack.direction === 'up') { + params.query = [ + '[', + stack.loc.low - opts.items_per_page - 1, + '%20TO%20', + stack.loc.low - 1, + ']' + ].join(''); + stack.loc.low = stack.loc.low - opts.items_per_page - 1; + } + } + + return params; + }; + + /* + #fetch_page(StackView, function) - Private + + Takes a StackView instance and a callback function. Retrieves the + next page according to the URL and other options of the StackView + instance. When the page is finished fetching, the callback is + invoked, passing in the array of items. + */ + var fetch_page = function(stack, callback) { + var params = calculate_params(stack), + querystring = $.param(params), + cachedResult; + + stack.page++; + cachedResult = window.stackCache.get(stack.options.url + querystring); + + if (cachedResult) { + callback(cachedResult); + } + else { + $.ajax({ + url: stack.options.url, + data: querystring, + dataType: stack.options.jsonp ? 'jsonp' : 'json', + success: function(data) { + window.stackCache.set( + stack.options.url + params, + data, + stack.options.cache_ttl + ); + callback(data); + } + }); + } + }; + + + + + /* StackView constructor, set up instance properties and call init. */ + StackView = function(elem, opts) { + this.element = elem; + this.$element = $(elem); + this.options = $.extend({}, StackView.defaults, opts); + this.page = 0; + this.finished = { + up: false, + down: false + }; + this.loc = { + low: null, + high: null + }; + this.direction = 'down'; + this.init(); + }; + + /* Static properties and functions */ + $.extend(true, StackView, { + + /* + The default options for a StackView instance. + + cache_ttl + How long a request will stay in cache. + + data + An alternative to URL, used for static data. Accepts a typical + URL response object or a simple array of item objects. + + id + When using a search type of loc_sort_order, this is the id of + the item that the search centers around. + + items_per_page + The number of items to request each page. + + jsonp + If true, the URL will expect a JSONP request. callback=? will be + added to the request parameters. + + query + The query passed to the script at URL. Passed as the + query parameter. + + ribbon + The text of the ribbon at the top of the stack. + + search_type + The type of search to be performed by the script at URL. This is + passed to the script as the search_type parameter. + + selectors + A number of selectors that are frequently used by the code to + identify key structures. + + item + A single item in the stack. + + item_list + Container around all of the stack items. + + ribbon + The text ribbon at the top of the stack. + + url + The URL to send requests to for item data. + */ + defaults: { + cache_ttl: 60, + data: '', + id: null, + items_per_page: 10, + jsonp: false, + query: '', + ribbon: 'Stack View', + search_type: 'keyword', + selectors: { + item: '.stack-item', + item_list: '.stack-items', + ribbon: '.ribbon' + }, + url: 'basic.json' + }, + + /* + StackView.get_heat(number) + + Takes a value between 0 and 100 and returns a number to be used with + heat classes to indicate popularity. + */ + utils: { + get_heat: function(scaled_value) { + return scaled_value === 100 ? 10 : Math.floor(scaled_value / 10) + 1; + } + }, + + /* + StackView.register_type(object) + + Registers an item type to be used by the stack. A Type object + has the following properties: + + name: string + A unique, identifying name of the item type. + + match: function(obj) -> obj + A function that takes a stack item and returns true if the + item matches this type. Example: + + match: function(item) { return item.type === 'book' } + + adapter: function(obj, obj) -> obj + This function allows the user to make transformations to the + item data before rendering it to the template. It takes as + parameters a raw item that matches the match function and the + options from the StackView instance. It should return an object + to render against "template." If no changes to the raw data need + to be made, the simplest value for this can be: + + adapter: function(item) { return item; } + + template: string + A microtemplating template to render for this type in the stack. + Receives as its data the return value from "adapter." + + */ + register_type: function(obj) { + types[obj.name] = obj; + }, + + /* + StackView.get_types() + + Returns the hash of item types. + */ + get_types: function() { + return types; + } + }); + + /* + StackView public methods + */ + $.extend(true, StackView.prototype, { + + /* + #init() + + Sets up the initial states of a stack. Including: + - Creating the HTML skeleton. + - Binding zIndex ordering to the pageload event. + - Loading the first page. + - Firing the init event. + */ + init: function() { + var that = this; + + this.$element + .html(tmpl(StackView.templates.scaffold, { + ribbon: this.options.ribbon + })) + .addClass('stackview') + .bind(events.page_load, function() { + that.zIndex(); + }); + + this.$element.data('stackviewObject', this); + this.$element.trigger(events.init); + this.next_page(); + }, + + /* + #next_page() + + Loads the next page of stack items. If we've already hit the + last page, this function does nothing. + */ + next_page: function() { + var $placeholder = $(tmpl(StackView.templates.placeholder, {})), + that = this, + opts = this.options; + + if (this.finished.down) { + return; + } + + this.direction = 'down'; + if (opts.data) { + render_items(this, opts.data.docs ? opts.data.docs : opts.data); + this.finished.down = true; + this.$element.trigger(events.page_load, [opts.data]); + } + else if (opts.url) { + this.$element + .find(opts.selectors.item_list) + .append($placeholder); + fetch_page(this, function(data) { + render_items(that, data.docs, $placeholder); + if (parseInt(data.start, 10) === -1) { + that.finished.down = true; + } + that.$element.trigger(events.page_load, [data]); + }); + } + }, + + /* + #prev_page() + + Loads the previous page of stack items. If we've already hit the + first page this function does nothing. This function only works + for stacks using the loc_sort_order search type. + */ + prev_page: function() { + var $placeholder = $(tmpl(StackView.templates.placeholder, {})), + opts = this.options, + that = this, + $oldMarker = that.$element.find(opts.selectors.item).first(); + + if (opts.search_type !== 'loc_sort_order' || this.finished.up) { + return; + } + + this.direction = 'up'; + this.$element.find(opts.selectors.item_list).prepend($placeholder); + fetch_page(this, function(data) { + var oldTop = $oldMarker.position().top; + + render_items(that, data.docs, $placeholder); + if (that.page > 1) { + that.$element.find(opts.selectors.item_list).animate({ + 'scrollTop': '+=' + ($oldMarker.position().top - oldTop) + }, 0); + } + if (parseInt(data.start, 10) === -1) { + that.finished.up = true; + } + that.$element.trigger(events.page_load, [data]); + }); + }, + + /* + #add([number,] object) + + Adds the specified item object to the stack, at the given index if + provided or at the end (bottom) of the stack if index is not given. + */ + add: function() { + var $items = this.$element.find(this.options.selectors.item), + index, item, type, action, $pivot, $item; + + if (typeof(arguments[0]) === 'number') { + index = arguments[0]; + item = arguments[1]; + } + else { + index = $items.length; + item = arguments[0]; + } + + if (index > $items.length || index < 0) { + return; + } + else if (index === $items.length) { + $pivot = $items.last(); + action = 'after'; + } + else { + $pivot = $items.eq(index); + action = 'before'; + } + + type = get_type(item); + if (type == null) { + return; + } + $item = $(tmpl(type.template, type.adapter(item, this.options))); + + $item.data('stackviewItem', item); + $pivot[action]($item); + this.zIndex(); + this.$element.trigger(events.item_added); + }, + + /* + #remove(number | object) + + If a number is given, it removes the item at that index. If an + object is given, this method finds the element that represents that + item and removes it. + */ + remove: function(arg) { + var $items = this.$element.find(this.options.selectors.item), + $found, data, index; + + if (typeof(arg) === 'number') { + $found = $items.eq(arg); + } + else if (arg.nodeType || arg.jquery){ + $found = $(arg); + } + else { + $items.each(function(i, el) { + var $el = $(el); + + if ($el.data('stackviewItem') === arg) { + $found = $el; + return false; + } + }); + } + + if ($found == null || !$found.length) { + return; + } + + $found.detach(); + data = $found.data('stackviewItem'); + this.$element.trigger(events.item_removed, [data]); + return $found; + }, + + + /* + #getData() + + Returns an array of all the item objects currently in the stack. + */ + getData: function() { + var data = []; + + this.$element.find(this.options.selectors.item).each(function() { + data.push($(this).data('stackviewItem')); + }); + + return data; + }, + + /* + #zIndex(boolean) + + Reverses the natural flow order of the stack items by giving those + earlier in the source (higher on the stack) a higher z-index. If + passed true, it will instead assign z-indexes in normal flow order. + */ + zIndex: function(reverse) { + var $items = this.$element.find(this.options.selectors.item), + length = $items.length, + i = 0, + z = reverse ? 0 : $items.length - 1; + + while (i < length) { + $items.eq(i).css('z-index', z); + z = z + (reverse ? 1 : -1); + i++; + } + } + }); + + /* + If .stackView has not been called on an element, the first call will + initialize the plugin. Subsequent calls expect a method from the + StackView class. Any method that returns undefined is assumed to + chain. If the method returns a value, only the value from the first + element in the jQuery set will be returned, the same as other getters + in jQuery. + */ + $.fn[plugin] = function(method) { + var response, + args = Array.prototype.slice.call(arguments, 1); + + this.each(function(i, el) { + var $el = $(el), + obj = $el.data('stackviewObject'); + + if (!obj) { + new StackView(el, method); + } + else if (obj[method]) { + var methodResponse = obj[method].apply(obj, args); + + if (response === undefined && methodResponse !== undefined) { + response = methodResponse; + } + } + }); + + return response === undefined ? this : response; + }; + + /* Expose the StackView class for extension */ + window.StackView = StackView; +})(jQuery, window, document); diff --git a/src/js/jquery.stackview.infinite.js b/src/js/jquery.stackview.infinite.js index d284aba..35d54ad 100644 --- a/src/js/jquery.stackview.infinite.js +++ b/src/js/jquery.stackview.infinite.js @@ -5,42 +5,42 @@ to fire the base methods of next_page and prev_page. */ (function($, undefined) { - var $d = $(document), - infinite; - - /* Extend defaults */ - $.extend(StackView.defaults, { - infiniteScrollDistance: 100 - }); - - infinite = function(event) { - var $stack = $(event.target), - stack = $stack.data('stackviewObject'), - opts = stack.options, - $itemList, $items, opts, lastItemTop, triggerPoint, scrollCheck; - - $itemList = $stack.find(opts.selectors.item_list); - $items = $stack.find(opts.selectors.item); - - lastItemTop = $items.length ? $items.last().position().top : 0; - lastItemTop += $itemList.scrollTop(); - triggerPoint = lastItemTop - $stack.height() - opts.infiniteScrollDistance; - - scrollCheck = function() { - if (opts.search_type === 'loc_sort_order' && - $itemList.scrollTop() <= opts.infiniteScrollDistance) { - $itemList.unbind('scroll.stackview'); - $stack.stackView('prev_page'); - } - else if ($itemList.scrollTop() >= triggerPoint) { - $itemList.unbind('scroll.stackview'); - $stack.stackView('next_page'); - } - }; - - $itemList.bind('scroll.stackview', scrollCheck); - scrollCheck(); - }; - - $d.delegate('.stackview', 'stackview.pageload', infinite); -})(jQuery); \ No newline at end of file + var $d = $(document), + infinite; + + /* Extend defaults */ + $.extend(StackView.defaults, { + infiniteScrollDistance: 100 + }); + + infinite = function(event) { + var $stack = $(event.target), + stack = $stack.data('stackviewObject'), + opts = stack.options, + $itemList, $items, opts, lastItemTop, triggerPoint, scrollCheck; + + $itemList = $stack.find(opts.selectors.item_list); + $items = $stack.find(opts.selectors.item); + + lastItemTop = $items.length ? $items.last().position().top : 0; + lastItemTop += $itemList.scrollTop(); + triggerPoint = lastItemTop - $stack.height() - opts.infiniteScrollDistance; + + scrollCheck = function() { + if (opts.search_type === 'loc_sort_order' && + $itemList.scrollTop() <= opts.infiniteScrollDistance) { + $itemList.unbind('scroll.stackview'); + $stack.stackView('prev_page'); + } + else if ($itemList.scrollTop() >= triggerPoint) { + $itemList.unbind('scroll.stackview'); + $stack.stackView('next_page'); + } + }; + + $itemList.bind('scroll.stackview', scrollCheck); + scrollCheck(); + }; + + $d.delegate('.stackview', 'stackview.pageload', infinite); +})(jQuery); diff --git a/src/js/jquery.stackview.ministack.js b/src/js/jquery.stackview.ministack.js index 6d9cbd0..d7adf53 100644 --- a/src/js/jquery.stackview.ministack.js +++ b/src/js/jquery.stackview.ministack.js @@ -1,33 +1,33 @@ (function($, undefined) { - var $d = $(document), - StackView = window.StackView; + var $d = $(document), + StackView = window.StackView; - $.extend(true, StackView.defaults, { - classes: { - ministack: 'stackview-mini' - }, + $.extend(true, StackView.defaults, { + classes: { + ministack: 'stackview-mini' + }, - ministack: { - breakpoint: 220, - max_height_percentage: 100, - min_height_percentage: 80, - page_multiple: .08 - } - }); + ministack: { + breakpoint: 220, + max_height_percentage: 100, + min_height_percentage: 80, + page_multiple: .08 + } + }); - $d.delegate('.stackview', 'stackview.init', function(event) { - var $stack = $(event.target), - stack = $stack.data('stackviewObject'); + $d.delegate('.stackview', 'stackview.init', function(event) { + var $stack = $(event.target), + stack = $stack.data('stackviewObject'); - if ($stack.width() <= stack.options.ministack.breakpoint) { - $stack.addClass(stack.options.classes.ministack); - $.each([ - 'max_height_percentage', - 'min_height_percentage', - 'page_multiple' - ], function(i, el) { - stack.options.book[el] = stack.options.ministack[el]; - }); - } - }); -})(jQuery); \ No newline at end of file + if ($stack.width() <= stack.options.ministack.breakpoint) { + $stack.addClass(stack.options.classes.ministack); + $.each([ + 'max_height_percentage', + 'min_height_percentage', + 'page_multiple' + ], function(i, el) { + stack.options.book[el] = stack.options.ministack[el]; + }); + } + }); +})(jQuery); diff --git a/src/js/jquery.stackview.navigation.js b/src/js/jquery.stackview.navigation.js index c09a82d..15d9d73 100644 --- a/src/js/jquery.stackview.navigation.js +++ b/src/js/jquery.stackview.navigation.js @@ -5,67 +5,67 @@ a # of items indicator. */ (function($, undefined) { - var $d = $(document), - StackView = window.StackView; - - $.extend(true, StackView.defaults, { - transitionDuration: 500, - transitionEasing: 'easeOutQuad', - navigationPercent: 80, - selectors: { - downstream: '.downstream', - upstream: '.upstream', - num_items: '.num-found span' - } - }); - - $d.delegate('.stackview', 'stackview.init', function(event) { - var $stack = $(event.target), - stack = $stack.data('stackviewObject'), - $items = $stack.find(stack.options.selectors.item_list), - delta = $stack.height() * stack.options.navigationPercent / 100; - - stack.num_found_delta = 0; - $stack.prepend(tmpl(StackView.templates.navigation, { - empty: stack.options.search_type === 'loc_sort_order' - })); - - $stack - .delegate(stack.options.selectors.downstream, 'click', function() { - $items.animate({ - scrollTop: '+=' + delta - }, stack.options.transitionDuration, stack.options.transitionEasing); - return false; - }) - .delegate(stack.options.selectors.upstream, 'click', function() { - $items.animate({ - scrollTop: '-=' + delta - }, stack.options.transitionDuration, stack.options.transitionEasing); - return false; - }); - - }).delegate('.stackview', 'stackview.pageload', function(event, data) { - var $stack = $(event.target), - stack = $stack.data('stackviewObject'), - num_found = data.num_found ? parseInt(data.num_found, 10) : data.length, - num; + var $d = $(document), + StackView = window.StackView; - stack.num_found = num_found; - num = num_found + stack.num_found_delta; - $stack.find(stack.options.selectors.num_items).text(num); - - }).delegate( - '.stackview', - 'stackview.itemadded stackview.itemremoved', - function(event) { - var $stack = $(event.target), - stack = $stack.data('stackviewObject'), - $items = $stack.find(stack.options.selectors.item), - num; + $.extend(true, StackView.defaults, { + transitionDuration: 500, + transitionEasing: 'easeOutQuad', + navigationPercent: 80, + selectors: { + downstream: '.downstream', + upstream: '.upstream', + num_items: '.num-found span' + } + }); - stack.num_found_delta += (event.namespace === 'itemadded' ? 1 : -1); - num = stack.num_found + stack.num_found_delta; - $stack.find(stack.options.selectors.num_items).text(num); - } - ); -})(jQuery); \ No newline at end of file + $d.delegate('.stackview', 'stackview.init', function(event) { + var $stack = $(event.target), + stack = $stack.data('stackviewObject'), + $items = $stack.find(stack.options.selectors.item_list), + delta = $stack.height() * stack.options.navigationPercent / 100; + + stack.num_found_delta = 0; + $stack.prepend(tmpl(StackView.templates.navigation, { + empty: stack.options.search_type === 'loc_sort_order' + })); + + $stack + .delegate(stack.options.selectors.downstream, 'click', function() { + $items.animate({ + scrollTop: '+=' + delta + }, stack.options.transitionDuration, stack.options.transitionEasing); + return false; + }) + .delegate(stack.options.selectors.upstream, 'click', function() { + $items.animate({ + scrollTop: '-=' + delta + }, stack.options.transitionDuration, stack.options.transitionEasing); + return false; + }); + + }).delegate('.stackview', 'stackview.pageload', function(event, data) { + var $stack = $(event.target), + stack = $stack.data('stackviewObject'), + num_found = data.num_found ? parseInt(data.num_found, 10) : data.length, + num; + + stack.num_found = num_found; + num = num_found + stack.num_found_delta; + $stack.find(stack.options.selectors.num_items).text(num); + + }).delegate( + '.stackview', + 'stackview.itemadded stackview.itemremoved', + function(event) { + var $stack = $(event.target), + stack = $stack.data('stackviewObject'), + $items = $stack.find(stack.options.selectors.item), + num; + + stack.num_found_delta += (event.namespace === 'itemadded' ? 1 : -1); + num = stack.num_found + stack.num_found_delta; + $stack.find(stack.options.selectors.num_items).text(num); + } + ); +})(jQuery); diff --git a/src/js/jquery.stackview.stackcache.js b/src/js/jquery.stackview.stackcache.js index 5c53f73..360cb83 100644 --- a/src/js/jquery.stackview.stackcache.js +++ b/src/js/jquery.stackview.stackcache.js @@ -1,7 +1,7 @@ window.stackCache = (function(window, undefined){ - + var cache = {}, - + // "Borrowed" from Modernizr use_localStorage = window.JSON && (function(){ try { @@ -10,14 +10,14 @@ window.stackCache = (function(window, undefined){ return false; } })(); - + // Expose these methods. return { set: set, get: get, remove: remove }; - + // Set a key-value pair with optional TTL. function set( key, value, ttl ) { var expires = ttl && new Date( +new Date() + ttl * 1000 ), @@ -25,7 +25,7 @@ window.stackCache = (function(window, undefined){ expires: +expires, value: value }; - + if ( use_localStorage ) { try { localStorage[ key ] = JSON.stringify( obj ); @@ -36,12 +36,12 @@ window.stackCache = (function(window, undefined){ cache[ key ] = obj; } }; - + // Get a value if it exists and hasn't expired. function get( key ) { var obj, val; - + if ( use_localStorage ) { obj = localStorage[ key ]; if ( obj ) { @@ -50,7 +50,7 @@ window.stackCache = (function(window, undefined){ } else { obj = cache[ key ]; } - + if ( obj ) { if ( obj.expires && obj.expires < +new Date() ) { remove( key ); @@ -58,10 +58,10 @@ window.stackCache = (function(window, undefined){ val = obj.value; } } - + return val; }; - + // Remove a key-value pair. function remove( key ) { if ( use_localStorage ) { @@ -70,5 +70,5 @@ window.stackCache = (function(window, undefined){ delete cache[ key ]; } }; - -})(window); \ No newline at end of file + +})(window); diff --git a/src/js/jquery.stackview.templates.js b/src/js/jquery.stackview.templates.js index 506ceaa..0fab90d 100644 --- a/src/js/jquery.stackview.templates.js +++ b/src/js/jquery.stackview.templates.js @@ -1,31 +1,31 @@ (function(undefined) { - StackView.templates = { - scaffold: '\ -
<%= ribbon %>
\ -