ym4r-mapstraction 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.DS_Store +0 -0
- data/.gitignore +2 -0
- data/LICENSE +20 -0
- data/README.rdoc +158 -0
- data/Rakefile +52 -0
- data/VERSION +1 -0
- data/javascript/clusterer.js +410 -0
- data/javascript/mapquest-js/mqcommon.js +1740 -0
- data/javascript/mapquest-js/mqexec.js +977 -0
- data/javascript/mapquest-js/mqobjects.js +10733 -0
- data/javascript/mapquest-js/mqutils.js +1001 -0
- data/javascript/mapstraction-geocode.js +179 -0
- data/javascript/mapstraction-route.js +200 -0
- data/javascript/mapstraction.js +3570 -0
- data/javascript/ym4r-mapstraction.js +105 -0
- data/lib/mapstraction_plugin/helper.rb +14 -0
- data/lib/mapstraction_plugin/mapping.rb +120 -0
- data/lib/mapstraction_plugin/mapstraction.rb +309 -0
- data/lib/mapstraction_plugin/overlay.rb +105 -0
- data/lib/mapstraction_plugin/routing.rb +56 -0
- data/lib/ym4r_mapstraction.rb +43 -0
- data/tasks/ym4r_mapstraction_tasks.rake +4 -0
- data/test/ym4r_mapstraction_test.rb +8 -0
- data/ym4r-mapstraction.gemspec +69 -0
- metadata +84 -0
@@ -0,0 +1,1001 @@
|
|
1
|
+
try{
|
2
|
+
var testCommons = new MQObject();
|
3
|
+
testCommons = null;
|
4
|
+
}catch(error){
|
5
|
+
throw "You must include mqcommon.js or toolkit api script prior to mqutils.js.";
|
6
|
+
}
|
7
|
+
var mqutils = 1;
|
8
|
+
/**
|
9
|
+
* @fileoverview This file contains the common utility functions used throughout the js API.
|
10
|
+
*/
|
11
|
+
/**
|
12
|
+
* Create a function for array to push onto the stack if the browser does
|
13
|
+
* not support it.
|
14
|
+
* Older broswer including IE5 don't support the array.push() method.
|
15
|
+
* @param Arguments[] arguments Objects to push onto the array.
|
16
|
+
* @return Returns the length of the array.
|
17
|
+
* @type int
|
18
|
+
* @private
|
19
|
+
*/
|
20
|
+
if (!Array.prototype.push) Array.prototype.push = function() {
|
21
|
+
var length = Array.push.arguments.length;
|
22
|
+
for (var i=0; i < length; i++)
|
23
|
+
this[this.length] = Array.push.arguments[i];
|
24
|
+
return this.length;
|
25
|
+
};
|
26
|
+
|
27
|
+
function mq_ParamExists (varname) {
|
28
|
+
var undef;
|
29
|
+
return (varname !== undef);
|
30
|
+
}
|
31
|
+
|
32
|
+
/**
|
33
|
+
* =GET ELEMENT BY ID
|
34
|
+
*/
|
35
|
+
function mqGetElementById(fId)
|
36
|
+
{
|
37
|
+
if(document.getElementById(fId))
|
38
|
+
{
|
39
|
+
return document.getElementById(fId);
|
40
|
+
}
|
41
|
+
return null;
|
42
|
+
} //mqGetElementById(fId)
|
43
|
+
|
44
|
+
|
45
|
+
/*******************************************************************************/
|
46
|
+
/* OAPI Functions */
|
47
|
+
/*******************************************************************************/
|
48
|
+
//function used to update a script node used for remote data calls.
|
49
|
+
//takes a string of the query data and string of the div name
|
50
|
+
function mqBuildUrl(strQueryData)
|
51
|
+
{
|
52
|
+
var mqServer = _mqServerPort.replace(/mapquest.com:?\d*/,'mapquest.com');
|
53
|
+
return (_reqPrefix + mqServer + "/oapi/transaction?" + strQueryData + "&key=" + _mqKey);
|
54
|
+
}
|
55
|
+
|
56
|
+
function mqUrlLimit()
|
57
|
+
{
|
58
|
+
var maxLength = 2048;
|
59
|
+
if (mqBrowserInfo.isNS) {
|
60
|
+
maxLength = 7168;
|
61
|
+
}
|
62
|
+
return maxLength;
|
63
|
+
}
|
64
|
+
|
65
|
+
function mqLimitDisplay()
|
66
|
+
{
|
67
|
+
var dispLength = 2;
|
68
|
+
if (mqBrowserInfo.isNS) {
|
69
|
+
dispLength = 7;
|
70
|
+
}
|
71
|
+
return dispLength;
|
72
|
+
}
|
73
|
+
|
74
|
+
function mqDoRemote(strQueryData, strDivName, strParentTagName, mqObj)
|
75
|
+
{
|
76
|
+
var parent = document.getElementsByTagName(strParentTagName).item(0);
|
77
|
+
var scMQRemote = mqGetElementById(strDivName);
|
78
|
+
if(scMQRemote)
|
79
|
+
{
|
80
|
+
parent.removeChild(scMQRemote);
|
81
|
+
}
|
82
|
+
scMQRemote = document.createElement("script");
|
83
|
+
var srcString = mqBuildUrl(strQueryData);
|
84
|
+
if (strQueryData.substring(0,4) == "http")
|
85
|
+
{
|
86
|
+
srcString = strQueryData;
|
87
|
+
}
|
88
|
+
if (srcString.length > mqUrlLimit())
|
89
|
+
{
|
90
|
+
alert("The request query exceeds the limit ("+mqLimitDisplay()+" Kb) allowed for your browser type. Please reduce the amount of data in the request query!");
|
91
|
+
return;
|
92
|
+
}
|
93
|
+
scMQRemote.src = srcString;
|
94
|
+
scMQRemote.type = "text/javascript";
|
95
|
+
scMQRemote.id = strDivName;
|
96
|
+
parent.appendChild(scMQRemote);
|
97
|
+
}//mqDoRemote()
|
98
|
+
|
99
|
+
//crossbrowser wrapper to create an xml document object
|
100
|
+
//by importing a node
|
101
|
+
function mqCreateXMLDocImportNode(ndNewRoot) {
|
102
|
+
var newDoc;
|
103
|
+
if (document.implementation.createDocument){
|
104
|
+
var newDoc = document.implementation.createDocument("", "", null);
|
105
|
+
try{newDoc.appendChild(newDoc.importNode(ndNewRoot,true))}catch(error){alert(error);alert(ndNewRoot.nodeName);};
|
106
|
+
} else if (window.ActiveXObject){
|
107
|
+
// Internet Explorer, create a new XML document using ActiveX
|
108
|
+
// and use loadXML as a DOM parser.
|
109
|
+
newDoc = new ActiveXObject("Microsoft.XMLDOM");
|
110
|
+
newDoc.async="false";
|
111
|
+
newDoc.loadXML(ndNewRoot.xml);
|
112
|
+
}
|
113
|
+
|
114
|
+
return newDoc;
|
115
|
+
}
|
116
|
+
//crossbrowser wrapper to convert an xml document object into a string
|
117
|
+
/**
|
118
|
+
* Crossbrowser wrapper to convert an xml document object into a string
|
119
|
+
* @param Document xmlDoc Xml Document to be converted into a string
|
120
|
+
* @return Returns the converted xmlDoc as a String.
|
121
|
+
* @type String
|
122
|
+
* @private
|
123
|
+
*/
|
124
|
+
function mqXmlToStr(xmlDoc) {
|
125
|
+
var strXml = new String;
|
126
|
+
var serializer = null;
|
127
|
+
if (xmlDoc == null) return "";
|
128
|
+
|
129
|
+
if (mqBrowserInfo.isNS) {
|
130
|
+
serializer = new window.XMLSerializer();
|
131
|
+
strXml = serializer.serializeToString(xmlDoc);
|
132
|
+
} else if (mqBrowserInfo.isIE) {
|
133
|
+
strXml = xmlDoc.xml;
|
134
|
+
}
|
135
|
+
|
136
|
+
if(mqBrowserInfo.isSafari)
|
137
|
+
{
|
138
|
+
serializer = new window.XMLSerializer();
|
139
|
+
strXml = serializer.serializeToString(xmlDoc);
|
140
|
+
strXml = strXml || "";
|
141
|
+
//un-escaping & for safari -start
|
142
|
+
strXml = strXml.replace( /#38;/g,'&');
|
143
|
+
//escaping & for safari -stop
|
144
|
+
}
|
145
|
+
return strXml;
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
function mqCreateNSManager(namespace) {
|
150
|
+
|
151
|
+
var nsmgr ={
|
152
|
+
normalResolver:
|
153
|
+
xmlDoc.createNSResolver(xmlDoc.documentElement),
|
154
|
+
lookupNamespaceURI : function (prefix) {
|
155
|
+
switch (prefix) {
|
156
|
+
case "_mq":
|
157
|
+
return namespace;
|
158
|
+
default:
|
159
|
+
return this.normalResolver.lookupNamespaceURI(prefix);
|
160
|
+
}
|
161
|
+
}
|
162
|
+
}
|
163
|
+
return nsmgr;
|
164
|
+
}
|
165
|
+
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
|
170
|
+
//crossbrowser wrapper used to return a node object given a specified xpath expression:
|
171
|
+
//ie xml doc <location><address></address></location>
|
172
|
+
//xpath expression /location/address
|
173
|
+
//will return a pointer to the address node
|
174
|
+
/**
|
175
|
+
* Crossbrowser wrapper used to return a node object given a specified xpath expression:
|
176
|
+
* ie xml doc <location><address></address></location>
|
177
|
+
* xpath expression /location/address will return a pointer to the address node
|
178
|
+
* @param Document xmlDoc Xml Document to be searched
|
179
|
+
* @param String strPath Path to search for in xmlDoc
|
180
|
+
* @return Returns the node if found.
|
181
|
+
* @type Node
|
182
|
+
* @private
|
183
|
+
*/
|
184
|
+
function mqGetNode(xmlDoc, strPath) {
|
185
|
+
var node;
|
186
|
+
//Safari adaptation start--
|
187
|
+
if (mqBrowserInfo.isSafari)
|
188
|
+
{
|
189
|
+
var names = new Array();
|
190
|
+
names = strPath.split('/');
|
191
|
+
if(names[names.length-1].indexOf('@') != -1)
|
192
|
+
{
|
193
|
+
names.splice(names.length-1,1);
|
194
|
+
}
|
195
|
+
var tree = xmlDoc.documentElement;
|
196
|
+
var isfound = false;
|
197
|
+
if( names.length == 2 && tree.tagName == names[1])
|
198
|
+
isfound = true;
|
199
|
+
else
|
200
|
+
{
|
201
|
+
var length = names.length -1 ;
|
202
|
+
for(var i=1; i < length ; i++)
|
203
|
+
{
|
204
|
+
isfound = false;
|
205
|
+
if(tree.tagName == names[i] && tree.hasChildNodes())
|
206
|
+
{
|
207
|
+
var nodes=(tree.hasChildNodes())?tree.childNodes.length:0;
|
208
|
+
for(var j=0; j<nodes; j++)
|
209
|
+
{
|
210
|
+
|
211
|
+
if(tree.childNodes[j].tagName == names[i+1])
|
212
|
+
{
|
213
|
+
tree = tree.childNodes[j];
|
214
|
+
isfound = true;
|
215
|
+
break;
|
216
|
+
}
|
217
|
+
}
|
218
|
+
}
|
219
|
+
|
220
|
+
if (names[i+1] && names[i+1].indexOf('text()') != -1)
|
221
|
+
{
|
222
|
+
isfound = true;
|
223
|
+
}
|
224
|
+
if(names[i + 1].indexOf('[') != -1)
|
225
|
+
{
|
226
|
+
var index = parseInt(names[i+1].substr(names[i+1].indexOf('[')+1,names[i+1].indexOf(']')-1));
|
227
|
+
names[i+1] = names[i+1].substr(0,names[i+1].indexOf('['));
|
228
|
+
tree = xmlDoc.getElementsByTagName(names[i+1]).item(index -1);//-1 for safari
|
229
|
+
isfound = true;
|
230
|
+
}
|
231
|
+
}
|
232
|
+
}
|
233
|
+
node = (isfound==true)? tree: null;
|
234
|
+
return node;
|
235
|
+
}
|
236
|
+
//Safari adaptation stop--
|
237
|
+
else if (mqBrowserInfo.isIE) {
|
238
|
+
node = xmlDoc.selectSingleNode(strPath);
|
239
|
+
return node;
|
240
|
+
} else if (mqBrowserInfo.isNS) {
|
241
|
+
node = xmlDoc.evaluate(strPath, xmlDoc, null, 9, null);
|
242
|
+
return node.singleNodeValue;
|
243
|
+
}
|
244
|
+
return null;
|
245
|
+
}
|
246
|
+
|
247
|
+
|
248
|
+
//crossbrowser wrapper used to return the text of a given node
|
249
|
+
//ie loop on all <request> nodes in xml to change text
|
250
|
+
// document.getElementsByTagName("request");
|
251
|
+
/**
|
252
|
+
* crossbrowser wrapper used to return the text of a given node
|
253
|
+
* ie loop on all <request> nodes in xml to change text
|
254
|
+
* document.getElementsByTagName("request");
|
255
|
+
* @param Node domNode Node to extract the text from
|
256
|
+
* @return Returns the text of the node.
|
257
|
+
* @type String
|
258
|
+
* @private
|
259
|
+
*/
|
260
|
+
function mqGetNodeText(domNode) {
|
261
|
+
var elemText = "";
|
262
|
+
if (mqBrowserInfo.isIE) {
|
263
|
+
elemText = domNode.text;
|
264
|
+
} else if (mqBrowserInfo.isNS && domNode.firstChild) {//without domNode.firstChild condition giving error in Mac(safari).
|
265
|
+
elemText = domNode.firstChild.nodeValue;
|
266
|
+
}
|
267
|
+
if(mqBrowserInfo.isSafari && domNode.firstChild) {//without domNode.firstChild condition giving error in Mac(safari).
|
268
|
+
elemText = domNode.firstChild.nodeValue;
|
269
|
+
// for Safari only elemText was null in some cases
|
270
|
+
elemText = (elemText ? elemText:"");
|
271
|
+
//un-escaping & for safari -start
|
272
|
+
elemText = elemText.replace( /#38;/g,'&');
|
273
|
+
//un-escaping & for safari -stop
|
274
|
+
}
|
275
|
+
return elemText;
|
276
|
+
}
|
277
|
+
|
278
|
+
//crossbrowser wrapper used to return the text of a given node given a specified xpath expression:
|
279
|
+
//ie xml doc <location><address>122 N Plum St.</address></location>
|
280
|
+
//xpath expression /location/address
|
281
|
+
//will return the string "122 N Plum St." or
|
282
|
+
//ie xml doc <locationCollection count="3">....</locationCollection>
|
283
|
+
//xpath expression /locationCollection/@count
|
284
|
+
//will return a value of 3
|
285
|
+
/**
|
286
|
+
* crossbrowser wrapper used to return the text of a given node given a specified xpath expression:
|
287
|
+
* ie xml doc <location><address>122 N Plum St.</address></location>
|
288
|
+
* xpath expression /location/address
|
289
|
+
* will return the string "122 N Plum St." or
|
290
|
+
* ie xml doc <locationCollection count="3">....</locationCollection>
|
291
|
+
* xpath expression /locationCollection/@count
|
292
|
+
* will return a value of 3
|
293
|
+
* @param Document xmlDoc Xml Document to be searched
|
294
|
+
* @param String strPath XPath where the text is
|
295
|
+
* @return Returns the text of the node.
|
296
|
+
* @type String
|
297
|
+
* @private
|
298
|
+
*/
|
299
|
+
function mqGetXPathNodeText(xmlDoc, strPath) {
|
300
|
+
var node;
|
301
|
+
//Safari adaptation start--
|
302
|
+
if(mqBrowserInfo.isSafari)
|
303
|
+
{
|
304
|
+
node = mqGetNode(xmlDoc, strPath);
|
305
|
+
var nodeText="";
|
306
|
+
var attribute="";
|
307
|
+
//for now support for @ only
|
308
|
+
if(strPath.indexOf('@') != -1)
|
309
|
+
{
|
310
|
+
attribute = strPath.substr(strPath.indexOf('@')+1, strPath.length);
|
311
|
+
nodeText = node.attributes.getNamedItem(attribute).nodeValue ;
|
312
|
+
}
|
313
|
+
else if(node)
|
314
|
+
{
|
315
|
+
nodeText = mqGetNodeText(node) ;
|
316
|
+
}
|
317
|
+
return nodeText;
|
318
|
+
}
|
319
|
+
//Safari adaptation stop--
|
320
|
+
if (mqBrowserInfo.isIE) {
|
321
|
+
node = xmlDoc.selectSingleNode(strPath);
|
322
|
+
return (node == null ? "" : node.text);
|
323
|
+
} else if (mqBrowserInfo.isNS) {
|
324
|
+
try{node = xmlDoc.evaluate(strPath, xmlDoc, null, 2, null);} catch(error) {alert(strPath); alert(error);}
|
325
|
+
return node.stringValue;
|
326
|
+
}
|
327
|
+
return "";
|
328
|
+
}
|
329
|
+
|
330
|
+
// used by mqSetNodeText after it finds the node
|
331
|
+
// using an XPath expr, so other funcs that have
|
332
|
+
// a nodeList can set text on each node in a loop
|
333
|
+
/**
|
334
|
+
* Used by mqSetNodeText after it finds the node
|
335
|
+
* using an XPath expr, so other funcs that have
|
336
|
+
* a nodeList can set text on each node in a loop
|
337
|
+
* @param Document xmlDoc Xml Document to be added to
|
338
|
+
* @param Node node Xml node to be replaced
|
339
|
+
* @param String strTxt text to add in the node
|
340
|
+
* @return Returns the node.
|
341
|
+
* @type Node
|
342
|
+
* @private
|
343
|
+
*/
|
344
|
+
function mqReplaceNode(xmlDoc,node,strTxt) {
|
345
|
+
var ndNewText = xmlDoc.createTextNode(strTxt);
|
346
|
+
if (node.firstChild) {
|
347
|
+
return node.replaceChild(ndNewText,node.firstChild);
|
348
|
+
} else {
|
349
|
+
return node.appendChild(ndNewText);
|
350
|
+
}
|
351
|
+
}
|
352
|
+
|
353
|
+
/**
|
354
|
+
* Used by saveXml method to replace a node
|
355
|
+
* using an XPath expr
|
356
|
+
* @param Document xmlDoc Xml Document to be added to
|
357
|
+
* @param Node nodeDoc Xml node to be replaced
|
358
|
+
* @param String xpath Xpath to node being replaced
|
359
|
+
* @return Returns the node.
|
360
|
+
* @type Node
|
361
|
+
* @private
|
362
|
+
*/
|
363
|
+
function mqReplaceElementNode(xmlDoc, nodeDoc, xpath) {
|
364
|
+
var root = xmlDoc.documentElement;
|
365
|
+
var newnode = nodeDoc.documentElement;
|
366
|
+
var oldnode = xmlDoc.getElementsByTagName(xpath).item(0);
|
367
|
+
if(mqBrowserInfo.isIE)
|
368
|
+
node = newnode
|
369
|
+
else
|
370
|
+
node = xmlDoc.importNode(newnode, true);
|
371
|
+
if (oldnode){
|
372
|
+
root.replaceChild(node, oldnode);
|
373
|
+
} else {
|
374
|
+
root.appendChild(node);
|
375
|
+
}
|
376
|
+
return xmlDoc;
|
377
|
+
}
|
378
|
+
|
379
|
+
//used to replace/add text to an existing node
|
380
|
+
//ie <location><address></address></location>
|
381
|
+
//if this function is given the xpath /location/address
|
382
|
+
//it will add text to the address node if not present or replace
|
383
|
+
//existing text. It will not add an address node.
|
384
|
+
/**
|
385
|
+
* Used to replace/add text to an existing node
|
386
|
+
* ie <location><address></address></location>
|
387
|
+
* if this function is given the xpath /location/address
|
388
|
+
* it will add text to the address node if not present or replace
|
389
|
+
* existing text. It will not add an address node.
|
390
|
+
* @param Document xmlDoc Xml Document to be changed
|
391
|
+
* @param String strXPath XPath where the text is to be set
|
392
|
+
* @param String strTxt Text to change in the node
|
393
|
+
* @return Returns the node.
|
394
|
+
* @type Node
|
395
|
+
* @private
|
396
|
+
*/
|
397
|
+
function mqSetNodeText(xmlDoc,strXPath,strTxt) {
|
398
|
+
var ndParent = mqGetNode(xmlDoc,strXPath);
|
399
|
+
if (ndParent == null) {
|
400
|
+
return null;
|
401
|
+
}
|
402
|
+
return mqReplaceNode(xmlDoc,ndParent,strTxt);
|
403
|
+
}
|
404
|
+
|
405
|
+
//crossbrowser wrapper used to return xhtml from xml xsl strings.
|
406
|
+
function mqTransformXMLFromString(strXml,strXsl,dvParent) {
|
407
|
+
var xmlDoc = mqCreateXMLDoc(strXml);
|
408
|
+
var xslDoc = mqCreateXMLDoc(strXsl);
|
409
|
+
var newFragment;
|
410
|
+
|
411
|
+
if (mqBrowserInfo.isNS) {
|
412
|
+
var xsltProcessor = new XSLTProcessor();
|
413
|
+
xsltProcessor.importStylesheet(xslDoc);
|
414
|
+
newFragment = xsltProcessor.transformToFragment(xmlDoc, document);
|
415
|
+
dvParent.appendChild(newFragment);
|
416
|
+
} else if (mqBrowserInfo.isIE) {
|
417
|
+
var newFragment = new ActiveXObject("Msxml2.DOMDocument.5.0");
|
418
|
+
newFragment = xmlDoc.transformNode(xslDoc);
|
419
|
+
dvParent.innerHTML += newFragment;
|
420
|
+
}
|
421
|
+
}
|
422
|
+
|
423
|
+
//crossbrowser wrapper used to return xhtml from an xml node an xsl string.
|
424
|
+
function mqTransformXMLFromNode(ndXml,strXsl,dvParent) {
|
425
|
+
var xslDoc = mqCreateXMLDoc(strXsl);
|
426
|
+
var newFragment;
|
427
|
+
|
428
|
+
if (mqBrowserInfo.isNS) {
|
429
|
+
var xsltProcessor = new XSLTProcessor();
|
430
|
+
xsltProcessor.importStylesheet(xslDoc);
|
431
|
+
newFragment = xsltProcessor.transformToFragment(ndXml, document);
|
432
|
+
dvParent.appendChild(newFragment);
|
433
|
+
} else if (mqBrowserInfo.isIE) {
|
434
|
+
var newFragment = new ActiveXObject("Msxml2.DOMDocument.5.0");
|
435
|
+
newFragment = ndXml.transformNode(xslDoc);
|
436
|
+
dvParent.innerHTML += newFragment;
|
437
|
+
}
|
438
|
+
}
|
439
|
+
|
440
|
+
|
441
|
+
/**
|
442
|
+
* =PNG/IE FIX
|
443
|
+
* Work around to make PNG alpha transparency for IE - Thanks to Drew McLellan @ allinthehead.com
|
444
|
+
*/
|
445
|
+
mqAddEvent(window, "load",alphaBackgrounds);
|
446
|
+
|
447
|
+
function alphaBackgrounds(){
|
448
|
+
if(navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer" && window.attachEvent) {
|
449
|
+
var rslt = navigator.appVersion.match(/MSIE (\d+\.\d+)/, '');
|
450
|
+
var itsAllGood = (rslt != null && Number(rslt[1]) >= 5.5);
|
451
|
+
for (i=0; i<document.all.length; i++){
|
452
|
+
var bg = document.all[i].currentStyle.backgroundImage;
|
453
|
+
if (itsAllGood && bg){
|
454
|
+
if (bg.match(/\.png/i) != null){
|
455
|
+
var mypng = bg.substring(5,bg.length-2);
|
456
|
+
document.all[i].style.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+mypng+"', sizingMethod='scale')";
|
457
|
+
document.all[i].style.backgroundImage = "url(/images/background-form-button.gif)";
|
458
|
+
}
|
459
|
+
}
|
460
|
+
}
|
461
|
+
}
|
462
|
+
}
|
463
|
+
|
464
|
+
/*******************************************************************************/
|
465
|
+
/* Following section contains functions for formatting numbers/time/distance */
|
466
|
+
/*******************************************************************************/
|
467
|
+
//function used to format a number (num) to x(dec) decimal places
|
468
|
+
function mqFormatNumber(num,dec) {
|
469
|
+
return Math.floor(num * Math.pow(10,dec))/Math.pow(10,dec);
|
470
|
+
}
|
471
|
+
|
472
|
+
//function displays the time in format x hours, x.xx minutes or x.xx minutes
|
473
|
+
function mq_display_time(totalTime) {
|
474
|
+
var newTime;
|
475
|
+
// more than a minute
|
476
|
+
if(totalTime > 3600)
|
477
|
+
{
|
478
|
+
newTime = totalTime/3600;
|
479
|
+
var result = (" " + Math.floor(newTime) + " hours,");
|
480
|
+
newTime = (totalTime/60)%60;
|
481
|
+
result += (" " + mqFormatNumber(newTime,2) + " minutes");
|
482
|
+
return result;
|
483
|
+
}
|
484
|
+
if(totalTime > 60)
|
485
|
+
{
|
486
|
+
newTime = totalTime/60;
|
487
|
+
return (" " + mqFormatNumber(newTime,2) + " minutes");
|
488
|
+
}
|
489
|
+
}
|
490
|
+
|
491
|
+
//function used to display distance formated in a div with right alignment.
|
492
|
+
//outputs miles or kilometers with 2 digits of precision
|
493
|
+
function mq_display_distance(totalDistance) {
|
494
|
+
return (" " + mqFormatNumber(totalDistance.value,2) + (totalDistance.units == "mi" ? " miles" : " kilometers"));
|
495
|
+
}
|
496
|
+
|
497
|
+
/*******************************************************************************/
|
498
|
+
/* Following section contains functions for adding common DOM elements to tree */
|
499
|
+
/*******************************************************************************/
|
500
|
+
var isIE5Mac = (navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1);
|
501
|
+
|
502
|
+
function mqCreateFormInput (container, id, spanClass, labelTxt, type, name, value, size, maxLength) {
|
503
|
+
var div = container.appendChild (document.createElement ('div'));
|
504
|
+
div.className = 'row';
|
505
|
+
var label = div.appendChild (document.createElement ('label'));
|
506
|
+
label.htmlFor = id;
|
507
|
+
label.appendChild (document.createTextNode (labelTxt));
|
508
|
+
div.appendChild (document.createElement ('br'));
|
509
|
+
var input = document.createElement ('input');
|
510
|
+
input.id = id;
|
511
|
+
input.type = type;
|
512
|
+
input.name = name;
|
513
|
+
if (size != "") {
|
514
|
+
input.size = size;
|
515
|
+
}
|
516
|
+
if (!isNaN(parseInt(maxLength))) {
|
517
|
+
input.maxLength = parseInt(maxLength);
|
518
|
+
}
|
519
|
+
if (value != "") {
|
520
|
+
input.value = value;
|
521
|
+
}
|
522
|
+
|
523
|
+
if (spanClass != "") {
|
524
|
+
var span = div.appendChild (document.createElement ('span'));
|
525
|
+
span.className = spanClass;
|
526
|
+
span.appendChild (input);
|
527
|
+
} else {
|
528
|
+
div.appendChild (input);
|
529
|
+
}
|
530
|
+
}
|
531
|
+
|
532
|
+
function mqCreateInput (container, id, type, name, value, size, maxLength) {
|
533
|
+
var input = document.createElement ('input');
|
534
|
+
input.id = id;
|
535
|
+
input.type = type;
|
536
|
+
input.name = name;
|
537
|
+
if (size != "") {
|
538
|
+
input.size = size;
|
539
|
+
}
|
540
|
+
if (!isNaN(parseInt(maxLength))) {
|
541
|
+
input.maxLength = parseInt(maxLength);
|
542
|
+
}
|
543
|
+
if (value != "") {
|
544
|
+
input.value = value;
|
545
|
+
}
|
546
|
+
container.appendChild (input);
|
547
|
+
}
|
548
|
+
|
549
|
+
function mqCreateHiddenInput (form, id, name, value) {
|
550
|
+
var input;
|
551
|
+
if (isIE5Mac) {
|
552
|
+
input = document.createElement ('input type=hidden');
|
553
|
+
} else {
|
554
|
+
input = document.createElement ('input');
|
555
|
+
input.type = 'hidden';
|
556
|
+
}
|
557
|
+
input.name = name;
|
558
|
+
if (id != '') {
|
559
|
+
input.id = id;
|
560
|
+
}
|
561
|
+
if (value != '') {
|
562
|
+
input.value = value;
|
563
|
+
}
|
564
|
+
form.appendChild (input);
|
565
|
+
}
|
566
|
+
|
567
|
+
function mqCreateFormSelect (container, id, spanClass, labelTxt, name, elements, node) {
|
568
|
+
var div = container.appendChild (document.createElement ('div'));
|
569
|
+
div.className = 'row';
|
570
|
+
var label = div.appendChild (document.createElement ('label'));
|
571
|
+
label.htmlFor = id;
|
572
|
+
label.appendChild (document.createTextNode (labelTxt));
|
573
|
+
div.appendChild (document.createElement ('br'));
|
574
|
+
if (spanClass != "") {
|
575
|
+
var span = div.appendChild (document.createElement ('span'));
|
576
|
+
span.className = spanClass;
|
577
|
+
var select = span.appendChild (document.createElement ('select'));
|
578
|
+
} else {
|
579
|
+
var select = div.appendChild (document.createElement ('select'));
|
580
|
+
}
|
581
|
+
select.id = id;
|
582
|
+
select.name = name;
|
583
|
+
length = elements.length;
|
584
|
+
for (x=0; x < length; x++) {
|
585
|
+
var option = select.appendChild (document.createElement ('option'));
|
586
|
+
eval ("option.value = elements[x]." + node);
|
587
|
+
eval ("option.appendChild (document.createTextNode (elements[x]." + node + "))");
|
588
|
+
}
|
589
|
+
return select;
|
590
|
+
}
|
591
|
+
|
592
|
+
function mqCreateDiv (container, className, id) {
|
593
|
+
var div = container.appendChild (document.createElement ('div'));
|
594
|
+
if (className != "") {
|
595
|
+
div.className = className;
|
596
|
+
}
|
597
|
+
if (id != "") {
|
598
|
+
div.id = id;
|
599
|
+
}
|
600
|
+
return div;
|
601
|
+
}
|
602
|
+
|
603
|
+
function mqCreateA (container, href, title) {
|
604
|
+
var a = container.appendChild (document.createElement ('a'));
|
605
|
+
a.href = href;
|
606
|
+
if (title != "") {
|
607
|
+
a.title = title;
|
608
|
+
}
|
609
|
+
return a;
|
610
|
+
}
|
611
|
+
|
612
|
+
function mqCreateSpan (container, className, id) {
|
613
|
+
var span = container.appendChild (document.createElement ('span'));
|
614
|
+
|
615
|
+
if (className != "") {
|
616
|
+
span.className = className;
|
617
|
+
}
|
618
|
+
if (id != "") {
|
619
|
+
span.id = id;
|
620
|
+
}
|
621
|
+
return span;
|
622
|
+
}
|
623
|
+
|
624
|
+
function mqCreateImg (container, src, width, height, id, name, alt) {
|
625
|
+
var img = container.appendChild (document.createElement ('img'));
|
626
|
+
|
627
|
+
if (src != "") {
|
628
|
+
img.src = src;
|
629
|
+
}
|
630
|
+
|
631
|
+
if (!isNaN(parseInt(width))) {
|
632
|
+
img.width = parseInt(width);
|
633
|
+
}
|
634
|
+
if (!isNaN(parseInt(height))) {
|
635
|
+
img.height = parseInt(height);
|
636
|
+
}
|
637
|
+
if (id != "") {
|
638
|
+
img.id = id;
|
639
|
+
}
|
640
|
+
if (name != "") {
|
641
|
+
img.name = name;
|
642
|
+
}
|
643
|
+
if (alt != "") {
|
644
|
+
img.alt = alt;
|
645
|
+
}
|
646
|
+
return img;
|
647
|
+
}
|
648
|
+
|
649
|
+
function mqCreateImgDiv (container, src, width, height, id, name, alt) {
|
650
|
+
var div = container.appendChild (document.createElement ('div'));
|
651
|
+
if (id != "") {
|
652
|
+
div.id = id;
|
653
|
+
}
|
654
|
+
if (!isNaN(parseInt(width))) {
|
655
|
+
div.style.width = parseInt(width)+"px";
|
656
|
+
}
|
657
|
+
if (!isNaN(parseInt(height))) {
|
658
|
+
div.style.height = parseInt(height)+"px";
|
659
|
+
}
|
660
|
+
if (name != "") {
|
661
|
+
div.name = name;
|
662
|
+
}
|
663
|
+
if (alt != "") {
|
664
|
+
div.alt = alt;
|
665
|
+
}
|
666
|
+
return div;
|
667
|
+
}
|
668
|
+
/**
|
669
|
+
* =HTTP XML REQUEST
|
670
|
+
* @makes a XMLHttpRequest standardized for supported browsers
|
671
|
+
*/
|
672
|
+
function mqXMLHttpRequest()
|
673
|
+
{
|
674
|
+
var request = null;
|
675
|
+
if(window.XMLHttpRequest)
|
676
|
+
{ //moz, safari1.2+, opera8
|
677
|
+
try
|
678
|
+
{
|
679
|
+
request = new XMLHttpRequest();
|
680
|
+
}
|
681
|
+
catch(e)
|
682
|
+
{
|
683
|
+
request = null;
|
684
|
+
}
|
685
|
+
}
|
686
|
+
else if(window.ActiveXObject)
|
687
|
+
{ //ie5.5+
|
688
|
+
try
|
689
|
+
{
|
690
|
+
request = new ActiveXObject("Msxml2.XMLHTTP");
|
691
|
+
}
|
692
|
+
catch(e)
|
693
|
+
{
|
694
|
+
try
|
695
|
+
{
|
696
|
+
request = new ActiveXObject("Microsoft.XMLHTTP");
|
697
|
+
}
|
698
|
+
catch(e)
|
699
|
+
{
|
700
|
+
request = null;
|
701
|
+
}
|
702
|
+
}
|
703
|
+
}
|
704
|
+
return request;
|
705
|
+
} //mqXMLHttpRequest()
|
706
|
+
|
707
|
+
|
708
|
+
/*******************************************************************************/
|
709
|
+
/*Event Listener Code */
|
710
|
+
/*******************************************************************************/
|
711
|
+
/**
|
712
|
+
* =ADD EVENT
|
713
|
+
* @attach event listener
|
714
|
+
*/
|
715
|
+
function mqAddEvent(fObj, fEvent, fn)
|
716
|
+
{
|
717
|
+
if(window.opera && mqBrowserInfo.version < 8)
|
718
|
+
{ // opera has bad dynamic event handling
|
719
|
+
var r = fObj.attachEvent("on"+fEvent, fn);
|
720
|
+
return r;
|
721
|
+
}
|
722
|
+
else if (fObj.addEventListener)
|
723
|
+
{ // moz, w3c
|
724
|
+
((window.opera) && (mqBrowserInfo.version >= 8))?fObj.addEventListener(fEvent, fn, false):fObj.addEventListener(fEvent, fn, true);
|
725
|
+
return true;
|
726
|
+
}
|
727
|
+
else if (fObj.attachEvent)
|
728
|
+
{ // IE
|
729
|
+
var r = fObj.attachEvent("on"+fEvent, fn);
|
730
|
+
return r;
|
731
|
+
}
|
732
|
+
else
|
733
|
+
{ //other
|
734
|
+
fObj["on" + fEvent] = fn;
|
735
|
+
}
|
736
|
+
}//addEvent()
|
737
|
+
|
738
|
+
/**
|
739
|
+
* =REMOVE EVENT
|
740
|
+
* @detach event listener
|
741
|
+
*/
|
742
|
+
function mqRemoveEvent(fObj, fEvent, fn)
|
743
|
+
{
|
744
|
+
if(window.opera)
|
745
|
+
{ // opera has bad dynamic event handling
|
746
|
+
eval("fObj.on" + fEvent + " = null");
|
747
|
+
}
|
748
|
+
if(fObj.removeEventListener)
|
749
|
+
{ //w3c
|
750
|
+
((window.opera) && (mqBrowserInfo.version >= 8))?fObj.removeEventListener(fEvent, fn, false):fObj.removeEventListener(fEvent, fn, true);
|
751
|
+
}
|
752
|
+
else if(fObj.detachEvent)
|
753
|
+
{ //ie
|
754
|
+
fObj.detachEvent("on" + fEvent, fn);
|
755
|
+
}
|
756
|
+
else
|
757
|
+
{ //opera and other
|
758
|
+
fObj["on" + fEvent] = null;
|
759
|
+
}
|
760
|
+
} //mqRemoveEvent()
|
761
|
+
|
762
|
+
/**
|
763
|
+
* =GET EVENT DATA
|
764
|
+
* @return the id that event is attached to
|
765
|
+
*/
|
766
|
+
function mqGetEventData(evt)
|
767
|
+
{
|
768
|
+
fEventData = new Object();
|
769
|
+
if(document.addEventListener)
|
770
|
+
{
|
771
|
+
fEventData.id = evt.target.id;
|
772
|
+
fEventData.type = evt.type;
|
773
|
+
fEventData.element = evt.target;
|
774
|
+
}
|
775
|
+
else if(window.event)
|
776
|
+
{
|
777
|
+
fEventData.id = window.event.srcElement.id;
|
778
|
+
fEventData.type = window.event.type;
|
779
|
+
fEventData.element = window.event.srcElement;
|
780
|
+
}
|
781
|
+
else
|
782
|
+
{
|
783
|
+
return null;
|
784
|
+
}
|
785
|
+
return fEventData;
|
786
|
+
} //mqGetEventData()
|
787
|
+
|
788
|
+
|
789
|
+
/*******************************************************************************/
|
790
|
+
/*Document Coordinate calculations */
|
791
|
+
/*******************************************************************************/
|
792
|
+
/**
|
793
|
+
* GET XY
|
794
|
+
* @get the XY coordinates
|
795
|
+
* @returns an array containing the event target id, and xy data for page and target
|
796
|
+
*
|
797
|
+
*/
|
798
|
+
function mqGetXY(evt)
|
799
|
+
{
|
800
|
+
xyData = new Object();
|
801
|
+
if(!document.createElement || !document.getElementsByTagName) return;
|
802
|
+
if(!document.createElementNS)
|
803
|
+
{ // to work in html and xml namespaces
|
804
|
+
document.createElementNS = function(ns,elt)
|
805
|
+
{
|
806
|
+
return document.createElement(elt);
|
807
|
+
}
|
808
|
+
}
|
809
|
+
if(document.addEventListener && typeof evt.pageX == "number")
|
810
|
+
{ // Moz and Opera
|
811
|
+
var Element = evt.target;
|
812
|
+
var CalculatedTotalOffsetLeft = CalculatedTotalOffsetTop = 0;
|
813
|
+
while(Element.offsetParent)
|
814
|
+
{
|
815
|
+
CalculatedTotalOffsetLeft += Element.offsetLeft;
|
816
|
+
CalculatedTotalOffsetTop += Element.offsetTop;
|
817
|
+
Element = Element.offsetParent;
|
818
|
+
}
|
819
|
+
var OffsetXForNS6 = evt.pageX - CalculatedTotalOffsetLeft;
|
820
|
+
var OffsetYForNS6 = evt.pageY - CalculatedTotalOffsetTop;
|
821
|
+
xyData.elementId = evt.target.id;
|
822
|
+
xyData.elementX = OffsetXForNS6;
|
823
|
+
xyData.elementY = OffsetYForNS6;
|
824
|
+
xyData.pageX = evt.pageX;
|
825
|
+
xyData.pageY = evt.pageY;
|
826
|
+
}
|
827
|
+
else if(window.event && typeof window.event.offsetX == "number")
|
828
|
+
{ //ie
|
829
|
+
xyData.elementId = window.event.srcElement.id;
|
830
|
+
xyData.elementX = event.offsetX;
|
831
|
+
xyData.elementY = event.offsetY;
|
832
|
+
xyData.pageX = 0;
|
833
|
+
xyData.pageY = 0;
|
834
|
+
var element = mqGetElementById(xyData.elementId);
|
835
|
+
while(element)
|
836
|
+
{
|
837
|
+
xyData.pageX += element.offsetLeft;
|
838
|
+
xyData.pageY += element.offsetTop;
|
839
|
+
element = element.offsetParent;
|
840
|
+
}
|
841
|
+
xyData.pageX += xyData.elementX;
|
842
|
+
xyData.pageY += xyData.elementY;
|
843
|
+
}
|
844
|
+
return xyData;
|
845
|
+
}//mqGetXY()
|
846
|
+
|
847
|
+
/**
|
848
|
+
* =GET parentDiv SIZE
|
849
|
+
* @get height and width of containing div canvas
|
850
|
+
*/
|
851
|
+
function mqGetPDivSize( pMQMapObject )
|
852
|
+
{
|
853
|
+
// for openapi
|
854
|
+
// 2 pixels padding overall div
|
855
|
+
size = new MQSize();
|
856
|
+
|
857
|
+
// Temporary defaults if the user hasn't set div size
|
858
|
+
if( pMQMapObject.parent.style.width.length == 0)
|
859
|
+
pMQMapObject.parent.style.width = "800px";
|
860
|
+
if( pMQMapObject.parent.style.height.length == 0)
|
861
|
+
pMQMapObject.parent.style.height = "600px";
|
862
|
+
size.setWidth(parseInt(pMQMapObject.parent.style.width) - 4);
|
863
|
+
size.setHeight(parseInt(pMQMapObject.parent.style.height) - 4);
|
864
|
+
return size;
|
865
|
+
}
|
866
|
+
|
867
|
+
/**
|
868
|
+
* =SET parentDiv SIZE
|
869
|
+
* @set height and width of containing div canvas
|
870
|
+
*/
|
871
|
+
function mqSetPDivSize( pMQMapObject, size )
|
872
|
+
{
|
873
|
+
pMQMapObject.parent.style.width = size.getWidth() + "px";
|
874
|
+
pMQMapObject.parent.style.height = size.getHeight() + "px";
|
875
|
+
}
|
876
|
+
|
877
|
+
/**
|
878
|
+
* urlencode used to fix url before server call
|
879
|
+
*/
|
880
|
+
function mqurlencode(strVal)
|
881
|
+
{
|
882
|
+
var strEncode;
|
883
|
+
strEncode = strVal.replace(/%/g,"%25");
|
884
|
+
strEncode = strEncode.replace(/&/g,"%26");
|
885
|
+
strEncode = strEncode.replace(/#/g,"%23");
|
886
|
+
strEncode = strEncode.replace(/\//g,"%2F");
|
887
|
+
strEncode = strEncode.replace(/:/g,"%3A");
|
888
|
+
strEncode = strEncode.replace(/;/g,"%3B");
|
889
|
+
strEncode = strEncode.replace(/=/g,"%3D");
|
890
|
+
strEncode = strEncode.replace(/\?/g,"%3F");
|
891
|
+
strEncode = strEncode.replace(/@/g,"%40");
|
892
|
+
strEncode = strEncode.replace(/\$/g,"%24");
|
893
|
+
strEncode = strEncode.replace(/,/g,"%2C");
|
894
|
+
strEncode = strEncode.replace(/\+/g,"%2B");
|
895
|
+
return strEncode;
|
896
|
+
}
|
897
|
+
|
898
|
+
function mqGetGuid()
|
899
|
+
{
|
900
|
+
var org = new Date(2006,0,1);
|
901
|
+
var now = new Date();
|
902
|
+
do {
|
903
|
+
var cur = new Date();
|
904
|
+
}while(cur - now < 1);
|
905
|
+
|
906
|
+
var diff = cur.getTime()-org.getTime();
|
907
|
+
return (Math.ceil(diff));
|
908
|
+
|
909
|
+
}
|
910
|
+
function mqPause(numberMillis)
|
911
|
+
{
|
912
|
+
var now = new Date();
|
913
|
+
var exitTime = now.getTime() + numberMillis;
|
914
|
+
while (true)
|
915
|
+
{
|
916
|
+
now = new Date();
|
917
|
+
if (now.getTime() > exitTime)
|
918
|
+
return;
|
919
|
+
}
|
920
|
+
}
|
921
|
+
var _mqLogStartTime = null;
|
922
|
+
var _mqLogCurTime = null;
|
923
|
+
var _mqLogprevTime = null;
|
924
|
+
function mqLogTime(str)
|
925
|
+
{
|
926
|
+
if(mqGetElementById("mqTimeLogs"))
|
927
|
+
{
|
928
|
+
var logtext = mqGetElementById("mqTimeLogs");
|
929
|
+
var mqTimeLogger = new Date();
|
930
|
+
if( _mqLogStartTime == null) {
|
931
|
+
logtext.value = "Time(ms) Difference\t Message\n";
|
932
|
+
_mqLogStartTime = mqTimeLogger.getTime();
|
933
|
+
_mqLogprevTime = _mqLogStartTime;
|
934
|
+
}
|
935
|
+
_mqLogCurTime = mqTimeLogger.getTime();
|
936
|
+
var diff = _mqLogCurTime - _mqLogStartTime;
|
937
|
+
var del = _mqLogCurTime - _mqLogprevTime;
|
938
|
+
logtext.value = logtext.value + diff + "\t " + del + "\t\t " + str + "\n";
|
939
|
+
_mqLogprevTime = _mqLogCurTime;
|
940
|
+
}
|
941
|
+
|
942
|
+
}
|
943
|
+
function mqResetTimeLogs()
|
944
|
+
{
|
945
|
+
if(mqGetElementById("mqTimeLogs"))
|
946
|
+
{
|
947
|
+
var logtext = mqGetElementById("mqTimeLogs");
|
948
|
+
var mqTimeLogger = new Date();
|
949
|
+
logtext.value = "Time(ms) Difference\t Message\n";
|
950
|
+
_mqLogStartTime = mqTimeLogger.getTime();
|
951
|
+
_mqLogprevTime = _mqLogStartTime;
|
952
|
+
}
|
953
|
+
}
|
954
|
+
|
955
|
+
function mqGetAdvantageResultPath(transaction) {
|
956
|
+
var resultsPath ;
|
957
|
+
if (transaction == "poiMap")
|
958
|
+
resultsPath = "poiResults";
|
959
|
+
else if (transaction == "locMap")
|
960
|
+
resultsPath = "locations";
|
961
|
+
else if (transaction == "search")
|
962
|
+
resultsPath = "searchResults";
|
963
|
+
|
964
|
+
return resultsPath;
|
965
|
+
}
|
966
|
+
|
967
|
+
function mqGetAdvantageMapPath(transaction) {
|
968
|
+
var mapPath ;
|
969
|
+
if (transaction == "locMap")
|
970
|
+
mapPath = "/advantage/"+transaction+"/locations/location/map";
|
971
|
+
else
|
972
|
+
mapPath = "/advantage/"+transaction+"/map";
|
973
|
+
return mapPath;
|
974
|
+
}
|
975
|
+
|
976
|
+
function mqPrepareMapUrl(strmapUrl) {
|
977
|
+
var mapUrl = "";
|
978
|
+
mapUrl = strmapUrl.replace(/https?:\/\//,_reqPrefix);
|
979
|
+
mapUrl = mapUrl.replace(/mapquest.com:?\d*/,'mapquest.com');
|
980
|
+
mapUrl = mapUrl.replace(/iwebsys.aol.com:?\d*/,'iwebsys.aol.com');
|
981
|
+
return mapUrl;
|
982
|
+
}
|
983
|
+
|
984
|
+
|
985
|
+
function display(pid, name, value, id , sClass) {
|
986
|
+
|
987
|
+
if (mqGetElementById(pid)) {
|
988
|
+
var div = mqGetElementById(pid);
|
989
|
+
var label = div.appendChild (document.createElement ('label'));
|
990
|
+
var bb = label.appendChild (document.createElement ('b'));
|
991
|
+
bb.appendChild (document.createTextNode (name));
|
992
|
+
div.appendChild (document.createElement ('br'));
|
993
|
+
var span = div.appendChild (document.createElement ('textarea'));
|
994
|
+
span.className = sClass;
|
995
|
+
span.style.overflow = "auto";
|
996
|
+
if(id != null) span.id = id;
|
997
|
+
span.appendChild (document.createTextNode (value));
|
998
|
+
div.appendChild (document.createElement ('br'));
|
999
|
+
div.appendChild (document.createElement ('br'));
|
1000
|
+
}
|
1001
|
+
}
|