From c5ba5b0456a711d157e317f220e9c739226e7f50 Mon Sep 17 00:00:00 2001 From: Joar Wandborg Date: Tue, 10 Jan 2012 01:54:37 +0100 Subject: Installed leaflet in extlib --- extlib/leaflet/src/core/Browser.js | 23 +++++++++ extlib/leaflet/src/core/Class.js | 66 ++++++++++++++++++++++++++ extlib/leaflet/src/core/Events.js | 58 +++++++++++++++++++++++ extlib/leaflet/src/core/Util.js | 96 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 extlib/leaflet/src/core/Browser.js create mode 100644 extlib/leaflet/src/core/Class.js create mode 100644 extlib/leaflet/src/core/Events.js create mode 100644 extlib/leaflet/src/core/Util.js (limited to 'extlib/leaflet/src/core') diff --git a/extlib/leaflet/src/core/Browser.js b/extlib/leaflet/src/core/Browser.js new file mode 100644 index 00000000..0604ed6d --- /dev/null +++ b/extlib/leaflet/src/core/Browser.js @@ -0,0 +1,23 @@ +(function() { + var ua = navigator.userAgent.toLowerCase(), + ie = !!window.ActiveXObject, + webkit = ua.indexOf("webkit") != -1, + mobile = ua.indexOf("mobi") != -1, + android = ua.indexOf("android") != -1, + opera = window.opera; + + L.Browser = { + ie: ie, + ie6: ie && !window.XMLHttpRequest, + webkit: webkit, + webkit3d: webkit && ('WebKitCSSMatrix' in window) && ('m11' in new WebKitCSSMatrix()), + mobileWebkit: webkit && (mobile || android), + mobileOpera: mobile && opera, + gecko: ua.indexOf("gecko") != -1, + android: android + }; + + //TODO replace ugly ua sniffing with feature detection + + L.Browser.touch = L.Browser.mobileWebkit || L.Browser.mobileOpera; +})(); \ No newline at end of file diff --git a/extlib/leaflet/src/core/Class.js b/extlib/leaflet/src/core/Class.js new file mode 100644 index 00000000..09a9e539 --- /dev/null +++ b/extlib/leaflet/src/core/Class.js @@ -0,0 +1,66 @@ +/* + * Class powers the OOP facilities of the library. Thanks to John Resig and Dean Edwards for inspiration! + */ + +L.Class = function() {}; + +L.Class.extend = function(/*Object*/ props) /*-> Class*/ { + + // extended class with the new prototype + var NewClass = function() { + if (!L.Class._prototyping && this.initialize) { + this.initialize.apply(this, arguments); + } + }; + + // instantiate class without calling constructor + L.Class._prototyping = true; + var proto = new this(); + L.Class._prototyping = false; + + proto.constructor = NewClass; + NewClass.prototype = proto; + + // add superclass access + proto.superclass = this.prototype; + + // add class name + //proto.className = props; + + // mix static properties into the class + if (props.statics) { + L.Util.extend(NewClass, props.statics); + delete props.statics; + } + + // mix includes into the prototype + if (props.includes) { + L.Util.extend.apply(null, [proto].concat(props.includes)); + delete props.includes; + } + + // merge options + if (props.options && proto.options) { + props.options = L.Util.extend({}, proto.options, props.options); + } + + // mix given properties into the prototype + L.Util.extend(proto, props); + + // allow inheriting further + NewClass.extend = arguments.callee; + + // method for adding properties to prototype + NewClass.include = function(props) { + L.Util.extend(this.prototype, props); + }; + + //inherit parent's statics + for (var i in this) { + if (this.hasOwnProperty(i) && i != 'prototype') { + NewClass[i] = this[i]; + } + } + + return NewClass; +}; \ No newline at end of file diff --git a/extlib/leaflet/src/core/Events.js b/extlib/leaflet/src/core/Events.js new file mode 100644 index 00000000..53ea20fa --- /dev/null +++ b/extlib/leaflet/src/core/Events.js @@ -0,0 +1,58 @@ +/* + * L.Mixin.Events adds custom events functionality to Leaflet classes + */ + +L.Mixin = {}; + +L.Mixin.Events = { + addEventListener: function(/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) { + var events = this._leaflet_events = this._leaflet_events || {}; + events[type] = events[type] || []; + events[type].push({ + action: fn, + context: context + }); + return this; + }, + + hasEventListeners: function(/*String*/ type) /*-> Boolean*/ { + var k = '_leaflet_events'; + return (k in this) && (type in this[k]) && (this[k][type].length > 0); + }, + + removeEventListener: function(/*String*/ type, /*Function*/ fn, /*(optional) Object*/ context) { + if (!this.hasEventListeners(type)) { return this; } + + for (var i = 0, events = this._leaflet_events, len = events[type].length; i < len; i++) { + if ( + (events[type][i].action === fn) && + (!context || (events[type][i].context === context)) + ) { + events[type].splice(i, 1); + return this; + } + } + return this; + }, + + fireEvent: function(/*String*/ type, /*(optional) Object*/ data) { + if (!this.hasEventListeners(type)) { return; } + + var event = L.Util.extend({ + type: type, + target: this + }, data); + + var listeners = this._leaflet_events[type].slice(); + + for (var i = 0, len = listeners.length; i < len; i++) { + listeners[i].action.call(listeners[i].context || this, event); + } + + return this; + } +}; + +L.Mixin.Events.on = L.Mixin.Events.addEventListener; +L.Mixin.Events.off = L.Mixin.Events.removeEventListener; +L.Mixin.Events.fire = L.Mixin.Events.fireEvent; \ No newline at end of file diff --git a/extlib/leaflet/src/core/Util.js b/extlib/leaflet/src/core/Util.js new file mode 100644 index 00000000..28daa284 --- /dev/null +++ b/extlib/leaflet/src/core/Util.js @@ -0,0 +1,96 @@ +/* + * L.Util is a namespace for various utility functions. + */ + +L.Util = { + extend: function(/*Object*/ dest) /*-> Object*/ { // merge src properties into dest + var sources = Array.prototype.slice.call(arguments, 1); + for (var j = 0, len = sources.length, src; j < len; j++) { + src = sources[j] || {}; + for (var i in src) { + if (src.hasOwnProperty(i)) { + dest[i] = src[i]; + } + } + } + return dest; + }, + + bind: function(/*Function*/ fn, /*Object*/ obj) /*-> Object*/ { + return function() { + return fn.apply(obj, arguments); + }; + }, + + stamp: (function() { + var lastId = 0, key = '_leaflet_id'; + return function(/*Object*/ obj) { + obj[key] = obj[key] || ++lastId; + return obj[key]; + }; + })(), + + requestAnimFrame: (function() { + function timeoutDefer(callback) { + window.setTimeout(callback, 1000 / 60); + } + + var requestFn = window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + timeoutDefer; + + return function(callback, context, immediate) { + callback = context ? L.Util.bind(callback, context) : context; + if (immediate && requestFn === timeoutDefer) { + callback(); + } else { + requestFn(callback); + } + }; + })(), + + limitExecByInterval: function(fn, time, context) { + var lock, execOnUnlock, args; + function exec(){ + lock = false; + if (execOnUnlock) { + args.callee.apply(context, args); + execOnUnlock = false; + } + } + return function() { + args = arguments; + if (!lock) { + lock = true; + setTimeout(exec, time); + fn.apply(context, args); + } else { + execOnUnlock = true; + } + }; + }, + + falseFn: function() { return false; }, + + formatNum: function(num, digits) { + var pow = Math.pow(10, digits || 5); + return Math.round(num * pow) / pow; + }, + + setOptions: function(obj, options) { + obj.options = L.Util.extend({}, obj.options, options); + }, + + getParamString: function(obj) { + var params = []; + for (var i in obj) { + if (obj.hasOwnProperty(i)) { + params.push(i + '=' + obj[i]); + } + } + return '?' + params.join('&'); + } +}; -- cgit v1.2.3