├── CNAME
├── .gitignore
├── js
├── .gitignore
├── images
│ ├── layers.png
│ ├── layers-2x.png
│ ├── marker-icon.png
│ ├── marker-icon-2x.png
│ └── marker-shadow.png
├── leaflet.spin.js
├── mapSetup.js
├── topojson.v1.min.js
├── leaflet.hash.js
├── leaflet.css
└── colorbrewer.js
├── img
├── glyphicons-halflings.png
└── glyphicons-halflings-white.png
├── jam
├── spin-js
│ ├── package.json
│ └── spin.js
├── catiline
│ ├── LICENCE.md
│ ├── jam
│ │ └── catiline
│ │ │ ├── jam
│ │ │ └── catiline
│ │ │ │ └── package.json
│ │ │ └── package.json
│ ├── package.json
│ ├── README.md
│ └── dist
│ │ └── catiline.js
├── shp
│ ├── package.json
│ └── README.md
├── require.config.js
└── require.js
├── package.json
├── index.html
├── license.md
├── README.md
└── script.js
/CNAME:
--------------------------------------------------------------------------------
1 | leaflet.calvinmetcalf.com
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | .c9revisions
3 | node_modules
--------------------------------------------------------------------------------
/js/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | .c9revisions
3 | node_modules
--------------------------------------------------------------------------------
/js/images/layers.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/calvinmetcalf/leaflet.workspace/HEAD/js/images/layers.png
--------------------------------------------------------------------------------
/js/images/layers-2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/calvinmetcalf/leaflet.workspace/HEAD/js/images/layers-2x.png
--------------------------------------------------------------------------------
/js/images/marker-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/calvinmetcalf/leaflet.workspace/HEAD/js/images/marker-icon.png
--------------------------------------------------------------------------------
/img/glyphicons-halflings.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/calvinmetcalf/leaflet.workspace/HEAD/img/glyphicons-halflings.png
--------------------------------------------------------------------------------
/js/images/marker-icon-2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/calvinmetcalf/leaflet.workspace/HEAD/js/images/marker-icon-2x.png
--------------------------------------------------------------------------------
/js/images/marker-shadow.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/calvinmetcalf/leaflet.workspace/HEAD/js/images/marker-shadow.png
--------------------------------------------------------------------------------
/img/glyphicons-halflings-white.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/calvinmetcalf/leaflet.workspace/HEAD/img/glyphicons-halflings-white.png
--------------------------------------------------------------------------------
/jam/spin-js/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "spin-js",
3 | "version": "1.2.5-jam.1",
4 | "description": "An animated CSS3 loading spinner with VML fallback for IE",
5 | "homepage": "http://fgnass.github.com/spin.js",
6 | "github": "https://github.com/fgnass/spin.js",
7 | "main": "spin.js"
8 | }
9 |
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "leaflet.workspace",
3 | "version": "0.0.0",
4 | "description": "a drag and drop workspace for viewing geojson, topojson, and zipped shapefiles in leaflet",
5 | "main": "index.html",
6 | "scripts": {
7 | "test": "test"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git://github.com/calvinmetcalf/leaflet.workspace.git"
12 | },
13 | "keywords": [
14 | "workspace",
15 | "leaflet",
16 | "map"
17 | ],
18 | "author": "Calvin Metcalf",
19 | "license": "BSD-2-Clause",
20 | "bugs": {
21 | "url": "https://github.com/calvinmetcalf/leaflet.workspace/issues"
22 | },
23 | "private":true,
24 | "jam":{
25 | "dependencies":{
26 | "catiline":">2.8.0",
27 | "shp":">=3.1.3",
28 | "spin-js":"1.2.5-jam.1"
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/index.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 | Leaflet
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/license.md:
--------------------------------------------------------------------------------
1 | #Copyright 2013 Calvin Metcalf
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | _THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE._
--------------------------------------------------------------------------------
/jam/catiline/LICENCE.md:
--------------------------------------------------------------------------------
1 | #Copyright 2013 Calvin Metcalf except where noted.
2 |
3 | Permission is hereby granted, free of charge, to any person obtaining
4 | a copy of this software and associated documentation files (the
5 | "Software"), to deal in the Software without restriction, including
6 | without limitation the rights to use, copy, modify, merge, publish,
7 | distribute, sublicense, and/or sell copies of the Software, and to
8 | permit persons to whom the Software is furnished to do so, subject to
9 | the following conditions:
10 |
11 | The above copyright notice and this permission notice shall be
12 | included in all copies or substantial portions of the Software.
13 |
14 | _THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE._
--------------------------------------------------------------------------------
/jam/catiline/jam/catiline/jam/catiline/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "catiline",
3 | "version": "2.7.0",
4 | "description": "Multi proccessing with workers in the browser.",
5 | "keywords": [
6 | "workers",
7 | "threads",
8 | "parallel"
9 | ],
10 | "author": "Calvin Metcalf (https://github.com/calvinmetcalf)",
11 | "bugs": {
12 | "url": "https://github.com/calvinmetcalf/catiline/issues"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "git://github.com/calvinmetcalf/catiline.git"
17 | },
18 | "scripts": {
19 | "test": "grunt"
20 | },
21 | "main": "dist/catiline.js",
22 | "license": "MIT",
23 | "devDependencies": {
24 | "grunt-cli": "~0.1.9",
25 | "grunt-contrib-uglify": "~0.2.0",
26 | "grunt-contrib-concat": "~0.1.3",
27 | "chai": "~1.5.0",
28 | "grunt-contrib-connect": "~0.3.0",
29 | "grunt-contrib-jshint": "~0.5.4",
30 | "grunt-saucelabs": "~4.0.4",
31 | "grunt": "~0.4.1",
32 | "grunt-mocha-phantomjs": "~0.3.0",
33 | "uglify-js": "~2.3.6",
34 | "lie": "~0.6.2",
35 | "defs": "~0.4.1"
36 | },
37 | "directories": {
38 | "test": "test"
39 | }
40 | }
41 |
--------------------------------------------------------------------------------
/jam/catiline/jam/catiline/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "catiline",
3 | "version": "2.7.1",
4 | "description": "Multi proccessing with workers in the browser.",
5 | "keywords": [
6 | "workers",
7 | "threads",
8 | "parallel"
9 | ],
10 | "author": "Calvin Metcalf (https://github.com/calvinmetcalf)",
11 | "bugs": {
12 | "url": "https://github.com/calvinmetcalf/catiline/issues"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "git://github.com/calvinmetcalf/catiline.git"
17 | },
18 | "scripts": {
19 | "test": "grunt"
20 | },
21 | "jam":{
22 | "include":["README.md","LICENCE.md","dist/catiline.js"]
23 | },
24 | "main": "dist/catiline.js",
25 | "license": "MIT",
26 | "devDependencies": {
27 | "grunt-cli": "~0.1.9",
28 | "grunt-contrib-uglify": "~0.2.0",
29 | "grunt-contrib-concat": "~0.1.3",
30 | "chai": "~1.5.0",
31 | "grunt-contrib-connect": "~0.3.0",
32 | "grunt-contrib-jshint": "~0.5.4",
33 | "grunt-saucelabs": "~4.0.4",
34 | "grunt": "~0.4.1",
35 | "grunt-mocha-phantomjs": "~0.3.0",
36 | "uglify-js": "~2.3.6",
37 | "lie": "~0.6.2",
38 | "defs": "~0.4.1"
39 | },
40 | "directories": {
41 | "test": "test"
42 | }
43 | }
44 |
--------------------------------------------------------------------------------
/jam/catiline/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "catiline",
3 | "version": "2.9.0-dev.2",
4 | "description": "Multi proccessing with workers in the browser.",
5 | "keywords": [
6 | "workers",
7 | "threads",
8 | "parallel"
9 | ],
10 | "author": "Calvin Metcalf (https://github.com/calvinmetcalf)",
11 | "bugs": {
12 | "url": "https://github.com/calvinmetcalf/catiline/issues"
13 | },
14 | "repository": {
15 | "type": "git",
16 | "url": "git://github.com/calvinmetcalf/catiline.git"
17 | },
18 | "scripts": {
19 | "test": "grunt"
20 | },
21 | "jam": {
22 | "include": [
23 | "README.md",
24 | "LICENCE.md",
25 | "dist/catiline.js"
26 | ]
27 | },
28 | "main": "dist/catiline.js",
29 | "license": "MIT",
30 | "devDependencies": {
31 | "grunt-cli": "~0.1.9",
32 | "grunt-contrib-uglify": "~0.2.0",
33 | "grunt-contrib-concat": "~0.1.3",
34 | "chai": "~1.7.2",
35 | "grunt-contrib-connect": "~0.3.0",
36 | "grunt-contrib-jshint": "~0.5.4",
37 | "grunt-saucelabs": "~4.0.4",
38 | "grunt": "~0.4.1",
39 | "uglify-js": "~2.3.6",
40 | "defs": "~0.4.1",
41 | "mocha": "~1.12.1",
42 | "grunt-mocha-phantomjs": "~0.3.0"
43 | },
44 | "directories": {
45 | "test": "test"
46 | }
47 | }
48 |
--------------------------------------------------------------------------------
/jam/shp/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "shpjs",
3 | "version": "3.1.3",
4 | "description": "A binary shapefile loader, for javascript. Not many caveats",
5 | "main": "lib/index.js",
6 | "repository": {
7 | "type": "git",
8 | "url": "git://github.com/calvinmetcalf/shapefile-js.git"
9 | },
10 | "scripts": {
11 | "test": "mocha ./test/test.js",
12 | "hint": "jshint ./lib/*.js",
13 | "build-test": "browserify ./test/test.js > ./test/bundle.js"
14 | },
15 | "author": "Calvin Metcalf",
16 | "license": "MIT",
17 | "readmeFilename": "README.md",
18 | "devDependencies": {
19 | "jshint": "^2.5.1",
20 | "uglify-js": "^2.4.13",
21 | "browserify": "^4.1.5",
22 | "chai-as-promised": "^4.1.1",
23 | "chai": "^1.9.1",
24 | "mocha": "^1.19.0",
25 | "testling": "^1.6.1"
26 | },
27 | "jam": {
28 | "name": "shp",
29 | "main": "dist/shp.js",
30 | "include": [
31 | "dist/shp.js",
32 | "README.md"
33 | ],
34 | "dependencies": {}
35 | },
36 | "categories": [
37 | "Geographic",
38 | "AJAX & Websockets"
39 | ],
40 | "dependencies": {
41 | "parsedbf": "0.0.1",
42 | "jszip": "git://github.com/calvinmetcalf/jszip.git#nobuffer",
43 | "proj4": "~2.1.0",
44 | "lie": "^2.7.6"
45 | },
46 | "browser": {
47 | "./lib/binaryajax.js": "./lib/binaryajax-browser.js"
48 | }
49 | }
50 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | Leaflet Workspace
2 | =====
3 |
4 | Drag and drop, or use the upload button to put a geojson file, topojson or a zipped shapefile onto a map. (geojson and topojson can also be zipped)
5 |
6 | The shapefile is parsed to GeoJSON using shapefile-js, which I also wrote, which uses DataView and array buffers to parse this mixed endian file. There are also promises used in here, kids these days like promises right?
7 |
8 | If you need a file to show [here is a zipped shapefile of the world](http://calvinmetcalf.github.io/shapefile-js/files/TM_WORLD_BORDERS_SIMPL-0.3.zip)
9 |
10 | There is a large amount of geojson in these repos
11 |
12 | - [Cambridge Open Data (also has topojson)](https://github.com/calvinmetcalf/CambridgeOpenData)
13 | - [Massachusetts GIS](https://github.com/calvinmetcalf/MassGIS)
14 | - [Washington D.C.](https://github.com/where-gov/dc-maps)
15 |
16 | Also Uses
17 |
18 | - [leaflet for mapping](http://leafletjs.com/)
19 | - [catiline for workers](http://catilinejs.com)
20 | - [shapefile-js](https://github.com/calvinmetcalf/shapefile-js)
21 | - [jsSHA for hashes](http://caligatio.github.com/jsSHA/)
22 | - [bootstrap for styles](https://github.com/twitter/bootstrap)
23 | - [color specifications and designs developed by Cynthia Brewer ](http://colorbrewer.org/)
24 | - [TopoJSON support from Mike Bostock's library](https://github.com/mbostock/topojson)
--------------------------------------------------------------------------------
/js/leaflet.spin.js:
--------------------------------------------------------------------------------
1 | require(['spin-js'],function(s){
2 | L.SpinMapMixin = {
3 | spin: function (state, options) {
4 | if (!!state) {
5 | // start spinning !
6 | if (!this._spinner) {
7 | this._spinner = new s.Spinner(options).spin(this._container);
8 | this._spinning = 0;
9 | }
10 | this._spinning++;
11 | }
12 | else {
13 | this._spinning--;
14 | if (this._spinning <= 0) {
15 | // end spinning !
16 | if (this._spinner) {
17 | this._spinner.stop();
18 | this._spinner = null;
19 | }
20 | }
21 | }
22 | }
23 | };
24 |
25 | L.Map.include(L.SpinMapMixin);
26 |
27 | L.Map.addInitHook(function () {
28 | this.on('layeradd', function (e) {
29 | // If added layer is currently loading, spin !
30 | if (e.layer.loading) this.spin(true);
31 | if (typeof e.layer.on != 'function') return;
32 | e.layer.on('data:loading', function () { this.spin(true); }, this);
33 | e.layer.on('data:loaded', function () { this.spin(false); }, this);
34 | }, this);
35 | this.on('layerremove', function (e) {
36 | // Clean-up
37 | if (e.layer.loading) this.spin(false);
38 | if (typeof e.layer.on != 'function') return;
39 | e.layer.off('data:loaded');
40 | e.layer.off('data:loading');
41 | }, this);
42 | });
43 | });
44 |
--------------------------------------------------------------------------------
/jam/require.config.js:
--------------------------------------------------------------------------------
1 | var jam = {
2 | "packages": [
3 | {
4 | "name": "catiline",
5 | "location": "jam/catiline",
6 | "main": "dist/catiline.js"
7 | },
8 | {
9 | "name": "shp",
10 | "location": "jam/shp",
11 | "main": "dist/shp.js"
12 | },
13 | {
14 | "name": "spin-js",
15 | "location": "jam/spin-js",
16 | "main": "spin.js"
17 | }
18 | ],
19 | "version": "0.2.17",
20 | "shim": {}
21 | };
22 |
23 | if (typeof require !== "undefined" && require.config) {
24 | require.config({
25 | "packages": [
26 | {
27 | "name": "catiline",
28 | "location": "jam/catiline",
29 | "main": "dist/catiline.js"
30 | },
31 | {
32 | "name": "shp",
33 | "location": "jam/shp",
34 | "main": "dist/shp.js"
35 | },
36 | {
37 | "name": "spin-js",
38 | "location": "jam/spin-js",
39 | "main": "spin.js"
40 | }
41 | ],
42 | "shim": {}
43 | });
44 | }
45 | else {
46 | var require = {
47 | "packages": [
48 | {
49 | "name": "catiline",
50 | "location": "jam/catiline",
51 | "main": "dist/catiline.js"
52 | },
53 | {
54 | "name": "shp",
55 | "location": "jam/shp",
56 | "main": "dist/shp.js"
57 | },
58 | {
59 | "name": "spin-js",
60 | "location": "jam/spin-js",
61 | "main": "spin.js"
62 | }
63 | ],
64 | "shim": {}
65 | };
66 | }
67 |
68 | if (typeof exports !== "undefined" && typeof module !== "undefined") {
69 | module.exports = jam;
70 | }
--------------------------------------------------------------------------------
/jam/catiline/README.md:
--------------------------------------------------------------------------------
1 | __Catiline.js__ is a JavaScript library all about workers. Workers should make your life easier, not harder, and with Catiline.js launching a new worker is as simple as calling a function. It works the same across all (modern) browsers. Formerly known as Communist.js, Catiline.js is the same great library with a less controversial name.
2 |
3 | How easy is it? `var worker = cw(myFunc)` creates a worker. Send it data with `var response = worker.data(YOUR DATA);`, and the response is a [promise](http://blogs.msdn.com/b/ie/archive/2011/09/11/asynchronous-programming-in-javascript-with-promises.aspx). It's that easy. For more in-depth usage, checkout the examples bellow or the
4 |
5 | API page.
6 |
7 | Want to use it? Grab the
8 | [development version](https://raw.github.com/calvinmetcalf/catiline/master/dist/catiline.js)
9 | or [production version](https://raw.github.com/calvinmetcalf/catiline/master/dist/catiline.min.js) from the dist folder.
10 |
11 | For usage in addition to the API page and documentation, I wrote a [blog post](http://cwmma.tumblr.com/post/54338607071/making-web-workers-with-communistjs) about Catiline.js (under its old name). Or, you can browse some demos:
12 |
13 | - [Parsing a dictionary](http://catilinejs.com/website/dict/)
14 | - [Fractal Map](http://catilinejs.com/website/leaflet-fractal/), (April Mozilla Dev Derby [Finalist](https://hacks.mozilla.org/2013/06/announcing-the-winners-of-the-april-2013-dev-derby/))
15 | - [RTree Bounding Boxes](http://leaflet-extras.github.io/RTree/examples/worker.html)
16 | - [Census Visualization](http://data-otp.rhcloud.com/)
17 | - [Vector Map Tiles](http://calvinmetcalf.github.io/vector-layers/)
18 | - [Unzipping files and reprojecting maps](http://calvinmetcalf.github.io/shapefile-js/site/proj.html)
19 |
20 | Updates and changes are all in the changelog.
21 |
22 | There is also a plugin list.
23 |
24 | __Important:__ the file catiline.js or catiline.min.js should be a standalone file hosted on the same domain as your web page. If you can't, or need to bundle catiline but you need it to work on IE10, Opera, and Safari, you have to host the file "SHIM_WORKER.js" on the same domain as the html file
25 | and set the path to it in a global variable `SHIM_WORKER_PATH` before you load catiline.
26 |
27 | This grew out of my work with [earlier versions](https://github.com/calvinmetcalf/catiline/tree/6e920be75ab3ed9b2a36d24dd184a9945f6b4000)
28 | of this library and my [differences in opinion](https://gist.github.com/calvinmetcalf/6050205) with
29 | [Parallel.js](https://github.com/adambom/parallel.js)'s direction. There is
30 | also a library doing very similar things called [operative](https://github.com/padolsey/operative).
31 |
32 | [](https://saucelabs.com/u/calvinmetcalf)
33 |
--------------------------------------------------------------------------------
/js/mapSetup.js:
--------------------------------------------------------------------------------
1 | L.Control.Layers.prototype._addItem = function(obj) {
2 | var label = document.createElement('label'),
3 | input,
4 | checked = this._map.hasLayer(obj.layer);
5 |
6 | if (obj.overlay) {
7 | input = document.createElement('input');
8 | input.type = 'checkbox';
9 | input.className = 'leaflet-control-layers-selector';
10 | input.defaultChecked = checked;
11 | }
12 | else {
13 | input = this._createRadioElement('leaflet-base-layers', checked);
14 | }
15 |
16 | input.layerId = L.stamp(obj.layer);
17 |
18 | L.DomEvent.on(input, 'click', this._onInputClick, this);
19 |
20 | var name = document.createElement('span');
21 | name.innerHTML = ' ' + obj.name;
22 |
23 | label.appendChild(input);
24 | label.appendChild(name);
25 | label.className = obj.overlay ? "checkbox" : "radio";
26 | var container = obj.overlay ? this._overlaysList : this._baseLayersList;
27 | container.appendChild(label);
28 |
29 | return label;
30 | }
31 | var m = L.map("map", {
32 | zoomControl: false
33 | });
34 | if (!location.hash) {
35 | m.setView([32.69, 10.55], 3);
36 | }
37 | m.addHash();
38 | var url = 'http://{s}.tile.stamen.com/toner/{z}/{x}/{y}.png'
39 |
40 | var optionsObject ={
41 | attribution: 'Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap contributors, CC-BY-SA'
42 | }
43 |
44 | var mq = L.tileLayer(url, optionsObject);
45 | var watercolor = L.tileLayer('http://{s}.tile.stamen.com/watercolor/{z}/{x}/{y}.jpg', {
46 | attribution: 'Map tiles by Stamen Design, CC BY 3.0 — Map data © OpenStreetMap contributors, CC-BY-SA'
47 | })
48 | mq.addTo(m);
49 | var lc = L.control.layers({
50 | "Stamen Watercolor": watercolor,
51 | "Stamen Toner": mq
52 | }).addTo(m);
53 | //make the map
54 | var options = {
55 | onEachFeature: function(feature, layer) {
56 | if (feature.properties) {
57 | layer.bindPopup(Object.keys(feature.properties).map(function(k) {
58 | if(k === '__color__'){
59 | return;
60 | }
61 | return k + ": " + feature.properties[k];
62 | }).join("
"), {
63 | maxHeight: 200
64 | });
65 | }
66 | },
67 | style: function(feature) {
68 | return {
69 | opacity: 1,
70 | fillOpacity: 0.7,
71 | radius: 6,
72 | color: feature.properties.__color__
73 | }
74 | },
75 | pointToLayer: function(feature, latlng) {
76 | return L.circleMarker(latlng, {
77 | opacity: 1,
78 | fillOpacity: 0.7,
79 | color: feature.properties.__color__
80 | });
81 | }
82 | };
83 |
--------------------------------------------------------------------------------
/js/topojson.v1.min.js:
--------------------------------------------------------------------------------
1 | topojson=function(){function e(e,t){function n(t){var n=e.arcs[t],r=n[0],o=[0,0];return n.forEach(function(e){o[0]+=e[0],o[1]+=e[1]}),[r,o]}var r={},o={};t.forEach(function(e){var t,a,i=n(e),u=i[0],c=i[1];if(t=o[u])if(delete o[t.end],t.push(e),t.end=c,a=r[c]){delete r[a.start];var s=a===t?t:t.concat(a);r[s.start=t.start]=o[s.end=a.end]=s}else if(a=o[c]){delete r[a.start],delete o[a.end];var s=t.concat(a.map(function(e){return~e}).reverse());r[s.start=t.start]=o[s.end=a.start]=s}else r[t.start]=o[t.end]=t;else if(t=r[c])if(delete r[t.start],t.unshift(e),t.start=u,a=o[u]){delete o[a.end];var f=a===t?t:a.concat(t);r[f.start=a.start]=o[f.end=t.end]=f}else if(a=r[u]){delete r[a.start],delete o[a.end];var f=a.map(function(e){return~e}).reverse().concat(t);r[f.start=a.end]=o[f.end=t.end]=f}else r[t.start]=o[t.end]=t;else if(t=r[u])if(delete r[t.start],t.unshift(~e),t.start=c,a=o[c]){delete o[a.end];var f=a===t?t:a.concat(t);r[f.start=a.start]=o[f.end=t.end]=f}else if(a=r[c]){delete r[a.start],delete o[a.end];var f=a.map(function(e){return~e}).reverse().concat(t);r[f.start=a.end]=o[f.end=t.end]=f}else r[t.start]=o[t.end]=t;else if(t=o[c])if(delete o[t.end],t.push(~e),t.end=u,a=o[u]){delete r[a.start];var s=a===t?t:t.concat(a);r[s.start=t.start]=o[s.end=a.end]=s}else if(a=r[u]){delete r[a.start],delete o[a.end];var s=t.concat(a.map(function(e){return~e}).reverse());r[s.start=t.start]=o[s.end=a.start]=s}else r[t.start]=o[t.end]=t;else t=[e],r[t.start=u]=o[t.end=c]=t});var a=[];for(var i in o)a.push(o[i]);return a}function t(t,n,r){function a(e){0>e&&(e=~e),(l[e]||(l[e]=[])).push(f)}function i(e){e.forEach(a)}function u(e){e.forEach(i)}function c(e){e.type==="GeometryCollection"?e.geometries.forEach(c):e.type in d&&(f=e,d[e.type](e.arcs))}var s=[];if(arguments.length>1){var f,l=[],d={LineString:i,MultiLineString:u,Polygon:u,MultiPolygon:function(e){e.forEach(u)}};c(n),l.forEach(arguments.length<3?function(e,t){s.push(t)}:function(e,t){r(e[0],e[e.length-1])&&s.push(t)})}else for(var p=0,h=t.arcs.length;h>p;++p)s.push(p);return o(t,{type:"MultiLineString",arcs:e(t,s)})}function n(e,t){return t.type==="GeometryCollection"?{type:"FeatureCollection",features:t.geometries.map(function(t){return r(e,t)})}:r(e,t)}function r(e,t){var n={type:"Feature",id:t.id,properties:t.properties||{},geometry:o(e,t)};return t.id==null&&delete n.id,n}function o(e,t){function n(e,t){t.length&&t.pop();for(var n,r=h[0>e?~e:e],o=0,i=r.length,u=0,c=0;i>o;++o)t.push([(u+=(n=r[o])[0])*f+d,(c+=n[1])*l+p]);0>e&&a(t,i)}function r(e){return[e[0]*f+d,e[1]*l+p]}function o(e){for(var t=[],r=0,o=e.length;o>r;++r)n(e[r],t);return t.length<2&&t.push(t[0].slice()),t}function i(e){for(var t=o(e);t.length<4;)t.push(t[0].slice());return t}function u(e){return e.map(i)}function c(e){var t=e.type;return"GeometryCollection"===t?{type:t,geometries:e.geometries.map(c)}:t in v?{type:t,coordinates:v[t](e)}:null}var s=e.transform,f=s.scale[0],l=s.scale[1],d=s.translate[0],p=s.translate[1],h=e.arcs,v={Point:function(e){return r(e.coordinates)},MultiPoint:function(e){return e.coordinates.map(r)},LineString:function(e){return o(e.arcs)},MultiLineString:function(e){return e.arcs.map(o)},Polygon:function(e){return u(e.arcs)},MultiPolygon:function(e){return e.arcs.map(u)}};return c(t)}function a(e,t){for(var n,r=e.length,o=r-t;o<--r;)n=e[o],e[o++]=e[r],e[r]=n}function i(e,t){for(var n=0,r=e.length;r>n;){var o=n+r>>>1;e[o]e&&(e=~e);var n=o[e];n?n.push(t):o[e]=[t]})}function n(e,n){e.forEach(function(e){t(e,n)})}function r(e,t){e.type==="GeometryCollection"?e.geometries.forEach(function(e){r(e,t)}):e.type in u&&u[e.type](e.arcs,t)}var o={},a=e.map(function(){return[]}),u={LineString:t,MultiLineString:n,Polygon:n,MultiPolygon:function(e,t){e.forEach(function(e){n(e,t)})}};e.forEach(r);for(var c in o)for(var s=o[c],f=s.length,l=0;f>l;++l)for(var d=l+1;f>d;++d){var p,h=s[l],v=s[d];(p=a[h])[c=i(p,v)]!==v&&p.splice(c,0,v),(p=a[v])[c=i(p,h)]!==h&&p.splice(c,0,h)}return a}return{version:"1.2.3",mesh:t,feature:n,neighbors:u}}();
--------------------------------------------------------------------------------
/js/leaflet.hash.js:
--------------------------------------------------------------------------------
1 | (function(window) {
2 | var HAS_HASHCHANGE = (function() {
3 | var doc_mode = window.documentMode;
4 | return ('onhashchange' in window) &&
5 | (doc_mode === undefined || doc_mode > 7);
6 | })();
7 |
8 | L.Hash = function(map) {
9 | this.onHashChange = L.Util.bind(this.onHashChange, this);
10 |
11 | if (map) {
12 | this.init(map);
13 | }
14 | };
15 |
16 | L.Hash.parseHash = function(hash) {
17 | if(hash.indexOf('#') === 0) {
18 | hash = hash.substr(1);
19 | }
20 | var args = hash.split("/");
21 | if (args.length == 3) {
22 | var zoom = parseInt(args[0], 10),
23 | lat = parseFloat(args[1]),
24 | lon = parseFloat(args[2]);
25 | if (isNaN(zoom) || isNaN(lat) || isNaN(lon)) {
26 | return false;
27 | } else {
28 | return {
29 | center: new L.LatLng(lat, lon),
30 | zoom: zoom
31 | };
32 | }
33 | } else {
34 | return false;
35 | }
36 | };
37 |
38 | L.Hash.formatHash = function(map) {
39 | var center = map.getCenter(),
40 | zoom = map.getZoom(),
41 | precision = Math.max(0, Math.ceil(Math.log(zoom) / Math.LN2));
42 |
43 | return "#" + [zoom,
44 | center.lat.toFixed(precision),
45 | center.lng.toFixed(precision)
46 | ].join("/");
47 | },
48 |
49 | L.Hash.prototype = {
50 | map: null,
51 | lastHash: null,
52 |
53 | parseHash: L.Hash.parseHash,
54 | formatHash: L.Hash.formatHash,
55 |
56 | init: function(map) {
57 | this.map = map;
58 |
59 | // reset the hash
60 | this.lastHash = null;
61 | this.onHashChange();
62 |
63 | if (!this.isListening) {
64 | this.startListening();
65 | }
66 | },
67 |
68 | remove: function() {
69 | if (this.changeTimeout) {
70 | clearTimeout(this.changeTimeout);
71 | }
72 |
73 | if (this.isListening) {
74 | this.stopListening();
75 | }
76 |
77 | this.map = null;
78 | },
79 |
80 | onMapMove: function() {
81 | // bail if we're moving the map (updating from a hash),
82 | // or if the map is not yet loaded
83 |
84 | if (this.movingMap || !this.map._loaded) {
85 | return false;
86 | }
87 |
88 | var hash = this.formatHash(this.map);
89 | if (this.lastHash != hash) {
90 | location.replace(hash);
91 | this.lastHash = hash;
92 | }
93 | },
94 |
95 | movingMap: false,
96 | update: function() {
97 | var hash = location.hash;
98 | if (hash === this.lastHash) {
99 | return;
100 | }
101 | var parsed = this.parseHash(hash);
102 | if (parsed) {
103 | this.movingMap = true;
104 |
105 | this.map.setView(parsed.center, parsed.zoom);
106 |
107 | this.movingMap = false;
108 | } else {
109 | this.onMapMove(this.map);
110 | }
111 | },
112 |
113 | // defer hash change updates every 100ms
114 | changeDefer: 100,
115 | changeTimeout: null,
116 | onHashChange: function() {
117 | // throttle calls to update() so that they only happen every
118 | // `changeDefer` ms
119 | if (!this.changeTimeout) {
120 | var that = this;
121 | this.changeTimeout = setTimeout(function() {
122 | that.update();
123 | that.changeTimeout = null;
124 | }, this.changeDefer);
125 | }
126 | },
127 |
128 | isListening: false,
129 | hashChangeInterval: null,
130 | startListening: function() {
131 | this.map.on("moveend", this.onMapMove, this);
132 |
133 | if (HAS_HASHCHANGE) {
134 | L.DomEvent.addListener(window, "hashchange", this.onHashChange);
135 | } else {
136 | clearInterval(this.hashChangeInterval);
137 | this.hashChangeInterval = setInterval(this.onHashChange, 50);
138 | }
139 | this.isListening = true;
140 | },
141 |
142 | stopListening: function() {
143 | this.map.off("moveend", this.onMapMove, this);
144 |
145 | if (HAS_HASHCHANGE) {
146 | L.DomEvent.removeListener(window, "hashchange", this.onHashChange);
147 | } else {
148 | clearInterval(this.hashChangeInterval);
149 | }
150 | this.isListening = false;
151 | }
152 | };
153 | L.hash = function(map) {
154 | return new L.Hash(map);
155 | };
156 | L.Map.prototype.addHash = function() {
157 | this._hash = L.hash(this);
158 | };
159 | L.Map.prototype.removeHash = function() {
160 | this._hash.remove();
161 | };
162 | })(window);
--------------------------------------------------------------------------------
/jam/shp/README.md:
--------------------------------------------------------------------------------
1 | # Shapefile.js
2 |
3 | Redoing all of this in modern JS. Promises, Typed Arrays, other hipster things, I wouldn't say it's based on [RandomEtc's version](https://github.com/RandomEtc/shapefile-js) as much as inspired by it as there is 0 code shared and I really only read the binary ajax part of his (hence why my function has the same name, they are otherwise not related). My sources were:
4 |
5 | - [wikipedia article](https://en.wikipedia.org/wiki/Shapefile)
6 | - [ESRI white paper](http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf)
7 | - [This page on Xbase](http://www.clicketyclick.dk/databases/xbase/format/dbf.html)
8 |
9 | ##Demos
10 |
11 | - [Countries/zipfile](http://calvinmetcalf.github.io/shapefile-js)
12 | - [Google maps](http://calvinmetcalf.github.io/shapefile-js/site/map.html)
13 | - [Local Zipfile](http://leaflet.calvinmetcalf.com)
14 | - [Projected big with web workers](http://calvinmetcalf.github.io/shapefile-js/site/proj.html)
15 | - [Projected small](http://calvinmetcalf.github.io/shapefile-js/site/proj-small.html)
16 |
17 | ##API
18 |
19 | Has a function `shp` which accepts a string which is the path the she shapefile minus the extension and returns a promise which resolves into geojson.
20 |
21 | ```javascript
22 | //for the shapefiles in the folder called 'files' with the name pandr.shp
23 | shp("files/pandr").then(function(geojson){
24 | //do something with your geojson
25 | });
26 | ```
27 | or you can call it on a .zip file which contains the shapefile
28 |
29 | ```javascript
30 | //for the shapefiles in the files folder called pandr.shp
31 | shp("files/pandr.zip").then(function(geojson){
32 | //see bellow for whats here this internally call shp.parseZip()
33 | });
34 | ```
35 |
36 | or if you got the zip some other way (like the file api) then with the arrayBuffer you can call
37 |
38 | ```javascript
39 | shp(buffer).then(function(geojson){});
40 | //or
41 | shp.parseZip(buffer)->returns zip
42 | ```
43 | If there is only one shp in the zipefile it returns geojson, if there are multiple then it will be an array. All of the geojson objects have an extra key `fileName` the value of which is the
44 | name of the shapefile minus the extension (I.E. the part of the name that's the same for all of them)
45 |
46 | You could also load the arraybuffers seperately:
47 |
48 | ```javascript
49 | shp.combine([shp.parseShp(shpBuffer, /*optional prj str*/),shp.parseDbf(dbfBuffer)]);
50 | ```
51 |
52 | ##Stick it in a worker
53 |
54 | I used my library [catiline](http://catilinejs.com/) to parallelize the demos to do so I changed
55 |
56 | ```html
57 |
58 |
63 | ```
64 |
65 | to
66 |
67 | ```html
68 |
69 |
79 | ```
80 |
81 | to send the worker a buffer from the file api you'd do (I'm omitting where you include the catiline script)
82 |
83 | ```javascript
84 | var worker = cw(function(data){
85 | importScripts('../dist/shp.js');
86 | return shp.parseZip(data);
87 | });
88 |
89 | worker.data(reader.result,[reader.result]).then(function(data){
90 | //do stuff with data
91 | });
92 | ```
93 |
94 | ##Done
95 |
96 | - Binary Ajax
97 | - parsing the shp
98 | - parse the dbf
99 | - join em
100 | - zip
101 | - file api
102 | - Some Projections
103 | - More Projections
104 |
105 | ##to do
106 |
107 | - check for geometry validity.
108 | - Tests
109 |
110 |
111 | ##LICENSE
112 | Main library MIT license, original version was less permissive but there is 0 code shared. Included libraries are under their respective lisenses which are:
113 | - [JSZip](https://github.com/Stuk/jszip/) by @Stuk MIT or GPLv3
114 | - [lie](https://github.com/calvinmetcalf/lie) by me and @RubenVerborgh MIT
115 | - [setImmediate](https://github.com/NobleJS/setImmediate) by @NobleJS et al MIT
116 | - [World Borders shapefile](http://thematicmapping.org/downloads/world_borders.php) is CC-BY-SA 3.0.
117 | - Park and Ride shapefile is from [MassDOT](http://mass.gov/massdot) and is public domain.
118 | - MA town boundaries from [MassGIS](http://www.mass.gov/anf/research-and-tech/it-serv-and-support/application-serv/office-of-geographic-information-massgis/) and is public domain
119 | - NJ County Boundaries from [NJgin](https://njgin.state.nj.us/NJ_NJGINExplorer/index.jsp) and should be public domain.
120 | - [Proj4js](https://github.com/proj4js/proj4js) by me et al MIT
121 |
--------------------------------------------------------------------------------
/script.js:
--------------------------------------------------------------------------------
1 | require(['catiline'], function(cw) {
2 | var worker = cw({
3 | init: function(scope) {
4 | importScripts('jam/require.js');
5 | require.config({
6 | baseUrl: this.base
7 | });
8 | require(['shp'], function(shp) {
9 | scope.shp = shp;
10 | });
11 | },
12 | data: function(data, cb, scope) {
13 | this.shp(data).then(function(geoJson){
14 | if(Array.isArray(geoJson)){
15 | geoJson.forEach(function(geo){
16 | scope.json([geo, geo.fileName, true],true,scope);
17 | });
18 | }else{
19 | scope.json([geoJson, geoJson.fileName, true],true,scope);
20 | }
21 | }, function(e) {
22 | console.log('shit', e);
23 | });
24 |
25 | },
26 | color:function(s){
27 | //from http://stackoverflow.com/a/15710692
28 | importScripts('js/colorbrewer.js');
29 | return colorbrewer.Spectral[11][Math.abs(JSON.stringify(s).split("").reduce(function(a,b){a=((a<<5)-a)+b.charCodeAt(0);return a&a},0)) % 11];
30 | },
31 | makeString:function(buffer) {
32 | var array = new Uint8Array(buffer);
33 | var len = array.length;
34 | var outString = "";
35 | var i = 0;
36 | while (i < len) {
37 | outString += String.fromCharCode(array[i++]);
38 | }
39 | return outString;
40 | },
41 | json: function(data, cb, scope) {
42 | importScripts('js/topojson.v1.min.js');
43 | var name = data[1];
44 | //console.log(name);
45 | var json = data.length === 2 ? JSON.parse(scope.makeString(data[0])) : data[0];
46 | var nom;
47 | if (json.type === 'Topology') {
48 | for (nom in json.objects) {
49 | scope.layer(topojson.feature(json, json.objects[nom]), nom, scope);
50 | }
51 | }
52 | else {
53 | scope.layer(json, name, scope);
54 | }
55 | },layer:function(json,name,scope){
56 |
57 | json.features.forEach(function(feature){
58 | feature.properties.__color__ = scope.color(feature);
59 | });
60 | scope.fire('json',[json,name]);
61 | },
62 | base: cw.makeUrl('.')
63 | });
64 | function readerLoad() {
65 | if (this.readyState !== 2 || this.error) {
66 | return;
67 | }
68 | else {
69 | worker.data(this.result, [this.result]);
70 | }
71 | }
72 |
73 | function handleZipFile(file) {
74 |
75 | var reader = new FileReader();
76 | reader.onload = readerLoad;
77 | reader.readAsArrayBuffer(file);
78 | }
79 |
80 | function handleFile(file) {
81 |
82 | m.spin(true);
83 | if (file.name.slice(-3) === 'zip') {
84 | return handleZipFile(file);
85 | }
86 | var reader = new FileReader();
87 | reader.onload = function() {
88 | var ext;
89 | if (reader.readyState !== 2 || reader.error) {
90 | return;
91 | }
92 | else {
93 | ext = file.name.split('.');
94 | ext = ext[ext.length - 1];
95 |
96 |
97 | worker.json([reader.result, file.name.slice(0, (0 - (ext.length + 1)))], [reader.result]);
98 | }
99 | };
100 | reader.readAsArrayBuffer(file);
101 | }
102 |
103 | function makeDiv() {
104 | var div = L.DomUtil.create('form', 'bgroup');
105 | div.id = "dropzone";
106 | return div;
107 | }
108 |
109 | function makeUp(div, handleFile) {
110 | var upButton = L.DomUtil.create('input', 'upStuff', div);
111 | upButton.type = "file";
112 | upButton.id = "input";
113 | upButton.onchange = function() {
114 | var file = document.getElementById("input").files[0];
115 |
116 | handleFile(file);
117 | };
118 | return upButton;
119 | }
120 |
121 | function setWorkerEvents() {
122 | worker.on('json', function(e) {
123 | m.spin(false);
124 | lc.addOverlay(L.geoJson(e[0], options).addTo(m), e[1]);
125 | });
126 | worker.on('error', function(e) {
127 | console.warn(e);
128 | });
129 | }
130 |
131 | function makeDone(div, upButton) {
132 | var doneButton = L.DomUtil.create('button', "btn btn-primary span3", div);
133 | doneButton.type = "button";
134 | doneButton.innerHTML = "Upload File
(or Drag and Drop Anywhere)
GeoJSON, TopoJSON, or Zipped Shapefile Work";
135 | L.DomEvent.addListener(doneButton, "click", function() {
136 | upButton.click();
137 | });
138 | return doneButton;
139 | }
140 |
141 | function addFunction(map) {
142 | // create the control container with a particular class name
143 | var div = makeDiv();
144 | var upButton = makeUp(div, handleFile);
145 | setWorkerEvents()
146 | var doneButton = makeDone(div, upButton);
147 |
148 |
149 |
150 |
151 |
152 |
153 | var dropbox = document.getElementById("map");
154 | dropbox.addEventListener("dragenter", dragenter, false);
155 | dropbox.addEventListener("dragover", dragover, false);
156 | dropbox.addEventListener("drop", drop, false);
157 | dropbox.addEventListener("dragleave", function() {
158 | m.scrollWheelZoom.enable();
159 | }, false);
160 |
161 | function dragenter(e) {
162 | e.stopPropagation();
163 | e.preventDefault();
164 | m.scrollWheelZoom.disable();
165 | }
166 |
167 | function dragover(e) {
168 | e.stopPropagation();
169 | e.preventDefault();
170 | }
171 |
172 | function drop(e) {
173 | e.stopPropagation();
174 | e.preventDefault();
175 | m.scrollWheelZoom.enable();
176 | var dt = e.dataTransfer;
177 | var files = dt.files;
178 |
179 | var i = 0;
180 | var len = files.length;
181 | if (!len) {
182 | return
183 | }
184 | while (i < len) {
185 | handleFile(files[i]);
186 | i++;
187 | }
188 | }
189 | return div;
190 | }
191 | var NewButton = L.Control.extend({ //creating the buttons
192 | options: {
193 | position: 'topleft'
194 | },
195 | onAdd: addFunction
196 | });
197 | //add them to the map
198 | m.addControl(new NewButton());
199 |
200 | });
201 |
--------------------------------------------------------------------------------
/jam/spin-js/spin.js:
--------------------------------------------------------------------------------
1 | //fgnass.github.com/spin.js#v1.2.5
2 |
3 | define('spin-js', [], function () {
4 |
5 | /**
6 | * Copyright (c) 2011 Felix Gnass [fgnass at neteye dot de]
7 | * Licensed under the MIT license
8 | */
9 |
10 | var prefixes = ['webkit', 'Moz', 'ms', 'O']; /* Vendor prefixes */
11 | var animations = {}; /* Animation rules keyed by their name */
12 | var useCssAnimations;
13 |
14 | /**
15 | * Utility function to create elements. If no tag name is given,
16 | * a DIV is created. Optionally properties can be passed.
17 | */
18 | function createEl(tag, prop) {
19 | var el = document.createElement(tag || 'div');
20 | var n;
21 |
22 | for(n in prop) {
23 | el[n] = prop[n];
24 | }
25 | return el;
26 | }
27 |
28 | /**
29 | * Appends children and returns the parent.
30 | */
31 | function ins(parent /* child1, child2, ...*/) {
32 | for (var i=1, n=arguments.length; i> 1) : o.left+mid) + 'px',
164 | top: (o.top == 'auto' ? tp.y-ep.y + (target.offsetHeight >> 1) : o.top+mid) + 'px'
165 | });
166 | }
167 |
168 | el.setAttribute('aria-role', 'progressbar');
169 | self.lines(el, self.opts);
170 |
171 | if (!useCssAnimations) {
172 | // No CSS animation support, use setTimeout() instead
173 | var i = 0;
174 | var fps = o.fps;
175 | var f = fps/o.speed;
176 | var ostep = (1-o.opacity)/(f*o.trail / 100);
177 | var astep = f/o.lines;
178 |
179 | !function anim() {
180 | i++;
181 | for (var s=o.lines; s; s--) {
182 | var alpha = Math.max(1-(i+s*astep)%f * ostep, o.opacity);
183 | self.opacity(el, o.lines-s, alpha, o);
184 | }
185 | self.timeout = self.el && setTimeout(anim, ~~(1000/fps));
186 | }();
187 | }
188 | return self;
189 | },
190 | stop: function() {
191 | var el = this.el;
192 | if (el) {
193 | clearTimeout(this.timeout);
194 | if (el.parentNode) el.parentNode.removeChild(el);
195 | this.el = undefined;
196 | }
197 | return this;
198 | },
199 | lines: function(el, o) {
200 | var i = 0;
201 | var seg;
202 |
203 | function fill(color, shadow) {
204 | return css(createEl(), {
205 | position: 'absolute',
206 | width: (o.length+o.width) + 'px',
207 | height: o.width + 'px',
208 | background: color,
209 | boxShadow: shadow,
210 | transformOrigin: 'left',
211 | transform: 'rotate(' + ~~(360/o.lines*i+o.rotate) + 'deg) translate(' + o.radius+'px' +',0)',
212 | borderRadius: (o.width>>1) + 'px'
213 | });
214 | }
215 | for (; i < o.lines; i++) {
216 | seg = css(createEl(), {
217 | position: 'absolute',
218 | top: 1+~(o.width/2) + 'px',
219 | transform: o.hwaccel ? 'translate3d(0,0,0)' : '',
220 | opacity: o.opacity,
221 | animation: useCssAnimations && addAnimation(o.opacity, o.trail, i, o.lines) + ' ' + 1/o.speed + 's linear infinite'
222 | });
223 | if (o.shadow) ins(seg, css(fill('#000', '0 0 4px ' + '#000'), {top: 2+'px'}));
224 | ins(el, ins(seg, fill(o.color, '0 0 1px rgba(0,0,0,.1)')));
225 | }
226 | return el;
227 | },
228 | opacity: function(el, i, val) {
229 | if (i < el.childNodes.length) el.childNodes[i].style.opacity = val;
230 | }
231 | });
232 |
233 | /////////////////////////////////////////////////////////////////////////
234 | // VML rendering for IE
235 | /////////////////////////////////////////////////////////////////////////
236 |
237 | /**
238 | * Check and init VML support
239 | */
240 | !function() {
241 |
242 | function vml(tag, attr) {
243 | return createEl('<' + tag + ' xmlns="urn:schemas-microsoft.com:vml" class="spin-vml">', attr);
244 | }
245 |
246 | var s = css(createEl('group'), {behavior: 'url(#default#VML)'});
247 |
248 | if (!vendor(s, 'transform') && s.adj) {
249 |
250 | // VML support detected. Insert CSS rule ...
251 | sheet.addRule('.spin-vml', 'behavior:url(#default#VML)');
252 |
253 | Spinner.prototype.lines = function(el, o) {
254 | var r = o.length+o.width;
255 | var s = 2*r;
256 |
257 | function grp() {
258 | return css(vml('group', {coordsize: s +' '+s, coordorigin: -r +' '+-r}), {width: s, height: s});
259 | }
260 |
261 | var margin = -(o.width+o.length)*2+'px';
262 | var g = css(grp(), {position: 'absolute', top: margin, left: margin});
263 |
264 | var i;
265 |
266 | function seg(i, dx, filter) {
267 | ins(g,
268 | ins(css(grp(), {rotation: 360 / o.lines * i + 'deg', left: ~~dx}),
269 | ins(css(vml('roundrect', {arcsize: 1}), {
270 | width: r,
271 | height: o.width,
272 | left: o.radius,
273 | top: -o.width>>1,
274 | filter: filter
275 | }),
276 | vml('fill', {color: o.color, opacity: o.opacity}),
277 | vml('stroke', {opacity: 0}) // transparent stroke to fix color bleeding upon opacity change
278 | )
279 | )
280 | );
281 | }
282 |
283 | if (o.shadow) {
284 | for (i = 1; i <= o.lines; i++) {
285 | seg(i, -2, 'progid:DXImageTransform.Microsoft.Blur(pixelradius=2,makeshadow=1,shadowopacity=.3)');
286 | }
287 | }
288 | for (i = 1; i <= o.lines; i++) seg(i);
289 | return ins(el, g);
290 | };
291 | Spinner.prototype.opacity = function(el, i, val, o) {
292 | var c = el.firstChild;
293 | o = o.shadow && o.lines || 0;
294 | if (c && i+o < c.childNodes.length) {
295 | c = c.childNodes[i+o]; c = c && c.firstChild; c = c && c.firstChild;
296 | if (c) c.opacity = val;
297 | }
298 | };
299 | }
300 | else {
301 | useCssAnimations = vendor(s, 'animation');
302 | }
303 | }();
304 |
305 | return {Spinner: Spinner};
306 |
307 | });
308 |
--------------------------------------------------------------------------------
/js/leaflet.css:
--------------------------------------------------------------------------------
1 | /* required styles */
2 |
3 | .leaflet-map-pane,
4 | .leaflet-tile,
5 | .leaflet-marker-icon,
6 | .leaflet-marker-shadow,
7 | .leaflet-tile-pane,
8 | .leaflet-tile-container,
9 | .leaflet-overlay-pane,
10 | .leaflet-shadow-pane,
11 | .leaflet-marker-pane,
12 | .leaflet-popup-pane,
13 | .leaflet-overlay-pane svg,
14 | .leaflet-zoom-box,
15 | .leaflet-image-layer,
16 | .leaflet-layer {
17 | position: absolute;
18 | left: 0;
19 | top: 0;
20 | }
21 | .leaflet-container {
22 | overflow: hidden;
23 | -ms-touch-action: none;
24 | }
25 | .leaflet-tile,
26 | .leaflet-marker-icon,
27 | .leaflet-marker-shadow {
28 | -webkit-user-select: none;
29 | -moz-user-select: none;
30 | user-select: none;
31 | -webkit-user-drag: none;
32 | }
33 | .leaflet-marker-icon,
34 | .leaflet-marker-shadow {
35 | display: block;
36 | }
37 | /* map is broken in FF if you have max-width: 100% on tiles */
38 | .leaflet-container img {
39 | max-width: none !important;
40 | }
41 | /* stupid Android 2 doesn't understand "max-width: none" properly */
42 | .leaflet-container img.leaflet-image-layer {
43 | max-width: 15000px !important;
44 | }
45 | .leaflet-tile {
46 | filter: inherit;
47 | visibility: hidden;
48 | }
49 | .leaflet-tile-loaded {
50 | visibility: inherit;
51 | }
52 | .leaflet-zoom-box {
53 | width: 0;
54 | height: 0;
55 | }
56 | /* workaround for https://bugzilla.mozilla.org/show_bug.cgi?id=888319 */
57 | .leaflet-overlay-pane svg {
58 | -moz-user-select: none;
59 | }
60 |
61 | .leaflet-tile-pane { z-index: 2; }
62 | .leaflet-objects-pane { z-index: 3; }
63 | .leaflet-overlay-pane { z-index: 4; }
64 | .leaflet-shadow-pane { z-index: 5; }
65 | .leaflet-marker-pane { z-index: 6; }
66 | .leaflet-popup-pane { z-index: 7; }
67 |
68 |
69 | /* control positioning */
70 |
71 | .leaflet-control {
72 | position: relative;
73 | z-index: 7;
74 | pointer-events: auto;
75 | }
76 | .leaflet-top,
77 | .leaflet-bottom {
78 | position: absolute;
79 | z-index: 1000;
80 | pointer-events: none;
81 | }
82 | .leaflet-top {
83 | top: 0;
84 | }
85 | .leaflet-right {
86 | right: 0;
87 | }
88 | .leaflet-bottom {
89 | bottom: 0;
90 | }
91 | .leaflet-left {
92 | left: 0;
93 | }
94 | .leaflet-control {
95 | float: left;
96 | clear: both;
97 | }
98 | .leaflet-right .leaflet-control {
99 | float: right;
100 | }
101 | .leaflet-top .leaflet-control {
102 | margin-top: 10px;
103 | }
104 | .leaflet-bottom .leaflet-control {
105 | margin-bottom: 10px;
106 | }
107 | .leaflet-left .leaflet-control {
108 | margin-left: 10px;
109 | }
110 | .leaflet-right .leaflet-control {
111 | margin-right: 10px;
112 | }
113 |
114 |
115 | /* zoom and fade animations */
116 |
117 | .leaflet-fade-anim .leaflet-tile,
118 | .leaflet-fade-anim .leaflet-popup {
119 | opacity: 0;
120 | -webkit-transition: opacity 0.2s linear;
121 | -moz-transition: opacity 0.2s linear;
122 | -o-transition: opacity 0.2s linear;
123 | transition: opacity 0.2s linear;
124 | }
125 | .leaflet-fade-anim .leaflet-tile-loaded,
126 | .leaflet-fade-anim .leaflet-map-pane .leaflet-popup {
127 | opacity: 1;
128 | }
129 |
130 | .leaflet-zoom-anim .leaflet-zoom-animated {
131 | -webkit-transition: -webkit-transform 0.25s cubic-bezier(0,0,0.25,1);
132 | -moz-transition: -moz-transform 0.25s cubic-bezier(0,0,0.25,1);
133 | -o-transition: -o-transform 0.25s cubic-bezier(0,0,0.25,1);
134 | transition: transform 0.25s cubic-bezier(0,0,0.25,1);
135 | }
136 | .leaflet-zoom-anim .leaflet-tile,
137 | .leaflet-pan-anim .leaflet-tile,
138 | .leaflet-touching .leaflet-zoom-animated {
139 | -webkit-transition: none;
140 | -moz-transition: none;
141 | -o-transition: none;
142 | transition: none;
143 | }
144 |
145 | .leaflet-zoom-anim .leaflet-zoom-hide {
146 | visibility: hidden;
147 | }
148 |
149 |
150 | /* cursors */
151 |
152 | .leaflet-clickable {
153 | cursor: pointer;
154 | }
155 | .leaflet-container {
156 | cursor: -webkit-grab;
157 | cursor: -moz-grab;
158 | }
159 | .leaflet-popup-pane,
160 | .leaflet-control {
161 | cursor: auto;
162 | }
163 | .leaflet-dragging,
164 | .leaflet-dragging .leaflet-clickable,
165 | .leaflet-dragging .leaflet-container {
166 | cursor: move;
167 | cursor: -webkit-grabbing;
168 | cursor: -moz-grabbing;
169 | }
170 |
171 |
172 | /* visual tweaks */
173 |
174 | .leaflet-container {
175 | background: #ddd;
176 | outline: 0;
177 | }
178 | .leaflet-container a {
179 | color: #0078A8;
180 | }
181 | .leaflet-container a.leaflet-active {
182 | outline: 2px solid orange;
183 | }
184 | .leaflet-zoom-box {
185 | border: 2px dotted #05f;
186 | background: white;
187 | opacity: 0.5;
188 | }
189 |
190 |
191 | /* general typography */
192 | .leaflet-container {
193 | font: 12px/1.5 "Helvetica Neue", Arial, Helvetica, sans-serif;
194 | }
195 |
196 |
197 | /* general toolbar styles */
198 |
199 | .leaflet-bar {
200 | box-shadow: 0 1px 7px rgba(0,0,0,0.65);
201 | -webkit-border-radius: 4px;
202 | border-radius: 4px;
203 | }
204 | .leaflet-bar a, .leaflet-bar a:hover {
205 | background-color: #fff;
206 | border-bottom: 1px solid #ccc;
207 | width: 26px;
208 | height: 26px;
209 | line-height: 26px;
210 | display: block;
211 | text-align: center;
212 | text-decoration: none;
213 | color: black;
214 | }
215 | .leaflet-bar a,
216 | .leaflet-control-layers-toggle {
217 | background-position: 50% 50%;
218 | background-repeat: no-repeat;
219 | display: block;
220 | }
221 | .leaflet-bar a:hover {
222 | background-color: #f4f4f4;
223 | }
224 | .leaflet-bar a:first-child {
225 | -webkit-border-top-left-radius: 4px;
226 | border-top-left-radius: 4px;
227 | -webkit-border-top-right-radius: 4px;
228 | border-top-right-radius: 4px;
229 | }
230 | .leaflet-bar a:last-child {
231 | -webkit-border-bottom-left-radius: 4px;
232 | border-bottom-left-radius: 4px;
233 | -webkit-border-bottom-right-radius: 4px;
234 | border-bottom-right-radius: 4px;
235 | border-bottom: none;
236 | }
237 | .leaflet-bar a.leaflet-disabled {
238 | cursor: default;
239 | background-color: #f4f4f4;
240 | color: #bbb;
241 | }
242 |
243 | .leaflet-touch .leaflet-bar {
244 | -webkit-border-radius: 10px;
245 | border-radius: 10px;
246 | }
247 | .leaflet-touch .leaflet-bar a {
248 | width: 30px;
249 | height: 30px;
250 | }
251 | .leaflet-touch .leaflet-bar a:first-child {
252 | -webkit-border-top-left-radius: 7px;
253 | border-top-left-radius: 7px;
254 | -webkit-border-top-right-radius: 7px;
255 | border-top-right-radius: 7px;
256 | }
257 | .leaflet-touch .leaflet-bar a:last-child {
258 | -webkit-border-bottom-left-radius: 7px;
259 | border-bottom-left-radius: 7px;
260 | -webkit-border-bottom-right-radius: 7px;
261 | border-bottom-right-radius: 7px;
262 | border-bottom: none;
263 | }
264 |
265 |
266 | /* zoom control */
267 |
268 | .leaflet-control-zoom-in {
269 | font: bold 18px 'Lucida Console', Monaco, monospace;
270 | }
271 | .leaflet-control-zoom-out {
272 | font: bold 22px 'Lucida Console', Monaco, monospace;
273 | }
274 |
275 | .leaflet-touch .leaflet-control-zoom-in {
276 | font-size: 22px;
277 | line-height: 30px;
278 | }
279 | .leaflet-touch .leaflet-control-zoom-out {
280 | font-size: 28px;
281 | line-height: 30px;
282 | }
283 |
284 |
285 | /* layers control */
286 |
287 | .leaflet-control-layers {
288 | box-shadow: 0 1px 7px rgba(0,0,0,0.4);
289 | background: #f8f8f9;
290 | -webkit-border-radius: 5px;
291 | border-radius: 5px;
292 | }
293 | .leaflet-control-layers-toggle {
294 | background-image: url(images/layers.png);
295 | width: 36px;
296 | height: 36px;
297 | }
298 | .leaflet-retina .leaflet-control-layers-toggle {
299 | background-image: url(images/layers-2x.png);
300 | background-size: 26px 26px;
301 | }
302 | .leaflet-touch .leaflet-control-layers-toggle {
303 | width: 44px;
304 | height: 44px;
305 | }
306 | .leaflet-control-layers .leaflet-control-layers-list,
307 | .leaflet-control-layers-expanded .leaflet-control-layers-toggle {
308 | display: none;
309 | }
310 | .leaflet-control-layers-expanded .leaflet-control-layers-list {
311 | display: block;
312 | position: relative;
313 | }
314 | .leaflet-control-layers-expanded {
315 | padding: 6px 10px 6px 6px;
316 | color: #333;
317 | background: #fff;
318 | }
319 | .leaflet-control-layers-selector {
320 | margin-top: 2px;
321 | position: relative;
322 | top: 1px;
323 | }
324 | .leaflet-control-layers label {
325 | display: block;
326 | }
327 | .leaflet-control-layers-separator {
328 | height: 0;
329 | border-top: 1px solid #ddd;
330 | margin: 5px -10px 5px -6px;
331 | }
332 |
333 |
334 | /* attribution and scale controls */
335 |
336 | .leaflet-container .leaflet-control-attribution {
337 | background-color: rgba(255, 255, 255, 0.7);
338 | box-shadow: 0 0 5px #bbb;
339 | margin: 0;
340 | }
341 | .leaflet-control-attribution,
342 | .leaflet-control-scale-line {
343 | padding: 0 5px;
344 | color: #333;
345 | }
346 | .leaflet-container .leaflet-control-attribution,
347 | .leaflet-container .leaflet-control-scale {
348 | font-size: 11px;
349 | }
350 | .leaflet-left .leaflet-control-scale {
351 | margin-left: 5px;
352 | }
353 | .leaflet-bottom .leaflet-control-scale {
354 | margin-bottom: 5px;
355 | }
356 | .leaflet-control-scale-line {
357 | border: 2px solid #777;
358 | border-top: none;
359 | color: black;
360 | line-height: 1.1;
361 | padding: 2px 5px 1px;
362 | font-size: 11px;
363 | text-shadow: 1px 1px 1px #fff;
364 | background-color: rgba(255, 255, 255, 0.5);
365 | box-shadow: 0 -1px 5px rgba(0, 0, 0, 0.2);
366 | white-space: nowrap;
367 | overflow: hidden;
368 | }
369 | .leaflet-control-scale-line:not(:first-child) {
370 | border-top: 2px solid #777;
371 | border-bottom: none;
372 | margin-top: -2px;
373 | box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
374 | }
375 | .leaflet-control-scale-line:not(:first-child):not(:last-child) {
376 | border-bottom: 2px solid #777;
377 | }
378 |
379 | .leaflet-touch .leaflet-control-attribution,
380 | .leaflet-touch .leaflet-control-layers,
381 | .leaflet-touch .leaflet-bar {
382 | box-shadow: none;
383 | }
384 | .leaflet-touch .leaflet-control-layers,
385 | .leaflet-touch .leaflet-bar {
386 | border: 4px solid rgba(0,0,0,0.3);
387 | }
388 |
389 |
390 | /* popup */
391 |
392 | .leaflet-popup {
393 | position: absolute;
394 | text-align: center;
395 | }
396 | .leaflet-popup-content-wrapper {
397 | padding: 1px;
398 | text-align: left;
399 | -webkit-border-radius: 12px;
400 | border-radius: 12px;
401 | }
402 | .leaflet-popup-content {
403 | margin: 13px 19px;
404 | line-height: 1.4;
405 | }
406 | .leaflet-popup-content p {
407 | margin: 18px 0;
408 | }
409 | .leaflet-popup-tip-container {
410 | margin: 0 auto;
411 | width: 40px;
412 | height: 20px;
413 | position: relative;
414 | overflow: hidden;
415 | }
416 | .leaflet-popup-tip {
417 | width: 17px;
418 | height: 17px;
419 | padding: 1px;
420 |
421 | margin: -10px auto 0;
422 |
423 | -webkit-transform: rotate(45deg);
424 | -moz-transform: rotate(45deg);
425 | -ms-transform: rotate(45deg);
426 | -o-transform: rotate(45deg);
427 | transform: rotate(45deg);
428 | }
429 | .leaflet-popup-content-wrapper, .leaflet-popup-tip {
430 | background: white;
431 |
432 | box-shadow: 0 3px 14px rgba(0,0,0,0.4);
433 | }
434 | .leaflet-container a.leaflet-popup-close-button {
435 | position: absolute;
436 | top: 0;
437 | right: 0;
438 | padding: 4px 4px 0 0;
439 | text-align: center;
440 | width: 18px;
441 | height: 14px;
442 | font: 16px/14px Tahoma, Verdana, sans-serif;
443 | color: #c3c3c3;
444 | text-decoration: none;
445 | font-weight: bold;
446 | background: transparent;
447 | }
448 | .leaflet-container a.leaflet-popup-close-button:hover {
449 | color: #999;
450 | }
451 | .leaflet-popup-scrolled {
452 | overflow: auto;
453 | border-bottom: 1px solid #ddd;
454 | border-top: 1px solid #ddd;
455 | }
456 |
457 |
458 | /* div icon */
459 |
460 | .leaflet-div-icon {
461 | background: #fff;
462 | border: 1px solid #666;
463 | }
464 | .leaflet-editing-icon {
465 | -webkit-border-radius: 2px;
466 | border-radius: 2px;
467 | }
468 |
--------------------------------------------------------------------------------
/js/colorbrewer.js:
--------------------------------------------------------------------------------
1 | // This product includes color specifications and designs developed by Cynthia Brewer (http://colorbrewer.org/).
2 | var colorbrewer = {YlGn: {
3 | 3: ["#f7fcb9","#addd8e","#31a354"],
4 | 4: ["#ffffcc","#c2e699","#78c679","#238443"],
5 | 5: ["#ffffcc","#c2e699","#78c679","#31a354","#006837"],
6 | 6: ["#ffffcc","#d9f0a3","#addd8e","#78c679","#31a354","#006837"],
7 | 7: ["#ffffcc","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#005a32"],
8 | 8: ["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#005a32"],
9 | 9: ["#ffffe5","#f7fcb9","#d9f0a3","#addd8e","#78c679","#41ab5d","#238443","#006837","#004529"]
10 | },YlGnBu: {
11 | 3: ["#edf8b1","#7fcdbb","#2c7fb8"],
12 | 4: ["#ffffcc","#a1dab4","#41b6c4","#225ea8"],
13 | 5: ["#ffffcc","#a1dab4","#41b6c4","#2c7fb8","#253494"],
14 | 6: ["#ffffcc","#c7e9b4","#7fcdbb","#41b6c4","#2c7fb8","#253494"],
15 | 7: ["#ffffcc","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#0c2c84"],
16 | 8: ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#0c2c84"],
17 | 9: ["#ffffd9","#edf8b1","#c7e9b4","#7fcdbb","#41b6c4","#1d91c0","#225ea8","#253494","#081d58"]
18 | },GnBu: {
19 | 3: ["#e0f3db","#a8ddb5","#43a2ca"],
20 | 4: ["#f0f9e8","#bae4bc","#7bccc4","#2b8cbe"],
21 | 5: ["#f0f9e8","#bae4bc","#7bccc4","#43a2ca","#0868ac"],
22 | 6: ["#f0f9e8","#ccebc5","#a8ddb5","#7bccc4","#43a2ca","#0868ac"],
23 | 7: ["#f0f9e8","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#08589e"],
24 | 8: ["#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#08589e"],
25 | 9: ["#f7fcf0","#e0f3db","#ccebc5","#a8ddb5","#7bccc4","#4eb3d3","#2b8cbe","#0868ac","#084081"]
26 | },BuGn: {
27 | 3: ["#e5f5f9","#99d8c9","#2ca25f"],
28 | 4: ["#edf8fb","#b2e2e2","#66c2a4","#238b45"],
29 | 5: ["#edf8fb","#b2e2e2","#66c2a4","#2ca25f","#006d2c"],
30 | 6: ["#edf8fb","#ccece6","#99d8c9","#66c2a4","#2ca25f","#006d2c"],
31 | 7: ["#edf8fb","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#005824"],
32 | 8: ["#f7fcfd","#e5f5f9","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#005824"],
33 | 9: ["#f7fcfd","#e5f5f9","#ccece6","#99d8c9","#66c2a4","#41ae76","#238b45","#006d2c","#00441b"]
34 | },PuBuGn: {
35 | 3: ["#ece2f0","#a6bddb","#1c9099"],
36 | 4: ["#f6eff7","#bdc9e1","#67a9cf","#02818a"],
37 | 5: ["#f6eff7","#bdc9e1","#67a9cf","#1c9099","#016c59"],
38 | 6: ["#f6eff7","#d0d1e6","#a6bddb","#67a9cf","#1c9099","#016c59"],
39 | 7: ["#f6eff7","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016450"],
40 | 8: ["#fff7fb","#ece2f0","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016450"],
41 | 9: ["#fff7fb","#ece2f0","#d0d1e6","#a6bddb","#67a9cf","#3690c0","#02818a","#016c59","#014636"]
42 | },PuBu: {
43 | 3: ["#ece7f2","#a6bddb","#2b8cbe"],
44 | 4: ["#f1eef6","#bdc9e1","#74a9cf","#0570b0"],
45 | 5: ["#f1eef6","#bdc9e1","#74a9cf","#2b8cbe","#045a8d"],
46 | 6: ["#f1eef6","#d0d1e6","#a6bddb","#74a9cf","#2b8cbe","#045a8d"],
47 | 7: ["#f1eef6","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#034e7b"],
48 | 8: ["#fff7fb","#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#034e7b"],
49 | 9: ["#fff7fb","#ece7f2","#d0d1e6","#a6bddb","#74a9cf","#3690c0","#0570b0","#045a8d","#023858"]
50 | },BuPu: {
51 | 3: ["#e0ecf4","#9ebcda","#8856a7"],
52 | 4: ["#edf8fb","#b3cde3","#8c96c6","#88419d"],
53 | 5: ["#edf8fb","#b3cde3","#8c96c6","#8856a7","#810f7c"],
54 | 6: ["#edf8fb","#bfd3e6","#9ebcda","#8c96c6","#8856a7","#810f7c"],
55 | 7: ["#edf8fb","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#6e016b"],
56 | 8: ["#f7fcfd","#e0ecf4","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#6e016b"],
57 | 9: ["#f7fcfd","#e0ecf4","#bfd3e6","#9ebcda","#8c96c6","#8c6bb1","#88419d","#810f7c","#4d004b"]
58 | },RdPu: {
59 | 3: ["#fde0dd","#fa9fb5","#c51b8a"],
60 | 4: ["#feebe2","#fbb4b9","#f768a1","#ae017e"],
61 | 5: ["#feebe2","#fbb4b9","#f768a1","#c51b8a","#7a0177"],
62 | 6: ["#feebe2","#fcc5c0","#fa9fb5","#f768a1","#c51b8a","#7a0177"],
63 | 7: ["#feebe2","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177"],
64 | 8: ["#fff7f3","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177"],
65 | 9: ["#fff7f3","#fde0dd","#fcc5c0","#fa9fb5","#f768a1","#dd3497","#ae017e","#7a0177","#49006a"]
66 | },PuRd: {
67 | 3: ["#e7e1ef","#c994c7","#dd1c77"],
68 | 4: ["#f1eef6","#d7b5d8","#df65b0","#ce1256"],
69 | 5: ["#f1eef6","#d7b5d8","#df65b0","#dd1c77","#980043"],
70 | 6: ["#f1eef6","#d4b9da","#c994c7","#df65b0","#dd1c77","#980043"],
71 | 7: ["#f1eef6","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#91003f"],
72 | 8: ["#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#91003f"],
73 | 9: ["#f7f4f9","#e7e1ef","#d4b9da","#c994c7","#df65b0","#e7298a","#ce1256","#980043","#67001f"]
74 | },OrRd: {
75 | 3: ["#fee8c8","#fdbb84","#e34a33"],
76 | 4: ["#fef0d9","#fdcc8a","#fc8d59","#d7301f"],
77 | 5: ["#fef0d9","#fdcc8a","#fc8d59","#e34a33","#b30000"],
78 | 6: ["#fef0d9","#fdd49e","#fdbb84","#fc8d59","#e34a33","#b30000"],
79 | 7: ["#fef0d9","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#990000"],
80 | 8: ["#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#990000"],
81 | 9: ["#fff7ec","#fee8c8","#fdd49e","#fdbb84","#fc8d59","#ef6548","#d7301f","#b30000","#7f0000"]
82 | },YlOrRd: {
83 | 3: ["#ffeda0","#feb24c","#f03b20"],
84 | 4: ["#ffffb2","#fecc5c","#fd8d3c","#e31a1c"],
85 | 5: ["#ffffb2","#fecc5c","#fd8d3c","#f03b20","#bd0026"],
86 | 6: ["#ffffb2","#fed976","#feb24c","#fd8d3c","#f03b20","#bd0026"],
87 | 7: ["#ffffb2","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#b10026"],
88 | 8: ["#ffffcc","#ffeda0","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#b10026"],
89 | 9: ["#ffffcc","#ffeda0","#fed976","#feb24c","#fd8d3c","#fc4e2a","#e31a1c","#bd0026","#800026"]
90 | },YlOrBr: {
91 | 3: ["#fff7bc","#fec44f","#d95f0e"],
92 | 4: ["#ffffd4","#fed98e","#fe9929","#cc4c02"],
93 | 5: ["#ffffd4","#fed98e","#fe9929","#d95f0e","#993404"],
94 | 6: ["#ffffd4","#fee391","#fec44f","#fe9929","#d95f0e","#993404"],
95 | 7: ["#ffffd4","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#8c2d04"],
96 | 8: ["#ffffe5","#fff7bc","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#8c2d04"],
97 | 9: ["#ffffe5","#fff7bc","#fee391","#fec44f","#fe9929","#ec7014","#cc4c02","#993404","#662506"]
98 | },Purples: {
99 | 3: ["#efedf5","#bcbddc","#756bb1"],
100 | 4: ["#f2f0f7","#cbc9e2","#9e9ac8","#6a51a3"],
101 | 5: ["#f2f0f7","#cbc9e2","#9e9ac8","#756bb1","#54278f"],
102 | 6: ["#f2f0f7","#dadaeb","#bcbddc","#9e9ac8","#756bb1","#54278f"],
103 | 7: ["#f2f0f7","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#4a1486"],
104 | 8: ["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#4a1486"],
105 | 9: ["#fcfbfd","#efedf5","#dadaeb","#bcbddc","#9e9ac8","#807dba","#6a51a3","#54278f","#3f007d"]
106 | },Blues: {
107 | 3: ["#deebf7","#9ecae1","#3182bd"],
108 | 4: ["#eff3ff","#bdd7e7","#6baed6","#2171b5"],
109 | 5: ["#eff3ff","#bdd7e7","#6baed6","#3182bd","#08519c"],
110 | 6: ["#eff3ff","#c6dbef","#9ecae1","#6baed6","#3182bd","#08519c"],
111 | 7: ["#eff3ff","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#084594"],
112 | 8: ["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#084594"],
113 | 9: ["#f7fbff","#deebf7","#c6dbef","#9ecae1","#6baed6","#4292c6","#2171b5","#08519c","#08306b"]
114 | },Greens: {
115 | 3: ["#e5f5e0","#a1d99b","#31a354"],
116 | 4: ["#edf8e9","#bae4b3","#74c476","#238b45"],
117 | 5: ["#edf8e9","#bae4b3","#74c476","#31a354","#006d2c"],
118 | 6: ["#edf8e9","#c7e9c0","#a1d99b","#74c476","#31a354","#006d2c"],
119 | 7: ["#edf8e9","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#005a32"],
120 | 8: ["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#005a32"],
121 | 9: ["#f7fcf5","#e5f5e0","#c7e9c0","#a1d99b","#74c476","#41ab5d","#238b45","#006d2c","#00441b"]
122 | },Oranges: {
123 | 3: ["#fee6ce","#fdae6b","#e6550d"],
124 | 4: ["#feedde","#fdbe85","#fd8d3c","#d94701"],
125 | 5: ["#feedde","#fdbe85","#fd8d3c","#e6550d","#a63603"],
126 | 6: ["#feedde","#fdd0a2","#fdae6b","#fd8d3c","#e6550d","#a63603"],
127 | 7: ["#feedde","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#8c2d04"],
128 | 8: ["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#8c2d04"],
129 | 9: ["#fff5eb","#fee6ce","#fdd0a2","#fdae6b","#fd8d3c","#f16913","#d94801","#a63603","#7f2704"]
130 | },Reds: {
131 | 3: ["#fee0d2","#fc9272","#de2d26"],
132 | 4: ["#fee5d9","#fcae91","#fb6a4a","#cb181d"],
133 | 5: ["#fee5d9","#fcae91","#fb6a4a","#de2d26","#a50f15"],
134 | 6: ["#fee5d9","#fcbba1","#fc9272","#fb6a4a","#de2d26","#a50f15"],
135 | 7: ["#fee5d9","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#99000d"],
136 | 8: ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#99000d"],
137 | 9: ["#fff5f0","#fee0d2","#fcbba1","#fc9272","#fb6a4a","#ef3b2c","#cb181d","#a50f15","#67000d"]
138 | },Greys: {
139 | 3: ["#f0f0f0","#bdbdbd","#636363"],
140 | 4: ["#f7f7f7","#cccccc","#969696","#525252"],
141 | 5: ["#f7f7f7","#cccccc","#969696","#636363","#252525"],
142 | 6: ["#f7f7f7","#d9d9d9","#bdbdbd","#969696","#636363","#252525"],
143 | 7: ["#f7f7f7","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525"],
144 | 8: ["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525"],
145 | 9: ["#ffffff","#f0f0f0","#d9d9d9","#bdbdbd","#969696","#737373","#525252","#252525","#000000"]
146 | },PuOr: {
147 | 3: ["#f1a340","#f7f7f7","#998ec3"],
148 | 4: ["#e66101","#fdb863","#b2abd2","#5e3c99"],
149 | 5: ["#e66101","#fdb863","#f7f7f7","#b2abd2","#5e3c99"],
150 | 6: ["#b35806","#f1a340","#fee0b6","#d8daeb","#998ec3","#542788"],
151 | 7: ["#b35806","#f1a340","#fee0b6","#f7f7f7","#d8daeb","#998ec3","#542788"],
152 | 8: ["#b35806","#e08214","#fdb863","#fee0b6","#d8daeb","#b2abd2","#8073ac","#542788"],
153 | 9: ["#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788"],
154 | 10: ["#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b"],
155 | 11: ["#7f3b08","#b35806","#e08214","#fdb863","#fee0b6","#f7f7f7","#d8daeb","#b2abd2","#8073ac","#542788","#2d004b"]
156 | },BrBG: {
157 | 3: ["#d8b365","#f5f5f5","#5ab4ac"],
158 | 4: ["#a6611a","#dfc27d","#80cdc1","#018571"],
159 | 5: ["#a6611a","#dfc27d","#f5f5f5","#80cdc1","#018571"],
160 | 6: ["#8c510a","#d8b365","#f6e8c3","#c7eae5","#5ab4ac","#01665e"],
161 | 7: ["#8c510a","#d8b365","#f6e8c3","#f5f5f5","#c7eae5","#5ab4ac","#01665e"],
162 | 8: ["#8c510a","#bf812d","#dfc27d","#f6e8c3","#c7eae5","#80cdc1","#35978f","#01665e"],
163 | 9: ["#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e"],
164 | 10: ["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"],
165 | 11: ["#543005","#8c510a","#bf812d","#dfc27d","#f6e8c3","#f5f5f5","#c7eae5","#80cdc1","#35978f","#01665e","#003c30"]
166 | },PRGn: {
167 | 3: ["#af8dc3","#f7f7f7","#7fbf7b"],
168 | 4: ["#7b3294","#c2a5cf","#a6dba0","#008837"],
169 | 5: ["#7b3294","#c2a5cf","#f7f7f7","#a6dba0","#008837"],
170 | 6: ["#762a83","#af8dc3","#e7d4e8","#d9f0d3","#7fbf7b","#1b7837"],
171 | 7: ["#762a83","#af8dc3","#e7d4e8","#f7f7f7","#d9f0d3","#7fbf7b","#1b7837"],
172 | 8: ["#762a83","#9970ab","#c2a5cf","#e7d4e8","#d9f0d3","#a6dba0","#5aae61","#1b7837"],
173 | 9: ["#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837"],
174 | 10: ["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"],
175 | 11: ["#40004b","#762a83","#9970ab","#c2a5cf","#e7d4e8","#f7f7f7","#d9f0d3","#a6dba0","#5aae61","#1b7837","#00441b"]
176 | },PiYG: {
177 | 3: ["#e9a3c9","#f7f7f7","#a1d76a"],
178 | 4: ["#d01c8b","#f1b6da","#b8e186","#4dac26"],
179 | 5: ["#d01c8b","#f1b6da","#f7f7f7","#b8e186","#4dac26"],
180 | 6: ["#c51b7d","#e9a3c9","#fde0ef","#e6f5d0","#a1d76a","#4d9221"],
181 | 7: ["#c51b7d","#e9a3c9","#fde0ef","#f7f7f7","#e6f5d0","#a1d76a","#4d9221"],
182 | 8: ["#c51b7d","#de77ae","#f1b6da","#fde0ef","#e6f5d0","#b8e186","#7fbc41","#4d9221"],
183 | 9: ["#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221"],
184 | 10: ["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"],
185 | 11: ["#8e0152","#c51b7d","#de77ae","#f1b6da","#fde0ef","#f7f7f7","#e6f5d0","#b8e186","#7fbc41","#4d9221","#276419"]
186 | },RdBu: {
187 | 3: ["#ef8a62","#f7f7f7","#67a9cf"],
188 | 4: ["#ca0020","#f4a582","#92c5de","#0571b0"],
189 | 5: ["#ca0020","#f4a582","#f7f7f7","#92c5de","#0571b0"],
190 | 6: ["#b2182b","#ef8a62","#fddbc7","#d1e5f0","#67a9cf","#2166ac"],
191 | 7: ["#b2182b","#ef8a62","#fddbc7","#f7f7f7","#d1e5f0","#67a9cf","#2166ac"],
192 | 8: ["#b2182b","#d6604d","#f4a582","#fddbc7","#d1e5f0","#92c5de","#4393c3","#2166ac"],
193 | 9: ["#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac"],
194 | 10: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"],
195 | 11: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#f7f7f7","#d1e5f0","#92c5de","#4393c3","#2166ac","#053061"]
196 | },RdGy: {
197 | 3: ["#ef8a62","#ffffff","#999999"],
198 | 4: ["#ca0020","#f4a582","#bababa","#404040"],
199 | 5: ["#ca0020","#f4a582","#ffffff","#bababa","#404040"],
200 | 6: ["#b2182b","#ef8a62","#fddbc7","#e0e0e0","#999999","#4d4d4d"],
201 | 7: ["#b2182b","#ef8a62","#fddbc7","#ffffff","#e0e0e0","#999999","#4d4d4d"],
202 | 8: ["#b2182b","#d6604d","#f4a582","#fddbc7","#e0e0e0","#bababa","#878787","#4d4d4d"],
203 | 9: ["#b2182b","#d6604d","#f4a582","#fddbc7","#ffffff","#e0e0e0","#bababa","#878787","#4d4d4d"],
204 | 10: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#e0e0e0","#bababa","#878787","#4d4d4d","#1a1a1a"],
205 | 11: ["#67001f","#b2182b","#d6604d","#f4a582","#fddbc7","#ffffff","#e0e0e0","#bababa","#878787","#4d4d4d","#1a1a1a"]
206 | },RdYlBu: {
207 | 3: ["#fc8d59","#ffffbf","#91bfdb"],
208 | 4: ["#d7191c","#fdae61","#abd9e9","#2c7bb6"],
209 | 5: ["#d7191c","#fdae61","#ffffbf","#abd9e9","#2c7bb6"],
210 | 6: ["#d73027","#fc8d59","#fee090","#e0f3f8","#91bfdb","#4575b4"],
211 | 7: ["#d73027","#fc8d59","#fee090","#ffffbf","#e0f3f8","#91bfdb","#4575b4"],
212 | 8: ["#d73027","#f46d43","#fdae61","#fee090","#e0f3f8","#abd9e9","#74add1","#4575b4"],
213 | 9: ["#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4"],
214 | 10: ["#a50026","#d73027","#f46d43","#fdae61","#fee090","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"],
215 | 11: ["#a50026","#d73027","#f46d43","#fdae61","#fee090","#ffffbf","#e0f3f8","#abd9e9","#74add1","#4575b4","#313695"]
216 | },Spectral: {
217 | 3: ["#fc8d59","#ffffbf","#99d594"],
218 | 4: ["#d7191c","#fdae61","#abdda4","#2b83ba"],
219 | 5: ["#d7191c","#fdae61","#ffffbf","#abdda4","#2b83ba"],
220 | 6: ["#d53e4f","#fc8d59","#fee08b","#e6f598","#99d594","#3288bd"],
221 | 7: ["#d53e4f","#fc8d59","#fee08b","#ffffbf","#e6f598","#99d594","#3288bd"],
222 | 8: ["#d53e4f","#f46d43","#fdae61","#fee08b","#e6f598","#abdda4","#66c2a5","#3288bd"],
223 | 9: ["#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd"],
224 | 10: ["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"],
225 | 11: ["#9e0142","#d53e4f","#f46d43","#fdae61","#fee08b","#ffffbf","#e6f598","#abdda4","#66c2a5","#3288bd","#5e4fa2"]
226 | },RdYlGn: {
227 | 3: ["#fc8d59","#ffffbf","#91cf60"],
228 | 4: ["#d7191c","#fdae61","#a6d96a","#1a9641"],
229 | 5: ["#d7191c","#fdae61","#ffffbf","#a6d96a","#1a9641"],
230 | 6: ["#d73027","#fc8d59","#fee08b","#d9ef8b","#91cf60","#1a9850"],
231 | 7: ["#d73027","#fc8d59","#fee08b","#ffffbf","#d9ef8b","#91cf60","#1a9850"],
232 | 8: ["#d73027","#f46d43","#fdae61","#fee08b","#d9ef8b","#a6d96a","#66bd63","#1a9850"],
233 | 9: ["#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850"],
234 | 10: ["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"],
235 | 11: ["#a50026","#d73027","#f46d43","#fdae61","#fee08b","#ffffbf","#d9ef8b","#a6d96a","#66bd63","#1a9850","#006837"]
236 | }};
--------------------------------------------------------------------------------
/jam/catiline/dist/catiline.js:
--------------------------------------------------------------------------------
1 | /*! catiline 2.9.0-dev.2 2013-09-30*/
2 | /*!©2013 Calvin Metcalf @license MIT https://github.com/calvinmetcalf/catiline */
3 | if (typeof document === 'undefined') {
4 | self._noTransferable=true;
5 | self.onmessage=function(e){
6 | /*jslint evil: true */
7 | eval(e.data);
8 | };
9 | } else {
10 | (function(global){
11 | 'use strict';
12 | //overall structure based on when
13 | //https://github.com/cujojs/when/blob/master/when.js#L805-L852
14 | var nextTick;
15 | var MutationObserver = global.MutationObserver || global.WebKitMutationObserver;
16 | /*if (typeof setImmediate === 'function') {
17 | nextTick = setImmediate.bind(global,drainQueue);
18 | }else */if(MutationObserver){
19 | //based on RSVP
20 | //https://github.com/tildeio/rsvp.js/blob/master/lib/rsvp/async.js
21 | var observer = new MutationObserver(drainQueue);
22 | var element = document.createElement('div');
23 | observer.observe(element, { attributes: true });
24 |
25 | // Chrome Memory Leak: https://bugs.webkit.org/show_bug.cgi?id=93661
26 | addEventListener('unload', function () {
27 | observer.disconnect();
28 | observer = null;
29 | }, false);
30 | nextTick = function () {
31 | element.setAttribute('drainQueue', 'drainQueue');
32 | };
33 | }else{
34 | var codeWord = 'com.catiline.setImmediate' + Math.random();
35 | addEventListener('message', function (event) {
36 | // This will catch all incoming messages (even from other windows!), so we need to try reasonably hard to
37 | // avoid letting anyone else trick us into firing off. We test the origin is still this window, and that a
38 | // (randomly generated) unpredictable identifying prefix is present.
39 | if (event.source === window && event.data === codeWord) {
40 | drainQueue();
41 | }
42 | }, false);
43 | nextTick = function() {
44 | postMessage(codeWord, '*');
45 | };
46 | }
47 | var mainQueue = [];
48 |
49 | /**
50 | * Enqueue a task. If the queue is not currently scheduled to be
51 | * drained, schedule it.
52 | * @param {function} task
53 | */
54 | catiline.nextTick = function(task) {
55 | if (mainQueue.push(task) === 1) {
56 | nextTick();
57 | }
58 | };
59 |
60 | /**
61 | * Drain the handler queue entirely, being careful to allow the
62 | * queue to be extended while it is being processed, and to continue
63 | * processing until it is truly empty.
64 | */
65 | function drainQueue() {
66 | var i = 0;
67 | var task;
68 | var innerQueue = mainQueue;
69 | mainQueue = [];
70 | /*jslint boss: true */
71 | while (task = innerQueue[i++]) {
72 | task();
73 | }
74 |
75 | }
76 |
77 | var func = 'function';
78 | // Creates a deferred: an object with a promise and corresponding resolve/reject methods
79 | function Deferred() {
80 | // The `handler` variable points to the function that will
81 | // 1) handle a .then(onFulfilled, onRejected) call
82 | // 2) handle a .resolve or .reject call (if not fulfilled)
83 | // Before 2), `handler` holds a queue of callbacks.
84 | // After 2), `handler` is a simple .then handler.
85 | // We use only one function to save memory and complexity.
86 | var handler = function(onFulfilled, onRejected, value) {
87 | // Case 1) handle a .then(onFulfilled, onRejected) call
88 | if (onFulfilled !== handler) {
89 | var createdDeffered = createDeferred();
90 | handler.queue.push({
91 | deferred: createdDeffered,
92 | resolve: onFulfilled,
93 | reject: onRejected
94 | });
95 | return createdDeffered.promise;
96 | }
97 |
98 | // Case 2) handle a .resolve or .reject call
99 | // (`onFulfilled` acts as a sentinel)
100 | // The actual function signature is
101 | // .re[ject|solve](sentinel, success, value)
102 | var action = onRejected ? 'resolve' : 'reject';
103 | for (var i = 0, l = handler.queue.length; i < l; i++) {
104 | var queue = handler.queue[i];
105 | var deferred = queue.deferred;
106 | var callback = queue[action];
107 | if (typeof callback !== func) {
108 | deferred[action](value);
109 | }
110 | else {
111 | execute(callback, value, deferred);
112 | }
113 | }
114 | // Replace this handler with a simple resolved or rejected handler
115 | handler = createHandler(promise, value, onRejected);
116 | };
117 |
118 | function Promise() {
119 | this.then = function(onFulfilled, onRejected) {
120 | return handler(onFulfilled, onRejected);
121 | };
122 | }
123 | var promise = new Promise();
124 | this.promise = promise;
125 | // The queue of deferreds
126 | handler.queue = [];
127 |
128 | this.resolve = function(value) {
129 | if (handler.queue) {
130 | handler(handler, true, value);
131 | }
132 | };
133 |
134 | this.fulfill = this.resolve;
135 |
136 | this.reject = function(reason) {
137 | if (handler.queue) {
138 | handler(handler, false, reason);
139 | }
140 | };
141 | }
142 |
143 | function createDeferred() {
144 | return new Deferred();
145 | }
146 |
147 | // Creates a fulfilled or rejected .then function
148 | function createHandler(promise, value, success) {
149 | return function(onFulfilled, onRejected) {
150 | var callback = success ? onFulfilled : onRejected;
151 | if (typeof callback !== func) {
152 | return promise;
153 | }
154 | var result = createDeferred();
155 | execute(callback, value, result);
156 | return result.promise;
157 | };
158 | }
159 |
160 | // Executes the callback with the specified value,
161 | // resolving or rejecting the deferred
162 | function execute(callback, value, deferred) {
163 | catiline.nextTick(function() {
164 | try {
165 | var result = callback(value);
166 | if (result && typeof result.then === func) {
167 | result.then(deferred.resolve, deferred.reject);
168 | }
169 | else {
170 | deferred.resolve(result);
171 | }
172 | }
173 | catch (error) {
174 | deferred.reject(error);
175 | }
176 | });
177 | }
178 | catiline.deferred = createDeferred;
179 | // Returns a resolved promise
180 | catiline.resolve = function(value) {
181 | var promise = {};
182 | promise.then = createHandler(promise, value, true);
183 | return promise;
184 | };
185 | // Returns a rejected promise
186 | catiline.reject = function(reason) {
187 | var promise = {};
188 | promise.then = createHandler(promise, reason, false);
189 | return promise;
190 | };
191 | // Returns a deferred
192 |
193 | catiline.all = function(array) {
194 | var promise = createDeferred();
195 | var len = array.length;
196 | var resolved = 0;
197 | var out = [];
198 | var onSuccess = function(n) {
199 | return function(v) {
200 | out[n] = v;
201 | resolved++;
202 | if (resolved === len) {
203 | promise.resolve(out);
204 | }
205 | };
206 | };
207 | array.forEach(function(v, i) {
208 | v.then(onSuccess(i), function(a) {
209 | promise.reject(a);
210 | });
211 | });
212 | return promise.promise;
213 | };
214 | catiline._hasWorker = typeof Worker !== 'undefined'&&typeof fakeLegacy === 'undefined';
215 | catiline.URL = window.URL || window.webkitURL;
216 | catiline._noTransferable=!catiline.URL;
217 | //regex out the importScript call and move it up to the top out of the function.
218 | function regexImports(string){
219 | var rest=string;
220 | var match = true;
221 | var matches = {};
222 | var loopFunc = function(a,b){
223 | if(b){
224 | 'importScripts('+b.split(',').forEach(function(cc){
225 | matches[catiline.makeUrl(cc.match(/\s*[\'\"](\S*)[\'\"]\s*/)[1])]=true; // trim whitespace, add to matches
226 | })+');\n';
227 | }
228 | };
229 | while(match){
230 | match = rest.match(/(importScripts\(.*?\);?)/);
231 | rest = rest.replace(/(importScripts\(\s*(?:[\'\"].*?[\'\"])?\s*\);?)/,'\n');
232 | if(match){
233 | match[0].replace(/importScripts\(\s*([\'\"].*?[\'\"])?\s*\);?/g,loopFunc);
234 | }
235 | }
236 | matches = Object.keys(matches);
237 | return [matches,rest];
238 | }
239 |
240 | function moveImports(string){
241 | var str = regexImports(string);
242 | var matches = str[0];
243 | var rest = str[1];
244 | if(matches.length>0){
245 | return 'importScripts(\''+matches.join('\',\'')+'\');\n'+rest;
246 | }else{
247 | return rest;
248 | }
249 | }
250 | function moveIimports(string){
251 | var str = regexImports(string);
252 | var matches = str[0];
253 | var rest = str[1];
254 | if(matches.length>0){
255 | return 'importScripts(\''+matches.join('\',\'')+'\');eval(__scripts__);\n'+rest;
256 | }else{
257 | return rest;
258 | }
259 | }
260 | function getPath(){
261 | if(typeof SHIM_WORKER_PATH !== 'undefined'){
262 | return SHIM_WORKER_PATH;
263 | }else if('SHIM_WORKER_PATH' in catiline){
264 | return catiline.SHIM_WORKER_PATH;
265 | }
266 | var scripts = document.getElementsByTagName('script');
267 | var len = scripts.length;
268 | var i = 0;
269 | while(i0){',
303 | ' scripts.forEach(function(url){',
304 | ' var ajax = new XMLHttpRequest();',
305 | ' ajax.open(\'GET\',url,false);',
306 | ' ajax.send();__scripts__+=ajax.responseText;',
307 | ' __scripts__+=\'\\n;\';',
308 | ' });',
309 | ' }',
310 | '};',
311 | script,
312 | '}catch(e){',
313 | ' window.parent.postMessage([\''+codeword+'\',\'error\'],\'*\')',
314 | '}'].join('\n');
315 | appendScript(iDoc,text);
316 | return iFrame;
317 | }
318 | function makeIframe(script,codeword){
319 | var promise = catiline.deferred();
320 | if(document.readyState==='complete'){
321 | promise.resolve(actualMakeI(script,codeword));
322 | }else{
323 | window.addEventListener('load',function(){
324 | promise.resolve(actualMakeI(script,codeword));
325 | },false);
326 | }
327 | return promise.promise;
328 | }
329 | catiline.makeIWorker = function (strings,codeword){
330 | var script =moveIimports(strings.join(''));
331 | var worker = {onmessage:function(){}};
332 | var ipromise = makeIframe(script,codeword);
333 | window.addEventListener('message',function(e){
334 | if(e.data.slice && e.data.slice(0,codeword.length) === codeword){
335 | worker.onmessage({data:JSON.parse(e.data.slice(codeword.length))});
336 | }
337 | });
338 | worker.postMessage=function(data){
339 | ipromise.then(function(iFrame){
340 | iFrame.contentWindow.postMessage(JSON.stringify(data),'*');
341 | });
342 | };
343 | worker.terminate=function(){
344 | ipromise.then(function(iFrame){
345 | document.body.removeChild(iFrame);
346 | });
347 | };
348 | return worker;
349 |
350 | };
351 |
352 | function makeFallbackWorker(script){
353 | catiline._noTransferable=true;
354 | var worker = new Worker(getPath());
355 | worker.postMessage(script);
356 | return worker;
357 | }
358 | //accepts an array of strings, joins them, and turns them into a worker.
359 | catiline.makeWorker = function (strings, codeword){
360 | if(!catiline._hasWorker){
361 | return catiline.makeIWorker(strings,codeword);
362 | }
363 | var worker;
364 | var script = moveImports(strings.join('\n'));
365 | if(catiline._noTransferable){
366 | return makeFallbackWorker(script);
367 | }
368 | try{
369 | worker= new Worker(catiline.URL.createObjectURL(new Blob([script],{type: 'text/javascript'})));
370 | }catch(e){
371 | try{
372 | worker=makeFallbackWorker(script);
373 | }catch(ee){
374 | worker = catiline.makeIWorker(strings,codeword);
375 | }
376 | }finally{
377 | return worker;
378 | }
379 | };
380 |
381 | catiline.makeUrl = function (fileName) {
382 | var link = document.createElement('link');
383 | link.href = fileName;
384 | return link.href;
385 | };
386 |
387 | function stringifyObject(obj){
388 | var out = '{';
389 | var first = true;
390 | for(var key in obj){
391 | if(first){
392 | first = false;
393 | }else{
394 | out+=',';
395 | }
396 | out += key;
397 | out += ':';
398 | out += catiline.stringify(obj[key]);
399 | }
400 | out += '}';
401 | return out;
402 | }
403 | function stringifyArray(array){
404 | if(array.length){
405 | var out = '[';
406 | out += catiline.stringify(array[0]);
407 | var i = 0;
408 | var len = array.length;
409 | while(++i 0) {
518 | eventName.split(' ').map(function(v) {
519 | return context.on(v, func, scope);
520 | }, this);
521 | return context;
522 | }
523 | if (!(eventName in listeners)) {
524 | listeners[eventName] = [];
525 | }
526 | var newFunc = function(a) {
527 | func.call(scope, a, scope);
528 | };
529 | newFunc.orig = func;
530 | listeners[eventName].push(newFunc);
531 | return context;
532 | };
533 | context.one = function(eventName, func, scope) {
534 | scope = scope || context;
535 |
536 | function ourFunc(a) {
537 | context.off(eventName, ourFunc);
538 | func.call(scope, a, scope);
539 | }
540 | return context.on(eventName, ourFunc);
541 | };
542 |
543 | context.trigger = function(eventName, data) {
544 | if (eventName.indexOf(' ') > 0) {
545 | eventName.split(' ').forEach(function(v) {
546 | context.trigger(v, data);
547 | });
548 | return context;
549 | }
550 | if (!(eventName in listeners)) {
551 | return context;
552 | }
553 | listeners[eventName].forEach(function(v) {
554 | v(data);
555 | });
556 | return context;
557 | };
558 | context.fire = function(eventName, data, transfer) {
559 | sendMessage([[eventName],data],transfer);
560 | return context;
561 | };
562 | context.off = function(eventName, func) {
563 | if (eventName.indexOf(' ') > 0) {
564 | eventName.split(' ').map(function(v) {
565 | return context.off(v, func);
566 | });
567 | return context;
568 | }
569 | if (!(eventName in listeners)) {
570 | return context;
571 | }
572 | else {
573 | if (func) {
574 | listeners[eventName] = listeners[eventName].map(function(a) {
575 | if (a.orig === func) {
576 | return false;
577 | }
578 | else {
579 | return a;
580 | }
581 | }).filter(function(a) {
582 | return a;
583 | });
584 | }
585 | else {
586 | delete listeners[eventName];
587 | }
588 | }
589 | return context;
590 | };
591 | };
592 | function Catiline(obj) {
593 | if (typeof obj === 'function') {
594 | obj = {
595 | data: obj
596 | };
597 | }
598 | var codeWord = 'com.catilinejs.' + (Catiline._hasWorker ? 'iframe' : 'worker') + Math.random();
599 | var self = this;
600 | var promises = [];
601 | addEvents(self, function(data, transfer) {
602 | if (catiline._noTransferable) {
603 | worker.postMessage(data);
604 | }
605 | else {
606 | worker.postMessage(data, transfer);
607 | }
608 | });
609 | var rejectPromises = function(msg) {
610 | if (typeof msg !== 'string' && 'preventDefault' in msg) {
611 | msg.preventDefault();
612 | msg = msg.message;
613 | }
614 | promises.forEach(function(p) {
615 | if (p) {
616 | p.reject(msg);
617 | }
618 | });
619 | };
620 | obj.__codeWord__ = codeWord;
621 | obj.__initialize__ = [workerSetup, addEvents];
622 | if (!('initialize' in obj)) {
623 | if ('init' in obj) {
624 | obj.__initialize__.push(obj.init);
625 | delete obj.init;
626 | }
627 | }
628 | else {
629 | obj.__initialize__.push(obj.initialize);
630 | //delete obj.initialize;
631 | }
632 |
633 | if (!('events' in obj)) {
634 | obj.events = {};
635 | }
636 | if ('listners' in obj && typeof obj.listners !== 'function') {
637 | for (var key in obj.listners) {
638 | self.on(key, obj.listners[key]);
639 | }
640 | delete obj.listners;
641 | }
642 | var fObj = 'var _db = {\n\t';
643 | var keyFunc = function(key) {
644 | var out = function(data, transfer) {
645 | var i = promises.length;
646 | promises[i] = catiline.deferred();
647 | if (catiline._noTransferable) {
648 | worker.postMessage([
649 | [codeWord, i], key, data]);
650 | }
651 | else {
652 | worker.postMessage([
653 | [codeWord, i], key, data], transfer);
654 | }
655 | return promises[i].promise;
656 | };
657 | return out;
658 | };
659 | var i = false;
660 | for (var key$0 in obj) {
661 | if (i) {
662 | fObj += ',\n\t';
663 | }
664 | else {
665 | i = true;
666 | }
667 | if (typeof obj[key$0] === 'function') {
668 | fObj = fObj + key$0 + ':' + obj[key$0].toString();
669 | self[key$0] = keyFunc(key$0);
670 | }
671 | else {
672 | var outThing = catiline.stringify(obj[key$0]);
673 | if (typeof outThing !== 'undefined') {
674 | fObj = fObj + key$0 + ':' + outThing;
675 | }
676 | }
677 | }
678 | fObj = fObj + '};';
679 | var worker = catiline.makeWorker(['\'use strict\';', '',
680 | fObj, '_db.__initialize__.forEach(function(f){', ' f.call(_db,_db);', '});', 'for(var key in _db.events){', ' _db.on(key,_db.events[key]);', '}'], codeWord);
681 | worker.onmessage = function(e) {
682 | self.trigger('message', e.data[1]);
683 | if (e.data[0][0] === codeWord) {
684 | promises[e.data[0][1]].resolve(e.data[1]);
685 | promises[e.data[0][1]] = 0;
686 | }
687 | else {
688 | self.trigger(e.data[0][0], e.data[1]);
689 | }
690 | };
691 | self.on('error', rejectPromises);
692 | worker.onerror = function(e) {
693 | self.trigger('error', e);
694 | };
695 | self.on('console', function(msg) {
696 | console[msg[0]].apply(console, msg[1]);
697 | });
698 | self._close = function() {
699 | worker.terminate();
700 | rejectPromises('closed');
701 | return catiline.resolve();
702 | };
703 | if (!('close' in self)) {
704 | self.close = self._close;
705 | }
706 | }
707 | catiline.Worker = Catiline;
708 |
709 | catiline.worker = function(obj){
710 | return new Catiline(obj);
711 | };
712 | catiline.Queue = function CatilineQueue(obj, n, dumb) {
713 | var self = this;
714 | self.__batchcb__ = {};
715 | self.__batchtcb__ = {};
716 | self.batch = function (cb) {
717 | if (typeof cb === 'function') {
718 | self.__batchcb__.__cb__ = cb;
719 | return self.__batchcb__;
720 | }
721 | else {
722 | return clearQueue(cb);
723 | }
724 | };
725 | self.batchTransfer = function (cb) {
726 | if (typeof cb === 'function') {
727 | self.__batchtcb__.__cb__ = cb;
728 | return self.__batchtcb__;
729 | }
730 | else {
731 | return clearQueue(cb);
732 | }
733 | };
734 | var workers = [];
735 | var numIdle = 0;
736 | var idle = [];
737 | var que = [];
738 | var queueLen = 0;
739 | while (numIdle < n) {
740 | workers[numIdle] = new catiline.Worker(obj);
741 | idle.push(numIdle);
742 | numIdle++;
743 | }
744 | self.on = function (eventName, func, context) {
745 | workers.forEach(function (worker) {
746 | worker.on(eventName, func, context);
747 | });
748 | return self;
749 | };
750 | self.off = function (eventName, func, context) {
751 | workers.forEach(function (worker) {
752 | worker.off(eventName, func, context);
753 | });
754 | return self;
755 | };
756 | var batchFire = function (eventName, data) {
757 | workers.forEach(function (worker) {
758 | worker.fire(eventName, data);
759 | });
760 | return self;
761 | };
762 | self.fire = function (eventName, data) {
763 | workers[~~ (Math.random() * n)].fire(eventName, data);
764 | return self;
765 | };
766 | self.batch.fire = batchFire;
767 | self.batchTransfer.fire = batchFire;
768 |
769 | function clearQueue(mgs) {
770 | mgs = mgs || 'canceled';
771 | queueLen = 0;
772 | var oQ = que;
773 | que = [];
774 | oQ.forEach(function (p) {
775 | p[3].reject(mgs);
776 | });
777 | return self;
778 | }
779 |
780 | function keyFunc(k) {
781 | return function (data, transfer) {
782 | return doStuff(k, data, transfer);
783 | };
784 | }
785 |
786 | function keyFuncBatch(k) {
787 | return function (array) {
788 | return catiline.all(array.map(function (data) {
789 | return doStuff(k, data);
790 | }));
791 | };
792 | }
793 |
794 | function keyFuncBatchCB(k) {
795 | return function (array) {
796 | var self = this;
797 | return catiline.all(array.map(function (data) {
798 | return doStuff(k, data).then(self.__cb__);
799 | }));
800 | };
801 | }
802 |
803 | function keyFuncBatchTransfer(k) {
804 | return function (array) {
805 | return catiline.all(array.map(function (data) {
806 | return doStuff(k, data[0], data[1]);
807 | }));
808 | };
809 | }
810 |
811 | function keyFuncBatchTransferCB(k) {
812 | return function (array) {
813 | var self = this;
814 | return catiline.all(array.map(function (data) {
815 | return doStuff(k, data[0], data[1]).then(self.__cb__);
816 | }));
817 | };
818 | }
819 | for (var key in obj) {
820 | self[key] = keyFunc(key);
821 | self.batch[key] = keyFuncBatch(key);
822 | self.__batchcb__[key] = keyFuncBatchCB(key);
823 | self.batchTransfer[key] = keyFuncBatchTransfer(key);
824 | self.__batchtcb__[key] = keyFuncBatchTransferCB(key);
825 | }
826 |
827 | function done(num) {
828 | if (queueLen) {
829 | var data = que.shift();
830 | queueLen--;
831 | workers[num][data[0]](data[1], data[2]).then(function (d) {
832 | done(num);
833 | data[3].resolve(d);
834 | }, function (d) {
835 | done(num);
836 | data[3].reject(d);
837 | });
838 | }
839 | else {
840 | numIdle++;
841 | idle.push(num);
842 | }
843 | }
844 |
845 | function doStuff(key, data, transfer) { //srsly better name!
846 | var promise = catiline.deferred();
847 | if (dumb) {
848 | promise.promise.cancel = function(reason){
849 | return promise.reject(reason);
850 | };
851 | workers[~~ (Math.random() * n)][key](data, transfer).then(function(v){
852 | return promise.resolve(v);
853 | },function(v){
854 | return promise.reject(v);
855 | });
856 | return promise.promise;
857 | }
858 | if (!queueLen && numIdle) {
859 | var num = idle.pop();
860 | numIdle--;
861 | promise.promise.cancel = function(reason){
862 | return promise.reject(reason);
863 | };
864 | workers[num][key](data, transfer).then(function (d) {
865 | done(num);
866 | promise.resolve(d);
867 | }, function (d) {
868 | done(num);
869 | promise.reject(d);
870 | });
871 | }
872 | else if (queueLen || !numIdle) {
873 | var queueItem = [key, data, transfer, promise];
874 | promise.promise.cancel = function(reason){
875 | var loc = que.indexOf(queueItem);
876 | if(loc>-1){
877 | que.splice(loc,1);
878 | queueLen--;
879 | }
880 | return promise.reject(reason);
881 | };
882 | queueLen = que.push(queueItem);
883 | }
884 | return promise.promise;
885 | }
886 | self._close = function () {
887 | return catiline.all(workers.map(function (w) {
888 | return w._close();
889 | }));
890 | };
891 | if (!('close' in self)) {
892 | self.close = self._close;
893 | }
894 | };
895 | catiline.queue = function (obj, n, dumb) {
896 | return new catiline.Queue(obj, n, dumb);
897 | };
898 |
899 | function catiline(object,queueLength,unmanaged){
900 | if(arguments.length === 1 || !queueLength || queueLength <= 1){
901 | return new catiline.Worker(object);
902 | }else{
903 | return new catiline.Queue(object,queueLength,unmanaged);
904 | }
905 | }
906 | //will be removed in v3
907 | catiline.setImmediate = catiline.nextTick;
908 | function initBrowser(catiline){
909 | var origCW = global.cw;
910 | catiline.noConflict=function(newName){
911 | global.cw = origCW;
912 | if(newName){
913 | global[newName]=catiline;
914 | }
915 | };
916 | global.catiline = catiline;
917 | global.cw = catiline;
918 | if(!('communist' in global)){
919 | global.communist=catiline;
920 | }
921 |
922 | }
923 |
924 | if(typeof define === 'function'){
925 | define(function(require){
926 | catiline.SHIM_WORKER_PATH=require.toUrl('./catiline.js');
927 | return catiline;
928 | });
929 | }else if(typeof module === 'undefined' || !('exports' in module)){
930 | initBrowser(catiline);
931 | } else {
932 | module.exports=catiline;
933 | }catiline.version = '2.9.0-dev.2';
934 | })(this);}
--------------------------------------------------------------------------------
/jam/require.js:
--------------------------------------------------------------------------------
1 | /** vim: et:ts=4:sw=4:sts=4
2 | * @license RequireJS 2.1.4 Copyright (c) 2010-2012, The Dojo Foundation All Rights Reserved.
3 | * Available via the MIT or new BSD license.
4 | * see: http://github.com/jrburke/requirejs for details
5 | */
6 | //Not using strict: uneven strict support in browsers, #392, and causes
7 | //problems with requirejs.exec()/transpiler plugins that may not be strict.
8 | /*jslint regexp: true, nomen: true, sloppy: true */
9 | /*global window, navigator, document, importScripts, setTimeout, opera */
10 |
11 | var requirejs, require, define;
12 | (function (global) {
13 | var req, s, head, baseElement, dataMain, src,
14 | interactiveScript, currentlyAddingScript, mainScript, subPath,
15 | version = '2.1.4',
16 | commentRegExp = /(\/\*([\s\S]*?)\*\/|([^:]|^)\/\/(.*)$)/mg,
17 | cjsRequireRegExp = /[^.]\s*require\s*\(\s*["']([^'"\s]+)["']\s*\)/g,
18 | jsSuffixRegExp = /\.js$/,
19 | currDirRegExp = /^\.\//,
20 | op = Object.prototype,
21 | ostring = op.toString,
22 | hasOwn = op.hasOwnProperty,
23 | ap = Array.prototype,
24 | apsp = ap.splice,
25 | isBrowser = !!(typeof window !== 'undefined' && navigator && document),
26 | isWebWorker = !isBrowser && typeof importScripts !== 'undefined',
27 | //PS3 indicates loaded and complete, but need to wait for complete
28 | //specifically. Sequence is 'loading', 'loaded', execution,
29 | // then 'complete'. The UA check is unfortunate, but not sure how
30 | //to feature test w/o causing perf issues.
31 | readyRegExp = isBrowser && navigator.platform === 'PLAYSTATION 3' ?
32 | /^complete$/ : /^(complete|loaded)$/,
33 | defContextName = '_',
34 | //Oh the tragedy, detecting opera. See the usage of isOpera for reason.
35 | isOpera = typeof opera !== 'undefined' && opera.toString() === '[object Opera]',
36 | contexts = {},
37 | cfg = {},
38 | globalDefQueue = [],
39 | useInteractive = false;
40 |
41 | function isFunction(it) {
42 | return ostring.call(it) === '[object Function]';
43 | }
44 |
45 | function isArray(it) {
46 | return ostring.call(it) === '[object Array]';
47 | }
48 |
49 | /**
50 | * Helper function for iterating over an array. If the func returns
51 | * a true value, it will break out of the loop.
52 | */
53 | function each(ary, func) {
54 | if (ary) {
55 | var i;
56 | for (i = 0; i < ary.length; i += 1) {
57 | if (ary[i] && func(ary[i], i, ary)) {
58 | break;
59 | }
60 | }
61 | }
62 | }
63 |
64 | /**
65 | * Helper function for iterating over an array backwards. If the func
66 | * returns a true value, it will break out of the loop.
67 | */
68 | function eachReverse(ary, func) {
69 | if (ary) {
70 | var i;
71 | for (i = ary.length - 1; i > -1; i -= 1) {
72 | if (ary[i] && func(ary[i], i, ary)) {
73 | break;
74 | }
75 | }
76 | }
77 | }
78 |
79 | function hasProp(obj, prop) {
80 | return hasOwn.call(obj, prop);
81 | }
82 |
83 | function getOwn(obj, prop) {
84 | return hasProp(obj, prop) && obj[prop];
85 | }
86 |
87 | /**
88 | * Cycles over properties in an object and calls a function for each
89 | * property value. If the function returns a truthy value, then the
90 | * iteration is stopped.
91 | */
92 | function eachProp(obj, func) {
93 | var prop;
94 | for (prop in obj) {
95 | if (hasProp(obj, prop)) {
96 | if (func(obj[prop], prop)) {
97 | break;
98 | }
99 | }
100 | }
101 | }
102 |
103 | /**
104 | * Simple function to mix in properties from source into target,
105 | * but only if target does not already have a property of the same name.
106 | */
107 | function mixin(target, source, force, deepStringMixin) {
108 | if (source) {
109 | eachProp(source, function (value, prop) {
110 | if (force || !hasProp(target, prop)) {
111 | if (deepStringMixin && typeof value !== 'string') {
112 | if (!target[prop]) {
113 | target[prop] = {};
114 | }
115 | mixin(target[prop], value, force, deepStringMixin);
116 | } else {
117 | target[prop] = value;
118 | }
119 | }
120 | });
121 | }
122 | return target;
123 | }
124 |
125 | //Similar to Function.prototype.bind, but the 'this' object is specified
126 | //first, since it is easier to read/figure out what 'this' will be.
127 | function bind(obj, fn) {
128 | return function () {
129 | return fn.apply(obj, arguments);
130 | };
131 | }
132 |
133 | function scripts() {
134 | return document.getElementsByTagName('script');
135 | }
136 |
137 | //Allow getting a global that expressed in
138 | //dot notation, like 'a.b.c'.
139 | function getGlobal(value) {
140 | if (!value) {
141 | return value;
142 | }
143 | var g = global;
144 | each(value.split('.'), function (part) {
145 | g = g[part];
146 | });
147 | return g;
148 | }
149 |
150 | /**
151 | * Constructs an error with a pointer to an URL with more information.
152 | * @param {String} id the error ID that maps to an ID on a web page.
153 | * @param {String} message human readable error.
154 | * @param {Error} [err] the original error, if there is one.
155 | *
156 | * @returns {Error}
157 | */
158 | function makeError(id, msg, err, requireModules) {
159 | var e = new Error(msg + '\nhttp://requirejs.org/docs/errors.html#' + id);
160 | e.requireType = id;
161 | e.requireModules = requireModules;
162 | if (err) {
163 | e.originalError = err;
164 | }
165 | return e;
166 | }
167 |
168 | if (typeof define !== 'undefined') {
169 | //If a define is already in play via another AMD loader,
170 | //do not overwrite.
171 | return;
172 | }
173 |
174 | if (typeof requirejs !== 'undefined') {
175 | if (isFunction(requirejs)) {
176 | //Do not overwrite and existing requirejs instance.
177 | return;
178 | }
179 | cfg = requirejs;
180 | requirejs = undefined;
181 | }
182 |
183 | //Allow for a require config object
184 | if (typeof require !== 'undefined' && !isFunction(require)) {
185 | //assume it is a config object.
186 | cfg = require;
187 | require = undefined;
188 | }
189 |
190 | function newContext(contextName) {
191 | var inCheckLoaded, Module, context, handlers,
192 | checkLoadedTimeoutId,
193 | config = {
194 | waitSeconds: 7,
195 | baseUrl: './',
196 | paths: {},
197 | pkgs: {},
198 | shim: {},
199 | map: {},
200 | config: {}
201 | },
202 | registry = {},
203 | undefEvents = {},
204 | defQueue = [],
205 | defined = {},
206 | urlFetched = {},
207 | requireCounter = 1,
208 | unnormalizedCounter = 1;
209 |
210 | /**
211 | * Trims the . and .. from an array of path segments.
212 | * It will keep a leading path segment if a .. will become
213 | * the first path segment, to help with module name lookups,
214 | * which act like paths, but can be remapped. But the end result,
215 | * all paths that use this function should look normalized.
216 | * NOTE: this method MODIFIES the input array.
217 | * @param {Array} ary the array of path segments.
218 | */
219 | function trimDots(ary) {
220 | var i, part;
221 | for (i = 0; ary[i]; i += 1) {
222 | part = ary[i];
223 | if (part === '.') {
224 | ary.splice(i, 1);
225 | i -= 1;
226 | } else if (part === '..') {
227 | if (i === 1 && (ary[2] === '..' || ary[0] === '..')) {
228 | //End of the line. Keep at least one non-dot
229 | //path segment at the front so it can be mapped
230 | //correctly to disk. Otherwise, there is likely
231 | //no path mapping for a path starting with '..'.
232 | //This can still fail, but catches the most reasonable
233 | //uses of ..
234 | break;
235 | } else if (i > 0) {
236 | ary.splice(i - 1, 2);
237 | i -= 2;
238 | }
239 | }
240 | }
241 | }
242 |
243 | /**
244 | * Given a relative module name, like ./something, normalize it to
245 | * a real name that can be mapped to a path.
246 | * @param {String} name the relative name
247 | * @param {String} baseName a real name that the name arg is relative
248 | * to.
249 | * @param {Boolean} applyMap apply the map config to the value. Should
250 | * only be done if this normalization is for a dependency ID.
251 | * @returns {String} normalized name
252 | */
253 | function normalize(name, baseName, applyMap) {
254 | var pkgName, pkgConfig, mapValue, nameParts, i, j, nameSegment,
255 | foundMap, foundI, foundStarMap, starI,
256 | baseParts = baseName && baseName.split('/'),
257 | normalizedBaseParts = baseParts,
258 | map = config.map,
259 | starMap = map && map['*'];
260 |
261 | //Adjust any relative paths.
262 | if (name && name.charAt(0) === '.') {
263 | //If have a base name, try to normalize against it,
264 | //otherwise, assume it is a top-level require that will
265 | //be relative to baseUrl in the end.
266 | if (baseName) {
267 | if (getOwn(config.pkgs, baseName)) {
268 | //If the baseName is a package name, then just treat it as one
269 | //name to concat the name with.
270 | normalizedBaseParts = baseParts = [baseName];
271 | } else {
272 | //Convert baseName to array, and lop off the last part,
273 | //so that . matches that 'directory' and not name of the baseName's
274 | //module. For instance, baseName of 'one/two/three', maps to
275 | //'one/two/three.js', but we want the directory, 'one/two' for
276 | //this normalization.
277 | normalizedBaseParts = baseParts.slice(0, baseParts.length - 1);
278 | }
279 |
280 | name = normalizedBaseParts.concat(name.split('/'));
281 | trimDots(name);
282 |
283 | //Some use of packages may use a . path to reference the
284 | //'main' module name, so normalize for that.
285 | pkgConfig = getOwn(config.pkgs, (pkgName = name[0]));
286 | name = name.join('/');
287 | if (pkgConfig && name === pkgName + '/' + pkgConfig.main) {
288 | name = pkgName;
289 | }
290 | } else if (name.indexOf('./') === 0) {
291 | // No baseName, so this is ID is resolved relative
292 | // to baseUrl, pull off the leading dot.
293 | name = name.substring(2);
294 | }
295 | }
296 |
297 | //Apply map config if available.
298 | if (applyMap && (baseParts || starMap) && map) {
299 | nameParts = name.split('/');
300 |
301 | for (i = nameParts.length; i > 0; i -= 1) {
302 | nameSegment = nameParts.slice(0, i).join('/');
303 |
304 | if (baseParts) {
305 | //Find the longest baseName segment match in the config.
306 | //So, do joins on the biggest to smallest lengths of baseParts.
307 | for (j = baseParts.length; j > 0; j -= 1) {
308 | mapValue = getOwn(map, baseParts.slice(0, j).join('/'));
309 |
310 | //baseName segment has config, find if it has one for
311 | //this name.
312 | if (mapValue) {
313 | mapValue = getOwn(mapValue, nameSegment);
314 | if (mapValue) {
315 | //Match, update name to the new value.
316 | foundMap = mapValue;
317 | foundI = i;
318 | break;
319 | }
320 | }
321 | }
322 | }
323 |
324 | if (foundMap) {
325 | break;
326 | }
327 |
328 | //Check for a star map match, but just hold on to it,
329 | //if there is a shorter segment match later in a matching
330 | //config, then favor over this star map.
331 | if (!foundStarMap && starMap && getOwn(starMap, nameSegment)) {
332 | foundStarMap = getOwn(starMap, nameSegment);
333 | starI = i;
334 | }
335 | }
336 |
337 | if (!foundMap && foundStarMap) {
338 | foundMap = foundStarMap;
339 | foundI = starI;
340 | }
341 |
342 | if (foundMap) {
343 | nameParts.splice(0, foundI, foundMap);
344 | name = nameParts.join('/');
345 | }
346 | }
347 |
348 | return name;
349 | }
350 |
351 | function removeScript(name) {
352 | if (isBrowser) {
353 | each(scripts(), function (scriptNode) {
354 | if (scriptNode.getAttribute('data-requiremodule') === name &&
355 | scriptNode.getAttribute('data-requirecontext') === context.contextName) {
356 | scriptNode.parentNode.removeChild(scriptNode);
357 | return true;
358 | }
359 | });
360 | }
361 | }
362 |
363 | function hasPathFallback(id) {
364 | var pathConfig = getOwn(config.paths, id);
365 | if (pathConfig && isArray(pathConfig) && pathConfig.length > 1) {
366 | removeScript(id);
367 | //Pop off the first array value, since it failed, and
368 | //retry
369 | pathConfig.shift();
370 | context.require.undef(id);
371 | context.require([id]);
372 | return true;
373 | }
374 | }
375 |
376 | //Turns a plugin!resource to [plugin, resource]
377 | //with the plugin being undefined if the name
378 | //did not have a plugin prefix.
379 | function splitPrefix(name) {
380 | var prefix,
381 | index = name ? name.indexOf('!') : -1;
382 | if (index > -1) {
383 | prefix = name.substring(0, index);
384 | name = name.substring(index + 1, name.length);
385 | }
386 | return [prefix, name];
387 | }
388 |
389 | /**
390 | * Creates a module mapping that includes plugin prefix, module
391 | * name, and path. If parentModuleMap is provided it will
392 | * also normalize the name via require.normalize()
393 | *
394 | * @param {String} name the module name
395 | * @param {String} [parentModuleMap] parent module map
396 | * for the module name, used to resolve relative names.
397 | * @param {Boolean} isNormalized: is the ID already normalized.
398 | * This is true if this call is done for a define() module ID.
399 | * @param {Boolean} applyMap: apply the map config to the ID.
400 | * Should only be true if this map is for a dependency.
401 | *
402 | * @returns {Object}
403 | */
404 | function makeModuleMap(name, parentModuleMap, isNormalized, applyMap) {
405 | var url, pluginModule, suffix, nameParts,
406 | prefix = null,
407 | parentName = parentModuleMap ? parentModuleMap.name : null,
408 | originalName = name,
409 | isDefine = true,
410 | normalizedName = '';
411 |
412 | //If no name, then it means it is a require call, generate an
413 | //internal name.
414 | if (!name) {
415 | isDefine = false;
416 | name = '_@r' + (requireCounter += 1);
417 | }
418 |
419 | nameParts = splitPrefix(name);
420 | prefix = nameParts[0];
421 | name = nameParts[1];
422 |
423 | if (prefix) {
424 | prefix = normalize(prefix, parentName, applyMap);
425 | pluginModule = getOwn(defined, prefix);
426 | }
427 |
428 | //Account for relative paths if there is a base name.
429 | if (name) {
430 | if (prefix) {
431 | if (pluginModule && pluginModule.normalize) {
432 | //Plugin is loaded, use its normalize method.
433 | normalizedName = pluginModule.normalize(name, function (name) {
434 | return normalize(name, parentName, applyMap);
435 | });
436 | } else {
437 | normalizedName = normalize(name, parentName, applyMap);
438 | }
439 | } else {
440 | //A regular module.
441 | normalizedName = normalize(name, parentName, applyMap);
442 |
443 | //Normalized name may be a plugin ID due to map config
444 | //application in normalize. The map config values must
445 | //already be normalized, so do not need to redo that part.
446 | nameParts = splitPrefix(normalizedName);
447 | prefix = nameParts[0];
448 | normalizedName = nameParts[1];
449 | isNormalized = true;
450 |
451 | url = context.nameToUrl(normalizedName);
452 | }
453 | }
454 |
455 | //If the id is a plugin id that cannot be determined if it needs
456 | //normalization, stamp it with a unique ID so two matching relative
457 | //ids that may conflict can be separate.
458 | suffix = prefix && !pluginModule && !isNormalized ?
459 | '_unnormalized' + (unnormalizedCounter += 1) :
460 | '';
461 |
462 | return {
463 | prefix: prefix,
464 | name: normalizedName,
465 | parentMap: parentModuleMap,
466 | unnormalized: !!suffix,
467 | url: url,
468 | originalName: originalName,
469 | isDefine: isDefine,
470 | id: (prefix ?
471 | prefix + '!' + normalizedName :
472 | normalizedName) + suffix
473 | };
474 | }
475 |
476 | function getModule(depMap) {
477 | var id = depMap.id,
478 | mod = getOwn(registry, id);
479 |
480 | if (!mod) {
481 | mod = registry[id] = new context.Module(depMap);
482 | }
483 |
484 | return mod;
485 | }
486 |
487 | function on(depMap, name, fn) {
488 | var id = depMap.id,
489 | mod = getOwn(registry, id);
490 |
491 | if (hasProp(defined, id) &&
492 | (!mod || mod.defineEmitComplete)) {
493 | if (name === 'defined') {
494 | fn(defined[id]);
495 | }
496 | } else {
497 | getModule(depMap).on(name, fn);
498 | }
499 | }
500 |
501 | function onError(err, errback) {
502 | var ids = err.requireModules,
503 | notified = false;
504 |
505 | if (errback) {
506 | errback(err);
507 | } else {
508 | each(ids, function (id) {
509 | var mod = getOwn(registry, id);
510 | if (mod) {
511 | //Set error on module, so it skips timeout checks.
512 | mod.error = err;
513 | if (mod.events.error) {
514 | notified = true;
515 | mod.emit('error', err);
516 | }
517 | }
518 | });
519 |
520 | if (!notified) {
521 | req.onError(err);
522 | }
523 | }
524 | }
525 |
526 | /**
527 | * Internal method to transfer globalQueue items to this context's
528 | * defQueue.
529 | */
530 | function takeGlobalQueue() {
531 | //Push all the globalDefQueue items into the context's defQueue
532 | if (globalDefQueue.length) {
533 | //Array splice in the values since the context code has a
534 | //local var ref to defQueue, so cannot just reassign the one
535 | //on context.
536 | apsp.apply(defQueue,
537 | [defQueue.length - 1, 0].concat(globalDefQueue));
538 | globalDefQueue = [];
539 | }
540 | }
541 |
542 | handlers = {
543 | 'require': function (mod) {
544 | if (mod.require) {
545 | return mod.require;
546 | } else {
547 | return (mod.require = context.makeRequire(mod.map));
548 | }
549 | },
550 | 'exports': function (mod) {
551 | mod.usingExports = true;
552 | if (mod.map.isDefine) {
553 | if (mod.exports) {
554 | return mod.exports;
555 | } else {
556 | return (mod.exports = defined[mod.map.id] = {});
557 | }
558 | }
559 | },
560 | 'module': function (mod) {
561 | if (mod.module) {
562 | return mod.module;
563 | } else {
564 | return (mod.module = {
565 | id: mod.map.id,
566 | uri: mod.map.url,
567 | config: function () {
568 | return (config.config && getOwn(config.config, mod.map.id)) || {};
569 | },
570 | exports: defined[mod.map.id]
571 | });
572 | }
573 | }
574 | };
575 |
576 | function cleanRegistry(id) {
577 | //Clean up machinery used for waiting modules.
578 | delete registry[id];
579 | }
580 |
581 | function breakCycle(mod, traced, processed) {
582 | var id = mod.map.id;
583 |
584 | if (mod.error) {
585 | mod.emit('error', mod.error);
586 | } else {
587 | traced[id] = true;
588 | each(mod.depMaps, function (depMap, i) {
589 | var depId = depMap.id,
590 | dep = getOwn(registry, depId);
591 |
592 | //Only force things that have not completed
593 | //being defined, so still in the registry,
594 | //and only if it has not been matched up
595 | //in the module already.
596 | if (dep && !mod.depMatched[i] && !processed[depId]) {
597 | if (getOwn(traced, depId)) {
598 | mod.defineDep(i, defined[depId]);
599 | mod.check(); //pass false?
600 | } else {
601 | breakCycle(dep, traced, processed);
602 | }
603 | }
604 | });
605 | processed[id] = true;
606 | }
607 | }
608 |
609 | function checkLoaded() {
610 | var map, modId, err, usingPathFallback,
611 | waitInterval = config.waitSeconds * 1000,
612 | //It is possible to disable the wait interval by using waitSeconds of 0.
613 | expired = waitInterval && (context.startTime + waitInterval) < new Date().getTime(),
614 | noLoads = [],
615 | reqCalls = [],
616 | stillLoading = false,
617 | needCycleCheck = true;
618 |
619 | //Do not bother if this call was a result of a cycle break.
620 | if (inCheckLoaded) {
621 | return;
622 | }
623 |
624 | inCheckLoaded = true;
625 |
626 | //Figure out the state of all the modules.
627 | eachProp(registry, function (mod) {
628 | map = mod.map;
629 | modId = map.id;
630 |
631 | //Skip things that are not enabled or in error state.
632 | if (!mod.enabled) {
633 | return;
634 | }
635 |
636 | if (!map.isDefine) {
637 | reqCalls.push(mod);
638 | }
639 |
640 | if (!mod.error) {
641 | //If the module should be executed, and it has not
642 | //been inited and time is up, remember it.
643 | if (!mod.inited && expired) {
644 | if (hasPathFallback(modId)) {
645 | usingPathFallback = true;
646 | stillLoading = true;
647 | } else {
648 | noLoads.push(modId);
649 | removeScript(modId);
650 | }
651 | } else if (!mod.inited && mod.fetched && map.isDefine) {
652 | stillLoading = true;
653 | if (!map.prefix) {
654 | //No reason to keep looking for unfinished
655 | //loading. If the only stillLoading is a
656 | //plugin resource though, keep going,
657 | //because it may be that a plugin resource
658 | //is waiting on a non-plugin cycle.
659 | return (needCycleCheck = false);
660 | }
661 | }
662 | }
663 | });
664 |
665 | if (expired && noLoads.length) {
666 | //If wait time expired, throw error of unloaded modules.
667 | err = makeError('timeout', 'Load timeout for modules: ' + noLoads, null, noLoads);
668 | err.contextName = context.contextName;
669 | return onError(err);
670 | }
671 |
672 | //Not expired, check for a cycle.
673 | if (needCycleCheck) {
674 | each(reqCalls, function (mod) {
675 | breakCycle(mod, {}, {});
676 | });
677 | }
678 |
679 | //If still waiting on loads, and the waiting load is something
680 | //other than a plugin resource, or there are still outstanding
681 | //scripts, then just try back later.
682 | if ((!expired || usingPathFallback) && stillLoading) {
683 | //Something is still waiting to load. Wait for it, but only
684 | //if a timeout is not already in effect.
685 | if ((isBrowser || isWebWorker) && !checkLoadedTimeoutId) {
686 | checkLoadedTimeoutId = setTimeout(function () {
687 | checkLoadedTimeoutId = 0;
688 | checkLoaded();
689 | }, 50);
690 | }
691 | }
692 |
693 | inCheckLoaded = false;
694 | }
695 |
696 | Module = function (map) {
697 | this.events = getOwn(undefEvents, map.id) || {};
698 | this.map = map;
699 | this.shim = getOwn(config.shim, map.id);
700 | this.depExports = [];
701 | this.depMaps = [];
702 | this.depMatched = [];
703 | this.pluginMaps = {};
704 | this.depCount = 0;
705 |
706 | /* this.exports this.factory
707 | this.depMaps = [],
708 | this.enabled, this.fetched
709 | */
710 | };
711 |
712 | Module.prototype = {
713 | init: function (depMaps, factory, errback, options) {
714 | options = options || {};
715 |
716 | //Do not do more inits if already done. Can happen if there
717 | //are multiple define calls for the same module. That is not
718 | //a normal, common case, but it is also not unexpected.
719 | if (this.inited) {
720 | return;
721 | }
722 |
723 | this.factory = factory;
724 |
725 | if (errback) {
726 | //Register for errors on this module.
727 | this.on('error', errback);
728 | } else if (this.events.error) {
729 | //If no errback already, but there are error listeners
730 | //on this module, set up an errback to pass to the deps.
731 | errback = bind(this, function (err) {
732 | this.emit('error', err);
733 | });
734 | }
735 |
736 | //Do a copy of the dependency array, so that
737 | //source inputs are not modified. For example
738 | //"shim" deps are passed in here directly, and
739 | //doing a direct modification of the depMaps array
740 | //would affect that config.
741 | this.depMaps = depMaps && depMaps.slice(0);
742 |
743 | this.errback = errback;
744 |
745 | //Indicate this module has be initialized
746 | this.inited = true;
747 |
748 | this.ignore = options.ignore;
749 |
750 | //Could have option to init this module in enabled mode,
751 | //or could have been previously marked as enabled. However,
752 | //the dependencies are not known until init is called. So
753 | //if enabled previously, now trigger dependencies as enabled.
754 | if (options.enabled || this.enabled) {
755 | //Enable this module and dependencies.
756 | //Will call this.check()
757 | this.enable();
758 | } else {
759 | this.check();
760 | }
761 | },
762 |
763 | defineDep: function (i, depExports) {
764 | //Because of cycles, defined callback for a given
765 | //export can be called more than once.
766 | if (!this.depMatched[i]) {
767 | this.depMatched[i] = true;
768 | this.depCount -= 1;
769 | this.depExports[i] = depExports;
770 | }
771 | },
772 |
773 | fetch: function () {
774 | if (this.fetched) {
775 | return;
776 | }
777 | this.fetched = true;
778 |
779 | context.startTime = (new Date()).getTime();
780 |
781 | var map = this.map;
782 |
783 | //If the manager is for a plugin managed resource,
784 | //ask the plugin to load it now.
785 | if (this.shim) {
786 | context.makeRequire(this.map, {
787 | enableBuildCallback: true
788 | })(this.shim.deps || [], bind(this, function () {
789 | return map.prefix ? this.callPlugin() : this.load();
790 | }));
791 | } else {
792 | //Regular dependency.
793 | return map.prefix ? this.callPlugin() : this.load();
794 | }
795 | },
796 |
797 | load: function () {
798 | var url = this.map.url;
799 |
800 | //Regular dependency.
801 | if (!urlFetched[url]) {
802 | urlFetched[url] = true;
803 | context.load(this.map.id, url);
804 | }
805 | },
806 |
807 | /**
808 | * Checks is the module is ready to define itself, and if so,
809 | * define it.
810 | */
811 | check: function () {
812 | if (!this.enabled || this.enabling) {
813 | return;
814 | }
815 |
816 | var err, cjsModule,
817 | id = this.map.id,
818 | depExports = this.depExports,
819 | exports = this.exports,
820 | factory = this.factory;
821 |
822 | if (!this.inited) {
823 | this.fetch();
824 | } else if (this.error) {
825 | this.emit('error', this.error);
826 | } else if (!this.defining) {
827 | //The factory could trigger another require call
828 | //that would result in checking this module to
829 | //define itself again. If already in the process
830 | //of doing that, skip this work.
831 | this.defining = true;
832 |
833 | if (this.depCount < 1 && !this.defined) {
834 | if (isFunction(factory)) {
835 | //If there is an error listener, favor passing
836 | //to that instead of throwing an error.
837 | if (this.events.error) {
838 | try {
839 | exports = context.execCb(id, factory, depExports, exports);
840 | } catch (e) {
841 | err = e;
842 | }
843 | } else {
844 | exports = context.execCb(id, factory, depExports, exports);
845 | }
846 |
847 | if (this.map.isDefine) {
848 | //If setting exports via 'module' is in play,
849 | //favor that over return value and exports. After that,
850 | //favor a non-undefined return value over exports use.
851 | cjsModule = this.module;
852 | if (cjsModule &&
853 | cjsModule.exports !== undefined &&
854 | //Make sure it is not already the exports value
855 | cjsModule.exports !== this.exports) {
856 | exports = cjsModule.exports;
857 | } else if (exports === undefined && this.usingExports) {
858 | //exports already set the defined value.
859 | exports = this.exports;
860 | }
861 | }
862 |
863 | if (err) {
864 | err.requireMap = this.map;
865 | err.requireModules = [this.map.id];
866 | err.requireType = 'define';
867 | return onError((this.error = err));
868 | }
869 |
870 | } else {
871 | //Just a literal value
872 | exports = factory;
873 | }
874 |
875 | this.exports = exports;
876 |
877 | if (this.map.isDefine && !this.ignore) {
878 | defined[id] = exports;
879 |
880 | if (req.onResourceLoad) {
881 | req.onResourceLoad(context, this.map, this.depMaps);
882 | }
883 | }
884 |
885 | //Clean up
886 | delete registry[id];
887 |
888 | this.defined = true;
889 | }
890 |
891 | //Finished the define stage. Allow calling check again
892 | //to allow define notifications below in the case of a
893 | //cycle.
894 | this.defining = false;
895 |
896 | if (this.defined && !this.defineEmitted) {
897 | this.defineEmitted = true;
898 | this.emit('defined', this.exports);
899 | this.defineEmitComplete = true;
900 | }
901 |
902 | }
903 | },
904 |
905 | callPlugin: function () {
906 | var map = this.map,
907 | id = map.id,
908 | //Map already normalized the prefix.
909 | pluginMap = makeModuleMap(map.prefix);
910 |
911 | //Mark this as a dependency for this plugin, so it
912 | //can be traced for cycles.
913 | this.depMaps.push(pluginMap);
914 |
915 | on(pluginMap, 'defined', bind(this, function (plugin) {
916 | var load, normalizedMap, normalizedMod,
917 | name = this.map.name,
918 | parentName = this.map.parentMap ? this.map.parentMap.name : null,
919 | localRequire = context.makeRequire(map.parentMap, {
920 | enableBuildCallback: true
921 | });
922 |
923 | //If current map is not normalized, wait for that
924 | //normalized name to load instead of continuing.
925 | if (this.map.unnormalized) {
926 | //Normalize the ID if the plugin allows it.
927 | if (plugin.normalize) {
928 | name = plugin.normalize(name, function (name) {
929 | return normalize(name, parentName, true);
930 | }) || '';
931 | }
932 |
933 | //prefix and name should already be normalized, no need
934 | //for applying map config again either.
935 | normalizedMap = makeModuleMap(map.prefix + '!' + name,
936 | this.map.parentMap);
937 | on(normalizedMap,
938 | 'defined', bind(this, function (value) {
939 | this.init([], function () { return value; }, null, {
940 | enabled: true,
941 | ignore: true
942 | });
943 | }));
944 |
945 | normalizedMod = getOwn(registry, normalizedMap.id);
946 | if (normalizedMod) {
947 | //Mark this as a dependency for this plugin, so it
948 | //can be traced for cycles.
949 | this.depMaps.push(normalizedMap);
950 |
951 | if (this.events.error) {
952 | normalizedMod.on('error', bind(this, function (err) {
953 | this.emit('error', err);
954 | }));
955 | }
956 | normalizedMod.enable();
957 | }
958 |
959 | return;
960 | }
961 |
962 | load = bind(this, function (value) {
963 | this.init([], function () { return value; }, null, {
964 | enabled: true
965 | });
966 | });
967 |
968 | load.error = bind(this, function (err) {
969 | this.inited = true;
970 | this.error = err;
971 | err.requireModules = [id];
972 |
973 | //Remove temp unnormalized modules for this module,
974 | //since they will never be resolved otherwise now.
975 | eachProp(registry, function (mod) {
976 | if (mod.map.id.indexOf(id + '_unnormalized') === 0) {
977 | cleanRegistry(mod.map.id);
978 | }
979 | });
980 |
981 | onError(err);
982 | });
983 |
984 | //Allow plugins to load other code without having to know the
985 | //context or how to 'complete' the load.
986 | load.fromText = bind(this, function (text, textAlt) {
987 | /*jslint evil: true */
988 | var moduleName = map.name,
989 | moduleMap = makeModuleMap(moduleName),
990 | hasInteractive = useInteractive;
991 |
992 | //As of 2.1.0, support just passing the text, to reinforce
993 | //fromText only being called once per resource. Still
994 | //support old style of passing moduleName but discard
995 | //that moduleName in favor of the internal ref.
996 | if (textAlt) {
997 | text = textAlt;
998 | }
999 |
1000 | //Turn off interactive script matching for IE for any define
1001 | //calls in the text, then turn it back on at the end.
1002 | if (hasInteractive) {
1003 | useInteractive = false;
1004 | }
1005 |
1006 | //Prime the system by creating a module instance for
1007 | //it.
1008 | getModule(moduleMap);
1009 |
1010 | //Transfer any config to this other module.
1011 | if (hasProp(config.config, id)) {
1012 | config.config[moduleName] = config.config[id];
1013 | }
1014 |
1015 | try {
1016 | req.exec(text);
1017 | } catch (e) {
1018 | return onError(makeError('fromtexteval',
1019 | 'fromText eval for ' + id +
1020 | ' failed: ' + e,
1021 | e,
1022 | [id]));
1023 | }
1024 |
1025 | if (hasInteractive) {
1026 | useInteractive = true;
1027 | }
1028 |
1029 | //Mark this as a dependency for the plugin
1030 | //resource
1031 | this.depMaps.push(moduleMap);
1032 |
1033 | //Support anonymous modules.
1034 | context.completeLoad(moduleName);
1035 |
1036 | //Bind the value of that module to the value for this
1037 | //resource ID.
1038 | localRequire([moduleName], load);
1039 | });
1040 |
1041 | //Use parentName here since the plugin's name is not reliable,
1042 | //could be some weird string with no path that actually wants to
1043 | //reference the parentName's path.
1044 | plugin.load(map.name, localRequire, load, config);
1045 | }));
1046 |
1047 | context.enable(pluginMap, this);
1048 | this.pluginMaps[pluginMap.id] = pluginMap;
1049 | },
1050 |
1051 | enable: function () {
1052 | this.enabled = true;
1053 |
1054 | //Set flag mentioning that the module is enabling,
1055 | //so that immediate calls to the defined callbacks
1056 | //for dependencies do not trigger inadvertent load
1057 | //with the depCount still being zero.
1058 | this.enabling = true;
1059 |
1060 | //Enable each dependency
1061 | each(this.depMaps, bind(this, function (depMap, i) {
1062 | var id, mod, handler;
1063 |
1064 | if (typeof depMap === 'string') {
1065 | //Dependency needs to be converted to a depMap
1066 | //and wired up to this module.
1067 | depMap = makeModuleMap(depMap,
1068 | (this.map.isDefine ? this.map : this.map.parentMap),
1069 | false,
1070 | !this.skipMap);
1071 | this.depMaps[i] = depMap;
1072 |
1073 | handler = getOwn(handlers, depMap.id);
1074 |
1075 | if (handler) {
1076 | this.depExports[i] = handler(this);
1077 | return;
1078 | }
1079 |
1080 | this.depCount += 1;
1081 |
1082 | on(depMap, 'defined', bind(this, function (depExports) {
1083 | this.defineDep(i, depExports);
1084 | this.check();
1085 | }));
1086 |
1087 | if (this.errback) {
1088 | on(depMap, 'error', this.errback);
1089 | }
1090 | }
1091 |
1092 | id = depMap.id;
1093 | mod = registry[id];
1094 |
1095 | //Skip special modules like 'require', 'exports', 'module'
1096 | //Also, don't call enable if it is already enabled,
1097 | //important in circular dependency cases.
1098 | if (!hasProp(handlers, id) && mod && !mod.enabled) {
1099 | context.enable(depMap, this);
1100 | }
1101 | }));
1102 |
1103 | //Enable each plugin that is used in
1104 | //a dependency
1105 | eachProp(this.pluginMaps, bind(this, function (pluginMap) {
1106 | var mod = getOwn(registry, pluginMap.id);
1107 | if (mod && !mod.enabled) {
1108 | context.enable(pluginMap, this);
1109 | }
1110 | }));
1111 |
1112 | this.enabling = false;
1113 |
1114 | this.check();
1115 | },
1116 |
1117 | on: function (name, cb) {
1118 | var cbs = this.events[name];
1119 | if (!cbs) {
1120 | cbs = this.events[name] = [];
1121 | }
1122 | cbs.push(cb);
1123 | },
1124 |
1125 | emit: function (name, evt) {
1126 | each(this.events[name], function (cb) {
1127 | cb(evt);
1128 | });
1129 | if (name === 'error') {
1130 | //Now that the error handler was triggered, remove
1131 | //the listeners, since this broken Module instance
1132 | //can stay around for a while in the registry.
1133 | delete this.events[name];
1134 | }
1135 | }
1136 | };
1137 |
1138 | function callGetModule(args) {
1139 | //Skip modules already defined.
1140 | if (!hasProp(defined, args[0])) {
1141 | getModule(makeModuleMap(args[0], null, true)).init(args[1], args[2]);
1142 | }
1143 | }
1144 |
1145 | function removeListener(node, func, name, ieName) {
1146 | //Favor detachEvent because of IE9
1147 | //issue, see attachEvent/addEventListener comment elsewhere
1148 | //in this file.
1149 | if (node.detachEvent && !isOpera) {
1150 | //Probably IE. If not it will throw an error, which will be
1151 | //useful to know.
1152 | if (ieName) {
1153 | node.detachEvent(ieName, func);
1154 | }
1155 | } else {
1156 | node.removeEventListener(name, func, false);
1157 | }
1158 | }
1159 |
1160 | /**
1161 | * Given an event from a script node, get the requirejs info from it,
1162 | * and then removes the event listeners on the node.
1163 | * @param {Event} evt
1164 | * @returns {Object}
1165 | */
1166 | function getScriptData(evt) {
1167 | //Using currentTarget instead of target for Firefox 2.0's sake. Not
1168 | //all old browsers will be supported, but this one was easy enough
1169 | //to support and still makes sense.
1170 | var node = evt.currentTarget || evt.srcElement;
1171 |
1172 | //Remove the listeners once here.
1173 | removeListener(node, context.onScriptLoad, 'load', 'onreadystatechange');
1174 | removeListener(node, context.onScriptError, 'error');
1175 |
1176 | return {
1177 | node: node,
1178 | id: node && node.getAttribute('data-requiremodule')
1179 | };
1180 | }
1181 |
1182 | function intakeDefines() {
1183 | var args;
1184 |
1185 | //Any defined modules in the global queue, intake them now.
1186 | takeGlobalQueue();
1187 |
1188 | //Make sure any remaining defQueue items get properly processed.
1189 | while (defQueue.length) {
1190 | args = defQueue.shift();
1191 | if (args[0] === null) {
1192 | return onError(makeError('mismatch', 'Mismatched anonymous define() module: ' + args[args.length - 1]));
1193 | } else {
1194 | //args are id, deps, factory. Should be normalized by the
1195 | //define() function.
1196 | callGetModule(args);
1197 | }
1198 | }
1199 | }
1200 |
1201 | context = {
1202 | config: config,
1203 | contextName: contextName,
1204 | registry: registry,
1205 | defined: defined,
1206 | urlFetched: urlFetched,
1207 | defQueue: defQueue,
1208 | Module: Module,
1209 | makeModuleMap: makeModuleMap,
1210 | nextTick: req.nextTick,
1211 |
1212 | /**
1213 | * Set a configuration for the context.
1214 | * @param {Object} cfg config object to integrate.
1215 | */
1216 | configure: function (cfg) {
1217 | //Make sure the baseUrl ends in a slash.
1218 | if (cfg.baseUrl) {
1219 | if (cfg.baseUrl.charAt(cfg.baseUrl.length - 1) !== '/') {
1220 | cfg.baseUrl += '/';
1221 | }
1222 | }
1223 |
1224 | //Save off the paths and packages since they require special processing,
1225 | //they are additive.
1226 | var pkgs = config.pkgs,
1227 | shim = config.shim,
1228 | objs = {
1229 | paths: true,
1230 | config: true,
1231 | map: true
1232 | };
1233 |
1234 | eachProp(cfg, function (value, prop) {
1235 | if (objs[prop]) {
1236 | if (prop === 'map') {
1237 | mixin(config[prop], value, true, true);
1238 | } else {
1239 | mixin(config[prop], value, true);
1240 | }
1241 | } else {
1242 | config[prop] = value;
1243 | }
1244 | });
1245 |
1246 | //Merge shim
1247 | if (cfg.shim) {
1248 | eachProp(cfg.shim, function (value, id) {
1249 | //Normalize the structure
1250 | if (isArray(value)) {
1251 | value = {
1252 | deps: value
1253 | };
1254 | }
1255 | if ((value.exports || value.init) && !value.exportsFn) {
1256 | value.exportsFn = context.makeShimExports(value);
1257 | }
1258 | shim[id] = value;
1259 | });
1260 | config.shim = shim;
1261 | }
1262 |
1263 | //Adjust packages if necessary.
1264 | if (cfg.packages) {
1265 | each(cfg.packages, function (pkgObj) {
1266 | var location;
1267 |
1268 | pkgObj = typeof pkgObj === 'string' ? { name: pkgObj } : pkgObj;
1269 | location = pkgObj.location;
1270 |
1271 | //Create a brand new object on pkgs, since currentPackages can
1272 | //be passed in again, and config.pkgs is the internal transformed
1273 | //state for all package configs.
1274 | pkgs[pkgObj.name] = {
1275 | name: pkgObj.name,
1276 | location: location || pkgObj.name,
1277 | //Remove leading dot in main, so main paths are normalized,
1278 | //and remove any trailing .js, since different package
1279 | //envs have different conventions: some use a module name,
1280 | //some use a file name.
1281 | main: (pkgObj.main || 'main')
1282 | .replace(currDirRegExp, '')
1283 | .replace(jsSuffixRegExp, '')
1284 | };
1285 | });
1286 |
1287 | //Done with modifications, assing packages back to context config
1288 | config.pkgs = pkgs;
1289 | }
1290 |
1291 | //If there are any "waiting to execute" modules in the registry,
1292 | //update the maps for them, since their info, like URLs to load,
1293 | //may have changed.
1294 | eachProp(registry, function (mod, id) {
1295 | //If module already has init called, since it is too
1296 | //late to modify them, and ignore unnormalized ones
1297 | //since they are transient.
1298 | if (!mod.inited && !mod.map.unnormalized) {
1299 | mod.map = makeModuleMap(id);
1300 | }
1301 | });
1302 |
1303 | //If a deps array or a config callback is specified, then call
1304 | //require with those args. This is useful when require is defined as a
1305 | //config object before require.js is loaded.
1306 | if (cfg.deps || cfg.callback) {
1307 | context.require(cfg.deps || [], cfg.callback);
1308 | }
1309 | },
1310 |
1311 | makeShimExports: function (value) {
1312 | function fn() {
1313 | var ret;
1314 | if (value.init) {
1315 | ret = value.init.apply(global, arguments);
1316 | }
1317 | return ret || (value.exports && getGlobal(value.exports));
1318 | }
1319 | return fn;
1320 | },
1321 |
1322 | makeRequire: function (relMap, options) {
1323 | options = options || {};
1324 |
1325 | function localRequire(deps, callback, errback) {
1326 | var id, map, requireMod;
1327 |
1328 | if (options.enableBuildCallback && callback && isFunction(callback)) {
1329 | callback.__requireJsBuild = true;
1330 | }
1331 |
1332 | if (typeof deps === 'string') {
1333 | if (isFunction(callback)) {
1334 | //Invalid call
1335 | return onError(makeError('requireargs', 'Invalid require call'), errback);
1336 | }
1337 |
1338 | //If require|exports|module are requested, get the
1339 | //value for them from the special handlers. Caveat:
1340 | //this only works while module is being defined.
1341 | if (relMap && hasProp(handlers, deps)) {
1342 | return handlers[deps](registry[relMap.id]);
1343 | }
1344 |
1345 | //Synchronous access to one module. If require.get is
1346 | //available (as in the Node adapter), prefer that.
1347 | if (req.get) {
1348 | return req.get(context, deps, relMap);
1349 | }
1350 |
1351 | //Normalize module name, if it contains . or ..
1352 | map = makeModuleMap(deps, relMap, false, true);
1353 | id = map.id;
1354 |
1355 | if (!hasProp(defined, id)) {
1356 | return onError(makeError('notloaded', 'Module name "' +
1357 | id +
1358 | '" has not been loaded yet for context: ' +
1359 | contextName +
1360 | (relMap ? '' : '. Use require([])')));
1361 | }
1362 | return defined[id];
1363 | }
1364 |
1365 | //Grab defines waiting in the global queue.
1366 | intakeDefines();
1367 |
1368 | //Mark all the dependencies as needing to be loaded.
1369 | context.nextTick(function () {
1370 | //Some defines could have been added since the
1371 | //require call, collect them.
1372 | intakeDefines();
1373 |
1374 | requireMod = getModule(makeModuleMap(null, relMap));
1375 |
1376 | //Store if map config should be applied to this require
1377 | //call for dependencies.
1378 | requireMod.skipMap = options.skipMap;
1379 |
1380 | requireMod.init(deps, callback, errback, {
1381 | enabled: true
1382 | });
1383 |
1384 | checkLoaded();
1385 | });
1386 |
1387 | return localRequire;
1388 | }
1389 |
1390 | mixin(localRequire, {
1391 | isBrowser: isBrowser,
1392 |
1393 | /**
1394 | * Converts a module name + .extension into an URL path.
1395 | * *Requires* the use of a module name. It does not support using
1396 | * plain URLs like nameToUrl.
1397 | */
1398 | toUrl: function (moduleNamePlusExt) {
1399 | var ext, url,
1400 | index = moduleNamePlusExt.lastIndexOf('.'),
1401 | segment = moduleNamePlusExt.split('/')[0],
1402 | isRelative = segment === '.' || segment === '..';
1403 |
1404 | //Have a file extension alias, and it is not the
1405 | //dots from a relative path.
1406 | if (index !== -1 && (!isRelative || index > 1)) {
1407 | ext = moduleNamePlusExt.substring(index, moduleNamePlusExt.length);
1408 | moduleNamePlusExt = moduleNamePlusExt.substring(0, index);
1409 | }
1410 |
1411 | url = context.nameToUrl(normalize(moduleNamePlusExt,
1412 | relMap && relMap.id, true), ext || '.fake');
1413 | return ext ? url : url.substring(0, url.length - 5);
1414 | },
1415 |
1416 | defined: function (id) {
1417 | return hasProp(defined, makeModuleMap(id, relMap, false, true).id);
1418 | },
1419 |
1420 | specified: function (id) {
1421 | id = makeModuleMap(id, relMap, false, true).id;
1422 | return hasProp(defined, id) || hasProp(registry, id);
1423 | }
1424 | });
1425 |
1426 | //Only allow undef on top level require calls
1427 | if (!relMap) {
1428 | localRequire.undef = function (id) {
1429 | //Bind any waiting define() calls to this context,
1430 | //fix for #408
1431 | takeGlobalQueue();
1432 |
1433 | var map = makeModuleMap(id, relMap, true),
1434 | mod = getOwn(registry, id);
1435 |
1436 | delete defined[id];
1437 | delete urlFetched[map.url];
1438 | delete undefEvents[id];
1439 |
1440 | if (mod) {
1441 | //Hold on to listeners in case the
1442 | //module will be attempted to be reloaded
1443 | //using a different config.
1444 | if (mod.events.defined) {
1445 | undefEvents[id] = mod.events;
1446 | }
1447 |
1448 | cleanRegistry(id);
1449 | }
1450 | };
1451 | }
1452 |
1453 | return localRequire;
1454 | },
1455 |
1456 | /**
1457 | * Called to enable a module if it is still in the registry
1458 | * awaiting enablement. A second arg, parent, the parent module,
1459 | * is passed in for context, when this method is overriden by
1460 | * the optimizer. Not shown here to keep code compact.
1461 | */
1462 | enable: function (depMap) {
1463 | var mod = getOwn(registry, depMap.id);
1464 | if (mod) {
1465 | getModule(depMap).enable();
1466 | }
1467 | },
1468 |
1469 | /**
1470 | * Internal method used by environment adapters to complete a load event.
1471 | * A load event could be a script load or just a load pass from a synchronous
1472 | * load call.
1473 | * @param {String} moduleName the name of the module to potentially complete.
1474 | */
1475 | completeLoad: function (moduleName) {
1476 | var found, args, mod,
1477 | shim = getOwn(config.shim, moduleName) || {},
1478 | shExports = shim.exports;
1479 |
1480 | takeGlobalQueue();
1481 |
1482 | while (defQueue.length) {
1483 | args = defQueue.shift();
1484 | if (args[0] === null) {
1485 | args[0] = moduleName;
1486 | //If already found an anonymous module and bound it
1487 | //to this name, then this is some other anon module
1488 | //waiting for its completeLoad to fire.
1489 | if (found) {
1490 | break;
1491 | }
1492 | found = true;
1493 | } else if (args[0] === moduleName) {
1494 | //Found matching define call for this script!
1495 | found = true;
1496 | }
1497 |
1498 | callGetModule(args);
1499 | }
1500 |
1501 | //Do this after the cycle of callGetModule in case the result
1502 | //of those calls/init calls changes the registry.
1503 | mod = getOwn(registry, moduleName);
1504 |
1505 | if (!found && !hasProp(defined, moduleName) && mod && !mod.inited) {
1506 | if (config.enforceDefine && (!shExports || !getGlobal(shExports))) {
1507 | if (hasPathFallback(moduleName)) {
1508 | return;
1509 | } else {
1510 | return onError(makeError('nodefine',
1511 | 'No define call for ' + moduleName,
1512 | null,
1513 | [moduleName]));
1514 | }
1515 | } else {
1516 | //A script that does not call define(), so just simulate
1517 | //the call for it.
1518 | callGetModule([moduleName, (shim.deps || []), shim.exportsFn]);
1519 | }
1520 | }
1521 |
1522 | checkLoaded();
1523 | },
1524 |
1525 | /**
1526 | * Converts a module name to a file path. Supports cases where
1527 | * moduleName may actually be just an URL.
1528 | * Note that it **does not** call normalize on the moduleName,
1529 | * it is assumed to have already been normalized. This is an
1530 | * internal API, not a public one. Use toUrl for the public API.
1531 | */
1532 | nameToUrl: function (moduleName, ext) {
1533 | var paths, pkgs, pkg, pkgPath, syms, i, parentModule, url,
1534 | parentPath;
1535 |
1536 | //If a colon is in the URL, it indicates a protocol is used and it is just
1537 | //an URL to a file, or if it starts with a slash, contains a query arg (i.e. ?)
1538 | //or ends with .js, then assume the user meant to use an url and not a module id.
1539 | //The slash is important for protocol-less URLs as well as full paths.
1540 | if (req.jsExtRegExp.test(moduleName)) {
1541 | //Just a plain path, not module name lookup, so just return it.
1542 | //Add extension if it is included. This is a bit wonky, only non-.js things pass
1543 | //an extension, this method probably needs to be reworked.
1544 | url = moduleName + (ext || '');
1545 | } else {
1546 | //A module that needs to be converted to a path.
1547 | paths = config.paths;
1548 | pkgs = config.pkgs;
1549 |
1550 | syms = moduleName.split('/');
1551 | //For each module name segment, see if there is a path
1552 | //registered for it. Start with most specific name
1553 | //and work up from it.
1554 | for (i = syms.length; i > 0; i -= 1) {
1555 | parentModule = syms.slice(0, i).join('/');
1556 | pkg = getOwn(pkgs, parentModule);
1557 | parentPath = getOwn(paths, parentModule);
1558 | if (parentPath) {
1559 | //If an array, it means there are a few choices,
1560 | //Choose the one that is desired
1561 | if (isArray(parentPath)) {
1562 | parentPath = parentPath[0];
1563 | }
1564 | syms.splice(0, i, parentPath);
1565 | break;
1566 | } else if (pkg) {
1567 | //If module name is just the package name, then looking
1568 | //for the main module.
1569 | if (moduleName === pkg.name) {
1570 | pkgPath = pkg.location + '/' + pkg.main;
1571 | } else {
1572 | pkgPath = pkg.location;
1573 | }
1574 | syms.splice(0, i, pkgPath);
1575 | break;
1576 | }
1577 | }
1578 |
1579 | //Join the path parts together, then figure out if baseUrl is needed.
1580 | url = syms.join('/');
1581 | url += (ext || (/\?/.test(url) ? '' : '.js'));
1582 | url = (url.charAt(0) === '/' || url.match(/^[\w\+\.\-]+:/) ? '' : config.baseUrl) + url;
1583 | }
1584 |
1585 | return config.urlArgs ? url +
1586 | ((url.indexOf('?') === -1 ? '?' : '&') +
1587 | config.urlArgs) : url;
1588 | },
1589 |
1590 | //Delegates to req.load. Broken out as a separate function to
1591 | //allow overriding in the optimizer.
1592 | load: function (id, url) {
1593 | req.load(context, id, url);
1594 | },
1595 |
1596 | /**
1597 | * Executes a module callack function. Broken out as a separate function
1598 | * solely to allow the build system to sequence the files in the built
1599 | * layer in the right sequence.
1600 | *
1601 | * @private
1602 | */
1603 | execCb: function (name, callback, args, exports) {
1604 | return callback.apply(exports, args);
1605 | },
1606 |
1607 | /**
1608 | * callback for script loads, used to check status of loading.
1609 | *
1610 | * @param {Event} evt the event from the browser for the script
1611 | * that was loaded.
1612 | */
1613 | onScriptLoad: function (evt) {
1614 | //Using currentTarget instead of target for Firefox 2.0's sake. Not
1615 | //all old browsers will be supported, but this one was easy enough
1616 | //to support and still makes sense.
1617 | if (evt.type === 'load' ||
1618 | (readyRegExp.test((evt.currentTarget || evt.srcElement).readyState))) {
1619 | //Reset interactive script so a script node is not held onto for
1620 | //to long.
1621 | interactiveScript = null;
1622 |
1623 | //Pull out the name of the module and the context.
1624 | var data = getScriptData(evt);
1625 | context.completeLoad(data.id);
1626 | }
1627 | },
1628 |
1629 | /**
1630 | * Callback for script errors.
1631 | */
1632 | onScriptError: function (evt) {
1633 | var data = getScriptData(evt);
1634 | if (!hasPathFallback(data.id)) {
1635 | return onError(makeError('scripterror', 'Script error', evt, [data.id]));
1636 | }
1637 | }
1638 | };
1639 |
1640 | context.require = context.makeRequire();
1641 | return context;
1642 | }
1643 |
1644 | /**
1645 | * Main entry point.
1646 | *
1647 | * If the only argument to require is a string, then the module that
1648 | * is represented by that string is fetched for the appropriate context.
1649 | *
1650 | * If the first argument is an array, then it will be treated as an array
1651 | * of dependency string names to fetch. An optional function callback can
1652 | * be specified to execute when all of those dependencies are available.
1653 | *
1654 | * Make a local req variable to help Caja compliance (it assumes things
1655 | * on a require that are not standardized), and to give a short
1656 | * name for minification/local scope use.
1657 | */
1658 | req = requirejs = function (deps, callback, errback, optional) {
1659 |
1660 | //Find the right context, use default
1661 | var context, config,
1662 | contextName = defContextName;
1663 |
1664 | // Determine if have config object in the call.
1665 | if (!isArray(deps) && typeof deps !== 'string') {
1666 | // deps is a config object
1667 | config = deps;
1668 | if (isArray(callback)) {
1669 | // Adjust args if there are dependencies
1670 | deps = callback;
1671 | callback = errback;
1672 | errback = optional;
1673 | } else {
1674 | deps = [];
1675 | }
1676 | }
1677 |
1678 | if (config && config.context) {
1679 | contextName = config.context;
1680 | }
1681 |
1682 | context = getOwn(contexts, contextName);
1683 | if (!context) {
1684 | context = contexts[contextName] = req.s.newContext(contextName);
1685 | }
1686 |
1687 | if (config) {
1688 | context.configure(config);
1689 | }
1690 |
1691 | return context.require(deps, callback, errback);
1692 | };
1693 |
1694 | /**
1695 | * Support require.config() to make it easier to cooperate with other
1696 | * AMD loaders on globally agreed names.
1697 | */
1698 | req.config = function (config) {
1699 | return req(config);
1700 | };
1701 |
1702 | /**
1703 | * Execute something after the current tick
1704 | * of the event loop. Override for other envs
1705 | * that have a better solution than setTimeout.
1706 | * @param {Function} fn function to execute later.
1707 | */
1708 | req.nextTick = typeof setTimeout !== 'undefined' ? function (fn) {
1709 | setTimeout(fn, 4);
1710 | } : function (fn) { fn(); };
1711 |
1712 | /**
1713 | * Export require as a global, but only if it does not already exist.
1714 | */
1715 | if (!require) {
1716 | require = req;
1717 | }
1718 |
1719 | req.version = version;
1720 |
1721 | //Used to filter out dependencies that are already paths.
1722 | req.jsExtRegExp = /^\/|:|\?|\.js$/;
1723 | req.isBrowser = isBrowser;
1724 | s = req.s = {
1725 | contexts: contexts,
1726 | newContext: newContext
1727 | };
1728 |
1729 | //Create default context.
1730 | req({});
1731 |
1732 | //Exports some context-sensitive methods on global require.
1733 | each([
1734 | 'toUrl',
1735 | 'undef',
1736 | 'defined',
1737 | 'specified'
1738 | ], function (prop) {
1739 | //Reference from contexts instead of early binding to default context,
1740 | //so that during builds, the latest instance of the default context
1741 | //with its config gets used.
1742 | req[prop] = function () {
1743 | var ctx = contexts[defContextName];
1744 | return ctx.require[prop].apply(ctx, arguments);
1745 | };
1746 | });
1747 |
1748 | if (isBrowser) {
1749 | head = s.head = document.getElementsByTagName('head')[0];
1750 | //If BASE tag is in play, using appendChild is a problem for IE6.
1751 | //When that browser dies, this can be removed. Details in this jQuery bug:
1752 | //http://dev.jquery.com/ticket/2709
1753 | baseElement = document.getElementsByTagName('base')[0];
1754 | if (baseElement) {
1755 | head = s.head = baseElement.parentNode;
1756 | }
1757 | }
1758 |
1759 | /**
1760 | * Any errors that require explicitly generates will be passed to this
1761 | * function. Intercept/override it if you want custom error handling.
1762 | * @param {Error} err the error object.
1763 | */
1764 | req.onError = function (err) {
1765 | throw err;
1766 | };
1767 |
1768 | /**
1769 | * Does the request to load a module for the browser case.
1770 | * Make this a separate function to allow other environments
1771 | * to override it.
1772 | *
1773 | * @param {Object} context the require context to find state.
1774 | * @param {String} moduleName the name of the module.
1775 | * @param {Object} url the URL to the module.
1776 | */
1777 | req.load = function (context, moduleName, url) {
1778 | var config = (context && context.config) || {},
1779 | node;
1780 | if (isBrowser) {
1781 | //In the browser so use a script tag
1782 | node = config.xhtml ?
1783 | document.createElementNS('http://www.w3.org/1999/xhtml', 'html:script') :
1784 | document.createElement('script');
1785 | node.type = config.scriptType || 'text/javascript';
1786 | node.charset = 'utf-8';
1787 | node.async = true;
1788 |
1789 | node.setAttribute('data-requirecontext', context.contextName);
1790 | node.setAttribute('data-requiremodule', moduleName);
1791 |
1792 | //Set up load listener. Test attachEvent first because IE9 has
1793 | //a subtle issue in its addEventListener and script onload firings
1794 | //that do not match the behavior of all other browsers with
1795 | //addEventListener support, which fire the onload event for a
1796 | //script right after the script execution. See:
1797 | //https://connect.microsoft.com/IE/feedback/details/648057/script-onload-event-is-not-fired-immediately-after-script-execution
1798 | //UNFORTUNATELY Opera implements attachEvent but does not follow the script
1799 | //script execution mode.
1800 | if (node.attachEvent &&
1801 | //Check if node.attachEvent is artificially added by custom script or
1802 | //natively supported by browser
1803 | //read https://github.com/jrburke/requirejs/issues/187
1804 | //if we can NOT find [native code] then it must NOT natively supported.
1805 | //in IE8, node.attachEvent does not have toString()
1806 | //Note the test for "[native code" with no closing brace, see:
1807 | //https://github.com/jrburke/requirejs/issues/273
1808 | !(node.attachEvent.toString && node.attachEvent.toString().indexOf('[native code') < 0) &&
1809 | !isOpera) {
1810 | //Probably IE. IE (at least 6-8) do not fire
1811 | //script onload right after executing the script, so
1812 | //we cannot tie the anonymous define call to a name.
1813 | //However, IE reports the script as being in 'interactive'
1814 | //readyState at the time of the define call.
1815 | useInteractive = true;
1816 |
1817 | node.attachEvent('onreadystatechange', context.onScriptLoad);
1818 | //It would be great to add an error handler here to catch
1819 | //404s in IE9+. However, onreadystatechange will fire before
1820 | //the error handler, so that does not help. If addEvenListener
1821 | //is used, then IE will fire error before load, but we cannot
1822 | //use that pathway given the connect.microsoft.com issue
1823 | //mentioned above about not doing the 'script execute,
1824 | //then fire the script load event listener before execute
1825 | //next script' that other browsers do.
1826 | //Best hope: IE10 fixes the issues,
1827 | //and then destroys all installs of IE 6-9.
1828 | //node.attachEvent('onerror', context.onScriptError);
1829 | } else {
1830 | node.addEventListener('load', context.onScriptLoad, false);
1831 | node.addEventListener('error', context.onScriptError, false);
1832 | }
1833 | node.src = url;
1834 |
1835 | //For some cache cases in IE 6-8, the script executes before the end
1836 | //of the appendChild execution, so to tie an anonymous define
1837 | //call to the module name (which is stored on the node), hold on
1838 | //to a reference to this node, but clear after the DOM insertion.
1839 | currentlyAddingScript = node;
1840 | if (baseElement) {
1841 | head.insertBefore(node, baseElement);
1842 | } else {
1843 | head.appendChild(node);
1844 | }
1845 | currentlyAddingScript = null;
1846 |
1847 | return node;
1848 | } else if (isWebWorker) {
1849 | //In a web worker, use importScripts. This is not a very
1850 | //efficient use of importScripts, importScripts will block until
1851 | //its script is downloaded and evaluated. However, if web workers
1852 | //are in play, the expectation that a build has been done so that
1853 | //only one script needs to be loaded anyway. This may need to be
1854 | //reevaluated if other use cases become common.
1855 | importScripts(url);
1856 |
1857 | //Account for anonymous modules
1858 | context.completeLoad(moduleName);
1859 | }
1860 | };
1861 |
1862 | function getInteractiveScript() {
1863 | if (interactiveScript && interactiveScript.readyState === 'interactive') {
1864 | return interactiveScript;
1865 | }
1866 |
1867 | eachReverse(scripts(), function (script) {
1868 | if (script.readyState === 'interactive') {
1869 | return (interactiveScript = script);
1870 | }
1871 | });
1872 | return interactiveScript;
1873 | }
1874 |
1875 | //Look for a data-main script attribute, which could also adjust the baseUrl.
1876 | if (isBrowser) {
1877 | //Figure out baseUrl. Get it from the script tag with require.js in it.
1878 | eachReverse(scripts(), function (script) {
1879 | //Set the 'head' where we can append children by
1880 | //using the script's parent.
1881 | if (!head) {
1882 | head = script.parentNode;
1883 | }
1884 |
1885 | //Look for a data-main attribute to set main script for the page
1886 | //to load. If it is there, the path to data main becomes the
1887 | //baseUrl, if it is not already set.
1888 | dataMain = script.getAttribute('data-main');
1889 | if (dataMain) {
1890 | //Set final baseUrl if there is not already an explicit one.
1891 | if (!cfg.baseUrl) {
1892 | //Pull off the directory of data-main for use as the
1893 | //baseUrl.
1894 | src = dataMain.split('/');
1895 | mainScript = src.pop();
1896 | subPath = src.length ? src.join('/') + '/' : './';
1897 |
1898 | cfg.baseUrl = subPath;
1899 | dataMain = mainScript;
1900 | }
1901 |
1902 | //Strip off any trailing .js since dataMain is now
1903 | //like a module name.
1904 | dataMain = dataMain.replace(jsSuffixRegExp, '');
1905 |
1906 | //Put the data-main script in the files to load.
1907 | cfg.deps = cfg.deps ? cfg.deps.concat(dataMain) : [dataMain];
1908 |
1909 | return true;
1910 | }
1911 | });
1912 | }
1913 |
1914 | /**
1915 | * The function that handles definitions of modules. Differs from
1916 | * require() in that a string for the module should be the first argument,
1917 | * and the function to execute after dependencies are loaded should
1918 | * return a value to define the module corresponding to the first argument's
1919 | * name.
1920 | */
1921 | define = function (name, deps, callback) {
1922 | var node, context;
1923 |
1924 | //Allow for anonymous modules
1925 | if (typeof name !== 'string') {
1926 | //Adjust args appropriately
1927 | callback = deps;
1928 | deps = name;
1929 | name = null;
1930 | }
1931 |
1932 | //This module may not have dependencies
1933 | if (!isArray(deps)) {
1934 | callback = deps;
1935 | deps = [];
1936 | }
1937 |
1938 | //If no name, and callback is a function, then figure out if it a
1939 | //CommonJS thing with dependencies.
1940 | if (!deps.length && isFunction(callback)) {
1941 | //Remove comments from the callback string,
1942 | //look for require calls, and pull them into the dependencies,
1943 | //but only if there are function args.
1944 | if (callback.length) {
1945 | callback
1946 | .toString()
1947 | .replace(commentRegExp, '')
1948 | .replace(cjsRequireRegExp, function (match, dep) {
1949 | deps.push(dep);
1950 | });
1951 |
1952 | //May be a CommonJS thing even without require calls, but still
1953 | //could use exports, and module. Avoid doing exports and module
1954 | //work though if it just needs require.
1955 | //REQUIRES the function to expect the CommonJS variables in the
1956 | //order listed below.
1957 | deps = (callback.length === 1 ? ['require'] : ['require', 'exports', 'module']).concat(deps);
1958 | }
1959 | }
1960 |
1961 | //If in IE 6-8 and hit an anonymous define() call, do the interactive
1962 | //work.
1963 | if (useInteractive) {
1964 | node = currentlyAddingScript || getInteractiveScript();
1965 | if (node) {
1966 | if (!name) {
1967 | name = node.getAttribute('data-requiremodule');
1968 | }
1969 | context = contexts[node.getAttribute('data-requirecontext')];
1970 | }
1971 | }
1972 |
1973 | //Always save off evaluating the def call until the script onload handler.
1974 | //This allows multiple modules to be in a file without prematurely
1975 | //tracing dependencies, and allows for anonymous module support,
1976 | //where the module name is not known until the script onload event
1977 | //occurs. If no context, use the global queue, and get it processed
1978 | //in the onscript load callback.
1979 | (context ? context.defQueue : globalDefQueue).push([name, deps, callback]);
1980 | };
1981 |
1982 | define.amd = {
1983 | jQuery: true
1984 | };
1985 |
1986 |
1987 | /**
1988 | * Executes the text. Normally just uses eval, but can be modified
1989 | * to use a better, environment-specific call. Only used for transpiling
1990 | * loader plugins, not for plain JS modules.
1991 | * @param {String} text the text to execute/evaluate.
1992 | */
1993 | req.exec = function (text) {
1994 | /*jslint evil: true */
1995 | return eval(text);
1996 | };
1997 |
1998 | //Set up with config info.
1999 | req(cfg);
2000 | }(this));
2001 |
2002 | var jam = {
2003 | "packages": [
2004 | {
2005 | "name": "catiline",
2006 | "location": "jam/catiline",
2007 | "main": "dist/catiline.js"
2008 | },
2009 | {
2010 | "name": "shp",
2011 | "location": "jam/shp",
2012 | "main": "dist/shp.js"
2013 | },
2014 | {
2015 | "name": "spin-js",
2016 | "location": "jam/spin-js",
2017 | "main": "spin.js"
2018 | }
2019 | ],
2020 | "version": "0.2.17",
2021 | "shim": {}
2022 | };
2023 |
2024 | if (typeof require !== "undefined" && require.config) {
2025 | require.config({
2026 | "packages": [
2027 | {
2028 | "name": "catiline",
2029 | "location": "jam/catiline",
2030 | "main": "dist/catiline.js"
2031 | },
2032 | {
2033 | "name": "shp",
2034 | "location": "jam/shp",
2035 | "main": "dist/shp.js"
2036 | },
2037 | {
2038 | "name": "spin-js",
2039 | "location": "jam/spin-js",
2040 | "main": "spin.js"
2041 | }
2042 | ],
2043 | "shim": {}
2044 | });
2045 | }
2046 | else {
2047 | var require = {
2048 | "packages": [
2049 | {
2050 | "name": "catiline",
2051 | "location": "jam/catiline",
2052 | "main": "dist/catiline.js"
2053 | },
2054 | {
2055 | "name": "shp",
2056 | "location": "jam/shp",
2057 | "main": "dist/shp.js"
2058 | },
2059 | {
2060 | "name": "spin-js",
2061 | "location": "jam/spin-js",
2062 | "main": "spin.js"
2063 | }
2064 | ],
2065 | "shim": {}
2066 | };
2067 | }
2068 |
2069 | if (typeof exports !== "undefined" && typeof module !== "undefined") {
2070 | module.exports = jam;
2071 | }
--------------------------------------------------------------------------------