Cleanup & travis (should break)

This commit is contained in:
Maxime Thirouin
2014-10-14 11:42:36 +02:00
parent 332cd4e876
commit 3bc67f245c
16 changed files with 104 additions and 101 deletions

1
.gitignore vendored
View File

@@ -1,4 +1,3 @@
.DS_Store .DS_Store
node_modules/ node_modules/
dist/
tests/scripts/index.html tests/scripts/index.html

View File

@@ -1,5 +1,10 @@
{ {
"excludeFiles": [], "excludeFiles": [
"node_modules/**"
],
"fileExtensions": [
".js"
],
"requireCurlyBraces": [ "requireCurlyBraces": [
"if", "if",
"else", "else",
@@ -20,16 +25,27 @@
"try", "try",
"catch" "catch"
], ],
"requireSpaceBeforeBlockStatements": true,
"requireParenthesesAroundIIFE": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"requireSpacesInFunctionExpression": { "requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true "beforeOpeningCurlyBrace": true
}, },
"disallowSpacesInFunctionExpression": { "disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true "beforeOpeningRoundBrace": true
}, },
"disallowMultipleVarDecl": true,
"requireBlocksOnNewline": 1,
"disallowPaddingNewlinesInBlocks": true,
"disallowEmptyBlocks": true, "disallowEmptyBlocks": true,
"disallowSpacesInsideParentheses": true,
"disallowSpacesInsideObjectBrackets": true, "disallowSpacesInsideObjectBrackets": true,
"disallowSpacesInsideArrayBrackets": true, "disallowSpacesInsideArrayBrackets": true,
"disallowSpacesInsideParentheses": true,
"disallowQuotedKeysInObjects": "allButReserved", "disallowQuotedKeysInObjects": "allButReserved",
"disallowSpaceAfterObjectKeys": true, "disallowSpaceAfterObjectKeys": true,
"requireCommaBeforeLineBreak": true, "requireCommaBeforeLineBreak": true,
@@ -49,41 +65,6 @@
"<", "<",
"<=" "<="
], ],
"disallowLeftStickedOperators": [
"?",
"+",
"-",
"/",
"*",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"requireRightStickedOperators": [
"!"
],
"disallowRightStickedOperators": [
"?",
"+",
"/",
"*",
":",
"=",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"disallowSpaceAfterPrefixUnaryOperators": [ "disallowSpaceAfterPrefixUnaryOperators": [
"++", "++",
"--", "--",
@@ -124,20 +105,26 @@
"binary", "binary",
"string" "string"
], ],
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"disallowKeywords": [ "disallowKeywords": [
"with" "with"
], ],
"disallowMultipleLineStrings": true, "disallowMultipleLineStrings": true,
"validateQuoteMarks": "\"", "validateQuoteMarks": "\"",
"validateIndentation": 2,
"disallowMixedSpacesAndTabs": true, "disallowMixedSpacesAndTabs": true,
"disallowTrailingWhitespace": true, "disallowTrailingWhitespace": true,
"requireKeywordsOnNewLine": [], "requireKeywordsOnNewLine": [
"else"
],
"requireLineFeedAtFileEnd": true, "requireLineFeedAtFileEnd": true,
"requireCapitalizedConstructors": true, "requireCapitalizedConstructors": true,
"safeContextKeyword": "that", "safeContextKeyword": "that",
"requireDotNotation": true,
"validateJSDoc": { "validateJSDoc": {
"checkParamNames": true, "checkParamNames": true,
"checkRedundantParams": true, "checkRedundantParams": true,
"requireParamTypes": true "requireParamTypes": true
} },
"requireSpaceAfterLineComment": true
} }

View File

@@ -1,4 +1,9 @@
{ {
"newcap": false,
"undef": true,
"unused": true,
"asi": true, "asi": true,
"laxcomma": true "esnext": true,
"node": true,
"browser": true
} }

7
.travis.yml Normal file
View 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

View File

