README.txt | 20 ----- aloha.format.inc | 153 +++++++++++++++++++++++++++++++++++++ aloha.module | 70 ++++++----------- aloha.pages.inc | 69 +++++++++++++++++ aloha/drupal-ui/lib/multiSplit.js | 15 ++-- aloha/drupal-ui/lib/tab.js | 5 -- aloha/drupal-ui/lib/toolbar.js | 67 ++++++++-------- caption/caption.module | 4 +- css/aloha-drupal-ui.css | 7 +- generate-core-patch.sh | 2 +- includes/format.inc | 153 ------------------------------------- includes/pages.inc | 68 ----------------- js/drupal.aloha.js | 2 +- 13 files changed, 290 insertions(+), 345 deletions(-) diff --git a/README.txt b/README.txt index 74f794d..0c9006c 100644 --- a/README.txt +++ b/README.txt @@ -1,23 +1,3 @@ -Installation instructions -------------------------- - -Install as any Drupal module (so also install its dependencies), with the -following additional steps: - -* Apply this core patch: http://drupal.org/files/drupal8.script-tag-attributes.4.patch -* Also apply this core patch: http://drupal.org/files/drupal_wysiwyg-in-core-round-one-1782838-44.patch -* Make sure you do a FRESH INSTALL of Drupal 8! (The default text formats have - been changed). Please use the "standard" install profile. - - -TODO ----- - -* BUG INTRODUCED: unable to align captioned images. -* Improve our build of Aloha Editor, so that we can leverage Drupal's - hook_library_info() even better. - - Rationales ---------- diff --git a/aloha.format.inc b/aloha.format.inc new file mode 100644 index 0000000..991836b --- /dev/null +++ b/aloha.format.inc @@ -0,0 +1,153 @@ + 'p', + // For a single

that would be stripped, filter_autop would generate + // it again, making it impossible to detect that filter_html actually + // stripped it away. Hence we need to use two adjacent

tags. + 'testcase' => '

Hello, world!

This is Drupal!

', + 'attributes' => array( + 'prefix' => '

'>Hello, world!

', + 'names' => array('dir'), + ), + ), + array( + 'tag' => 'blockquote', + 'testcase' => '
Veni, vidi, vici.
', + 'attributes' => array( + 'prefix' => '
'>Veni, vidi, vici!
', + 'names' => array('cite'), + ), + ), + array('tag' => 'h1', 'testcase' => '

heading 1

'), + array('tag' => 'h2', 'testcase' => '

heading 2

'), + array('tag' => 'h3', 'testcase' => '

heading 3

'), + array('tag' => 'h4', 'testcase' => '

heading 4

'), + array('tag' => 'h5', 'testcase' => '
heading 5
'), + array('tag' => 'h6', 'testcase' => '
heading 6
'), + array('tag' => 'ul', 'testcase' => ''), + array('tag' => 'ol', 'testcase' => '
  1. A
  2. B
