diff --git a/jquery.treeTable.css b/jquery.treeTable.css
deleted file mode 100644
index bec225a..0000000
--- a/jquery.treeTable.css
+++ /dev/null
@@ -1,44 +0,0 @@
-
-/* jQuery TreeTable Core 2.0 stylesheet
- *
- * This file contains styles that are used to display the tree table. Each tree
- * table is assigned the +treeTable+ class.
- * ========================================================================= */
-
-/* jquery.treeTable.collapsible
- * ------------------------------------------------------------------------- */
-.treeTable tr td .expander {
- background-position: left center;
- background-repeat: no-repeat;
- cursor: pointer;
- padding: 0;
- zoom: 1; /* IE7 Hack */
-}
-
-.treeTable tr.collapsed td .expander {
- background-image: url(arrow-right.png);
-}
-
-.treeTable tr.expanded td .expander {
- background-image: url(arrow-down.png);
-}
-
-/* jquery.treeTable.sortable
- * ------------------------------------------------------------------------- */
-.treeTable tr.selected, .treeTable tr.accept {
- background-color: #3875d7;
- color: #fff;
-}
-
-.treeTable tr.collapsed.selected td .expander, .treeTable tr.collapsed.accept td .expander {
- background-image: url(../images/toggle-expand-light.png);
-}
-
-.treeTable tr.expanded.selected td .expander, .treeTable tr.expanded.accept td .expander {
- background-image: url(../images/toggle-collapse-light.png);
-}
-
-.treeTable .ui-draggable-dragging {
- color: #000;
- z-index: 1;
-}
diff --git a/jquery.treeTable.js b/jquery.treeTable.js
deleted file mode 100644
index 847b8f3..0000000
--- a/jquery.treeTable.js
+++ /dev/null
@@ -1,220 +0,0 @@
-
-/*
- * jQuery treeTable Plugin 2.3.0
- * http://ludo.cubicphuse.nl/jquery-plugins/treeTable/
- *
- * Copyright 2010, Ludo van den Boom
- * Dual licensed under the MIT or GPL Version 2 licenses.
- */
-(function($) {
- // Helps to make options available to all functions
- // TODO: This gives problems when there are both expandable and non-expandable
- // trees on a page. The options shouldn't be global to all these instances!
- var options;
- var defaultPaddingLeft;
-
- $.fn.treeTable = function(opts) {
- options = $.extend({}, $.fn.treeTable.defaults, opts);
-
- return this.each(function() {
- $(this).addClass("treeTable").find("tbody tr").each(function() {
- // Initialize root nodes only if possible
- if(!options.expandable || $(this)[0].className.search(options.childPrefix) == -1) {
- // To optimize performance of indentation, I retrieve the padding-left
- // value of the first root node. This way I only have to call +css+
- // once.
- if (isNaN(defaultPaddingLeft)) {
- defaultPaddingLeft = parseInt($($(this).children("td")[options.treeColumn]).css('padding-left'), 10);
- }
-
- initialize($(this));
- } else if(options.initialState == "collapsed") {
- this.style.display = "none"; // Performance! $(this).hide() is slow...
- }
- });
- });
- };
-
- $.fn.treeTable.defaults = {
- childPrefix: "child-of-",
- clickableNodeNames: false,
- expandable: true,
- indent: 19,
- initialState: "collapsed",
- treeColumn: 0
- };
-
- // Recursively hide all node's children in a tree
- $.fn.collapse = function() {
- $(this).addClass("collapsed");
-
- childrenOf($(this)).each(function() {
- if(!$(this).hasClass("collapsed")) {
- $(this).collapse();
- }
-
- this.style.display = "none"; // Performance! $(this).hide() is slow...
- });
-
- return this;
- };
-
- // Recursively show all node's children in a tree
- $.fn.expand = function() {
- $(this).removeClass("collapsed").addClass("expanded");
-
- childrenOf($(this)).each(function() {
- initialize($(this));
-
- if($(this).is(".expanded.parent")) {
- $(this).expand();
- }
-
- // this.style.display = "table-row"; // Unfortunately this is not possible with IE :-(
- $(this).show();
- });
-
- return this;
- };
-
- // Reveal a node by expanding all ancestors
- $.fn.reveal = function() {
- $(ancestorsOf($(this)).reverse()).each(function() {
- initialize($(this));
- $(this).expand().show();
- });
-
- return this;
- };
-
- // Add an entire branch to +destination+
- $.fn.appendBranchTo = function(destination) {
- var node = $(this);
- var parent = parentOf(node);
-
- var ancestorNames = $.map(ancestorsOf($(destination)), function(a) { return a.id; });
-
- // Conditions:
- // 1: +node+ should not be inserted in a location in a branch if this would
- // result in +node+ being an ancestor of itself.
- // 2: +node+ should not have a parent OR the destination should not be the
- // same as +node+'s current parent (this last condition prevents +node+
- // from being moved to the same location where it already is).
- // 3: +node+ should not be inserted as a child of +node+ itself.
- if($.inArray(node[0].id, ancestorNames) == -1 && (!parent || (destination.id != parent[0].id)) && destination.id != node[0].id) {
- indent(node, ancestorsOf(node).length * options.indent * -1); // Remove indentation
-
- if(parent) { node.removeClass(options.childPrefix + parent[0].id); }
-
- node.addClass(options.childPrefix + destination.id);
- move(node, destination); // Recursively move nodes to new location
- indent(node, ancestorsOf(node).length * options.indent);
- }
-
- return this;
- };
-
- // Add reverse() function from JS Arrays
- $.fn.reverse = function() {
- return this.pushStack(this.get().reverse(), arguments);
- };
-
- // Toggle an entire branch
- $.fn.toggleBranch = function() {
- if($(this).hasClass("collapsed")) {
- $(this).expand();
- } else {
- $(this).removeClass("expanded").collapse();
- }
-
- return this;
- };
-
- // === Private functions
-
- function ancestorsOf(node) {
- var ancestors = [];
- while(node = parentOf(node)) {
- ancestors[ancestors.length] = node[0];
- }
- return ancestors;
- };
-
- function childrenOf(node) {
- return $(node).siblings("tr." + options.childPrefix + node[0].id);
- };
-
- function getPaddingLeft(node) {
- var paddingLeft = parseInt(node[0].style.paddingLeft, 10);
- return (isNaN(paddingLeft)) ? defaultPaddingLeft : paddingLeft;
- }
-
- function indent(node, value) {
- var cell = $(node.children("td")[options.treeColumn]);
- cell[0].style.paddingLeft = getPaddingLeft(cell) + value + "px";
-
- childrenOf(node).each(function() {
- indent($(this), value);
- });
- };
-
- function initialize(node) {
- if(!node.hasClass("initialized")) {
- node.addClass("initialized");
-
- var childNodes = childrenOf(node);
-
- if(!node.hasClass("parent") && childNodes.length > 0) {
- node.addClass("parent");
- }
-
- if(node.hasClass("parent")) {
- var cell = $(node.children("td")[options.treeColumn]);
- var padding = getPaddingLeft(cell) + options.indent;
-
- childNodes.each(function() {
- $(this).children("td")[options.treeColumn].style.paddingLeft = padding + "px";
- });
-
- if(options.expandable) {
- cell.prepend('');
- $(cell[0].firstChild).click(function() { node.toggleBranch(); });
-
- if(options.clickableNodeNames) {
- cell[0].style.cursor = "pointer";
- $(cell).click(function(e) {
- // Don't double-toggle if the click is on the existing expander icon
- if (e.target.className != 'expander') {
- node.toggleBranch();
- }
- });
- }
-
- // Check for a class set explicitly by the user, otherwise set the default class
- if(!(node.hasClass("expanded") || node.hasClass("collapsed"))) {
- node.addClass(options.initialState);
- }
-
- if(node.hasClass("expanded")) {
- node.expand();
- }
- }
- }
- }
- };
-
- function move(node, destination) {
- node.insertAfter(destination);
- childrenOf(node).reverse().each(function() { move($(this), node[0]); });
- };
-
- function parentOf(node) {
- var classNames = node[0].className.split(' ');
-
- for(key in classNames) {
- if(classNames[key].match(options.childPrefix)) {
- return $(node).siblings("#" + classNames[key].substring(options.childPrefix.length));
- }
- }
- };
-})(jQuery);
diff --git a/token.js b/token.js
index 98d1ac3..beb172b 100644
--- a/token.js
+++ b/token.js
@@ -4,7 +4,47 @@
Drupal.behaviors.tokenTree = {
attach: function (context, settings) {
$('table.token-tree', context).once('token-tree', function () {
- $(this).treeTable();
+ $('tr', this).each(function() {
+ var tokenType = $(this).attr('token-type');
+ if (!tokenType) return;
+
+ $('td:eq(1)', this).bind('load_node.jstree', function() { Drupal.attachBehaviors(this) }).jstree({
+ json_data : {
+ data : function(n, callback) {
+ this._get_settings().json_data.data = false;
+ return callback([{data: tokenType, state: "closed", metadata: {root: true}}])
+ },
+
+ ajax : {
+ url : function(n) {
+ var url = Drupal.settings.basePath + 'token/autocomplete/' + tokenType + "/";
+
+ if (n.data().root) {
+ return url + '[' + tokenType + ':';
+ }
+ else {
+ return url + $('> a', n).text().trim()
+ }
+ },
+ success : function(data) {
+ var nodes=[];
+ for(var k in data) {
+ if (data.hasOwnProperty(k)) {
+ if (k[k.length-1] == ':') {
+ nodes.push({data: {title: k, attr: {href: "javascript:false;"}}, state: "closed"})
+ }
+ else {
+ nodes.push({data: k, attr: {class: 'token-key'}})
+ }
+ }
+ }
+ return nodes;
+ }
+ }
+ },
+ plugins : [ "themes", "json_data" ]
+ });
+ });
});
}
};
@@ -47,9 +87,9 @@ Drupal.behaviors.tokenInsert = {
$('textarea, input[type="text"]', context).focus(function() {
Drupal.settings.tokenFocusedField = this;
});
-
- $('.token-click-insert .token-key', context).once('token-click-insert', function() {
- var newThis = $('' + $(this).html() + '').click(function(){
+
+ $('.token-key a', context).once('token-click-insert', function() {
+ $(this).click(function() {
if (typeof Drupal.settings.tokenFocusedField == 'undefined') {
alert(Drupal.t('First click a text field to insert your tokens into.'));
}
@@ -79,7 +119,6 @@ Drupal.behaviors.tokenInsert = {
}
return false;
});
- $(this).html(newThis);
});
}
};
diff --git a/token.module b/token.module
index b683c70..39456b8 100644
--- a/token.module
+++ b/token.module
@@ -170,7 +170,6 @@ function token_theme() {
'global_types' => TRUE,
'click_insert' => TRUE,
'show_restricted' => FALSE,
- 'recursion_limit' => 3,
'dialog' => FALSE,
),
'file' => 'token.pages.inc',
@@ -191,16 +190,16 @@ function token_theme() {
* Implements hook_library().
*/
function token_library() {
- // jQuery treeTable plugin.
- $libraries['treeTable'] = array(
- 'title' => 'jQuery treeTable',
- 'website' => 'http://plugins.jquery.com/project/treetable',
- 'version' => '2.3.0',
+ // jQuery jsTree plugin.
+ $libraries['jsTree'] = array(
+ 'title' => 'jQuery jsTree',
+ 'website' => 'http://www.jstree.com/',
+ 'version' => '1.0-rc3',
'js' => array(
- drupal_get_path('module', 'token') . '/jquery.treeTable.js' => array(),
+ drupal_get_path('module', 'token') . '/jquery.jstree.js' => array(),
),
'css' => array(
- drupal_get_path('module', 'token') . '/jquery.treeTable.css' => array(),
+ drupal_get_path('module', 'token') . '/jquery.jstree.css' => array(),
),
);
@@ -875,8 +874,6 @@ function token_form_user_admin_settings_alter(&$form, &$form_state) {
* @param $show_restricted
* A boolean if TRUE will show restricted tokens. Otherwise they will be
* hidden. Default is FALSE.
- * @param $recursion_limit
- * An integer with the maximum number of token levels to recurse.
* @param $parents
* An optional array with the current parents of the tokens.
*/
diff --git a/token.pages.inc b/token.pages.inc
index 85b8fe3..c7e55f1 100644
--- a/token.pages.inc
+++ b/token.pages.inc
@@ -82,7 +82,7 @@ function theme_tree_table($variables) {
}
if (!empty($variables['rows'])) {
- drupal_add_library('token', 'treeTable');
+ drupal_add_library('token', 'jsTree');
}
return theme('table', $variables);
@@ -108,20 +108,10 @@ function theme_token_tree($variables) {
$token_types = array_merge($token_types, token_get_global_token_types());
}
- $element = array(
- '#cache' => array(
- 'cid' => 'tree-rendered:' . hash('sha256', serialize(array('token_types' => $token_types, 'global_types' => NULL) + $variables)),
- 'bin' => 'cache_token',
- ),
- );
- if ($cached_output = token_render_cache_get($element)) {
- return $cached_output;
- }
-
$options = array(
'flat' => TRUE,
'restricted' => $variables['show_restricted'],
- 'depth' => $variables['recursion_limit'],
+ 'depth' => 0
);
$multiple_token_types = (count($token_types) > 1);
$rows = array();
@@ -133,26 +123,14 @@ function theme_token_tree($variables) {
if ($multiple_token_types) {
$row = _token_token_tree_format_row($type, $type_info, TRUE);
- unset($row['data']['value']);
- $rows[] = $row;
- }
-
- $tree = token_build_tree($type, $options);
- foreach ($tree as $token => $token_info) {
- if (!empty($token_info['restricted']) && empty($variables['show_restricted'])) {
- continue;
- }
- if ($multiple_token_types && !isset($token_info['parent'])) {
- $token_info['parent'] = $type;
- }
- $row = _token_token_tree_format_row($token, $token_info);
+ $row['token-type'] = $type;
unset($row['data']['value']);
$rows[] = $row;
}
}
- $element += array(
- '#theme' => 'tree_table',
+ $element = array(
+ '#theme' => 'table',
'#header' => array(
t('Name'),
t('Token'),
@@ -164,7 +142,7 @@ function theme_token_tree($variables) {
'#attached' => array(
'js' => array(drupal_get_path('module', 'token') . '/token.js'),
'css' => array(drupal_get_path('module', 'token') . '/token.css'),
- 'library' => array(array('token', 'treeTable')),
+ 'library' => array(array('token', 'jsTree')),
),
);
@@ -173,9 +151,7 @@ function theme_token_tree($variables) {
$element['#attributes']['class'][] = 'token-click-insert';
}
- $output = drupal_render($element);
- token_render_cache_set($output, $element);
- return $output;
+ return drupal_render($element);
}
/**