Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
some-say committed Sep 15, 2015
0 parents commit bc45526
Show file tree
Hide file tree
Showing 24 changed files with 1,686 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
node_modules
.idea
nbproject
.svn
.project
*.log
/test
94 changes: 94 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details

"maxerr": 50, // {int} Maximum error before stopping

// Enforcing
"bitwise": true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase": false, // true: Identifiers must be in camelCase
"curly": true, // true: Require {} for every new block or scope
"eqeqeq": true, // true: Require triple equals (===) for comparison
"forin": true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed": false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"indent": 4, // {int} Number of spaces to use for indentation
"latedef": false, // true: Require variables/functions to be defined before being used
"newcap": false, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg": true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty": true, // true: Prohibit use of empty blocks
"nonew": false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus": false, // true: Prohibit use of `++` & `--`
"quotmark": false, // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef": true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused": true, // true: Require all defined variables be used
"strict": true, // true: Requires all functions run in ES5 Strict Mode
"maxparams": false, // {int} Max number of formal params allowed per function
"maxdepth": false, // {int} Max depth of nested blocks (within functions)
"maxstatements": false, // {int} Max number statements per function
"maxcomplexity": false, // {int} Max cyclomatic complexity per function
"maxlen": false, // {int} Max number of characters per line

// Relaxing
"asi": false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss": false, // true: Tolerate assignments where comparisons would be expected
"debug": false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull": false, // true: Tolerate use of `== null`
"es5": false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext": false, // true: Allow ES.next (ES6) syntax (ex: `const`)
"moz": false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
// (ex: `for each`, multiple try/catch, function expression�)
"evil": true, // true: Tolerate use of `eval` and `new Function()` - skinner.js (view.js needs it)
"expr": false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope": false, // true: Tolerate defining variables inside control statements"
"globalstrict": false, // true: Allow global "use strict" (also enables 'strict')
"iterator": false, // true: Tolerate using the `__iterator__` property
"lastsemic": false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak": false, // true: Tolerate possibly unsafe line breakings
"laxcomma": false, // true: Tolerate comma-first style coding
"loopfunc": false, // true: Tolerate functions being defined in loops
"multistr": false, // true: Tolerate multi-line strings
"proto": false, // true: Tolerate using the `__proto__` property
"scripturl": false, // true: Tolerate script-targeted URLs
"shadow": false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub": false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew": false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis": false, // true: Tolerate using this in a non-constructor function

// Environments
"browser": true, // Web Browser (window, document, etc)
"couch": false, // CouchDB
"devel": false, // Development/debugging (alert, confirm, etc)
"dojo": false, // Dojo Toolkit
"jquery": true, // jQuery
"mootools": false, // MooTools
"node": false, // Node.js
"nonstandard": false, // Widely adopted globals (escape, unescape, etc)
"prototypejs": false, // Prototype and Scriptaculous
"rhino": false, // Rhino
"worker": false, // Web Workers
"wsh": false, // Windows Scripting Host
"yui": false, // Yahoo User Interface

// Custom Globals
"globals": {
"module": false, // node.js (in Gruntfile.js)
"require": false, // RequireJS
"define": false, // RequireJS
"describe": false, // Jasmine
"it": false, // Jasmine
"xdescribe": false, // Jasmine
"xit": false, // Jasmine
"before": false, // Jasmine
"beforeEach": false, // Jasmine
"after": false, // Jasmine
"afterEach": false, // Jasmine
"jasmine": false, // Jasmine
"expect": false, // Jasmine
"blConfig": false, // Bootloader configuration,
"Bootloader": false //Bootloader
}
}
8 changes: 8 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
language: node_js
node_js:
- '0.12'
- '0.10'
install:
- npm install -g grunt-cli
- npm install
script: grunt
209 changes: 209 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,209 @@
module.exports = function (grunt) {
'use strict';

var matchdep = require('matchdep');
var config = {
pkg: grunt.file.readJSON('package.json')
};

matchdep.filter('grunt-*').forEach(grunt.loadNpmTasks);
matchdep.filterDev('grunt-*').forEach(grunt.loadNpmTasks);

var rdefineEnd = /\}\);[^}\w]*$/;

