用过Joomla 2.5的朋友应该都知道插入很多图像时是比較麻烦的。点了文章以下的图片button,它会弹出个div,让你选择图片,每选一张。div就关闭。

再选第二张的时候,它又要你又一次选择文件夹。对于我常常要一次插入10张图片以上的非常麻烦。

(这里借用官网的图片。以下把这里叫sbox)

当然了,这是Joomla自带的插入图片的快捷button。我用的TinyMCE的图片插入更朴素:

我一直在找一种便于插入图片的方法。

本来是想升级editor到TinyMCE 4的,但是我的Joomla是Synology自带的应用。跟官方的Joomla不太一样,升级不了。

想用JCE 2.6,安装之后死活出不来编辑器的界面,查了一下好多人也有这问题。并且能一边预览一边插入的好像也不多。

仅仅好自己动手了,

1. 思路:

在点击“图片”button后将TinyMCE editor中的文章的HTML源代码载入到sbox中,然后一边浏览图片一边将图片地址插入到文章的HTML源代码中,这个过程中sbox的div窗体不关闭。

等终于图片插入完成后,点一个自己添加的button,将文章返回给TinyMCE editor。同一时候关闭窗体。

2. 草案:

须要添加一个textarea。来放置文章的源码。一个button。title="OK",用来在完毕后返回文章编辑界面。

同一时候要改动自带的Insert的行为。

3. 代码:

a. joomla->administrator->components->com_media->views->images->tmpl->default.php的终于代码。(这里相应图片选择器)