@@ -18,8 +18,6 @@
], ],
"license": "MIT", "license": "MIT",
"moduleType": [ "moduleType": [
"amd",
"globals",
"node" "node"
], ],
"ignore": [ "ignore": [

View File

@@ -1,5 +1,11 @@
/* global _gaq: true, ga: true */
var newUid = require("./lib/uniqueid.js") 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) { var Pjax = function(options) {
this.firstrun = true this.firstrun = true
@@ -44,7 +50,7 @@ var Pjax = function(options) {
this.parseDOM(document) this.parseDOM(document)
Pjax.on(window, "popstate", function(st) { on(window, "popstate", function(st) {
if (st.state) { if (st.state) {
var opt = Pjax.clone(this.options) var opt = Pjax.clone(this.options)
opt.url = st.state.url opt.url = st.state.url
@@ -63,7 +69,6 @@ var Pjax = function(options) {
this.loadUrl(st.state.url, opt) this.loadUrl(st.state.url, opt)
} }
}.bind(this)) }.bind(this))
} }
Pjax.prototype = { Pjax.prototype = {
@@ -97,7 +102,7 @@ Pjax.prototype = {
}, },
onSwitch: function() { onSwitch: function() {
Pjax.trigger(window, "resize scroll") trigger(window, "resize scroll")
}, },
loadContent: function(html, options) { loadContent: function(html, options) {
@@ -163,14 +168,13 @@ Pjax.prototype = {
loadUrl: function(href, options) { loadUrl: function(href, options) {
this.log("load href", href, options) this.log("load href", href, options)
Pjax.trigger(document, "pjax:send", options); trigger(document, "pjax:send", options);
// Do the request // Do the request
this.doRequest(href, function(html) { this.doRequest(href, function(html) {
// Fail if unable to load HTML via AJAX // Fail if unable to load HTML via AJAX
if (html === false) { if (html === false) {
Pjax.trigger(document,"pjax:complete pjax:error", options) trigger(document,"pjax:complete pjax:error", options)
return return
} }
@@ -195,7 +199,6 @@ Pjax.prototype = {
} }
if (options.history) { if (options.history) {
if (this.firstrun) { if (this.firstrun) {
this.lastUid = this.maxUid = newUid() this.lastUid = this.maxUid = newUid()
this.firstrun = false this.firstrun = false
@@ -223,7 +226,7 @@ Pjax.prototype = {
}, this) }, this)
// Fire Events // Fire Events
Pjax.trigger(document,"pjax:complete pjax:success", options) trigger(document,"pjax:complete pjax:success", options)
options.analytics() options.analytics()

View File

@@ -1,3 +1,5 @@
/* global HTMLCollection: true */
module.exports = function(els, fn, context) { module.exports = function(els, fn, context) {
if (els instanceof HTMLCollection || els instanceof NodeList || els instanceof Array) { if (els instanceof HTMLCollection || els instanceof NodeList || els instanceof Array) {
return Array.prototype.forEach.call(els, fn, context) return Array.prototype.forEach.call(els, fn, context)

View File

@@ -1,19 +1,19 @@
if (!Function.prototype.bind) { if (!Function.prototype.bind) {
Function.prototype.bind = function (oThis) { Function.prototype.bind = function(oThis) {
if (typeof this !== "function") { if (typeof this !== "function") {
// closest thing possible to the ECMAScript 5 internal IsCallable 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") throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable")
} }
var aArgs = Array.prototype.slice.call(arguments, 1) var aArgs = Array.prototype.slice.call(arguments, 1)
var fToBind = this var that = this
var fNOP = function () {} var Fnoop = function() {}
var fBound = function () { var fBound = function() {
return fToBind.apply(this instanceof fNOP && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments))) return that.apply(this instanceof Fnoop && oThis ? this : oThis, aArgs.concat(Array.prototype.slice.call(arguments)))
} }
fNOP.prototype = this.prototype Fnoop.prototype = this.prototype
fBound.prototype = new fNOP() fBound.prototype = new Fnoop()
return fBound return fBound
} }

View File

@@ -54,23 +54,21 @@ var linkAction = function(el, event) {
} }
module.exports = function(el) { module.exports = function(el) {
var instance = this var that = this
on(el, "click", function(event) { on(el, "click", function(event) {
linkAction.call(instance, el, event) linkAction.call(that, el, event)
}) })
on(el, "keyup", function(event) { on(el, "keyup", function(event) {
// Dont break browser special behavior on links (like page in new window) // Dont break browser special behavior on links (like page in new window)
if (event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) { if (event.which > 1 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) {
el.setAttribute(attrKey, "modifier") el.setAttribute(attrKey, "modifier")
return return
} }
if(event.keyCode == 13) { if (event.keyCode == 13) {
linkAction.call(instance, el, event) linkAction.call(that, el, event)
} }
}.bind(this)) }.bind(this))
} }

View File

@@ -3,5 +3,5 @@ var forEachEls = require("../foreach-els")
var parseElement = require("../parse-element") var parseElement = require("../parse-element")
module.exports = function(el) { module.exports = function(el) {
forEachEls(this.getElements(el), parseElement }, this) forEachEls(this.getElements(el), parseElement, this)
} }

View File

@@ -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.setRequestHeader("X-Requested-With", "XMLHttpRequest")
request.send(null) request.send(null)
return request return request

View File

@@ -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 = { module.exports = {
outerHTML: function(oldEl, newEl, options) { outerHTML: function(oldEl, newEl) {
oldEl.outerHTML = newEl.outerHTML oldEl.outerHTML = newEl.outerHTML
this.onSwitch() this.onSwitch()
}, },
innerHTML: function(oldEl, newEl, options) { innerHTML: function(oldEl, newEl) {
oldEl.innerHTML = newEl.innerHTML oldEl.innerHTML = newEl.innerHTML
oldEl.className = newEl.className oldEl.className = newEl.className
this.onSwitch() this.onSwitch()
@@ -17,7 +22,7 @@ module.exports = {
var fragToAppend = document.createDocumentFragment() var fragToAppend = document.createDocumentFragment()
// height transition are shitty on safari // height transition are shitty on safari
// so commented for now (until I found something ?) // so commented for now (until I found something ?)
//var relevantHeight = 0 // var relevantHeight = 0
var animationEventNames = "animationend webkitAnimationEnd MSAnimationEnd oanimationend" var animationEventNames = "animationend webkitAnimationEnd MSAnimationEnd oanimationend"
var animatedElsNumber = 0 var animatedElsNumber = 0
var sexyAnimationEnd = function(e) { var sexyAnimationEnd = function(e) {
@@ -50,7 +55,7 @@ module.exports = {
// this is to trigger some repaint (example: picturefill) // this is to trigger some repaint (example: picturefill)
this.onSwitch() this.onSwitch()
//Pjax.trigger(window, "scroll") // Pjax.trigger(window, "scroll")
} }
}.bind(this) }.bind(this)
@@ -79,7 +84,7 @@ module.exports = {
el.className += " " + switchOptions.classNames.remove + " " + (options.backward ? switchOptions.classNames.backward : switchOptions.classNames.forward) el.className += " " + switchOptions.classNames.remove + " " + (options.backward ? switchOptions.classNames.backward : switchOptions.classNames.forward)
} }
animatedElsNumber++ animatedElsNumber++
Pjax.on(el, animationEventNames, sexyAnimationEnd, true) on(el, animationEventNames, sexyAnimationEnd, true)
} }
}) })
@@ -97,7 +102,7 @@ module.exports = {
elsToAdd.push(el) elsToAdd.push(el)
fragToAppend.appendChild(el) fragToAppend.appendChild(el)
animatedElsNumber++ animatedElsNumber++
Pjax.on(el, animationEventNames, sexyAnimationEnd, true) on(el, animationEventNames, sexyAnimationEnd, true)
} }
}) })

View File

@@ -7,8 +7,8 @@ var trigger = require("../../lib/events/trigger")
var el = document.createElement("div") var el = document.createElement("div")
var el2 = document.createElement("span") var el2 = document.createElement("span")
var els = [el, el2] var els = [el, el2]
var eventType2 = "resize" // var eventType2 = "resize"
var eventsType = "click resize" // var eventsType = "click resize"
var classCb = function() { var classCb = function() {
this.className += "on" this.className += "on"
} }

View File

@@ -3,7 +3,6 @@ var tape = require("tape")
var parseElement = require("../../../lib/proto/parse-element") var parseElement = require("../../../lib/proto/parse-element")
var protoMock = {attachLink: function() { return true}} var protoMock = {attachLink: function() { return true}}
tape("test parse element prototype method", function(t) { tape("test parse element prototype method", function(t) {
t.doesNotThrow(function() { t.doesNotThrow(function() {
var a = document.createElement("a") var a = document.createElement("a")
parseElement.call(protoMock, a) parseElement.call(protoMock, a)

View File

@@ -3,7 +3,7 @@ var tape = require("tape")
var request = require("../../lib/request.js") var request = require("../../lib/request.js")
tape("test xhr request", function(t) { tape("test xhr request", function(t) {
var xhr = request("https://api.github.com/", function(result) { request("https://api.github.com/", function(result) {
try { try {
result = JSON.parse(result) result = JSON.parse(result)
} }

View File

@@ -1,6 +1,6 @@
var tape = require("tape") var tape = require("tape")
var switchesSelectors = require("../../lib/switches-selectors.js") // var switchesSelectors = require("../../lib/switches-selectors.js")
tape("test switchesSelectors", function(t) { tape("test switchesSelectors", function(t) {
t.fail() t.fail()