flash.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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. KindEditor.plugin('flash', function(K) {
  10. var self = this, name = 'flash', lang = self.lang(name + '.'),
  11. allowFlashUpload = K.undef(self.allowFlashUpload, true),
  12. allowFileManager = K.undef(self.allowFileManager, false),
  13. formatUploadUrl = K.undef(self.formatUploadUrl, true),
  14. extraParams = K.undef(self.extraFileUploadParams, {}),
  15. filePostName = K.undef(self.filePostName, 'imgFile'),
  16. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  17. self.plugin.flash = {
  18. edit : function() {
  19. var html = [
  20. '<div style="padding:20px;">',
  21. //url
  22. '<div class="ke-dialog-row">',
  23. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  24. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  25. '<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
  26. '<span class="ke-button-common ke-button-outer">',
  27. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  28. '</span>',
  29. '</div>',
  30. //width
  31. '<div class="ke-dialog-row">',
  32. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  33. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  34. '</div>',
  35. //height
  36. '<div class="ke-dialog-row">',
  37. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  38. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  39. '</div>',
  40. '</div>'
  41. ].join('');
  42. var dialog = self.createDialog({
  43. name : name,
  44. width : 450,
  45. title : self.lang(name),
  46. body : html,
  47. yesBtn : {
  48. name : self.lang('yes'),
  49. click : function(e) {
  50. var url = K.trim(urlBox.val()),
  51. width = widthBox.val(),
  52. height = heightBox.val();
  53. if (url == 'http://' || K.invalidUrl(url)) {
  54. alert(self.lang('invalidUrl'));
  55. urlBox[0].focus();
  56. return;
  57. }
  58. if (!/^\d*$/.test(width)) {
  59. alert(self.lang('invalidWidth'));
  60. widthBox[0].focus();
  61. return;
  62. }
  63. if (!/^\d*$/.test(height)) {
  64. alert(self.lang('invalidHeight'));
  65. heightBox[0].focus();
  66. return;
  67. }
  68. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  69. src : url,
  70. type : K.mediaType('.swf'),
  71. width : width,
  72. height : height,
  73. quality : 'high'
  74. });
  75. self.insertHtml(html).hideDialog().focus();
  76. }
  77. }
  78. }),
  79. div = dialog.div,
  80. urlBox = K('[name="url"]', div),
  81. viewServerBtn = K('[name="viewServer"]', div),
  82. widthBox = K('[name="width"]', div),
  83. heightBox = K('[name="height"]', div);
  84. urlBox.val('http://');
  85. if (allowFlashUpload) {
  86. var uploadbutton = K.uploadbutton({
  87. button : K('.ke-upload-button', div)[0],
  88. fieldName : filePostName,
  89. extraParams : extraParams,
  90. url : K.addParam(uploadJson, 'dir=flash'),
  91. afterUpload : function(data) {
  92. dialog.hideLoading();
  93. if (data.error === 0) {
  94. var url = data.url;
  95. if (formatUploadUrl) {
  96. url = K.formatUrl(url, 'absolute');
  97. }
  98. urlBox.val(url);
  99. if (self.afterUpload) {
  100. self.afterUpload.call(self, url, data, name);
  101. }
  102. alert(self.lang('uploadSuccess'));
  103. } else {
  104. alert(data.message);
  105. }
  106. },
  107. afterError : function(html) {
  108. dialog.hideLoading();
  109. self.errorDialog(html);
  110. }
  111. });
  112. uploadbutton.fileBox.change(function(e) {
  113. dialog.showLoading(self.lang('uploadLoading'));
  114. uploadbutton.submit();
  115. });
  116. } else {
  117. K('.ke-upload-button', div).hide();
  118. }
  119. if (allowFileManager) {
  120. viewServerBtn.click(function(e) {
  121. self.loadPlugin('filemanager', function() {
  122. self.plugin.filemanagerDialog({
  123. viewType : 'LIST',
  124. dirName : 'flash',
  125. clickFn : function(url, title) {
  126. if (self.dialogs.length > 1) {
  127. K('[name="url"]', div).val(url);
  128. if (self.afterSelectFile) {
  129. self.afterSelectFile.call(self, url);
  130. }
  131. self.hideDialog();
  132. }
  133. }
  134. });
  135. });
  136. });
  137. } else {
  138. viewServerBtn.hide();
  139. }
  140. var img = self.plugin.getSelectedFlash();
  141. if (img) {
  142. var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
  143. urlBox.val(attrs.src);
  144. widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
  145. heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
  146. }
  147. urlBox[0].focus();
  148. urlBox[0].select();
  149. },
  150. 'delete' : function() {
  151. self.plugin.getSelectedFlash().remove();
  152. // [IE] 删除图片后立即点击图片按钮出错
  153. self.addBookmark();
  154. }
  155. };
  156. self.clickToolbar(name, self.plugin.flash.edit);
  157. });