Skip to content
Merged
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
65 changes: 65 additions & 0 deletions dist/scopedQuerySelectorShim.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* scopeQuerySelectorShim.js
*
* Copyright (C) 2015 Larry Davis
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*/
(function() {
if (!HTMLElement.prototype.querySelectorAll) {
throw new Error("rootedQuerySelectorAll: This polyfill can only be used with browsers that support querySelectorAll");
}
// A temporary element to query against for elements not currently in the DOM
// We'll also use this element to test for :scope support
var container = document.createElement("div");
// Check if the browser supports :scope
try {
// Browser supports :scope, do nothing
container.querySelectorAll(":scope *");
} catch (e) {
// Match usage of scope
var scopeRE = /^\s*:scope/gi;
// Overrides
function overrideNodeMethod(prototype, methodName) {
// Store the old method for use later
var oldMethod = prototype[methodName];
// Override the method
prototype[methodName] = function(query) {
var nodeList, gaveId = false, gaveContainer = false;
if (query.match(scopeRE)) {
// Remove :scope
query = query.replace(scopeRE, "");
if (!this.parentNode) {
// Add to temporary container
container.appendChild(this);
gaveContainer = true;
}
parentNode = this.parentNode;
if (!this.id) {
// Give temporary ID
this.id = "rootedQuerySelector_id_" + new Date().getTime();
gaveId = true;
}
// Find elements against parent node
nodeList = oldMethod.call(parentNode, "#" + this.id + " " + query);
// Reset the ID
if (gaveId) {
this.id = "";
}
// Remove from temporary container
if (gaveContainer) {
container.removeChild(this);
}
return nodeList;
} else {
// No immediate child selector used
return oldMethod.call(this, query);
}
};
}
// Browser doesn't support :scope, add polyfill
overrideNodeMethod(HTMLElement.prototype, "querySelector");
overrideNodeMethod(HTMLElement.prototype, "querySelectorAll");
}
})();
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

I'm not a big fan of committing built files to the repo, it makes diffs for PRs ugly and bloats the history.

I haven't done enough with bower to know if it's simple to do, but is there a way we can only run the build when we're publishing and not commit the output to master, maybe in a separate branch?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

generally bower packages have a dist folder idea being everything else is ignored and just that is fetched. If people want to fetch everything, or the src folder too, then they use bower exportsOverride to define what gets pulled.
I've never heard of anyone using a separate branch for releases. That seems to be what tags are for...
As far as PRs, you can ignore anything in the diffs directory. Remember those are slave files. Even if there is a conflict on a dist file, Just make sure the source files look ok, merge them if needed, and rebuild.
I guess you could say a src/dest workflow "bloats the history", but is the current method of serving un-minified assets not a bloat on bandwidth? The minified file is 33% smaller.
Aside from optimization, this workflow is proposed so that the repo observes it's own license. Note that the files in the dist/ directory have the required credits.

9 changes: 9 additions & 0 deletions dist/scopedQuerySelectorShim.min.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
/* scopeQuerySelectorShim.js
*
* Copyright (C) 2015 Larry Davis
* All rights reserved.
*
* This software may be modified and distributed under the terms
* of the BSD license. See the LICENSE file for details.
*/
!function(){function a(a,c){var e=a[c];a[c]=function(a){var c,f=!1,g=!1;return a.match(d)?(a=a.replace(d,""),this.parentNode||(b.appendChild(this),g=!0),parentNode=this.parentNode,this.id||(this.id="rootedQuerySelector_id_"+(new Date).getTime(),f=!0),c=e.call(parentNode,"#"+this.id+" "+a),f&&(this.id=""),g&&b.removeChild(this),c):e.call(this,a)}}if(!HTMLElement.prototype.querySelectorAll)throw new Error("rootedQuerySelectorAll: This polyfill can only be used with browsers that support querySelectorAll");var b=document.createElement("div");try{b.querySelectorAll(":scope *")}catch(c){var d=/^\s*:scope/gi;a(HTMLElement.prototype,"querySelector"),a(HTMLElement.prototype,"querySelectorAll")}}();
25 changes: 24 additions & 1 deletion gruntfile.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
module.exports = function(grunt) {
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-karma');

grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
year: new Date().getFullYear(),
jshint: {
gruntfile: 'Gruntfile.js',
tests: 'test/*.js',
Expand All @@ -30,14 +32,35 @@ module.exports = function(grunt) {
singleRun: true
}
},
uglify:{
options:{
banner:'/* scopeQuerySelectorShim.js' + '\n*' + '\n* Copyright (C) <%= year %> Larry Davis' + '\n* All rights reserved.' + '\n*' + '\n* This software may be modified and distributed under the terms' + '\n* of the BSD license. See the LICENSE file for details.' + '\n*/\n'
},
expanded:{
options:{
mangle:false,
compress:false,
beautify:true,
preserveComments:true
},
files:{
'dist/scopedQuerySelectorShim.js':[ 'src/scopedQuerySelectorShim.js' ]
}
},
minified:{
files:{
'dist/scopedQuerySelectorShim.min.js':[ 'src/scopedQuerySelectorShim.js' ]
}
}
},
watchFiles: {
gruntfile: {
files: 'Gruntfile.js',
tasks: 'jshint:gruntfile'
},
src: {
files: [ 'src/**' ],
tasks: [ 'jshint:src', 'karma:watch:run' ]
tasks: [ 'jshint:src', 'uglify', 'karma:watch:run' ]
},
unitTests: {
files: [ 'test/*.js' ],
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"grunt": "~0.4.1",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.9.1",
"grunt-karma": "~0.6.2",
"karma": "~0.10.5",
"karma-firefox-launcher": "~0.1.0",
Expand Down