Cleanup & travis (should break)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,4 +1,3 @@
|
||||
.DS_Store
|
||||
node_modules/
|
||||
dist/
|
||||
tests/scripts/index.html
|
||||
|
||||
@@ -1,5 +1,10 @@
|
||||
{
|
||||
"excludeFiles": [],
|
||||
"excludeFiles": [
|
||||
"node_modules/**"
|
||||
],
|
||||
"fileExtensions": [
|
||||
".js"
|
||||
],
|
||||
"requireCurlyBraces": [
|
||||
"if",
|
||||
"else",
|
||||
@@ -20,16 +25,27 @@
|
||||
"try",
|
||||
"catch"
|
||||
],
|
||||
"requireSpaceBeforeBlockStatements": true,
|
||||
"requireParenthesesAroundIIFE": true,
|
||||
"requireSpacesInConditionalExpression": {
|
||||
"afterTest": true,
|
||||
"beforeConsequent": true,
|
||||
"afterConsequent": true,
|
||||
"beforeAlternate": true
|
||||
},
|
||||
"requireSpacesInFunctionExpression": {
|
||||
"beforeOpeningCurlyBrace": true
|
||||
},
|
||||
"disallowSpacesInFunctionExpression": {
|
||||
"beforeOpeningRoundBrace": true
|
||||
},
|
||||
"disallowMultipleVarDecl": true,
|
||||
"requireBlocksOnNewline": 1,
|
||||
"disallowPaddingNewlinesInBlocks": true,
|
||||
"disallowEmptyBlocks": true,
|
||||
"disallowSpacesInsideParentheses": true,
|
||||
"disallowSpacesInsideObjectBrackets": true,
|
||||
"disallowSpacesInsideArrayBrackets": true,
|
||||
"disallowSpacesInsideParentheses": true,
|
||||
"disallowQuotedKeysInObjects": "allButReserved",
|
||||
"disallowSpaceAfterObjectKeys": true,
|
||||
"requireCommaBeforeLineBreak": true,
|
||||
@@ -49,41 +65,6 @@
|
||||
"<",
|
||||
"<="
|
||||
],
|
||||
"disallowLeftStickedOperators": [
|
||||
"?",
|
||||
"+",
|
||||
"-",
|
||||
"/",
|
||||
"*",
|
||||
"=",
|
||||
"==",
|
||||
"===",
|
||||
"!=",
|
||||
"!==",
|
||||
">",
|
||||
">=",
|
||||
"<",
|
||||
"<="
|
||||
],
|
||||
"requireRightStickedOperators": [
|
||||
"!"
|
||||
],
|
||||
"disallowRightStickedOperators": [
|
||||
"?",
|
||||
"+",
|
||||
"/",
|
||||
"*",
|
||||
":",
|
||||
"=",
|
||||
"==",
|
||||
"===",
|
||||
"!=",
|
||||
"!==",
|
||||
">",
|
||||
">=",
|
||||
"<",
|
||||
"<="
|
||||
],
|
||||
"disallowSpaceAfterPrefixUnaryOperators": [
|
||||
"++",
|
||||
"--",
|
||||
@@ -124,20 +105,26 @@
|
||||
"binary",
|
||||
"string"
|
||||
],
|
||||
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
|
||||
"disallowKeywords": [
|
||||
"with"
|
||||
],
|
||||
"disallowMultipleLineStrings": true,
|
||||
"validateQuoteMarks": "\"",
|
||||
"validateIndentation": 2,
|
||||
"disallowMixedSpacesAndTabs": true,
|
||||
"disallowTrailingWhitespace": true,
|
||||
"requireKeywordsOnNewLine": [],
|
||||
"requireKeywordsOnNewLine": [
|
||||
"else"
|
||||
],
|
||||
"requireLineFeedAtFileEnd": true,
|
||||
"requireCapitalizedConstructors": true,
|
||||
"safeContextKeyword": "that",
|
||||
"requireDotNotation": true,
|
||||
"validateJSDoc": {
|
||||
"checkParamNames": true,
|
||||
"checkRedundantParams": true,
|
||||
"requireParamTypes": true
|
||||
}
|
||||
},
|
||||
"requireSpaceAfterLineComment": true
|
||||
}
|
||||
@@ -1,4 +1,9 @@
|
||||
{
|
||||
"newcap": false,
|
||||
"undef": true,
|
||||
"unused": true,
|
||||
"asi": true,
|
||||
"laxcomma": true
|
||||
"esnext": true,
|
||||
"node": true,
|
||||
"browser": true
|
||||
}
|
||||
|
||||
7
.travis.yml
Normal file
7
.travis.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
language: "node_js"
|
||||
before_script:
|
||||
# testling use headless browser
|
||||
# on travis-ci, firefox is the default one
|
||||
# & it needs a display to works
|
||||
- export DISPLAY=:99.0
|
||||
- sh -e /etc/init.d/xvfb start
|
||||
@@ -18,8 +18,6 @@
|
||||
],
|
||||
"license": "MIT",
|
||||
"moduleType": [
|
||||
"amd",
|
||||
"globals",
|
||||
"node"
|
||||
],
|
||||
"ignore": [
|
||||
|
||||
67
index.js
67
index.js
@@ -1,5 +1,11 @@
|
||||
/* global _gaq: true, ga: true */
|
||||
|
||||
var newUid = require("./lib/uniqueid.js")
|
||||
|
||||
var on = require("./lib/events/on.js")
|
||||
// var off = require("./lib/events/on.js")
|
||||
var trigger = require("./lib/events/trigger.js")
|
||||
|
||||
var Pjax = function(options) {
|
||||
this.firstrun = true
|
||||
|
||||
@@ -44,7 +50,7 @@ var Pjax = function(options) {
|
||||
|
||||
this.parseDOM(document)
|
||||
|
||||
Pjax.on(window, "popstate", function(st) {
|
||||
on(window, "popstate", function(st) {
|
||||
if (st.state) {
|
||||
var opt = Pjax.clone(this.options)
|
||||
opt.url = st.state.url
|
||||
@@ -63,7 +69,6 @@ var Pjax = function(options) {
|
||||
this.loadUrl(st.state.url, opt)
|
||||
}
|
||||
}.bind(this))
|
||||
|
||||
}
|
||||
|
||||
Pjax.prototype = {
|
||||
@@ -97,7 +102,7 @@ Pjax.prototype = {
|
||||
},
|
||||
|
||||
onSwitch: function() {
|
||||
Pjax.trigger(window, "resize scroll")
|
||||
trigger(window, "resize scroll")
|
||||
},
|
||||
|
||||
loadContent: function(html, options) {
|
||||
@@ -131,24 +136,24 @@ Pjax.prototype = {
|
||||
}
|
||||
|
||||
// try {
|
||||
this.switchSelectors(this.options.selectors, tmpEl, document, options)
|
||||
this.switchSelectors(this.options.selectors, tmpEl, document, options)
|
||||
|
||||
// FF bug: Won’t autofocus fields that are inserted via JS.
|
||||
// This behavior is incorrect. So if theres no current focus, autofocus
|
||||
// the last field.
|
||||
//
|
||||
// http://www.w3.org/html/wg/drafts/html/master/forms.html
|
||||
var autofocusEl = Array.prototype.slice.call(document.querySelectorAll("[autofocus]")).pop()
|
||||
if (autofocusEl && document.activeElement !== autofocusEl) {
|
||||
autofocusEl.focus();
|
||||
}
|
||||
// FF bug: Won’t autofocus fields that are inserted via JS.
|
||||
// This behavior is incorrect. So if theres no current focus, autofocus
|
||||
// the last field.
|
||||
//
|
||||
// http://www.w3.org/html/wg/drafts/html/master/forms.html
|
||||
var autofocusEl = Array.prototype.slice.call(document.querySelectorAll("[autofocus]")).pop()
|
||||
if (autofocusEl && document.activeElement !== autofocusEl) {
|
||||
autofocusEl.focus();
|
||||
}
|
||||
|
||||
// execute scripts when DOM have been completely updated
|
||||
this.options.selectors.forEach(function(selector) {
|
||||
Pjax.forEachEls(document.querySelectorAll(selector), function(el) {
|
||||
Pjax.executeScripts(el)
|
||||
})
|
||||
// execute scripts when DOM have been completely updated
|
||||
this.options.selectors.forEach(function(selector) {
|
||||
Pjax.forEachEls(document.querySelectorAll(selector), function(el) {
|
||||
Pjax.executeScripts(el)
|
||||
})
|
||||
})
|
||||
// }
|
||||
// catch(e) {
|
||||
// if (this.options.debug) {
|
||||
@@ -163,14 +168,13 @@ Pjax.prototype = {
|
||||
loadUrl: function(href, options) {
|
||||
this.log("load href", href, options)
|
||||
|
||||
Pjax.trigger(document, "pjax:send", options);
|
||||
trigger(document, "pjax:send", options);
|
||||
|
||||
// Do the request
|
||||
this.doRequest(href, function(html) {
|
||||
|
||||
// Fail if unable to load HTML via AJAX
|
||||
if (html === false) {
|
||||
Pjax.trigger(document,"pjax:complete pjax:error", options)
|
||||
trigger(document,"pjax:complete pjax:error", options)
|
||||
|
||||
return
|
||||
}
|
||||
@@ -195,25 +199,24 @@ Pjax.prototype = {
|
||||
}
|
||||
|
||||
if (options.history) {
|
||||
|
||||
if (this.firstrun) {
|
||||
this.lastUid = this.maxUid = newUid()
|
||||
this.firstrun = false
|
||||
window.history.replaceState({
|
||||
url: window.location.href,
|
||||
title: document.title,
|
||||
uid: this.maxUid
|
||||
},
|
||||
document.title)
|
||||
url: window.location.href,
|
||||
title: document.title,
|
||||
uid: this.maxUid
|
||||
},
|
||||
document.title)
|
||||
}
|
||||
|
||||
// Update browser history
|
||||
this.lastUid = this.maxUid = newUid()
|
||||
window.history.pushState({
|
||||
url: href,
|
||||
title: options.title,
|
||||
uid: this.maxUid
|
||||
},
|
||||
url: href,
|
||||
title: options.title,
|
||||
uid: this.maxUid
|
||||
},
|
||||
options.title,
|
||||
href)
|
||||
}
|
||||
@@ -223,7 +226,7 @@ Pjax.prototype = {
|
||||
}, this)
|
||||
|
||||
// Fire Events
|
||||
Pjax.trigger(document,"pjax:complete pjax:success", options)
|
||||
trigger(document,"pjax:complete pjax:success", options)
|
||||
|
||||
options.analytics()
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
/* global HTMLCollection: true */
|
||||
|
||||
module.exports = function(els, fn, context) {
|
||||
if (els instanceof HTMLCollection || els instanceof NodeList || els instanceof Array) {
|
||||
return Array.prototype.forEach.call(els, fn, context)
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function (oThis) {
|
||||
Function.prototype.bind = function(oThis) {
|
||||
if (typeof this !== "function") {
|
||||
// closest thing possible to the ECMAScript 5 internal IsCallable function
|
||||
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable")
|
||||
}
|
||||
|
||||
var aArgs = Array.prototype.slice.call(arguments, 1)
|
||||
var fToBind = this
|
||||
var fNOP = function () {}
|
||||
var fBound = function () {
|
||||
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)))
|
||||
var that = this
|
||||
var Fnoop = function() {}
|
||||
var fBound = function() {
|
||||
return that.apply(this instanceof Fnoop && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)))
|
||||
}
|
||||
|
||||
fNOP.prototype = this.prototype
|
||||
fBound.prototype = new fNOP()
|
||||
Fnoop.prototype = this.prototype
|
||||
fBound.prototype = new Fnoop()
|
||||
|
||||
return fBound
|
||||
}
|
||||
|
||||
@@ -54,23 +54,21 @@ var linkAction = function(el, event) {
|
||||
}
|
||||
|
||||
module.exports = function(el) {
|
||||
var instance = this
|
||||
var that = this
|
||||
|
||||
on(el, "click", function(event) {
|
||||
linkAction.call(instance, el, event)
|
||||
linkAction.call(that, el, event)
|
||||
})
|
||||
|
||||
on(el, "keyup", function(event) {
|
||||
|
||||
// Don’t break browser special behavior on links (like page in new window)
|
||||
if (event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
|
||||
el.setAttribute(attrKey, "modifier")
|
||||
return
|
||||
}
|
||||
|
||||
if(event.keyCode == 13) {
|
||||
linkAction.call(instance, el, event)
|
||||
if (event.keyCode == 13) {
|
||||
linkAction.call(that, el, event)
|
||||
}
|
||||
|
||||
}.bind(this))
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@ var forEachEls = require("../foreach-els")
|
||||
var parseElement = require("../parse-element")
|
||||
|
||||
module.exports = function(el) {
|
||||
forEachEls(this.getElements(el), parseElement }, this)
|
||||
forEachEls(this.getElements(el), parseElement, this)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ module.exports = function(location, callback) {
|
||||
}
|
||||
}
|
||||
|
||||
request.open("GET", location + (!/[?&]/.test(location) ? "?": "&") + (new Date().getTime()), true)
|
||||
request.open("GET", location + (!/[?&]/.test(location) ? "?" : "&") + (new Date().getTime()), true)
|
||||
request.setRequestHeader("X-Requested-With", "XMLHttpRequest")
|
||||
request.send(null)
|
||||
return request
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
var on = require("./lib/events/on.js")
|
||||
// var off = require("./lib/events/on.js")
|
||||
// var trigger = require("./lib/events/trigger.js")
|
||||
|
||||
|
||||
module.exports = {
|
||||
outerHTML: function(oldEl, newEl, options) {
|
||||
outerHTML: function(oldEl, newEl) {
|
||||
oldEl.outerHTML = newEl.outerHTML
|
||||
this.onSwitch()
|
||||
},
|
||||
|
||||
innerHTML: function(oldEl, newEl, options) {
|
||||
innerHTML: function(oldEl, newEl) {
|
||||
oldEl.innerHTML = newEl.innerHTML
|
||||
oldEl.className = newEl.className
|
||||
this.onSwitch()
|
||||
@@ -17,7 +22,7 @@ module.exports = {
|
||||
var fragToAppend = document.createDocumentFragment()
|
||||
// height transition are shitty on safari
|
||||
// so commented for now (until I found something ?)
|
||||
//var relevantHeight = 0
|
||||
// var relevantHeight = 0
|
||||
var animationEventNames = "animationend webkitAnimationEnd MSAnimationEnd oanimationend"
|
||||
var animatedElsNumber = 0
|
||||
var sexyAnimationEnd = function(e) {
|
||||
@@ -50,7 +55,7 @@ module.exports = {
|
||||
|
||||
// this is to trigger some repaint (example: picturefill)
|
||||
this.onSwitch()
|
||||
//Pjax.trigger(window, "scroll")
|
||||
// Pjax.trigger(window, "scroll")
|
||||
}
|
||||
}.bind(this)
|
||||
|
||||
@@ -79,7 +84,7 @@ module.exports = {
|
||||
el.className += " " + switchOptions.classNames.remove + " " + (options.backward ? switchOptions.classNames.backward : switchOptions.classNames.forward)
|
||||
}
|
||||
animatedElsNumber++
|
||||
Pjax.on(el, animationEventNames, sexyAnimationEnd, true)
|
||||
on(el, animationEventNames, sexyAnimationEnd, true)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -97,7 +102,7 @@ module.exports = {
|
||||
elsToAdd.push(el)
|
||||
fragToAppend.appendChild(el)
|
||||
animatedElsNumber++
|
||||
Pjax.on(el, animationEventNames, sexyAnimationEnd, true)
|
||||
on(el, animationEventNames, sexyAnimationEnd, true)
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -7,8 +7,8 @@ var trigger = require("../../lib/events/trigger")
|
||||
var el = document.createElement("div")
|
||||
var el2 = document.createElement("span")
|
||||
var els = [el, el2]
|
||||
var eventType2 = "resize"
|
||||
var eventsType = "click resize"
|
||||
// var eventType2 = "resize"
|
||||
// var eventsType = "click resize"
|
||||
var classCb = function() {
|
||||
this.className += "on"
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ var tape = require("tape")
|
||||
var parseElement = require("../../../lib/proto/parse-element")
|
||||
var protoMock = {attachLink: function() { return true}}
|
||||
tape("test parse element prototype method", function(t) {
|
||||
|
||||
t.doesNotThrow(function() {
|
||||
var a = document.createElement("a")
|
||||
parseElement.call(protoMock, a)
|
||||
|
||||
@@ -3,7 +3,7 @@ var tape = require("tape")
|
||||
var request = require("../../lib/request.js")
|
||||
|
||||
tape("test xhr request", function(t) {
|
||||
var xhr = request("https://api.github.com/", function(result) {
|
||||
request("https://api.github.com/", function(result) {
|
||||
try {
|
||||
result = JSON.parse(result)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
var tape = require("tape")
|
||||
|
||||
var switchesSelectors = require("../../lib/switches-selectors.js")
|
||||
// var switchesSelectors = require("../../lib/switches-selectors.js")
|
||||
|
||||
tape("test switchesSelectors", function(t) {
|
||||
t.fail()
|
||||
|
||||
Reference in New Issue
Block a user