Skip to content
Snippets Groups Projects
Commit adfe1d2b authored by Jeff C. Decker's avatar Jeff C. Decker
Browse files

bidirectional and IMCE support added

parent 50527b1d
No related branches found
No related tags found
No related merge requests found
.yui-skin-sam .yui-toolbar-container .yui-toolbar-editcode span.yui-toolbar-icon {
background-image: url( ../assets/html_editor.gif );
background-position: 0 1px;
left: 5px;
}
.yui-skin-sam .yui-toolbar-container .yui-button-editcode-selected span.yui-toolbar-icon {
background-image: url( ../assets/html_editor.gif );
background-position: 0 1px;
left: 5px;
}
<?php
function yui_editor_bidi_settings(&$form, &$profile) {
$form['plugins']['bidi'] = array(
'#type' => 'checkbox',
'#title' => t('bidi buttons'),
'#default_value' => $profile['bidi'],
'#description' => t('Add a button fto control text directionality.'));
}
function yui_editor_bidi_render(&$profile) {
if ($profile['bidi'] == 1) {
drupal_add_js(drupal_get_path("module", "yui_editor") ."/plugins/bidi.js", 'module', 'footer');
drupal_add_css(drupal_get_path("module", "yui_editor") ."/plugins/bidi.css", 'module');
}
}
function yui_editor_bidi() {
for (var e in YAHOO.Drupal.editors) {
var myEditor = YAHOO.Drupal.editors[e].editor;
var config = YAHOO.Drupal.editors[e].config;
var id = YAHOO.Drupal.editors[e].id;
if (config.bidi == 1) {
myEditor.on('toolbarLoaded', function () {
var bidiConfig = {
type: 'push', label: 'Switch to Right-to-Left', value: 'bidi'
};
myEditor.toolbar.addButtonToGroup(bidiConfig, 'plugins');
myEditor.toolbar.on('bidiClick', function(ev) {
var rtlHTML ='im inserted here';
var sel = this._getSelection();
myEditor.execCommand('inserthtml', '<p dir="rtl">'+sel+'</p>');
}, myEditor, true);
});
}
}
}
YAHOO.Drupal.yui_editor_load.subscribe(yui_editor_bidi);
\ No newline at end of file
<?php
/**
* YUI Editor Image Browser Plugin - using IMCE
*
* @author Dave Hall <info@davehall.com.au>
* @license GNU General Public License v2 (or later) http://www.gnu.org/licenses/gpl-2.0.html
*/
/**
* Rendering hook
*
* @internal just adds some JS to the template - if IMCE is installed and available to the user
*
* @param array $profile Current user's profile data
*
* @return void
*/
function yui_editor_img_browser_render(&$profile) {
$has_access = module_exists('imce') && function_exists('imce_access') && imce_access();
$profile['img_browser'] = ($has_access ? $profile['img_browser'] : 0);
if ($profile['img_browser'] == 1) {
drupal_add_js(drupal_get_path("module", "yui_editor")."/plugins/img_browser.js", 'module', 'footer');
}
}
/**
* Settings hook to allow the inclusion IMCE
*
* @internal only rendered if IMCE is installed
*
* @param object $form the form being editted
* @param object $profile The current user's profile data
*
* @return void
*/
function yui_editor_img_browser_settings(&$form, &$profile) {
if ( !module_exists('imce') ) {
return;
}
$form['plugins']['img_browser'] = array(
'#type' => 'checkbox',
'#title' => t('Image Browser'),
'#default_value' => $profile['img_browser'],
'#description' => t('Allow users to browse images directly from the editor for insertion into the editor. Note: IMCE module must be installed and configured for this to work. Works only with YUI 2.5.x at present.'));
}
\ No newline at end of file
/**
* ICME image browser integration
*
* @author Dave Hall <info@davehall.com.au>
*
* @internal loosely based on the IMCE API docs - see http://ufku.com/drupal/imce/api
* and the YUI editor img_upload plugin
*/
/**
* @var object IMCEPopup Global reference to IMCE popup
*/
var imcePopup;
/**
* IMCE integration bootstrapper
*
* This function integrates IMCE into the YUI image insertion dialog box
*
* @return void
*/
function yui_editor_img_browser() {
var myEditor, config;
for ( var e in YAHOO.Drupal.editors) {
myEditor = YAHOO.Drupal.editors[e].editor;
config = YAHOO.Drupal.editors[e].config;
if (config.img_browser == 1) {
yui_editor_img_browser_attach(myEditor);
}
}
};
/**
* Attach the event listeners so the IMCE popup works
*
* @param object rte YUI Editor to attach events to
*
* @return void
*/
function yui_editor_img_browser_attach(rte) {
rte.addListener('toolbarLoaded',function() {
rte.toolbar.addListener('insertimageClick',function(o) {
var imgPanel = new YAHOO.util.Element('yui-editor-panel');
imgPanel.on('contentReady', function() {
var Dom = YAHOO.util.Dom,
urlInput = Dom.get('insertimage_url'),
urlW = yui_editor_img_browser_pasreWidth(Dom.getStyle(urlInput, 'width')),
imceTrigger = new YAHOO.widget.Button(
{
id : 'imceTrigger',
label : 'Browse',
container : urlInput.parentNode,
onclick : {fn : yui_editor_img_browser_show}
}),
btnW = yui_editor_img_browser_pasreWidth(Dom.getStyle('imceTrigger', 'width'));
Dom.setStyle(urlInput, 'width', (urlW.val - (btnW.val * 1.1)) + urlW.unit);
});
});
});
};
/*
* Parse a CSS width value
*
* @param string w the width to parse
*
* @return object the value (val) and the unit of measure (unit)
*/
function yui_editor_img_browser_pasreWidth(w) {
var l = w.length,
c = l - 2,
r = {val: 0, unit: ''};
return {val : w.substr(0, c), unit : w.substr(c, 2)};
};
/**
* onClick handler which displays the IMCE popup window
*
* @return void
*/
function yui_editor_img_browser_show() {
if (typeof imcePopup == 'undefined' || imcePopup.closed) {
imcePopup = window.open('?q=imce', '',
'width=760,height=560,resizable=1');
imcePopup['imceOnLoad'] = function(win) {
win.imce.setSendTo('Update fields', yui_editor_img_browser_finish);
};
}
imcePopup.focus();
};
/**
* Event handler for populating the YUI image insert dialog
*
* @param object file the selected file
* @param object win the popup window
*
* @return void
*/
function yui_editor_img_browser_finish(file, win) {
var Dom = YAHOO.util.Dom;
Dom.get('insertimage_url').value = file.url;
Dom.get('insertimage_width').value = file.width;
Dom.get('insertimage_height').value = file.height;
win.blur();
};
YAHOO.Drupal.yui_editor_load.subscribe(yui_editor_img_browser);
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment