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

Moved inline DOM functions to within constructor #843

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
2 changes: 1 addition & 1 deletion src/helpers/caf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var win = window;
import { win } from './dom.js';

export var caf = win.cancelAnimationFrame
|| win.mozCancelAnimationFrame
Expand Down
4 changes: 3 additions & 1 deletion src/helpers/classListSupport.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
export var classListSupport = 'classList' in document.createElement('_');
import { classListSupport } from './dom.js';

export { classListSupport };
3 changes: 2 additions & 1 deletion src/helpers/docElement.js
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export var docElement = document.documentElement;
import { docElement } from './dom.js';
export { docElement }
22 changes: 22 additions & 0 deletions src/helpers/dom.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
var win = {};
var doc = {};
var docElement = {};
var classListSupport = {};

function initDOM(){
win = window;
doc = document;
docElement = document.documentElement;
classListSupport = 'classList' in document.createElement('_');

// ChildNode.remove - runs upon DOM initialization function
if(!("remove" in Element.prototype)){
Element.prototype.remove = function(){
if(this.parentNode) {
this.parentNode.removeChild(this);
}
};
}
}

export { win, doc, docElement, classListSupport, initDOM };
2 changes: 1 addition & 1 deletion src/helpers/raf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var win = window;
import { win } from './dom.js';

export var raf = win.requestAnimationFrame
|| win.webkitRequestAnimationFrame
Expand Down
8 changes: 5 additions & 3 deletions src/tiny-slider.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ if(!("remove" in Element.prototype)){
};
}

import { win, doc, initDOM } from './helpers/dom.js';
import { raf } from './helpers/raf.js';
import { caf } from './helpers/caf.js';
import { extend } from './helpers/extend.js';
Expand Down Expand Up @@ -111,9 +112,10 @@ export var tns = function(options) {
nonce: false
}, options || {});

var doc = document,
win = window,
KEYS = {
// initialize DOM objects - delayed so SSR frameworks can use module
initDOM();

var KEYS = {
ENTER: 13,
SPACE: 32,
LEFT: 37,
Expand Down