Skip to content

Commit

Permalink
resolves bespokejs#6 init synchronously unless deferStart option is true
Browse files Browse the repository at this point in the history
  • Loading branch information
mojavelinux committed Oct 3, 2017
1 parent 75a8e0e commit 3d225c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 8 deletions.
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

0 comments on commit 3d225c8

Please sign in to comment.