'), + array('tag' => 'li', 'testcase' => '
  • A
  • '), + array('tag' => 'pre', 'testcase' => '
    preformatted text
    '), + // Text-level elements. (Should all be wrapped in

    tags.) + array( + 'tag' => 'a', + 'testcase' => '

    hyperlink

    ', + 'attributes' => array( + 'prefix' => '

    '>hyperlink

    ', + 'names' => array('href', 'target', 'rel', 'media'), + ), + ), + array('tag' => 'em', 'testcase' => '

    emphasized

    '), + array('tag' => 'strong', 'testcase' => '

    strong

    '), + array('tag' => 'i', 'testcase' => '

    italicized

    '), + array('tag' => 'b', 'testcase' => '

    bold

    '), + array('tag' => 'u', 'testcase' => '

    underlined

    '), + array('tag' => 'cite', 'testcase' => '

    He said "WOW, Drupal rocks!"

    '), + array('tag' => 'q', 'testcase' => '

    He said "WOW, Drupal rocks!"

    '), + array('tag' => 'br', 'testcase' => '

    First line
    Second line

    '), + array( + 'tag' => 'code', + 'testcase' => '

    Hello, world!

    ', + 'attributes' => array( + 'prefix' => '

    '>Hello, world!

    ', + 'names' => array('lang'), + ), + ), + array( + 'tag' => 'img', + 'testcase' => '

    ', + 'attributes' => array( + 'prefix' => '

    ' />

    ', + 'names' => array('src', 'alt', 'title') + ), + ), + ); +} + +/** + * Calculates the allowed HTML tags. + * + * @param string $format_id + * A text format ID. + * @return + * @see aloha_get_allowed_html_by_format() + * + * @todo: POST_COMMIT. Refactor. + * @todo: PRE_COMMIT. Unit tests. Start from http://drupal.org/node/1782838#comment-6562024. + */ +function _aloha_calculate_allowed_html($format_id) { + // For testing whether any attribute is allowed. + $any = 'thisIsAnExtremelyUnlikelyToExistAttributeName'; + + // For testing whether data- attributes are allowed. + $data = 'data-' . chr(mt_rand(65, 90)); + + // Helper function to assert the filtered text still contains the original. + $assert_match = function ($original, $format_id) { + $filtered = check_markup($original, $format_id); + $result = preg_replace("/>\s+<", $filtered); + return stripos($result, $original) !== FALSE; + }; + + // Run all the above tag tests to determine which tags and attributes are + // allowed in the given text format. + $allowed_html = array_reduce( + _aloha_allowed_html_tests(), + function($result, $tagtest) use ($assert_match, $format_id, $any, $data) { + $tag = $tagtest['tag']; + if ($assert_match($tagtest['testcase'], $format_id)) { + $result[$tag] = array(); + + // Break early if there are no attributes to test. + if (!isset($tagtest['attributes'])) { + return $result; + } + + // Anonymous function to generate attribute test cases. + $generate_attr_testcase = function($attr) use ($tagtest) { + $case = ''; + $case .= $tagtest['attributes']['prefix']; + $case .= $attr . '="' . $attr . ' attribute test"'; + $case .= $tagtest['attributes']['suffix']; + return $case; + }; + + // The tag test passed, then we can also do the attribute tests. First, + // check if any attribute is allowed, if that's not the case, then + // figure out which specific attributes are allowed. + if ($assert_match($generate_attr_testcase($any), $format_id)) { + $result[$tag][] = '*'; + } + else { + $attrs = array_merge(array($data), $tagtest['attributes']['names']); + foreach ($attrs as $attr) { + if ($assert_match($generate_attr_testcase($attr), $format_id)) { + $result[$tag][] = ($attr === $data) ? 'data-' : $attr; + } + } + } + } + + return $result; + }, + array() + ); + + return $allowed_html; +} diff --git a/aloha.module b/aloha.module index 7eaa21b..1ab6614 100644 --- a/aloha.module +++ b/aloha.module @@ -6,11 +6,10 @@ */ /** - * @todo Improve Aloha Editor build for Drupal. - * @see http://drupal.org/node/1782348 + * @todo POST_COMMIT(Aloha Editor, https://github.com/alohaeditor/Aloha-Editor/issues/737, http://drupal.org/node/1782348) + * Improve Aloha Editor build for Drupal. */ -// @todo Establish a versioning scheme for our custom build. const ALOHA_VERSION = 'custom build: 0.22.2+dev at f9b2a7679abc913e4ccf16ce4bccacd8c998b592'; /** @@ -22,14 +21,14 @@ function aloha_menu() { 'page arguments' => array(3), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, - 'file' => 'includes/pages.inc', + 'file' => 'aloha.pages.inc', ); $items['aloha/repository/image/%'] = array( 'page callback' => 'aloha_repository_image', 'page arguments' => array(3), 'access arguments' => array('access content'), 'type' => MENU_CALLBACK, - 'file' => 'includes/pages.inc', + 'file' => 'aloha.pages.inc', ); return $items; } @@ -48,16 +47,6 @@ function aloha_library_info() { 'version' => VERSION, 'js' => array( $module_path . '/js/drupal.aloha.textarea.js' => array(), - array( - 'type' => 'setting', - 'data' => array('aloha' => array('settings' => array( - // Allow other modules, e.g. the Edit module, to embed the rendered - // toolbar within their own DOM infrastructure. - 'DrupalUI' => array( - 'renderOwnToolbarContainer' => TRUE, - ), - ))), - ), ), 'dependencies' => array( array('aloha', 'aloha'), @@ -68,7 +57,7 @@ function aloha_library_info() { // be loaded should hook_library_info_alter() this library and inject their // own dependencies. // Look at Drupal.settings.aloha.settings.plugins.load (this is identical to - // Aloha.settings.plugins) to see the fullly expanded list of Aloha Editor + // Aloha.settings.plugins) to see the fully expanded list of Aloha Editor // plug-ins that will be loaded. $libraries['aloha'] = array( 'title' => 'Pseudo-library that depends on the core of Aloha Editor and contains a list of all Aloha Editor plug-ins that should be loaded.', @@ -107,18 +96,18 @@ function aloha_library_info() { 'weight' => -30, // jquery.js has weight -20, html5.js has weight -21. 'preprocess' => TRUE, 'cache' => TRUE, - 'defer' => FALSE, ), // Load the aggregated Aloha JS file. $library_path . '/lib/' . $library_file => array( 'group' => JS_LIBRARY, 'weight' => -10, - 'defer' => FALSE, 'preprocess' => FALSE, + 'attributes' => array( + 'data-aloha-defer-init' => 'true', + ), ), $module_path . '/js/drupal.aloha.js' => array( 'group' => JS_LIBRARY, - 'defer' => FALSE, ), // Aloha Editor core settings. array( @@ -325,7 +314,7 @@ function aloha_library_info() { // Aloha Editor: "drupal" bundle of plug-ins (shipped with this module). $libraries['aloha.drupal'] = array( - 'title' => 'Register the "drupal" bundle, this is the bundle that ships with this module, the "Aloha" module.', + 'title' => '"Drupal" plugin bundle.', 'version' => VERSION, 'js' => array( array( @@ -337,7 +326,7 @@ function aloha_library_info() { ), ); $libraries['aloha.drupal/drupal'] = array( - 'title' => '"Drupal" Aloha Editor plug-in: link repository', + 'title' => '"Drupal" Aloha Editor plug-in: link and image repositories.', 'version' => VERSION, 'js' => array( array( @@ -489,10 +478,9 @@ function aloha_filter_format_update($format) { } /** - * Get a list of HTML tags and attributes that are allowed by a given text - * format, by performing black-box testing. + * Get a allowed HTML tags and attributes using blackbox testing. * - * @param string $format_id + * @param string $format_id * A text format ID. * @return array * An array of which the keys list all allowed tags and the corresponding @@ -507,7 +495,7 @@ function aloha_get_allowed_html_by_format($format_id) { return $cached->data; } - module_load_include('inc', 'aloha', 'includes/format'); + module_load_include('inc', 'aloha', 'aloha.format'); $allowed_html = _aloha_calculate_allowed_html($format_id); cache()->set($cache_id, $allowed_html); @@ -530,7 +518,7 @@ function aloha_get_allowed_html_by_format($format_id) { * - 'necessary tags allowed': whether the tags for Aloha Editor to function * are allowed by the text format * - 'verdict': whether this text format is compatible with Aloha Editor - * based on the two measures above + * based on the two measures above */ function _aloha_check_format_compatibility_detailed($format_id) { $filter_types = filter_get_filter_types_by_format($format_id); @@ -558,12 +546,12 @@ function aloha_check_format_compatibility($format_id) { } /** - * Adds Drupal.settings.aloha.formats and Aloha.settings.plugins.drupal. Ensures - * Aloha Editor has the metadata to deal with formats. + * Ensures Aloha Editor has the metadata to deal with formats. * - * @todo refactor; how to make the mapping of Aloha cleaner? - * @todo revisit mapping when this Aloha issue is solved: - * https://github.com/alohaeditor/Aloha-Editor/issues/794 + * Adds Drupal.settings.aloha.formats and Aloha.settings.plugins.drupal. + * + * @todo POST_COMMIT(Aloha Editor, https://github.com/alohaeditor/Aloha-Editor/issues/794). + * Revisit mapping when this Aloha issue is solved. */ function aloha_add_format_settings() { $format_settings_added = &drupal_static(__FUNCTION__, FALSE); @@ -573,7 +561,7 @@ function aloha_add_format_settings() { // Mapping from HTML element to Aloha Editor plug-in. $tag_mapping = array( 'a' => 'link', - // Drupal does not approve . + // Drupal does not allow . 'b' => FALSE, 'blockquote' => 'cite', 'br' => 'format', @@ -586,7 +574,7 @@ function aloha_add_format_settings() { 'h4' => 'format', 'h5' => 'format', 'h6' => 'format', - // Drupal does not approve . + // Drupal does not allow . 'i' => FALSE, 'img' => 'image', 'li' => 'list', @@ -647,7 +635,7 @@ function aloha_add_format_settings() { continue; } $settings['settings']['plugins'][$plugin]['editables']['.' . $class][] = $tag; - // For some, there also exists an attribute mapping. + // For some, there is also an attribute mapping. if (isset($attr_mapping[$tag])) { $attrs = array_keys($attr_mapping[$tag]); $allowed_attrs = $allowed_html[$tag]; @@ -685,17 +673,3 @@ function aloha_add_format_settings() { $format_settings_added = TRUE; } } - -/** - * Implements hook_process_html(). - * - * A temporary work-around to avoid needing a core patch. Aloha currently - * requires a custom attribute on its script tag. - * - * @see http://drupal.org/node/1664602 - */ -function aloha_process_html(&$variables) { - if (strpos($variables['scripts'], '/lib/aloha.js') !== FALSE) { - $variables['scripts'] = preg_replace('/(\/lib\/aloha\.js[^"]*["])/', '$1 data-aloha-defer-init="true"', $variables['scripts'], 1); - } -} diff --git a/aloha.pages.inc b/aloha.pages.inc new file mode 100644 index 0000000..59f096f --- /dev/null +++ b/aloha.pages.inc @@ -0,0 +1,69 @@ + $result['link'], + 't' => $result['title'], + 's' => $result['score'], + ); + } + print drupal_json_encode($json); + exit; + } +} + +/** + * Page callback: looks up relevant images in the site given a keyword. + * + * Note that also files with status = 0 are returned, i.e. those which were + * uploaded at some point in time, but not necessarily used. + * + * @param string $lookup + * The keyword to look up relevant images for. + * + * @return string + * A JSON-encoded result. + */ +function aloha_repository_image($lookup) { + // @todo: POST_COMMIT. Convert to EFQ2. + $result = db_query("SELECT * FROM {file_managed} WHERE SUBSTRING(filemime, 1, 6) = 'image/' AND filename LIKE :lookup ORDER BY timestamp DESC", array( + ':lookup' => "%$lookup%" + )); + + $json = array(); + foreach ($result as $record) { + $json[] = array( + 'u' => file_create_url($record->uri), + 't' => $record->filename, + 's' => 1.0, + ); + } + + print drupal_json_encode($json); + exit; +} diff --git a/aloha/drupal-ui/lib/multiSplit.js b/aloha/drupal-ui/lib/multiSplit.js index 6a3974f..6581033 100644 --- a/aloha/drupal-ui/lib/multiSplit.js +++ b/aloha/drupal-ui/lib/multiSplit.js @@ -35,17 +35,13 @@ define([ jQuery.each(this.buttons, function (i, button) { var text = button.name.toUpperCase(); - // @todo: this is a quick hack to remove the "remove formatting" button - // from the p/h1/... dropdown; we want it to live elsewhere. + // @todo: POST_COMMIT(Aloha Editor, https://github.com/alohaeditor/Aloha-Editor/issues/747) + // This is a quick hack to remove the "remove formatting" button from + // the p/h1/... dropdown; we want it to live elsewhere. if (button.name === "removeFormat") { return; } - // @todo: fix this upstream; this is a typo in AE. - if (button.tooltip === 'Pre formated text') { - button.tooltip = "Preformatted text"; - } - // In Drupal's UI, we don't have "large icons". Rename the class name so // that the automatic conversion into data icons can happen in ui/utils. // button.icon = button.icon.replace('aloha-large-icon-', 'aloha-icon-') @@ -67,7 +63,10 @@ define([ // Ensure the button is shown/hidden depending on the current selection. this.element = formatMenuButton.element; this.items = formatMenuButton.items; - this.setActiveButton('p'); // @todo: don't make this assumption! + // @todo: POST_COMMIT(Aloha Editor, https://github.com/alohaeditor/Aloha-Editor/issues/747) + // Don't make this assumption! Aloha Editor's UI should pass us the + // necessary information. + this.setActiveButton('p'); Surface.trackRange(this.element); }, diff --git a/aloha/drupal-ui/lib/tab.js b/aloha/drupal-ui/lib/tab.js index b5a4d30..ad36171 100644 --- a/aloha/drupal-ui/lib/tab.js +++ b/aloha/drupal-ui/lib/tab.js @@ -353,11 +353,6 @@ define([ return; } } - - // It doesn't make any sense to leave the toolbar - // visible after all tabs have been hidden. - // @todo - // this.container.hide(); } } diff --git a/aloha/drupal-ui/lib/toolbar.js b/aloha/drupal-ui/lib/toolbar.js index 1c2b64b..9ed5213 100644 --- a/aloha/drupal-ui/lib/toolbar.js +++ b/aloha/drupal-ui/lib/toolbar.js @@ -78,7 +78,7 @@ define([ * Shows the toolbar. */ show: function () { - if (Toolbar.renderOwnToolbarContainer) { + if (!this._hasCustomToolbarLocation()) { var $textarea = Aloha.activeEditable.obj.closest('.aloha-textarea'); Aloha.jQuery('.edit-toolbar-container .edit-toolbar.tertiary .edit-toolgroup.wysiwyg') .width($textarea.width() + 8); @@ -103,7 +103,7 @@ define([ * Hides the toolbar. */ hide: function () { - if (Toolbar.renderOwnToolbarContainer) { + if (!this._hasCustomToolbarLocation()) { Toolbar.$toolbarSurfaceContainer.stop().fadeOut(200, function () { Toolbar.$toolbarSurfaceContainer .detach() @@ -115,14 +115,20 @@ define([ .add(Toolbar.$handlesSurfaceContainer) .stop().fadeOut(200, function () { // Move the toolbar surface into its original location again. - Toolbar.$panelsSurfaceContainer - .detach() - .appendTo('body'); Toolbar.$handlesSurfaceContainer .detach() - .appendTo('body'); + .appendTo(Toolbar.$toolbarSurfaceContainer) + .show(); + Toolbar.$panelsSurfaceContainer + .detach() + .appendTo(Toolbar.$toolbarSurfaceContainer) + .show(); }); } + }, + + _hasCustomToolbarLocation: function() { + return Aloha.activeEditable.obj.attr('data-edit-aloha-toolbar-custom-location') !== undefined; } }); @@ -143,7 +149,8 @@ define([ */ $toolbarSurfaceContainer: null, - // @todo: get rid of this by fixing AE plug-ins that incorrectly assume this exists! + // @todo: POST_COMMIT(Aloha Editor, https://github.com/alohaeditor/Aloha-Editor/issues/747) + // Get rid of this: fix AE plug-ins that incorrectly assume this exists! $surfaceContainer: $([]), /** @@ -162,40 +169,28 @@ define([ 'unselectable': 'on' }).hide(); - Toolbar.renderOwnToolbarContainer = Aloha.settings && - Aloha.settings.DrupalUI && - Aloha.settings.DrupalUI.renderOwnToolbarContainer === true; - - if (Toolbar.renderOwnToolbarContainer) { - Toolbar.$toolbarSurfaceContainer = $('
    ', { - 'class': 'aloha-surface aloha-toolbar', - 'unselectable': 'on' - }) - .append(Toolbar.$handlesSurfaceContainer) - .append(Toolbar.$panelsSurfaceContainer) - .hide(); - Toolbar.$handlesSurfaceContainer.removeClass('aloha-surface').show(); - Toolbar.$panelsSurfaceContainer.removeClass('aloha-surface').show(); - } + + Toolbar.$toolbarSurfaceContainer = $('
    ', { + 'class': 'aloha-surface aloha-toolbar', + 'unselectable': 'on' + }) + .append(Toolbar.$handlesSurfaceContainer) + .append(Toolbar.$panelsSurfaceContainer) + .hide(); + Toolbar.$handlesSurfaceContainer.removeClass('aloha-surface').show(); + Toolbar.$panelsSurfaceContainer.removeClass('aloha-surface').show(); // In the built aloha.js, init will happend before the body has // finished loading, so we have to defer appending the element. $(function () { - if (Toolbar.renderOwnToolbarContainer) { - Toolbar.$toolbarSurfaceContainer.appendTo('body'); - } - else { - Toolbar.$panelsSurfaceContainer.appendTo('body'); - Toolbar.$handlesSurfaceContainer.appendTo('body'); - } + Toolbar.$toolbarSurfaceContainer.appendTo('body'); }); - if (Toolbar.renderOwnToolbarContainer) { - Surface.trackRange(Toolbar.$toolbarSurfaceContainer); - } - else { - Surface.trackRange(Toolbar.$panelsSurfaceContainer); - Surface.trackRange(Toolbar.$handlesSurfaceContainer); - } + Surface.trackRange(Toolbar.$toolbarSurfaceContainer); + + // Unnecessary when the UI renders itself completely, but essential when + // the toolbar must be rendered into a custom location. + Surface.trackRange(Toolbar.$panelsSurfaceContainer); + Surface.trackRange(Toolbar.$handlesSurfaceContainer); } }); diff --git a/caption/caption.module b/caption/caption.module index d83b465..c86a8c5 100644 --- a/caption/caption.module +++ b/caption/caption.module @@ -45,7 +45,7 @@ function caption_library_info() { // we can target it with our custom CSS. 'blockClass' => 'caption-captioned-image-block', // Function callback, gets set in `js/caption-aloha.js`. - // 'render' => function() {}, + // 'render' => function() {}, ), ), 'contentHandler' => array( @@ -105,8 +105,6 @@ function caption_library_info_alter(&$libraries, $module) { * Implements hook_init(). */ function caption_init() { - // @todo: we should only add this when the caption filter was actually used, - // but there is currently no elegant way to do this in Drupal 7 or 8. drupal_add_library('caption', 'caption', TRUE); } diff --git a/css/aloha-drupal-ui.css b/css/aloha-drupal-ui.css index 62625c6..0600b7f 100644 --- a/css/aloha-drupal-ui.css +++ b/css/aloha-drupal-ui.css @@ -406,8 +406,11 @@ * Custom UI for common/block. */ -/* @todo Temporarily disable Aloha Blocks' handles, because the CaptionedImage - plug-in can't deal yet with dragging images into an alignment. */ +/* + * @todo POST_COMMIT(Aloha Editor, https://github.com/alohaeditor/Aloha-Editor/issues/685) + * Temporarily disable Aloha Blocks' handles, because the CaptionedImage plug-in + * can't deal yet with dragging images into an alignment. + */ .aloha-block-handle { background: none; border: none; diff --git a/generate-core-patch.sh b/generate-core-patch.sh index 9367ffe..ebf6d9d 100644 --- a/generate-core-patch.sh +++ b/generate-core-patch.sh @@ -18,7 +18,7 @@ COMMENTNR=$2 mkdir $DRUPAL_DIR/core/modules/aloha # Generate the patch for the Aloha module. -cp -R aloha aloha.* css fonts includes js README.txt $DRUPAL_DIR/core/modules/aloha/ +cp -R aloha aloha.* css fonts includes js $DRUPAL_DIR/core/modules/aloha/ cd $DRUPAL_DIR git add core/modules/aloha git diff --staged --binary --patch-with-stat > $ALOHA_DIR/$FILENAME-aloha-module-$COMMENTNR.patch diff --git a/includes/format.inc b/includes/format.inc deleted file mode 100644 index ddf1146..0000000 --- a/includes/format.inc +++ /dev/null @@ -1,153 +0,0 @@ - 'p', - // For a single

    that would be stripped, filter_autop would generate - // it again, making it impossible to detect that filter_html actually - // stripped it away. Hence we need to use two adjacent

    tags. - 'testcase' => '

    Hello, world!

    This is Drupal!

    ', - 'attributes' => array( - 'prefix' => '

    '>Hello, world!

    ', - 'names' => array('dir'), - ), - ), - array( - 'tag' => 'blockquote', - 'testcase' => '
    Veni, vidi, vici.
    ', - 'attributes' => array( - 'prefix' => '
    '>Veni, vidi, vici!
    ', - 'names' => array('cite'), - ), - ), - array('tag' => 'h1', 'testcase' => '

    heading 1

    '), - array('tag' => 'h2', 'testcase' => '

    heading 2

    '), - array('tag' => 'h3', 'testcase' => '

    heading 3

    '), - array('tag' => 'h4', 'testcase' => '

    heading 4

    '), - array('tag' => 'h5', 'testcase' => '
    heading 5
    '), - array('tag' => 'h6', 'testcase' => '
    heading 6
    '), - array('tag' => 'ul', 'testcase' => '
    • A
    • B
    '), - array('tag' => 'ol', 'testcase' => '
    1. A
    2. B
    '), - array('tag' => 'li', 'testcase' => '
  • A
  • '), - array('tag' => 'pre', 'testcase' => '
    preformatted text
    '), - // Text-level elements. (Should all be wrapped in

    tags.) - array( - 'tag' => 'a', - 'testcase' => '

    hyperlink

    ', - 'attributes' => array( - 'prefix' => '

    '>hyperlink

    ', - 'names' => array('href', 'target', 'rel', 'media'), - ), - ), - array('tag' => 'em', 'testcase' => '

    emphasized

    '), - array('tag' => 'strong', 'testcase' => '

    strong

    '), - array('tag' => 'i', 'testcase' => '

    italicized

    '), - array('tag' => 'b', 'testcase' => '

    bold

    '), - array('tag' => 'u', 'testcase' => '

    underlined

    '), - array('tag' => 'cite', 'testcase' => '

    He said "WOW, Drupal rocks!"

    '), - array('tag' => 'q', 'testcase' => '

    He said "WOW, Drupal rocks!"

    '), - array('tag' => 'br', 'testcase' => '

    First line
    Second line

    '), - array( - 'tag' => 'code', - 'testcase' => '

    Hello, world!

    ', - 'attributes' => array( - 'prefix' => '

    '>Hello, world!

    ', - 'names' => array('lang'), - ), - ), - array( - 'tag' => 'img', - 'testcase' => '

    ', - 'attributes' => array( - 'prefix' => '

    ' />

    ', - 'names' => array('src', 'alt', 'title') - ), - ), - ); -} - -/** - * Calculates the allowed HTML tags. - * - * @param string $format_id - * A text format ID. - * @return - * @see aloha_get_allowed_html_by_format() - * - * @todo Refactor. - * @todo Unit tests. Start from http://drupal.org/node/1782838#comment-6562024. - */ -function _aloha_calculate_allowed_html($format_id) { - // For testing whether any attribute is allowed. - $any = 'thisIsAnExtremelyUnlikelyToExistAttributeName'; - - // For testing whether data- attributes are allowed. - $data = 'data-' . chr(mt_rand(65, 90)); - - // Helper function to assert the filtered text still contains the original. - $assert_match = function ($original, $format_id) { - $filtered = check_markup($original, $format_id); - $result = preg_replace("/>\s+<", $filtered); - return stripos($result, $original) !== FALSE; - }; - - // Run all the above tagtests to determine which tags and attributes are - // allowed in the given text format. - $allowed_html = array_reduce( - _aloha_allowed_html_tests(), - function($result, $tagtest) use ($assert_match, $format_id, $any, $data) { - $tag = $tagtest['tag']; - if ($assert_match($tagtest['testcase'], $format_id)) { - $result[$tag] = array(); - - // Break early if there are no attributes to test. - if (!isset($tagtest['attributes'])) { - return $result; - } - - // Anonymous function to generate attribute test cases. - $generate_attr_testcase = function($attr) use ($tagtest) { - $case = ''; - $case .= $tagtest['attributes']['prefix']; - $case .= $attr . '="' . $attr . ' attribute test"'; - $case .= $tagtest['attributes']['suffix']; - return $case; - }; - - // The tag test passed, then we can also do the attribute tests. First, - // check if any attribute is allowed, if that's not the case, then - // figure out which specific attributes are allowed. - if ($assert_match($generate_attr_testcase($any), $format_id)) { - $result[$tag][] = '*'; - } - else { - $attrs = array_merge(array($data), $tagtest['attributes']['names']); - foreach ($attrs as $attr) { - if ($assert_match($generate_attr_testcase($attr), $format_id)) { - $result[$tag][] = ($attr === $data) ? 'data-' : $attr; - } - } - } - } - - return $result; - }, - array() - ); - - return $allowed_html; -} diff --git a/includes/pages.inc b/includes/pages.inc deleted file mode 100644 index a27422d..0000000 --- a/includes/pages.inc +++ /dev/null @@ -1,68 +0,0 @@ - $result['link'], - 't' => $result['title'], - 's' => $result['score'], - ); - } - print drupal_json_encode($json); - exit; - } -} - -/** - * Page callback: looks up relevant images in the site given a keyword. - * - * Note that also files with status = 0 are returned, i.e. those who were - * uploaded at some point in time, but not necessarily used. - * - * @param string $lookup - * The keyword to look up relevant images for. - * - * @return string - * A JSON-encoded result. - */ -function aloha_repository_image($lookup) { - $result = db_query("SELECT * FROM {file_managed} WHERE SUBSTRING(filemime, 1, 6) = 'image/' AND filename LIKE :lookup ORDER BY timestamp DESC", array( - ':lookup' => "%$lookup%" - )); - - $json = array(); - foreach ($result as $record) { - $json[] = array( - 'u' => file_create_url($record->uri), - 't' => $record->filename, - 's' => 1.0, - ); - } - - print drupal_json_encode($json); - exit; -} diff --git a/js/drupal.aloha.js b/js/drupal.aloha.js index c159ae3..f170533 100644 --- a/js/drupal.aloha.js +++ b/js/drupal.aloha.js @@ -211,7 +211,7 @@ Drupal.aloha = { // Populate the div with the value of the textarea and hide the textarea. $div - .css('height', $editable.height()) // @todo: make the height of the div resizable, like it is for textareas. + .css('height', $editable.height()) .html($editable.val()); $editable.hide(); }