2011-09-23 03:45:47 +00:00
|
|
|
/*******************************************************************************
|
|
|
|
* KindEditor - WYSIWYG HTML Editor for Internet
|
|
|
|
* Copyright (C) 2006-2011 kindsoft.net
|
|
|
|
*
|
|
|
|
* @author Roddy <luolonghao@gmail.com>
|
|
|
|
* @site http://www.kindsoft.net/
|
|
|
|
* @licence http://www.kindsoft.net/license.php
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
KindEditor.plugin('insertfile', function(K) {
|
|
|
|
var self = this, name = 'insertfile',
|
2012-03-16 02:22:29 +00:00
|
|
|
allowFileManager = K.undef(self.allowFileManager, false),
|
|
|
|
uploadJson = K.undef(self.uploadJson, self.basePath + 'php/upload_json.php'),
|
|
|
|
lang = self.lang(name + '.');
|
|
|
|
|
|
|
|
self.plugin.fileDialog = function(options) {
|
|
|
|
var fileUrl = K.undef(options.fileUrl, 'http://'),
|
|
|
|
fileTitle = K.undef(options.fileTitle, ''),
|
|
|
|
clickFn = options.clickFn;
|
2011-09-23 03:45:47 +00:00
|
|
|
var html = [
|
2012-03-16 02:22:29 +00:00
|
|
|
'<div style="padding:10px 20px;">',
|
|
|
|
'<div class="ke-dialog-row">',
|
|
|
|
'<label for="keUrl" style="width:60px;">' + lang.url + '</label>',
|
|
|
|
'<input type="text" id="keUrl" name="url" class="ke-input-text" style="width:160px;" /> ',
|
|
|
|
'<input type="button" class="ke-upload-button" value="' + lang.upload + '" /> ',
|
|
|
|
'<span class="ke-button-common ke-button-outer">',
|
|
|
|
'<input type="button" class="ke-button-common ke-button" name="viewServer" value="' + lang.viewServer + '" />',
|
|
|
|
'</span>',
|
|
|
|
'</div>',
|
|
|
|
//title
|
|
|
|
'<div class="ke-dialog-row">',
|
|
|
|
'<label for="keTitle" style="width:60px;">' + lang.title + '</label>',
|
|
|
|
'<input type="text" id="keTitle" class="ke-input-text" name="title" value="" style="width:160px;" /></div>',
|
|
|
|
'</div>',
|
|
|
|
//form end
|
|
|
|
'</form>',
|
|
|
|
'</div>'
|
|
|
|
].join('');
|
2011-09-23 03:45:47 +00:00
|
|
|
var dialog = self.createDialog({
|
|
|
|
name : name,
|
|
|
|
width : 450,
|
|
|
|
height : 180,
|
|
|
|
title : self.lang(name),
|
|
|
|
body : html,
|
|
|
|
yesBtn : {
|
|
|
|
name : self.lang('yes'),
|
|
|
|
click : function(e) {
|
2012-03-16 02:22:29 +00:00
|
|
|
var url = K.trim(urlBox.val()),
|
2011-09-23 03:45:47 +00:00
|
|
|
title = titleBox.val();
|
2012-03-16 02:22:29 +00:00
|
|
|
if (url == 'http://' || K.invalidUrl(url)) {
|
|
|
|
alert(self.lang('invalidUrl'));
|
|
|
|
urlBox[0].focus();
|
|
|
|
return;
|
|
|
|
}
|
2011-09-23 03:45:47 +00:00
|
|
|
if (K.trim(title) === '') {
|
|
|
|
title = url;
|
|
|
|
}
|
2012-03-16 02:22:29 +00:00
|
|
|
clickFn.call(self, url, title);
|
2011-09-23 03:45:47 +00:00
|
|
|
}
|
2012-03-16 02:22:29 +00:00
|
|
|
},
|
|
|
|
beforeRemove : function() {
|
|
|
|
viewServerBtn.remove();
|
|
|
|
uploadbutton.remove();
|
2011-09-23 03:45:47 +00:00
|
|
|
}
|
|
|
|
}),
|
|
|
|
div = dialog.div;
|
|
|
|
|
|
|
|
var urlBox = K('[name="url"]', div),
|
|
|
|
viewServerBtn = K('[name="viewServer"]', div),
|
|
|
|
titleBox = K('[name="title"]', div);
|
|
|
|
|
|
|
|
var uploadbutton = K.uploadbutton({
|
|
|
|
button : K('.ke-upload-button', div)[0],
|
|
|
|
fieldName : 'imgFile',
|
2012-03-16 02:22:29 +00:00
|
|
|
url : K.addParam(uploadJson, 'dir=file'),
|
2011-09-23 03:45:47 +00:00
|
|
|
afterUpload : function(data) {
|
2012-03-16 02:22:29 +00:00
|
|
|
dialog.hideLoading();
|
2011-09-23 03:45:47 +00:00
|
|
|
if (data.error === 0) {
|
|
|
|
var url = K.formatUrl(data.url, 'absolute');
|
|
|
|
urlBox.val(url);
|
|
|
|
if (self.afterUpload) {
|
|
|
|
self.afterUpload.call(self, url);
|
|
|
|
}
|
|
|
|
alert(self.lang('uploadSuccess'));
|
|
|
|
} else {
|
|
|
|
alert(data.message);
|
|
|
|
}
|
2012-03-16 02:22:29 +00:00
|
|
|
},
|
|
|
|
afterError : function(html) {
|
|
|
|
dialog.hideLoading();
|
|
|
|
self.errorDialog(html);
|
2011-09-23 03:45:47 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
uploadbutton.fileBox.change(function(e) {
|
2012-03-16 02:22:29 +00:00
|
|
|
dialog.showLoading(self.lang('uploadLoading'));
|
2011-09-23 03:45:47 +00:00
|
|
|
uploadbutton.submit();
|
|
|
|
});
|
|
|
|
if (allowFileManager) {
|
|
|
|
viewServerBtn.click(function(e) {
|
|
|
|
self.loadPlugin('filemanager', function() {
|
|
|
|
self.plugin.filemanagerDialog({
|
|
|
|
viewType : 'LIST',
|
|
|
|
dirName : 'file',
|
|
|
|
clickFn : function(url, title) {
|
|
|
|
if (self.dialogs.length > 1) {
|
|
|
|
K('[name="url"]', div).val(url);
|
|
|
|
self.hideDialog();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
viewServerBtn.hide();
|
|
|
|
}
|
2012-03-16 02:22:29 +00:00
|
|
|
urlBox.val(fileUrl);
|
|
|
|
titleBox.val(fileTitle);
|
2011-09-23 03:45:47 +00:00
|
|
|
urlBox[0].focus();
|
|
|
|
urlBox[0].select();
|
2012-03-16 02:22:29 +00:00
|
|
|
};
|
|
|
|
self.clickToolbar(name, function() {
|
|
|
|
self.plugin.fileDialog({
|
|
|
|
clickFn : function(url, title) {
|
|
|
|
var html = '<a href="' + url + '" data-ke-src="' + url + '" target="_blank">' + title + '</a>';
|
|
|
|
self.insertHtml(html).hideDialog().focus();
|
|
|
|
}
|
|
|
|
});
|
2011-09-23 03:45:47 +00:00
|
|
|
});
|
|
|
|
});
|