修正插入
This commit is contained in:
@@ -26,8 +26,55 @@ $(document).ready(function() {
|
||||
onUpload : function (file, id) {
|
||||
$('<li id="' + id + '" class="loading">'
|
||||
+ file + '</li>').prependTo('#file-list');
|
||||
}
|
||||
},
|
||||
onError : function (id, word) {
|
||||
$('#' + id).remove();
|
||||
alert('<?php _e('文件上传失败'); ?>');
|
||||
},
|
||||
onComplete : function (id, url, data) {
|
||||
var li = $('#' + id).removeClass('loading').data('cid', data.cid)
|
||||
.data('url', data.url)
|
||||
.data('image', data.isImage)
|
||||
.html('<input type="hidden" name="attachment[]" value="' + data.cid + '" />'
|
||||
+ '<a class="file" target="_blank" href="<?php $options->adminUrl('media.php'); ?>?cid='
|
||||
+ data.cid + '">' + data.title + '</a> ' + data.bits
|
||||
+ ' <a class="insert" href="#">' + <?php _e('插入'); ?> + '</a>'
|
||||
+ ' <a class="delete" href="#">×</a>')
|
||||
.effect('highlight', '#AACB36', 1000);
|
||||
|
||||
attachInsertEvent(li);
|
||||
attachDeleteEvent(li);
|
||||
},
|
||||
});
|
||||
|
||||
$('#file-list li').each(function () {
|
||||
attachInsertEvent(this);
|
||||
attachDeleteEvent(this);
|
||||
});
|
||||
|
||||
function attachInsertEvent (el) {
|
||||
$('.insert', el).click(function () {
|
||||
var p = $(this).parents('li');
|
||||
Typecho.insertFileToEditor(p.data('url'), p.data('image'));
|
||||
return false;
|
||||
});
|
||||
}
|
||||
|
||||
function attachDeleteEvent (el) {
|
||||
var file = $('a.file', el).text();
|
||||
$('.delete', el).click(function () {
|
||||
if (confirm('<?php _e('确认要删除附件 %s 吗?'); ?>'.replace('%s', file))) {
|
||||
var cid = $(this).parents('li').data('cid');
|
||||
$.post('<?php $options->index('/action/contents-attachment-edit'); ?>',
|
||||
{'do' : 'delete', 'cid' : cid},
|
||||
function () {
|
||||
el.remove();
|
||||
});
|
||||
}
|
||||
|
||||
return false;
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
+3
-87
@@ -12,96 +12,12 @@ if (isset($post) || isset($page)) {
|
||||
}
|
||||
?>
|
||||
|
||||
<!--<style>
|
||||
.upload-progress {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
#upload-panel ul li.upload-progress-item {
|
||||
background-image: url(<?php $options->adminUrl('images/progress.gif'); ?>);
|
||||
background-repeat: repeat-y;
|
||||
background-position: -1000px 0;
|
||||
background-color: #fff;
|
||||
padding: 5px;
|
||||
margin-bottom: 5px;
|
||||
border: 1px solid #C1CD94;
|
||||
|
||||
-moz-border-radius-topleft: 2px;
|
||||
-moz-border-radius-topright: 2px;
|
||||
-moz-border-radius-bottomleft: 2px;
|
||||
-moz-border-radius-bottomright: 2px;
|
||||
-webkit-border-top-left-radius: 2px;
|
||||
-webkit-border-top-right-radius: 2px;
|
||||
-webkit-border-bottom-left-radius: 2px;
|
||||
-webkit-border-bottom-right-radius: 2px;
|
||||
|
||||
/* hope IE support border radius, God save me! */
|
||||
border-top-left-radius: 2px;
|
||||
border-top-right-radius: 2px;
|
||||
border-bottom-left-radius: 2px;
|
||||
border-bottom-right-radius: 2px;
|
||||
}
|
||||
|
||||
.upload-progress-item strong {
|
||||
float: left;
|
||||
}
|
||||
|
||||
.upload-progress-item strong.delete {
|
||||
text-decoration: line-through;
|
||||
}
|
||||
|
||||
.upload-progress-item small {
|
||||
float: right;
|
||||
font-size: 8pt;
|
||||
}
|
||||
|
||||
.upload-progress-item small .insert, .upload-progress-item small .delete {
|
||||
cursor: pointer;
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.upload-progress-item small .insert {
|
||||
color: #00AA00;
|
||||
}
|
||||
|
||||
.upload-progress-item small .delete {
|
||||
color: #CC0000;
|
||||
}
|
||||
</style>
|
||||
|
||||
<div class="typecho-list-operate">
|
||||
<p class="operate">
|
||||
<a class="button"><?php _e('正在加载上传组件'); ?></a>
|
||||
<span id="swfu"><span id="swfu-placeholder"></span></span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<ul class="upload-progress">
|
||||
<?php while ($attachment->next()): ?>
|
||||
<li class="upload-progress-item clearfix">
|
||||
<strong>
|
||||
<?php $attachment->title(); ?>
|
||||
<input type="hidden" name="attachment[]" value="<?php $attachment->cid(); ?>" />
|
||||
</strong>
|
||||
<small>
|
||||
<span class="insert" onclick="<?php if ($attachment->attachment->isImage){
|
||||
echo "insertImageToEditor('{$attachment->title}', '{$attachment->attachment->url}', '{$attachment->permalink}', {$attachment->cid});";
|
||||
} else {
|
||||
echo "insertLinkToEditor('{$attachment->title}', '{$attachment->attachment->url}', '{$attachment->permalink}', {$attachment->cid});";
|
||||
} ?>"><?php _e('插入'); ?></span>
|
||||
,
|
||||
<span class="delete" onclick="deleteAttachment(<?php $attachment->cid(); ?>, this);"><?php _e('删除'); ?></span>
|
||||
</small>
|
||||
</li>
|
||||
<?php endwhile; ?>
|
||||
</ul>-->
|
||||
|
||||
<div id="upload-panel" class="p">
|
||||
将要上传的文件拖放到这里 或者 <a href="" class="upload-file">选择文件上传</a><input type="file" class="visuallyhidden">
|
||||
<ul id="file-list">
|
||||
<li class="loading">widescreen.jpg</li>
|
||||
<li><a href="###">Sample.zip</a> 100KB <a href="###" class="delete">×</a></li>
|
||||
<li><a href="###">segmentfault.profile.png</a> 60KB <a href="###" class="delete">×</a></li>
|
||||
<?php while ($attachment->next()): ?>
|
||||
<li data-cid="<?php $attachment->cid(); ?>" data-url="<?php echo $attachment->attachment->url; ?>" data-image="<?php echo $attachment->attachment->isImage ? 1 : 0; ?>"><input type="hidden" name="attachment[]" value="<?php $attachment->cid(); ?>" /><a class="file" target="_blank" href="<?php $options->adminUrl('media.php?cid=' . $attachment->cid); ?>"><?php $attachment->title(); ?></a> <?php echo number_format(ceil($attachment->attachment->size / 1024)); ?> Kb <a href="#" class="insert">插入</a> <a href="#" class="delete">×</a></li>
|
||||
<?php endwhile; ?>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -1,3 +1,9 @@
|
||||
(function (w) {
|
||||
w.Typecho = {
|
||||
insertFileToEditor : function () {}
|
||||
};
|
||||
})(window);
|
||||
|
||||
(function ($) {
|
||||
// 下拉菜单插件
|
||||
$.fn.dropdownMenu = function (options) {
|
||||
@@ -84,12 +90,14 @@
|
||||
url : null,
|
||||
onUpload : null,
|
||||
onComplete : null,
|
||||
onError : null,
|
||||
types : null,
|
||||
name : 'file',
|
||||
typesError : 'file type error',
|
||||
single : false
|
||||
}, options),
|
||||
p = this.parent().css('position', 'relative'),
|
||||
input = $('<input type="file" />').css({
|
||||
input = $('<input name="' + s.name + '" type="file" />').css({
|
||||
opacity : 0,
|
||||
cursor : 'pointer',
|
||||
position : 'absolute',
|
||||
@@ -100,7 +108,7 @@
|
||||
}).insertAfter(this), queue = {}, prefix = 'queue-',
|
||||
index = 0, types = [];
|
||||
|
||||
window.fileUploadComplete = function (id, url) {
|
||||
window.fileUploadComplete = function (id, url, data) {
|
||||
if (s.single) {
|
||||
input.prop('disabled', false);
|
||||
}
|
||||
@@ -110,7 +118,22 @@
|
||||
delete queue[id];
|
||||
|
||||
if (s.onComplete) {
|
||||
s.onComplete.call(input.get(0), id, url);
|
||||
s.onComplete.call(input.get(0), id, url, data);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
window.fileUploadError = function (id, word) {
|
||||
if (s.single) {
|
||||
input.prop('disabled', false);
|
||||
}
|
||||
|
||||
if (!!id && queue[id]) {
|
||||
queue[id].remove();
|
||||
delete queue[id];
|
||||
|
||||
if (s.onError) {
|
||||
s.onError.call(input.get(0), id, word);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -118,7 +141,9 @@
|
||||
if (!!s.types) {
|
||||
var list = s.types.split(';');
|
||||
for (var i = 0; i < list.length; i ++) {
|
||||
types.push(list[i].split('.').pop());
|
||||
var parts = list[i].split('.');
|
||||
parts.shift();
|
||||
types.push('.' + parts.join('.'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,8 +166,19 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
var type = file.split('.').pop();
|
||||
return $.inArray(types, type) >= 0;
|
||||
for (var i = 0; i < types.length; i ++) {
|
||||
var ext = types[i];
|
||||
|
||||
if (file.length <= ext.length) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ext == file.substring(file.length - ext.length)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
input.change(function () {
|
||||
|
||||
Reference in New Issue
Block a user