baidumap.js 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /*******************************************************************************
  2. * KindEditor - WYSIWYG HTML Editor for Internet
  3. * Copyright (C) 2006-2011 kindsoft.net
  4. *
  5. * @author Roddy <luolonghao@gmail.com>
  6. * @site http://www.kindsoft.net/
  7. * @licence http://www.kindsoft.net/license.php
  8. *******************************************************************************/
  9. // Baidu Maps: http://dev.baidu.com/wiki/map/index.php?title=%E9%A6%96%E9%A1%B5
  10. KindEditor.plugin('baidumap', function(K) {
  11. var self = this, name = 'baidumap', lang = self.lang(name + '.');
  12. self.clickToolbar(name, function() {
  13. var html = ['<div style="padding:10px 20px;">',
  14. '<div class="ke-dialog-row">',
  15. lang.address + ' <input id="kindeditor_plugin_map_address" name="address" class="ke-input-text" value="" style="width:200px;" /> ',
  16. '<span class="ke-button-common ke-button-outer">',
  17. '<input type="button" name="searchBtn" class="ke-button-common ke-button" value="' + lang.search + '" />',
  18. '</span>',
  19. '</div>',
  20. '<div class="ke-map" style="width:558px;height:360px;"></div>',
  21. '</div>'].join('');
  22. var dialog = self.createDialog({
  23. name : name,
  24. width : 600,
  25. title : self.lang(name),
  26. body : html,
  27. yesBtn : {
  28. name : self.lang('yes'),
  29. click : function(e) {
  30. var map = win.map;
  31. var centerObj = map.getCenter();
  32. var center = centerObj.lng + ',' + centerObj.lat;
  33. var zoom = map.getZoom();
  34. var url = ['http://api.map.baidu.com/staticimage',
  35. '?center=' + encodeURIComponent(center),
  36. '&zoom=' + encodeURIComponent(zoom),
  37. '&width=558',
  38. '&height=360',
  39. '&markers=' + encodeURIComponent(center),
  40. '&markerStyles=' + encodeURIComponent('l,A')].join('');
  41. self.exec('insertimage', url).hideDialog().focus();
  42. }
  43. },
  44. beforeRemove : function() {
  45. searchBtn.remove();
  46. if (doc) {
  47. doc.write('');
  48. }
  49. iframe.remove();
  50. }
  51. });
  52. var div = dialog.div,
  53. addressBox = K('[name="address"]', div),
  54. searchBtn = K('[name="searchBtn"]', div),
  55. win, doc;
  56. var iframe = K('<iframe class="ke-textarea" frameborder="0" src="' + self.pluginsPath + 'baidumap/map.html" style="width:558px;height:360px;"></iframe>');
  57. function ready() {
  58. win = iframe[0].contentWindow;
  59. doc = K.iframeDoc(iframe);
  60. }
  61. iframe.bind('load', function() {
  62. iframe.unbind('load');
  63. if (K.IE) {
  64. ready();
  65. } else {
  66. setTimeout(ready, 0);
  67. }
  68. });
  69. K('.ke-map', div).replaceWith(iframe);
  70. // search map
  71. searchBtn.click(function() {
  72. win.search(addressBox.val());
  73. });
  74. });
  75. });