From 8581a3da3a3c6a4e94052066a65e61196683b37c Mon Sep 17 00:00:00 2001 From: rolux Date: Mon, 4 Jun 2012 11:49:27 +0200 Subject: [PATCH] remove unneeded constants --- source/Ox.UI/js/Map/Map.js | 9 +++---- source/Ox/js/Constants.js | 49 +++++++++++--------------------------- source/Ox/js/JavaScript.js | 32 +++++++++++++++++++++---- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/source/Ox.UI/js/Map/Map.js b/source/Ox.UI/js/Map/Map.js index f08ddd95..1bef97cb 100644 --- a/source/Ox.UI/js/Map/Map.js +++ b/source/Ox.UI/js/Map/Map.js @@ -277,7 +277,8 @@ Ox.Map = function(options, self) { 500, 200, 100, 50, 20, 10 ]; - self.shiftKey = false; + self.shiftKey = false, + self.tileSize = 256; if (self.options.showToolbar) { self.$toolbar = Ox.Bar({ @@ -736,7 +737,7 @@ Ox.Map = function(options, self) { function getMetersPerPixel() { // m/px = m/deg * deg/px - var degreesPerPixel = 360 / (Ox.MAP_TILE_SIZE * Math.pow(2, self.map.getZoom())); + var degreesPerPixel = 360 / (self.tileSize * Math.pow(2, self.map.getZoom())); return Ox.getMetersPerDegree(self.map.getCenter().lat()) * degreesPerPixel; } @@ -748,7 +749,7 @@ Ox.Map = function(options, self) { // fixme: there must be a function for this... /* return Math.ceil( - Ox.log(self.mapHeight / Ox.MAP_TILE_SIZE, 2) + Ox.log(self.mapHeight / self.tileSize, 2) ); */ } @@ -1321,7 +1322,7 @@ Ox.Map = function(options, self) { function spansGlobe() { // fixme: or self.options.width ?? - return self.$map.width() > Ox.MAP_TILE_SIZE * Math.pow(2, self.map.getZoom()); + return self.$map.width() > self.tileSize * Math.pow(2, self.map.getZoom()); }; function submitFind(data) { diff --git a/source/Ox/js/Constants.js b/source/Ox/js/Constants.js index 8fff0f0b..a33b2790 100644 --- a/source/Ox/js/Constants.js +++ b/source/Ox/js/Constants.js @@ -1,20 +1,19 @@ 'use strict'; -//@ Ox.AMPM <[str]> ['AM', 'PM'] +//@ Ox.AMPM <[s]> ['AM', 'PM'] Ox.AMPM = ['AM', 'PM']; //@ Ox.BASE_32_ALIASES Base 32 aliases Ox.BASE_32_ALIASES = {'I': '1', 'L': '1', 'O': '0', 'U': 'V'}, //@ Ox.BASE_32_DIGITS Base 32 digits Ox.BASE_32_DIGITS = '0123456789ABCDEFGHJKMNPQRSTVWXYZ'; -//@ Ox.BCAD <[str]> ['BC', 'AD'] +//@ Ox.BCAD <[s]> ['BC', 'AD'] Ox.BCAD = ['BC', 'AD']; -// fixme: this is unused, and probably unneeded -//@ Ox.DURATIONS <[str]> ['year', 'month', 'day', 'hour', 'minute', 'second'] -Ox.DURATIONS = ['year', 'month', 'day', 'hour', 'minute', 'second']; -//@ Ox.EARTH_RADIUS Radius of the earth in meters -// see http://en.wikipedia.org/wiki/WGS-84 +/*@ +Ox.EARTH_RADIUS Radius of the earth in meters + See http://en.wikipedia.org/wiki/WGS-84 +*/ Ox.EARTH_RADIUS = 6378137; -//@ Ox.EARTH_CIRCUMFERENCE Circumference of the earth in meters +//@ Ox.EARTH_CIRCUMFERENCE Circumference of the earth in meters Ox.EARTH_CIRCUMFERENCE = Ox.EARTH_RADIUS * 2 * Math.PI; //@ Ox.HTML_ENTITIES HTML entities for ... (FIXME) Ox.HTML_ENTITIES = { @@ -53,31 +52,11 @@ Ox.KEYS = { 220: 'backslash', 221: 'closebracket', 222: 'quote', 224: 'meta' // see dojo, for ex. }, -//@ Ox.KEYWORDS <[s]> JavaScript keywords -// see https://developer.mozilla.org/en/JavaScript/Reference -Ox.KEYWORDS = [ - 'break', - 'case', 'catch', 'class', 'const', 'continue', - 'debugger', 'default', 'delete', 'do', - 'else', 'enum', 'export', 'extends', - 'false', 'finally', 'for', 'function', - 'if', 'implements', 'import', 'in', 'instanceof', 'interface', - 'let', 'module', - 'new', 'null', - 'package', 'private', 'protected', 'public', - 'return', - 'super', 'switch', 'static', - 'this', 'throw', 'true', 'try', 'typeof', - 'var', 'void', - 'yield', - 'while', 'with' -]; -Ox.MAP_TILE_SIZE = 256; // fixme: definitely not needed here //@ Ox.MAX_LATITUDE Maximum latitude of a Mercator projection Ox.MAX_LATITUDE = Ox.deg(Math.atan(Ox.sinh(Math.PI))); //@ Ox.MIN_LATITUDE Minimum latitude of a Mercator projection Ox.MIN_LATITUDE = -Ox.MAX_LATITUDE; -//@ Ox.MODIFIER_KEYS Names for modifier keys +//@ Ox.MODIFIER_KEYS Names for modifier keys // meta comes last so that one can differentiate between // alt_control_shift_meta.left and alt_control_shift_meta.right Ox.MODIFIER_KEYS = { @@ -86,7 +65,7 @@ Ox.MODIFIER_KEYS = { shiftKey: 'shift', metaKey: 'meta' // Mac: command } -//@ Ox.MONTHS <[str]> Names of months +//@ Ox.MONTHS <[s]> Names of months Ox.MONTHS = [ 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December' @@ -103,11 +82,11 @@ Ox.PATH = Ox.toArray( })[0].src.replace(/Ox\.js$/, ''); //@ Ox.PREFIXES <[str]> `['', 'K', 'M', 'G', 'T', 'P']` Ox.PREFIXES = ['', 'K', 'M', 'G', 'T', 'P']; -//@ Ox.SEASONS <[str]> Names of the seasons of the year +//@ Ox.SEASONS <[s]> Names of the seasons of the year Ox.SEASONS = ['Winter', 'Spring', 'Summer', 'Fall']; //@ Ox.STACK_SIZE Maximum number of arguments Ox.STACK_SIZE = 65536; -//@ Ox.SYMBOLS Unicode characters for symbols +//@ Ox.SYMBOLS Unicode characters for symbols Ox.SYMBOLS = { DOLLAR: '\u0024', CENT: '\u00A2', POUND: '\u00A3', CURRENCY: '\u00A4', YEN: '\u00A5', @@ -133,13 +112,13 @@ Ox.SYMBOLS = { CLOSE: '\u2715', BALLOT: '\u2717', WINDOWS: '\u2756', EDIT: '\uF802', CLICK: '\uF803', APPLE: '\uF8FF' }; -//@ Ox.VERSION OxJS version number +//@ Ox.VERSION OxJS version number Ox.VERSION = '0.1'; -//@ Ox.WEEKDAYS <[str]> Names of weekdays +//@ Ox.WEEKDAYS <[s]> Names of weekdays Ox.WEEKDAYS = [ 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday' ]; -//@ Ox.SHORT_WEEKDAYS <[str]> Short names of weekdays +//@ Ox.SHORT_WEEKDAYS <[s]> Short names of weekdays Ox.SHORT_WEEKDAYS = Ox.WEEKDAYS.map(function(val) { return val.slice(0, 3); }); diff --git a/source/Ox/js/JavaScript.js b/source/Ox/js/JavaScript.js index 613e785f..5b52f637 100644 --- a/source/Ox/js/JavaScript.js +++ b/source/Ox/js/JavaScript.js @@ -475,9 +475,15 @@ Ox.doc = (function() { /*@ Ox.identify Returns the type of a JavaScript identifier - (str) -> Type + (string) -> Type Type can be `constant`, `identifier`, `keyword`, `method`, `object` or `property`. + > Ox.identify('foo') + 'identifier' + > Ox.identify('break') + 'keyword' + > Ox.identify('window') + 'object' @*/ Ox.identify = (function() { // see https://developer.mozilla.org/en/JavaScript/Reference @@ -488,6 +494,23 @@ Ox.identify = (function() { // Number 'MAX_VALUE', 'MIN_VALUE', 'NEGATIVE_INFINITY', 'POSITIVE_INFINITY' ], + keyword: [ + 'break', + 'case', 'catch', 'class', 'const', 'continue', + 'debugger', 'default', 'delete', 'do', + 'else', 'enum', 'export', 'extends', + 'false', 'finally', 'for', 'function', + 'if', 'implements', 'import', 'in', 'instanceof', 'interface', + 'let', 'module', + 'new', 'null', + 'package', 'private', 'protected', 'public', + 'return', + 'super', 'switch', 'static', + 'this', 'throw', 'true', 'try', 'typeof', + 'var', 'void', + 'yield', + 'while', 'with' + ], method: [ // Array 'concat', @@ -615,10 +638,11 @@ Ox.identify = (function() { }; return function(identifier) { var ret; - if (Ox.KEYWORDS.indexOf(identifier) > -1) { - ret = 'keyword' + if (identifiers.keyword.indexOf(identifier) > -1) { + // fast track for keywords (used in Ox.tokenize) + ret = 'keyword'; } else { - ret = 'identifier' + ret = 'identifier'; Ox.forEach(identifiers, function(words, type) { if (words.indexOf(identifier) > -1) { ret = type;