Skip to content

Commit

Permalink
Fixes & custom event polyfill
Browse files Browse the repository at this point in the history
  • Loading branch information
skerit committed Oct 6, 2015
1 parent d0896c3 commit 4504b78
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 11 deletions.
14 changes: 14 additions & 0 deletions index.js
Expand Up @@ -87,6 +87,20 @@ Hawkejs.setMethod(function afterInit() {
// Require these files in the browser only
this.load('lib/client/isvisible.js', {server: false});

// Register CustomEvent Polyfill for IE
this.load('lib/client/custom_event.js', {
server: false,
versions: {
android: {max: 4.2}, // ?
chrome: {max: 14},
firefox: {max: 10},
ie: {max: 11},
mobile_safari: {max: 7.0}, // ?
opera: {max: 11.5},
safari: {max: 7.0} // ?
}
});

// Register Weakmap Polyfill
this.load('lib/client/weakmap.js', {
server: false,
Expand Down
37 changes: 30 additions & 7 deletions lib/class/scene.js
Expand Up @@ -311,9 +311,12 @@ module.exports = function hawkejsSceneClass(Hawkejs, Blast) {
*/
Scene.setMethod(function attachHistoryListener() {

var that = this;
var hash = location.hash,
that = this;

// Listen to the "popstate" event, a back or forward button press
// Listen to the "popstate" event,
// which happends when the back or forward button is pressed,
// but also when a hashchange happens
window.addEventListener('popstate', function onPopstate(e) {

var viewRender,
Expand Down Expand Up @@ -347,11 +350,23 @@ module.exports = function hawkejsSceneClass(Hawkejs, Blast) {
that.emit('postHistory', content, viewRender);
});
} else {

var returnLocation,
old_hash = hash;

// Overwrite the old hash
hash = location.hash;

// Just emit a hash change event, don't reload the url
if (hash) {
return that.emit('hashchange', hash, old_hash);
}

// It wasn't found, so we'll just have to re-request the page
// without adding it to the history again, of course

// Get the wanted location
var returnLocation = history.location || document.location;
returnLocation = history.location || document.location;

// Go there
// @todo: don't add this to the history again!
Expand Down Expand Up @@ -1264,12 +1279,18 @@ module.exports = function hawkejsSceneClass(Hawkejs, Blast) {
return Blast.setImmediate(callback);
}

tasks = new Array(styles.length);
tasks = [];

styles.forEach(function eachStyle(parameters, index) {
tasks[index] = function doStyle(next) {

// Empty arrays mean no styles need to be loaded
if (!parameters[0] || !parameters[0].length) {
return;
}

tasks.push(function doStyle(next) {
that.enableStyle(parameters[0], parameters[1], next);
};
});
});

// Unlike scripts, styles should be loaded parallel.
Expand Down Expand Up @@ -1495,7 +1516,9 @@ module.exports = function hawkejsSceneClass(Hawkejs, Blast) {
name = path;

// Normalize the path
if (path[0] == '/') {
if (path.slice(0, 4) === 'http') {
// Do nothing, path is a regular url
} else if (path[0] == '/') {
if (path[1] != '/') {
path = Blast.Bound.String.beforeLast(this.hawkejs.root, '/') + path;
}
Expand Down
9 changes: 7 additions & 2 deletions lib/class/view_render.js
Expand Up @@ -1112,15 +1112,20 @@ module.exports = function(Hawkejs, Blast) {
anchor.attr('href', href);

for (name in options.attributes) {
anchor.attr(name, options.attributes[name]);

if (name == 'class' || name == 'className') {
anchor.addClass(options.attributes[name]);
} else {
anchor.attr(name, options.attributes[name]);
}
}

// Get the content of the anchor
content = (options.content || '') || anchor.attr('title') || href;

anchor.setContent([options.prepend, content, options.append], options.escape);

return this.print(anchor);
return anchor;
});

/**
Expand Down
17 changes: 17 additions & 0 deletions lib/client/custom_event.js
@@ -0,0 +1,17 @@
module.exports = function() {

function CustomEvent (event, params) {

var evt;

params = params || {bubbles: false, cancelable: false, detail: undefined};
evt = document.createEvent('CustomEvent');

evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
return evt;
}

CustomEvent.prototype = window.Event.prototype;

window.CustomEvent = CustomEvent;
};
2 changes: 1 addition & 1 deletion lib/client/element_bound.js
Expand Up @@ -11,7 +11,7 @@ module.exports = function hawkejsRegisterElement(Hawkejs, Blast) {
Hawkejs.registerElement('he-bound');

/**
* Attach to elemtns with data-update-request attributes
* Attach to elements with data-update-request attributes
*
* @author Jelle De Loecker <jelle@develry.be>
* @since 1.0.0
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -27,4 +27,4 @@
"engines": {
"node": ">=0.8"
}
}
}

0 comments on commit 4504b78

Please sign in to comment.