1 2 /** 3 * @name CeL function for API 4 * @fileoverview 5 * 本檔案包含了 include API 專用的 functions。 6 * @since 2010/6/20 13:28:50 7 */ 8 9 /* 10 11 */ 12 13 if (typeof CeL === 'function'){ 14 15 /** 16 * 本 module 之 name(id),<span style="text-decoration:line-through;">不設定時會從呼叫時之 path 取得</span>。 17 * @type String 18 * @constant 19 * @inner 20 * @ignore 21 */ 22 var module_name = 'code.API'; 23 24 //=================================================== 25 /** 26 * 若欲 include 整個 module 時,需囊括之 code。 27 * @type Function 28 * @param {Function} library_namespace namespace of library 29 * @param load_arguments 呼叫時之 argument(s) 30 * @return 31 * @name CeL.code.API 32 * @constant 33 * @inner 34 * @ignore 35 */ 36 var code_for_including = function(library_namespace, load_arguments) { 37 38 // ** no requires 39 40 41 /** 42 * null module constructor 43 * @class 相容性 test 專用的 functions 44 */ 45 CeL.code.API 46 = function() { 47 // null module constructor 48 }; 49 50 /** 51 * for JSDT: 有 prototype 才會將之當作 Class 52 */ 53 CeL.code.API 54 .prototype = { 55 }; 56 57 58 59 60 61 /* 2008/5/29 20:6:23-6/4 2:10:21 62 7/3 13:34 showNeighbor: 可拖曳 loc->name/address, 有資料的提高優先權, bug fix: 有些太遠的還是會被列入, 有些近的可能因為不是住址而不會被列入 63 7/9 13:9:15 context menu 64 7/9 21:12:3 getLocations 65 2009/7/20 20:27:58 稍作修正 66 67 68 bug: 69 名稱相同時會出現被覆蓋的情況! 70 71 72 TO TEST: 73 74 75 showClass.setRepository('_ev_'); 76 77 sC=showClass.showOnScope; 78 79 sC('mp',GLog.write); 80 81 sC('Fb','mp'); 82 83 sC('y','Fb'); 84 85 sC('A','y'); 86 87 88 to use: 89 90 <script type="text/javascript" src="map.js"></script> 91 <script type="text/javascript">//<![CDATA[ 92 wAPIcode('Gmap'); 93 //]]></script> 94 95 96 TODO: 97 分類(Categories)&分顏色顯示 98 Auto Zoom Out http://esa.ilmari.googlepages.com/sorry.htm 99 search data only 100 preload map & markers 101 GDirections 102 圈選 103 用經緯度查詢 104 105 c.f. http://jmaps.digitalspaghetti.me.uk/ 106 107 http://www.ascc.sinica.edu.tw/nl/90/1706/02.txt 108 臺灣地區地名網站 109 http://tgnis.ascc.net 110 http://placesearch.moi.gov.tw/index_tw.php 111 112 地名學名詞解釋彙編 113 http://webgis.sinica.edu.tw/geo/Termquery.asp 114 115 臺灣地區地名相關文獻查詢系統 116 http://webgis.sinica.edu.tw/geo/reference.html 117 118 經濟部中央地質調查所-地質資料整合查詢 119 http://datawarehouse.moeacgs.gov.tw/geo/index/GISSearch/MSDefault.htm 120 121 122 http://gissrv3.sinica.edu.tw/tgnis_query/link.php?cid=1 123 http://www.edu.geo.ntnu.edu.tw/modules/wordpress/2008/06/08/yxaewaweaeobmh/ 124 125 126 http://gissrv3.sinica.edu.tw/search/left2_detail.php?d_number=1&d_database=25k_2002 127 http://gissrv3.sinica.edu.tw/search/left2_detail.php?d_number=1085&d_database=5000_1 128 http://gissrv3.sinica.edu.tw/search/left2_detail.php?d_number=01663&d_database=chen_quo 129 http://gissrv3.sinica.edu.tw/search/left2_detail.php?d_number=1663&d_database=chen_jen 130 http://gissrv3.sinica.edu.tw/search/left2_detail.php?d_number=11880&d_database=tw_fort 131 http://gissrv3.sinica.edu.tw/search/left2_detail.php?d_number=02713&d_database=ching 132 133 http://gissrv3.sinica.edu.tw/input/detail.php?input_id=45875 134 135 資料庫 編號 類型(類別) 名稱 地理座標(經緯度) 所屬縣市鄉鎮(所屬行政區,地點) 別稱 註記(所在圖號) 意義(說明) 136 137 138 139 http://www.isp.tw/zip.php 140 141 小工具 142 143 1.溫度轉換 144 2.進位換算 145 3.BMI值及熱量需求計算 146 4.角度徑度換算 147 5.度量衡計算 148 6.區碼國碼查詢 149 7.郵遞區號查詢 150 8.金融機構代號查詢 151 9.色彩表示法查詢 152 10.摩斯密碼及字母述語 153 11.生肖星座查詢 154 12.婦女安全期計算 155 13.花言花語查詢 156 14.常用機關電話查詢 157 15.航空公司機場代碼查詢 158 16.簡易匯率換算 159 17.國曆農曆換算 160 18.急救及疾病忌口寶典 161 19.尺碼對照表 162 20.自訂公式計算 163 21.股票投資組合管理 164 165 166 */ 167 168 169 170 171 /* 初始化 Google Gears 172 http://code.google.com/apis/gears/gears_init.js 173 http://blog.ericsk.org/archives/978 174 http://chuiwenchiu.spaces.live.com/blog/cns!CA5D9227DF9E78E8!1063.entry 175 176 Google Gears退休: Gears功能正被整合到HTML5規格中 177 we expect developers to use HTML5 for these features moving forward as it's a standards-based approach that will be available across all browsers. 178 http://it.solidot.org/article.pl?sid=09/12/03/0539248 179 */ 180 function init_Google_Gears() { 181 // 檢查是否已經定義 Google Gear 182 if (window.google && google.gears) 183 return; 184 185 var factory = null; 186 // 依據不同的瀏覽器,採用不同方式產生 GearFactory 187 if (typeof GearsFactory != 'undefined') 188 // Firefox 189 factory = new GearsFactory(); 190 else 191 try { 192 // IE 193 factory = new ActiveXObject('Gears.Factory'); 194 // privateSetGlobalObject is only required and supported on WinCE. 195 if (factory.getBuildInfo().indexOf('ie_mobile') != -1) 196 factory.privateSetGlobalObject(this); 197 } catch (e) { 198 // Safari 199 if (typeof navigator.mimeTypes != 'undefined' 200 && navigator.mimeTypes["application/x-googlegears"]) { 201 factory = document.createElement("object"); 202 factory.style.display = "none"; 203 factory.width = factory.height = 0; 204 factory.type = "application/x-googlegears"; 205 document.documentElement.appendChild(factory); 206 } 207 } 208 if (!factory) 209 return 1; 210 211 if (!window.google) 212 window.google = {}; 213 if (!google.gears) 214 google.gears = { 215 factory : factory 216 }; 217 218 } 219 220 221 /* 222 f={catch:true/false/update, restore:false/true.} 223 */ 224 catchFile.ls=0; // localServer 225 catchFile.sn='catch-files'; // storeName: 定義 Managed Store 的名稱,這個名稱可用於 createManagedStore, removeManagedStore 和 openManagedStore 三個 API 226 catchFile.s=0; // managed store 227 // 228 catchFile.f=function(url,success,captureId){}; 229 catchFile.fL=[location.pathname]; // file list 230 catchFile.doCache=1; 231 catchFile.noAsk=1; 232 function catchFile(fList, f) { 233 var _f = arguments.callee; 234 if (!_f.doCache) 235 return; 236 237 if (window.location.protocol == 'file:') { 238 sl('catchFile: Google Gears 不能在本機上執行或測試!'); 239 return 0; 240 } 241 242 if (init_Google_Gears()) { 243 if (_f.answered) 244 return 0; 245 _f.answered = 1; 246 if (!_f.noAsk && confirm('使用本功能必須安裝 Google Gears,請問您要安裝嗎?')) 247 // ?action=install&message=加入你的訊息&return=安裝後要導回的網址 248 window.location.href = 'http://gears.google.com/'; 249 else 250 sl('<em>catchFile: 若不安裝 Google Gears 則將無法使用本功能!</em>'); 251 return 1; 252 } 253 254 if (!_f.ls) 255 try { 256 // 建立 Local Server 257 _f.ls = window.google.gears.factory.create('beta.localserver', 258 '1.0'); 259 } catch (e) { 260 sl('catchFile: Could not create local server: [' 261 + (e.number & 0xFFFF) + '] ' + e.message); 262 return 2; 263 } 264 265 if (!_f.s) 266 try { 267 // 建立儲存空間 268 _f.s = _f.ls.createManagedStore(_f.sn); 269 _f.s = _f.ls.createStore(_f.sn); 270 } catch (e) { 271 if (window.location.protocol == 'file:') 272 sl('Google Gears 不能在本機上執行測試!'); 273 else 274 sl('catchFile: Could not create managed store: [' 275 + (e.number & 0xFFFF) + '] ' + e.message); 276 return 3; 277 } 278 279 if ((fList instanceof String) && fList) { 280 // TODO: untested!! 281 // 指定 json 的 url 282 _f.s.manifestUrl(fList); 283 // 開始確定版本及同步 284 _f.s.checkForUpdate(); 285 286 // 為了確認是否同步結束了,可以加入下列的 timer 來檢查: 287 var timer = google.gears.factory.create('beta.timer'); 288 // 每 500ms 檢查一下 289 var timerId = timer.setInterval(function() { 290 // 同步完成 291 if (store.currentVersion) { 292 timer.clearInterval(timerId); 293 sl('同步完成'); 294 } 295 }, 500); 296 } else if ((fList instanceof Array) && fList.length) 297 _f.fL = _f.fL.concat(fList); 298 299 // If the store already exists, it will be opened 300 if (_f.s) 301 try { 302 _f.s.capture(_f.fL, _f.f); 303 } catch (e) { 304 if (e.message == 'Url is not from the same origin') 305 sl('需要在同樣的 domain!'); 306 else 307 sl('catchFile: Could not capture file: [' + (e.number & 0xFFFF) 308 + '] ' + e.message); 309 return 4; 310 } 311 312 /* 313 // uncapture 314 for ( var i = 0; i < fList.length; i++) { 315 _f.s.remove(fList[i]); 316 } 317 // removeStore 318 if (localServer.openStore(storeName)) { 319 localServer.removeStore(storeName); 320 _f.s = null; 321 } 322 */ 323 324 }; 325 326 327 328 /* http://blog.wctang.info/2007/07/use-google-map-api-without-api-key.html 329 驗證的程式叫 GValidateKey,是定義在 main.js,但呼叫的動作是寫在 maps.js 裡 330 331 332 333 function showClass(c, n) { 334 var i, sp = '<hr style="width:40%;float:left;"/><br style="clear:both;"/>', h = '<span style="color:#bbb;font-size:.8em;">', p = function( 335 m, p) { 336 sl(h + n + (p ? '.prototype' : '') + '.</span><em>' + m + '</em> ' + h 337 + '=</span> ' + f(c[m])); 338 }, f = function(f) { 339 return (f + '').replace(/\n/g, '<br/>').replace(/ /g, ' '); 340 }; 341 if (typeof c == 'string') { 342 if (!n) 343 n = c; 344 c = eval(c); 345 } 346 if (!n) 347 n = ''; 348 sl('<hr/>Show class: (' + (typeof c) + ')' 349 + (n ? ' [<em>' + n + '</em>]' : '') + '<br/>' 350 // +(n?'<em>'+n+'</em> '+h+'=</span> ':'') 351 + f(c)); 352 if (c) { 353 sl(sp + 'class member:'); 354 for (i in c) 355 if (i != 'prototype') 356 p(i); 357 sl(sp + 'prototype:'); 358 c = c.prototype; 359 for (i in c) 360 p(i, 1); 361 } 362 sl('<hr/>'); 363 } 364 365 //showClass('GValidateKey'); 366 367 _v = {}; 368 eval('_v.lp=lp;', GValidateKey); 369 //showClass(_v.lp,'lp'); 370 371 eval('_v.j=j;', GValidateKey); 372 //showClass(_v.j,'j'); 373 374 eval('_v.ep=ep;', GValidateKey); 375 showClass(_v.ep, 'ep'); 376 377 //sl(_v.lp('http:', 'lyrics.meicho.com.tw', '/game/index.htm').join('<br/>')); 378 379 var b = _v.lp('http:', 'lyrics.meicho.com.tw', '/game/index.htm'); 380 for ( var c = 0; c < b.length; ++c) { 381 var d = b[c]; 382 sl(d + '; ' + _v.ep(d)); 383 } 384 385 */ 386 387 388 389 390 391 CeL.code.API 392 . 393 /** 394 * 自動挑選 domain 395 * @param API API name 396 * @param callback null: do NOT load 397 * @return [ API url, API key ] 398 * @since 2010/6/20 22:12:23 399 * @see 400 * 401 */ 402 use_API = function(API, callback) { 403 var _s = _.use_API, 404 url_set = _s.API_URL, url = window.location, 405 key_set = _s.API_key, API_key; 406 407 if ( !library_namespace.is_Array(url_set = url_set[API]) || typeof url_set[1] !== 'function' || 408 !library_namespace.is_Object(key_set = key_set[url_set[0]]) 409 ){ 410 CeL.err(url = 'use_API: The kind of API [' + API + '] is not included in the code pool!'); 411 throw new Error(url); 412 } 413 414 if (url.protocol === 'file:') 415 // 取得任何 legal key 416 for (url in key_set){ 417 if (typeof key_set[url] === 'string') 418 break; 419 } 420 421 // this is for domain + path 422 //else if ((url = url.href.replace(/[^\/]+$/, '')) in key_set) ; 423 424 // this is for domain. 不能用 .pathname: IE 會作特殊處置 425 else if (!(url = url.href.match(/^([a-z-]+:\/\/[^\/]+\/)/)) || !((url = url[1]) in key_set)){ 426 CeL.err(url = 'use_API: This domain [' + url + '] is not included in ' + url_set[0] + ' code pool!'); 427 throw new Error(url); 428 } 429 430 //library_namespace.debug('[' + url + ']\n' + key_set[url] + '\n' + location.href + '\n' + location.pathname); 431 432 url = url_set[1](API_key = key_set[url] || '', _s.language || ''); 433 434 if (callback !== null){ 435 library_namespace.include_resource( 436 url, 437 callback 438 // 某些舊版 Firefox 使用 createElement('script') 不被接受,因此可能需要用寫的。 439 , 0 440 , 0 441 ); 442 443 library_namespace.debug('load [' + url_set[0] + '] ' + API + ': [<a href="' + url + '">' + url + '</a>].'); 444 } 445 446 return [ url, API_key ]; 447 }; 448 449 CeL.code.API 450 . 451 /** 452 * 語系. e.g., zh-TW, ja, en 453 */ 454 use_API.language = 'zh-TW'; 455 456 CeL.code.API 457 . 458 use_API.API_key = { 459 Google : { 460 /* 461 * 在本機上試用 Google Map API 並不需要去申請 API Key。 462 * 2008/7/15 20:40:49 但幾天前起 GClientGeocoder 需要。而在 Firefox,即使在 file:// 也不可行?? 463 */ 464 465 /* 466 // by account fan0123321 467 'http://lyrics.meicho.com.tw/' : 'ABQIAAAAx1BFd-K0IXzdNnudsKfW3BR_OWH2p1vlzGygO-LFq-ywbfjcNBQ4wJpNt5E4VTHG4JLZ_HX8LQxVEQ', 468 'https://lyrics.meicho.com.tw/' : 'ABQIAAAAx1BFd-K0IXzdNnudsKfW3BQ2grkpcb8ONU70KrnysR7Wz3iAOhQ7rov77Kc_pTW2t8r5-BSiIg5j6w', 469 'http://kanashimi.meicho.com.tw/' : 'ABQIAAAAx1BFd-K0IXzdNnudsKfW3BSETOz6DhT-d0fFy_mIERGWK3ymyxQKcydi2zFol0W_QslvBsxp3BffQQ', 470 'https://kanashimi.meicho.com.tw/' : 'ABQIAAAAx1BFd-K0IXzdNnudsKfW3BTFY8WBNAy3k9U7ZNA5kvqHv9VA-BSzdXmlU2Sm9WU6hvuSysY85kLdGw', 471 */ 472 473 // by account cedegree 474 // AJAX Search API Key: http://code.google.com/intl/zh-TW/apis/ajaxsearch/signup.html 475 'http://meicho.com.tw/' : 'ABQIAAAA8YsRfLuORC22bc07JTNYsBS3JAeykUxPSpDNfPvIbcz6s5aBrRRdn1nyUM_9cYox7ymS-IgI-2CNuA', 476 'http://211.22.213.114/' : 'ABQIAAAA8YsRfLuORC22bc07JTNYsBQ1Uh1TD6YMX-95u9UsztRVu87z9xSXJOXSHjEtKMQm2v4PGPwji5o2oA', 477 478 // by account kanasimi 479 'http://lyrics.meicho.com.tw/' : 'ABQIAAAAgGipxXX8cQ5RHLEVH9TO-RR_OWH2p1vlzGygO-LFq-ywbfjcNBQcZtd9Bp9zMEQhrEtSnBy9_wJQmg', 480 // 事實上 domain-key 就夠了。 481 //'http://lyrics.meicho.com.tw/program/map/' : 'ABQIAAAAgGipxXX8cQ5RHLEVH9TO-RQQofoUntuAmbaLi2tPP0I7mS20HxSIGUQ5BPerzSbJB2mFqHQq07idRg', 482 'https://lyrics.meicho.com.tw/' : 'ABQIAAAAgGipxXX8cQ5RHLEVH9TO-RQ2grkpcb8ONU70KrnysR7Wz3iAOhS24gkxeP-OqUBmABKA7PZQoacWHQ', 483 'http://kanashimi.meicho.com.tw/' : 'ABQIAAAAgGipxXX8cQ5RHLEVH9TO-RSETOz6DhT-d0fFy_mIERGWK3ymyxSPw4AHxgM4dHjkgesM0FKx4ui2BQ', 484 'https://kanashimi.meicho.com.tw/' : 'ABQIAAAAgGipxXX8cQ5RHLEVH9TO-RTFY8WBNAy3k9U7ZNA5kvqHv9VA-BRu-OKx8fvfBtyuqJZfb5PK0HllUQ' 485 486 /* 487 事實上 [*.]*.com.tw 用下面這個也行。 488 'http://com.tw/':'ABQIAAAAgGipxXX8cQ5RHLEVH9TO-RTXVjoday36ta5qc6JGQW5WaWldDhTZrWmq9ZDX6Bhhzgk7MlY9qQXvzA', 489 490 對 http://lyrics.meicho.com.tw/game/ 會檢查的: 491 http://lyrics.meicho.com.tw/game/ 492 http://lyrics.meicho.com.tw/ 493 http://www.lyrics.meicho.com.tw/game/ 494 http://www.lyrics.meicho.com.tw/ 495 http://meicho.com.tw/game/ 496 http://meicho.com.tw/ 497 http://com.tw/game/ 498 http://com.tw/ 499 */ 500 501 }, 502 503 Yahoo : { 504 // by account colorlessecho for Yahoo! map 505 'http://lyrics.meicho.com.tw/' : 'XX9YCu_V34G1xvKMy7EOmVkPFtALrHIkVP_qG5ANRAzuTNlQKuoXVssSTBYiGSX9gjssAA--' 506 }, 507 508 Microsoft : { 509 // by account cedegree@hotmail.com for VLS 510 // http://www.bing.com/developers/ 511 '' : 'BCBE2B0C4E58461B987145E3EBB1BFAB96FBCCD0', 512 'http://meicho.com.tw/' : 'BCBE2B0C4E58461B987145E3EBB1BFAB96FBCCD0', 513 'http://211.22.213.114/' : 'BCBE2B0C4E58461B987145E3EBB1BFAB96FBCCD0' 514 } 515 }; 516 517 CeL.code.API 518 . 519 use_API.API_URL = { 520 Gmap : [ 521 'Google', 522 function(k, l) { 523 return 'http://maps.google.com/maps?file=api&v=2&hl=' + l + '&key=' + k; 524 } ], 525 GAPI : [ 'Google', function(k, l) { 526 return 'http://www.google.com/jsapi?hl=' + l + '&key=' + k; 527 } ], 528 529 YMap : [ 'Yahoo', function(k) { 530 return 'http://api.maps.yahoo.com/ajaxymap?v=3.8&appid=' + k; 531 } ], 532 twYMap : [ 'Yahoo', function(k) { 533 return 'http://tw.api.maps.yahoo.com/ajaxymap?v=3.8&appid=' + k; 534 } ], 535 536 Bing: [ 'Microsoft', function(k) { 537 return 'http://api.microsofttranslator.com/V1/Ajax.svc/Embed?appId=' + k; 538 } ] 539 }; 540 541 542 543 544 545 546 CeL.code.API 547 . 548 /** 549 * 為 Microsoft Translator 設置 550 * @param text test to translate 551 * @param callback callback(from text,to text) 552 * @param [from_enc] 553 * @param [to_enc] 554 * @return 555 * @see 556 * <a href="http://msdn.microsoft.com/en-us/library/ff512406.aspx" accessdate="2010/7/12 20:22">Translate Method</a>, 557 * <a href="http://www.west-wind.com/Weblog/posts/107136.aspx" accessdate="2010/7/12 20:22">JSONP for cross-site Callbacks - Rick Strahl's Web Log</a> 558 */ 559 add_Microsoft_translate = function(text, callback, from_enc, to_enc) { 560 if (!text || !callback) 561 return; 562 563 var _s = _.add_Microsoft_translate, url = _s.url, name = _s.reference_name, count; 564 // 初始化 initialization 565 if (!url) 566 _s.url = url = 'http://api.microsofttranslator.com/V2/Ajax.svc/Translate?appId=' + 567 _.use_API('Bing', null)[1]; 568 569 //library_namespace.debug('<a href="' + url + encodeURIComponent(text) + '">' + url + encodeURIComponent(text) + '</a>'); 570 571 _s.buffer[count = _s.counter++] = [ text, callback ]; 572 // response, count, function name of add_Microsoft_translate 573 _s['c' + count] = new Function('r', 574 name + '.callback(r,' + count + ',"' + name + '");' 575 ); 576 library_namespace.include_resource( 577 url 578 + '&from=' + (from_enc || _s.from) 579 + '&to=' + (to_enc || _s.to) 580 + '&text=' + encodeURIComponent(text) 581 + '&oncomplete=' + name + '.c' + count, 582 0, 583 0 584 ); 585 }; 586 587 CeL.code.API 588 . 589 add_Microsoft_translate.from = 'en'; 590 591 CeL.code.API 592 . 593 add_Microsoft_translate.to = 'zh-cht'; 594 595 CeL.code.API 596 . 597 add_Microsoft_translate.reference_name = library_namespace.Class + '.add_Microsoft_translate'; 598 599 600 601 CeL.code.API 602 . 603 /** 604 * @inner 605 * @private 606 */ 607 add_Microsoft_translate.counter = 0; 608 609 CeL.code.API 610 . 611 /** 612 * @inner 613 * @private 614 */ 615 add_Microsoft_translate.buffer = []; 616 617 var ELEMENT_NODE = 1; 618 619 CeL.code.API 620 . 621 /** 622 * @inner 623 * @private 624 */ 625 add_Microsoft_translate.callback = function(response, count, name) { 626 try{ 627 var _s = library_namespace.get_various(name), 628 origin = _s.buffer[count], 629 callback = origin[1]; 630 origin = origin[0]; 631 delete _s.buffer[count]; 632 delete _s['c' + count]; 633 if (typeof callback === 'function') { 634 callback(response, origin); 635 } else { 636 if (typeof callback === 'string') 637 callback = document.getElementById(callback); 638 if (typeof callback === 'object' 639 && callback.nodeType === ELEMENT_NODE) 640 callback.appendChild(document.createTextNode(response)); 641 } 642 }catch (e) { 643 library_namespace.warn('add_Microsoft_translate.callback: '+name+': error!'); 644 } 645 }; 646 647 648 649 650 651 return ( 652 CeL.code.API 653 ); 654 }; 655 656 //=================================================== 657 658 CeL.setup_module(module_name, code_for_including); 659 660 }; 661