Permalink
Browse files

Adjusted to changes in ace. Loading via requirejs.

  • Loading branch information...
1 parent b29210a commit d6e882215f8305e8c29f6b0fa5d0578cb79c31a7 zensations committed Jan 17, 2012
Showing with 243 additions and 3,031 deletions.
  1. +5 −4 coffee/{toolbar-drupdown.coffee → toolbar.coffee}
  2. +30 −17 drupdown.module
  3. +157 −0 js/highlight.js
  4. +0 −3,006 js/mode-drupdown.js
  5. +48 −0 js/mode.js
  6. +3 −4 js/{toolbar-drupdown.js → toolbar.js}
@@ -1,8 +1,8 @@
$ = jQuery
-define 'ace/toolbar/drupdown', ['require', 'exports', 'module'], (require, exports, module) ->
+define 'drupdown/toolbar', ['require', 'exports', 'module'], (require, exports, module) ->
Range = require("ace/range").Range;
class DrupdownToolbar
- constructor: (@element, @editor, @field_name, @format) ->
+ constructor: (@element, @editor, @format) ->
header: (level) ->
session = @editor.getSession()
@@ -184,11 +184,12 @@ define 'ace/toolbar/drupdown', ['require', 'exports', 'module'], (require, expor
$('.drupdown-float-options .column', dialog).click ->
$('input', this).attr('checked', 'checked')
files = []
+
formats = Drupal.settings.drupdown.styles[@format]
for file in ($(file).val() for file in $('.drupdown-resource'))
if file.match /^original:\/\//
- $.each formats, (style) ->
- files.push file.replace /^original:\/\//, style + '://'
+ $.each formats, (name, style) ->
+ files.push (file.replace(/^original:\/\//, style + '://'))
else
files.push file
View
@@ -10,23 +10,19 @@ function drupdown_menu() {
);
}
+function drupdown_requirejs_paths() {
+ return array(
+ 'drupdown' => drupal_get_path('module', 'drupdown') . '/js',
+ );
+}
+
function drupdown_ace_plugins_alter(&$plugins) {
- $plugins['modes']['drupdown'] = array(
- 'title' => t('Drupdown'),
- 'module' => 'ace/mode/drupdown',
- 'attached' => array(
- 'js' => array(
- drupal_get_path('module', 'drupdown') . '/js/mode-drupdown.js',
- ),
- ),
+ $plugins['modes']['drupdown/mode'] = array(
+ 'title' => 'Drupdown',
);
- $plugins['toolbars']['drupdown'] = array(
- 'title' => t('Drupdown'),
- 'module' => 'ace/toolbar/drupdown',
+ $plugins['toolbars']['drupdown/toolbar'] = array(
+ 'title' => 'Drupdown',
'attached' => array(
- 'js' => array(
- drupal_get_path('module', 'drupdown') . '/js/toolbar-drupdown.js',
- ),
'css' => array(
drupal_get_path('module', 'drupdown') . '/drupdown.css',
),
@@ -224,6 +220,7 @@ function _drupdown_link_callback($text, $url, $title, $modifier, $matches) {
function drupdown_element_info_alter(&$types) {
$types['managed_file']['#process'][] = 'drupdown_file_element_process';
$types['text_format']['#process'][] = 'drupdown_text_format_process';
+ $types['textarea']['#process'][] = 'drupdown_textarea_process';
}
function drupdown_file_element_process($element) {
@@ -246,7 +243,24 @@ function drupdown_file_element_process($element) {
}
function drupdown_text_format_process($element) {
- $formats = array_keys($element['format']['format']['#options']);
+ if (array_key_exists('format', $element)) {
+ $formats = array_keys($element['format']['format']['#options']);
+ $style_settings = _drupdown_style_settings($formats);
+ drupal_add_js(array('drupdown' => array('styles' => $style_settings)), 'setting');
+ }
+ return $element;
+}
+
+function drupdown_textarea_process($element) {
+ if (array_key_exists('#ace_format', $element)) {
+ $format = $element['#ace_format'];
+ $style_settings = _drupdown_style_settings(array($format));
+ drupal_add_js(array('drupdown' => array('styles' => $style_settings)), 'setting');
+ }
+ return $element;
+}
+
+function _drupdown_style_settings($formats = array()) {
$style_settings = array();
foreach ($formats as $format_id) {
$filters = filter_list_format($format_id);
@@ -261,6 +275,5 @@ function drupdown_text_format_process($element) {
}
}
}
- drupal_add_js(array('drupdown' => array('styles' => $style_settings)), 'setting');
- return $element;
+ return $style_settings;
}
View
@@ -0,0 +1,157 @@
+define('drupdown/highlight', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules', 'ace/mode/javascript_highlight_rules', 'ace/mode/xml_highlight_rules', 'ace/mode/html_highlight_rules', 'ace/mode/css_highlight_rules'], function(require, exports, module) {
+ "use strict";
+
+ var oop = require("ace/lib/oop");
+ var TextHighlightRules = require("ace/mode/text_highlight_rules").TextHighlightRules;
+ var JavaScriptHighlightRules = require("ace/mode/javascript_highlight_rules").JavaScriptHighlightRules;
+ var XmlHighlightRules = require("ace/mode/xml_highlight_rules").XmlHighlightRules;
+ var HtmlHighlightRules = require("ace/mode/html_highlight_rules").HtmlHighlightRules;
+ var CssHighlightRules = require("ace/mode/css_highlight_rules").CssHighlightRules;
+
+ function github_embed(tag, prefix) {
+ return { // Github style block
+ token : "support.function",
+ regex : "^```" + tag + "\\s*$",
+ next : prefix + "start"
+ };
+ }
+
+ var DrupdownHighlightRules = function() {
+
+ // regexp must not have capturing parentheses
+ // regexps are ordered -> the first match is used
+
+ this.$rules = {
+ "start" : [ {
+ token : "empty_line",
+ regex : '^$'
+ }, { // code span `
+ token : "support.function",
+ regex : "(`+)([^\\r]*?[^`])(\\1)"
+ }, { // code block
+ token : "support.function",
+ regex : "^[ ]{4}.+"
+ }, { // h1
+ token: "markup.heading.1",
+ regex: "^=+(?=\\s*$)"
+ }, { // h2
+ token: "markup.heading.1",
+ regex: "^\\-+(?=\\s*$)"
+ }, { // header
+ token : function(value) {
+ return "markup.heading." + value.length;
+ },
+ regex : "^#{1,6}"
+ }, github_embed("javascript", "js-"),
+ github_embed("xml", "xml-"),
+ github_embed("html", "html-"),
+ github_embed("css", "css-"),
+ { // Github style block
+ token : "support.function",
+ regex : "^```[a-zA-Z]+\\s*$",
+ next : "githubblock"
+ }, { // block quote
+ token : "string",
+ regex : "^[<>!][ ].+$",
+ next : "blockquote"
+ }, { // reference
+ token : ["text", "constant", "text", "url", "string", "text"],
+ regex : "^([ ]{0,3}\\[)([^\\]]+)(\\]:\\s*)([^ ]+)(\\s*(?:[\"][^\"]+[\"])?\\s*)$"
+ }, { // link by reference
+ token : ["text", "string", "text", "constant", "text"],
+ regex : "(\\[)((?:[[^\\]]*\\]|[^\\[\\]])*)(\\][ ]?(?:\\n[ ]*)?\\[)(.*?)(\\])"
+ }, { // link by url
+ token : ["text", "string", "text", "markup.underline", "string", "text"],
+ regex : "(\\[)"+
+ "(\\[[^\\]]*\\]|[^\\[\\]]*)"+
+ "(\\]\\([ \\t]*)"+
+ "(<?(?:(?:[^\\(]*?\\([^\\)]*?\\)\\S*?)|(?:.*?))>?)"+
+ "((?:[ \t]*\"(?:.*?)\"[ \\t]*)?)"+
+ "(\\))"
+ }, { // HR *
+ token : "constant",
+ regex : "^[ ]{0,2}(?:[ ]?\\*[ ]?){3,}\\s*$"
+ }, { // HR -
+ token : "constant",
+ regex : "^[ ]{0,2}(?:[ ]?\\-[ ]?){3,}\\s*$"
+ }, { // HR _
+ token : "constant",
+ regex : "^[ ]{0,2}(?:[ ]?\\_[ ]?){3,}\\s*$"
+ }, { // list
+ token : "markup.list",
+ regex : "^\\s{0,3}(?:[*+-]|\\d+\\.)\\s+",
+ next : "listblock"
+ }, { // strong ** __
+ token : "string",
+ regex : "([*]{2}|[_]{2}(?=\\S))([^\\r]*?\\S[*_]*)(\\1)"
+ }, { // emphasis * _
+ token : "string",
+ regex : "([*]|[_](?=\\S))([^\\r]*?\\S[*_]*)(\\1)"
+ }, { //
+ token : ["text", "url", "text"],
+ regex : "(<)("+
+ "(?:https?|ftp|dict):[^'\">\\s]+"+
+ "|"+
+ "(?:mailto:)?[-.\\w]+\\@[-a-z0-9]+(?:\\.[-a-z0-9]+)*\\.[a-z]+"+
+ ")(>)"
+ }, {
+ token : "text",
+ regex : "[^\\*_%$`\\[#<>]+"
+ } ],
+
+ "listblock" : [ { // Lists only escape on completely blank lines.
+ token : "empty_line",
+ regex : "^$",
+ next : "start"
+ }, {
+ token : "markup.list",
+ regex : ".+"
+ } ],
+
+ "blockquote" : [ { // BLockquotes only escape on blank lines.
+ token : "empty_line",
+ regex : "^\\s*$",
+ next : "start"
+ }, {
+ token : "string",
+ regex : ".+"
+ } ],
+
+ "githubblock" : [ {
+ token : "support.function",
+ regex : "^```",
+ next : "start"
+ }, {
+ token : "support.function",
+ regex : ".+"
+ } ]
+ };
+
+ this.embedRules(JavaScriptHighlightRules, "js-", [{
+ token : "support.function",
+ regex : "^```",
+ next : "start"
+ }]);
+
+ this.embedRules(HtmlHighlightRules, "html-", [{
+ token : "support.function",
+ regex : "^```",
+ next : "start"
+ }]);
+
+ this.embedRules(CssHighlightRules, "css-", [{
+ token : "support.function",
+ regex : "^```",
+ next : "start"
+ }]);
+
+ this.embedRules(XmlHighlightRules, "xml-", [{
+ token : "support.function",
+ regex : "^```",
+ next : "start"
+ }]);
+ };
+ oop.inherits(DrupdownHighlightRules, TextHighlightRules);
+
+ exports.DrupdownHighlightRules = DrupdownHighlightRules;
+});
Oops, something went wrong.

0 comments on commit d6e8822

Please sign in to comment.