//base on jQuery strip
function convert(name, path, contents) {
var amdName;
// Convert var modules
if (/.\/var\//.test(path)) {
contents = contents
.replace(/define\([\w\W]*?return/, "var " + (/var\/([\w-]+)/.exec(name)[1]) + " =")
.replace(rdefineEnd, "");

} else {

// Ignore Bootloader's exports (the only necessary one)
if (name !== "bootloader") {
contents = contents
.replace(/\s*return\s+[^\}]+(\}\);[^\w\}]*)$/, "$1")

// Multiple exports
.replace(/\s*exports\.\w+\s*=\s*\w+;/g, "");
}

// Remove define wrappers, closure ends, and empty declarations
contents = contents
.replace(/define\([^{]*?{/, "")
.replace(rdefineEnd, "");

// Remove anything wrapped with
//* ExcludeStart */ /* ExcludeEnd */
// or a single line directly after a // BuildExclude comment
contents = contents
.replace(/\/\*\s*ExcludeStart\s*\*\/[\w\W]*?\/\*\s*ExcludeEnd\s*\*\//ig, "")
.replace(/\/\/\s*BuildExclude\n\r?[\w\W]*?\n\r?/ig, "");
// Remove empty definitions
contents = contents
.replace(/define\(\[[^\]]+\]\)[\W\n]+$/, "");
}
// AMD Name
if ((amdName = grunt.option("amd")) !== null && /^exports\/amd$/.test(name)) {
if (amdName) {
grunt.log.writeln("Naming Bootloader with AMD name: " + amdName);
} else {
grunt.log.writeln("AMD name now anonymous");
}
// Remove the comma for anonymous defines
contents = contents
.replace(/(\s*)"bootloader"(\,\s*)/, amdName ? "$1\"" + amdName + "\"$2" : "");
}
return contents;
}

config.meta = {
banner: "/*!\n * <%= pkg.title %> v<%= pkg.version %> - " +
"<%= grunt.template.today('yyyy-mm-dd') %> - <%= pkg.description %>\n" +
" *\n" +
" * <%= pkg.homepage %>\n" +
" *\n" +
" * Copyright <%= grunt.template.today('yyyy') %> <%= pkg.author %>\n" +
" * Released under the <%= pkg.license %> license.\n */\n\n"
};

/**
* JSHINT
*/
config.jshint = {
options: {

// use custom rules
jshintrc: './.jshintrc',

// report errors but do not fail the task
force: true,

// folders to ignore
ignores: []
},
src: [
'test/**/*Spec.js'
],
build: [
'dist/**/*.js',
'!dist/**/bootloader-frame.js',
'!dist/**/*.min.js'
]
};

config.clean = {
options: {
force: true
},
dist: [
'./dist/**/*.*'
]
};

config.requirejs = {
compile: {
options: {
name: 'bootloader',
baseUrl: './src',
out: 'dist/bootloader.js',
optimize: 'none',
findNestedDependencies: true,
skipSemiColonInsertion: true,
wrap: false,
rawText: {},
onBuildWrite: convert
}
},
iframe: {
options: {
name: 'bootloader-frame',
baseUrl: './src',
out: 'dist/bootloader-frame.js',
optimize: 'none',
findNestedDependencies: true,
skipSemiColonInsertion: true,
wrap: false,
rawText: {},
onBuildWrite: convert
}
}
};

config.umd = {
compile: {
src: 'dist/bootloader.js',
globalAlias: 'Bootloader',
template: 'src/templates/dist.hbs',
dest: 'dist/bootloader.js'
},
iframe: {
src: 'dist/bootloader-frame.min.js',
pkg: config.pkg,
template: 'src/templates/bootloader-frame.hbs',
dest: 'dist/bootloader-frame.html'
}
};

config.uglify = {
options: {
banner: '<%= meta.banner %>',
report: 'gzip'
},
dist: {
files: {
'dist/bootloader.min.js': 'dist/bootloader.js'
}
},
iframe: {
options: {
banner: ''
},
files: {
'dist/bootloader-frame.min.js': 'dist/bootloader-frame.js'
}
}
};

config.usebanner = {
dist: {
options: {
position: 'top',
banner: '<%= meta.banner %>'
},
files: {
src: ['dist/bootloader.js', 'dist/bootloader.js']
}
}
};

config.watch = {
scripts: {
files: './src/**/*.js',
tasks: ['build']
}
};

config.karma = {
options: {
configFile: './karma.conf.js'
},
run: {
options: {
coverageReporter: {
type: 'text-summary'
}
}
}
};

grunt.registerTask('build', ['jshint:src', 'clean', 'requirejs', 'umd:compile', 'uglify', 'umd:iframe', 'usebanner:dist', 'jshint:build']);

// Default grunt
grunt.registerTask('default', ['build']);

grunt.initConfig(config);
};
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Bootloader.JS