<?php
/**
* @package Joomla.Administrator
* @subpackage com_media
* @copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/ // No direct access.
defined('_JEXEC') or die;
$user = JFactory::getUser();
? >
<script type='text/javascript'>
var image_base_path = '<?php $params = JComponentHelper::getParams('com_media');
echo $params->get('image_path', 'images');?>/';
//Added by henry var $$ = function(func){
var oldOnload =window.onload;
if(typeof window.onload != 'function'){
window.onload = func;
}else{
window.onload = function(){
oldOnload();
func();
}
}
} $$(function(){
console.dir(parent);
document.getElementById('htmlSourceForImage').value = parent.tinyMCE.editors.getLast().getContent({source_view : true})
}) function insertText(obj,str) {
if (document.selection) {
var sel = document.selection.createRange();
sel.text = str;
} else if (typeof obj.selectionStart === 'number' && typeof obj.selectionEnd === 'number') {
var startPos = obj.selectionStart,
endPos = obj.selectionEnd,
cursorPos = startPos,
tmpStr = obj.value;
obj.value = tmpStr.substring(0, startPos) + str + tmpStr.substring(endPos, tmpStr.length);
cursorPos += str.length;
obj.selectionStart = obj.selectionEnd = cursorPos;
} else {
obj.value += str;
}
} function insertImageToContent() {
extra = '';
// Get the image tag field information
var url = document.getElementById('f_url').value;
var alt = document.getElementById('f_alt').value;
var align = document.getElementById('f_align').value;
var title = document.getElementById('f_title').value;
var caption = document.getElementById('f_caption').value; if (url != '') {
// Set alt attribute
if (alt != '') {
extra = extra + 'alt="'+alt+'" ';
} else {
extra = extra + 'alt="" ';
}
// Set align attribute
if (align != '') {
extra = extra + 'align="'+align+'" ';
}
// Set align attribute
if (title != '') {
extra = extra + 'title="'+title+'" ';
}
// Set align attribute
if (caption != '') {
extra = extra + 'class="caption" ';
} var tag = "<img src=\""+url+"\" "+extra+"/>";
}
insertText(document.getElementById('htmlSourceForImage'), tag);
} function saveContent() {
parent.tinyMCE.editors.getLast().setContent(document.getElementById('htmlSourceForImage').value, {source_view : true});
} //Ended by henry
</script>
<form action="index.php?option=com_media&asset=<? php echo JRequest::getCmd('asset');? >&author=<?php echo JRequest::getCmd('author');? >" id="imageForm" method="post" enctype="multipart/form-data">
<div id="messages" style="display: none;">
<span id="message"></span><? php echo JHtml::_('image', 'media/dots.gif', '...', array('width' =>22, 'height' => 12), true)?>
</div>
<fieldset>
<div class="fltlft">
<label for="folder"><?php echo JText::_('COM_MEDIA_DIRECTORY') ?></label>
<?php echo $this->folderList; ? >
<button type="button" id="upbutton" title="<?php echo JText::_('COM_MEDIA_DIRECTORY_UP') ?>"><?php echo JText::_('COM_MEDIA_UP') ?></button>
</div>
<div class="fltrt">
<!-- added by henry -->
<button type="button" onclick="insertImageToContent();" title="Insert image tag in article content HTML code below and do NOT close this window">Insert</button>
<button type="button" onclick="saveContent(); window.parent.SqueezeBox.close();" title="Set HTML code of editor with below and close this window">OK</button>
<!-- ended by henry -->
<button type="button" onclick="<? php if ($this->state->get('field.id')):?>window.parent.jInsertFieldValue(document.id('f_url').value,'<? php echo $this->state->get('field.id');?>');<? php else:? >ImageManager.onok();<? php endif;? >window.parent.SqueezeBox.close();" title="ONLY insert ONE selected image tag in editor and close this window"><? php echo JText::_('COM_MEDIA_INSERT') ?></button>
<button type="button" onclick="window.parent.SqueezeBox.close();" title="Just close this window"><?php echo JText::_('JCANCEL') ?></button>
</div>
</fieldset> <iframe id="imageframe" name="imageframe" src="index.php? option=com_media&view=imagesList&tmpl=component&folder=<? php echo $this->state->folder?>&asset=<? php echo JRequest::getCmd('asset');?>&author=<?php echo JRequest::getCmd('author');?>"></iframe>
<!--Added by henry-->
<fieldset>
<label>Article content source HTML code:</label>
<textarea name="html_source" id="htmlSourceForImage" rows="15" cols="100"
style="width: 100%; height: 200px; font-family: 'Courier New', Courier, monospace; font-size: 12px; white-space: pre-wrap;"
dir="ltr" wrap="off" class="mceFocus"></textarea>
</fieldset>
<!--ended by henry-->
<fieldset>
<table class="properties">
<tr>
<td><label for="f_url"><?php echo JText::_('COM_MEDIA_IMAGE_URL') ?></label></td>
<td><input type="text" id="f_url" value="" /></td>
<?php if (!$this->state->get('field.id')):?>
<td><label for="f_align"><? php echo JText::_('COM_MEDIA_ALIGN') ?></label></td>
<td>
<select size="1" id="f_align" >
<option value="" selected="selected"><?php echo JText::_('COM_MEDIA_NOT_SET') ?></option>
<option value="left"><?php echo JText::_('JGLOBAL_LEFT') ?></option>
<option value="right"><? php echo JText::_('JGLOBAL_RIGHT') ?></option>
</select>
</td>
<td> <?php echo JText::_('COM_MEDIA_ALIGN_DESC');? > </td>
<? php endif;?>
</tr>
<? php if (!$this->state->get('field.id')):? >
<tr>
<td><label for="f_alt"><?php echo JText::_('COM_MEDIA_IMAGE_DESCRIPTION') ? ></label></td>
<td><input type="text" id="f_alt" value="" /></td>
</tr>
<tr>
<td><label for="f_title"><? php echo JText::_('COM_MEDIA_TITLE') ?></label></td>
<td><input type="text" id="f_title" value="" /></td>
<td><label for="f_caption"><?php echo JText::_('COM_MEDIA_CAPTION') ?></label></td>
<td>
<select size="1" id="f_caption" >
<option value="" selected="selected" ><? php echo JText::_('JNO') ?></option>
<option value="1"><?php echo JText::_('JYES') ?></option>
</select>
</td>
<td> <?php echo JText::_('COM_MEDIA_CAPTION_DESC');?> </td>
</tr>
<?php endif;? >
</table> <input type="hidden" id="dirPath" name="dirPath" />
<input type="hidden" id="f_file" name="f_file" />
<input type="hidden" id="tmpl" name="component" /> </fieldset>
</form> <? php if ($user->authorise('core.create', 'com_media')): ?>
<form action="<?php echo JURI::base(); ?>index.php?option=com_media&task=file.upload&tmpl=component&<? php echo $this->session->getName().'='.$this->session->getId(); ?>&<?php echo JSession::getFormToken();?>=1&asset=<? php echo JRequest::getCmd('asset');?>&author=<?php echo JRequest::getCmd('author');?>&view=images" id="uploadForm" name="uploadForm" method="post" enctype="multipart/form-data">
<fieldset id="uploadform">
<legend><?php echo $this->config->get('upload_maxsize')=='0' ? JText::_('COM_MEDIA_UPLOAD_FILES_NOLIMIT') : JText::sprintf('COM_MEDIA_UPLOAD_FILES', $this->config->get('upload_maxsize')); ?></legend>
<fieldset id="upload-noflash" class="actions">
<label for="upload-file" class="hidelabeltxt"><?php echo JText::_('COM_MEDIA_UPLOAD_FILE'); ?></label>
<input type="file" id="upload-file" name="Filedata[]" multiple />
<label for="upload-submit" class="hidelabeltxt"><? php echo JText::_('COM_MEDIA_START_UPLOAD'); ? ></label>
<input type="submit" id="upload-submit" value="<? php echo JText::_('COM_MEDIA_START_UPLOAD'); ?>"/>
</fieldset>
<input type="hidden" name="return-url" value="<?php echo base64_encode('index.php? option=com_media&view=images&tmpl=component&fieldid='.JRequest::getCmd('fieldid', '').'&e_name='.JRequest::getCmd('e_name').'&asset='.JRequest::getCmd('asset').'&author='.JRequest::getCmd('author')); ? >" />
</fieldset>
</form>
<?php endif; ?>

上面我添加的部分都用//added by henry和//ended by henry包围了起来。

b. 由于添加了一个textarea。所以原先整个sbox的高度也要适当添加:

在joomla->plugins->editors-xtd->image->image.php的倒数第8行左右。找到这句:

$button->set('options', "{handler: 'iframe', size: {x: 800, y: 500}}");

改成

$button->set('options', "{handler: 'iframe', size: {x: 800, y: 700}}");

700的高度适应性挺好的。

终于的效果:

一边看着图片一边点击“Insert”插入到HTML代码中:

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGh5Mzg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

插入完成之后,点击“OK”,将HTML源码返回tiny mce编辑器。

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvdGh5Mzg=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

感觉还不错,写多图文章不再是恶梦。

希望本文让Joomla的用户插入图片时更舒服些。

为Joomla 2.5的连续插入多幅图像添加便捷方式的更多相关文章

  1. 使用VIM将文件的其中的连续几行注释删除或者给其中的连续几行添加注释

    一.使用VIM将文件的其中的连续几行注释删除 1.用VIM打开一个文件,比如打开sshd_config文件,以该文件的下面几行为例: #vim  sshd_config 2.此时,按ctrl+v键,使 ...

  2. mybatis中批量插入的两种方式(高效插入)

    MyBatis简介 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以使用 ...

  3. SQL 数据库连续插入大批量数据时超时

    经常会处理大批量千万级的数据,一直以来都没问题.最近在处理时确出来了经常超时,程序跑一段时间就得停下来重启服务器,根据几次的调整发现了问题的所在,产生这类问题主要是以下几点所导致:      1.数据 ...

  4. springmvc 使用poi解析excel并通过hibernate连续插入多条数据 实际数据库只能保存最后一条

    有一个原始数据的excel表 用poi解析之后通过hibernate插数据库 结果 后来发现,有人说 果断尝试 问题解决 但是这好像并不是真正解决问题,只是解决了一个现象 因为有人说 https:// ...

  5. 动态插入、添加删除表格行的JS代码

    <html> <head> <title>Table对象的方法</title> <script language="JavaScript ...

  6. vue.js插入dom节点的方式

    html代码: <div id="app"></div> js代码: var MyComponent = Vue.extend({ template: '& ...

  7. MyBatis_动态sql_foreach_mysql下foreach批量插入的两种方式

    方法1: 笔记要点出错分析与总结工程组织数据库组织0.重新修改Bean类    修改1.定义接口 //批量插入 public void addEmps(@Param("emps") ...

  8. CSS插入的四种方式

    一.什么是CSS CSS(Cascading style sheets  层叠样式表),CSS可以用以为网页构建样式表,通过样式表来达到对网页进行美化的效果.所谓层叠可以将网页想象成一层层的结构,高层 ...

  9. python元组 列表 (取值、替换、插入、添加、删除)

    1.元组 列表 字典 元组( 元组是不可变的) hello = (1,2,3,4,5) type(hello)

随机推荐

  1. wlan

    一.概述 CSMA/CD    --->以太网介质 CSMA/CA------->无线介质 IEEE----->802.11   a  b  g  e  f   h  i  j 分类 ...

  2. 汇编CMOS

    汇编 端口 端口 前面讲过,各种存储器都和CPU的地址线.数据线.控制线相连.CPU在操控它们的时候,把它们都当作内存来对待,把它们总的看做一个由若干存储单元组成的逻辑存储器,这个逻辑器我们称其为内存 ...

  3. hlgoj 1766 Cubing

    模拟.下图是我做的小模型. #include <iostream> #include <stdio.h> #include <queue> #include < ...

  4. php文档php-fpm.conf配置

    cat php-fpm.conf|grep -v "^;"|grep -v "^$" [global] pid = run/php-fpm.pid   //pi ...

  5. 【bzoj4868】[Shoi2017]期末考试 前缀和+暴力

    题目描述 有n位同学,每位同学都参加了全部的m门课程的期末考试,都在焦急的等待成绩的公布.第i位同学希望在第ti天或之前得知所.有.课程的成绩.如果在第ti天,有至少一门课程的成绩没有公布,他就会等待 ...

  6. 【luogu】P1772物流运输(最短路+DP)

    题目链接 对于本题我们设ext[i][j]计算第i个码头在前j天总共有几天不能用(其实就一前缀和),设dis[i][j]是从第i天到第j天不变运输路线的最短路径,设f[i]是前i天运输货物的最小花费. ...

  7. HDU——4549M斐波那契数列(矩阵快速幂+快速幂+费马小定理)

    M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Su ...

  8. JSON与字符串互相转换的几种方法

    1 2 3 4 5 6 7 8 字符串转对象(strJSON代表json字符串)   var obj = eval(strJSON);   var obj = strJSON.parseJSON(); ...

  9. Vmware虚拟机三种网卡模式详解

    由于Linux目前很热门,越来越多的人在学习linux,但是买一台服务放家里来学习,实在是很浪费.那么如何解决这个问题?虚拟机软件是很好的选择,常用的虚拟机软件有vmware workstations ...

  10. Jackson转换JSON例子

    Jackson可以轻松的将Java对象转换成json对象和xml文档,同样也可以将json.xml转换成Java对象. 前面有介绍过json-lib这个框架,在线博文:http://www.cnblo ...