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

Add compatiblity for IE8 #124

Merged
merged 2 commits into from
May 24, 2014
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add compatiblity for IE8
  • Loading branch information
Jonathan Weiß committed May 23, 2014
commit 5d88b8faf9d7671f596ac83b95abe02eb7861436
3 changes: 2 additions & 1 deletion .jshintrc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"globals": {
"jQuery": true,
"define": true,
"module": true
"module": true,
"bean": true
}
}
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## HEAD

* Add compatiblity for IE8 (use "bean" library for event handling)
* Allow the content with id 0 to be selected

* Fix max height of modal content
Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<!--[if lt IE 9]>
<script src="test/lib/html5shiv.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/bean/1.0.6/bean.min.js"></script>
<![endif]-->

<style>
Expand Down
66 changes: 36 additions & 30 deletions modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,11 @@

'use strict';

/*
* Polyfill CustomEvent
*/
var CustomEvent = function (event, params) {
var evt = document.createEvent('CustomEvent');

params = params || {
bubbles: false,
cancelable: false,
detail: undefined
};

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

return evt;
};

if (!window.CustomEvent) {
CustomEvent.prototype = window.Event.prototype;
window.CustomEvent = CustomEvent;
// We use bean if the browser doesn't support CustomEvents
if (window.CustomEvent) {
if (!window.bean) {
throw new Error('This browser doesn\'t support CustomEvent - please include bean: https://github.com/fat/bean');
}
}

/*
Expand All @@ -53,6 +38,7 @@
* @param callback {function} gets fired if event is triggered
*/
on: function (event, element, callback) {

if (typeof event !== 'string') {
throw new Error('Type error: `error` has to be a string');
}
Expand All @@ -65,10 +51,10 @@
return;
}

if (element.addEventListener) {
element.addEventListener(event, callback, false);
if (window.bean) {
bean.on(element, event, callback);
} else {
element.attachEvent('on' + event, callback);
element.addEventListener(event, callback, false);
}
},

Expand All @@ -78,13 +64,24 @@
* @param modal {string} id of modal that the event is triggered on
*/
trigger: function (event, modal) {
var eventTrigger = new CustomEvent(event,{
detail: {
'modal': modal
}
});
var eventTrigger;

if (window.bean) {
eventTrigger = {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can use a new variable for this object and reuse it later in both if's?

detail: {
'modal': modal
}
};
bean.fire(document, event, eventTrigger);
} else {
eventTrigger = new CustomEvent(event,{
detail: {
'modal': modal
}
});

document.dispatchEvent(eventTrigger);
document.dispatchEvent(eventTrigger);
}
},

/*
Expand Down Expand Up @@ -138,7 +135,16 @@
* @param element {node} element to keep focus in
*/
keepFocus: function (element) {
var allTabbableElements = element.querySelectorAll(modal.tabbableElements);
var allTabbableElements = [];

// Don't keep the focus if the browser is unable to support
// CSS3 selectors
try {
allTabbableElements = element.querySelectorAll(modal.tabbableElements);
} catch (ex) {
return;
}

var firstTabbableElement = allTabbableElements[0];
var lastTabbableElement = allTabbableElements[allTabbableElements.length - 1];

Expand Down
8 changes: 4 additions & 4 deletions plugins/gallery.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
* @return {Object} The detail image
*/
var _getDetailView = function (element) {
var container = element.getElementsByClassName('modal-detail')[0];
var container = element.querySelectorAll('.modal-detail')[0];

if (!container) {
throw new Error('".modal-detail" not found!');
Expand Down Expand Up @@ -145,8 +145,8 @@
var i = 0;

// Setup touch / click events
_prev = element.getElementsByClassName('modal--gallery-navigation-prev')[0];
_next = element.getElementsByClassName('modal--gallery-navigation-next')[0];
_prev = element.querySelectorAll('.modal--gallery-navigation-prev')[0];
_next = element.querySelectorAll('.modal--gallery-navigation-next')[0];

for (; i < events.length; i++) {
CSSModal.on(events[i], _prev, showPrevious);
Expand All @@ -167,7 +167,7 @@
* @return {void}
*/
var _readContent = function (element) {
var contentList = element.getElementsByClassName('modal-content-list')[0];
var contentList = element.querySelectorAll('.modal-content-list')[0];
return contentList.getElementsByTagName('li');
};

Expand Down
6 changes: 4 additions & 2 deletions plugins/modal-resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,17 +187,19 @@
};

var getHorizontalOffset = function () {
var innerWidth = global.innerWidth ? global.innerWidth : document.body.clientWidth;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indention is wrong.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also

var innerWidth = global.innerWidth || document.body.clientWidth

might be a bit more elegant.

var element = CSSModal.activeElement.querySelector('.modal-inner');
var elementWidth = parseInt(global.getComputedStyle(element).getPropertyValue('width'), 10);
var offset = (global.innerWidth - elementWidth) / 2;
var offset = (innerWidth - elementWidth) / 2;

return offset;
};

var getVerticalOffset = function () {
var innerHeight = global.innerHeight ? global.innerWidth : document.body.clientHeight;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above.

var element = CSSModal.activeElement.querySelector('.modal-inner');
var elementHeight = parseInt(global.getComputedStyle(element).getPropertyValue('height'), 10);
var offset = (global.innerHeight - elementHeight) / 2;
var offset = (innerHeight - elementHeight) / 2;

return offset;
};
Expand Down