flash.js 4.8 KB

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