vendor/assets/javascripts/jstree.js in jstree-rails-4-3.1.0 vs vendor/assets/javascripts/jstree.js in jstree-rails-4-3.1.1

- old
+ new

@@ -11,11 +11,11 @@ factory(jQuery); } }(function ($, undefined) { "use strict"; /*! - * jsTree 3.1.0 + * jsTree 3.1.1 * http://jstree.com/ * * Copyright (c) 2014 Ivan Bozhanov (http://vakata.com) * * Licensed same as jquery - under the terms of the MIT License @@ -69,11 +69,11 @@ $.jstree = { /** * specifies the jstree version in use * @name $.jstree.version */ - version : '3.1.0', + version : '3.1.1', /** * holds all the default options used when creating new instances * @name $.jstree.defaults */ defaults : { @@ -709,11 +709,11 @@ */ this.trigger("loaded"); } if(!this._data.core.ready) { setTimeout($.proxy(function() { - if(!this.get_container_ul().find('.jstree-loading').length) { + if(this.element && !this.get_container_ul().find('.jstree-loading').length) { this._data.core.ready = true; if(this._data.core.selected.length) { if(this.settings.core.expand_selected_onload) { var tmp = [], i, j; for(i = 0, j = this._data.core.selected.length; i < j; i++) { @@ -824,11 +824,14 @@ this.element.attr('tabindex', '-1'); }, this)) .on('focus.jstree', $.proxy(function () { if(+(new Date()) - was_click > 500 && !this._data.core.focused) { was_click = 0; - this.get_node(this.element.attr('aria-activedescendant'), true).find('> .jstree-anchor').focus(); + var act = this.get_node(this.element.attr('aria-activedescendant'), true); + if(act) { + act.find('> .jstree-anchor').focus(); + } } }, this)) .on('mouseenter.jstree', '.jstree-anchor', $.proxy(function (e) { this.hover_node(e.currentTarget); }, this)) @@ -1466,10 +1469,11 @@ * @param {String} data the JSON object to parse and append * @param {Boolean} force_processing internal param - do not set * @trigger model.jstree, changed.jstree */ _append_json_data : function (dom, data, cb, force_processing) { + if(this.element === null) { return; } dom = this.get_node(dom); dom.children = []; dom.children_d = []; // *%$@!!! if(data.d) { @@ -1759,10 +1763,11 @@ else { return rslt; } }, rslt = function (rslt, worker) { + if(this.element === null) { return; } this._cnt = rslt.cnt; this._model.data = rslt.mod; // breaks the reference in load_node - careful if(worker) { var i, j, a = rslt.add, r = rslt.sel, s = this._data.core.selected.slice(), m = this._model.data; @@ -1925,11 +1930,11 @@ } tmp = d.children("a").children(".jstree-themeicon"); if(tmp.length) { data.icon = tmp.hasClass('jstree-themeicon-hidden') ? false : tmp.attr('rel'); } - if(data.state.icon) { + if(data.state.icon !== undefined) { data.icon = data.state.icon; } if(data.icon === undefined || data.icon === null || data.icon === "") { data.icon = true; } @@ -2823,11 +2828,11 @@ c = !c; } if(p[i] === l) { c = !c; } - if(c || p[i] === o || p[i] === l) { + if(!this.is_disabled(p[i]) && (c || p[i] === o || p[i] === l)) { this.select_node(p[i], true, false, e); } else { this.deselect_node(p[i], true, e); } @@ -3714,11 +3719,11 @@ old_par = (obj.parent || '#').toString(); new_par = (!pos.toString().match(/^(before|after)$/) || par.id === '#') ? par : this.get_node(par.parent); old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id)); is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id); old_pos = old_ins && old_ins._id && old_par && old_ins._model.data[old_par] && old_ins._model.data[old_par].children ? $.inArray(obj.id, old_ins._model.data[old_par].children) : -1; - if(old_ins || old_ins._id) { + if(old_ins && old_ins._id) { obj = old_ins._model.data[obj.id]; } if(is_multi) { if((tmp = this.copy_node(obj, par, pos, callback, is_loaded, false, origin))) { @@ -3886,11 +3891,11 @@ old_par = (obj.parent || '#').toString(); new_par = (!pos.toString().match(/^(before|after)$/) || par.id === '#') ? par : this.get_node(par.parent); old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id)); is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id); - if(old_ins || old_ins._id) { + if(old_ins && old_ins._id) { obj = old_ins._model.data[obj.id]; } if(par.id === '#') { if(pos === "before") { pos = "first"; } @@ -4082,15 +4087,16 @@ */ this.trigger('clear_buffer'); }, /** * put a node in edit mode (input field to rename the node) - * @name edit(obj [, default_text]) + * @name edit(obj [, default_text, callback]) * @param {mixed} obj - * @param {String} default_text the text to populate the input with (if omitted the node text value is used) + * @param {String} default_text the text to populate the input with (if omitted or set to a non-string value the node's text value is used) + * @param {Function} callback a function to be called once the text box is blurred, it is called in the instance's scope and receives the node and a status parameter - true if the rename is successful, false otherwise. You can access the node's title using .text */ - edit : function (obj, default_text) { + edit : function (obj, default_text, callback) { var rtl, w, a, s, t, h1, h2, fn, tmp; obj = this.get_node(obj); if(!obj) { return false; } if(this.settings.core.check_callback === false) { this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_07', 'reason' : 'Could not edit node because of check_callback' }; @@ -4128,19 +4134,26 @@ "lineHeight" : (this._data.core.li_height) + "px", "width" : "150px" // will be set a bit further down }, "blur" : $.proxy(function () { var i = s.children(".jstree-rename-input"), - v = i.val(); + v = i.val(), + f = this.settings.core.force_text, + nv; if(v === "") { v = t; } h1.remove(); s.replaceWith(a); s.remove(); + t = f ? t : $('<div></div>').append($.parseHTML(t)).html(); this.set_text(obj, t); - if(this.rename_node(obj, $('<div></div>').text(v)[this.settings.core.force_text ? 'text' : 'html']()) === false) { + nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html()); + if(!nv) { this.set_text(obj, t); // move this up? and fix #483 } + if(callback) { + callback.call(this, tmp, nv); + } }, this), "keydown" : function (event) { var key = event.which; if(key === 27) { this.value = t; @@ -4778,10 +4791,11 @@ * @private * @name _undetermined() * @plugin checkbox */ this._undetermined = function () { + if(this.element === null) { return; } var i, j, k, l, o = {}, m = this._model.data, t = this.settings.checkbox.tie_selection, s = this._data[ t ? 'core' : 'checkbox' ].selected, p = [], tt = this; for(i = 0, j = s.length; i < j; i++) { if(m[s[i]] && m[s[i]].parents) { for(k = 0, l = m[s[i]].parents.length; k < l; k++) { if(o[m[s[i]].parents[k]] === undefined && m[s[i]].parents[k] !== '#') { @@ -6431,10 +6445,17 @@ * @name $.jstree.defaults.search.show_only_matches * @plugin search */ show_only_matches : false, /** + * Indicates if the children of matched element are shown (when show_only_matches is true) + * This setting can be changed at runtime when calling the search method. Default is `false`. + * @name $.jstree.defaults.search.show_only_matches_children + * @plugin search + */ + show_only_matches_children : false, + /** * Indicates if all nodes opened to reveal the search result, should be closed when the search is cleared or a new search is performed. Default is `true`. * @name $.jstree.defaults.search.close_opened_onclear * @plugin search */ close_opened_onclear : true, @@ -6460,10 +6481,11 @@ this._data.search.str = ""; this._data.search.dom = $(); this._data.search.res = []; this._data.search.opn = []; this._data.search.som = false; + this._data.search.smc = false; this.element .on('before_open.jstree', $.proxy(function (e, data) { var i, j, f, r = this._data.search.res, s = [], o = $(); if(r && r.length) { @@ -6476,19 +6498,25 @@ s = $.vakata.array_remove_item($.vakata.array_unique(s),'#'); o = s.length ? $(this.element[0].querySelectorAll('#' + $.map(s, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #'))) : $(); this.element.find(".jstree-node").hide().filter('.jstree-last').filter(function() { return this.nextSibling; }).removeClass('jstree-last'); o = o.add(this._data.search.dom); + if(this._data.search.smc) { + this._data.search.dom.children(".jstree-children").find(".jstree-node").show(); + } o.parentsUntil(".jstree").addBack().show() .filter(".jstree-children").each(function () { $(this).children(".jstree-node:visible").eq(-1).addClass("jstree-last"); }); } } }, this)) .on("search.jstree", $.proxy(function (e, data) { if(this._data.search.som) { if(data.nodes.length) { this.element.find(".jstree-node").hide().filter('.jstree-last').filter(function() { return this.nextSibling; }).removeClass('jstree-last'); + if(this._data.search.smc) { + data.nodes.children(".jstree-children").find(".jstree-node").show(); + } data.nodes.parentsUntil(".jstree").addBack().show() .filter(".jstree-children").each(function () { $(this).children(".jstree-node:visible").eq(-1).addClass("jstree-last"); }); } } }, this)) @@ -6507,11 +6535,11 @@ * @param {mixed} inside an optional node to whose children to limit the search * @param {Boolean} append if set to true the results of this search are appended to the previous search * @plugin search * @trigger search.jstree */ - this.search = function (str, skip_async, show_only_matches, inside, append) { + this.search = function (str, skip_async, show_only_matches, inside, append, show_only_matches_children) { if(str === false || $.trim(str.toString()) === "") { return this.clear_search(); } inside = this.get_node(inside); inside = inside && inside.id ? inside.id : null; @@ -6526,10 +6554,13 @@ this.clear_search(); } if(show_only_matches === undefined) { show_only_matches = s.show_only_matches; } + if(show_only_matches_children === undefined) { + show_only_matches_children = s.show_only_matches_children; + } if(!skip_async && a !== false) { if($.isFunction(a)) { return a.call(this, str, $.proxy(function (d) { if(d && d.d) { d = d.d; } this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () { @@ -6561,9 +6592,10 @@ this._data.search.str = str; this._data.search.dom = $(); this._data.search.res = []; this._data.search.opn = []; this._data.search.som = show_only_matches; + this._data.search.smc = show_only_matches_children; } f = new $.vakata.search(str, true, { caseSensitive : s.case_sensitive, fuzzy : s.fuzzy }); $.each(m[inside ? inside : '#'].children_d, function (ii, i) { var v = m[i]; \ No newline at end of file