为Joomla 2.5的连续插入多幅图像添加便捷方式
用过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的连续插入多幅图像添加便捷方式的更多相关文章
- 使用VIM将文件的其中的连续几行注释删除或者给其中的连续几行添加注释
一.使用VIM将文件的其中的连续几行注释删除 1.用VIM打开一个文件,比如打开sshd_config文件,以该文件的下面几行为例: #vim sshd_config 2.此时,按ctrl+v键,使 ...
- mybatis中批量插入的两种方式(高效插入)
MyBatis简介 MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以使用 ...
- SQL 数据库连续插入大批量数据时超时
经常会处理大批量千万级的数据,一直以来都没问题.最近在处理时确出来了经常超时,程序跑一段时间就得停下来重启服务器,根据几次的调整发现了问题的所在,产生这类问题主要是以下几点所导致: 1.数据 ...
- springmvc 使用poi解析excel并通过hibernate连续插入多条数据 实际数据库只能保存最后一条
有一个原始数据的excel表 用poi解析之后通过hibernate插数据库 结果 后来发现,有人说 果断尝试 问题解决 但是这好像并不是真正解决问题,只是解决了一个现象 因为有人说 https:// ...
- 动态插入、添加删除表格行的JS代码
<html> <head> <title>Table对象的方法</title> <script language="JavaScript ...
- vue.js插入dom节点的方式
html代码: <div id="app"></div> js代码: var MyComponent = Vue.extend({ template: '& ...
- MyBatis_动态sql_foreach_mysql下foreach批量插入的两种方式
方法1: 笔记要点出错分析与总结工程组织数据库组织0.重新修改Bean类 修改1.定义接口 //批量插入 public void addEmps(@Param("emps") ...
- CSS插入的四种方式
一.什么是CSS CSS(Cascading style sheets 层叠样式表),CSS可以用以为网页构建样式表,通过样式表来达到对网页进行美化的效果.所谓层叠可以将网页想象成一层层的结构,高层 ...
- python元组 列表 (取值、替换、插入、添加、删除)
1.元组 列表 字典 元组( 元组是不可变的) hello = (1,2,3,4,5) type(hello)
随机推荐
- Cocos2d-x学习资料集锦
Cocos2d-x学习资料集锦: 1.Cocos2d-x官方中文文档:https://github.com/chukong/cocos-docs/blob/master/catalog/zh.md 推 ...
- DocView mode 2 -- 快捷键
** 启动 C-c C-c 切换DocView和文件内容显示 M-x doc-view-mode 启动主模式 M-x doc-view-minor-mode 启动辅模式 k k ...
- python模块--random
random主要用于生成随机字符串等,例如登录页面上随机字符串验证. random常用方法: import random print(random.randrange(1, 10)) # 返回1-10 ...
- python基础学习笔记——collections模块
在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict.namedtuple和Ord ...
- B树总结
B树是一种平衡的多路查找树,一棵m阶B树或为空树,或满足下列特性: 1. 每个节点之多有m棵子树 2. 若根节点不是叶子节点,则至少有两颗子树 3. 除根之外所有非终端节点至少有[m/2]可子树 ...
- tomcat的管理(manager)报错403
管理tomcat的时候遇到了以下问题: 1.刚开始需要用户名密码,不知道用户名和密码是什么,但是输入什么都不正确. 解决办法: 自己在tomcat-users.xml中按格式添加用户 conf文件夹里 ...
- [HDU-5536] Chip Factory (01字典树)
Problem Description John is a manager of a CPU chip factory, the factory produces lots of chips ever ...
- ORACLE的impdp和expdp命令【登录、创建用户、授权、导入导出】
使用EXPDP和IMPDP时应该注意的事项: EXP和IMP是客户端工具程序,它们既可以在客户端使用,也可以在服务端使用. EXPDP和IMPDP是服务端的工具程序,他们只能在ORACLE服务端使用, ...
- python3里的Urllib库
首先Urllib是python内置的HTTP请求库. 包括以下模块: urllib.request 请求模块: urllib.error 异常处理模块: urllib.parse url解析模块: u ...
- OSI模型详解
OSI 七层模型通过七个层次化的结构模型使不同的系统不同的网络之间实现可靠的通讯,因此其最主要的功能就是帮助不同类型的主机实现数据传输 . 完成中继功能的节点通常称为中继系统.在OSI七层模型中,处于 ...