## Instalation

`npm install bootloader-js --save`

and add in <HEAD>
```html
<script src="./node_modules/bootloader-js/dist/bootloader.min.js"></script>
```

## Configuration
after script bootloader
```js
<script>
window.blConfig = {
prefix: 'BL.',
lifeTime: 43200000, // default 12 hours
noRequireWaitTime: 10000, // default 10 sec.
cookieName: 'firstLoadBL',
cookieExpires: 43200000, // default 12 hours expires
iframeUrl: false, // for cross origin localStorage
};
</script>
```

## Example

after bootloader script and config
~~~html
<style type="text/css" data-hash="{{ hashFile }}" data-require="1" data-url="{{ urlFile }}"></style>
~~~

for javascript file add in <body>
~~~html
<script type="text/javascript" data-hash="{{ hashFile }}" data-require="1" data-src="{{ urlFile }}"></script>
~~~
11 changes: 11 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"name": "Bootloader.js",
"version": "1.1.2",
"description": "Bootloader.js is a script and resource loader for caching and loading using localStorage.",
"author": "it.esky.pl",
"license": "MIT",
"homepage": "http://it.esky.pl/",
"main": [
"dist/**/*"
]
}
1 change: 1 addition & 0 deletions dist/bootloader-frame.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<!DOCTYPE html><html><head lang="en"><meta charset="UTF-8"><title>bootloader-js v.1.1.2 Frame - Cross-Domain</title><script type="text/javascript">var config={prefix:"BL.",lifeTime:432e5,noRequireWaitTime:1e4,cookieName:"firstLoadBL",cookieExpires:432e5,iframeUrl:!1,iframeOrigin:!1},debug={};try{window.console||(window.console={log:function(){},debug:function(){},info:function(){},warn:function(){},error:function(){}}),debug=console}catch(e){}var hasStorage=!0;try{window.localStorage["BL.checkStorage"]=1,delete window.localStorage["BL.checkStorage"]}catch(e){hasStorage=!1}var localStorage=hasStorage?localStorage||window.localStorage:{},setStorage=function(a,b){if(!hasStorage)return!1;var c=+new Date;try{return localStorage[config.prefix+a]=JSON.stringify({data:b,expiration:c+config.lifeTime}),!0}catch(d){if(d&&d.name.toUpperCase().indexOf("QUOTA")>=0){var e,f=[];for(e in localStorage)localStorage.hasOwnProperty(e)&&-1!==e.indexOf(config.prefix)&&f.push({key:e,value:JSON.parse(localStorage[e])});return f.length?(f.sort(function(a,b){return a.value.expiration-b.value.expiration}),delete localStorage[f[0].key],setStorage(a,b)):!0}return debug.error('Cache: could not add item with key "'+a+'".',d.message),!1}},flushStorage=function(){if(!hasStorage)return!1;var a,b=+new Date;for(a in localStorage)if(localStorage.hasOwnProperty(a)&&-1!==a.indexOf(config.prefix)){var c=JSON.parse(localStorage[a]);c.expiration<b&&delete localStorage[a]}return!0};window.self===window.top&&debug.error("Bootloader: please include in iframe."),(!hasStorage||!1 in window)&&debug.error("Bootloader: localStorage is disabled.");var url="http://"+location.host,urlSsl="https://"+location.host,frameOrigin=window.name||!1;flushStorage();var onMessage=function(a){if(a.origin===url||a.origin===urlSsl||-1!==a.origin.indexOf(frameOrigin)){var b=JSON.parse(a.data);"setStorage"in b?a.source.postMessage(setStorage(b.hash,b.data),a.origin):debug.warn("Bootloader: no action.")}};window.addEventListener?window.addEventListener("message",onMessage,!1):window.attachEvent&&window.attachEvent("onmessage",onMessage);</script></head><body></body></html>
Loading

0 comments on commit bc45526

Please sign in to comment.