flash.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  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. upFlashUrl = K.undef(self.upFlashUrl, false),
  17. uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
  18. self.plugin.flash = {
  19. edit : function() {
  20. var html = [
  21. '<div style="padding:20px;">',
  22. //url
  23. '<div class="ke-dialog-row">',
  24. '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
  25. '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
  26. '<div style="display:none;"><input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;</div>',
  27. '<span class="ke-button-common ke-button-outer">',
  28. '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
  29. '</span>',
  30. '</div>',
  31. //width
  32. '<div class="ke-dialog-row">',
  33. '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
  34. '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" /> ',
  35. '</div>',
  36. //height
  37. '<div class="ke-dialog-row">',
  38. '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
  39. '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" /> ',
  40. '</div>',
  41. '</div>'
  42. ].join('');
  43. var dialog = self.createDialog({
  44. name : name,
  45. width : 450,
  46. title : self.lang(name),
  47. body : html,
  48. yesBtn : {
  49. name : self.lang('yes'),
  50. click : function(e) {
  51. var url = K.trim(urlBox.val()),
  52. width = widthBox.val(),
  53. height = heightBox.val();
  54. if (url == 'http://' || K.invalidUrl(url)) {
  55. alert(self.lang('invalidUrl'));
  56. urlBox[0].focus();
  57. return;
  58. }
  59. if (!/^\d*$/.test(width)) {
  60. alert(self.lang('invalidWidth'));
  61. widthBox[0].focus();
  62. return;
  63. }
  64. if (!/^\d*$/.test(height)) {
  65. alert(self.lang('invalidHeight'));
  66. heightBox[0].focus();
  67. return;
  68. }
  69. var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
  70. src : url,
  71. type : K.mediaType('.swf'),
  72. width : width,
  73. height : height,
  74. quality : 'high'
  75. });
  76. self.insertHtml(html).hideDialog().focus();
  77. }
  78. }
  79. }),
  80. div = dialog.div,
  81. urlBox = K('[name="url"]', div),
  82. viewServerBtn = K('[name="viewServer"]', div),
  83. widthBox = K('[name="width"]', div),
  84. heightBox = K('[name="height"]', div);
  85. urlBox.val('http://');
  86. if (allowFlashUpload) {
  87. var uploadbutton = K.uploadbutton({
  88. button : K('.ke-upload-button', div)[0],
  89. fieldName : filePostName,
  90. extraParams : extraParams,
  91. url : K.addParam(uploadJson, 'dir=flash'),
  92. afterUpload : function(data) {
  93. dialog.hideLoading();
  94. if (data.error === 0) {
  95. var url = data.url;
  96. if (formatUploadUrl) {
  97. url = K.formatUrl(url, 'absolute');
  98. }
  99. urlBox.val(url);
  100. if (self.afterUpload) {
  101. self.afterUpload.call(self, url, data, name);
  102. }
  103. alert(self.lang('uploadSuccess'));
  104. } else {
  105. alert(data.message);
  106. }
  107. },
  108. afterError : function(html) {
  109. dialog.hideLoading();
  110. self.errorDialog(html);
  111. }
  112. });
  113. uploadbutton.fileBox.change(function(e) {
  114. dialog.showLoading(self.lang('uploadLoading'));
  115. uploadbutton.submit();
  116. });
  117. } else {
  118. K('.ke-upload-button', div).hide();
  119. }
  120. if (allowFileManager) {
  121. viewServerBtn.click(function(e) {
  122. self.loadPlugin('filemanager', function() {
  123. self.plugin.filemanagerDialog({
  124. upUrl : upFlashUrl,
  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. }
  153. };
  154. self.clickToolbar(name, self.plugin.flash.edit);
  155. });