first import
This commit is contained in:
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* Wysiwyg API integration.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Implementation of hook_wysiwyg_plugin().
|
||||
*/
|
||||
function shortcode_wysiwyg_shortcode_wysiwyg_plugin() {
|
||||
$plugins['shortcode_wysiwyg'] = array(
|
||||
'title' => t('Shortcode'),
|
||||
'vendor url' => 'http://drupal.org/project/shortcode',
|
||||
'icon file' => 'insert.png',
|
||||
'icon title' => t('Insert a shortcode'),
|
||||
'settings' => array(),
|
||||
);
|
||||
return $plugins;
|
||||
}
|
||||
|
Binary file not shown.
After Width: | Height: | Size: 711 B |
@@ -0,0 +1,152 @@
|
||||
(function ($) {
|
||||
/**
|
||||
* Wysiwyg plugin button implementation for shortcode plugin.
|
||||
*/
|
||||
Drupal.wysiwyg.plugins.shortcode_wysiwyg = {
|
||||
/**
|
||||
* Return whether the passed node belongs to this plugin.
|
||||
*
|
||||
* @param node
|
||||
* The currently focused DOM element in the editor content.
|
||||
*/
|
||||
isNode: function(node) {
|
||||
return ($(node).is('img.shortcode_wysiwyg-shortcode_wysiwyg'));
|
||||
},
|
||||
|
||||
/**
|
||||
* Execute the button.
|
||||
*
|
||||
* @param data
|
||||
* An object containing data about the current selection:
|
||||
* - format: 'html' when the passed data is HTML content, 'text' when the
|
||||
* passed data is plain-text content.
|
||||
* - node: When 'format' is 'html', the focused DOM element in the editor.
|
||||
* - content: The textual representation of the focused/selected editor
|
||||
* content.
|
||||
* @param settings
|
||||
* The plugin settings, as provided in the plugin's PHP include file.
|
||||
* @param instanceId
|
||||
* The ID of the current editor instance.
|
||||
*/
|
||||
invoke: function(data, settings, instanceId) {
|
||||
/*
|
||||
if (data.format == 'html') {
|
||||
var content = this._getPlaceholder(settings);
|
||||
}
|
||||
else {
|
||||
var content = '<!--shortcode_wysiwyg-->';
|
||||
}
|
||||
*/
|
||||
Drupal.wysiwyg.plugins.shortcode_wysiwyg.insert_form(data, settings, instanceId);
|
||||
},
|
||||
|
||||
|
||||
insert_form: function (data, settings, instanceId) {
|
||||
form_id = Drupal.settings.shortcode_wysiwyg.current_form;
|
||||
// Location, where to fetch the dialog.
|
||||
var aurl = Drupal.settings.basePath + 'index.php?q=shortcode_wysiwyg/'+ Drupal.wysiwyg.instances[instanceId].format +'/' + form_id;
|
||||
dialogdiv = jQuery('<div id="shortcode-insert-dialog"></div>');
|
||||
dialogdiv.load(aurl + " .content #shortcode-wysiwyg-form", function(){
|
||||
var dialogClose = function () {
|
||||
try {
|
||||
dialogdiv.dialog('destroy').remove();
|
||||
} catch (e) {};
|
||||
};
|
||||
btns = {};
|
||||
btns[Drupal.t('Insert shortcode')] = function () {
|
||||
|
||||
var shortcode = dialogdiv.contents().find('#edit-shortcode option:selected').val();
|
||||
var editor_id = instanceId;
|
||||
|
||||
var options = [];
|
||||
dialogdiv.contents().find('input,select')
|
||||
.not('#edit-shortcode,[type="hidden"]')
|
||||
.each(function () {
|
||||
var name = $(this).attr('name'), val = $(this).val();
|
||||
if (val.length) {
|
||||
options.push(name + '=' + val);
|
||||
}
|
||||
});
|
||||
|
||||
shortcode = '[' + shortcode + (options.length ? ' ' + options.join(' ') : '') + ']'+ data.content +'[/' + shortcode + ']';
|
||||
|
||||
Drupal.wysiwyg.plugins.shortcode_wysiwyg.insertIntoEditor(shortcode, editor_id);
|
||||
jQuery(this).dialog("close");
|
||||
|
||||
};
|
||||
|
||||
btns[Drupal.t('Cancel')] = function () {
|
||||
jQuery(this).dialog("close");
|
||||
};
|
||||
|
||||
dialogdiv.dialog({
|
||||
modal: true,
|
||||
autoOpen: false,
|
||||
closeOnEscape: true,
|
||||
resizable: false,
|
||||
draggable: false,
|
||||
autoresize: true,
|
||||
namespace: 'jquery_ui_dialog_default_ns',
|
||||
dialogClass: 'jquery_ui_dialog-dialog',
|
||||
title: Drupal.t('Insert shortcode'),
|
||||
buttons: btns,
|
||||
width: 700,
|
||||
close: dialogClose
|
||||
});
|
||||
dialogdiv.dialog("open");
|
||||
});
|
||||
},
|
||||
|
||||
insertIntoEditor: function (shortcode, editor_id) {
|
||||
Drupal.wysiwyg.instances[editor_id].insert(shortcode);
|
||||
},
|
||||
|
||||
/**
|
||||
* Prepare all plain-text contents of this plugin with HTML representations.
|
||||
*
|
||||
* Optional; only required for "inline macro tag-processing" plugins.
|
||||
*
|
||||
* @param content
|
||||
* The plain-text contents of a textarea.
|
||||
* @param settings
|
||||
* The plugin settings, as provided in the plugin's PHP include file.
|
||||
* @param instanceId
|
||||
* The ID of the current editor instance.
|
||||
*/
|
||||
attach: function(content, settings, instanceId) {
|
||||
content = content.replace(/<!--shortcode_wysiwyg-->/g, this._getPlaceholder(settings));
|
||||
return content;
|
||||
},
|
||||
|
||||
/**
|
||||
* Process all HTML placeholders of this plugin with plain-text contents.
|
||||
*
|
||||
* Optional; only required for "inline macro tag-processing" plugins.
|
||||
*
|
||||
* @param content
|
||||
* The HTML content string of the editor.
|
||||
* @param settings
|
||||
* The plugin settings, as provided in the plugin's PHP include file.
|
||||
* @param instanceId
|
||||
* The ID of the current editor instance.
|
||||
*/
|
||||
detach: function(content, settings, instanceId) {
|
||||
var $content = $('<div>' + content + '</div>');
|
||||
$.each($('img.shortcode_wysiwyg-shortcode_wysiwyg', $content), function (i, elem) {
|
||||
//...
|
||||
});
|
||||
return $content.html();
|
||||
},
|
||||
|
||||
/**
|
||||
* Helper function to return a HTML placeholder.
|
||||
*
|
||||
* The 'drupal-content' CSS class is required for HTML elements in the editor
|
||||
* content that shall not trigger any editor's native buttons (such as the
|
||||
* image button for this example placeholder markup).
|
||||
*/
|
||||
_getPlaceholder: function (settings) {
|
||||
return '<img src="' + settings.path + '/images/spacer.gif" alt="<--shortcode_wysiwyg->" title="<--shortcode_wysiwyg-->" class="shortcode_wysiwyg-shortcode_wysiwyg drupal-content" />';
|
||||
}
|
||||
};
|
||||
})(jQuery);
|
@@ -0,0 +1,11 @@
|
||||
name = Shortcode wysiwyg EXPERIMENTAL
|
||||
description = "Shortcode wysiwyg integration"
|
||||
core = 7.x
|
||||
package = Shortcode
|
||||
dependencies[] = shortcode
|
||||
; Information added by drupal.org packaging script on 2012-03-10
|
||||
version = "7.x-2.0-alpha1"
|
||||
core = "7.x"
|
||||
project = "shortcode"
|
||||
datestamp = "1331420143"
|
||||
|
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @file
|
||||
* This module provides wysiwyg support for shortcodes.
|
||||
*/
|
||||
function shortcode_wysiwyg_wysiwyg_include_directory($type) {
|
||||
switch ($type) {
|
||||
case 'plugins':
|
||||
return $type;
|
||||
}
|
||||
}
|
||||
|
||||
function shortcode_wysiwyg_form_alter(&$form, $form_state, $form_id) {
|
||||
if (strpos($form_id, 'node_form') !== FALSE || strpos($form_id, 'comment') !== FALSE) {
|
||||
drupal_add_library('system', 'ui.dialog');
|
||||
drupal_add_library('system', 'ui.draggable');
|
||||
drupal_add_js(array('shortcode_wysiwyg' => array('current_form' => $form['form_build_id']['#value'])), 'setting');
|
||||
}
|
||||
}
|
||||
|
||||
function shortcode_wysiwyg_menu() {
|
||||
$items = array();
|
||||
$items['shortcode_wysiwyg/%/%'] = array(
|
||||
'page callback' => 'drupal_get_form',
|
||||
'page arguments' => array('shortcode_wysiwyg_form', 1, 2),
|
||||
'access callback' => TRUE,
|
||||
'type' => MENU_CALLBACK,
|
||||
);
|
||||
|
||||
return $items;
|
||||
}
|
||||
|
||||
function shortcode_wysiwyg_form($form, &$form_state, $format_id) {
|
||||
$options = $form = array();
|
||||
module_load_include('inc', 'shortcode', 'shortcode');
|
||||
drupal_set_title(t('Shortcode'));
|
||||
|
||||
$format_id = str_replace("format", "", $format_id); /// euhj...wtf...
|
||||
$shortcodes = shortcode_list_all_enabled($format_id);
|
||||
|
||||
foreach($shortcodes as $name => $shortcode) {
|
||||
$options[$name] = $shortcode['title'];
|
||||
}
|
||||
|
||||
$form['shortcode'] = array(
|
||||
'#type' => 'select',
|
||||
'#title' => t('Choose the shortcode you want to insert.'),
|
||||
'#options' => $options,
|
||||
'#description' => t('This shortcode will be inserted in your textfield')
|
||||
);
|
||||
|
||||
foreach($shortcodes as $name => $shortcode) {
|
||||
if ($shortcode['attributes callback']) {
|
||||
$form[$name] = call_user_func_array($shortcode['attributes callback'], array(array(), $form_state));
|
||||
}
|
||||
}
|
||||
|
||||
return $form;
|
||||
}
|
Reference in New Issue
Block a user