Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #6 init synchronously unless deferStart option is true #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions dist/bespoke-hash.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/

(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g=(g.bespoke||(g.bespoke = {}));g=(g.plugins||(g.plugins = {}));g.hash = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
module.exports = function() {
module.exports = function(opts) {
return function(deck) {
var activateSlide = function(index) {
var indexToActivate = -1 < index && index < deck.slides.length ? index : 0;
Expand All @@ -33,7 +33,7 @@ module.exports = function() {
}
};

setTimeout(function() {
var init = function() {
parseHash();

deck.on('activate', function(e) {
Expand All @@ -42,7 +42,14 @@ module.exports = function() {
});

window.addEventListener('hashchange', parseHash);
}, 0);
}

// honor option to enable legacy behavior
if ((opts || {}).deferStart) {
setTimeout(init, 0);
} else {
init();
}
};
};

Expand Down
2 changes: 1 addition & 1 deletion dist/bespoke-hash.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 10 additions & 3 deletions lib/bespoke-hash.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function() {
module.exports = function(opts) {
return function(deck) {
var activateSlide = function(index) {
var indexToActivate = -1 < index && index < deck.slides.length ? index : 0;
Expand All @@ -24,7 +24,7 @@ module.exports = function() {
}
};

setTimeout(function() {
var init = function() {
parseHash();

deck.on('activate', function(e) {
Expand All @@ -33,6 +33,13 @@ module.exports = function() {
});

window.addEventListener('hashchange', parseHash);
}, 0);
}

// honor option to enable legacy behavior
if ((opts || {}).deferStart) {
setTimeout(init, 0);
} else {
init();
}
};
};
2 changes: 1 addition & 1 deletion test/spec/bespoke-hashSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("bespoke-hash", function() {
document.body.appendChild(article);

deck = bespoke.from(PARENT_TAG, [
hash()
hash({ deferStart: true })
]);

// Wait for next tick
Expand Down