diff --git a/.jshintrc b/.jshintrc index 908cbc1..596aeaf 100644 --- a/.jshintrc +++ b/.jshintrc @@ -1,52 +1,40 @@ { - /* - * ENVIRONMENTS - * ================= - */ - - // Define globals exposed by modern browsers. - "browser": true, - - // Define globals exposed by jQuery. - "jquery": true, - - "globals": {"L": false}, - - /* - * ENFORCING OPTIONS - * ================= - */ - - // Force all variable names to use either camelCase style or UPPER_CASE - // with underscores. - "camelcase": true, - - // Prohibit use of == and != in favor of === and !==. - "eqeqeq": true, - - // Suppress warnings about == null comparisons. - "eqnull": true, - - // Enforce tab width of 2 spaces. - "indent": 2, - - "smarttabs": true, - - // Prohibit use of a variable before it is defined. - "latedef": true, - - // Require capitalized names for constructor functions. - "newcap": true, - - // Enforce use of single quotation marks for strings. - "quotmark": "single", - - // Prohibit trailing whitespace. - "trailing": true, - - // Prohibit use of explicitly undeclared variables. - "undef": true, - - // Warn when variables are defined but never used. - "unused": true + // environment + "browser": true, + "node": true, + "globals": { + "L": true, + "define": true + }, + "strict": false, + "es3": true, + + // code style + "bitwise": true, + "camelcase": true, + "curly": true, + "eqeqeq": true, + "forin": false, + "immed": true, + "latedef": true, + "newcap": true, + "noarg": true, + "noempty": true, + "nonew": true, + "undef": true, + "unused": true, + "quotmark": "single", + + // whitespace + "indent": 4, + "trailing": true, + "white": true, + "smarttabs": true, + "maxlen": 120 + + // code simplicity - not enforced but nice to check from time to time + // "maxstatements": 20, + // "maxcomplexity": 5 + // "maxparams": 4, + // "maxdepth": 4 } diff --git a/Gruntfile.js b/Gruntfile.js index 2f75376..71cf0e5 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -1,35 +1,61 @@ -/*global module:false*/ -module.exports = function(grunt) { +module.exports = function (grunt) { - // Project configuration. - grunt.initConfig({ - // Metadata. - pkg: grunt.file.readJSON('package.json') - }); + // Project configuration. + grunt.initConfig({ + // Metadata. + pkg: grunt.file.readJSON('package.json'), + jshint: { + files: [ + 'Gruntfile.js', + 'src/L.Control.Zoomslider.js', + 'spec/**/*.js' + ], + options: { + jshintrc: '.jshintrc', + ignores: [ + 'spec/happen.js' + ] + } + }, + karma: { + options: { + files: [ + 'node_modules/expect.js/expect.js', + 'spec/happen.js', + 'node_modules/leaflet/dist/leaflet-src.js', + 'src/L.Control.Zoomslider.js', + 'spec/before.js', + 'spec/suites/*.js' + ], + singleRun: true, + plugins: [ + 'karma-mocha', + 'karma-chrome-launcher', + 'karma-firefox-launcher', + 'karma-phantomjs-launcher' + ], + frameworks: ['mocha'] - // Test suite - grunt.registerTask('test', function() { - var karma = require('karma'), - testConfig = { configFile: __dirname+'/spec/karma.conf.js' }; + }, + phantomjs: { + browsers: ['PhantomJS'] + }, + firefox: { + browsers: ['Firefox'] + }, + chrome : { + browsers: ['Chrome'] + }, + all: { + browsers: ['Chrome', 'Firefox', 'PhantomJS'] + } + } + }); - this.async(); - testConfig.singleRun = true; - testConfig.autoWatch = false; - testConfig.browsers = ['PhantomJS']; - if (isArgv('--chrome')) { - testConfig.browsers.push('Chrome'); - } - if (isArgv('--ff')) { - testConfig.browsers.push('Firefox'); - } + grunt.loadNpmTasks('grunt-contrib-jshint'); + grunt.loadNpmTasks('grunt-karma'); - karma.server.start(testConfig); - - function isArgv(optName) { - return process.argv.indexOf(optName) !== -1; - } - }); - - // Default task. - grunt.registerTask('default', ['test']); + // Default task. + grunt.registerTask('default', ['jshint', 'karma:phantomjs']); + grunt.registerTask('test', ['jshint', 'karma:all']); }; diff --git a/LICENSE b/LICENSE index 7595092..a128658 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012, Kartena AB +Copyright (c) 2012-2014, Kartena AB, Mattias Bengtsson All rights reserved. Redistribution and use in source and binary forms, with or without diff --git a/README.md b/README.md index 3599aba..e5bd57a 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -[Leaflet.zoomslider](http://kartena.github.com/Leaflet.zoomslider/) +[Leaflet.zoomslider][1] ================== ## Description @@ -6,19 +6,17 @@ A zoom slider widget for [Leaflet][2] Tested with Chrome, IE 7-9 and Firefox. -Also see [Leaflet.Pancontrol][1] - ## Branches - 0.4 — tracks Leaflet 0.4.x and should be stable. - 0.5 — tracks Leaflet 0.5.x and should be stable. - - 0.6 — tracks Leaflet 0.6.x and should be stable. + - 0.6 — tracks Leaflet 0.6.x and should be stable. + - 0.7 — tracks Leaflet 0.7.x and should be stable. - master — tracks Leaflet master and can be considered unstable (but please file bugs!). ## Tests Install the needed dependencies: ``` -$ git submodule update --init $ npm install ``` @@ -27,13 +25,11 @@ $ npm install $ open spec/index.html # xdg-open on Linux ``` -### Node.js +### Node.js / phantomjs ``` -$ brew install phantomjs # or get it from http://phantomjs.org/ -$ npm install -g grunt-cli -$ grunt test +$ npm install -g grunt-cli phantomjs +$ grunt ``` - -[1]: https://github.com/kartena/Leaflet.Pancontrol +[1]: http://kartena.github.io/Leaflet.zoomslider/ [2]: http://leafletjs.com/ diff --git a/examples/index.html b/examples/index.html index dc98af5..505de84 100644 --- a/examples/index.html +++ b/examples/index.html @@ -3,28 +3,27 @@ - + -
- + - - - diff --git a/examples/lib/Leaflet b/examples/lib/Leaflet deleted file mode 160000 index ae5bc1c..0000000 --- a/examples/lib/Leaflet +++ /dev/null @@ -1 +0,0 @@ -Subproject commit ae5bc1cc82acb9a17b86130b6c891cd68a249243 diff --git a/examples/lib/leaflet-tilejson b/examples/lib/leaflet-tilejson deleted file mode 160000 index db5aaca..0000000 --- a/examples/lib/leaflet-tilejson +++ /dev/null @@ -1 +0,0 @@ -Subproject commit db5aaca621992c4c5d75b05f63b6735197f3e164 diff --git a/examples/markers.html b/examples/markers.html index 919ac56..cc43b67 100644 --- a/examples/markers.html +++ b/examples/markers.html @@ -3,30 +3,33 @@ - + -
- + - - - diff --git a/examples/osm.tilejson.js b/examples/osm.tilejson.js deleted file mode 100644 index 22cc9d9..0000000 --- a/examples/osm.tilejson.js +++ /dev/null @@ -1,17 +0,0 @@ -window.osmTileJSON = { - "tilejson": "2.0.0", - "name": "OpenStreetMap", - "description": "A free editable map of the whole world.", - "version": "1.0.0", - "attribution": "© OpenStreetMap contributors, CC-BY-SA", - "scheme": "xyz", - "tiles": [ - "http://a.tile.openstreetmap.org/${z}/${x}/${y}.png", - "http://b.tile.openstreetmap.org/${z}/${x}/${y}.png", - "http://c.tile.openstreetmap.org/${z}/${x}/${y}.png" - ], - "minzoom": 5, - "maxzoom": 12, - "bounds": [ -180, -85, 180, 85 ], - "center": [ 11.9, 57.7, 8 ] -}; diff --git a/examples/test1.html b/examples/test1.html index 7b3540b..5b0c503 100644 --- a/examples/test1.html +++ b/examples/test1.html @@ -3,23 +3,24 @@ - + -
- - - - - + + + - - - + - - - + - - - diff --git a/examples/touch.html b/examples/touch.html index 8708506..c396206 100644 --- a/examples/touch.html +++ b/examples/touch.html @@ -4,37 +4,24 @@ - + -
- + - - - - diff --git a/package.json b/package.json index 49438b9..993d00b 100644 --- a/package.json +++ b/package.json @@ -1,31 +1,31 @@ { "name": "leaflet.zoomslider", - "version": "0.6.2", - "author": "Mattias Bengtsson ", - "contributors": [ - "Bryan Shelton (https://github.com/bshelton229)", - "Peter Thorin (https://github.com/pthorin)", - "Per Liedman (https://github.com/perliedman)", - "Poisbeau Mathieu (https://github.com/freepius44)", - "Alexis THOMAS (https://github.com/ath0mas)" - ], + "version": "0.7.0", + "author": "Mattias Bengtsson ", + "contributors": [ + "Bryan Shelton (https://github.com/bshelton229)", + "Peter Thorin (https://github.com/pthorin)", + "Per Liedman (https://github.com/perliedman)", + "Poisbeau Mathieu (https://github.com/freepius44)", + "Alexis THOMAS (https://github.com/ath0mas)" + ], "description": "A zoom slider widget for Leaflet", - "dependencies": { - "leaflet": "~0.6.4" - }, + "dependencies": { + "leaflet": "~0.7.1" + }, "devDependencies": { - "jshint": "~1.1.0", "mocha": "~1.9.0", - "karma": "~0.8.0", - "uglify-js": "~2.2.5", - "jake": "~0.5.10", "expect.js": "~0.2.0", - "grunt": "~0.4.1" + "grunt": "~0.4.1", + "grunt-karma": "~0.6.2", + "grunt-contrib-jshint": "~0.7.2", + "karma-mocha": "~0.1.1" }, "main": "src/L.Control.Zoomslider.js", "repository": { "type": "git", "url": "git://github.com/kartena/Leaflet.zoomslider.git" }, - "keywords": ["maps", "leaflet"] + "keywords": ["maps", "leaflet"], + "license": "MIT" } diff --git a/spec/before.js b/spec/before.js index fe9c8d7..648e45c 100644 --- a/spec/before.js +++ b/spec/before.js @@ -1,2 +1,8 @@ +/*exported createMap */ + // put after Leaflet files as imagePath can't be detected in a PhantomJS env -L.Icon.Default.imagePath = "../examples/lib/Leaflet/dist/images"; +L.Icon.Default.imagePath = '../node_modules/Leaflet/dist/images'; + +function createMap(options) { + return L.map(document.createElement('div'), options).setView([0, 0], 16); +} diff --git a/spec/index.html b/spec/index.html index f00cd53..31355fc 100644 --- a/spec/index.html +++ b/spec/index.html @@ -9,11 +9,11 @@ - + - - - + diff --git a/spec/karma.conf.js b/spec/karma.conf.js deleted file mode 100644 index a4b03c8..0000000 --- a/spec/karma.conf.js +++ /dev/null @@ -1,73 +0,0 @@ -// Karma configuration -// Generated on Wed May 01 2013 08:51:27 GMT-0500 (CDT) - - -// base path, that will be used to resolve files and exclude -basePath = ''; - - -// list of files / patterns to load in the browser -files = [ - MOCHA, - MOCHA_ADAPTER, - '../node_modules/expect.js/expect.js', - '../spec/happen.js', - '../examples/lib/Leaflet/dist/leaflet-src.js', - '../src/L.Control.Zoomslider.js', - '../examples/lib/leaflet-tilejson/src/tilejson.js', - '../examples/osm.tilejson.js', - 'before.js', - './**/*_spec.js' -]; - - -// list of files to exclude -exclude = [ - -]; - - -// test results reporter to use -// possible values: 'dots', 'progress', 'junit' -reporters = ['progress']; - - -// web server port -port = 9876; - - -// cli runner port -runnerPort = 9100; - - -// enable / disable colors in the output (reporters and logs) -colors = true; - - -// level of logging -// possible values: LOG_DISABLE || LOG_ERROR || LOG_WARN || LOG_INFO || LOG_DEBUG -logLevel = LOG_INFO; - - -// enable / disable watching file and executing tests whenever any file changes -autoWatch = true; - - -// Start these browsers, currently available: -// - Chrome -// - ChromeCanary -// - Firefox -// - Opera -// - Safari (only Mac) -// - PhantomJS -// - IE (only Windows) -browsers = ['PhantomJS']; - - -// If browser does not capture in given timeout [ms], kill it -captureTimeout = 60000; - - -// Continuous Integration mode -// if true, it capture browsers, run tests and exit -singleRun = false; diff --git a/spec/suites/zooming_spec.js b/spec/suites/zooming_spec.js index db9b6ba..d8d671a 100644 --- a/spec/suites/zooming_spec.js +++ b/spec/suites/zooming_spec.js @@ -1,42 +1,43 @@ -describe('Zooming behavior', function() { +/*global describe, it, beforeEach, expect, happen, createMap */ +describe('Zooming behavior', function () { var map, tileLayer, ui; - beforeEach(function() { - map = L.map(document.createElement('div'), { zoomAnimation: false }).setView([0,0], 16); + beforeEach(function () { + map = createMap({ zoomAnimation: false, zoomsliderControl: true }); tileLayer = L.tileLayer('{x},{y},{z}', { minZoom: 0, maxZoom: 19 }).addTo(map); ui = map.zoomsliderControl._ui; }); - describe('Buttons', function() { - it('Should be able to zoom in', function() { + describe('Buttons', function () { + it('Should be able to zoom in', function () { map.setZoom(16); expect(map.getZoom()).to.eql(16); - happen.click( ui.zoomIn ); + happen.click(ui.zoomIn); expect(map.getZoom()).to.eql(17); }); - it('Should be able to zoom out', function() { + it('Should be able to zoom out', function () { map.setZoom(16); expect(map.getZoom()).to.eql(16); - happen.click( ui.zoomOut ); + happen.click(ui.zoomOut); expect(map.getZoom()).to.eql(15); }); }); - describe('Knob', function() { + describe('Knob', function () { var knob; - beforeEach(function() { + beforeEach(function () { knob = map.zoomsliderControl._knob; }); - it('Should set max value to be map maxZoom - minZoom', function() { - expect( knob._maxValue ).to.eql( map.getMaxZoom() - map.getMinZoom() ); + it('Should set max value to be map maxZoom - minZoom', function () { + expect(knob._maxValue).to.eql(map.getMaxZoom() - map.getMinZoom()); }); - it('Should match the map zoom level', function() { + it('Should match the map zoom level', function () { map.zoomIn(); expect(map.getZoom()).to.eql(17); expect(knob.getValue()).to.eql(17); diff --git a/spec/suites/zoomslider_leaflet_control_spec.js b/spec/suites/zoomslider_leaflet_control_spec.js index 9f694c6..ea99e28 100644 --- a/spec/suites/zoomslider_leaflet_control_spec.js +++ b/spec/suites/zoomslider_leaflet_control_spec.js @@ -1,20 +1,21 @@ -describe('Control', function() { +/*global describe, it, expect, createMap */ +describe('Control', function () { var map, tileLayer; - it('Should add itself to the map unless zoomSliderControl is false', function() { - map = L.map(document.createElement('div'), { zoomAnimation: false }).setView([0,0], 16); + it('Should add itself to the map unless zoomSliderControl is false', function () { + map = createMap({ zoomAnimation: false, zoomsliderControl: true }); expect(map.zoomsliderControl).to.be.an(L.Control.Zoomslider); }); - it('Should not add itself to the map if zoomSliderControl is set to false', function() { - map = L.map(document.createElement('div'), { zoomAnimation: false, zoomsliderControl: false }).setView([0,0], 16); + it('Should not add itself to the map if zoomSliderControl is set to false', function () { + map = createMap({ zoomAnimation: false, zoomsliderControl: false }); expect(map.zoomsliderControl).to.be(undefined); }); - it('The slider should move to the correct position when a layer is added', function() { - map = L.map(document.createElement('div'), { zoomAnimation: false }).setView([0,0], 16); + it('The slider should move to the correct position when a layer is added', function () { + map = createMap({ zoomAnimation: false, zoomsliderControl: true }); tileLayer = L.tileLayer('{x},{y},{z}', { minZoom: 0, maxZoom: 19 }).addTo(map); - expect( map.zoomsliderControl._knob.getValue() ).to.eql(16); + expect(map.zoomsliderControl._knob.getValue()).to.eql(16); }); }); diff --git a/src/L.Control.Zoomslider.css b/src/L.Control.Zoomslider.css index 923b9a0..fa6d154 100644 --- a/src/L.Control.Zoomslider.css +++ b/src/L.Control.Zoomslider.css @@ -103,3 +103,20 @@ box-shadow: none; border: 4px solid rgba(0,0,0,0.3); } + +/* Old IE */ + +.leaflet-oldie .leaflet-control-zoomslider-wrap { + width: 26px; +} + +.leaflet-oldie .leaflet-control-zoomslider { + border: 1px solid #999; +} + +.leaflet-oldie .leaflet-control-zoomslider-in { + *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = '+'); +} +.leaflet-oldie .leaflet-control-zoomslider-out { + *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = '-'); +} \ No newline at end of file diff --git a/src/L.Control.Zoomslider.ie.css b/src/L.Control.Zoomslider.ie.css deleted file mode 100644 index 4e81ea1..0000000 --- a/src/L.Control.Zoomslider.ie.css +++ /dev/null @@ -1,16 +0,0 @@ -/* IE6-7 specific hacks */ -.leaflet-control-zoomslider-wrap { - *width: 26px; -} -/* Fix IE6-divs having a too large min height */ -.leaflet-control-zoomslider-knob { - *overflow: hidden; -} - -/* Support for element:after { content: 'text' } */ -.leaflet-control-zoomslider-in { - *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = '+'); -} -.leaflet-control-zoomslider-out { - *zoom: expression( this.runtimeStyle['zoom'] = '1', this.innerHTML = '-'); -} \ No newline at end of file diff --git a/src/L.Control.Zoomslider.js b/src/L.Control.Zoomslider.js index dd55fec..606cd1d 100644 --- a/src/L.Control.Zoomslider.js +++ b/src/L.Control.Zoomslider.js @@ -10,12 +10,14 @@ module.exports = factory(L); } else { // Browser globals - if (typeof window.L === 'undefined') - throw 'Leaflet must be loaded first'; + if (typeof window.L === 'undefined') { + throw new Error('Leaflet must be loaded first'); + } factory(window.L); } }(function (L) { 'use strict'; + L.Control.Zoomslider = (function () { var Knob = L.Draggable.extend({ @@ -88,16 +90,16 @@ this.options.stepHeight, this.options.knobHeight); - map .whenReady(this._initKnob, this) - .whenReady(this._initEvents, this) - .whenReady(this._updateSize, this) - .whenReady(this._updateKnobValue, this) - .whenReady(this._updateDisabled, this); + map.whenReady(this._initKnob, this) + .whenReady(this._initEvents, this) + .whenReady(this._updateSize, this) + .whenReady(this._updateKnobValue, this) + .whenReady(this._updateDisabled, this); return this._ui.bar; }, onRemove: function (map) { - map .off('zoomlevelschange', this._updateSize, this) + map.off('zoomlevelschange', this._updateSize, this) .off('zoomend zoomlevelschange', this._updateKnobValue, this) .off('zoomend zoomlevelschange', this._updateDisabled, this); },