Commit c10b6c9d authored by Vanessa's avatar Vanessa

fixed #144

parent 2b112f73
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
*/ */
package org.b3log.solo.event.rhythm; package org.b3log.solo.event.rhythm;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.util.Date; import java.util.Date;
...@@ -38,6 +39,7 @@ import org.b3log.solo.model.Preference; ...@@ -38,6 +39,7 @@ import org.b3log.solo.model.Preference;
import org.b3log.solo.service.PreferenceQueryService; import org.b3log.solo.service.PreferenceQueryService;
import org.json.JSONObject; import org.json.JSONObject;
/** /**
* This listener is responsible for updating article to B3log Rhythm. * This listener is responsible for updating article to B3log Rhythm.
* *
...@@ -85,7 +87,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> { ...@@ -85,7 +87,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> {
final JSONObject data = event.getData(); final JSONObject data = event.getData();
LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]", LOGGER.log(Level.FINER, "Processing an event[type={0}, data={1}] in listener[className={2}]",
new Object[]{event.getType(), data, ArticleUpdater.class.getName()}); new Object[] {event.getType(), data, ArticleUpdater.class.getName()});
try { try {
final JSONObject originalArticle = data.getJSONObject(Article.ARTICLE); final JSONObject originalArticle = data.getJSONObject(Article.ARTICLE);
...@@ -107,7 +109,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> { ...@@ -107,7 +109,7 @@ public final class ArticleUpdater extends AbstractEventListener<JSONObject> {
if (blogHost.contains("localhost")) { if (blogHost.contains("localhost")) {
LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not send this article[id={0}, title={1}] to Rhythm", LOGGER.log(Level.INFO, "Blog Solo runs on local server, so should not send this article[id={0}, title={1}] to Rhythm",
new Object[]{originalArticle.getString(Keys.OBJECT_ID), originalArticle.getString(Article.ARTICLE_TITLE)}); new Object[] {originalArticle.getString(Keys.OBJECT_ID), originalArticle.getString(Article.ARTICLE_TITLE)});
return; return;
} }
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
*/ */
/** /**
* @fileoverview KindEditor * @fileoverview KindEditor
* @description 修改点:plugins/image/image.js 注释 173-176
* plugins/media/media.js 注释 26 & 28
* *
* @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a> * @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
* @version 1.0.0.2, Jun 19, 2012 * @version 1.0.0.2, Jun 19, 2012
......
...@@ -482,6 +482,8 @@ admin.editors.tinyMCE = { ...@@ -482,6 +482,8 @@ admin.editors.tinyMCE = {
*/ */
/** /**
* @fileoverview KindEditor * @fileoverview KindEditor
* @description 修改点:plugins/image/image.js 注释 173-176
* plugins/media/media.js 注释 26 & 28
* *
* @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a> * @author <a href="mailto:LLY219@gmail.com">Liyuan Li</a>
* @version 1.0.0.2, Jun 19, 2012 * @version 1.0.0.2, Jun 19, 2012
......
/******************************************************************************* /*******************************************************************************
* KindEditor - WYSIWYG HTML Editor for Internet * KindEditor - WYSIWYG HTML Editor for Internet
* Copyright (C) 2006-2011 kindsoft.net * Copyright (C) 2006-2011 kindsoft.net
* *
* @author Roddy <luolonghao@gmail.com> * @author Roddy <luolonghao@gmail.com>
* @site http://www.kindsoft.net/ * @site http://www.kindsoft.net/
* @licence http://www.kindsoft.net/license.php * @licence http://www.kindsoft.net/license.php
*******************************************************************************/ *******************************************************************************/
KindEditor.plugin('image', function(K) { KindEditor.plugin('image', function(K) {
var self = this, name = 'image', var self = this, name = 'image',
allowImageUpload = K.undef(self.allowImageUpload, true), allowImageUpload = K.undef(self.allowImageUpload, true),
formatUploadUrl = K.undef(self.formatUploadUrl, true), formatUploadUrl = K.undef(self.formatUploadUrl, true),
allowFileManager = K.undef(self.allowFileManager, false), allowFileManager = K.undef(self.allowFileManager, false),
uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'), uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
imageTabIndex = K.undef(self.imageTabIndex, 0), imageTabIndex = K.undef(self.imageTabIndex, 0),
imgPath = self.pluginsPath + 'image/images/', imgPath = self.pluginsPath + 'image/images/',
extraParams = K.undef(self.extraFileUploadParams, {}), extraParams = K.undef(self.extraFileUploadParams, {}),
filePostName = K.undef(self.filePostName, 'imgFile'), filePostName = K.undef(self.filePostName, 'imgFile'),
fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false), fillDescAfterUploadImage = K.undef(self.fillDescAfterUploadImage, false),
lang = self.lang(name + '.'); lang = self.lang(name + '.');
self.plugin.imageDialog = function(options) { self.plugin.imageDialog = function(options) {
var imageUrl = options.imageUrl, var imageUrl = options.imageUrl,
imageWidth = K.undef(options.imageWidth, ''), imageWidth = K.undef(options.imageWidth, ''),
imageHeight = K.undef(options.imageHeight, ''), imageHeight = K.undef(options.imageHeight, ''),
imageTitle = K.undef(options.imageTitle, ''), imageTitle = K.undef(options.imageTitle, ''),
imageAlign = K.undef(options.imageAlign, ''), imageAlign = K.undef(options.imageAlign, ''),
showRemote = K.undef(options.showRemote, true), showRemote = K.undef(options.showRemote, true),
showLocal = K.undef(options.showLocal, true), showLocal = K.undef(options.showLocal, true),
tabIndex = K.undef(options.tabIndex, 0), tabIndex = K.undef(options.tabIndex, 0),
clickFn = options.clickFn; clickFn = options.clickFn;
var target = 'kindeditor_upload_iframe_' + new Date().getTime(); var target = 'kindeditor_upload_iframe_' + new Date().getTime();
var hiddenElements = []; var hiddenElements = [];
for(var k in extraParams){ for(var k in extraParams){
hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />'); hiddenElements.push('<input type="hidden" name="' + k + '" value="' + extraParams[k] + '" />');
} }
var html = [ var html = [
'<div style="padding:20px;">', '<div style="padding:20px;">',
//tabs //tabs
'<div class="tabs"></div>', '<div class="tabs"></div>',
//remote image - start //remote image - start
'<div class="tab1" style="display:none;">', '<div class="tab1" style="display:none;">',
//url //url
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
'<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>', '<label for="remoteUrl" style="width:60px;">' + lang.remoteUrl + '</label>',
'<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;', '<input type="text" id="remoteUrl" class="ke-input-text" name="url" value="" style="width:200px;" /> &nbsp;',
'<span class="ke-button-common ke-button-outer">', '<span class="ke-button-common ke-button-outer">',
'<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />', '<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
'</span>', '</span>',
'</div>', '</div>',
//size //size
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
'<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>', '<label for="remoteWidth" style="width:60px;">' + lang.size + '</label>',
lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ', lang.width + ' <input type="text" id="remoteWidth" class="ke-input-text ke-input-number" name="width" value="" maxlength="4" /> ',
lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ', lang.height + ' <input type="text" class="ke-input-text ke-input-number" name="height" value="" maxlength="4" /> ',
'<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />', '<img class="ke-refresh-btn" src="' + imgPath + 'refresh.png" width="16" height="16" alt="" style="cursor:pointer;" title="' + lang.resetSize + '" />',
'</div>', '</div>',
//align //align
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
'<label style="width:60px;">' + lang.align + '</label>', '<label style="width:60px;">' + lang.align + '</label>',
'<input type="radio" name="align" class="ke-inline-block" value="" checked="checked" /> <img name="defaultImg" src="' + imgPath + 'align_top.gif" width="23" height="25" alt="" />', '<input type="radio" name="align" class="ke-inline-block" value="" checked="checked" /> <img name="defaultImg" src="' + imgPath + 'align_top.gif" width="23" height="25" alt="" />',
' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />', ' <input type="radio" name="align" class="ke-inline-block" value="left" /> <img name="leftImg" src="' + imgPath + 'align_left.gif" width="23" height="25" alt="" />',
' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />', ' <input type="radio" name="align" class="ke-inline-block" value="right" /> <img name="rightImg" src="' + imgPath + 'align_right.gif" width="23" height="25" alt="" />',
'</div>', '</div>',
//title //title
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
'<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>', '<label for="remoteTitle" style="width:60px;">' + lang.imgTitle + '</label>',
'<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />', '<input type="text" id="remoteTitle" class="ke-input-text" name="title" value="" style="width:200px;" />',
'</div>', '</div>',
'</div>', '</div>',
//remote image - end //remote image - end
//local upload - start //local upload - start
'<div class="tab2" style="display:none;">', '<div class="tab2" style="display:none;">',
'<iframe name="' + target + '" style="display:none;"></iframe>', '<iframe name="' + target + '" style="display:none;"></iframe>',
'<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">', '<form class="ke-upload-area ke-form" method="post" enctype="multipart/form-data" target="' + target + '" action="' + K.addParam(uploadJson, 'dir=image') + '">',
//file //file
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
hiddenElements.join(''), hiddenElements.join(''),
'<label style="width:60px;">' + lang.localUrl + '</label>', '<label style="width:60px;">' + lang.localUrl + '</label>',
'<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;', '<input type="text" name="localUrl" class="ke-input-text" tabindex="-1" style="width:200px;" readonly="true" /> &nbsp;',
'<input type="button" class="ke-upload-button" value="' + lang.upload + '" />', '<input type="button" class="ke-upload-button" value="' + lang.upload + '" />',
'</div>', '</div>',
'</form>', '</form>',
'</div>', '</div>',
//local upload - end //local upload - end
'</div>' '</div>'
].join(''); ].join('');
var dialogWidth = showLocal || allowFileManager ? 450 : 400, var dialogWidth = showLocal || allowFileManager ? 450 : 400,
dialogHeight = showLocal && showRemote ? 300 : 250; dialogHeight = showLocal && showRemote ? 300 : 250;
var dialog = self.createDialog({ var dialog = self.createDialog({
name : name, name : name,
width : dialogWidth, width : dialogWidth,
height : dialogHeight, height : dialogHeight,
title : self.lang(name), title : self.lang(name),
body : html, body : html,
yesBtn : { yesBtn : {
name : self.lang('yes'), name : self.lang('yes'),
click : function(e) { click : function(e) {
// Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319 // Bugfix: http://code.google.com/p/kindeditor/issues/detail?id=319
if (dialog.isLoading) { if (dialog.isLoading) {
return; return;
} }
// insert local image // insert local image
if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) { if (showLocal && showRemote && tabs && tabs.selectedIndex === 1 || !showRemote) {
if (uploadbutton.fileBox.val() == '') { if (uploadbutton.fileBox.val() == '') {
alert(self.lang('pleaseSelectFile')); alert(self.lang('pleaseSelectFile'));
return; return;
} }
dialog.showLoading(self.lang('uploadLoading')); dialog.showLoading(self.lang('uploadLoading'));
uploadbutton.submit(); uploadbutton.submit();
localUrlBox.val(''); localUrlBox.val('');
return; return;
} }
// insert remote image // insert remote image
var url = K.trim(urlBox.val()), var url = K.trim(urlBox.val()),
width = widthBox.val(), width = widthBox.val(),
height = heightBox.val(), height = heightBox.val(),
title = titleBox.val(), title = titleBox.val(),
align = ''; align = '';
alignBox.each(function() { alignBox.each(function() {
if (this.checked) { if (this.checked) {
align = this.value; align = this.value;
return false; return false;
} }
}); });
if (url == 'http://' || K.invalidUrl(url)) { if (url == 'http://' || K.invalidUrl(url)) {
alert(self.lang('invalidUrl')); alert(self.lang('invalidUrl'));
urlBox[0].focus(); urlBox[0].focus();
return; return;
} }
if (!/^\d*$/.test(width)) { if (!/^\d*$/.test(width)) {
alert(self.lang('invalidWidth')); alert(self.lang('invalidWidth'));
widthBox[0].focus(); widthBox[0].focus();
return; return;
} }
if (!/^\d*$/.test(height)) { if (!/^\d*$/.test(height)) {
alert(self.lang('invalidHeight')); alert(self.lang('invalidHeight'));
heightBox[0].focus(); heightBox[0].focus();
return; return;
} }
clickFn.call(self, url, title, width, height, 0, align); clickFn.call(self, url, title, width, height, 0, align);
} }
}, },
beforeRemove : function() { beforeRemove : function() {
viewServerBtn.unbind(); viewServerBtn.unbind();
widthBox.unbind(); widthBox.unbind();
heightBox.unbind(); heightBox.unbind();
refreshBtn.unbind(); refreshBtn.unbind();
} }
}), }),
div = dialog.div; div = dialog.div;
var urlBox = K('[name="url"]', div), var urlBox = K('[name="url"]', div),
localUrlBox = K('[name="localUrl"]', div), localUrlBox = K('[name="localUrl"]', div),
viewServerBtn = K('[name="viewServer"]', div), viewServerBtn = K('[name="viewServer"]', div),
widthBox = K('.tab1 [name="width"]', div), widthBox = K('.tab1 [name="width"]', div),
heightBox = K('.tab1 [name="height"]', div), heightBox = K('.tab1 [name="height"]', div),
refreshBtn = K('.ke-refresh-btn', div), refreshBtn = K('.ke-refresh-btn', div),
titleBox = K('.tab1 [name="title"]', div), titleBox = K('.tab1 [name="title"]', div),
alignBox = K('.tab1 [name="align"]', div); alignBox = K('.tab1 [name="align"]', div);
var tabs; var tabs;
if (showRemote && showLocal) { if (showRemote && showLocal) {
tabs = K.tabs({ tabs = K.tabs({
src : K('.tabs', div), src : K('.tabs', div),
afterSelect : function(i) {} afterSelect : function(i) {}
}); });
tabs.add({ tabs.add({
title : lang.remoteImage, title : lang.remoteImage,
panel : K('.tab1', div) panel : K('.tab1', div)
}); });
tabs.add({ // tabs.add({
title : lang.localImage, // title : lang.localImage,
panel : K('.tab2', div) // panel : K('.tab2', div)
}); // });
tabs.select(tabIndex); tabs.select(tabIndex);
} else if (showRemote) { } else if (showRemote) {
K('.tab1', div).show(); K('.tab1', div).show();
} else if (showLocal) { } else if (showLocal) {
K('.tab2', div).show(); K('.tab2', div).show();
} }
var uploadbutton = K.uploadbutton({ var uploadbutton = K.uploadbutton({
button : K('.ke-upload-button', div)[0], button : K('.ke-upload-button', div)[0],
fieldName : filePostName, fieldName : filePostName,
url : K.addParam(uploadJson, 'dir=image'), url : K.addParam(uploadJson, 'dir=image'),
form : K('.ke-form', div), form : K('.ke-form', div),
target : target, target : target,
width: 60, width: 60,
afterUpload : function(data) { afterUpload : function(data) {
dialog.hideLoading(); dialog.hideLoading();
if (data.error === 0) { if (data.error === 0) {
var url = data.url; var url = data.url;
if (formatUploadUrl) { if (formatUploadUrl) {
url = K.formatUrl(url, 'absolute'); url = K.formatUrl(url, 'absolute');
} }
if (self.afterUpload) { if (self.afterUpload) {
self.afterUpload.call(self, url, data, name); self.afterUpload.call(self, url, data, name);
} }
if (!fillDescAfterUploadImage) { if (!fillDescAfterUploadImage) {
clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align); clickFn.call(self, url, data.title, data.width, data.height, data.border, data.align);
} else { } else {
K(".ke-dialog-row #remoteUrl", div).val(url); K(".ke-dialog-row #remoteUrl", div).val(url);
K(".ke-tabs-li", div)[0].click(); K(".ke-tabs-li", div)[0].click();
K(".ke-refresh-btn", div).click(); K(".ke-refresh-btn", div).click();
} }
} else { } else {
alert(data.message); alert(data.message);
} }
}, },
afterError : function(html) { afterError : function(html) {
dialog.hideLoading(); dialog.hideLoading();
self.errorDialog(html); self.errorDialog(html);
} }
}); });
uploadbutton.fileBox.change(function(e) { uploadbutton.fileBox.change(function(e) {
localUrlBox.val(uploadbutton.fileBox.val()); localUrlBox.val(uploadbutton.fileBox.val());
}); });
if (allowFileManager) { if (allowFileManager) {
viewServerBtn.click(function(e) { viewServerBtn.click(function(e) {
self.loadPlugin('filemanager', function() { self.loadPlugin('filemanager', function() {
self.plugin.filemanagerDialog({ self.plugin.filemanagerDialog({
viewType : 'VIEW', viewType : 'VIEW',
dirName : 'image', dirName : 'image',
clickFn : function(url, title) { clickFn : function(url, title) {
if (self.dialogs.length > 1) { if (self.dialogs.length > 1) {
K('[name="url"]', div).val(url); K('[name="url"]', div).val(url);
if (self.afterSelectFile) { if (self.afterSelectFile) {
self.afterSelectFile.call(self, url); self.afterSelectFile.call(self, url);
} }
self.hideDialog(); self.hideDialog();
} }
} }
}); });
}); });
}); });
} else { } else {
viewServerBtn.hide(); viewServerBtn.hide();
} }
var originalWidth = 0, originalHeight = 0; var originalWidth = 0, originalHeight = 0;
function setSize(width, height) { function setSize(width, height) {
widthBox.val(width); widthBox.val(width);
heightBox.val(height); heightBox.val(height);
originalWidth = width; originalWidth = width;
originalHeight = height; originalHeight = height;
} }
refreshBtn.click(function(e) { refreshBtn.click(function(e) {
var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({ var tempImg = K('<img src="' + urlBox.val() + '" />', document).css({
position : 'absolute', position : 'absolute',
visibility : 'hidden', visibility : 'hidden',
top : 0, top : 0,
left : '-1000px' left : '-1000px'
}); });
tempImg.bind('load', function() { tempImg.bind('load', function() {
setSize(tempImg.width(), tempImg.height()); setSize(tempImg.width(), tempImg.height());
tempImg.remove(); tempImg.remove();
}); });
K(document.body).append(tempImg); K(document.body).append(tempImg);
}); });
widthBox.change(function(e) { widthBox.change(function(e) {
if (originalWidth > 0) { if (originalWidth > 0) {
heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10))); heightBox.val(Math.round(originalHeight / originalWidth * parseInt(this.value, 10)));
} }
}); });
heightBox.change(function(e) { heightBox.change(function(e) {
if (originalHeight > 0) { if (originalHeight > 0) {
widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10))); widthBox.val(Math.round(originalWidth / originalHeight * parseInt(this.value, 10)));
} }
}); });
urlBox.val(options.imageUrl); urlBox.val(options.imageUrl);
setSize(options.imageWidth, options.imageHeight); setSize(options.imageWidth, options.imageHeight);
titleBox.val(options.imageTitle); titleBox.val(options.imageTitle);
alignBox.each(function() { alignBox.each(function() {
if (this.value === options.imageAlign) { if (this.value === options.imageAlign) {
this.checked = true; this.checked = true;
return false; return false;
} }
}); });
if (tabIndex === 0) { if (tabIndex === 0) {
urlBox[0].focus(); urlBox[0].focus();
urlBox[0].select(); urlBox[0].select();
} }
return dialog; return dialog;
}; };
self.plugin.image = { self.plugin.image = {
edit : function() { edit : function() {
var img = self.plugin.getSelectedImage(); var img = self.plugin.getSelectedImage();
self.plugin.imageDialog({ self.plugin.imageDialog({
imageUrl : img ? img.attr('data-ke-src') : 'http://', imageUrl : img ? img.attr('data-ke-src') : 'http://',
imageWidth : img ? img.width() : '', imageWidth : img ? img.width() : '',
imageHeight : img ? img.height() : '', imageHeight : img ? img.height() : '',
imageTitle : img ? img.attr('title') : '', imageTitle : img ? img.attr('title') : '',
imageAlign : img ? img.attr('align') : '', imageAlign : img ? img.attr('align') : '',
showRemote : true, showRemote : true,
showLocal : allowImageUpload, showLocal : allowImageUpload,
tabIndex: img ? 0 : imageTabIndex, tabIndex: img ? 0 : imageTabIndex,
clickFn : function(url, title, width, height, border, align) { clickFn : function(url, title, width, height, border, align) {
self.exec('insertimage', url, title, width, height, border, align); self.exec('insertimage', url, title, width, height, border, align);
// Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog // Bugfix: [Firefox] 上传图片后,总是出现正在加载的样式,需要延迟执行hideDialog
setTimeout(function() { setTimeout(function() {
self.hideDialog().focus(); self.hideDialog().focus();
}, 0); }, 0);
} }
}); });
}, },
'delete' : function() { 'delete' : function() {
var target = self.plugin.getSelectedImage(); var target = self.plugin.getSelectedImage();
if (target.parent().name == 'a') { if (target.parent().name == 'a') {
target = target.parent(); target = target.parent();
} }
target.remove(); target.remove();
} }
}; };
self.clickToolbar(name, self.plugin.image.edit); self.clickToolbar(name, self.plugin.image.edit);
}); });
/******************************************************************************* /*******************************************************************************
* KindEditor - WYSIWYG HTML Editor for Internet * KindEditor - WYSIWYG HTML Editor for Internet
* Copyright (C) 2006-2011 kindsoft.net * Copyright (C) 2006-2011 kindsoft.net
* *
* @author Roddy <luolonghao@gmail.com> * @author Roddy <luolonghao@gmail.com>
* @site http://www.kindsoft.net/ * @site http://www.kindsoft.net/
* @licence http://www.kindsoft.net/license.php * @licence http://www.kindsoft.net/license.php
*******************************************************************************/ *******************************************************************************/
KindEditor.plugin('media', function(K) { KindEditor.plugin('media', function(K) {
var self = this, name = 'media', lang = self.lang(name + '.'), var self = this, name = 'media', lang = self.lang(name + '.'),
allowMediaUpload = K.undef(self.allowMediaUpload, true), allowMediaUpload = K.undef(self.allowMediaUpload, true),
allowFileManager = K.undef(self.allowFileManager, false), allowFileManager = K.undef(self.allowFileManager, false),
formatUploadUrl = K.undef(self.formatUploadUrl, true), formatUploadUrl = K.undef(self.formatUploadUrl, true),
extraParams = K.undef(self.extraFileUploadParams, {}), extraParams = K.undef(self.extraFileUploadParams, {}),
filePostName = K.undef(self.filePostName, 'imgFile'), filePostName = K.undef(self.filePostName, 'imgFile'),
uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'); uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php');
self.plugin.media = { self.plugin.media = {
edit : function() { edit : function() {
var html = [ var html = [
'<div style="padding:20px;">', '<div style="padding:20px;">',
//url //url
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
'<label for="keUrl" style="width:60px;">' + lang.url + '</label>', '<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
'<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;', '<input class="ke-input-text" type="text" id="keUrl" name="url" value="" style="width:160px;" /> &nbsp;',
'<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;', //'<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> &nbsp;',
'<span class="ke-button-common ke-button-outer">', '<span class="ke-button-common ke-button-outer">',
'<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />', //'<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
'</span>', '</span>',
'</div>', '</div>',
//width //width
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
'<label for="keWidth" style="width:60px;">' + lang.width + '</label>', '<label for="keWidth" style="width:60px;">' + lang.width + '</label>',
'<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />', '<input type="text" id="keWidth" class="ke-input-text ke-input-number" name="width" value="550" maxlength="4" />',
'</div>', '</div>',
//height //height
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
'<label for="keHeight" style="width:60px;">' + lang.height + '</label>', '<label for="keHeight" style="width:60px;">' + lang.height + '</label>',
'<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />', '<input type="text" id="keHeight" class="ke-input-text ke-input-number" name="height" value="400" maxlength="4" />',
'</div>', '</div>',
//autostart //autostart
'<div class="ke-dialog-row">', '<div class="ke-dialog-row">',
'<label for="keAutostart">' + lang.autostart + '</label>', '<label for="keAutostart">' + lang.autostart + '</label>',
'<input type="checkbox" id="keAutostart" name="autostart" value="" /> ', '<input type="checkbox" id="keAutostart" name="autostart" value="" /> ',
'</div>', '</div>',
'</div>' '</div>'
].join(''); ].join('');
var dialog = self.createDialog({ var dialog = self.createDialog({
name : name, name : name,
width : 450, width : 450,
height : 230, height : 230,
title : self.lang(name), title : self.lang(name),
body : html, body : html,
yesBtn : { yesBtn : {
name : self.lang('yes'), name : self.lang('yes'),
click : function(e) { click : function(e) {
var url = K.trim(urlBox.val()), var url = K.trim(urlBox.val()),
width = widthBox.val(), width = widthBox.val(),
height = heightBox.val(); height = heightBox.val();
if (url == 'http://' || K.invalidUrl(url)) { if (url == 'http://' || K.invalidUrl(url)) {
alert(self.lang('invalidUrl')); alert(self.lang('invalidUrl'));
urlBox[0].focus(); urlBox[0].focus();
return; return;
} }
if (!/^\d*$/.test(width)) { if (!/^\d*$/.test(width)) {
alert(self.lang('invalidWidth')); alert(self.lang('invalidWidth'));
widthBox[0].focus(); widthBox[0].focus();
return; return;
} }
if (!/^\d*$/.test(height)) { if (!/^\d*$/.test(height)) {
alert(self.lang('invalidHeight')); alert(self.lang('invalidHeight'));
heightBox[0].focus(); heightBox[0].focus();
return; return;
} }
var html = K.mediaImg(self.themesPath + 'common/blank.gif', { var html = K.mediaImg(self.themesPath + 'common/blank.gif', {
src : url, src : url,
type : K.mediaType(url), type : K.mediaType(url),
width : width, width : width,
height : height, height : height,
autostart : autostartBox[0].checked ? 'true' : 'false', autostart : autostartBox[0].checked ? 'true' : 'false',
loop : 'true' loop : 'true'
}); });
self.insertHtml(html).hideDialog().focus(); self.insertHtml(html).hideDialog().focus();
} }
} }
}), }),
div = dialog.div, div = dialog.div,
urlBox = K('[name="url"]', div), urlBox = K('[name="url"]', div),
viewServerBtn = K('[name="viewServer"]', div), viewServerBtn = K('[name="viewServer"]', div),
widthBox = K('[name="width"]', div), widthBox = K('[name="width"]', div),
heightBox = K('[name="height"]', div), heightBox = K('[name="height"]', div),
autostartBox = K('[name="autostart"]', div); autostartBox = K('[name="autostart"]', div);
urlBox.val('http://'); urlBox.val('http://');
if (allowMediaUpload) { if (allowMediaUpload) {
var uploadbutton = K.uploadbutton({ var uploadbutton = K.uploadbutton({
button : K('.ke-upload-button', div)[0], button : K('.ke-upload-button', div)[0],
fieldName : filePostName, fieldName : filePostName,
extraParams : extraParams, extraParams : extraParams,
url : K.addParam(uploadJson, 'dir=media'), url : K.addParam(uploadJson, 'dir=media'),
afterUpload : function(data) { afterUpload : function(data) {
dialog.hideLoading(); dialog.hideLoading();
if (data.error === 0) { if (data.error === 0) {
var url = data.url; var url = data.url;
if (formatUploadUrl) { if (formatUploadUrl) {
url = K.formatUrl(url, 'absolute'); url = K.formatUrl(url, 'absolute');
} }
urlBox.val(url); urlBox.val(url);
if (self.afterUpload) { if (self.afterUpload) {
self.afterUpload.call(self, url, data, name); self.afterUpload.call(self, url, data, name);
} }
alert(self.lang('uploadSuccess')); alert(self.lang('uploadSuccess'));
} else { } else {
alert(data.message); alert(data.message);
} }
}, },
afterError : function(html) { afterError : function(html) {
dialog.hideLoading(); dialog.hideLoading();
self.errorDialog(html); self.errorDialog(html);
} }
}); });
uploadbutton.fileBox.change(function(e) { uploadbutton.fileBox.change(function(e) {
dialog.showLoading(self.lang('uploadLoading')); dialog.showLoading(self.lang('uploadLoading'));
uploadbutton.submit(); uploadbutton.submit();
}); });
} else { } else {
K('.ke-upload-button', div).hide(); K('.ke-upload-button', div).hide();
} }
if (allowFileManager) { if (allowFileManager) {
viewServerBtn.click(function(e) { viewServerBtn.click(function(e) {
self.loadPlugin('filemanager', function() { self.loadPlugin('filemanager', function() {
self.plugin.filemanagerDialog({ self.plugin.filemanagerDialog({
viewType : 'LIST', viewType : 'LIST',
dirName : 'media', dirName : 'media',
clickFn : function(url, title) { clickFn : function(url, title) {
if (self.dialogs.length > 1) { if (self.dialogs.length > 1) {
K('[name="url"]', div).val(url); K('[name="url"]', div).val(url);
if (self.afterSelectFile) { if (self.afterSelectFile) {
self.afterSelectFile.call(self, url); self.afterSelectFile.call(self, url);
} }
self.hideDialog(); self.hideDialog();
} }
} }
}); });
}); });
}); });
} else { } else {
viewServerBtn.hide(); viewServerBtn.hide();
} }
var img = self.plugin.getSelectedMedia(); var img = self.plugin.getSelectedMedia();
if (img) { if (img) {
var attrs = K.mediaAttrs(img.attr('data-ke-tag')); var attrs = K.mediaAttrs(img.attr('data-ke-tag'));
urlBox.val(attrs.src); urlBox.val(attrs.src);
widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0); widthBox.val(K.removeUnit(img.css('width')) || attrs.width || 0);
heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0); heightBox.val(K.removeUnit(img.css('height')) || attrs.height || 0);
autostartBox[0].checked = (attrs.autostart === 'true'); autostartBox[0].checked = (attrs.autostart === 'true');
} }
urlBox[0].focus(); urlBox[0].focus();
urlBox[0].select(); urlBox[0].select();
}, },
'delete' : function() { 'delete' : function() {
self.plugin.getSelectedMedia().remove(); self.plugin.getSelectedMedia().remove();
} }
}; };
self.clickToolbar(name, self.plugin.media.edit); self.clickToolbar(name, self.plugin.media.edit);
}); });
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment