Responsive Lightbox & Gallery - Version 2.2.0

Version Description

  • New: Introducing Remote Library feature
  • New: Gutenberg editor compatibility
  • Tweak: PHP 7.3 support
Download this release

Release Info

Developer dfactory
Plugin Icon 128x128 Responsive Lightbox & Gallery
Version 2.2.0
Comparing to
See all releases

Code changes from version 2.1 to 2.2.0

assets/featherlight/featherlight.css CHANGED
@@ -1,160 +1,158 @@
1
- /**
2
- * Featherlight – ultra slim jQuery lightbox
3
- * Version 1.7.12 - http://noelboss.github.io/featherlight/
4
- *
5
- * Copyright 2017, Noël Raoul Bossart (http://www.noelboss.com)
6
- * MIT Licensed.
7
- **/
8
- @media all {
9
- html.with-featherlight {
10
- /* disable global scrolling when featherlights are visible */
11
- overflow: hidden;
12
- }
13
-
14
- .featherlight {
15
- display: none;
16
-
17
- /* dimensions: spanning the background from edge to edge */
18
- position:fixed;
19
- top: 0; right: 0; bottom: 0; left: 0;
20
- z-index: 2147483647; /* z-index needs to be >= elements on the site. */
21
-
22
- /* position: centering content */
23
- text-align: center;
24
-
25
- /* insures that the ::before pseudo element doesn't force wrap with fixed width content; */
26
- white-space: nowrap;
27
-
28
- /* styling */
29
- cursor: pointer;
30
- background: #333;
31
- /* IE8 "hack" for nested featherlights */
32
- background: rgba(0, 0, 0, 0);
33
- }
34
-
35
- /* support for nested featherlights. Does not work in IE8 (use JS to fix) */
36
- .featherlight:last-of-type {
37
- background: rgba(0, 0, 0, 0.8);
38
- }
39
-
40
- .featherlight:before {
41
- /* position: trick to center content vertically */
42
- content: '';
43
- display: inline-block;
44
- height: 100%;
45
- vertical-align: middle;
46
- }
47
-
48
- .featherlight .featherlight-content {
49
- /* make content container for positioned elements (close button) */
50
- position: relative;
51
-
52
- /* position: centering vertical and horizontal */
53
- text-align: left;
54
- vertical-align: middle;
55
- display: inline-block;
56
-
57
- /* dimensions: cut off images */
58
- overflow: auto;
59
- padding: 25px 25px 0;
60
- border-bottom: 25px solid transparent;
61
-
62
- /* dimensions: handling large content */
63
- margin-left: 5%;
64
- margin-right: 5%;
65
- max-height: 95%;
66
-
67
- /* styling */
68
- background: #fff;
69
- cursor: auto;
70
-
71
- /* reset white-space wrapping */
72
- white-space: normal;
73
- }
74
-
75
- /* contains the content */
76
- .featherlight .featherlight-inner {
77
- /* make sure its visible */
78
- display: block;
79
- }
80
-
81
- /* don't show these though */
82
- .featherlight script.featherlight-inner,
83
- .featherlight link.featherlight-inner,
84
- .featherlight style.featherlight-inner {
85
- display: none;
86
- }
87
-
88
- .featherlight .featherlight-close-icon {
89
- /* position: centering vertical and horizontal */
90
- position: absolute;
91
- z-index: 9999;
92
- top: 0;
93
- right: 0;
94
-
95
- /* dimensions: 25px x 25px */
96
- line-height: 25px;
97
- width: 25px;
98
-
99
- /* styling */
100
- cursor: pointer;
101
- text-align: center;
102
- font-family: Arial, sans-serif;
103
- background: #fff; /* Set the background in case it overlaps the content */
104
- background: rgba(255, 255, 255, 0.3);
105
- color: #000;
106
- border: none;
107
- padding: 0;
108
- }
109
-
110
- /* See http://stackoverflow.com/questions/16077341/how-to-reset-all-default-styles-of-the-html5-button-element */
111
- .featherlight .featherlight-close-icon::-moz-focus-inner {
112
- border: 0;
113
- padding: 0;
114
- }
115
-
116
- .featherlight .featherlight-image {
117
- /* styling */
118
- width: 100%;
119
- }
120
-
121
-
122
- .featherlight-iframe .featherlight-content {
123
- /* removed the border for image croping since iframe is edge to edge */
124
- border-bottom: 0;
125
- padding: 0;
126
- -webkit-overflow-scrolling: touch;
127
- overflow-y: scroll;
128
- }
129
-
130
- .featherlight iframe {
131
- /* styling */
132
- border: none;
133
- }
134
-
135
- .featherlight * { /* See https://github.com/noelboss/featherlight/issues/42 */
136
- -webkit-box-sizing: border-box;
137
- -moz-box-sizing: border-box;
138
- box-sizing: border-box;
139
- }
140
- }
141
-
142
- /* handling phones and small screens */
143
- @media only screen and (max-width: 1024px) {
144
- .featherlight .featherlight-content {
145
- /* dimensions: maximize lightbox with for small screens */
146
- margin-left: 0;
147
- margin-right: 0;
148
- max-height: 98%;
149
-
150
- padding: 10px 10px 0;
151
- border-bottom: 10px solid transparent;
152
- }
153
- }
154
-
155
- /* hide non featherlight items when printing */
156
- @media print {
157
- html.with-featherlight > * > :not(.featherlight) {
158
- display: none;
159
- }
160
- }
1
+ /**
2
+ * Featherlight – ultra slim jQuery lightbox
3
+ * Version 1.7.13 - http://noelboss.github.io/featherlight/
4
+ *
5
+ * Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
6
+ * MIT Licensed.
7
+ **/
8
+
9
+ html.with-featherlight {
10
+ /* disable global scrolling when featherlights are visible */
11
+ overflow: hidden;
12
+ }
13
+
14
+ .featherlight {
15
+ display: none;
16
+
17
+ /* dimensions: spanning the background from edge to edge */
18
+ position:fixed;
19
+ top: 0; right: 0; bottom: 0; left: 0;
20
+ z-index: 2147483647; /* z-index needs to be >= elements on the site. */
21
+
22
+ /* position: centering content */
23
+ text-align: center;
24
+
25
+ /* insures that the ::before pseudo element doesn't force wrap with fixed width content; */
26
+ white-space: nowrap;
27
+
28
+ /* styling */
29
+ cursor: pointer;
30
+ background: #333;
31
+ /* IE8 "hack" for nested featherlights */
32
+ background: rgba(0, 0, 0, 0);
33
+ }
34
+
35
+ /* support for nested featherlights. Does not work in IE8 (use JS to fix) */
36
+ .featherlight:last-of-type {
37
+ background: rgba(0, 0, 0, 0.8);
38
+ }
39
+
40
+ .featherlight:before {
41
+ /* position: trick to center content vertically */
42
+ content: '';
43
+ display: inline-block;
44
+ height: 100%;
45
+ vertical-align: middle;
46
+ }
47
+
48
+ .featherlight .featherlight-content {
49
+ /* make content container for positioned elements (close button) */
50
+ position: relative;
51
+
52
+ /* position: centering vertical and horizontal */
53
+ text-align: left;
54
+ vertical-align: middle;
55
+ display: inline-block;
56
+
57
+ /* dimensions: cut off images */
58
+ overflow: auto;
59
+ padding: 25px 25px 0;
60
+ border-bottom: 25px solid transparent;
61
+
62
+ /* dimensions: handling large content */
63
+ margin-left: 5%;
64
+ margin-right: 5%;
65
+ max-height: 95%;
66
+
67
+ /* styling */
68
+ background: #fff;
69
+ cursor: auto;
70
+
71
+ /* reset white-space wrapping */
72
+ white-space: normal;
73
+ }
74
+
75
+ /* contains the content */
76
+ .featherlight .featherlight-inner {
77
+ /* make sure its visible */
78
+ display: block;
79
+ }
80
+
81
+ /* don't show these though */
82
+ .featherlight script.featherlight-inner,
83
+ .featherlight link.featherlight-inner,
84
+ .featherlight style.featherlight-inner {
85
+ display: none;
86
+ }
87
+
88
+ .featherlight .featherlight-close-icon {
89
+ /* position: centering vertical and horizontal */
90
+ position: absolute;
91
+ z-index: 9999;
92
+ top: 0;
93
+ right: 0;
94
+
95
+ /* dimensions: 25px x 25px */
96
+ line-height: 25px;
97
+ width: 25px;
98
+
99
+ /* styling */
100
+ cursor: pointer;
101
+ text-align: center;
102
+ font-family: Arial, sans-serif;
103
+ background: #fff; /* Set the background in case it overlaps the content */
104
+ background: rgba(255, 255, 255, 0.3);
105
+ color: #000;
106
+ border: none;
107
+ padding: 0;
108
+ }
109
+
110
+ /* See http://stackoverflow.com/questions/16077341/how-to-reset-all-default-styles-of-the-html5-button-element */
111
+ .featherlight .featherlight-close-icon::-moz-focus-inner {
112
+ border: 0;
113
+ padding: 0;
114
+ }
115
+
116
+ .featherlight .featherlight-image {
117
+ /* styling */
118
+ width: 100%;
119
+ }
120
+
121
+
122
+ .featherlight-iframe .featherlight-content {
123
+ /* removed the border for image croping since iframe is edge to edge */
124
+ border-bottom: 0;
125
+ padding: 0;
126
+ -webkit-overflow-scrolling: touch;
127
+ }
128
+
129
+ .featherlight iframe {
130
+ /* styling */
131
+ border: none;
132
+ }
133
+
134
+ .featherlight * { /* See https://github.com/noelboss/featherlight/issues/42 */
135
+ -webkit-box-sizing: border-box;
136
+ -moz-box-sizing: border-box;
137
+ box-sizing: border-box;
138
+ }
139
+
140
+ /* handling phones and small screens */
141
+ @media only screen and (max-width: 1024px) {
142
+ .featherlight .featherlight-content {
143
+ /* dimensions: maximize lightbox with for small screens */
144
+ margin-left: 0;
145
+ margin-right: 0;
146
+ max-height: 98%;
147
+
148
+ padding: 10px 10px 0;
149
+ border-bottom: 10px solid transparent;
150
+ }
151
+ }
152
+
153
+ /* hide non featherlight items when printing */
154
+ @media print {
155
+ html.with-featherlight > * > :not(.featherlight) {
156
+ display: none;
157
+ }
158
+ }
 
 
assets/featherlight/featherlight.gallery.css CHANGED
@@ -1,122 +1,122 @@
1
- /**
2
- * Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3
- * Version 1.7.12 - http://noelboss.github.io/featherlight/
4
- *
5
- * Copyright 2017, Noël Raoul Bossart (http://www.noelboss.com)
6
- * MIT Licensed.
7
- **/
8
- @media all {
9
- .featherlight-next,
10
- .featherlight-previous {
11
- display: block;
12
- position: absolute;
13
- top: 25px;
14
- right: 25px;
15
- bottom: 0;
16
- left: 80%;
17
- cursor: pointer;
18
- /* preventing text selection */
19
- -webkit-touch-callout: none;
20
- -webkit-user-select: none;
21
- -khtml-user-select: none;
22
- -moz-user-select: none;
23
- -ms-user-select: none;
24
- user-select: none;
25
- /* IE9 hack, otherwise navigation doesn't appear */
26
- background: rgba(0,0,0,0);
27
- }
28
-
29
- .featherlight-previous {
30
- left: 25px;
31
- right: 80%;
32
- }
33
-
34
- .featherlight-next:hover,
35
- .featherlight-previous:hover {
36
- background: rgba(255,255,255,0.25);
37
- }
38
-
39
-
40
- .featherlight-next span,
41
- .featherlight-previous span {
42
- display: none;
43
- position: absolute;
44
-
45
- top: 50%;
46
- left: 5%;
47
- width: 82%;
48
-
49
- /* center horizontally */
50
- text-align: center;
51
-
52
- font-size: 80px;
53
- line-height: 80px;
54
-
55
- /* center vertically */
56
- margin-top: -40px;
57
-
58
- text-shadow: 0px 0px 5px #fff;
59
- color: #fff;
60
- font-style: normal;
61
- font-weight: normal;
62
- }
63
- .featherlight-next span {
64
- right: 5%;
65
- left: auto;
66
- }
67
-
68
-
69
- .featherlight-next:hover span,
70
- .featherlight-previous:hover span {
71
- display: inline-block;
72
- }
73
-
74
- .featherlight-swipe-aware .featherlight-next,
75
- .featherlight-swipe-aware .featherlight-previous {
76
- display: none;
77
- }
78
-
79
- /* Hide navigation while loading */
80
- .featherlight-loading .featherlight-previous, .featherlight-loading .featherlight-next {
81
- display:none;
82
- }
83
-
84
- /* Hide navigation in case of single image */
85
- .featherlight-first-slide.featherlight-last-slide .featherlight-previous,
86
- .featherlight-first-slide.featherlight-last-slide .featherlight-next {
87
- display:none;
88
- }
89
- }
90
-
91
- /* Always display arrows on touch devices */
92
- @media only screen and (max-device-width: 1024px){
93
- .featherlight-next:hover,
94
- .featherlight-previous:hover {
95
- background: none;
96
- }
97
- .featherlight-next span,
98
- .featherlight-previous span {
99
- display: block;
100
- }
101
- }
102
-
103
- /* handling phones and small screens */
104
- @media only screen and (max-width: 1024px) {
105
- .featherlight-next,
106
- .featherlight-previous {
107
- top: 10px;
108
- right: 10px;
109
- left: 85%;
110
- }
111
-
112
- .featherlight-previous {
113
- left: 10px;
114
- right: 85%;
115
- }
116
-
117
- .featherlight-next span,
118
- .featherlight-previous span {
119
- margin-top: -30px;
120
- font-size: 40px;
121
- }
122
- }
1
+ /**
2
+ * Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3
+ * Version 1.7.13 - http://noelboss.github.io/featherlight/
4
+ *
5
+ * Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
6
+ * MIT Licensed.
7
+ **/
8
+
9
+ .featherlight-next,
10
+ .featherlight-previous {
11
+ display: block;
12
+ position: absolute;
13
+ top: 25px;
14
+ right: 25px;
15
+ bottom: 0;
16
+ left: 80%;
17
+ cursor: pointer;
18
+ /* preventing text selection */
19
+ -webkit-touch-callout: none;
20
+ -webkit-user-select: none;
21
+ -khtml-user-select: none;
22
+ -moz-user-select: none;
23
+ -ms-user-select: none;
24
+ user-select: none;
25
+ /* IE9 hack, otherwise navigation doesn't appear */
26
+ background: rgba(0,0,0,0);
27
+ }
28
+
29
+ .featherlight-previous {
30
+ left: 25px;
31
+ right: 80%;
32
+ }
33
+
34
+ .featherlight-next:hover,
35
+ .featherlight-previous:hover {
36
+ background: rgba(255,255,255,0.25);
37
+ }
38
+
39
+
40
+ .featherlight-next span,
41
+ .featherlight-previous span {
42
+ display: none;
43
+ position: absolute;
44
+
45
+ top: 50%;
46
+ left: 5%;
47
+ width: 82%;
48
+
49
+ /* center horizontally */
50
+ text-align: center;
51
+
52
+ font-size: 80px;
53
+ line-height: 80px;
54
+
55
+ /* center vertically */
56
+ margin-top: -40px;
57
+
58
+ text-shadow: 0px 0px 5px #fff;
59
+ color: #fff;
60
+ font-style: normal;
61
+ font-weight: normal;
62
+ }
63
+ .featherlight-next span {
64
+ right: 5%;
65
+ left: auto;
66
+ }
67
+
68
+
69
+ .featherlight-next:hover span,
70
+ .featherlight-previous:hover span {
71
+ display: inline-block;
72
+ }
73
+
74
+ .featherlight-swipe-aware .featherlight-next,
75
+ .featherlight-swipe-aware .featherlight-previous {
76
+ display: none;
77
+ }
78
+
79
+ /* Hide navigation while loading */
80
+ .featherlight-loading .featherlight-previous, .featherlight-loading .featherlight-next {
81
+ display:none;
82
+ }
83
+
84
+ /* Hide navigation in case of single image */
85
+ .featherlight-first-slide.featherlight-last-slide .featherlight-previous,
86
+ .featherlight-first-slide.featherlight-last-slide .featherlight-next {
87
+ display:none;
88
+ }
89
+
90
+
91
+ /* Always display arrows on touch devices */
92
+ @media only screen and (max-device-width: 1024px){
93
+ .featherlight-next:hover,
94
+ .featherlight-previous:hover {
95
+ background: none;
96
+ }
97
+ .featherlight-next span,
98
+ .featherlight-previous span {
99
+ display: block;
100
+ }
101
+ }
102
+
103
+ /* handling phones and small screens */
104
+ @media only screen and (max-width: 1024px) {
105
+ .featherlight-next,
106
+ .featherlight-previous {
107
+ top: 10px;
108
+ right: 10px;
109
+ left: 85%;
110
+ }
111
+
112
+ .featherlight-previous {
113
+ left: 10px;
114
+ right: 85%;
115
+ }
116
+
117
+ .featherlight-next span,
118
+ .featherlight-previous span {
119
+ margin-top: -30px;
120
+ font-size: 40px;
121
+ }
122
+ }
assets/featherlight/featherlight.gallery.js CHANGED
@@ -1,169 +1,169 @@
1
- /**
2
- * Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3
- * Version 1.7.12 - http://noelboss.github.io/featherlight/
4
- *
5
- * Copyright 2017, Noël Raoul Bossart (http://www.noelboss.com)
6
- * MIT Licensed.
7
- **/
8
- (function($) {
9
- "use strict";
10
-
11
- var warn = function(m) {
12
- if(window.console && window.console.warn) {
13
- window.console.warn('FeatherlightGallery: ' + m);
14
- }
15
- };
16
-
17
- if('undefined' === typeof $) {
18
- return warn('Too much lightness, Featherlight needs jQuery.');
19
- } else if(!$.featherlight) {
20
- return warn('Load the featherlight plugin before the gallery plugin');
21
- }
22
-
23
- var isTouchAware = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch,
24
- jQueryConstructor = $.event && $.event.special.swipeleft && $,
25
- hammerConstructor = window.Hammer && function($el){
26
- var mc = new window.Hammer.Manager($el[0]);
27
- mc.add(new window.Hammer.Swipe());
28
- return mc;
29
- },
30
- swipeAwareConstructor = isTouchAware && (jQueryConstructor || hammerConstructor);
31
- if(isTouchAware && !swipeAwareConstructor) {
32
- warn('No compatible swipe library detected; one must be included before featherlightGallery for swipe motions to navigate the galleries.');
33
- }
34
-
35
- var callbackChain = {
36
- afterClose: function(_super, event) {
37
- var self = this;
38
- self.$instance.off('next.'+self.namespace+' previous.'+self.namespace);
39
- if (self._swiper) {
40
- self._swiper
41
- .off('swipeleft', self._swipeleft) /* See http://stackoverflow.com/questions/17367198/hammer-js-cant-remove-event-listener */
42
- .off('swiperight', self._swiperight);
43
- self._swiper = null;
44
- }
45
- return _super(event);
46
- },
47
- beforeOpen: function(_super, event){
48
- var self = this;
49
-
50
- self.$instance.on('next.'+self.namespace+' previous.'+self.namespace, function(event){
51
- var offset = event.type === 'next' ? +1 : -1;
52
- self.navigateTo(self.currentNavigation() + offset);
53
- });
54
-
55
- if (swipeAwareConstructor) {
56
- self._swiper = swipeAwareConstructor(self.$instance)
57
- .on('swipeleft', self._swipeleft = function() { self.$instance.trigger('next'); })
58
- .on('swiperight', self._swiperight = function() { self.$instance.trigger('previous'); });
59
-
60
- self.$instance
61
- .addClass(this.namespace+'-swipe-aware', swipeAwareConstructor);
62
- }
63
-
64
- self.$instance.find('.'+self.namespace+'-content')
65
- .append(self.createNavigation('previous'))
66
- .append(self.createNavigation('next'));
67
-
68
- return _super(event);
69
- },
70
- beforeContent: function(_super, event) {
71
- var index = this.currentNavigation();
72
- var len = this.slides().length;
73
- this.$instance
74
- .toggleClass(this.namespace+'-first-slide', index === 0)
75
- .toggleClass(this.namespace+'-last-slide', index === len - 1);
76
- return _super(event);
77
- },
78
- onKeyUp: function(_super, event){
79
- var dir = {
80
- 37: 'previous', /* Left arrow */
81
- 39: 'next' /* Rigth arrow */
82
- }[event.keyCode];
83
- if(dir) {
84
- this.$instance.trigger(dir);
85
- return false;
86
- } else {
87
- return _super(event);
88
- }
89
- }
90
- };
91
-
92
- function FeatherlightGallery($source, config) {
93
- if(this instanceof FeatherlightGallery) { /* called with new */
94
- $.featherlight.apply(this, arguments);
95
- this.chainCallbacks(callbackChain);
96
- } else {
97
- var flg = new FeatherlightGallery($.extend({$source: $source, $currentTarget: $source.first()}, config));
98
- flg.open();
99
- return flg;
100
- }
101
- }
102
-
103
- $.featherlight.extend(FeatherlightGallery, {
104
- autoBind: '[data-featherlight-gallery]'
105
- });
106
-
107
- $.extend(FeatherlightGallery.prototype, {
108
- /** Additional settings for Gallery **/
109
- previousIcon: '◀', /* Code that is used as previous icon */
110
- nextIcon: '▶', /* Code that is used as next icon */
111
- galleryFadeIn: 100, /* fadeIn speed when image is loaded */
112
- galleryFadeOut: 300, /* fadeOut speed before image is loaded */
113
-
114
- slides: function() {
115
- if (this.filter) {
116
- return this.$source.find(this.filter);
117
- }
118
- return this.$source;
119
- },
120
-
121
- images: function() {
122
- warn('images is deprecated, please use slides instead');
123
- return this.slides();
124
- },
125
-
126
- currentNavigation: function() {
127
- return this.slides().index(this.$currentTarget);
128
- },
129
-
130
- navigateTo: function(index) {
131
- var self = this,
132
- source = self.slides(),
133
- len = source.length,
134
- $inner = self.$instance.find('.' + self.namespace + '-inner');
135
- index = ((index % len) + len) % len; /* pin index to [0, len[ */
136
-
137
- self.$currentTarget = source.eq(index);
138
- self.beforeContent();
139
- return $.when(
140
- self.getContent(),
141
- $inner.fadeTo(self.galleryFadeOut,0.2)
142
- ).always(function($newContent) {
143
- self.setContent($newContent);
144
- self.afterContent();
145
- $newContent.fadeTo(self.galleryFadeIn,1);
146
- });
147
- },
148
-
149
- createNavigation: function(target) {
150
- var self = this;
151
- return $('<span title="'+target+'" class="'+this.namespace+'-'+target+'"><span>'+this[target+'Icon']+'</span></span>').click(function(evt){
152
- $(this).trigger(target+'.'+self.namespace);
153
- evt.preventDefault();
154
- });
155
- }
156
- });
157
-
158
- $.featherlightGallery = FeatherlightGallery;
159
-
160
- /* extend jQuery with selector featherlight method $(elm).featherlight(config, elm); */
161
- $.fn.featherlightGallery = function(config) {
162
- FeatherlightGallery.attach(this, config);
163
- return this;
164
- };
165
-
166
- /* bind featherlight on ready if config autoBind is set */
167
- $(document).ready(function(){ FeatherlightGallery._onReady(); });
168
-
169
- }(jQuery));
1
+ /**
2
+ * Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3
+ * Version 1.7.13 - http://noelboss.github.io/featherlight/
4
+ *
5
+ * Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
6
+ * MIT Licensed.
7
+ **/
8
+ (function($) {
9
+ "use strict";
10
+
11
+ var warn = function(m) {
12
+ if(window.console && window.console.warn) {
13
+ window.console.warn('FeatherlightGallery: ' + m);
14
+ }
15
+ };
16
+
17
+ if('undefined' === typeof $) {
18
+ return warn('Too much lightness, Featherlight needs jQuery.');
19
+ } else if(!$.featherlight) {
20
+ return warn('Load the featherlight plugin before the gallery plugin');
21
+ }
22
+
23
+ var isTouchAware = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch,
24
+ jQueryConstructor = $.event && $.event.special.swipeleft && $,
25
+ hammerConstructor = window.Hammer && function($el){
26
+ var mc = new window.Hammer.Manager($el[0]);
27
+ mc.add(new window.Hammer.Swipe());
28
+ return mc;
29
+ },
30
+ swipeAwareConstructor = isTouchAware && (jQueryConstructor || hammerConstructor);
31
+ if(isTouchAware && !swipeAwareConstructor) {
32
+ warn('No compatible swipe library detected; one must be included before featherlightGallery for swipe motions to navigate the galleries.');
33
+ }
34
+
35
+ var callbackChain = {
36
+ afterClose: function(_super, event) {
37
+ var self = this;
38
+ self.$instance.off('next.'+self.namespace+' previous.'+self.namespace);
39
+ if (self._swiper) {
40
+ self._swiper
41
+ .off('swipeleft', self._swipeleft) /* See http://stackoverflow.com/questions/17367198/hammer-js-cant-remove-event-listener */
42
+ .off('swiperight', self._swiperight);
43
+ self._swiper = null;
44
+ }
45
+ return _super(event);
46
+ },
47
+ beforeOpen: function(_super, event){
48
+ var self = this;
49
+
50
+ self.$instance.on('next.'+self.namespace+' previous.'+self.namespace, function(event){
51
+ var offset = event.type === 'next' ? +1 : -1;
52
+ self.navigateTo(self.currentNavigation() + offset);
53
+ });
54
+
55
+ if (swipeAwareConstructor) {
56
+ self._swiper = swipeAwareConstructor(self.$instance)
57
+ .on('swipeleft', self._swipeleft = function() { self.$instance.trigger('next'); })
58
+ .on('swiperight', self._swiperight = function() { self.$instance.trigger('previous'); });
59
+
60
+ self.$instance
61
+ .addClass(this.namespace+'-swipe-aware', swipeAwareConstructor);
62
+ }
63
+
64
+ self.$instance.find('.'+self.namespace+'-content')
65
+ .append(self.createNavigation('previous'))
66
+ .append(self.createNavigation('next'));
67
+
68
+ return _super(event);
69
+ },
70
+ beforeContent: function(_super, event) {
71
+ var index = this.currentNavigation();
72
+ var len = this.slides().length;
73
+ this.$instance
74
+ .toggleClass(this.namespace+'-first-slide', index === 0)
75
+ .toggleClass(this.namespace+'-last-slide', index === len - 1);
76
+ return _super(event);
77
+ },
78
+ onKeyUp: function(_super, event){
79
+ var dir = {
80
+ 37: 'previous', /* Left arrow */
81
+ 39: 'next' /* Rigth arrow */
82
+ }[event.keyCode];
83
+ if(dir) {
84
+ this.$instance.trigger(dir);
85
+ return false;
86
+ } else {
87
+ return _super(event);
88
+ }
89
+ }
90
+ };
91
+
92
+ function FeatherlightGallery($source, config) {
93
+ if(this instanceof FeatherlightGallery) { /* called with new */
94
+ $.featherlight.apply(this, arguments);
95
+ this.chainCallbacks(callbackChain);
96
+ } else {
97
+ var flg = new FeatherlightGallery($.extend({$source: $source, $currentTarget: $source.first()}, config));
98
+ flg.open();
99
+ return flg;
100
+ }
101
+ }
102
+
103
+ $.featherlight.extend(FeatherlightGallery, {
104
+ autoBind: '[data-featherlight-gallery]'
105
+ });
106
+
107
+ $.extend(FeatherlightGallery.prototype, {
108
+ /** Additional settings for Gallery **/
109
+ previousIcon: '&#9664;', /* Code that is used as previous icon */
110
+ nextIcon: '&#9654;', /* Code that is used as next icon */
111
+ galleryFadeIn: 100, /* fadeIn speed when image is loaded */
112
+ galleryFadeOut: 300, /* fadeOut speed before image is loaded */
113
+
114
+ slides: function() {
115
+ if (this.filter) {
116
+ return this.$source.find(this.filter);
117
+ }
118
+ return this.$source;
119
+ },
120
+
121
+ images: function() {
122
+ warn('images is deprecated, please use slides instead');
123
+ return this.slides();
124
+ },
125
+
126
+ currentNavigation: function() {
127
+ return this.slides().index(this.$currentTarget);
128
+ },
129
+
130
+ navigateTo: function(index) {
131
+ var self = this,
132
+ source = self.slides(),
133
+ len = source.length,
134
+ $inner = self.$instance.find('.' + self.namespace + '-inner');
135
+ index = ((index % len) + len) % len; /* pin index to [0, len[ */
136
+
137
+ self.$currentTarget = source.eq(index);
138
+ self.beforeContent();
139
+ return $.when(
140
+ self.getContent(),
141
+ $inner.fadeTo(self.galleryFadeOut,0.2)
142
+ ).always(function($newContent) {
143
+ self.setContent($newContent);
144
+ self.afterContent();
145
+ $newContent.fadeTo(self.galleryFadeIn,1);
146
+ });
147
+ },
148
+
149
+ createNavigation: function(target) {
150
+ var self = this;
151
+ return $('<span title="'+target+'" class="'+this.namespace+'-'+target+'"><span>'+this[target+'Icon']+'</span></span>').click(function(evt){
152
+ $(this).trigger(target+'.'+self.namespace);
153
+ evt.preventDefault();
154
+ });
155
+ }
156
+ });
157
+
158
+ $.featherlightGallery = FeatherlightGallery;
159
+
160
+ /* extend jQuery with selector featherlight method $(elm).featherlight(config, elm); */
161
+ $.fn.featherlightGallery = function(config) {
162
+ FeatherlightGallery.attach(this, config);
163
+ return this;
164
+ };
165
+
166
+ /* bind featherlight on ready if config autoBind is set */
167
+ $(document).ready(function(){ FeatherlightGallery._onReady(); });
168
+
169
+ }(jQuery));
assets/featherlight/featherlight.gallery.min.css CHANGED
@@ -1,8 +1,8 @@
1
- /**
2
- * Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3
- * Version 1.7.12 - http://noelboss.github.io/featherlight/
4
- *
5
- * Copyright 2017, Noël Raoul Bossart (http://www.noelboss.com)
6
- * MIT Licensed.
7
- **/
8
- @media all{.featherlight-next,.featherlight-previous{display:block;position:absolute;top:25px;right:25px;bottom:0;left:80%;cursor:pointer;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background:rgba(0,0,0,0)}.featherlight-previous{left:25px;right:80%}.featherlight-next:hover,.featherlight-previous:hover{background:rgba(255,255,255,.25)}.featherlight-next span,.featherlight-previous span{display:none;position:absolute;top:50%;left:5%;width:82%;text-align:center;font-size:80px;line-height:80px;margin-top:-40px;text-shadow:0 0 5px #fff;color:#fff;font-style:normal;font-weight:400}.featherlight-next span{right:5%;left:auto}.featherlight-next:hover span,.featherlight-previous:hover span{display:inline-block}.featherlight-first-slide.featherlight-last-slide .featherlight-next,.featherlight-first-slide.featherlight-last-slide .featherlight-previous,.featherlight-loading .featherlight-next,.featherlight-loading .featherlight-previous,.featherlight-swipe-aware .featherlight-next,.featherlight-swipe-aware .featherlight-previous{display:none}}@media only screen and (max-device-width:1024px){.featherlight-next:hover,.featherlight-previous:hover{background:0 0}.featherlight-next span,.featherlight-previous span{display:block}}@media only screen and (max-width:1024px){.featherlight-next,.featherlight-previous{top:10px;right:10px;left:85%}.featherlight-previous{left:10px;right:85%}.featherlight-next span,.featherlight-previous span{margin-top:-30px;font-size:40px}}
1
+ /**
2
+ * Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3
+ * Version 1.7.13 - http://noelboss.github.io/featherlight/
4
+ *
5
+ * Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
6
+ * MIT Licensed.
7
+ **/
8
+ .featherlight-next,.featherlight-previous{display:block;position:absolute;top:25px;right:25px;bottom:0;left:80%;cursor:pointer;-webkit-touch-callout:none;-webkit-user-select:none;-khtml-user-select:none;-moz-user-select:none;-ms-user-select:none;user-select:none;background:rgba(0,0,0,0)}.featherlight-previous{left:25px;right:80%}.featherlight-next:hover,.featherlight-previous:hover{background:rgba(255,255,255,.25)}.featherlight-next span,.featherlight-previous span{display:none;position:absolute;top:50%;left:5%;width:82%;text-align:center;font-size:80px;line-height:80px;margin-top:-40px;text-shadow:0 0 5px #fff;color:#fff;font-style:normal;font-weight:400}.featherlight-next span{right:5%;left:auto}.featherlight-next:hover span,.featherlight-previous:hover span{display:inline-block}.featherlight-first-slide.featherlight-last-slide .featherlight-next,.featherlight-first-slide.featherlight-last-slide .featherlight-previous,.featherlight-loading .featherlight-next,.featherlight-loading .featherlight-previous,.featherlight-swipe-aware .featherlight-next,.featherlight-swipe-aware .featherlight-previous{display:none}@media only screen and (max-device-width:1024px){.featherlight-next:hover,.featherlight-previous:hover{background:0 0}.featherlight-next span,.featherlight-previous span{display:block}}@media only screen and (max-width:1024px){.featherlight-next,.featherlight-previous{top:10px;right:10px;left:85%}.featherlight-previous{left:10px;right:85%}.featherlight-next span,.featherlight-previous span{margin-top:-30px;font-size:40px}}
assets/featherlight/featherlight.gallery.min.js CHANGED
@@ -1,7 +1,7 @@
1
- /**
2
- * Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3
- * Version 1.7.12 - http://noelboss.github.io/featherlight/
4
- *
5
- * Copyright 2017, Noël Raoul Bossart (http://www.noelboss.com)
6
- * MIT Licensed.
7
  **/!function(a){"use strict";function b(c,d){if(!(this instanceof b)){var e=new b(a.extend({$source:c,$currentTarget:c.first()},d));return e.open(),e}a.featherlight.apply(this,arguments),this.chainCallbacks(h)}var c=function(a){window.console&&window.console.warn&&window.console.warn("FeatherlightGallery: "+a)};if("undefined"==typeof a)return c("Too much lightness, Featherlight needs jQuery.");if(!a.featherlight)return c("Load the featherlight plugin before the gallery plugin");var d="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,e=a.event&&a.event.special.swipeleft&&a,f=window.Hammer&&function(a){var b=new window.Hammer.Manager(a[0]);return b.add(new window.Hammer.Swipe),b},g=d&&(e||f);d&&!g&&c("No compatible swipe library detected; one must be included before featherlightGallery for swipe motions to navigate the galleries.");var h={afterClose:function(a,b){var c=this;return c.$instance.off("next."+c.namespace+" previous."+c.namespace),c._swiper&&(c._swiper.off("swipeleft",c._swipeleft).off("swiperight",c._swiperight),c._swiper=null),a(b)},beforeOpen:function(a,b){var c=this;return c.$instance.on("next."+c.namespace+" previous."+c.namespace,function(a){var b="next"===a.type?1:-1;c.navigateTo(c.currentNavigation()+b)}),g&&(c._swiper=g(c.$instance).on("swipeleft",c._swipeleft=function(){c.$instance.trigger("next")}).on("swiperight",c._swiperight=function(){c.$instance.trigger("previous")}),c.$instance.addClass(this.namespace+"-swipe-aware",g)),c.$instance.find("."+c.namespace+"-content").append(c.createNavigation("previous")).append(c.createNavigation("next")),a(b)},beforeContent:function(a,b){var c=this.currentNavigation(),d=this.slides().length;return this.$instance.toggleClass(this.namespace+"-first-slide",0===c).toggleClass(this.namespace+"-last-slide",c===d-1),a(b)},onKeyUp:function(a,b){var c={37:"previous",39:"next"}[b.keyCode];return c?(this.$instance.trigger(c),!1):a(b)}};a.featherlight.extend(b,{autoBind:"[data-featherlight-gallery]"}),a.extend(b.prototype,{previousIcon:"&#9664;",nextIcon:"&#9654;",galleryFadeIn:100,galleryFadeOut:300,slides:function(){return this.filter?this.$source.find(this.filter):this.$source},images:function(){return c("images is deprecated, please use slides instead"),this.slides()},currentNavigation:function(){return this.slides().index(this.$currentTarget)},navigateTo:function(b){var c=this,d=c.slides(),e=d.length,f=c.$instance.find("."+c.namespace+"-inner");return b=(b%e+e)%e,c.$currentTarget=d.eq(b),c.beforeContent(),a.when(c.getContent(),f.fadeTo(c.galleryFadeOut,.2)).always(function(a){c.setContent(a),c.afterContent(),a.fadeTo(c.galleryFadeIn,1)})},createNavigation:function(b){var c=this;return a('<span title="'+b+'" class="'+this.namespace+"-"+b+'"><span>'+this[b+"Icon"]+"</span></span>").click(function(d){a(this).trigger(b+"."+c.namespace),d.preventDefault()})}}),a.featherlightGallery=b,a.fn.featherlightGallery=function(a){return b.attach(this,a),this},a(document).ready(function(){b._onReady()})}(jQuery);
1
+ /**
2
+ * Featherlight Gallery – an extension for the ultra slim jQuery lightbox
3
+ * Version 1.7.13 - http://noelboss.github.io/featherlight/
4
+ *
5
+ * Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
6
+ * MIT Licensed.
7
  **/!function(a){"use strict";function b(c,d){if(!(this instanceof b)){var e=new b(a.extend({$source:c,$currentTarget:c.first()},d));return e.open(),e}a.featherlight.apply(this,arguments),this.chainCallbacks(h)}var c=function(a){window.console&&window.console.warn&&window.console.warn("FeatherlightGallery: "+a)};if("undefined"==typeof a)return c("Too much lightness, Featherlight needs jQuery.");if(!a.featherlight)return c("Load the featherlight plugin before the gallery plugin");var d="ontouchstart"in window||window.DocumentTouch&&document instanceof DocumentTouch,e=a.event&&a.event.special.swipeleft&&a,f=window.Hammer&&function(a){var b=new window.Hammer.Manager(a[0]);return b.add(new window.Hammer.Swipe),b},g=d&&(e||f);d&&!g&&c("No compatible swipe library detected; one must be included before featherlightGallery for swipe motions to navigate the galleries.");var h={afterClose:function(a,b){var c=this;return c.$instance.off("next."+c.namespace+" previous."+c.namespace),c._swiper&&(c._swiper.off("swipeleft",c._swipeleft).off("swiperight",c._swiperight),c._swiper=null),a(b)},beforeOpen:function(a,b){var c=this;return c.$instance.on("next."+c.namespace+" previous."+c.namespace,function(a){var b="next"===a.type?1:-1;c.navigateTo(c.currentNavigation()+b)}),g&&(c._swiper=g(c.$instance).on("swipeleft",c._swipeleft=function(){c.$instance.trigger("next")}).on("swiperight",c._swiperight=function(){c.$instance.trigger("previous")}),c.$instance.addClass(this.namespace+"-swipe-aware",g)),c.$instance.find("."+c.namespace+"-content").append(c.createNavigation("previous")).append(c.createNavigation("next")),a(b)},beforeContent:function(a,b){var c=this.currentNavigation(),d=this.slides().length;return this.$instance.toggleClass(this.namespace+"-first-slide",0===c).toggleClass(this.namespace+"-last-slide",c===d-1),a(b)},onKeyUp:function(a,b){var c={37:"previous",39:"next"}[b.keyCode];return c?(this.$instance.trigger(c),!1):a(b)}};a.featherlight.extend(b,{autoBind:"[data-featherlight-gallery]"}),a.extend(b.prototype,{previousIcon:"&#9664;",nextIcon:"&#9654;",galleryFadeIn:100,galleryFadeOut:300,slides:function(){return this.filter?this.$source.find(this.filter):this.$source},images:function(){return c("images is deprecated, please use slides instead"),this.slides()},currentNavigation:function(){return this.slides().index(this.$currentTarget)},navigateTo:function(b){var c=this,d=c.slides(),e=d.length,f=c.$instance.find("."+c.namespace+"-inner");return b=(b%e+e)%e,c.$currentTarget=d.eq(b),c.beforeContent(),a.when(c.getContent(),f.fadeTo(c.galleryFadeOut,.2)).always(function(a){c.setContent(a),c.afterContent(),a.fadeTo(c.galleryFadeIn,1)})},createNavigation:function(b){var c=this;return a('<span title="'+b+'" class="'+this.namespace+"-"+b+'"><span>'+this[b+"Icon"]+"</span></span>").click(function(d){a(this).trigger(b+"."+c.namespace),d.preventDefault()})}}),a.featherlightGallery=b,a.fn.featherlightGallery=function(a){return b.attach(this,a),this},a(document).ready(function(){b._onReady()})}(jQuery);
assets/featherlight/featherlight.js CHANGED
@@ -1,631 +1,641 @@
1
- /**
2
- * Featherlight - ultra slim jQuery lightbox
3
- * Version 1.7.12 - http://noelboss.github.io/featherlight/
4
- *
5
- * Copyright 2017, Noël Raoul Bossart (http://www.noelboss.com)
6
- * MIT Licensed.
7
- **/
8
- (function($) {
9
- "use strict";
10
-
11
- if('undefined' === typeof $) {
12
- if('console' in window){ window.console.info('Too much lightness, Featherlight needs jQuery.'); }
13
- return;
14
- }
15
- if($.fn.jquery.match(/-ajax/)) {
16
- if('console' in window){ window.console.info('Featherlight needs regular jQuery, not the slim version.'); }
17
- return;
18
- }
19
- /* Featherlight is exported as $.featherlight.
20
- It is a function used to open a featherlight lightbox.
21
-
22
- [tech]
23
- Featherlight uses prototype inheritance.
24
- Each opened lightbox will have a corresponding object.
25
- That object may have some attributes that override the
26
- prototype's.
27
- Extensions created with Featherlight.extend will have their
28
- own prototype that inherits from Featherlight's prototype,
29
- thus attributes can be overriden either at the object level,
30
- or at the extension level.
31
- To create callbacks that chain themselves instead of overriding,
32
- use chainCallbacks.
33
- For those familiar with CoffeeScript, this correspond to
34
- Featherlight being a class and the Gallery being a class
35
- extending Featherlight.
36
- The chainCallbacks is used since we don't have access to
37
- CoffeeScript's `super`.
38
- */
39
-
40
- function Featherlight($content, config) {
41
- if(this instanceof Featherlight) { /* called with new */
42
- this.id = Featherlight.id++;
43
- this.setup($content, config);
44
- this.chainCallbacks(Featherlight._callbackChain);
45
- } else {
46
- var fl = new Featherlight($content, config);
47
- fl.open();
48
- return fl;
49
- }
50
- }
51
-
52
- var opened = [],
53
- pruneOpened = function(remove) {
54
- opened = $.grep(opened, function(fl) {
55
- return fl !== remove && fl.$instance.closest('body').length > 0;
56
- } );
57
- return opened;
58
- };
59
-
60
- // Removes keys of `set` from `obj` and returns the removed key/values.
61
- function slice(obj, set) {
62
- var r = {};
63
- for (var key in obj) {
64
- if (key in set) {
65
- r[key] = obj[key];
66
- delete obj[key];
67
- }
68
- }
69
- return r;
70
- }
71
-
72
- // NOTE: List of available [iframe attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe).
73
- var iFrameAttributeSet = {
74
- allowfullscreen: 1, frameborder: 1, height: 1, longdesc: 1, marginheight: 1, marginwidth: 1,
75
- name: 1, referrerpolicy: 1, scrolling: 1, sandbox: 1, src: 1, srcdoc: 1, width: 1
76
- };
77
-
78
- // Converts camelCased attributes to dasherized versions for given prefix:
79
- // parseAttrs({hello: 1, hellFrozeOver: 2}, 'hell') => {froze-over: 2}
80
- function parseAttrs(obj, prefix) {
81
- var attrs = {},
82
- regex = new RegExp('^' + prefix + '([A-Z])(.*)');
83
- for (var key in obj) {
84
- var match = key.match(regex);
85
- if (match) {
86
- var dasherized = (match[1] + match[2].replace(/([A-Z])/g, '-$1')).toLowerCase();
87
- attrs[dasherized] = obj[key];
88
- }
89
- }
90
- return attrs;
91
- }
92
-
93
- /* document wide key handler */
94
- var eventMap = { keyup: 'onKeyUp', resize: 'onResize' };
95
-
96
- var globalEventHandler = function(event) {
97
- $.each(Featherlight.opened().reverse(), function() {
98
- if (!event.isDefaultPrevented()) {
99
- if (false === this[eventMap[event.type]](event)) {
100
- event.preventDefault(); event.stopPropagation(); return false;
101
- }
102
- }
103
- });
104
- };
105
-
106
- var toggleGlobalEvents = function(set) {
107
- if(set !== Featherlight._globalHandlerInstalled) {
108
- Featherlight._globalHandlerInstalled = set;
109
- var events = $.map(eventMap, function(_, name) { return name+'.'+Featherlight.prototype.namespace; } ).join(' ');
110
- $(window)[set ? 'on' : 'off'](events, globalEventHandler);
111
- }
112
- };
113
-
114
- Featherlight.prototype = {
115
- constructor: Featherlight,
116
- /*** defaults ***/
117
- /* extend featherlight with defaults and methods */
118
- namespace: 'featherlight', /* Name of the events and css class prefix */
119
- targetAttr: 'data-featherlight', /* Attribute of the triggered element that contains the selector to the lightbox content */
120
- variant: null, /* Class that will be added to change look of the lightbox */
121
- resetCss: false, /* Reset all css */
122
- background: null, /* Custom DOM for the background, wrapper and the closebutton */
123
- openTrigger: 'click', /* Event that triggers the lightbox */
124
- closeTrigger: 'click', /* Event that triggers the closing of the lightbox */
125
- filter: null, /* Selector to filter events. Think $(...).on('click', filter, eventHandler) */
126
- root: 'body', /* Where to append featherlights */
127
- openSpeed: 250, /* Duration of opening animation */
128
- closeSpeed: 250, /* Duration of closing animation */
129
- closeOnClick: 'background', /* Close lightbox on click ('background', 'anywhere' or false) */
130
- closeOnEsc: true, /* Close lightbox when pressing esc */
131
- closeIcon: '&#10005;', /* Close icon */
132
- loading: '', /* Content to show while initial content is loading */
133
- persist: false, /* If set, the content will persist and will be shown again when opened again. 'shared' is a special value when binding multiple elements for them to share the same content */
134
- otherClose: null, /* Selector for alternate close buttons (e.g. "a.close") */
135
- beforeOpen: $.noop, /* Called before open. can return false to prevent opening of lightbox. Gets event as parameter, this contains all data */
136
- beforeContent: $.noop, /* Called when content is loaded. Gets event as parameter, this contains all data */
137
- beforeClose: $.noop, /* Called before close. can return false to prevent opening of lightbox. Gets event as parameter, this contains all data */
138
- afterOpen: $.noop, /* Called after open. Gets event as parameter, this contains all data */
139
- afterContent: $.noop, /* Called after content is ready and has been set. Gets event as parameter, this contains all data */
140
- afterClose: $.noop, /* Called after close. Gets event as parameter, this contains all data */
141
- onKeyUp: $.noop, /* Called on key up for the frontmost featherlight */
142
- onResize: $.noop, /* Called after new content and when a window is resized */
143
- type: null, /* Specify type of lightbox. If unset, it will check for the targetAttrs value. */
144
- contentFilters: ['jquery', 'image', 'html', 'ajax', 'iframe', 'text'], /* List of content filters to use to determine the content */
145
-
146
- /*** methods ***/
147
- /* setup iterates over a single instance of featherlight and prepares the background and binds the events */
148
- setup: function(target, config){
149
- /* all arguments are optional */
150
- if (typeof target === 'object' && target instanceof $ === false && !config) {
151
- config = target;
152
- target = undefined;
153
- }
154
-
155
- var self = $.extend(this, config, {target: target}),
156
- css = !self.resetCss ? self.namespace : self.namespace+'-reset', /* by adding -reset to the classname, we reset all the default css */
157
- $background = $(self.background || [
158
- '<div class="'+css+'-loading '+css+'">',
159
- '<div class="'+css+'-content">',
160
- '<button class="'+css+'-close-icon '+ self.namespace + '-close" aria-label="Close">',
161
- self.closeIcon,
162
- '</button>',
163
- '<div class="'+self.namespace+'-inner">' + self.loading + '</div>',
164
- '</div>',
165
- '</div>'].join('')),
166
- closeButtonSelector = '.'+self.namespace+'-close' + (self.otherClose ? ',' + self.otherClose : '');
167
-
168
- self.$instance = $background.clone().addClass(self.variant); /* clone DOM for the background, wrapper and the close button */
169
-
170
- /* close when click on background/anywhere/null or closebox */
171
- self.$instance.on(self.closeTrigger+'.'+self.namespace, function(event) {
172
- if(event.isDefaultPrevented()) {
173
- return;
174
- }
175
- var $target = $(event.target);
176
- if( ('background' === self.closeOnClick && $target.is('.'+self.namespace))
177
- || 'anywhere' === self.closeOnClick
178
- || $target.closest(closeButtonSelector).length ){
179
- self.close(event);
180
- event.preventDefault();
181
- }
182
- });
183
-
184
- return this;
185
- },
186
-
187
- /* this method prepares the content and converts it into a jQuery object or a promise */
188
- getContent: function(){
189
- if(this.persist !== false && this.$content) {
190
- return this.$content;
191
- }
192
- var self = this,
193
- filters = this.constructor.contentFilters,
194
- readTargetAttr = function(name){ return self.$currentTarget && self.$currentTarget.attr(name); },
195
- targetValue = readTargetAttr(self.targetAttr),
196
- data = self.target || targetValue || '';
197
-
198
- /* Find which filter applies */
199
- var filter = filters[self.type]; /* check explicit type like {type: 'image'} */
200
-
201
- /* check explicit type like data-featherlight="image" */
202
- if(!filter && data in filters) {
203
- filter = filters[data];
204
- data = self.target && targetValue;
205
- }
206
- data = data || readTargetAttr('href') || '';
207
-
208
- /* check explicity type & content like {image: 'photo.jpg'} */
209
- if(!filter) {
210
- for(var filterName in filters) {
211
- if(self[filterName]) {
212
- filter = filters[filterName];
213
- data = self[filterName];
214
- }
215
- }
216
- }
217
-
218
- /* otherwise it's implicit, run checks */
219
- if(!filter) {
220
- var target = data;
221
- data = null;
222
- $.each(self.contentFilters, function() {
223
- filter = filters[this];
224
- if(filter.test) {
225
- data = filter.test(target);
226
- }
227
- if(!data && filter.regex && target.match && target.match(filter.regex)) {
228
- data = target;
229
- }
230
- return !data;
231
- });
232
- if(!data) {
233
- if('console' in window){ window.console.error('Featherlight: no content filter found ' + (target ? ' for "' + target + '"' : ' (no target specified)')); }
234
- return false;
235
- }
236
- }
237
- /* Process it */
238
- return filter.process.call(self, data);
239
- },
240
-
241
- /* sets the content of $instance to $content */
242
- setContent: function($content){
243
- this.$instance.removeClass(this.namespace+'-loading');
244
-
245
- /* we need a special class for the iframe */
246
- this.$instance.toggleClass(this.namespace+'-iframe', $content.is('iframe'));
247
-
248
- /* replace content by appending to existing one before it is removed
249
- this insures that featherlight-inner remain at the same relative
250
- position to any other items added to featherlight-content */
251
- this.$instance.find('.'+this.namespace+'-inner')
252
- .not($content) /* excluded new content, important if persisted */
253
- .slice(1).remove().end() /* In the unexpected event where there are many inner elements, remove all but the first one */
254
- .replaceWith($.contains(this.$instance[0], $content[0]) ? '' : $content);
255
-
256
- this.$content = $content.addClass(this.namespace+'-inner');
257
-
258
- return this;
259
- },
260
-
261
- /* opens the lightbox. "this" contains $instance with the lightbox, and with the config.
262
- Returns a promise that is resolved after is successfully opened. */
263
- open: function(event){
264
- var self = this;
265
- self.$instance.hide().appendTo(self.root);
266
- if((!event || !event.isDefaultPrevented())
267
- && self.beforeOpen(event) !== false) {
268
-
269
- if(event){
270
- event.preventDefault();
271
- }
272
- var $content = self.getContent();
273
-
274
- if($content) {
275
- opened.push(self);
276
-
277
- toggleGlobalEvents(true);
278
-
279
- self.$instance.fadeIn(self.openSpeed);
280
- self.beforeContent(event);
281
-
282
- /* Set content and show */
283
- return $.when($content)
284
- .always(function($content){
285
- self.setContent($content);
286
- self.afterContent(event);
287
- })
288
- .then(self.$instance.promise())
289
- /* Call afterOpen after fadeIn is done */
290
- .done(function(){ self.afterOpen(event); });
291
- }
292
- }
293
- self.$instance.detach();
294
- return $.Deferred().reject().promise();
295
- },
296
-
297
- /* closes the lightbox. "this" contains $instance with the lightbox, and with the config
298
- returns a promise, resolved after the lightbox is successfully closed. */
299
- close: function(event){
300
- var self = this,
301
- deferred = $.Deferred();
302
-
303
- if(self.beforeClose(event) === false) {
304
- deferred.reject();
305
- } else {
306
-
307
- if (0 === pruneOpened(self).length) {
308
- toggleGlobalEvents(false);
309
- }
310
-
311
- self.$instance.fadeOut(self.closeSpeed,function(){
312
- self.$instance.detach();
313
- self.afterClose(event);
314
- deferred.resolve();
315
- });
316
- }
317
- return deferred.promise();
318
- },
319
-
320
- /* resizes the content so it fits in visible area and keeps the same aspect ratio.
321
- Does nothing if either the width or the height is not specified.
322
- Called automatically on window resize.
323
- Override if you want different behavior. */
324
- resize: function(w, h) {
325
- if (w && h) {
326
- /* Reset apparent image size first so container grows */
327
- this.$content.css('width', '').css('height', '');
328
- /* Calculate the worst ratio so that dimensions fit */
329
- /* Note: -1 to avoid rounding errors */
330
- var ratio = Math.max(
331
- w / (this.$content.parent().width()-1),
332
- h / (this.$content.parent().height()-1));
333
- /* Resize content */
334
- if (ratio > 1) {
335
- ratio = h / Math.floor(h / ratio); /* Round ratio down so height calc works */
336
- this.$content.css('width', '' + w / ratio + 'px').css('height', '' + h / ratio + 'px');
337
- }
338
- }
339
- },
340
-
341
- /* Utility function to chain callbacks
342
- [Warning: guru-level]
343
- Used be extensions that want to let users specify callbacks but
344
- also need themselves to use the callbacks.
345
- The argument 'chain' has callback names as keys and function(super, event)
346
- as values. That function is meant to call `super` at some point.
347
- */
348
- chainCallbacks: function(chain) {
349
- for (var name in chain) {
350
- this[name] = $.proxy(chain[name], this, $.proxy(this[name], this));
351
- }
352
- }
353
- };
354
-
355
- $.extend(Featherlight, {
356
- id: 0, /* Used to id single featherlight instances */
357
- autoBind: '[data-featherlight]', /* Will automatically bind elements matching this selector. Clear or set before onReady */
358
- defaults: Featherlight.prototype, /* You can access and override all defaults using $.featherlight.defaults, which is just a synonym for $.featherlight.prototype */
359
- /* Contains the logic to determine content */
360
- contentFilters: {
361
- jquery: {
362
- regex: /^[#.]\w/, /* Anything that starts with a class name or identifiers */
363
- test: function(elem) { return elem instanceof $ && elem; },
364
- process: function(elem) { return this.persist !== false ? $(elem) : $(elem).clone(true); }
365
- },
366
- image: {
367
- regex: /\.(png|jpg|jpeg|gif|tiff?|bmp|svg)(\?\S*)?$/i,
368
- process: function(url) {
369
- var self = this,
370
- deferred = $.Deferred(),
371
- img = new Image(),
372
- $img = $('<img src="'+url+'" alt="" class="'+self.namespace+'-image" />');
373
- img.onload = function() {
374
- /* Store naturalWidth & height for IE8 */
375
- $img.naturalWidth = img.width; $img.naturalHeight = img.height;
376
- deferred.resolve( $img );
377
- };
378
- img.onerror = function() { deferred.reject($img); };
379
- img.src = url;
380
- return deferred.promise();
381
- }
382
- },
383
- html: {
384
- regex: /^\s*<[\w!][^<]*>/, /* Anything that starts with some kind of valid tag */
385
- process: function(html) { return $(html); }
386
- },
387
- ajax: {
388
- regex: /./, /* At this point, any content is assumed to be an URL */
389
- process: function(url) {
390
- var self = this,
391
- deferred = $.Deferred();
392
- /* we are using load so one can specify a target with: url.html #targetelement */
393
- var $container = $('<div></div>').load(url, function(response, status){
394
- if ( status !== "error" ) {
395
- deferred.resolve($container.contents());
396
- }
397
- deferred.fail();
398
- });
399
- return deferred.promise();
400
- }
401
- },
402
- iframe: {
403
- process: function(url) {
404
- var deferred = new $.Deferred();
405
- var $content = $('<iframe/>');
406
- var css = parseAttrs(this, 'iframe');
407
- var attrs = slice(css, iFrameAttributeSet);
408
- $content.hide()
409
- .attr('src', url)
410
- .attr(attrs)
411
- .css(css)
412
- .on('load', function() { deferred.resolve($content.show()); })
413
- // We can't move an <iframe> and avoid reloading it,
414
- // so let's put it in place ourselves right now:
415
- .appendTo(this.$instance.find('.' + this.namespace + '-content'));
416
- return deferred.promise();
417
- }
418
- },
419
- text: {
420
- process: function(text) { return $('<div>', {text: text}); }
421
- }
422
- },
423
-
424
- functionAttributes: ['beforeOpen', 'afterOpen', 'beforeContent', 'afterContent', 'beforeClose', 'afterClose'],
425
-
426
- /*** class methods ***/
427
- /* read element's attributes starting with data-featherlight- */
428
- readElementConfig: function(element, namespace) {
429
- var Klass = this,
430
- regexp = new RegExp('^data-' + namespace + '-(.*)'),
431
- config = {};
432
- if (element && element.attributes) {
433
- $.each(element.attributes, function(){
434
- var match = this.name.match(regexp);
435
- if (match) {
436
- var val = this.value,
437
- name = $.camelCase(match[1]);
438
- if ($.inArray(name, Klass.functionAttributes) >= 0) { /* jshint -W054 */
439
- val = new Function(val); /* jshint +W054 */
440
- } else {
441
- try { val = JSON.parse(val); }
442
- catch(e) {}
443
- }
444
- config[name] = val;
445
- }
446
- });
447
- }
448
- return config;
449
- },
450
-
451
- /* Used to create a Featherlight extension
452
- [Warning: guru-level]
453
- Creates the extension's prototype that in turn
454
- inherits Featherlight's prototype.
455
- Could be used to extend an extension too...
456
- This is pretty high level wizardy, it comes pretty much straight
457
- from CoffeeScript and won't teach you anything about Featherlight
458
- as it's not really specific to this library.
459
- My suggestion: move along and keep your sanity.
460
- */
461
- extend: function(child, defaults) {
462
- /* Setup class hierarchy, adapted from CoffeeScript */
463
- var Ctor = function(){ this.constructor = child; };
464
- Ctor.prototype = this.prototype;
465
- child.prototype = new Ctor();
466
- child.__super__ = this.prototype;
467
- /* Copy class methods & attributes */
468
- $.extend(child, this, defaults);
469
- child.defaults = child.prototype;
470
- return child;
471
- },
472
-
473
- attach: function($source, $content, config) {
474
- var Klass = this;
475
- if (typeof $content === 'object' && $content instanceof $ === false && !config) {
476
- config = $content;
477
- $content = undefined;
478
- }
479
- /* make a copy */
480
- config = $.extend({}, config);
481
-
482
- /* Only for openTrigger and namespace... */
483
- var namespace = config.namespace || Klass.defaults.namespace,
484
- tempConfig = $.extend({}, Klass.defaults, Klass.readElementConfig($source[0], namespace), config),
485
- sharedPersist;
486
- var handler = function(event) {
487
- var $target = $(event.currentTarget);
488
- /* ... since we might as well compute the config on the actual target */
489
- var elemConfig = $.extend(
490
- {$source: $source, $currentTarget: $target},
491
- Klass.readElementConfig($source[0], tempConfig.namespace),
492
- Klass.readElementConfig(event.currentTarget, tempConfig.namespace),
493
- config);
494
- var fl = sharedPersist || $target.data('featherlight-persisted') || new Klass($content, elemConfig);
495
- if(fl.persist === 'shared') {
496
- sharedPersist = fl;
497
- } else if(fl.persist !== false) {
498
- $target.data('featherlight-persisted', fl);
499
- }
500
- if (elemConfig.$currentTarget.blur) {
501
- elemConfig.$currentTarget.blur(); // Otherwise 'enter' key might trigger the dialog again
502
- }
503
- fl.open(event);
504
- };
505
-
506
- $source.on(tempConfig.openTrigger+'.'+tempConfig.namespace, tempConfig.filter, handler);
507
-
508
- return handler;
509
- },
510
-
511
- current: function() {
512
- var all = this.opened();
513
- return all[all.length - 1] || null;
514
- },
515
-
516
- opened: function() {
517
- var klass = this;
518
- pruneOpened();
519
- return $.grep(opened, function(fl) { return fl instanceof klass; } );
520
- },
521
-
522
- close: function(event) {
523
- var cur = this.current();
524
- if(cur) { return cur.close(event); }
525
- },
526
-
527
- /* Does the auto binding on startup.
528
- Meant only to be used by Featherlight and its extensions
529
- */
530
- _onReady: function() {
531
- var Klass = this;
532
- if(Klass.autoBind){
533
- /* Bind existing elements */
534
- $(Klass.autoBind).each(function(){
535
- Klass.attach($(this));
536
- });
537
- /* If a click propagates to the document level, then we have an item that was added later on */
538
- $(document).on('click', Klass.autoBind, function(evt) {
539
- if (evt.isDefaultPrevented()) {
540
- return;
541
- }
542
- /* Bind featherlight */
543
- var handler = Klass.attach($(evt.currentTarget));
544
- /* Dispatch event directly */
545
- handler(evt);
546
- });
547
- }
548
- },
549
-
550
- /* Featherlight uses the onKeyUp callback to intercept the escape key.
551
- Private to Featherlight.
552
- */
553
- _callbackChain: {
554
- onKeyUp: function(_super, event){
555
- if(27 === event.keyCode) {
556
- if (this.closeOnEsc) {
557
- $.featherlight.close(event);
558
- }
559
- return false;
560
- } else {
561
- return _super(event);
562
- }
563
- },
564
-
565
- beforeOpen: function(_super, event) {
566
- // Used to disable scrolling
567
- $(document.documentElement).addClass('with-featherlight');
568
-
569
- // Remember focus:
570
- this._previouslyActive = document.activeElement;
571
-
572
- // Disable tabbing:
573
- // See http://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus
574
- this._$previouslyTabbable = $("a, input, select, textarea, iframe, button, iframe, [contentEditable=true]")
575
- .not('[tabindex]')
576
- .not(this.$instance.find('button'));
577
-
578
- this._$previouslyWithTabIndex = $('[tabindex]').not('[tabindex="-1"]');
579
- this._previousWithTabIndices = this._$previouslyWithTabIndex.map(function(_i, elem) {
580
- return $(elem).attr('tabindex');
581
- });
582
-
583
- this._$previouslyWithTabIndex.add(this._$previouslyTabbable).attr('tabindex', -1);
584
-
585
- if (document.activeElement.blur) {
586
- document.activeElement.blur();
587
- }
588
- return _super(event);
589
- },
590
-
591
- afterClose: function(_super, event) {
592
- var r = _super(event);
593
- // Restore focus
594
- var self = this;
595
- this._$previouslyTabbable.removeAttr('tabindex');
596
- this._$previouslyWithTabIndex.each(function(i, elem) {
597
- $(elem).attr('tabindex', self._previousWithTabIndices[i]);
598
- });
599
- this._previouslyActive.focus();
600
- // Restore scroll
601
- if(Featherlight.opened().length === 0) {
602
- $(document.documentElement).removeClass('with-featherlight');
603
- }
604
- return r;
605
- },
606
-
607
- onResize: function(_super, event){
608
- this.resize(this.$content.naturalWidth, this.$content.naturalHeight);
609
- return _super(event);
610
- },
611
-
612
- afterContent: function(_super, event){
613
- var r = _super(event);
614
- this.$instance.find('[autofocus]:not([disabled])').focus();
615
- this.onResize(event);
616
- return r;
617
- }
618
- }
619
- });
620
-
621
- $.featherlight = Featherlight;
622
-
623
- /* bind jQuery elements to trigger featherlight */
624
- $.fn.featherlight = function($content, config) {
625
- Featherlight.attach(this, $content, config);
626
- return this;
627
- };
628
-
629
- /* bind featherlight on ready if config autoBind is set */
630
- $(document).ready(function(){ Featherlight._onReady(); });
631
- }(jQuery));
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * Featherlight - ultra slim jQuery lightbox
3
+ * Version 1.7.13 - http://noelboss.github.io/featherlight/
4
+ *
5
+ * Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
6
+ * MIT Licensed.
7
+ **/
8
+ (function($) {
9
+ "use strict";
10
+
11
+ if('undefined' === typeof $) {
12
+ if('console' in window){ window.console.info('Too much lightness, Featherlight needs jQuery.'); }
13
+ return;
14
+ }
15
+ if($.fn.jquery.match(/-ajax/)) {
16
+ if('console' in window){ window.console.info('Featherlight needs regular jQuery, not the slim version.'); }
17
+ return;
18
+ }
19
+ /* Featherlight is exported as $.featherlight.
20
+ It is a function used to open a featherlight lightbox.
21
+
22
+ [tech]
23
+ Featherlight uses prototype inheritance.
24
+ Each opened lightbox will have a corresponding object.
25
+ That object may have some attributes that override the
26
+ prototype's.
27
+ Extensions created with Featherlight.extend will have their
28
+ own prototype that inherits from Featherlight's prototype,
29
+ thus attributes can be overriden either at the object level,
30
+ or at the extension level.
31
+ To create callbacks that chain themselves instead of overriding,
32
+ use chainCallbacks.
33
+ For those familiar with CoffeeScript, this correspond to
34
+ Featherlight being a class and the Gallery being a class
35
+ extending Featherlight.
36
+ The chainCallbacks is used since we don't have access to
37
+ CoffeeScript's `super`.
38
+ */
39
+
40
+ function Featherlight($content, config) {
41
+ if(this instanceof Featherlight) { /* called with new */
42
+ this.id = Featherlight.id++;
43
+ this.setup($content, config);
44
+ this.chainCallbacks(Featherlight._callbackChain);
45
+ } else {
46
+ var fl = new Featherlight($content, config);
47
+ fl.open();
48
+ return fl;
49
+ }
50
+ }
51
+
52
+ var opened = [],
53
+ pruneOpened = function(remove) {
54
+ opened = $.grep(opened, function(fl) {
55
+ return fl !== remove && fl.$instance.closest('body').length > 0;
56
+ } );
57
+ return opened;
58
+ };
59
+
60
+ // Removes keys of `set` from `obj` and returns the removed key/values.
61
+ function slice(obj, set) {
62
+ var r = {};
63
+ for (var key in obj) {
64
+ if (key in set) {
65
+ r[key] = obj[key];
66
+ delete obj[key];
67
+ }
68
+ }
69
+ return r;
70
+ }
71
+
72
+ // NOTE: List of available [iframe attributes](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/iframe).
73
+ var iFrameAttributeSet = {
74
+ allow: 1, allowfullscreen: 1, frameborder: 1, height: 1, longdesc: 1, marginheight: 1, marginwidth: 1,
75
+ mozallowfullscreen: 1, name: 1, referrerpolicy: 1, sandbox: 1, scrolling: 1, src: 1, srcdoc: 1, style: 1,
76
+ webkitallowfullscreen: 1, width: 1
77
+ };
78
+
79
+ // Converts camelCased attributes to dasherized versions for given prefix:
80
+ // parseAttrs({hello: 1, hellFrozeOver: 2}, 'hell') => {froze-over: 2}
81
+ function parseAttrs(obj, prefix) {
82
+ var attrs = {},
83
+ regex = new RegExp('^' + prefix + '([A-Z])(.*)');
84
+ for (var key in obj) {
85
+ var match = key.match(regex);
86
+ if (match) {
87
+ var dasherized = (match[1] + match[2].replace(/([A-Z])/g, '-$1')).toLowerCase();
88
+ attrs[dasherized] = obj[key];
89
+ }
90
+ }
91
+ return attrs;
92
+ }
93
+
94
+ /* document wide key handler */
95
+ var eventMap = { keyup: 'onKeyUp', resize: 'onResize' };
96
+
97
+ var globalEventHandler = function(event) {
98
+ $.each(Featherlight.opened().reverse(), function() {
99
+ if (!event.isDefaultPrevented()) {
100
+ if (false === this[eventMap[event.type]](event)) {
101
+ event.preventDefault(); event.stopPropagation(); return false;
102
+ }
103
+ }
104
+ });
105
+ };
106
+
107
+ var toggleGlobalEvents = function(set) {
108
+ if(set !== Featherlight._globalHandlerInstalled) {
109
+ Featherlight._globalHandlerInstalled = set;
110
+ var events = $.map(eventMap, function(_, name) { return name+'.'+Featherlight.prototype.namespace; } ).join(' ');
111
+ $(window)[set ? 'on' : 'off'](events, globalEventHandler);
112
+ }
113
+ };
114
+
115
+ Featherlight.prototype = {
116
+ constructor: Featherlight,
117
+ /*** defaults ***/
118
+ /* extend featherlight with defaults and methods */
119
+ namespace: 'featherlight', /* Name of the events and css class prefix */
120
+ targetAttr: 'data-featherlight', /* Attribute of the triggered element that contains the selector to the lightbox content */
121
+ variant: null, /* Class that will be added to change look of the lightbox */
122
+ resetCss: false, /* Reset all css */
123
+ background: null, /* Custom DOM for the background, wrapper and the closebutton */
124
+ openTrigger: 'click', /* Event that triggers the lightbox */
125
+ closeTrigger: 'click', /* Event that triggers the closing of the lightbox */
126
+ filter: null, /* Selector to filter events. Think $(...).on('click', filter, eventHandler) */
127
+ root: 'body', /* Where to append featherlights */
128
+ openSpeed: 250, /* Duration of opening animation */
129
+ closeSpeed: 250, /* Duration of closing animation */
130
+ closeOnClick: 'background', /* Close lightbox on click ('background', 'anywhere' or false) */
131
+ closeOnEsc: true, /* Close lightbox when pressing esc */
132
+ closeIcon: '&#10005;', /* Close icon */
133
+ loading: '', /* Content to show while initial content is loading */
134
+ persist: false, /* If set, the content will persist and will be shown again when opened again. 'shared' is a special value when binding multiple elements for them to share the same content */
135
+ otherClose: null, /* Selector for alternate close buttons (e.g. "a.close") */
136
+ beforeOpen: $.noop, /* Called before open. can return false to prevent opening of lightbox. Gets event as parameter, this contains all data */
137
+ beforeContent: $.noop, /* Called when content is loaded. Gets event as parameter, this contains all data */
138
+ beforeClose: $.noop, /* Called before close. can return false to prevent opening of lightbox. Gets event as parameter, this contains all data */
139
+ afterOpen: $.noop, /* Called after open. Gets event as parameter, this contains all data */
140
+ afterContent: $.noop, /* Called after content is ready and has been set. Gets event as parameter, this contains all data */
141
+ afterClose: $.noop, /* Called after close. Gets event as parameter, this contains all data */
142
+ onKeyUp: $.noop, /* Called on key up for the frontmost featherlight */
143
+ onResize: $.noop, /* Called after new content and when a window is resized */
144
+ type: null, /* Specify type of lightbox. If unset, it will check for the targetAttrs value. */
145
+ contentFilters: ['jquery', 'image', 'html', 'ajax', 'iframe', 'text'], /* List of content filters to use to determine the content */
146
+
147
+ /*** methods ***/
148
+ /* setup iterates over a single instance of featherlight and prepares the background and binds the events */
149
+ setup: function(target, config){
150
+ /* all arguments are optional */
151
+ if (typeof target === 'object' && target instanceof $ === false && !config) {
152
+ config = target;
153
+ target = undefined;
154
+ }
155
+
156
+ var self = $.extend(this, config, {target: target}),
157
+ css = !self.resetCss ? self.namespace : self.namespace+'-reset', /* by adding -reset to the classname, we reset all the default css */
158
+ $background = $(self.background || [
159
+ '<div class="'+css+'-loading '+css+'">',
160
+ '<div class="'+css+'-content">',
161
+ '<button class="'+css+'-close-icon '+ self.namespace + '-close" aria-label="Close">',
162
+ self.closeIcon,
163
+ '</button>',
164
+ '<div class="'+self.namespace+'-inner">' + self.loading + '</div>',
165
+ '</div>',
166
+ '</div>'].join('')),
167
+ closeButtonSelector = '.'+self.namespace+'-close' + (self.otherClose ? ',' + self.otherClose : '');
168
+
169
+ self.$instance = $background.clone().addClass(self.variant); /* clone DOM for the background, wrapper and the close button */
170
+
171
+ /* close when click on background/anywhere/null or closebox */
172
+ self.$instance.on(self.closeTrigger+'.'+self.namespace, function(event) {
173
+ if(event.isDefaultPrevented()) {
174
+ return;
175
+ }
176
+ var $target = $(event.target);
177
+ if( ('background' === self.closeOnClick && $target.is('.'+self.namespace))
178
+ || 'anywhere' === self.closeOnClick
179
+ || $target.closest(closeButtonSelector).length ){
180
+ self.close(event);
181
+ event.preventDefault();
182
+ }
183
+ });
184
+
185
+ return this;
186
+ },
187
+
188
+ /* this method prepares the content and converts it into a jQuery object or a promise */
189
+ getContent: function(){
190
+ if(this.persist !== false && this.$content) {
191
+ return this.$content;
192
+ }
193
+ var self = this,
194
+ filters = this.constructor.contentFilters,
195
+ readTargetAttr = function(name){ return self.$currentTarget && self.$currentTarget.attr(name); },
196
+ targetValue = readTargetAttr(self.targetAttr),
197
+ data = self.target || targetValue || '';
198
+
199
+ /* Find which filter applies */
200
+ var filter = filters[self.type]; /* check explicit type like {type: 'image'} */
201
+
202
+ /* check explicit type like data-featherlight="image" */
203
+ if(!filter && data in filters) {
204
+ filter = filters[data];
205
+ data = self.target && targetValue;
206
+ }
207
+ data = data || readTargetAttr('href') || '';
208
+
209
+ /* check explicity type & content like {image: 'photo.jpg'} */
210
+ if(!filter) {
211
+ for(var filterName in filters) {
212
+ if(self[filterName]) {
213
+ filter = filters[filterName];
214
+ data = self[filterName];
215
+ }
216
+ }
217
+ }
218
+
219
+ /* otherwise it's implicit, run checks */
220
+ if(!filter) {
221
+ var target = data;
222
+ data = null;
223
+ $.each(self.contentFilters, function() {
224
+ filter = filters[this];
225
+ if(filter.test) {
226
+ data = filter.test(target);
227
+ }
228
+ if(!data && filter.regex && target.match && target.match(filter.regex)) {
229
+ data = target;
230
+ }
231
+ return !data;
232
+ });
233
+ if(!data) {
234
+ if('console' in window){ window.console.error('Featherlight: no content filter found ' + (target ? ' for "' + target + '"' : ' (no target specified)')); }
235
+ return false;
236
+ }
237
+ }
238
+ /* Process it */
239
+ return filter.process.call(self, data);
240
+ },
241
+
242
+ /* sets the content of $instance to $content */
243
+ setContent: function($content){
244
+ this.$instance.removeClass(this.namespace+'-loading');
245
+
246
+ /* we need a special class for the iframe */
247
+ this.$instance.toggleClass(this.namespace+'-iframe', $content.is('iframe'));
248
+
249
+ /* replace content by appending to existing one before it is removed
250
+ this insures that featherlight-inner remain at the same relative
251
+ position to any other items added to featherlight-content */
252
+ this.$instance.find('.'+this.namespace+'-inner')
253
+ .not($content) /* excluded new content, important if persisted */
254
+ .slice(1).remove().end() /* In the unexpected event where there are many inner elements, remove all but the first one */
255
+ .replaceWith($.contains(this.$instance[0], $content[0]) ? '' : $content);
256
+
257
+ this.$content = $content.addClass(this.namespace+'-inner');
258
+
259
+ return this;
260
+ },
261
+
262
+ /* opens the lightbox. "this" contains $instance with the lightbox, and with the config.
263
+ Returns a promise that is resolved after is successfully opened. */
264
+ open: function(event){
265
+ var self = this;
266
+ self.$instance.hide().appendTo(self.root);
267
+ if((!event || !event.isDefaultPrevented())
268
+ && self.beforeOpen(event) !== false) {
269
+
270
+ if(event){
271
+ event.preventDefault();
272
+ }
273
+ var $content = self.getContent();
274
+
275
+ if($content) {
276
+ opened.push(self);
277
+
278
+ toggleGlobalEvents(true);
279
+
280
+ self.$instance.fadeIn(self.openSpeed);
281
+ self.beforeContent(event);
282
+
283
+ /* Set content and show */
284
+ return $.when($content)
285
+ .always(function($content){
286
+ self.setContent($content);
287
+ self.afterContent(event);
288
+ })
289
+ .then(self.$instance.promise())
290
+ /* Call afterOpen after fadeIn is done */
291
+ .done(function(){ self.afterOpen(event); });
292
+ }
293
+ }
294
+ self.$instance.detach();
295
+ return $.Deferred().reject().promise();
296
+ },
297
+
298
+ /* closes the lightbox. "this" contains $instance with the lightbox, and with the config
299
+ returns a promise, resolved after the lightbox is successfully closed. */
300
+ close: function(event){
301
+ var self = this,
302
+ deferred = $.Deferred();
303
+
304
+ if(self.beforeClose(event) === false) {
305
+ deferred.reject();
306
+ } else {
307
+
308
+ if (0 === pruneOpened(self).length) {
309
+ toggleGlobalEvents(false);
310
+ }
311
+
312
+ self.$instance.fadeOut(self.closeSpeed,function(){
313
+ self.$instance.detach();
314
+ self.afterClose(event);
315
+ deferred.resolve();
316
+ });
317
+ }
318
+ return deferred.promise();
319
+ },
320
+
321
+ /* resizes the content so it fits in visible area and keeps the same aspect ratio.
322
+ Does nothing if either the width or the height is not specified.
323
+ Called automatically on window resize.
324
+ Override if you want different behavior. */
325
+ resize: function(w, h) {
326
+ if (w && h) {
327
+ /* Reset apparent image size first so container grows */
328
+ this.$content.css('width', '').css('height', '');
329
+ /* Calculate the worst ratio so that dimensions fit */
330
+ /* Note: -1 to avoid rounding errors */
331
+ var ratio = Math.max(
332
+ w / (this.$content.parent().width()-1),
333
+ h / (this.$content.parent().height()-1));
334
+ /* Resize content */
335
+ if (ratio > 1) {
336
+ ratio = h / Math.floor(h / ratio); /* Round ratio down so height calc works */
337
+ this.$content.css('width', '' + w / ratio + 'px').css('height', '' + h / ratio + 'px');
338
+ }
339
+ }
340
+ },
341
+
342
+ /* Utility function to chain callbacks
343
+ [Warning: guru-level]
344
+ Used be extensions that want to let users specify callbacks but
345
+ also need themselves to use the callbacks.
346
+ The argument 'chain' has callback names as keys and function(super, event)
347
+ as values. That function is meant to call `super` at some point.
348
+ */
349
+ chainCallbacks: function(chain) {
350
+ for (var name in chain) {
351
+ this[name] = $.proxy(chain[name], this, $.proxy(this[name], this));
352
+ }
353
+ }
354
+ };
355
+
356
+ $.extend(Featherlight, {
357
+ id: 0, /* Used to id single featherlight instances */
358
+ autoBind: '[data-featherlight]', /* Will automatically bind elements matching this selector. Clear or set before onReady */
359
+ defaults: Featherlight.prototype, /* You can access and override all defaults using $.featherlight.defaults, which is just a synonym for $.featherlight.prototype */
360
+ /* Contains the logic to determine content */
361
+ contentFilters: {
362
+ jquery: {
363
+ regex: /^[#.]\w/, /* Anything that starts with a class name or identifiers */
364
+ test: function(elem) { return elem instanceof $ && elem; },
365
+ process: function(elem) { return this.persist !== false ? $(elem) : $(elem).clone(true); }
366
+ },
367
+ image: {
368
+ regex: /\.(png|jpg|jpeg|gif|tiff?|bmp|svg)(\?\S*)?$/i,
369
+ process: function(url) {
370
+ var self = this,
371
+ deferred = $.Deferred(),
372
+ img = new Image(),
373
+ $img = $('<img src="'+url+'" alt="" class="'+self.namespace+'-image" />');
374
+ img.onload = function() {
375
+ /* Store naturalWidth & height for IE8 */
376
+ $img.naturalWidth = img.width; $img.naturalHeight = img.height;
377
+ deferred.resolve( $img );
378
+ };
379
+ img.onerror = function() { deferred.reject($img); };
380
+ img.src = url;
381
+ return deferred.promise();
382
+ }
383
+ },
384
+ html: {
385
+ regex: /^\s*<[\w!][^<]*>/, /* Anything that starts with some kind of valid tag */
386
+ process: function(html) { return $(html); }
387
+ },
388
+ ajax: {
389
+ regex: /./, /* At this point, any content is assumed to be an URL */
390
+ process: function(url) {
391
+ var self = this,
392
+ deferred = $.Deferred();
393
+ /* we are using load so one can specify a target with: url.html #targetelement */
394
+ var $container = $('<div></div>').load(url, function(response, status){
395
+ if ( status !== "error" ) {
396
+ deferred.resolve($container.contents());
397
+ }
398
+ deferred.fail();
399
+ });
400
+ return deferred.promise();
401
+ }
402
+ },
403
+ iframe: {
404
+ process: function(url) {
405
+ var deferred = new $.Deferred();
406
+ var $content = $('<iframe/>');
407
+ var css = parseAttrs(this, 'iframe');
408
+ var attrs = slice(css, iFrameAttributeSet);
409
+ $content.hide()
410
+ .attr('src', url)
411
+ .attr(attrs)
412
+ .css(css)
413
+ .on('load', function() { deferred.resolve($content.show()); })
414
+ // We can't move an <iframe> and avoid reloading it,
415
+ // so let's put it in place ourselves right now:
416
+ .appendTo(this.$instance.find('.' + this.namespace + '-content'));
417
+ return deferred.promise();
418
+ }
419
+ },
420
+ text: {
421
+ process: function(text) { return $('<div>', {text: text}); }
422
+ }
423
+ },
424
+
425
+ functionAttributes: ['beforeOpen', 'afterOpen', 'beforeContent', 'afterContent', 'beforeClose', 'afterClose'],
426
+
427
+ /*** class methods ***/
428
+ /* read element's attributes starting with data-featherlight- */
429
+ readElementConfig: function(element, namespace) {
430
+ var Klass = this,
431
+ regexp = new RegExp('^data-' + namespace + '-(.*)'),
432
+ config = {};
433
+ if (element && element.attributes) {
434
+ $.each(element.attributes, function(){
435
+ var match = this.name.match(regexp);
436
+ if (match) {
437
+ var val = this.value,
438
+ name = $.camelCase(match[1]);
439
+ if ($.inArray(name, Klass.functionAttributes) >= 0) { /* jshint -W054 */
440
+ val = new Function(val); /* jshint +W054 */
441
+ } else {
442
+ try { val = JSON.parse(val); }
443
+ catch(e) {}
444
+ }
445
+ config[name] = val;
446
+ }
447
+ });
448
+ }
449
+ return config;
450
+ },
451
+
452
+ /* Used to create a Featherlight extension
453
+ [Warning: guru-level]
454
+ Creates the extension's prototype that in turn
455
+ inherits Featherlight's prototype.
456
+ Could be used to extend an extension too...
457
+ This is pretty high level wizardy, it comes pretty much straight
458
+ from CoffeeScript and won't teach you anything about Featherlight
459
+ as it's not really specific to this library.
460
+ My suggestion: move along and keep your sanity.
461
+ */
462
+ extend: function(child, defaults) {
463
+ /* Setup class hierarchy, adapted from CoffeeScript */
464
+ var Ctor = function(){ this.constructor = child; };
465
+ Ctor.prototype = this.prototype;
466
+ child.prototype = new Ctor();
467
+ child.__super__ = this.prototype;
468
+ /* Copy class methods & attributes */
469
+ $.extend(child, this, defaults);
470
+ child.defaults = child.prototype;
471
+ return child;
472
+ },
473
+
474
+ attach: function($source, $content, config) {
475
+ var Klass = this;
476
+ if (typeof $content === 'object' && $content instanceof $ === false && !config) {
477
+ config = $content;
478
+ $content = undefined;
479
+ }
480
+ /* make a copy */
481
+ config = $.extend({}, config);
482
+
483
+ /* Only for openTrigger, filter & namespace... */
484
+ var namespace = config.namespace || Klass.defaults.namespace,
485
+ tempConfig = $.extend({}, Klass.defaults, Klass.readElementConfig($source[0], namespace), config),
486
+ sharedPersist;
487
+ var handler = function(event) {
488
+ var $target = $(event.currentTarget);
489
+ /* ... since we might as well compute the config on the actual target */
490
+ var elemConfig = $.extend(
491
+ {$source: $source, $currentTarget: $target},
492
+ Klass.readElementConfig($source[0], tempConfig.namespace),
493
+ Klass.readElementConfig(event.currentTarget, tempConfig.namespace),
494
+ config);
495
+ var fl = sharedPersist || $target.data('featherlight-persisted') || new Klass($content, elemConfig);
496
+ if(fl.persist === 'shared') {
497
+ sharedPersist = fl;
498
+ } else if(fl.persist !== false) {
499
+ $target.data('featherlight-persisted', fl);
500
+ }
501
+ if (elemConfig.$currentTarget.blur) {
502
+ elemConfig.$currentTarget.blur(); // Otherwise 'enter' key might trigger the dialog again
503
+ }
504
+ fl.open(event);
505
+ };
506
+
507
+ $source.on(tempConfig.openTrigger+'.'+tempConfig.namespace, tempConfig.filter, handler);
508
+
509
+ return {filter: tempConfig.filter, handler: handler};
510
+ },
511
+
512
+ current: function() {
513
+ var all = this.opened();
514
+ return all[all.length - 1] || null;
515
+ },
516
+
517
+ opened: function() {
518
+ var klass = this;
519
+ pruneOpened();
520
+ return $.grep(opened, function(fl) { return fl instanceof klass; } );
521
+ },
522
+
523
+ close: function(event) {
524
+ var cur = this.current();
525
+ if(cur) { return cur.close(event); }
526
+ },
527
+
528
+ /* Does the auto binding on startup.
529
+ Meant only to be used by Featherlight and its extensions
530
+ */
531
+ _onReady: function() {
532
+ var Klass = this;
533
+ if(Klass.autoBind){
534
+ var $autobound = $(Klass.autoBind);
535
+ /* Bind existing elements */
536
+ $autobound.each(function(){
537
+ Klass.attach($(this));
538
+ });
539
+ /* If a click propagates to the document level, then we have an item that was added later on */
540
+ $(document).on('click', Klass.autoBind, function(evt) {
541
+ if (evt.isDefaultPrevented()) {
542
+ return;
543
+ }
544
+ var $cur = $(evt.currentTarget);
545
+ var len = $autobound.length;
546
+ $autobound = $autobound.add($cur);
547
+ if(len === $autobound.length) {
548
+ return; /* already bound */
549
+ }
550
+ /* Bind featherlight */
551
+ var data = Klass.attach($cur);
552
+ /* Dispatch event directly */
553
+ if (!data.filter || $(evt.target).parentsUntil($cur, data.filter).length > 0) {
554
+ data.handler(evt);
555
+ }
556
+ });
557
+ }
558
+ },
559
+
560
+ /* Featherlight uses the onKeyUp callback to intercept the escape key.
561
+ Private to Featherlight.
562
+ */
563
+ _callbackChain: {
564
+ onKeyUp: function(_super, event){
565
+ if(27 === event.keyCode) {
566
+ if (this.closeOnEsc) {
567
+ $.featherlight.close(event);
568
+ }
569
+ return false;
570
+ } else {
571
+ return _super(event);
572
+ }
573
+ },
574
+
575
+ beforeOpen: function(_super, event) {
576
+ // Used to disable scrolling
577
+ $(document.documentElement).addClass('with-featherlight');
578
+
579
+ // Remember focus:
580
+ this._previouslyActive = document.activeElement;
581
+
582
+ // Disable tabbing:
583
+ // See http://stackoverflow.com/questions/1599660/which-html-elements-can-receive-focus
584
+ this._$previouslyTabbable = $("a, input, select, textarea, iframe, button, iframe, [contentEditable=true]")
585
+ .not('[tabindex]')
586
+ .not(this.$instance.find('button'));
587
+
588
+ this._$previouslyWithTabIndex = $('[tabindex]').not('[tabindex="-1"]');
589
+ this._previousWithTabIndices = this._$previouslyWithTabIndex.map(function(_i, elem) {
590
+ return $(elem).attr('tabindex');
591
+ });
592
+
593
+ this._$previouslyWithTabIndex.add(this._$previouslyTabbable).attr('tabindex', -1);
594
+
595
+ if (document.activeElement.blur) {
596
+ document.activeElement.blur();
597
+ }
598
+ return _super(event);
599
+ },
600
+
601
+ afterClose: function(_super, event) {
602
+ var r = _super(event);
603
+ // Restore focus
604
+ var self = this;
605
+ this._$previouslyTabbable.removeAttr('tabindex');
606
+ this._$previouslyWithTabIndex.each(function(i, elem) {
607
+ $(elem).attr('tabindex', self._previousWithTabIndices[i]);
608
+ });
609
+ this._previouslyActive.focus();
610
+ // Restore scroll
611
+ if(Featherlight.opened().length === 0) {
612
+ $(document.documentElement).removeClass('with-featherlight');
613
+ }
614
+ return r;
615
+ },
616
+
617
+ onResize: function(_super, event){
618
+ this.resize(this.$content.naturalWidth, this.$content.naturalHeight);
619
+ return _super(event);
620
+ },
621
+
622
+ afterContent: function(_super, event){
623
+ var r = _super(event);
624
+ this.$instance.find('[autofocus]:not([disabled])').focus();
625
+ this.onResize(event);
626
+ return r;
627
+ }
628
+ }
629
+ });
630
+
631
+ $.featherlight = Featherlight;
632
+
633
+ /* bind jQuery elements to trigger featherlight */
634
+ $.fn.featherlight = function($content, config) {
635
+ Featherlight.attach(this, $content, config);
636
+ return this;
637
+ };
638
+
639
+ /* bind featherlight on ready if config autoBind is set */
640
+ $(document).ready(function(){ Featherlight._onReady(); });
641
+ }(jQuery));
assets/featherlight/featherlight.min.css CHANGED
@@ -1,8 +1,8 @@
1
- /**
2
- * Featherlight - ultra slim jQuery lightbox
3
- * Version 1.7.12 - http://noelboss.github.io/featherlight/
4
- *
5
- * Copyright 2017, Noël Raoul Bossart (http://www.noelboss.com)
6
- * MIT Licensed.
7
- **/
8
- @media all{html.with-featherlight{overflow:hidden}.featherlight{display:none;position:fixed;top:0;right:0;bottom:0;left:0;z-index:2147483647;text-align:center;white-space:nowrap;cursor:pointer;background:#333;background:rgba(0,0,0,0)}.featherlight:last-of-type{background:rgba(0,0,0,.8)}.featherlight:before{content:'';display:inline-block;height:100%;vertical-align:middle}.featherlight .featherlight-content{position:relative;text-align:left;vertical-align:middle;display:inline-block;overflow:auto;padding:25px 25px 0;border-bottom:25px solid transparent;margin-left:5%;margin-right:5%;max-height:95%;background:#fff;cursor:auto;white-space:normal}.featherlight .featherlight-inner{display:block}.featherlight link.featherlight-inner,.featherlight script.featherlight-inner,.featherlight style.featherlight-inner{display:none}.featherlight .featherlight-close-icon{position:absolute;z-index:9999;top:0;right:0;line-height:25px;width:25px;cursor:pointer;text-align:center;font-family:Arial,sans-serif;background:#fff;background:rgba(255,255,255,.3);color:#000;border:0;padding:0}.featherlight .featherlight-close-icon::-moz-focus-inner{border:0;padding:0}.featherlight .featherlight-image{width:100%}.featherlight-iframe .featherlight-content{border-bottom:0;padding:0;-webkit-overflow-scrolling:touch;overflow-y:scroll}.featherlight iframe{border:0}.featherlight *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}}@media only screen and (max-width:1024px){.featherlight .featherlight-content{margin-left:0;margin-right:0;max-height:98%;padding:10px 10px 0;border-bottom:10px solid transparent}}@media print{html.with-featherlight>*>:not(.featherlight){display:none}}
1
+ /**
2
+ * Featherlight - ultra slim jQuery lightbox
3
+ * Version 1.7.13 - http://noelboss.github.io/featherlight/
4
+ *
5
+ * Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
6
+ * MIT Licensed.
7
+ **/
8
+ html.with-featherlight{overflow:hidden}.featherlight{display:none;position:fixed;top:0;right:0;bottom:0;left:0;z-index:2147483647;text-align:center;white-space:nowrap;cursor:pointer;background:#333;background:rgba(0,0,0,0)}.featherlight:last-of-type{background:rgba(0,0,0,.8)}.featherlight:before{content:'';display:inline-block;height:100%;vertical-align:middle}.featherlight .featherlight-content{position:relative;text-align:left;vertical-align:middle;display:inline-block;overflow:auto;padding:25px 25px 0;border-bottom:25px solid transparent;margin-left:5%;margin-right:5%;max-height:95%;background:#fff;cursor:auto;white-space:normal}.featherlight .featherlight-inner{display:block}.featherlight link.featherlight-inner,.featherlight script.featherlight-inner,.featherlight style.featherlight-inner{display:none}.featherlight .featherlight-close-icon{position:absolute;z-index:9999;top:0;right:0;line-height:25px;width:25px;cursor:pointer;text-align:center;font-family:Arial,sans-serif;background:#fff;background:rgba(255,255,255,.3);color:#000;border:0;padding:0}.featherlight .featherlight-close-icon::-moz-focus-inner{border:0;padding:0}.featherlight .featherlight-image{width:100%}.featherlight-iframe .featherlight-content{border-bottom:0;padding:0;-webkit-overflow-scrolling:touch}.featherlight iframe{border:0}.featherlight *{-webkit-box-sizing:border-box;-moz-box-sizing:border-box;box-sizing:border-box}@media only screen and (max-width:1024px){.featherlight .featherlight-content{margin-left:0;margin-right:0;max-height:98%;padding:10px 10px 0;border-bottom:10px solid transparent}}@media print{html.with-featherlight>*>:not(.featherlight){display:none}}
assets/featherlight/featherlight.min.js CHANGED
@@ -1,8 +1,8 @@
1
- /**
2
- * Featherlight - ultra slim jQuery lightbox
3
- * Version 1.7.12 - http://noelboss.github.io/featherlight/
4
- *
5
- * Copyright 2017, Noël Raoul Bossart (http://www.noelboss.com)
6
- * MIT Licensed.
7
- **/
8
- !function(a){"use strict";function b(a,c){if(!(this instanceof b)){var d=new b(a,c);return d.open(),d}this.id=b.id++,this.setup(a,c),this.chainCallbacks(b._callbackChain)}function c(a,b){var c={};for(var d in a)d in b&&(c[d]=a[d],delete a[d]);return c}function d(a,b){var c={},d=new RegExp("^"+b+"([A-Z])(.*)");for(var e in a){var f=e.match(d);if(f){var g=(f[1]+f[2].replace(/([A-Z])/g,"-$1")).toLowerCase();c[g]=a[e]}}return c}if("undefined"==typeof a)return void("console"in window&&window.console.info("Too much lightness, Featherlight needs jQuery."));if(a.fn.jquery.match(/-ajax/))return void("console"in window&&window.console.info("Featherlight needs regular jQuery, not the slim version."));var e=[],f=function(b){return e=a.grep(e,function(a){return a!==b&&a.$instance.closest("body").length>0})},g={allowfullscreen:1,frameborder:1,height:1,longdesc:1,marginheight:1,marginwidth:1,name:1,referrerpolicy:1,scrolling:1,sandbox:1,src:1,srcdoc:1,width:1},h={keyup:"onKeyUp",resize:"onResize"},i=function(c){a.each(b.opened().reverse(),function(){return c.isDefaultPrevented()||!1!==this[h[c.type]](c)?void 0:(c.preventDefault(),c.stopPropagation(),!1)})},j=function(c){if(c!==b._globalHandlerInstalled){b._globalHandlerInstalled=c;var d=a.map(h,function(a,c){return c+"."+b.prototype.namespace}).join(" ");a(window)[c?"on":"off"](d,i)}};b.prototype={constructor:b,namespace:"featherlight",targetAttr:"data-featherlight",variant:null,resetCss:!1,background:null,openTrigger:"click",closeTrigger:"click",filter:null,root:"body",openSpeed:250,closeSpeed:250,closeOnClick:"background",closeOnEsc:!0,closeIcon:"&#10005;",loading:"",persist:!1,otherClose:null,beforeOpen:a.noop,beforeContent:a.noop,beforeClose:a.noop,afterOpen:a.noop,afterContent:a.noop,afterClose:a.noop,onKeyUp:a.noop,onResize:a.noop,type:null,contentFilters:["jquery","image","html","ajax","iframe","text"],setup:function(b,c){"object"!=typeof b||b instanceof a!=!1||c||(c=b,b=void 0);var d=a.extend(this,c,{target:b}),e=d.resetCss?d.namespace+"-reset":d.namespace,f=a(d.background||['<div class="'+e+"-loading "+e+'">','<div class="'+e+'-content">','<button class="'+e+"-close-icon "+d.namespace+'-close" aria-label="Close">',d.closeIcon,"</button>",'<div class="'+d.namespace+'-inner">'+d.loading+"</div>","</div>","</div>"].join("")),g="."+d.namespace+"-close"+(d.otherClose?","+d.otherClose:"");return d.$instance=f.clone().addClass(d.variant),d.$instance.on(d.closeTrigger+"."+d.namespace,function(b){if(!b.isDefaultPrevented()){var c=a(b.target);("background"===d.closeOnClick&&c.is("."+d.namespace)||"anywhere"===d.closeOnClick||c.closest(g).length)&&(d.close(b),b.preventDefault())}}),this},getContent:function(){if(this.persist!==!1&&this.$content)return this.$content;var b=this,c=this.constructor.contentFilters,d=function(a){return b.$currentTarget&&b.$currentTarget.attr(a)},e=d(b.targetAttr),f=b.target||e||"",g=c[b.type];if(!g&&f in c&&(g=c[f],f=b.target&&e),f=f||d("href")||"",!g)for(var h in c)b[h]&&(g=c[h],f=b[h]);if(!g){var i=f;if(f=null,a.each(b.contentFilters,function(){return g=c[this],g.test&&(f=g.test(i)),!f&&g.regex&&i.match&&i.match(g.regex)&&(f=i),!f}),!f)return"console"in window&&window.console.error("Featherlight: no content filter found "+(i?' for "'+i+'"':" (no target specified)")),!1}return g.process.call(b,f)},setContent:function(b){return this.$instance.removeClass(this.namespace+"-loading"),this.$instance.toggleClass(this.namespace+"-iframe",b.is("iframe")),this.$instance.find("."+this.namespace+"-inner").not(b).slice(1).remove().end().replaceWith(a.contains(this.$instance[0],b[0])?"":b),this.$content=b.addClass(this.namespace+"-inner"),this},open:function(b){var c=this;if(c.$instance.hide().appendTo(c.root),!(b&&b.isDefaultPrevented()||c.beforeOpen(b)===!1)){b&&b.preventDefault();var d=c.getContent();if(d)return e.push(c),j(!0),c.$instance.fadeIn(c.openSpeed),c.beforeContent(b),a.when(d).always(function(a){c.setContent(a),c.afterContent(b)}).then(c.$instance.promise()).done(function(){c.afterOpen(b)})}return c.$instance.detach(),a.Deferred().reject().promise()},close:function(b){var c=this,d=a.Deferred();return c.beforeClose(b)===!1?d.reject():(0===f(c).length&&j(!1),c.$instance.fadeOut(c.closeSpeed,function(){c.$instance.detach(),c.afterClose(b),d.resolve()})),d.promise()},resize:function(a,b){if(a&&b){this.$content.css("width","").css("height","");var c=Math.max(a/(this.$content.parent().width()-1),b/(this.$content.parent().height()-1));c>1&&(c=b/Math.floor(b/c),this.$content.css("width",""+a/c+"px").css("height",""+b/c+"px"))}},chainCallbacks:function(b){for(var c in b)this[c]=a.proxy(b[c],this,a.proxy(this[c],this))}},a.extend(b,{id:0,autoBind:"[data-featherlight]",defaults:b.prototype,contentFilters:{jquery:{regex:/^[#.]\w/,test:function(b){return b instanceof a&&b},process:function(b){return this.persist!==!1?a(b):a(b).clone(!0)}},image:{regex:/\.(png|jpg|jpeg|gif|tiff?|bmp|svg)(\?\S*)?$/i,process:function(b){var c=this,d=a.Deferred(),e=new Image,f=a('<img src="'+b+'" alt="" class="'+c.namespace+'-image" />');return e.onload=function(){f.naturalWidth=e.width,f.naturalHeight=e.height,d.resolve(f)},e.onerror=function(){d.reject(f)},e.src=b,d.promise()}},html:{regex:/^\s*<[\w!][^<]*>/,process:function(b){return a(b)}},ajax:{regex:/./,process:function(b){var c=a.Deferred(),d=a("<div></div>").load(b,function(a,b){"error"!==b&&c.resolve(d.contents()),c.fail()});return c.promise()}},iframe:{process:function(b){var e=new a.Deferred,f=a("<iframe/>"),h=d(this,"iframe"),i=c(h,g);return f.hide().attr("src",b).attr(i).css(h).on("load",function(){e.resolve(f.show())}).appendTo(this.$instance.find("."+this.namespace+"-content")),e.promise()}},text:{process:function(b){return a("<div>",{text:b})}}},functionAttributes:["beforeOpen","afterOpen","beforeContent","afterContent","beforeClose","afterClose"],readElementConfig:function(b,c){var d=this,e=new RegExp("^data-"+c+"-(.*)"),f={};return b&&b.attributes&&a.each(b.attributes,function(){var b=this.name.match(e);if(b){var c=this.value,g=a.camelCase(b[1]);if(a.inArray(g,d.functionAttributes)>=0)c=new Function(c);else try{c=JSON.parse(c)}catch(h){}f[g]=c}}),f},extend:function(b,c){var d=function(){this.constructor=b};return d.prototype=this.prototype,b.prototype=new d,b.__super__=this.prototype,a.extend(b,this,c),b.defaults=b.prototype,b},attach:function(b,c,d){var e=this;"object"!=typeof c||c instanceof a!=!1||d||(d=c,c=void 0),d=a.extend({},d);var f,g=d.namespace||e.defaults.namespace,h=a.extend({},e.defaults,e.readElementConfig(b[0],g),d),i=function(g){var i=a(g.currentTarget),j=a.extend({$source:b,$currentTarget:i},e.readElementConfig(b[0],h.namespace),e.readElementConfig(g.currentTarget,h.namespace),d),k=f||i.data("featherlight-persisted")||new e(c,j);"shared"===k.persist?f=k:k.persist!==!1&&i.data("featherlight-persisted",k),j.$currentTarget.blur&&j.$currentTarget.blur(),k.open(g)};return b.on(h.openTrigger+"."+h.namespace,h.filter,i),i},current:function(){var a=this.opened();return a[a.length-1]||null},opened:function(){var b=this;return f(),a.grep(e,function(a){return a instanceof b})},close:function(a){var b=this.current();return b?b.close(a):void 0},_onReady:function(){var b=this;b.autoBind&&(a(b.autoBind).each(function(){b.attach(a(this))}),a(document).on("click",b.autoBind,function(c){if(!c.isDefaultPrevented()){var d=b.attach(a(c.currentTarget));d(c)}}))},_callbackChain:{onKeyUp:function(b,c){return 27===c.keyCode?(this.closeOnEsc&&a.featherlight.close(c),!1):b(c)},beforeOpen:function(b,c){return a(document.documentElement).addClass("with-featherlight"),this._previouslyActive=document.activeElement,this._$previouslyTabbable=a("a, input, select, textarea, iframe, button, iframe, [contentEditable=true]").not("[tabindex]").not(this.$instance.find("button")),this._$previouslyWithTabIndex=a("[tabindex]").not('[tabindex="-1"]'),this._previousWithTabIndices=this._$previouslyWithTabIndex.map(function(b,c){return a(c).attr("tabindex")}),this._$previouslyWithTabIndex.add(this._$previouslyTabbable).attr("tabindex",-1),document.activeElement.blur&&document.activeElement.blur(),b(c)},afterClose:function(c,d){var e=c(d),f=this;return this._$previouslyTabbable.removeAttr("tabindex"),this._$previouslyWithTabIndex.each(function(b,c){a(c).attr("tabindex",f._previousWithTabIndices[b])}),this._previouslyActive.focus(),0===b.opened().length&&a(document.documentElement).removeClass("with-featherlight"),e},onResize:function(a,b){return this.resize(this.$content.naturalWidth,this.$content.naturalHeight),a(b)},afterContent:function(a,b){var c=a(b);return this.$instance.find("[autofocus]:not([disabled])").focus(),this.onResize(b),c}}}),a.featherlight=b,a.fn.featherlight=function(a,c){return b.attach(this,a,c),this},a(document).ready(function(){b._onReady()})}(jQuery);
1
+ /**
2
+ * Featherlight - ultra slim jQuery lightbox
3
+ * Version 1.7.13 - http://noelboss.github.io/featherlight/
4
+ *
5
+ * Copyright 2018, Noël Raoul Bossart (http://www.noelboss.com)
6
+ * MIT Licensed.
7
+ **/
8
+ !function(a){"use strict";function b(a,c){if(!(this instanceof b)){var d=new b(a,c);return d.open(),d}this.id=b.id++,this.setup(a,c),this.chainCallbacks(b._callbackChain)}function c(a,b){var c={};for(var d in a)d in b&&(c[d]=a[d],delete a[d]);return c}function d(a,b){var c={},d=new RegExp("^"+b+"([A-Z])(.*)");for(var e in a){var f=e.match(d);if(f){var g=(f[1]+f[2].replace(/([A-Z])/g,"-$1")).toLowerCase();c[g]=a[e]}}return c}if("undefined"==typeof a)return void("console"in window&&window.console.info("Too much lightness, Featherlight needs jQuery."));if(a.fn.jquery.match(/-ajax/))return void("console"in window&&window.console.info("Featherlight needs regular jQuery, not the slim version."));var e=[],f=function(b){return e=a.grep(e,function(a){return a!==b&&a.$instance.closest("body").length>0})},g={allow:1,allowfullscreen:1,frameborder:1,height:1,longdesc:1,marginheight:1,marginwidth:1,mozallowfullscreen:1,name:1,referrerpolicy:1,sandbox:1,scrolling:1,src:1,srcdoc:1,style:1,webkitallowfullscreen:1,width:1},h={keyup:"onKeyUp",resize:"onResize"},i=function(c){a.each(b.opened().reverse(),function(){return c.isDefaultPrevented()||!1!==this[h[c.type]](c)?void 0:(c.preventDefault(),c.stopPropagation(),!1)})},j=function(c){if(c!==b._globalHandlerInstalled){b._globalHandlerInstalled=c;var d=a.map(h,function(a,c){return c+"."+b.prototype.namespace}).join(" ");a(window)[c?"on":"off"](d,i)}};b.prototype={constructor:b,namespace:"featherlight",targetAttr:"data-featherlight",variant:null,resetCss:!1,background:null,openTrigger:"click",closeTrigger:"click",filter:null,root:"body",openSpeed:250,closeSpeed:250,closeOnClick:"background",closeOnEsc:!0,closeIcon:"&#10005;",loading:"",persist:!1,otherClose:null,beforeOpen:a.noop,beforeContent:a.noop,beforeClose:a.noop,afterOpen:a.noop,afterContent:a.noop,afterClose:a.noop,onKeyUp:a.noop,onResize:a.noop,type:null,contentFilters:["jquery","image","html","ajax","iframe","text"],setup:function(b,c){"object"!=typeof b||b instanceof a!=!1||c||(c=b,b=void 0);var d=a.extend(this,c,{target:b}),e=d.resetCss?d.namespace+"-reset":d.namespace,f=a(d.background||['<div class="'+e+"-loading "+e+'">','<div class="'+e+'-content">','<button class="'+e+"-close-icon "+d.namespace+'-close" aria-label="Close">',d.closeIcon,"</button>",'<div class="'+d.namespace+'-inner">'+d.loading+"</div>","</div>","</div>"].join("")),g="."+d.namespace+"-close"+(d.otherClose?","+d.otherClose:"");return d.$instance=f.clone().addClass(d.variant),d.$instance.on(d.closeTrigger+"."+d.namespace,function(b){if(!b.isDefaultPrevented()){var c=a(b.target);("background"===d.closeOnClick&&c.is("."+d.namespace)||"anywhere"===d.closeOnClick||c.closest(g).length)&&(d.close(b),b.preventDefault())}}),this},getContent:function(){if(this.persist!==!1&&this.$content)return this.$content;var b=this,c=this.constructor.contentFilters,d=function(a){return b.$currentTarget&&b.$currentTarget.attr(a)},e=d(b.targetAttr),f=b.target||e||"",g=c[b.type];if(!g&&f in c&&(g=c[f],f=b.target&&e),f=f||d("href")||"",!g)for(var h in c)b[h]&&(g=c[h],f=b[h]);if(!g){var i=f;if(f=null,a.each(b.contentFilters,function(){return g=c[this],g.test&&(f=g.test(i)),!f&&g.regex&&i.match&&i.match(g.regex)&&(f=i),!f}),!f)return"console"in window&&window.console.error("Featherlight: no content filter found "+(i?' for "'+i+'"':" (no target specified)")),!1}return g.process.call(b,f)},setContent:function(b){return this.$instance.removeClass(this.namespace+"-loading"),this.$instance.toggleClass(this.namespace+"-iframe",b.is("iframe")),this.$instance.find("."+this.namespace+"-inner").not(b).slice(1).remove().end().replaceWith(a.contains(this.$instance[0],b[0])?"":b),this.$content=b.addClass(this.namespace+"-inner"),this},open:function(b){var c=this;if(c.$instance.hide().appendTo(c.root),!(b&&b.isDefaultPrevented()||c.beforeOpen(b)===!1)){b&&b.preventDefault();var d=c.getContent();if(d)return e.push(c),j(!0),c.$instance.fadeIn(c.openSpeed),c.beforeContent(b),a.when(d).always(function(a){c.setContent(a),c.afterContent(b)}).then(c.$instance.promise()).done(function(){c.afterOpen(b)})}return c.$instance.detach(),a.Deferred().reject().promise()},close:function(b){var c=this,d=a.Deferred();return c.beforeClose(b)===!1?d.reject():(0===f(c).length&&j(!1),c.$instance.fadeOut(c.closeSpeed,function(){c.$instance.detach(),c.afterClose(b),d.resolve()})),d.promise()},resize:function(a,b){if(a&&b){this.$content.css("width","").css("height","");var c=Math.max(a/(this.$content.parent().width()-1),b/(this.$content.parent().height()-1));c>1&&(c=b/Math.floor(b/c),this.$content.css("width",""+a/c+"px").css("height",""+b/c+"px"))}},chainCallbacks:function(b){for(var c in b)this[c]=a.proxy(b[c],this,a.proxy(this[c],this))}},a.extend(b,{id:0,autoBind:"[data-featherlight]",defaults:b.prototype,contentFilters:{jquery:{regex:/^[#.]\w/,test:function(b){return b instanceof a&&b},process:function(b){return this.persist!==!1?a(b):a(b).clone(!0)}},image:{regex:/\.(png|jpg|jpeg|gif|tiff?|bmp|svg)(\?\S*)?$/i,process:function(b){var c=this,d=a.Deferred(),e=new Image,f=a('<img src="'+b+'" alt="" class="'+c.namespace+'-image" />');return e.onload=function(){f.naturalWidth=e.width,f.naturalHeight=e.height,d.resolve(f)},e.onerror=function(){d.reject(f)},e.src=b,d.promise()}},html:{regex:/^\s*<[\w!][^<]*>/,process:function(b){return a(b)}},ajax:{regex:/./,process:function(b){var c=a.Deferred(),d=a("<div></div>").load(b,function(a,b){"error"!==b&&c.resolve(d.contents()),c.fail()});return c.promise()}},iframe:{process:function(b){var e=new a.Deferred,f=a("<iframe/>"),h=d(this,"iframe"),i=c(h,g);return f.hide().attr("src",b).attr(i).css(h).on("load",function(){e.resolve(f.show())}).appendTo(this.$instance.find("."+this.namespace+"-content")),e.promise()}},text:{process:function(b){return a("<div>",{text:b})}}},functionAttributes:["beforeOpen","afterOpen","beforeContent","afterContent","beforeClose","afterClose"],readElementConfig:function(b,c){var d=this,e=new RegExp("^data-"+c+"-(.*)"),f={};return b&&b.attributes&&a.each(b.attributes,function(){var b=this.name.match(e);if(b){var c=this.value,g=a.camelCase(b[1]);if(a.inArray(g,d.functionAttributes)>=0)c=new Function(c);else try{c=JSON.parse(c)}catch(h){}f[g]=c}}),f},extend:function(b,c){var d=function(){this.constructor=b};return d.prototype=this.prototype,b.prototype=new d,b.__super__=this.prototype,a.extend(b,this,c),b.defaults=b.prototype,b},attach:function(b,c,d){var e=this;"object"!=typeof c||c instanceof a!=!1||d||(d=c,c=void 0),d=a.extend({},d);var f,g=d.namespace||e.defaults.namespace,h=a.extend({},e.defaults,e.readElementConfig(b[0],g),d),i=function(g){var i=a(g.currentTarget),j=a.extend({$source:b,$currentTarget:i},e.readElementConfig(b[0],h.namespace),e.readElementConfig(g.currentTarget,h.namespace),d),k=f||i.data("featherlight-persisted")||new e(c,j);"shared"===k.persist?f=k:k.persist!==!1&&i.data("featherlight-persisted",k),j.$currentTarget.blur&&j.$currentTarget.blur(),k.open(g)};return b.on(h.openTrigger+"."+h.namespace,h.filter,i),{filter:h.filter,handler:i}},current:function(){var a=this.opened();return a[a.length-1]||null},opened:function(){var b=this;return f(),a.grep(e,function(a){return a instanceof b})},close:function(a){var b=this.current();return b?b.close(a):void 0},_onReady:function(){var b=this;if(b.autoBind){var c=a(b.autoBind);c.each(function(){b.attach(a(this))}),a(document).on("click",b.autoBind,function(d){if(!d.isDefaultPrevented()){var e=a(d.currentTarget),f=c.length;if(c=c.add(e),f!==c.length){var g=b.attach(e);(!g.filter||a(d.target).parentsUntil(e,g.filter).length>0)&&g.handler(d)}}})}},_callbackChain:{onKeyUp:function(b,c){return 27===c.keyCode?(this.closeOnEsc&&a.featherlight.close(c),!1):b(c)},beforeOpen:function(b,c){return a(document.documentElement).addClass("with-featherlight"),this._previouslyActive=document.activeElement,this._$previouslyTabbable=a("a, input, select, textarea, iframe, button, iframe, [contentEditable=true]").not("[tabindex]").not(this.$instance.find("button")),this._$previouslyWithTabIndex=a("[tabindex]").not('[tabindex="-1"]'),this._previousWithTabIndices=this._$previouslyWithTabIndex.map(function(b,c){return a(c).attr("tabindex")}),this._$previouslyWithTabIndex.add(this._$previouslyTabbable).attr("tabindex",-1),document.activeElement.blur&&document.activeElement.blur(),b(c)},afterClose:function(c,d){var e=c(d),f=this;return this._$previouslyTabbable.removeAttr("tabindex"),this._$previouslyWithTabIndex.each(function(b,c){a(c).attr("tabindex",f._previousWithTabIndices[b])}),this._previouslyActive.focus(),0===b.opened().length&&a(document.documentElement).removeClass("with-featherlight"),e},onResize:function(a,b){return this.resize(this.$content.naturalWidth,this.$content.naturalHeight),a(b)},afterContent:function(a,b){var c=a(b);return this.$instance.find("[autofocus]:not([disabled])").focus(),this.onResize(b),c}}}),a.featherlight=b,a.fn.featherlight=function(a,c){return b.attach(this,a,c),this},a(document).ready(function(){b._onReady()})}(jQuery);
assets/imagelightbox/css/imagelightbox.css CHANGED
@@ -1,6 +1,8 @@
1
- #imagelightbox {
2
- position: fixed;
3
- z-index: 9999;
4
- -ms-touch-action: none;
5
- touch-action: none;
 
 
6
  }
1
+ #imagelightbox
2
+ {
3
+ position: fixed;
4
+ z-index: 9999;
5
+
6
+ -ms-touch-action: none;
7
+ touch-action: none;
8
  }
assets/imagelightbox/css/imagelightbox.min.css DELETED
@@ -1 +0,0 @@
1
- #imagelightbox{position:fixed;z-index:9999;-ms-touch-action:none;touch-action:none}
 
assets/imagelightbox/js/imagelightbox.js DELETED
@@ -1,315 +0,0 @@
1
-
2
- /*
3
- By Osvaldas Valutis, www.osvaldas.info
4
- Available for use under the MIT License
5
- */
6
-
7
- ;( function( $, window, document, undefined )
8
- {
9
- 'use strict';
10
-
11
- var cssTransitionSupport = function()
12
- {
13
- var s = document.body || document.documentElement, s = s.style;
14
- if( s.WebkitTransition == '' ) return '-webkit-';
15
- if( s.MozTransition == '' ) return '-moz-';
16
- if( s.OTransition == '' ) return '-o-';
17
- if( s.transition == '' ) return '';
18
- return false;
19
- },
20
-
21
- isCssTransitionSupport = cssTransitionSupport() === false ? false : true,
22
-
23
- cssTransitionTranslateX = function( element, positionX, speed )
24
- {
25
- var options = {}, prefix = cssTransitionSupport();
26
- options[ prefix + 'transform' ] = 'translateX(' + positionX + ')';
27
- options[ prefix + 'transition' ] = prefix + 'transform ' + speed + 's linear';
28
- element.css( options );
29
- },
30
-
31
- hasTouch = ( 'ontouchstart' in window ),
32
- hasPointers = window.navigator.pointerEnabled || window.navigator.msPointerEnabled,
33
- wasTouched = function( event )
34
- {
35
- if( hasTouch )
36
- return true;
37
-
38
- if( !hasPointers || typeof event === 'undefined' || typeof event.pointerType === 'undefined' )
39
- return false;
40
-
41
- if( typeof event.MSPOINTER_TYPE_MOUSE !== 'undefined' )
42
- {
43
- if( event.MSPOINTER_TYPE_MOUSE != event.pointerType )
44
- return true;
45
- }
46
- else
47
- if( event.pointerType != 'mouse' )
48
- return true;
49
-
50
- return false;
51
- };
52
-
53
- $.fn.imageLightbox = function( options )
54
- {
55
- var options = $.extend(
56
- {
57
- selector: 'id="imagelightbox"',
58
- animationSpeed: 250,
59
- preloadNext: true,
60
- enableKeyboard: true,
61
- quitOnEnd: false,
62
- quitOnImgClick: false,
63
- quitOnDocClick: true,
64
- onStart: false,
65
- onEnd: false,
66
- onLoadStart: false,
67
- onLoadEnd: false
68
- },
69
- options ),
70
-
71
- targets = $([]),
72
- target = $(),
73
- image = $(),
74
- imageWidth = 0,
75
- imageHeight = 0,
76
- swipeDiff = 0,
77
- inProgress = false,
78
-
79
- setImage = function()
80
- {
81
- if( !image.length ) return true;
82
-
83
- var screenWidth = $( window ).width() * 0.8,
84
- screenHeight = $( window ).height() * 0.9,
85
- tmpImage = new Image();
86
-
87
- tmpImage.src = image.attr( 'src' );
88
- tmpImage.onload = function()
89
- {
90
- imageWidth = tmpImage.width;
91
- imageHeight = tmpImage.height;
92
-
93
- if( imageWidth > screenWidth || imageHeight > screenHeight )
94
- {
95
- var ratio = imageWidth / imageHeight > screenWidth / screenHeight ? imageWidth / screenWidth : imageHeight / screenHeight;
96
- imageWidth /= ratio;
97
- imageHeight /= ratio;
98
- }
99
-
100
- image.css(
101
- {
102
- 'width': imageWidth + 'px',
103
- 'height': imageHeight + 'px',
104
- 'top': ( $( window ).height() - imageHeight ) / 2 + 'px',
105
- 'left': ( $( window ).width() - imageWidth ) / 2 + 'px'
106
- });
107
- };
108
- },
109
-
110
- loadImage = function( direction )
111
- {
112
- if( inProgress ) return false;
113
-
114
- direction = typeof direction === 'undefined' ? false : direction == 'left' ? 1 : -1;
115
-
116
- if( image.length )
117
- {
118
- if( direction !== false && ( targets.length < 2 || ( options.quitOnEnd === true && ( ( direction === -1 && targets.index( target ) == 0 ) || ( direction === 1 && targets.index( target ) == targets.length - 1 ) ) ) ) )
119
- {
120
- quitLightbox();
121
- return false;
122
- }
123
- var params = { 'opacity': 0 };
124
- if( isCssTransitionSupport ) cssTransitionTranslateX( image, ( 100 * direction ) - swipeDiff + 'px', options.animationSpeed / 1000 );
125
- else params.left = parseInt( image.css( 'left' ) ) + 100 * direction + 'px';
126
- image.animate( params, options.animationSpeed, function(){ removeImage(); });
127
- swipeDiff = 0;
128
- }
129
-
130
- inProgress = true;
131
- if( options.onLoadStart !== false ) options.onLoadStart();
132
-
133
- setTimeout( function()
134
- {
135
- image = $( '<img ' + options.selector + ' />' )
136
- .attr( 'src', target.attr( 'href' ) )
137
- .on( 'load', function()
138
- {
139
- image.appendTo( 'body' );
140
- setImage();
141
-
142
- var params = { 'opacity': 1 };
143
-
144
- image.css( 'opacity', 0 );
145
- if( isCssTransitionSupport )
146
- {
147
- cssTransitionTranslateX( image, -100 * direction + 'px', 0 );
148
- setTimeout( function(){ cssTransitionTranslateX( image, 0 + 'px', options.animationSpeed / 1000 ) }, 50 );
149
- }
150
- else
151
- {
152
- var imagePosLeft = parseInt( image.css( 'left' ) );
153
- params.left = imagePosLeft + 'px';
154
- image.css( 'left', imagePosLeft - 100 * direction + 'px' );
155
- }
156
-
157
- image.animate( params, options.animationSpeed, function()
158
- {
159
- inProgress = false;
160
- if( options.onLoadEnd !== false ) options.onLoadEnd();
161
- });
162
- if( options.preloadNext )
163
- {
164
- var nextTarget = targets.eq( targets.index( target ) + 1 );
165
- if( !nextTarget.length ) nextTarget = targets.eq( 0 );
166
- $( '<img />' ).attr( 'src', nextTarget.attr( 'href' ) );
167
- }
168
- })
169
- .on( 'error', function()
170
- {
171
- if( options.onLoadEnd !== false ) options.onLoadEnd();
172
- });
173
-
174
- var swipeStart = 0,
175
- swipeEnd = 0,
176
- imagePosLeft = 0;
177
-
178
- image.on( hasPointers ? 'pointerup MSPointerUp' : 'click', function( e )
179
- {
180
- e.preventDefault();
181
- if( options.quitOnImgClick )
182
- {
183
- quitLightbox();
184
- return false;
185
- }
186
- if( wasTouched( e.originalEvent ) ) return true;
187
- var posX = ( e.pageX || e.originalEvent.pageX ) - e.target.offsetLeft;
188
- target = targets.eq( targets.index( target ) - ( imageWidth / 2 > posX ? 1 : -1 ) );
189
- if( !target.length ) target = targets.eq( imageWidth / 2 > posX ? targets.length : 0 );
190
- loadImage( imageWidth / 2 > posX ? 'left' : 'right' );
191
- })
192
- .on( 'touchstart pointerdown MSPointerDown', function( e )
193
- {
194
- if( !wasTouched( e.originalEvent ) || options.quitOnImgClick ) return true;
195
- if( isCssTransitionSupport ) imagePosLeft = parseInt( image.css( 'left' ) );
196
- swipeStart = e.originalEvent.pageX || e.originalEvent.touches[ 0 ].pageX;
197
- })
198
- .on( 'touchmove pointermove MSPointerMove', function( e )
199
- {
200
- if( !wasTouched( e.originalEvent ) || options.quitOnImgClick ) return true;
201
- e.preventDefault();
202
- swipeEnd = e.originalEvent.pageX || e.originalEvent.touches[ 0 ].pageX;
203
- swipeDiff = swipeStart - swipeEnd;
204
- if( isCssTransitionSupport ) cssTransitionTranslateX( image, -swipeDiff + 'px', 0 );
205
- else image.css( 'left', imagePosLeft - swipeDiff + 'px' );
206
- })
207
- .on( 'touchend touchcancel pointerup pointercancel MSPointerUp MSPointerCancel', function( e )
208
- {
209
- if( !wasTouched( e.originalEvent ) || options.quitOnImgClick ) return true;
210
- if( Math.abs( swipeDiff ) > 50 )
211
- {
212
- target = targets.eq( targets.index( target ) - ( swipeDiff < 0 ? 1 : -1 ) );
213
- if( !target.length ) target = targets.eq( swipeDiff < 0 ? targets.length : 0 );
214
- loadImage( swipeDiff > 0 ? 'right' : 'left' );
215
- }
216
- else
217
- {
218
- if( isCssTransitionSupport ) cssTransitionTranslateX( image, 0 + 'px', options.animationSpeed / 1000 );
219
- else image.animate({ 'left': imagePosLeft + 'px' }, options.animationSpeed / 2 );
220
- }
221
- });
222
-
223
- }, options.animationSpeed + 100 );
224
- },
225
-
226
- removeImage = function()
227
- {
228
- if( !image.length ) return false;
229
- image.remove();
230
- image = $();
231
- },
232
-
233
- quitLightbox = function()
234
- {
235
- if( !image.length ) return false;
236
- image.animate({ 'opacity': 0 }, options.animationSpeed, function()
237
- {
238
- removeImage();
239
- inProgress = false;
240
- if( options.onEnd !== false ) options.onEnd();
241
- });
242
- },
243
-
244
- addTargets = function( newTargets )
245
- {
246
- newTargets.each( function()
247
- {
248
- targets = targets.add( $( this ) );
249
- });
250
-
251
- newTargets.on( 'click.imageLightbox', function( e )
252
- {
253
- e.preventDefault();
254
- if( inProgress ) return false;
255
- inProgress = false;
256
- if( options.onStart !== false ) options.onStart();
257
- target = $( this );
258
- loadImage();
259
- });
260
- };
261
-
262
- $( window ).on( 'resize', setImage );
263
-
264
- if( options.quitOnDocClick )
265
- {
266
- $( document ).on( hasTouch ? 'touchend' : 'click', function( e )
267
- {
268
- if( image.length && !$( e.target ).is( image ) ) quitLightbox();
269
- });
270
- }
271
-
272
- if( options.enableKeyboard )
273
- {
274
- $( document ).on( 'keyup', function( e )
275
- {
276
- if( !image.length ) return true;
277
- e.preventDefault();
278
- if( e.keyCode == 27 ) quitLightbox();
279
- if( e.keyCode == 37 || e.keyCode == 39 )
280
- {
281
- target = targets.eq( targets.index( target ) - ( e.keyCode == 37 ? 1 : -1 ) );
282
- if( !target.length ) target = targets.eq( e.keyCode == 37 ? targets.length : 0 );
283
- loadImage( e.keyCode == 37 ? 'left' : 'right' );
284
- }
285
- });
286
- }
287
-
288
- addTargets( $( this ) );
289
-
290
- this.switchImageLightbox = function( index )
291
- {
292
- var tmpTarget = targets.eq( index );
293
- if( tmpTarget.length )
294
- {
295
- var currentIndex = targets.index( target );
296
- target = tmpTarget;
297
- loadImage( index < currentIndex ? 'left' : 'right' );
298
- }
299
- return this;
300
- };
301
-
302
- this.addToImageLightbox = function( newTargets )
303
- {
304
- addTargets( newTargets );
305
- };
306
-
307
- this.quitImageLightbox = function()
308
- {
309
- quitLightbox();
310
- return this;
311
- };
312
-
313
- return this;
314
- };
315
- })( jQuery, window, document );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
assets/imagelightbox/js/imagelightbox.min.js CHANGED
@@ -3,4 +3,4 @@
3
  Available for use under the MIT License
4
  */
5
 
6
- !function(n,t,e,i){"use strict";var o=function(){var n=e.body||e.documentElement,n=n.style;return""==n.WebkitTransition?"-webkit-":""==n.MozTransition?"-moz-":""==n.OTransition?"-o-":""==n.transition?"":!1},r=o()===!1?!1:!0,a=function(n,t,e){var i={},r=o();i[r+"transform"]="translateX("+t+")",i[r+"transition"]=r+"transform "+e+"s linear",n.css(i)},u="ontouchstart"in t,d=t.navigator.pointerEnabled||t.navigator.msPointerEnabled,c=function(n){if(u)return!0;if(!d||"undefined"==typeof n||"undefined"==typeof n.pointerType)return!1;if("undefined"!=typeof n.MSPOINTER_TYPE_MOUSE){if(n.MSPOINTER_TYPE_MOUSE!=n.pointerType)return!0}else if("mouse"!=n.pointerType)return!0;return!1};n.fn.imageLightbox=function(i){var i=n.extend({selector:'id="imagelightbox"',animationSpeed:250,preloadNext:!0,enableKeyboard:!0,quitOnEnd:!1,quitOnImgClick:!1,quitOnDocClick:!0,onStart:!1,onEnd:!1,onLoadStart:!1,onLoadEnd:!1},i),o=n([]),f=n(),l=n(),p=0,g=0,s=0,h=!1,m=function(){if(!l.length)return!0;var e=.8*n(t).width(),i=.9*n(t).height(),o=new Image;o.src=l.attr("src"),o.onload=function(){if(p=o.width,g=o.height,p>e||g>i){var r=p/g>e/i?p/e:g/i;p/=r,g/=r}l.css({width:p+"px",height:g+"px",top:(n(t).height()-g)/2+"px",left:(n(t).width()-p)/2+"px"})}},v=function(t){if(h)return!1;if(t="undefined"==typeof t?!1:"left"==t?1:-1,l.length){if(t!==!1&&(o.length<2||i.quitOnEnd===!0&&(-1===t&&0==o.index(f)||1===t&&o.index(f)==o.length-1)))return E(),!1;var e={opacity:0};r?a(l,100*t-s+"px",i.animationSpeed/1e3):e.left=parseInt(l.css("left"))+100*t+"px",l.animate(e,i.animationSpeed,function(){x()}),s=0}h=!0,i.onLoadStart!==!1&&i.onLoadStart(),setTimeout(function(){l=n("<img "+i.selector+" />").attr("src",f.attr("href")).on("load",function(){l.appendTo("body"),m();var e={opacity:1};if(l.css("opacity",0),r)a(l,-100*t+"px",0),setTimeout(function(){a(l,"0px",i.animationSpeed/1e3)},50);else{var u=parseInt(l.css("left"));e.left=u+"px",l.css("left",u-100*t+"px")}if(l.animate(e,i.animationSpeed,function(){h=!1,i.onLoadEnd!==!1&&i.onLoadEnd()}),i.preloadNext){var d=o.eq(o.index(f)+1);d.length||(d=o.eq(0)),n("<img />").attr("src",d.attr("href"))}}).on("error",function(){i.onLoadEnd!==!1&&i.onLoadEnd()});var e=0,u=0,g=0;l.on(d?"pointerup MSPointerUp":"click",function(n){if(n.preventDefault(),i.quitOnImgClick)return E(),!1;if(c(n.originalEvent))return!0;var t=(n.pageX||n.originalEvent.pageX)-n.target.offsetLeft;f=o.eq(o.index(f)-(p/2>t?1:-1)),f.length||(f=o.eq(p/2>t?o.length:0)),v(p/2>t?"left":"right")}).on("touchstart pointerdown MSPointerDown",function(n){return!c(n.originalEvent)||i.quitOnImgClick?!0:(r&&(g=parseInt(l.css("left"))),void(e=n.originalEvent.pageX||n.originalEvent.touches[0].pageX))}).on("touchmove pointermove MSPointerMove",function(n){return!c(n.originalEvent)||i.quitOnImgClick?!0:(n.preventDefault(),u=n.originalEvent.pageX||n.originalEvent.touches[0].pageX,s=e-u,void(r?a(l,-s+"px",0):l.css("left",g-s+"px")))}).on("touchend touchcancel pointerup pointercancel MSPointerUp MSPointerCancel",function(n){return!c(n.originalEvent)||i.quitOnImgClick?!0:void(Math.abs(s)>50?(f=o.eq(o.index(f)-(0>s?1:-1)),f.length||(f=o.eq(0>s?o.length:0)),v(s>0?"right":"left")):r?a(l,"0px",i.animationSpeed/1e3):l.animate({left:g+"px"},i.animationSpeed/2))})},i.animationSpeed+100)},x=function(){return l.length?(l.remove(),void(l=n())):!1},E=function(){return l.length?void l.animate({opacity:0},i.animationSpeed,function(){x(),h=!1,i.onEnd!==!1&&i.onEnd()}):!1},y=function(t){t.each(function(){o=o.add(n(this))}),t.on("click.imageLightbox",function(t){return t.preventDefault(),h?!1:(h=!1,i.onStart!==!1&&i.onStart(),f=n(this),void v())})};return n(t).on("resize",m),i.quitOnDocClick&&n(e).on(u?"touchend":"click",function(t){l.length&&!n(t.target).is(l)&&E()}),i.enableKeyboard&&n(e).on("keyup",function(n){return l.length?(n.preventDefault(),27==n.keyCode&&E(),void((37==n.keyCode||39==n.keyCode)&&(f=o.eq(o.index(f)-(37==n.keyCode?1:-1)),f.length||(f=o.eq(37==n.keyCode?o.length:0)),v(37==n.keyCode?"left":"right")))):!0}),y(n(this)),this.switchImageLightbox=function(n){var t=o.eq(n);if(t.length){var e=o.index(f);f=t,v(e>n?"left":"right")}return this},this.addToImageLightbox=function(n){y(n)},this.quitImageLightbox=function(){return E(),this},this}}(jQuery,window,document);
3
  Available for use under the MIT License
4
  */
5
 
6
+ ;(function(e,t,n,r){"use strict";var i=function(){var e=n.body||n.documentElement,e=e.style;if(e.WebkitTransition=="")return"-webkit-";if(e.MozTransition=="")return"-moz-";if(e.OTransition=="")return"-o-";if(e.transition=="")return"";return false},s=i()===false?false:true,o=function(e,t,n){var r={},s=i();r[s+"transform"]="translateX("+t+")";r[s+"transition"]=s+"transform "+n+"s linear";e.css(r)},u="ontouchstart"in t,a=t.navigator.pointerEnabled||t.navigator.msPointerEnabled,f=function(e){if(u)return true;if(!a||typeof e==="undefined"||typeof e.pointerType==="undefined")return false;if(typeof e.MSPOINTER_TYPE_MOUSE!=="undefined"){if(e.MSPOINTER_TYPE_MOUSE!=e.pointerType)return true}else if(e.pointerType!="mouse")return true;return false};e.fn.imageLightbox=function(r){var r=e.extend({selector:'id="imagelightbox"',allowedTypes:"png|jpg|jpeg|gif",animationSpeed:250,preloadNext:true,enableKeyboard:true,quitOnEnd:false,quitOnImgClick:false,quitOnDocClick:true,onStart:false,onEnd:false,onLoadStart:false,onLoadEnd:false},r),i=e([]),l=e(),c=e(),h=0,p=0,d=0,v=false,m=function(t){return e(t).prop("tagName").toLowerCase()=="a"&&(new RegExp(".("+r.allowedTypes+")$","i")).test(e(t).attr("href"))},g=function(){if(!c.length)return true;var n=e(t).width()*.8,r=e(t).height()*.9,i=new Image;i.src=c.attr("src");i.onload=function(){h=i.width;p=i.height;if(h>n||p>r){var s=h/p>n/r?h/n:p/r;h/=s;p/=s}c.css({width:h+"px",height:p+"px",top:(e(t).height()-p)/2+"px",left:(e(t).width()-h)/2+"px"})}},y=function(t){if(v)return false;t=typeof t==="undefined"?false:t=="left"?1:-1;if(c.length){if(t!==false&&(i.length<2||r.quitOnEnd===true&&(t===-1&&i.index(l)==0||t===1&&i.index(l)==i.length-1))){w();return false}var n={opacity:0};if(s)o(c,100*t-d+"px",r.animationSpeed/1e3);else n.left=parseInt(c.css("left"))+100*t+"px";c.animate(n,r.animationSpeed,function(){b()});d=0}v=true;if(r.onLoadStart!==false)r.onLoadStart();setTimeout(function(){c=e("<img "+r.selector+" />").attr("src",l.attr("href")).load(function(){c.appendTo("body");g();var n={opacity:1};c.css("opacity",0);if(s){o(c,-100*t+"px",0);setTimeout(function(){o(c,0+"px",r.animationSpeed/1e3)},50)}else{var u=parseInt(c.css("left"));n.left=u+"px";c.css("left",u-100*t+"px")}c.animate(n,r.animationSpeed,function(){v=false;if(r.onLoadEnd!==false)r.onLoadEnd()});if(r.preloadNext){var a=i.eq(i.index(l)+1);if(!a.length)a=i.eq(0);e("<img />").attr("src",a.attr("href")).load()}}).error(function(){if(r.onLoadEnd!==false)r.onLoadEnd()});var n=0,u=0,p=0;c.on(a?"pointerup MSPointerUp":"click",function(e){e.preventDefault();if(r.quitOnImgClick){w();return false}if(f(e.originalEvent))return true;var t=(e.pageX||e.originalEvent.pageX)-e.target.offsetLeft;l=i.eq(i.index(l)-(h/2>t?1:-1));if(!l.length)l=i.eq(h/2>t?i.length:0);y(h/2>t?"left":"right")}).on("touchstart pointerdown MSPointerDown",function(e){if(!f(e.originalEvent)||r.quitOnImgClick)return true;if(s)p=parseInt(c.css("left"));n=e.originalEvent.pageX||e.originalEvent.touches[0].pageX}).on("touchmove pointermove MSPointerMove",function(e){if(!f(e.originalEvent)||r.quitOnImgClick)return true;e.preventDefault();u=e.originalEvent.pageX||e.originalEvent.touches[0].pageX;d=n-u;if(s)o(c,-d+"px",0);else c.css("left",p-d+"px")}).on("touchend touchcancel pointerup pointercancel MSPointerUp MSPointerCancel",function(e){if(!f(e.originalEvent)||r.quitOnImgClick)return true;if(Math.abs(d)>50){l=i.eq(i.index(l)-(d<0?1:-1));if(!l.length)l=i.eq(d<0?i.length:0);y(d>0?"right":"left")}else{if(s)o(c,0+"px",r.animationSpeed/1e3);else c.animate({left:p+"px"},r.animationSpeed/2)}})},r.animationSpeed+100)},b=function(){if(!c.length)return false;c.remove();c=e()},w=function(){if(!c.length)return false;c.animate({opacity:0},r.animationSpeed,function(){b();v=false;if(r.onEnd!==false)r.onEnd()})};e(t).on("resize",g);if(r.quitOnDocClick){e(n).on(u?"touchend":"click",function(t){if(c.length&&!e(t.target).is(c))w()})}if(r.enableKeyboard){e(n).on("keyup",function(e){if(!c.length)return true;e.preventDefault();if(e.keyCode==27)w();if(e.keyCode==37||e.keyCode==39){l=i.eq(i.index(l)-(e.keyCode==37?1:-1));if(!l.length)l=i.eq(e.keyCode==37?i.length:0);y(e.keyCode==37?"left":"right")}})}e(n).on("click",this.selector,function(t){if(!m(this))return true;t.preventDefault();if(v)return false;v=false;if(r.onStart!==false)r.onStart();l=e(this);y()});this.each(function(){if(!m(this))return true;i=i.add(e(this))});this.switchImageLightbox=function(e){var t=i.eq(e);if(t.length){var n=i.index(l);l=t;y(e<n?"left":"right")}return this};this.quitImageLightbox=function(){w();return this};return this}})(jQuery,window,document);
assets/infinitescroll/infinite-scroll.pkgd.js CHANGED
@@ -1,2197 +1,2204 @@
1
- /*!
2
- * Infinite Scroll PACKAGED v3.0.4
3
- * Automatically add next page
4
- *
5
- * Licensed GPLv3 for open source use
6
- * or Infinite Scroll Commercial License for commercial use
7
- *
8
- * https://infinite-scroll.com
9
- * Copyright 2018 Metafizzy
10
- */
11
-
12
- /**
13
- * Bridget makes jQuery widgets
14
- * v2.0.1
15
- * MIT license
16
- */
17
-
18
- /* jshint browser: true, strict: true, undef: true, unused: true */
19
-
20
- ( function( window, factory ) {
21
- // universal module definition
22
- /*jshint strict: false */ /* globals define, module, require */
23
- if ( typeof define == 'function' && define.amd ) {
24
- // AMD
25
- define( 'jquery-bridget/jquery-bridget',[ 'jquery' ], function( jQuery ) {
26
- return factory( window, jQuery );
27
- });
28
- } else if ( typeof module == 'object' && module.exports ) {
29
- // CommonJS
30
- module.exports = factory(
31
- window,
32
- require('jquery')
33
- );
34
- } else {
35
- // browser global
36
- window.jQueryBridget = factory(
37
- window,
38
- window.jQuery
39
- );
40
- }
41
-
42
- }( window, function factory( window, jQuery ) {
43
- 'use strict';
44
-
45
- // ----- utils ----- //
46
-
47
- var arraySlice = Array.prototype.slice;
48
-
49
- // helper function for logging errors
50
- // $.error breaks jQuery chaining
51
- var console = window.console;
52
- var logError = typeof console == 'undefined' ? function() {} :
53
- function( message ) {
54
- console.error( message );
55
- };
56
-
57
- // ----- jQueryBridget ----- //
58
-
59
- function jQueryBridget( namespace, PluginClass, $ ) {
60
- $ = $ || jQuery || window.jQuery;
61
- if ( !$ ) {
62
- return;
63
- }
64
-
65
- // add option method -> $().plugin('option', {...})
66
- if ( !PluginClass.prototype.option ) {
67
- // option setter
68
- PluginClass.prototype.option = function( opts ) {
69
- // bail out if not an object
70
- if ( !$.isPlainObject( opts ) ){
71
- return;
72
- }
73
- this.options = $.extend( true, this.options, opts );
74
- };
75
- }
76
-
77
- // make jQuery plugin
78
- $.fn[ namespace ] = function( arg0 /*, arg1 */ ) {
79
- if ( typeof arg0 == 'string' ) {
80
- // method call $().plugin( 'methodName', { options } )
81
- // shift arguments by 1
82
- var args = arraySlice.call( arguments, 1 );
83
- return methodCall( this, arg0, args );
84
- }
85
- // just $().plugin({ options })
86
- plainCall( this, arg0 );
87
- return this;
88
- };
89
-
90
- // $().plugin('methodName')
91
- function methodCall( $elems, methodName, args ) {
92
- var returnValue;
93
- var pluginMethodStr = '$().' + namespace + '("' + methodName + '")';
94
-
95
- $elems.each( function( i, elem ) {
96
- // get instance
97
- var instance = $.data( elem, namespace );
98
- if ( !instance ) {
99
- logError( namespace + ' not initialized. Cannot call methods, i.e. ' +
100
- pluginMethodStr );
101
- return;
102
- }
103
-
104
- var method = instance[ methodName ];
105
- if ( !method || methodName.charAt(0) == '_' ) {
106
- logError( pluginMethodStr + ' is not a valid method' );
107
- return;
108
- }
109
-
110
- // apply method, get return value
111
- var value = method.apply( instance, args );
112
- // set return value if value is returned, use only first value
113
- returnValue = returnValue === undefined ? value : returnValue;
114
- });
115
-
116
- return returnValue !== undefined ? returnValue : $elems;
117
- }
118
-
119
- function plainCall( $elems, options ) {
120
- $elems.each( function( i, elem ) {
121
- var instance = $.data( elem, namespace );
122
- if ( instance ) {
123
- // set options & init
124
- instance.option( options );
125
- instance._init();
126
- } else {
127
- // initialize new instance
128
- instance = new PluginClass( elem, options );
129
- $.data( elem, namespace, instance );
130
- }
131
- });
132
- }
133
-
134
- updateJQuery( $ );
135
-
136
- }
137
-
138
- // ----- updateJQuery ----- //
139
-
140
- // set $.bridget for v1 backwards compatibility
141
- function updateJQuery( $ ) {
142
- if ( !$ || ( $ && $.bridget ) ) {
143
- return;
144
- }
145
- $.bridget = jQueryBridget;
146
- }
147
-
148
- updateJQuery( jQuery || window.jQuery );
149
-
150
- // ----- ----- //
151
-
152
- return jQueryBridget;
153
-
154
- }));
155
-
156
- /**
157
- * EvEmitter v1.1.0
158
- * Lil' event emitter
159
- * MIT License
160
- */
161
-
162
- /* jshint unused: true, undef: true, strict: true */
163
-
164
- ( function( global, factory ) {
165
- // universal module definition
166
- /* jshint strict: false */ /* globals define, module, window */
167
- if ( typeof define == 'function' && define.amd ) {
168
- // AMD - RequireJS
169
- define( 'ev-emitter/ev-emitter',factory );
170
- } else if ( typeof module == 'object' && module.exports ) {
171
- // CommonJS - Browserify, Webpack
172
- module.exports = factory();
173
- } else {
174
- // Browser globals
175
- global.EvEmitter = factory();
176
- }
177
-
178
- }( typeof window != 'undefined' ? window : this, function() {
179
-
180
-
181
-
182
- function EvEmitter() {}
183
-
184
- var proto = EvEmitter.prototype;
185
-
186
- proto.on = function( eventName, listener ) {
187
- if ( !eventName || !listener ) {
188
- return;
189
- }
190
- // set events hash
191
- var events = this._events = this._events || {};
192
- // set listeners array
193
- var listeners = events[ eventName ] = events[ eventName ] || [];
194
- // only add once
195
- if ( listeners.indexOf( listener ) == -1 ) {
196
- listeners.push( listener );
197
- }
198
-
199
- return this;
200
- };
201
-
202
- proto.once = function( eventName, listener ) {
203
- if ( !eventName || !listener ) {
204
- return;
205
- }
206
- // add event
207
- this.on( eventName, listener );
208
- // set once flag
209
- // set onceEvents hash
210
- var onceEvents = this._onceEvents = this._onceEvents || {};
211
- // set onceListeners object
212
- var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
213
- // set flag
214
- onceListeners[ listener ] = true;
215
-
216
- return this;
217
- };
218
-
219
- proto.off = function( eventName, listener ) {
220
- var listeners = this._events && this._events[ eventName ];
221
- if ( !listeners || !listeners.length ) {
222
- return;
223
- }
224
- var index = listeners.indexOf( listener );
225
- if ( index != -1 ) {
226
- listeners.splice( index, 1 );
227
- }
228
-
229
- return this;
230
- };
231
-
232
- proto.emitEvent = function( eventName, args ) {
233
- var listeners = this._events && this._events[ eventName ];
234
- if ( !listeners || !listeners.length ) {
235
- return;
236
- }
237
- // copy over to avoid interference if .off() in listener
238
- listeners = listeners.slice(0);
239
- args = args || [];
240
- // once stuff
241
- var onceListeners = this._onceEvents && this._onceEvents[ eventName ];
242
-
243
- for ( var i=0; i < listeners.length; i++ ) {
244
- var listener = listeners[i]
245
- var isOnce = onceListeners && onceListeners[ listener ];
246
- if ( isOnce ) {
247
- // remove listener
248
- // remove before trigger to prevent recursion
249
- this.off( eventName, listener );
250
- // unset once flag
251
- delete onceListeners[ listener ];
252
- }
253
- // trigger listener
254
- listener.apply( this, args );
255
- }
256
-
257
- return this;
258
- };
259
-
260
- proto.allOff = function() {
261
- delete this._events;
262
- delete this._onceEvents;
263
- };
264
-
265
- return EvEmitter;
266
-
267
- }));
268
-
269
- /**
270
- * matchesSelector v2.0.2
271
- * matchesSelector( element, '.selector' )
272
- * MIT license
273
- */
274
-
275
- /*jshint browser: true, strict: true, undef: true, unused: true */
276
-
277
- ( function( window, factory ) {
278
- /*global define: false, module: false */
279
- 'use strict';
280
- // universal module definition
281
- if ( typeof define == 'function' && define.amd ) {
282
- // AMD
283
- define( 'desandro-matches-selector/matches-selector',factory );
284
- } else if ( typeof module == 'object' && module.exports ) {
285
- // CommonJS
286
- module.exports = factory();
287
- } else {
288
- // browser global
289
- window.matchesSelector = factory();
290
- }
291
-
292
- }( window, function factory() {
293
- 'use strict';
294
-
295
- var matchesMethod = ( function() {
296
- var ElemProto = window.Element.prototype;
297
- // check for the standard method name first
298
- if ( ElemProto.matches ) {
299
- return 'matches';
300
- }
301
- // check un-prefixed
302
- if ( ElemProto.matchesSelector ) {
303
- return 'matchesSelector';
304
- }
305
- // check vendor prefixes
306
- var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
307
-
308
- for ( var i=0; i < prefixes.length; i++ ) {
309
- var prefix = prefixes[i];
310
- var method = prefix + 'MatchesSelector';
311
- if ( ElemProto[ method ] ) {
312
- return method;
313
- }
314
- }
315
- })();
316
-
317
- return function matchesSelector( elem, selector ) {
318
- return elem[ matchesMethod ]( selector );
319
- };
320
-
321
- }));
322
-
323
- /**
324
- * Fizzy UI utils v2.0.7
325
- * MIT license
326
- */
327
-
328
- /*jshint browser: true, undef: true, unused: true, strict: true */
329
-
330
- ( function( window, factory ) {
331
- // universal module definition
332
- /*jshint strict: false */ /*globals define, module, require */
333
-
334
- if ( typeof define == 'function' && define.amd ) {
335
- // AMD
336
- define( 'fizzy-ui-utils/utils',[
337
- 'desandro-matches-selector/matches-selector'
338
- ], function( matchesSelector ) {
339
- return factory( window, matchesSelector );
340
- });
341
- } else if ( typeof module == 'object' && module.exports ) {
342
- // CommonJS
343
- module.exports = factory(
344
- window,
345
- require('desandro-matches-selector')
346
- );
347
- } else {
348
- // browser global
349
- window.fizzyUIUtils = factory(
350
- window,
351
- window.matchesSelector
352
- );
353
- }
354
-
355
- }( window, function factory( window, matchesSelector ) {
356
-
357
-
358
-
359
- var utils = {};
360
-
361
- // ----- extend ----- //
362
-
363
- // extends objects
364
- utils.extend = function( a, b ) {
365
- for ( var prop in b ) {
366
- a[ prop ] = b[ prop ];
367
- }
368
- return a;
369
- };
370
-
371
- // ----- modulo ----- //
372
-
373
- utils.modulo = function( num, div ) {
374
- return ( ( num % div ) + div ) % div;
375
- };
376
-
377
- // ----- makeArray ----- //
378
-
379
- var arraySlice = Array.prototype.slice;
380
-
381
- // turn element or nodeList into an array
382
- utils.makeArray = function( obj ) {
383
- if ( Array.isArray( obj ) ) {
384
- // use object if already an array
385
- return obj;
386
- }
387
- // return empty array if undefined or null. #6
388
- if ( obj === null || obj === undefined ) {
389
- return [];
390
- }
391
-
392
- var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number';
393
- if ( isArrayLike ) {
394
- // convert nodeList to array
395
- return arraySlice.call( obj );
396
- }
397
-
398
- // array of single index
399
- return [ obj ];
400
- };
401
-
402
- // ----- removeFrom ----- //
403
-
404
- utils.removeFrom = function( ary, obj ) {
405
- var index = ary.indexOf( obj );
406
- if ( index != -1 ) {
407
- ary.splice( index, 1 );
408
- }
409
- };
410
-
411
- // ----- getParent ----- //
412
-
413
- utils.getParent = function( elem, selector ) {
414
- while ( elem.parentNode && elem != document.body ) {
415
- elem = elem.parentNode;
416
- if ( matchesSelector( elem, selector ) ) {
417
- return elem;
418
- }
419
- }
420
- };
421
-
422
- // ----- getQueryElement ----- //
423
-
424
- // use element as selector string
425
- utils.getQueryElement = function( elem ) {
426
- if ( typeof elem == 'string' ) {
427
- return document.querySelector( elem );
428
- }
429
- return elem;
430
- };
431
-
432
- // ----- handleEvent ----- //
433
-
434
- // enable .ontype to trigger from .addEventListener( elem, 'type' )
435
- utils.handleEvent = function( event ) {
436
- var method = 'on' + event.type;
437
- if ( this[ method ] ) {
438
- this[ method ]( event );
439
- }
440
- };
441
-
442
- // ----- filterFindElements ----- //
443
-
444
- utils.filterFindElements = function( elems, selector ) {
445
- // make array of elems
446
- elems = utils.makeArray( elems );
447
- var ffElems = [];
448
-
449
- elems.forEach( function( elem ) {
450
- // check that elem is an actual element
451
- if ( !( elem instanceof HTMLElement ) ) {
452
- return;
453
- }
454
- // add elem if no selector
455
- if ( !selector ) {
456
- ffElems.push( elem );
457
- return;
458
- }
459
- // filter & find items if we have a selector
460
- // filter
461
- if ( matchesSelector( elem, selector ) ) {
462
- ffElems.push( elem );
463
- }
464
- // find children
465
- var childElems = elem.querySelectorAll( selector );
466
- // concat childElems to filterFound array
467
- for ( var i=0; i < childElems.length; i++ ) {
468
- ffElems.push( childElems[i] );
469
- }
470
- });
471
-
472
- return ffElems;
473
- };
474
-
475
- // ----- debounceMethod ----- //
476
-
477
- utils.debounceMethod = function( _class, methodName, threshold ) {
478
- threshold = threshold || 100;
479
- // original method
480
- var method = _class.prototype[ methodName ];
481
- var timeoutName = methodName + 'Timeout';
482
-
483
- _class.prototype[ methodName ] = function() {
484
- var timeout = this[ timeoutName ];
485
- clearTimeout( timeout );
486
-
487
- var args = arguments;
488
- var _this = this;
489
- this[ timeoutName ] = setTimeout( function() {
490
- method.apply( _this, args );
491
- delete _this[ timeoutName ];
492
- }, threshold );
493
- };
494
- };
495
-
496
- // ----- docReady ----- //
497
-
498
- utils.docReady = function( callback ) {
499
- var readyState = document.readyState;
500
- if ( readyState == 'complete' || readyState == 'interactive' ) {
501
- // do async to allow for other scripts to run. metafizzy/flickity#441
502
- setTimeout( callback );
503
- } else {
504
- document.addEventListener( 'DOMContentLoaded', callback );
505
- }
506
- };
507
-
508
- // ----- htmlInit ----- //
509
-
510
- // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
511
- utils.toDashed = function( str ) {
512
- return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) {
513
- return $1 + '-' + $2;
514
- }).toLowerCase();
515
- };
516
-
517
- var console = window.console;
518
- /**
519
- * allow user to initialize classes via [data-namespace] or .js-namespace class
520
- * htmlInit( Widget, 'widgetName' )
521
- * options are parsed from data-namespace-options
522
- */
523
- utils.htmlInit = function( WidgetClass, namespace ) {
524
- utils.docReady( function() {
525
- var dashedNamespace = utils.toDashed( namespace );
526
- var dataAttr = 'data-' + dashedNamespace;
527
- var dataAttrElems = document.querySelectorAll( '[' + dataAttr + ']' );
528
- var jsDashElems = document.querySelectorAll( '.js-' + dashedNamespace );
529
- var elems = utils.makeArray( dataAttrElems )
530
- .concat( utils.makeArray( jsDashElems ) );
531
- var dataOptionsAttr = dataAttr + '-options';
532
- var jQuery = window.jQuery;
533
-
534
- elems.forEach( function( elem ) {
535
- var attr = elem.getAttribute( dataAttr ) ||
536
- elem.getAttribute( dataOptionsAttr );
537
- var options;
538
- try {
539
- options = attr && JSON.parse( attr );
540
- } catch ( error ) {
541
- // log error, do not initialize
542
- if ( console ) {
543
- console.error( 'Error parsing ' + dataAttr + ' on ' + elem.className +
544
- ': ' + error );
545
- }
546
- return;
547
- }
548
- // initialize
549
- var instance = new WidgetClass( elem, options );
550
- // make available via $().data('namespace')
551
- if ( jQuery ) {
552
- jQuery.data( elem, namespace, instance );
553
- }
554
- });
555
-
556
- });
557
- };
558
-
559
- // ----- ----- //
560
-
561
- return utils;
562
-
563
- }));
564
-
565
- // core
566
- ( function( window, factory ) {
567
- // universal module definition
568
- /* globals define, module, require */
569
- if ( typeof define == 'function' && define.amd ) {
570
- // AMD
571
- define( 'infinite-scroll/js/core',[
572
- 'ev-emitter/ev-emitter',
573
- 'fizzy-ui-utils/utils',
574
- ], function( EvEmitter, utils) {
575
- return factory( window, EvEmitter, utils );
576
- });
577
- } else if ( typeof module == 'object' && module.exports ) {
578
- // CommonJS
579
- module.exports = factory(
580
- window,
581
- require('ev-emitter'),
582
- require('fizzy-ui-utils')
583
- );
584
- } else {
585
- // browser global
586
- window.InfiniteScroll = factory(
587
- window,
588
- window.EvEmitter,
589
- window.fizzyUIUtils
590
- );
591
- }
592
-
593
- }( window, function factory( window, EvEmitter, utils ) {
594
-
595
- var jQuery = window.jQuery;
596
- // internal store of all InfiniteScroll intances
597
- var instances = {};
598
-
599
- function InfiniteScroll( element, options ) {
600
- var queryElem = utils.getQueryElement( element );
601
-
602
- if ( !queryElem ) {
603
- console.error( 'Bad element for InfiniteScroll: ' + ( queryElem || element ) );
604
- return;
605
- }
606
- element = queryElem;
607
- // do not initialize twice on same element
608
- if ( element.infiniteScrollGUID ) {
609
- var instance = instances[ element.infiniteScrollGUID ];
610
- instance.option( options );
611
- return instance;
612
- }
613
-
614
- this.element = element;
615
- // options
616
- this.options = utils.extend( {}, InfiniteScroll.defaults );
617
- this.option( options );
618
- // add jQuery
619
- if ( jQuery ) {
620
- this.$element = jQuery( this.element );
621
- }
622
-
623
- this.create();
624
- }
625
-
626
- // defaults
627
- InfiniteScroll.defaults = {
628
- // path: null,
629
- // hideNav: null,
630
- // debug: false,
631
- };
632
-
633
- // create & destroy methods
634
- InfiniteScroll.create = {};
635
- InfiniteScroll.destroy = {};
636
-
637
- var proto = InfiniteScroll.prototype;
638
- // inherit EvEmitter
639
- utils.extend( proto, EvEmitter.prototype );
640
-
641
- // -------------------------- -------------------------- //
642
-
643
- // globally unique identifiers
644
- var GUID = 0;
645
-
646
- proto.create = function() {
647
- // create core
648
- // add id for InfiniteScroll.data
649
- var id = this.guid = ++GUID;
650
- this.element.infiniteScrollGUID = id; // expando
651
- instances[ id ] = this; // associate via id
652
- // properties
653
- this.pageIndex = 1; // default to first page
654
- this.loadCount = 0;
655
- this.updateGetPath();
656
- // bail if getPath not set, or returns falsey #776
657
- var hasPath = this.getPath && this.getPath();
658
- if ( !hasPath ) {
659
- console.error('Disabling InfiniteScroll');
660
- return;
661
- }
662
- this.updateGetAbsolutePath();
663
- this.log( 'initialized', [ this.element.className ] );
664
- this.callOnInit();
665
- // create features
666
- for ( var method in InfiniteScroll.create ) {
667
- InfiniteScroll.create[ method ].call( this );
668
- }
669
- };
670
-
671
- proto.option = function( opts ) {
672
- utils.extend( this.options, opts );
673
- };
674
-
675
- // call onInit option, used for binding events on init
676
- proto.callOnInit = function() {
677
- var onInit = this.options.onInit;
678
- if ( onInit ) {
679
- onInit.call( this, this );
680
- }
681
- };
682
-
683
- // ----- events ----- //
684
-
685
- proto.dispatchEvent = function( type, event, args ) {
686
- this.log( type, args );
687
- var emitArgs = event ? [ event ].concat( args ) : args;
688
- this.emitEvent( type, emitArgs );
689
- // trigger jQuery event
690
- if ( !jQuery || !this.$element ) {
691
- return;
692
- }
693
- // namespace jQuery event
694
- type += '.infiniteScroll';
695
- var $event = type;
696
- if ( event ) {
697
- // create jQuery event
698
- var jQEvent = jQuery.Event( event );
699
- jQEvent.type = type;
700
- $event = jQEvent;
701
- }
702
- this.$element.trigger( $event, args );
703
- };
704
-
705
- var loggers = {
706
- initialized: function( className ) {
707
- return 'on ' + className;
708
- },
709
- request: function( path ) {
710
- return 'URL: ' + path;
711
- },
712
- load: function( response, path ) {
713
- return ( response.title || '' ) + '. URL: ' + path;
714
- },
715
- error: function( error, path ) {
716
- return error + '. URL: ' + path;
717
- },
718
- append: function( response, path, items ) {
719
- return items.length + ' items. URL: ' + path;
720
- },
721
- last: function( response, path ) {
722
- return 'URL: ' + path;
723
- },
724
- history: function( title, path ) {
725
- return 'URL: ' + path;
726
- },
727
- pageIndex: function( index, origin ) {
728
- return 'current page determined to be: ' + index + ' from ' + origin;
729
- },
730
- };
731
-
732
- // log events
733
- proto.log = function( type, args ) {
734
- if ( !this.options.debug ) {
735
- return;
736
- }
737
- var message = '[InfiniteScroll] ' + type;
738
- var logger = loggers[ type ];
739
- if ( logger ) {
740
- message += '. ' + logger.apply( this, args );
741
- }
742
- console.log( message );
743
- };
744
-
745
- // -------------------------- methods used amoung features -------------------------- //
746
-
747
- proto.updateMeasurements = function() {
748
- this.windowHeight = window.innerHeight;
749
- var rect = this.element.getBoundingClientRect();
750
- this.top = rect.top + window.pageYOffset;
751
- };
752
-
753
- proto.updateScroller = function() {
754
- var elementScroll = this.options.elementScroll;
755
- if ( !elementScroll ) {
756
- // default, use window
757
- this.scroller = window;
758
- return;
759
- }
760
- // if true, set to element, otherwise use option
761
- this.scroller = elementScroll === true ? this.element :
762
- utils.getQueryElement( elementScroll );
763
- if ( !this.scroller ) {
764
- throw 'Unable to find elementScroll: ' + elementScroll;
765
- }
766
- };
767
-
768
- // -------------------------- page path -------------------------- //
769
-
770
- proto.updateGetPath = function() {
771
- var optPath = this.options.path;
772
- if ( !optPath ) {
773
- console.error( 'InfiniteScroll path option required. Set as: ' + optPath );
774
- return;
775
- }
776
- // function
777
- var type = typeof optPath;
778
- if ( type == 'function' ) {
779
- this.getPath = optPath;
780
- return;
781
- }
782
- // template string: '/pages/{{#}}.html'
783
- var templateMatch = type == 'string' && optPath.match('{{#}}');
784
- if ( templateMatch ) {
785
- this.updateGetPathTemplate( optPath );
786
- return;
787
- }
788
- // selector: '.next-page-selector'
789
- this.updateGetPathSelector( optPath );
790
- };
791
-
792
- proto.updateGetPathTemplate = function( optPath ) {
793
- // set getPath with template string
794
- this.getPath = function() {
795
- var nextIndex = this.pageIndex + 1;
796
- return optPath.replace( '{{#}}', nextIndex );
797
- }.bind( this );
798
- // get pageIndex from location
799
- // convert path option into regex to look for pattern in location
800
- var regexString = optPath.replace( '{{#}}', '(\\d\\d?\\d?)' );
801
- var templateRe = new RegExp( regexString );
802
- var match = location.href.match( templateRe );
803
- if ( match ) {
804
- this.pageIndex = parseInt( match[1], 10 );
805
- this.log( 'pageIndex', [ this.pageIndex, 'template string' ] );
806
- }
807
- };
808
-
809
- var pathRegexes = [
810
- // WordPress & Tumblr - example.com/page/2
811
- // Jekyll - example.com/page2
812
- /^(.*?\/?page\/?)(\d\d?\d?)(.*?$)/,
813
- // Drupal - example.com/?page=1
814
- /^(.*?\/?\?page=)(\d\d?\d?)(.*?$)/,
815
- // catch all, last occurence of a number
816
- /(.*?)(\d\d?\d?)(?!.*\d)(.*?$)/,
817
- ];
818
-
819
- proto.updateGetPathSelector = function( optPath ) {
820
- // parse href of link: '.next-page-link'
821
- var hrefElem = document.querySelector( optPath );
822
- if ( !hrefElem ) {
823
- console.error( 'Bad InfiniteScroll path option. Next link not found: ' +
824
- optPath );
825
- return;
826
- }
827
- var href = hrefElem.getAttribute('href');
828
- // try matching href to pathRegexes patterns
829
- var pathParts, regex;
830
- for ( var i=0; href && i < pathRegexes.length; i++ ) {
831
- regex = pathRegexes[i];
832
- var match = href.match( regex );
833
- if ( match ) {
834
- pathParts = match.slice(1); // remove first part
835
- break;
836
- }
837
- }
838
- if ( !pathParts ) {
839
- console.error( 'InfiniteScroll unable to parse next link href: ' + href );
840
- return;
841
- }
842
- this.isPathSelector = true; // flag for checkLastPage()
843
- this.getPath = function() {
844
- var nextIndex = this.pageIndex + 1;
845
- return pathParts[0] + nextIndex + pathParts[2];
846
- }.bind( this );
847
- // get pageIndex from href
848
- this.pageIndex = parseInt( pathParts[1], 10 ) - 1;
849
- this.log( 'pageIndex', [ this.pageIndex, 'next link' ] );
850
- };
851
-
852
- proto.updateGetAbsolutePath = function() {
853
- var path = this.getPath();
854
- // path doesn't start with http or /
855
- var isAbsolute = path.match( /^http/ ) || path.match( /^\// );
856
- if ( isAbsolute ) {
857
- this.getAbsolutePath = this.getPath;
858
- return;
859
- }
860
-
861
- var pathname = location.pathname;
862
- // /foo/bar/index.html => /foo/bar
863
- var directory = pathname.substring( 0, pathname.lastIndexOf('/') );
864
-
865
- this.getAbsolutePath = function() {
866
- return directory + '/' + this.getPath();
867
- };
868
- };
869
-
870
- // -------------------------- nav -------------------------- //
871
-
872
- // hide navigation
873
- InfiniteScroll.create.hideNav = function() {
874
- var nav = utils.getQueryElement( this.options.hideNav );
875
- if ( !nav ) {
876
- return;
877
- }
878
- nav.style.display = 'none';
879
- this.nav = nav;
880
- };
881
-
882
- InfiniteScroll.destroy.hideNav = function() {
883
- if ( this.nav ) {
884
- this.nav.style.display = '';
885
- }
886
- };
887
-
888
- // -------------------------- destroy -------------------------- //
889
-
890
- proto.destroy = function() {
891
- this.allOff(); // remove all event listeners
892
- // call destroy methods
893
- for ( var method in InfiniteScroll.destroy ) {
894
- InfiniteScroll.destroy[ method ].call( this );
895
- }
896
-
897
- delete this.element.infiniteScrollGUID;
898
- delete instances[ this.guid ];
899
- };
900
-
901
- // -------------------------- utilities -------------------------- //
902
-
903
- // https://remysharp.com/2010/07/21/throttling-function-calls
904
- InfiniteScroll.throttle = function( fn, threshold ) {
905
- threshold = threshold || 200;
906
- var last, timeout;
907
-
908
- return function() {
909
- var now = +new Date();
910
- var args = arguments;
911
- var trigger = function() {
912
- last = now;
913
- fn.apply( this, args );
914
- }.bind( this );
915
- if ( last && now < last + threshold ) {
916
- // hold on to it
917
- clearTimeout( timeout );
918
- timeout = setTimeout( trigger, threshold );
919
- } else {
920
- trigger();
921
- }
922
- };
923
- };
924
-
925
- InfiniteScroll.data = function( elem ) {
926
- elem = utils.getQueryElement( elem );
927
- var id = elem && elem.infiniteScrollGUID;
928
- return id && instances[ id ];
929
- };
930
-
931
- // set internal jQuery, for Webpack + jQuery v3
932
- InfiniteScroll.setJQuery = function( $ ) {
933
- jQuery = $;
934
- };
935
-
936
- // -------------------------- setup -------------------------- //
937
-
938
- utils.htmlInit( InfiniteScroll, 'infinite-scroll' );
939
-
940
- if ( jQuery && jQuery.bridget ) {
941
- jQuery.bridget( 'infiniteScroll', InfiniteScroll );
942
- }
943
-
944
- // -------------------------- -------------------------- //
945
-
946
- return InfiniteScroll;
947
-
948
- }));
949
-
950
- // page-load
951
- ( function( window, factory ) {
952
- // universal module definition
953
- /* globals define, module, require */
954
- if ( typeof define == 'function' && define.amd ) {
955
- // AMD
956
- define( 'infinite-scroll/js/page-load',[
957
- './core',
958
- ], function( InfiniteScroll ) {
959
- return factory( window, InfiniteScroll );
960
- });
961
- } else if ( typeof module == 'object' && module.exports ) {
962
- // CommonJS
963
- module.exports = factory(
964
- window,
965
- require('./core')
966
- );
967
- } else {
968
- // browser global
969
- factory(
970
- window,
971
- window.InfiniteScroll
972
- );
973
- }
974
-
975
- }( window, function factory( window, InfiniteScroll ) {
976
-
977
- var proto = InfiniteScroll.prototype;
978
-
979
- // InfiniteScroll.defaults.append = false;
980
- InfiniteScroll.defaults.loadOnScroll = true;
981
- InfiniteScroll.defaults.checkLastPage = true;
982
- InfiniteScroll.defaults.responseType = 'document';
983
- // InfiniteScroll.defaults.prefill = false;
984
- // InfiniteScroll.defaults.outlayer = null;
985
-
986
- InfiniteScroll.create.pageLoad = function() {
987
- this.canLoad = true;
988
- this.on( 'scrollThreshold', this.onScrollThresholdLoad );
989
- this.on( 'load', this.checkLastPage );
990
- if ( this.options.outlayer ) {
991
- this.on( 'append', this.onAppendOutlayer );
992
- }
993
- };
994
-
995
- proto.onScrollThresholdLoad = function() {
996
- if ( this.options.loadOnScroll ) {
997
- this.loadNextPage();
998
- }
999
- };
1000
-
1001
- proto.loadNextPage = function() {
1002
- if ( this.isLoading || !this.canLoad ) {
1003
- return;
1004
- }
1005
-
1006
- var path = this.getAbsolutePath();
1007
- this.isLoading = true;
1008
-
1009
- var onLoad = function( response ) {
1010
- this.onPageLoad( response, path );
1011
- }.bind( this );
1012
-
1013
- var onError = function( error ) {
1014
- this.onPageError( error, path );
1015
- }.bind( this );
1016
-
1017
- request( path, this.options.responseType, onLoad, onError );
1018
- this.dispatchEvent( 'request', null, [ path ] );
1019
- };
1020
-
1021
- proto.onPageLoad = function( response, path ) {
1022
- // done loading if not appending
1023
- if ( !this.options.append ) {
1024
- this.isLoading = false;
1025
- }
1026
- this.pageIndex++;
1027
- this.loadCount++;
1028
- this.dispatchEvent( 'load', null, [ response, path ] );
1029
- this.appendNextPage( response, path );
1030
- return response;
1031
- };
1032
-
1033
- proto.appendNextPage = function( response, path ) {
1034
- var optAppend = this.options.append;
1035
- // do not append json
1036
- var isDocument = this.options.responseType == 'document';
1037
- if ( !isDocument || !optAppend ) {
1038
- return;
1039
- }
1040
-
1041
- var items = response.querySelectorAll( optAppend );
1042
- var fragment = getItemsFragment( items );
1043
- var appendReady = function () {
1044
- this.appendItems( items, fragment );
1045
- this.isLoading = false;
1046
- this.dispatchEvent( 'append', null, [ response, path, items ] );
1047
- }.bind( this );
1048
-
1049
- // TODO add hook for option to trigger appendReady
1050
- if ( this.options.outlayer ) {
1051
- this.appendOutlayerItems( fragment, appendReady );
1052
- } else {
1053
- appendReady();
1054
- }
1055
- };
1056
-
1057
- proto.appendItems = function( items, fragment ) {
1058
- if ( !items || !items.length ) {
1059
- return;
1060
- }
1061
- // get fragment if not provided
1062
- fragment = fragment || getItemsFragment( items );
1063
- refreshScripts( fragment );
1064
- this.element.appendChild( fragment );
1065
- };
1066
-
1067
- function getItemsFragment( items ) {
1068
- // add items to fragment
1069
- var fragment = document.createDocumentFragment();
1070
- for ( var i=0; items && i < items.length; i++ ) {
1071
- fragment.appendChild( items[i] );
1072
- }
1073
- return fragment;
1074
- }
1075
-
1076
- // replace <script>s with copies so they load
1077
- // <script>s added by InfiniteScroll will not load
1078
- // similar to https://stackoverflow.com/questions/610995
1079
- function refreshScripts( fragment ) {
1080
- var scripts = fragment.querySelectorAll('script');
1081
- for ( var i=0; i < scripts.length; i++ ) {
1082
- var script = scripts[i];
1083
- var freshScript = document.createElement('script');
1084
- copyAttributes( script, freshScript );
1085
- // copy inner script code. #718, #782
1086
- freshScript.innerHTML = script.innerHTML;
1087
- script.parentNode.replaceChild( freshScript, script );
1088
- }
1089
- }
1090
-
1091
- function copyAttributes( fromNode, toNode ) {
1092
- var attrs = fromNode.attributes;
1093
- for ( var i=0; i < attrs.length; i++ ) {
1094
- var attr = attrs[i];
1095
- toNode.setAttribute( attr.name, attr.value );
1096
- }
1097
- }
1098
-
1099
- // ----- outlayer ----- //
1100
-
1101
- proto.appendOutlayerItems = function( fragment, appendReady ) {
1102
- var imagesLoaded = InfiniteScroll.imagesLoaded || window.imagesLoaded;
1103
- if ( !imagesLoaded ) {
1104
- console.error('[InfiniteScroll] imagesLoaded required for outlayer option');
1105
- this.isLoading = false;
1106
- return;
1107
- }
1108
- // append once images loaded
1109
- imagesLoaded( fragment, appendReady );
1110
- };
1111
-
1112
- proto.onAppendOutlayer = function( response, path, items ) {
1113
- this.options.outlayer.appended( items );
1114
- };
1115
-
1116
- // ----- checkLastPage ----- //
1117
-
1118
- // check response for next element
1119
- proto.checkLastPage = function( response, path ) {
1120
- var checkLastPage = this.options.checkLastPage;
1121
- if ( !checkLastPage ) {
1122
- return;
1123
- }
1124
-
1125
- var pathOpt = this.options.path;
1126
- // if path is function, check if next path is truthy
1127
- if ( typeof pathOpt == 'function' ) {
1128
- var nextPath = this.getPath();
1129
- if ( !nextPath ) {
1130
- this.lastPageReached( response, path );
1131
- return;
1132
- }
1133
- }
1134
- // get selector from checkLastPage or path option
1135
- var selector;
1136
- if ( typeof checkLastPage == 'string' ) {
1137
- selector = checkLastPage;
1138
- } else if ( this.isPathSelector ) {
1139
- // path option is selector string
1140
- selector = pathOpt;
1141
- }
1142
- // check last page for selector
1143
- // bail if no selector or not document response
1144
- if ( !selector || !response.querySelector ) {
1145
- return;
1146
- }
1147
- // check if response has selector
1148
- var nextElem = response.querySelector( selector );
1149
- if ( !nextElem ) {
1150
- this.lastPageReached( response, path );
1151
- }
1152
- };
1153
-
1154
- proto.lastPageReached = function( response, path ) {
1155
- this.canLoad = false;
1156
- this.dispatchEvent( 'last', null, [ response, path ] );
1157
- };
1158
-
1159
- // ----- error ----- //
1160
-
1161
- proto.onPageError = function( error, path ) {
1162
- this.isLoading = false;
1163
- this.canLoad = false;
1164
- this.dispatchEvent( 'error', null, [ error, path ] );
1165
- return error;
1166
- };
1167
-
1168
- // -------------------------- prefill -------------------------- //
1169
-
1170
- InfiniteScroll.create.prefill = function() {
1171
- if ( !this.options.prefill ) {
1172
- return;
1173
- }
1174
- var append = this.options.append;
1175
- if ( !append ) {
1176
- console.error( 'append option required for prefill. Set as :' + append );
1177
- return;
1178
- }
1179
- this.updateMeasurements();
1180
- this.updateScroller();
1181
- this.isPrefilling = true;
1182
- this.on( 'append', this.prefill );
1183
- this.once( 'error', this.stopPrefill );
1184
- this.once( 'last', this.stopPrefill );
1185
- this.prefill();
1186
- };
1187
-
1188
- proto.prefill = function() {
1189
- var distance = this.getPrefillDistance();
1190
- this.isPrefilling = distance >= 0;
1191
- if ( this.isPrefilling ) {
1192
- this.log('prefill');
1193
- this.loadNextPage();
1194
- } else {
1195
- this.stopPrefill();
1196
- }
1197
- };
1198
-
1199
- proto.getPrefillDistance = function() {
1200
- // element scroll
1201
- if ( this.options.elementScroll ) {
1202
- return this.scroller.clientHeight - this.scroller.scrollHeight;
1203
- }
1204
- // window
1205
- return this.windowHeight - this.element.clientHeight;
1206
- };
1207
-
1208
- proto.stopPrefill = function() {
1209
- this.log('stopPrefill');
1210
- this.off( 'append', this.prefill );
1211
- };
1212
-
1213
- // -------------------------- request -------------------------- //
1214
-
1215
- function request( url, responseType, onLoad, onError ) {
1216
- var req = new XMLHttpRequest();
1217
- req.open( 'GET', url, true );
1218
- // set responseType document to return DOM
1219
- req.responseType = responseType || '';
1220
-
1221
- // set X-Requested-With header to check that is ajax request
1222
- req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
1223
-
1224
- req.onload = function() {
1225
- if ( req.status == 200 ) {
1226
- onLoad( req.response );
1227
- } else {
1228
- // not 200 OK, error
1229
- var error = new Error( req.statusText );
1230
- onError( error );
1231
- }
1232
- };
1233
-
1234
- // Handle network errors
1235
- req.onerror = function() {
1236
- var error = new Error( 'Network error requesting ' + url );
1237
- onError( error );
1238
- };
1239
-
1240
- req.send();
1241
- }
1242
-
1243
- // -------------------------- -------------------------- //
1244
-
1245
- return InfiniteScroll;
1246
-
1247
- }));
1248
-
1249
- // scroll-watch
1250
- ( function( window, factory ) {
1251
- // universal module definition
1252
- /* globals define, module, require */
1253
- if ( typeof define == 'function' && define.amd ) {
1254
- // AMD
1255
- define( 'infinite-scroll/js/scroll-watch',[
1256
- './core',
1257
- 'fizzy-ui-utils/utils',
1258
- ], function( InfiniteScroll, utils ) {
1259
- return factory( window, InfiniteScroll, utils );
1260
- });
1261
- } else if ( typeof module == 'object' && module.exports ) {
1262
- // CommonJS
1263
- module.exports = factory(
1264
- window,
1265
- require('./core'),
1266
- require('fizzy-ui-utils')
1267
- );
1268
- } else {
1269
- // browser global
1270
- factory(
1271
- window,
1272
- window.InfiniteScroll,
1273
- window.fizzyUIUtils
1274
- );
1275
- }
1276
-
1277
- }( window, function factory( window, InfiniteScroll, utils ) {
1278
-
1279
- var proto = InfiniteScroll.prototype;
1280
-
1281
- // default options
1282
- InfiniteScroll.defaults.scrollThreshold = 400;
1283
- // InfiniteScroll.defaults.elementScroll = null;
1284
-
1285
- InfiniteScroll.create.scrollWatch = function() {
1286
- // events
1287
- this.pageScrollHandler = this.onPageScroll.bind( this );
1288
- this.resizeHandler = this.onResize.bind( this );
1289
-
1290
- var scrollThreshold = this.options.scrollThreshold;
1291
- var isEnable = scrollThreshold || scrollThreshold === 0;
1292
- if ( isEnable ) {
1293
- this.enableScrollWatch();
1294
- }
1295
- };
1296
-
1297
- InfiniteScroll.destroy.scrollWatch = function() {
1298
- this.disableScrollWatch();
1299
- };
1300
-
1301
- proto.enableScrollWatch = function() {
1302
- if ( this.isScrollWatching ) {
1303
- return;
1304
- }
1305
- this.isScrollWatching = true;
1306
- this.updateMeasurements();
1307
- this.updateScroller();
1308
- // TODO disable after error?
1309
- this.on( 'last', this.disableScrollWatch );
1310
- this.bindScrollWatchEvents( true );
1311
- };
1312
-
1313
- proto.disableScrollWatch = function() {
1314
- if ( !this.isScrollWatching ) {
1315
- return;
1316
- }
1317
- this.bindScrollWatchEvents( false );
1318
- delete this.isScrollWatching;
1319
- };
1320
-
1321
- proto.bindScrollWatchEvents = function( isBind ) {
1322
- var addRemove = isBind ? 'addEventListener' : 'removeEventListener';
1323
- this.scroller[ addRemove ]( 'scroll', this.pageScrollHandler );
1324
- window[ addRemove ]( 'resize', this.resizeHandler );
1325
- };
1326
-
1327
- proto.onPageScroll = InfiniteScroll.throttle( function() {
1328
- var distance = this.getBottomDistance();
1329
- if ( distance <= this.options.scrollThreshold ) {
1330
- this.dispatchEvent('scrollThreshold');
1331
- }
1332
- });
1333
-
1334
- proto.getBottomDistance = function() {
1335
- if ( this.options.elementScroll ) {
1336
- return this.getElementBottomDistance();
1337
- } else {
1338
- return this.getWindowBottomDistance();
1339
- }
1340
- };
1341
-
1342
- proto.getWindowBottomDistance = function() {
1343
- var bottom = this.top + this.element.clientHeight;
1344
- var scrollY = window.pageYOffset + this.windowHeight;
1345
- return bottom - scrollY;
1346
- };
1347
-
1348
- proto.getElementBottomDistance = function() {
1349
- var bottom = this.scroller.scrollHeight;
1350
- var scrollY = this.scroller.scrollTop + this.scroller.clientHeight;
1351
- return bottom - scrollY;
1352
- };
1353
-
1354
- proto.onResize = function() {
1355
- this.updateMeasurements();
1356
- };
1357
-
1358
- utils.debounceMethod( InfiniteScroll, 'onResize', 150 );
1359
-
1360
- // -------------------------- -------------------------- //
1361
-
1362
- return InfiniteScroll;
1363
-
1364
- }));
1365
-
1366
- // history
1367
- ( function( window, factory ) {
1368
- // universal module definition
1369
- /* globals define, module, require */
1370
- if ( typeof define == 'function' && define.amd ) {
1371
- // AMD
1372
- define( 'infinite-scroll/js/history',[
1373
- './core',
1374
- 'fizzy-ui-utils/utils',
1375
- ], function( InfiniteScroll, utils ) {
1376
- return factory( window, InfiniteScroll, utils );
1377
- });
1378
- } else if ( typeof module == 'object' && module.exports ) {
1379
- // CommonJS
1380
- module.exports = factory(
1381
- window,
1382
- require('./core'),
1383
- require('fizzy-ui-utils')
1384
- );
1385
- } else {
1386
- // browser global
1387
- factory(
1388
- window,
1389
- window.InfiniteScroll,
1390
- window.fizzyUIUtils
1391
- );
1392
- }
1393
-
1394
- }( window, function factory( window, InfiniteScroll, utils ) {
1395
-
1396
- var proto = InfiniteScroll.prototype;
1397
-
1398
- InfiniteScroll.defaults.history = 'replace';
1399
- // InfiniteScroll.defaults.historyTitle = false;
1400
-
1401
- var link = document.createElement('a');
1402
-
1403
- // ----- create/destroy ----- //
1404
-
1405
- InfiniteScroll.create.history = function() {
1406
- if ( !this.options.history ) {
1407
- return;
1408
- }
1409
- // check for same origin
1410
- link.href = this.getAbsolutePath();
1411
- // MS Edge does not have origin on link https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12236493/
1412
- var linkOrigin = link.origin || link.protocol + '//' + link.host;
1413
- var isSameOrigin = linkOrigin == location.origin;
1414
- if ( !isSameOrigin ) {
1415
- console.error( '[InfiniteScroll] cannot set history with different origin: ' +
1416
- link.origin + ' on ' + location.origin +
1417
- ' . History behavior disabled.' );
1418
- return;
1419
- }
1420
-
1421
- // two ways to handle changing history
1422
- if ( this.options.append ) {
1423
- this.createHistoryAppend();
1424
- } else {
1425
- this.createHistoryPageLoad();
1426
- }
1427
- };
1428
-
1429
- proto.createHistoryAppend = function() {
1430
- this.updateMeasurements();
1431
- this.updateScroller();
1432
- // array of scroll positions of appended pages
1433
- this.scrollPages = [
1434
- {
1435
- // first page
1436
- top: 0,
1437
- path: location.href,
1438
- title: document.title,
1439
- }
1440
- ];
1441
- this.scrollPageIndex = 0;
1442
- // events
1443
- this.scrollHistoryHandler = this.onScrollHistory.bind( this );
1444
- this.unloadHandler = this.onUnload.bind( this );
1445
- this.scroller.addEventListener( 'scroll', this.scrollHistoryHandler );
1446
- this.on( 'append', this.onAppendHistory );
1447
- this.bindHistoryAppendEvents( true );
1448
- };
1449
-
1450
- proto.bindHistoryAppendEvents = function( isBind ) {
1451
- var addRemove = isBind ? 'addEventListener' : 'removeEventListener';
1452
- this.scroller[ addRemove ]( 'scroll', this.scrollHistoryHandler );
1453
- window[ addRemove ]( 'unload', this.unloadHandler );
1454
- };
1455
-
1456
- proto.createHistoryPageLoad = function() {
1457
- this.on( 'load', this.onPageLoadHistory );
1458
- };
1459
-
1460
- InfiniteScroll.destroy.history =
1461
- proto.destroyHistory = function() {
1462
- var isHistoryAppend = this.options.history && this.options.append;
1463
- if ( isHistoryAppend ) {
1464
- this.bindHistoryAppendEvents( false );
1465
- }
1466
- };
1467
-
1468
- // ----- append history ----- //
1469
-
1470
- proto.onAppendHistory = function( response, path, items ) {
1471
- // do not proceed if no items. #779
1472
- if ( !items || !items.length ) {
1473
- return;
1474
- }
1475
- var firstItem = items[0];
1476
- var elemScrollY = this.getElementScrollY( firstItem );
1477
- // resolve path
1478
- link.href = path;
1479
- // add page data to hash
1480
- this.scrollPages.push({
1481
- top: elemScrollY,
1482
- path: link.href,
1483
- title: response.title,
1484
- });
1485
- };
1486
-
1487
- proto.getElementScrollY = function( elem ) {
1488
- if ( this.options.elementScroll ) {
1489
- return this.getElementElementScrollY( elem );
1490
- } else {
1491
- return this.getElementWindowScrollY( elem );
1492
- }
1493
- };
1494
-
1495
- proto.getElementWindowScrollY = function( elem ) {
1496
- var rect = elem.getBoundingClientRect();
1497
- return rect.top + window.pageYOffset;
1498
- };
1499
-
1500
- // wow, stupid name
1501
- proto.getElementElementScrollY = function( elem ) {
1502
- return elem.offsetTop - this.top;
1503
- };
1504
-
1505
- proto.onScrollHistory = function() {
1506
- // cycle through positions, find biggest without going over
1507
- var scrollViewY = this.getScrollViewY();
1508
- var pageIndex, page;
1509
- for ( var i=0; i < this.scrollPages.length; i++ ) {
1510
- var scrollPage = this.scrollPages[i];
1511
- if ( scrollPage.top >= scrollViewY ) {
1512
- break;
1513
- }
1514
- pageIndex = i;
1515
- page = scrollPage;
1516
- }
1517
- // set history if changed
1518
- if ( pageIndex != this.scrollPageIndex ) {
1519
- this.scrollPageIndex = pageIndex;
1520
- this.setHistory( page.title, page.path );
1521
- }
1522
- };
1523
-
1524
- utils.debounceMethod( InfiniteScroll, 'onScrollHistory', 150 );
1525
-
1526
- proto.getScrollViewY = function() {
1527
- if ( this.options.elementScroll ) {
1528
- return this.scroller.scrollTop + this.scroller.clientHeight/2;
1529
- } else {
1530
- return window.pageYOffset + this.windowHeight/2;
1531
- }
1532
- };
1533
-
1534
- proto.setHistory = function( title, path ) {
1535
- var optHistory = this.options.history;
1536
- var historyMethod = optHistory && history[ optHistory + 'State' ];
1537
- if ( !historyMethod ) {
1538
- return;
1539
- }
1540
-
1541
- history[ optHistory + 'State' ]( null, title, path );
1542
-
1543
- if ( this.options.historyTitle ) {
1544
- document.title = title;
1545
- }
1546
-
1547
- this.dispatchEvent( 'history', null, [ title, path ] );
1548
- };
1549
-
1550
- // scroll to top to prevent initial scroll-reset after page refresh
1551
- // https://stackoverflow.com/a/18633915/182183
1552
- proto.onUnload = function() {
1553
- var pageIndex = this.scrollPageIndex;
1554
- if ( pageIndex === 0 ) {
1555
- return;
1556
- }
1557
- // calculate where scroll position would be on refresh
1558
- var scrollPage = this.scrollPages[ pageIndex ];
1559
- var scrollY = window.pageYOffset - scrollPage.top + this.top;
1560
- // disable scroll event before setting scroll #679
1561
- this.destroyHistory();
1562
- scrollTo( 0, scrollY );
1563
- };
1564
-
1565
- // ----- load history ----- //
1566
-
1567
- // update URL
1568
- proto.onPageLoadHistory = function( response, path ) {
1569
- this.setHistory( response.title, path );
1570
- };
1571
-
1572
- // -------------------------- -------------------------- //
1573
-
1574
- return InfiniteScroll;
1575
-
1576
- }));
1577
-
1578
- // button
1579
- ( function( window, factory ) {
1580
- // universal module definition
1581
- /* globals define, module, require */
1582
- if ( typeof define == 'function' && define.amd ) {
1583
- // AMD
1584
- define( 'infinite-scroll/js/button',[
1585
- './core',
1586
- 'fizzy-ui-utils/utils',
1587
- ], function( InfiniteScroll, utils ) {
1588
- return factory( window, InfiniteScroll, utils );
1589
- });
1590
- } else if ( typeof module == 'object' && module.exports ) {
1591
- // CommonJS
1592
- module.exports = factory(
1593
- window,
1594
- require('./core'),
1595
- require('fizzy-ui-utils')
1596
- );
1597
- } else {
1598
- // browser global
1599
- factory(
1600
- window,
1601
- window.InfiniteScroll,
1602
- window.fizzyUIUtils
1603
- );
1604
- }
1605
-
1606
- }( window, function factory( window, InfiniteScroll, utils ) {
1607
-
1608
- // InfiniteScroll.defaults.button = null;
1609
-
1610
- InfiniteScroll.create.button = function() {
1611
- var buttonElem = utils.getQueryElement( this.options.button );
1612
- if ( buttonElem ) {
1613
- this.button = new InfiniteScrollButton( buttonElem, this );
1614
- return;
1615
- }
1616
- };
1617
-
1618
- InfiniteScroll.destroy.button = function() {
1619
- if ( this.button ) {
1620
- this.button.destroy();
1621
- }
1622
- };
1623
-
1624
- // -------------------------- InfiniteScrollButton -------------------------- //
1625
-
1626
- function InfiniteScrollButton( element, infScroll ) {
1627
- this.element = element;
1628
- this.infScroll = infScroll;
1629
- // events
1630
- this.clickHandler = this.onClick.bind( this );
1631
- this.element.addEventListener( 'click', this.clickHandler );
1632
- infScroll.on( 'request', this.disable.bind( this ) );
1633
- infScroll.on( 'load', this.enable.bind( this ) );
1634
- infScroll.on( 'error', this.hide.bind( this ) );
1635
- infScroll.on( 'last', this.hide.bind( this ) );
1636
- }
1637
-
1638
- InfiniteScrollButton.prototype.onClick = function( event ) {
1639
- event.preventDefault();
1640
- this.infScroll.loadNextPage();
1641
- };
1642
-
1643
- InfiniteScrollButton.prototype.enable = function() {
1644
- this.element.removeAttribute('disabled');
1645
- };
1646
-
1647
- InfiniteScrollButton.prototype.disable = function() {
1648
- this.element.disabled = 'disabled';
1649
- };
1650
-
1651
- InfiniteScrollButton.prototype.hide = function() {
1652
- this.element.style.display = 'none';
1653
- };
1654
-
1655
- InfiniteScrollButton.prototype.destroy = function() {
1656
- this.element.removeEventListener( 'click', this.clickHandler );
1657
- };
1658
-
1659
- // -------------------------- -------------------------- //
1660
-
1661
- InfiniteScroll.Button = InfiniteScrollButton;
1662
-
1663
- return InfiniteScroll;
1664
-
1665
- }));
1666
-
1667
- // status
1668
- ( function( window, factory ) {
1669
- // universal module definition
1670
- /* globals define, module, require */
1671
- if ( typeof define == 'function' && define.amd ) {
1672
- // AMD
1673
- define( 'infinite-scroll/js/status',[
1674
- './core',
1675
- 'fizzy-ui-utils/utils',
1676
- ], function( InfiniteScroll, utils ) {
1677
- return factory( window, InfiniteScroll, utils );
1678
- });
1679
- } else if ( typeof module == 'object' && module.exports ) {
1680
- // CommonJS
1681
- module.exports = factory(
1682
- window,
1683
- require('./core'),
1684
- require('fizzy-ui-utils')
1685
- );
1686
- } else {
1687
- // browser global
1688
- factory(
1689
- window,
1690
- window.InfiniteScroll,
1691
- window.fizzyUIUtils
1692
- );
1693
- }
1694
-
1695
- }( window, function factory( window, InfiniteScroll, utils ) {
1696
-
1697
- var proto = InfiniteScroll.prototype;
1698
-
1699
- // InfiniteScroll.defaults.status = null;
1700
-
1701
- InfiniteScroll.create.status = function() {
1702
- var statusElem = utils.getQueryElement( this.options.status );
1703
- if ( !statusElem ) {
1704
- return;
1705
- }
1706
- // elements
1707
- this.statusElement = statusElem;
1708
- this.statusEventElements = {
1709
- request: statusElem.querySelector('.infinite-scroll-request'),
1710
- error: statusElem.querySelector('.infinite-scroll-error'),
1711
- last: statusElem.querySelector('.infinite-scroll-last'),
1712
- };
1713
- // events
1714
- this.on( 'request', this.showRequestStatus );
1715
- this.on( 'error', this.showErrorStatus );
1716
- this.on( 'last', this.showLastStatus );
1717
- this.bindHideStatus('on');
1718
- };
1719
-
1720
- proto.bindHideStatus = function( bindMethod ) {
1721
- var hideEvent = this.options.append ? 'append' : 'load';
1722
- this[ bindMethod ]( hideEvent, this.hideAllStatus );
1723
- };
1724
-
1725
- proto.showRequestStatus = function() {
1726
- this.showStatus('request');
1727
- };
1728
-
1729
- proto.showErrorStatus = function() {
1730
- this.showStatus('error');
1731
- };
1732
-
1733
- proto.showLastStatus = function() {
1734
- this.showStatus('last');
1735
- // prevent last then append event race condition from showing last status #706
1736
- this.bindHideStatus('off');
1737
- };
1738
-
1739
- proto.showStatus = function( eventName ) {
1740
- show( this.statusElement );
1741
- this.hideStatusEventElements();
1742
- var eventElem = this.statusEventElements[ eventName ];
1743
- show( eventElem );
1744
- };
1745
-
1746
- proto.hideAllStatus = function() {
1747
- hide( this.statusElement );
1748
- this.hideStatusEventElements();
1749
- };
1750
-
1751
- proto.hideStatusEventElements = function() {
1752
- for ( var type in this.statusEventElements ) {
1753
- var eventElem = this.statusEventElements[ type ];
1754
- hide( eventElem );
1755
- }
1756
- };
1757
-
1758
- // -------------------------- -------------------------- //
1759
-
1760
- function hide( elem ) {
1761
- setDisplay( elem, 'none' );
1762
- }
1763
-
1764
- function show( elem ) {
1765
- setDisplay( elem, 'block' );
1766
- }
1767
-
1768
- function setDisplay( elem, value ) {
1769
- if ( elem ) {
1770
- elem.style.display = value;
1771
- }
1772
- }
1773
-
1774
- // -------------------------- -------------------------- //
1775
-
1776
- return InfiniteScroll;
1777
-
1778
- }));
1779
-
1780
- /*!
1781
- * Infinite Scroll v3.0.4
1782
- * Automatically add next page
1783
- *
1784
- * Licensed GPLv3 for open source use
1785
- * or Infinite Scroll Commercial License for commercial use
1786
- *
1787
- * https://infinite-scroll.com
1788
- * Copyright 2018 Metafizzy
1789
- */
1790
-
1791
- ( function( window, factory ) {
1792
- // universal module definition
1793
- /* globals define, module, require */
1794
- if ( typeof define == 'function' && define.amd ) {
1795
- // AMD
1796
- define( [
1797
- 'infinite-scroll/js/core',
1798
- 'infinite-scroll/js/page-load',
1799
- 'infinite-scroll/js/scroll-watch',
1800
- 'infinite-scroll/js/history',
1801
- 'infinite-scroll/js/button',
1802
- 'infinite-scroll/js/status',
1803
- ], factory );
1804
- } else if ( typeof module == 'object' && module.exports ) {
1805
- // CommonJS
1806
- module.exports = factory(
1807
- require('./core'),
1808
- require('./page-load'),
1809
- require('./scroll-watch'),
1810
- require('./history'),
1811
- require('./button'),
1812
- require('./status')
1813
- );
1814
- }
1815
-
1816
- })( window, function factory( InfiniteScroll ) {
1817
- return InfiniteScroll;
1818
- });
1819
-
1820
- /*!
1821
- * imagesLoaded v4.1.4
1822
- * JavaScript is all like "You images are done yet or what?"
1823
- * MIT License
1824
- */
1825
-
1826
- ( function( window, factory ) { 'use strict';
1827
- // universal module definition
1828
-
1829
- /*global define: false, module: false, require: false */
1830
-
1831
- if ( typeof define == 'function' && define.amd ) {
1832
- // AMD
1833
- define( 'imagesloaded/imagesloaded',[
1834
- 'ev-emitter/ev-emitter'
1835
- ], function( EvEmitter ) {
1836
- return factory( window, EvEmitter );
1837
- });
1838
- } else if ( typeof module == 'object' && module.exports ) {
1839
- // CommonJS
1840
- module.exports = factory(
1841
- window,
1842
- require('ev-emitter')
1843
- );
1844
- } else {
1845
- // browser global
1846
- window.imagesLoaded = factory(
1847
- window,
1848
- window.EvEmitter
1849
- );
1850
- }
1851
-
1852
- })( typeof window !== 'undefined' ? window : this,
1853
-
1854
- // -------------------------- factory -------------------------- //
1855
-
1856
- function factory( window, EvEmitter ) {
1857
-
1858
-
1859
-
1860
- var $ = window.jQuery;
1861
- var console = window.console;
1862
-
1863
- // -------------------------- helpers -------------------------- //
1864
-
1865
- // extend objects
1866
- function extend( a, b ) {
1867
- for ( var prop in b ) {
1868
- a[ prop ] = b[ prop ];
1869
- }
1870
- return a;
1871
- }
1872
-
1873
- var arraySlice = Array.prototype.slice;
1874
-
1875
- // turn element or nodeList into an array
1876
- function makeArray( obj ) {
1877
- if ( Array.isArray( obj ) ) {
1878
- // use object if already an array
1879
- return obj;
1880
- }
1881
-
1882
- var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number';
1883
- if ( isArrayLike ) {
1884
- // convert nodeList to array
1885
- return arraySlice.call( obj );
1886
- }
1887
-
1888
- // array of single index
1889
- return [ obj ];
1890
- }
1891
-
1892
- // -------------------------- imagesLoaded -------------------------- //
1893
-
1894
- /**
1895
- * @param {Array, Element, NodeList, String} elem
1896
- * @param {Object or Function} options - if function, use as callback
1897
- * @param {Function} onAlways - callback function
1898
- */
1899
- function ImagesLoaded( elem, options, onAlways ) {
1900
- // coerce ImagesLoaded() without new, to be new ImagesLoaded()
1901
- if ( !( this instanceof ImagesLoaded ) ) {
1902
- return new ImagesLoaded( elem, options, onAlways );
1903
- }
1904
- // use elem as selector string
1905
- var queryElem = elem;
1906
- if ( typeof elem == 'string' ) {
1907
- queryElem = document.querySelectorAll( elem );
1908
- }
1909
- // bail if bad element
1910
- if ( !queryElem ) {
1911
- console.error( 'Bad element for imagesLoaded ' + ( queryElem || elem ) );
1912
- return;
1913
- }
1914
-
1915
- this.elements = makeArray( queryElem );
1916
- this.options = extend( {}, this.options );
1917
- // shift arguments if no options set
1918
- if ( typeof options == 'function' ) {
1919
- onAlways = options;
1920
- } else {
1921
- extend( this.options, options );
1922
- }
1923
-
1924
- if ( onAlways ) {
1925
- this.on( 'always', onAlways );
1926
- }
1927
-
1928
- this.getImages();
1929
-
1930
- if ( $ ) {
1931
- // add jQuery Deferred object
1932
- this.jqDeferred = new $.Deferred();
1933
- }
1934
-
1935
- // HACK check async to allow time to bind listeners
1936
- setTimeout( this.check.bind( this ) );
1937
- }
1938
-
1939
- ImagesLoaded.prototype = Object.create( EvEmitter.prototype );
1940
-
1941
- ImagesLoaded.prototype.options = {};
1942
-
1943
- ImagesLoaded.prototype.getImages = function() {
1944
- this.images = [];
1945
-
1946
- // filter & find items if we have an item selector
1947
- this.elements.forEach( this.addElementImages, this );
1948
- };
1949
-
1950
- /**
1951
- * @param {Node} element
1952
- */
1953
- ImagesLoaded.prototype.addElementImages = function( elem ) {
1954
- // filter siblings
1955
- if ( elem.nodeName == 'IMG' ) {
1956
- this.addImage( elem );
1957
- }
1958
- // get background image on element
1959
- if ( this.options.background === true ) {
1960
- this.addElementBackgroundImages( elem );
1961
- }
1962
-
1963
- // find children
1964
- // no non-element nodes, #143
1965
- var nodeType = elem.nodeType;
1966
- if ( !nodeType || !elementNodeTypes[ nodeType ] ) {
1967
- return;
1968
- }
1969
- var childImgs = elem.querySelectorAll('img');
1970
- // concat childElems to filterFound array
1971
- for ( var i=0; i < childImgs.length; i++ ) {
1972
- var img = childImgs[i];
1973
- this.addImage( img );
1974
- }
1975
-
1976
- // get child background images
1977
- if ( typeof this.options.background == 'string' ) {
1978
- var children = elem.querySelectorAll( this.options.background );
1979
- for ( i=0; i < children.length; i++ ) {
1980
- var child = children[i];
1981
- this.addElementBackgroundImages( child );
1982
- }
1983
- }
1984
- };
1985
-
1986
- var elementNodeTypes = {
1987
- 1: true,
1988
- 9: true,
1989
- 11: true
1990
- };
1991
-
1992
- ImagesLoaded.prototype.addElementBackgroundImages = function( elem ) {
1993
- var style = getComputedStyle( elem );
1994
- if ( !style ) {
1995
- // Firefox returns null if in a hidden iframe https://bugzil.la/548397
1996
- return;
1997
- }
1998
- // get url inside url("...")
1999
- var reURL = /url\((['"])?(.*?)\1\)/gi;
2000
- var matches = reURL.exec( style.backgroundImage );
2001
- while ( matches !== null ) {
2002
- var url = matches && matches[2];
2003
- if ( url ) {
2004
- this.addBackground( url, elem );
2005
- }
2006
- matches = reURL.exec( style.backgroundImage );
2007
- }
2008
- };
2009
-
2010
- /**
2011
- * @param {Image} img
2012
- */
2013
- ImagesLoaded.prototype.addImage = function( img ) {
2014
- var loadingImage = new LoadingImage( img );
2015
- this.images.push( loadingImage );
2016
- };
2017
-
2018
- ImagesLoaded.prototype.addBackground = function( url, elem ) {
2019
- var background = new Background( url, elem );
2020
- this.images.push( background );
2021
- };
2022
-
2023
- ImagesLoaded.prototype.check = function() {
2024
- var _this = this;
2025
- this.progressedCount = 0;
2026
- this.hasAnyBroken = false;
2027
- // complete if no images
2028
- if ( !this.images.length ) {
2029
- this.complete();
2030
- return;
2031
- }
2032
-
2033
- function onProgress( image, elem, message ) {
2034
- // HACK - Chrome triggers event before object properties have changed. #83
2035
- setTimeout( function() {
2036
- _this.progress( image, elem, message );
2037
- });
2038
- }
2039
-
2040
- this.images.forEach( function( loadingImage ) {
2041
- loadingImage.once( 'progress', onProgress );
2042
- loadingImage.check();
2043
- });
2044
- };
2045
-
2046
- ImagesLoaded.prototype.progress = function( image, elem, message ) {
2047
- this.progressedCount++;
2048
- this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded;
2049
- // progress event
2050
- this.emitEvent( 'progress', [ this, image, elem ] );
2051
- if ( this.jqDeferred && this.jqDeferred.notify ) {
2052
- this.jqDeferred.notify( this, image );
2053
- }
2054
- // check if completed
2055
- if ( this.progressedCount == this.images.length ) {
2056
- this.complete();
2057
- }
2058
-
2059
- if ( this.options.debug && console ) {
2060
- console.log( 'progress: ' + message, image, elem );
2061
- }
2062
- };
2063
-
2064
- ImagesLoaded.prototype.complete = function() {
2065
- var eventName = this.hasAnyBroken ? 'fail' : 'done';
2066
- this.isComplete = true;
2067
- this.emitEvent( eventName, [ this ] );
2068
- this.emitEvent( 'always', [ this ] );
2069
- if ( this.jqDeferred ) {
2070
- var jqMethod = this.hasAnyBroken ? 'reject' : 'resolve';
2071
- this.jqDeferred[ jqMethod ]( this );
2072
- }
2073
- };
2074
-
2075
- // -------------------------- -------------------------- //
2076
-
2077
- function LoadingImage( img ) {
2078
- this.img = img;
2079
- }
2080
-
2081
- LoadingImage.prototype = Object.create( EvEmitter.prototype );
2082
-
2083
- LoadingImage.prototype.check = function() {
2084
- // If complete is true and browser supports natural sizes,
2085
- // try to check for image status manually.
2086
- var isComplete = this.getIsImageComplete();
2087
- if ( isComplete ) {
2088
- // report based on naturalWidth
2089
- this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
2090
- return;
2091
- }
2092
-
2093
- // If none of the checks above matched, simulate loading on detached element.
2094
- this.proxyImage = new Image();
2095
- this.proxyImage.addEventListener( 'load', this );
2096
- this.proxyImage.addEventListener( 'error', this );
2097
- // bind to image as well for Firefox. #191
2098
- this.img.addEventListener( 'load', this );
2099
- this.img.addEventListener( 'error', this );
2100
- this.proxyImage.src = this.img.src;
2101
- };
2102
-
2103
- LoadingImage.prototype.getIsImageComplete = function() {
2104
- // check for non-zero, non-undefined naturalWidth
2105
- // fixes Safari+InfiniteScroll+Masonry bug infinite-scroll#671
2106
- return this.img.complete && this.img.naturalWidth;
2107
- };
2108
-
2109
- LoadingImage.prototype.confirm = function( isLoaded, message ) {
2110
- this.isLoaded = isLoaded;
2111
- this.emitEvent( 'progress', [ this, this.img, message ] );
2112
- };
2113
-
2114
- // ----- events ----- //
2115
-
2116
- // trigger specified handler for event type
2117
- LoadingImage.prototype.handleEvent = function( event ) {
2118
- var method = 'on' + event.type;
2119
- if ( this[ method ] ) {
2120
- this[ method ]( event );
2121
- }
2122
- };
2123
-
2124
- LoadingImage.prototype.onload = function() {
2125
- this.confirm( true, 'onload' );
2126
- this.unbindEvents();
2127
- };
2128
-
2129
- LoadingImage.prototype.onerror = function() {
2130
- this.confirm( false, 'onerror' );
2131
- this.unbindEvents();
2132
- };
2133
-
2134
- LoadingImage.prototype.unbindEvents = function() {
2135
- this.proxyImage.removeEventListener( 'load', this );
2136
- this.proxyImage.removeEventListener( 'error', this );
2137
- this.img.removeEventListener( 'load', this );
2138
- this.img.removeEventListener( 'error', this );
2139
- };
2140
-
2141
- // -------------------------- Background -------------------------- //
2142
-
2143
- function Background( url, element ) {
2144
- this.url = url;
2145
- this.element = element;
2146
- this.img = new Image();
2147
- }
2148
-
2149
- // inherit LoadingImage prototype
2150
- Background.prototype = Object.create( LoadingImage.prototype );
2151
-
2152
- Background.prototype.check = function() {
2153
- this.img.addEventListener( 'load', this );
2154
- this.img.addEventListener( 'error', this );
2155
- this.img.src = this.url;
2156
- // check if image is already complete
2157
- var isComplete = this.getIsImageComplete();
2158
- if ( isComplete ) {
2159
- this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
2160
- this.unbindEvents();
2161
- }
2162
- };
2163
-
2164
- Background.prototype.unbindEvents = function() {
2165
- this.img.removeEventListener( 'load', this );
2166
- this.img.removeEventListener( 'error', this );
2167
- };
2168
-
2169
- Background.prototype.confirm = function( isLoaded, message ) {
2170
- this.isLoaded = isLoaded;
2171
- this.emitEvent( 'progress', [ this, this.element, message ] );
2172
- };
2173
-
2174
- // -------------------------- jQuery -------------------------- //
2175
-
2176
- ImagesLoaded.makeJQueryPlugin = function( jQuery ) {
2177
- jQuery = jQuery || window.jQuery;
2178
- if ( !jQuery ) {
2179
- return;
2180
- }
2181
- // set local variable
2182
- $ = jQuery;
2183
- // $().imagesLoaded()
2184
- $.fn.imagesLoaded = function( options, callback ) {
2185
- var instance = new ImagesLoaded( this, options, callback );
2186
- return instance.jqDeferred.promise( $(this) );
2187
- };
2188
- };
2189
- // try making plugin
2190
- ImagesLoaded.makeJQueryPlugin();
2191
-
2192
- // -------------------------- -------------------------- //
2193
-
2194
- return ImagesLoaded;
2195
-
2196
- });
2197
-
 
 
 
 
 
 
 
1
+ /*!
2
+ * Infinite Scroll PACKAGED v3.0.5
3
+ * Automatically add next page
4
+ *
5
+ * Licensed GPLv3 for open source use
6
+ * or Infinite Scroll Commercial License for commercial use
7
+ *
8
+ * https://infinite-scroll.com
9
+ * Copyright 2018 Metafizzy
10
+ */
11
+
12
+ /**
13
+ * Bridget makes jQuery widgets
14
+ * v2.0.1
15
+ * MIT license
16
+ */
17
+
18
+ /* jshint browser: true, strict: true, undef: true, unused: true */
19
+
20
+ ( function( window, factory ) {
21
+ // universal module definition
22
+ /*jshint strict: false */ /* globals define, module, require */
23
+ if ( typeof define == 'function' && define.amd ) {
24
+ // AMD
25
+ define( 'jquery-bridget/jquery-bridget',[ 'jquery' ], function( jQuery ) {
26
+ return factory( window, jQuery );
27
+ });
28
+ } else if ( typeof module == 'object' && module.exports ) {
29
+ // CommonJS
30
+ module.exports = factory(
31
+ window,
32
+ require('jquery')
33
+ );
34
+ } else {
35
+ // browser global
36
+ window.jQueryBridget = factory(
37
+ window,
38
+ window.jQuery
39
+ );
40
+ }
41
+
42
+ }( window, function factory( window, jQuery ) {
43
+ 'use strict';
44
+
45
+ // ----- utils ----- //
46
+
47
+ var arraySlice = Array.prototype.slice;
48
+
49
+ // helper function for logging errors
50
+ // $.error breaks jQuery chaining
51
+ var console = window.console;
52
+ var logError = typeof console == 'undefined' ? function() {} :
53
+ function( message ) {
54
+ console.error( message );
55
+ };
56
+
57
+ // ----- jQueryBridget ----- //
58
+
59
+ function jQueryBridget( namespace, PluginClass, $ ) {
60
+ $ = $ || jQuery || window.jQuery;
61
+ if ( !$ ) {
62
+ return;
63
+ }
64
+
65
+ // add option method -> $().plugin('option', {...})
66
+ if ( !PluginClass.prototype.option ) {
67
+ // option setter
68
+ PluginClass.prototype.option = function( opts ) {
69
+ // bail out if not an object
70
+ if ( !$.isPlainObject( opts ) ){
71
+ return;
72
+ }
73
+ this.options = $.extend( true, this.options, opts );
74
+ };
75
+ }
76
+
77
+ // make jQuery plugin
78
+ $.fn[ namespace ] = function( arg0 /*, arg1 */ ) {
79
+ if ( typeof arg0 == 'string' ) {
80
+ // method call $().plugin( 'methodName', { options } )
81
+ // shift arguments by 1
82
+ var args = arraySlice.call( arguments, 1 );
83
+ return methodCall( this, arg0, args );
84
+ }
85
+ // just $().plugin({ options })
86
+ plainCall( this, arg0 );
87
+ return this;
88
+ };
89
+
90
+ // $().plugin('methodName')
91
+ function methodCall( $elems, methodName, args ) {
92
+ var returnValue;
93
+ var pluginMethodStr = '$().' + namespace + '("' + methodName + '")';
94
+
95
+ $elems.each( function( i, elem ) {
96
+ // get instance
97
+ var instance = $.data( elem, namespace );
98
+ if ( !instance ) {
99
+ logError( namespace + ' not initialized. Cannot call methods, i.e. ' +
100
+ pluginMethodStr );
101
+ return;
102
+ }
103
+
104
+ var method = instance[ methodName ];
105
+ if ( !method || methodName.charAt(0) == '_' ) {
106
+ logError( pluginMethodStr + ' is not a valid method' );
107
+ return;
108
+ }
109
+
110
+ // apply method, get return value
111
+ var value = method.apply( instance, args );
112
+ // set return value if value is returned, use only first value
113
+ returnValue = returnValue === undefined ? value : returnValue;
114
+ });
115
+
116
+ return returnValue !== undefined ? returnValue : $elems;
117
+ }
118
+
119
+ function plainCall( $elems, options ) {
120
+ $elems.each( function( i, elem ) {
121
+ var instance = $.data( elem, namespace );
122
+ if ( instance ) {
123
+ // set options & init
124
+ instance.option( options );
125
+ instance._init();
126
+ } else {
127
+ // initialize new instance
128
+ instance = new PluginClass( elem, options );
129
+ $.data( elem, namespace, instance );
130
+ }
131
+ });
132
+ }
133
+
134
+ updateJQuery( $ );
135
+
136
+ }
137
+
138
+ // ----- updateJQuery ----- //
139
+
140
+ // set $.bridget for v1 backwards compatibility
141
+ function updateJQuery( $ ) {
142
+ if ( !$ || ( $ && $.bridget ) ) {
143
+ return;
144
+ }
145
+ $.bridget = jQueryBridget;
146
+ }
147
+
148
+ updateJQuery( jQuery || window.jQuery );
149
+
150
+ // ----- ----- //
151
+
152
+ return jQueryBridget;
153
+
154
+ }));
155
+
156
+ /**
157
+ * EvEmitter v1.1.0
158
+ * Lil' event emitter
159
+ * MIT License
160
+ */
161
+
162
+ /* jshint unused: true, undef: true, strict: true */
163
+
164
+ ( function( global, factory ) {
165
+ // universal module definition
166
+ /* jshint strict: false */ /* globals define, module, window */
167
+ if ( typeof define == 'function' && define.amd ) {
168
+ // AMD - RequireJS
169
+ define( 'ev-emitter/ev-emitter',factory );
170
+ } else if ( typeof module == 'object' && module.exports ) {
171
+ // CommonJS - Browserify, Webpack
172
+ module.exports = factory();
173
+ } else {
174
+ // Browser globals
175
+ global.EvEmitter = factory();
176
+ }
177
+
178
+ }( typeof window != 'undefined' ? window : this, function() {
179
+
180
+
181
+
182
+ function EvEmitter() {}
183
+
184
+ var proto = EvEmitter.prototype;
185
+
186
+ proto.on = function( eventName, listener ) {
187
+ if ( !eventName || !listener ) {
188
+ return;
189
+ }
190
+ // set events hash
191
+ var events = this._events = this._events || {};
192
+ // set listeners array
193
+ var listeners = events[ eventName ] = events[ eventName ] || [];
194
+ // only add once
195
+ if ( listeners.indexOf( listener ) == -1 ) {
196
+ listeners.push( listener );
197
+ }
198
+
199
+ return this;
200
+ };
201
+
202
+ proto.once = function( eventName, listener ) {
203
+ if ( !eventName || !listener ) {
204
+ return;
205
+ }
206
+ // add event
207
+ this.on( eventName, listener );
208
+ // set once flag
209
+ // set onceEvents hash
210
+ var onceEvents = this._onceEvents = this._onceEvents || {};
211
+ // set onceListeners object
212
+ var onceListeners = onceEvents[ eventName ] = onceEvents[ eventName ] || {};
213
+ // set flag
214
+ onceListeners[ listener ] = true;
215
+
216
+ return this;
217
+ };
218
+
219
+ proto.off = function( eventName, listener ) {
220
+ var listeners = this._events && this._events[ eventName ];
221
+ if ( !listeners || !listeners.length ) {
222
+ return;
223
+ }
224
+ var index = listeners.indexOf( listener );
225
+ if ( index != -1 ) {
226
+ listeners.splice( index, 1 );
227
+ }
228
+
229
+ return this;
230
+ };
231
+
232
+ proto.emitEvent = function( eventName, args ) {
233
+ var listeners = this._events && this._events[ eventName ];
234
+ if ( !listeners || !listeners.length ) {
235
+ return;
236
+ }
237
+ // copy over to avoid interference if .off() in listener
238
+ listeners = listeners.slice(0);
239
+ args = args || [];
240
+ // once stuff
241
+ var onceListeners = this._onceEvents && this._onceEvents[ eventName ];
242
+
243
+ for ( var i=0; i < listeners.length; i++ ) {
244
+ var listener = listeners[i]
245
+ var isOnce = onceListeners && onceListeners[ listener ];
246
+ if ( isOnce ) {
247
+ // remove listener
248
+ // remove before trigger to prevent recursion
249
+ this.off( eventName, listener );
250
+ // unset once flag
251
+ delete onceListeners[ listener ];
252
+ }
253
+ // trigger listener
254
+ listener.apply( this, args );
255
+ }
256
+
257
+ return this;
258
+ };
259
+
260
+ proto.allOff = function() {
261
+ delete this._events;
262
+ delete this._onceEvents;
263
+ };
264
+
265
+ return EvEmitter;
266
+
267
+ }));
268
+
269
+ /**
270
+ * matchesSelector v2.0.2
271
+ * matchesSelector( element, '.selector' )
272
+ * MIT license
273
+ */
274
+
275
+ /*jshint browser: true, strict: true, undef: true, unused: true */
276
+
277
+ ( function( window, factory ) {
278
+ /*global define: false, module: false */
279
+ 'use strict';
280
+ // universal module definition
281
+ if ( typeof define == 'function' && define.amd ) {
282
+ // AMD
283
+ define( 'desandro-matches-selector/matches-selector',factory );
284
+ } else if ( typeof module == 'object' && module.exports ) {
285
+ // CommonJS
286
+ module.exports = factory();
287
+ } else {
288
+ // browser global
289
+ window.matchesSelector = factory();
290
+ }
291
+
292
+ }( window, function factory() {
293
+ 'use strict';
294
+
295
+ var matchesMethod = ( function() {
296
+ var ElemProto = window.Element.prototype;
297
+ // check for the standard method name first
298
+ if ( ElemProto.matches ) {
299
+ return 'matches';
300
+ }
301
+ // check un-prefixed
302
+ if ( ElemProto.matchesSelector ) {
303
+ return 'matchesSelector';
304
+ }
305
+ // check vendor prefixes
306
+ var prefixes = [ 'webkit', 'moz', 'ms', 'o' ];
307
+
308
+ for ( var i=0; i < prefixes.length; i++ ) {
309
+ var prefix = prefixes[i];
310
+ var method = prefix + 'MatchesSelector';
311
+ if ( ElemProto[ method ] ) {
312
+ return method;
313
+ }
314
+ }
315
+ })();
316
+
317
+ return function matchesSelector( elem, selector ) {
318
+ return elem[ matchesMethod ]( selector );
319
+ };
320
+
321
+ }));
322
+
323
+ /**
324
+ * Fizzy UI utils v2.0.7
325
+ * MIT license
326
+ */
327
+
328
+ /*jshint browser: true, undef: true, unused: true, strict: true */
329
+
330
+ ( function( window, factory ) {
331
+ // universal module definition
332
+ /*jshint strict: false */ /*globals define, module, require */
333
+
334
+ if ( typeof define == 'function' && define.amd ) {
335
+ // AMD
336
+ define( 'fizzy-ui-utils/utils',[
337
+ 'desandro-matches-selector/matches-selector'
338
+ ], function( matchesSelector ) {
339
+ return factory( window, matchesSelector );
340
+ });
341
+ } else if ( typeof module == 'object' && module.exports ) {
342
+ // CommonJS
343
+ module.exports = factory(
344
+ window,
345
+ require('desandro-matches-selector')
346
+ );
347
+ } else {
348
+ // browser global
349
+ window.fizzyUIUtils = factory(
350
+ window,
351
+ window.matchesSelector
352
+ );
353
+ }
354
+
355
+ }( window, function factory( window, matchesSelector ) {
356
+
357
+
358
+
359
+ var utils = {};
360
+
361
+ // ----- extend ----- //
362
+
363
+ // extends objects
364
+ utils.extend = function( a, b ) {
365
+ for ( var prop in b ) {
366
+ a[ prop ] = b[ prop ];
367
+ }
368
+ return a;
369
+ };
370
+
371
+ // ----- modulo ----- //
372
+
373
+ utils.modulo = function( num, div ) {
374
+ return ( ( num % div ) + div ) % div;
375
+ };
376
+
377
+ // ----- makeArray ----- //
378
+
379
+ var arraySlice = Array.prototype.slice;
380
+
381
+ // turn element or nodeList into an array
382
+ utils.makeArray = function( obj ) {
383
+ if ( Array.isArray( obj ) ) {
384
+ // use object if already an array
385
+ return obj;
386
+ }
387
+ // return empty array if undefined or null. #6
388
+ if ( obj === null || obj === undefined ) {
389
+ return [];
390
+ }
391
+
392
+ var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number';
393
+ if ( isArrayLike ) {
394
+ // convert nodeList to array
395
+ return arraySlice.call( obj );
396
+ }
397
+
398
+ // array of single index
399
+ return [ obj ];
400
+ };
401
+
402
+ // ----- removeFrom ----- //
403
+
404
+ utils.removeFrom = function( ary, obj ) {
405
+ var index = ary.indexOf( obj );
406
+ if ( index != -1 ) {
407
+ ary.splice( index, 1 );
408
+ }
409
+ };
410
+
411
+ // ----- getParent ----- //
412
+
413
+ utils.getParent = function( elem, selector ) {
414
+ while ( elem.parentNode && elem != document.body ) {
415
+ elem = elem.parentNode;
416
+ if ( matchesSelector( elem, selector ) ) {
417
+ return elem;
418
+ }
419
+ }
420
+ };
421
+
422
+ // ----- getQueryElement ----- //
423
+
424
+ // use element as selector string
425
+ utils.getQueryElement = function( elem ) {
426
+ if ( typeof elem == 'string' ) {
427
+ return document.querySelector( elem );
428
+ }
429
+ return elem;
430
+ };
431
+
432
+ // ----- handleEvent ----- //
433
+
434
+ // enable .ontype to trigger from .addEventListener( elem, 'type' )
435
+ utils.handleEvent = function( event ) {
436
+ var method = 'on' + event.type;
437
+ if ( this[ method ] ) {
438
+ this[ method ]( event );
439
+ }
440
+ };
441
+
442
+ // ----- filterFindElements ----- //
443
+
444
+ utils.filterFindElements = function( elems, selector ) {
445
+ // make array of elems
446
+ elems = utils.makeArray( elems );
447
+ var ffElems = [];
448
+
449
+ elems.forEach( function( elem ) {
450
+ // check that elem is an actual element
451
+ if ( !( elem instanceof HTMLElement ) ) {
452
+ return;
453
+ }
454
+ // add elem if no selector
455
+ if ( !selector ) {
456
+ ffElems.push( elem );
457
+ return;
458
+ }
459
+ // filter & find items if we have a selector
460
+ // filter
461
+ if ( matchesSelector( elem, selector ) ) {
462
+ ffElems.push( elem );
463
+ }
464
+ // find children
465
+ var childElems = elem.querySelectorAll( selector );
466
+ // concat childElems to filterFound array
467
+ for ( var i=0; i < childElems.length; i++ ) {
468
+ ffElems.push( childElems[i] );
469
+ }
470
+ });
471
+
472
+ return ffElems;
473
+ };
474
+
475
+ // ----- debounceMethod ----- //
476
+
477
+ utils.debounceMethod = function( _class, methodName, threshold ) {
478
+ threshold = threshold || 100;
479
+ // original method
480
+ var method = _class.prototype[ methodName ];
481
+ var timeoutName = methodName + 'Timeout';
482
+
483
+ _class.prototype[ methodName ] = function() {
484
+ var timeout = this[ timeoutName ];
485
+ clearTimeout( timeout );
486
+
487
+ var args = arguments;
488
+ var _this = this;
489
+ this[ timeoutName ] = setTimeout( function() {
490
+ method.apply( _this, args );
491
+ delete _this[ timeoutName ];
492
+ }, threshold );
493
+ };
494
+ };
495
+
496
+ // ----- docReady ----- //
497
+
498
+ utils.docReady = function( callback ) {
499
+ var readyState = document.readyState;
500
+ if ( readyState == 'complete' || readyState == 'interactive' ) {
501
+ // do async to allow for other scripts to run. metafizzy/flickity#441
502
+ setTimeout( callback );
503
+ } else {
504
+ document.addEventListener( 'DOMContentLoaded', callback );
505
+ }
506
+ };
507
+
508
+ // ----- htmlInit ----- //
509
+
510
+ // http://jamesroberts.name/blog/2010/02/22/string-functions-for-javascript-trim-to-camel-case-to-dashed-and-to-underscore/
511
+ utils.toDashed = function( str ) {
512
+ return str.replace( /(.)([A-Z])/g, function( match, $1, $2 ) {
513
+ return $1 + '-' + $2;
514
+ }).toLowerCase();
515
+ };
516
+
517
+ var console = window.console;
518
+ /**
519
+ * allow user to initialize classes via [data-namespace] or .js-namespace class
520
+ * htmlInit( Widget, 'widgetName' )
521
+ * options are parsed from data-namespace-options
522
+ */
523
+ utils.htmlInit = function( WidgetClass, namespace ) {
524
+ utils.docReady( function() {
525
+ var dashedNamespace = utils.toDashed( namespace );
526
+ var dataAttr = 'data-' + dashedNamespace;
527
+ var dataAttrElems = document.querySelectorAll( '[' + dataAttr + ']' );
528
+ var jsDashElems = document.querySelectorAll( '.js-' + dashedNamespace );
529
+ var elems = utils.makeArray( dataAttrElems )
530
+ .concat( utils.makeArray( jsDashElems ) );
531
+ var dataOptionsAttr = dataAttr + '-options';
532
+ var jQuery = window.jQuery;
533
+
534
+ elems.forEach( function( elem ) {
535
+ var attr = elem.getAttribute( dataAttr ) ||
536
+ elem.getAttribute( dataOptionsAttr );
537
+ var options;
538
+ try {
539
+ options = attr && JSON.parse( attr );
540
+ } catch ( error ) {
541
+ // log error, do not initialize
542
+ if ( console ) {
543
+ console.error( 'Error parsing ' + dataAttr + ' on ' + elem.className +
544
+ ': ' + error );
545
+ }
546
+ return;
547
+ }
548
+ // initialize
549
+ var instance = new WidgetClass( elem, options );
550
+ // make available via $().data('namespace')
551
+ if ( jQuery ) {
552
+ jQuery.data( elem, namespace, instance );
553
+ }
554
+ });
555
+
556
+ });
557
+ };
558
+
559
+ // ----- ----- //
560
+
561
+ return utils;
562
+
563
+ }));
564
+
565
+ // core
566
+ ( function( window, factory ) {
567
+ // universal module definition
568
+ /* globals define, module, require */
569
+ if ( typeof define == 'function' && define.amd ) {
570
+ // AMD
571
+ define( 'infinite-scroll/js/core',[
572
+ 'ev-emitter/ev-emitter',
573
+ 'fizzy-ui-utils/utils',
574
+ ], function( EvEmitter, utils) {
575
+ return factory( window, EvEmitter, utils );
576
+ });
577
+ } else if ( typeof module == 'object' && module.exports ) {
578
+ // CommonJS
579
+ module.exports = factory(
580
+ window,
581
+ require('ev-emitter'),
582
+ require('fizzy-ui-utils')
583
+ );
584
+ } else {
585
+ // browser global
586
+ window.InfiniteScroll = factory(
587
+ window,
588
+ window.EvEmitter,
589
+ window.fizzyUIUtils
590
+ );
591
+ }
592
+
593
+ }( window, function factory( window, EvEmitter, utils ) {
594
+
595
+ var jQuery = window.jQuery;
596
+ // internal store of all InfiniteScroll intances
597
+ var instances = {};
598
+
599
+ function InfiniteScroll( element, options ) {
600
+ var queryElem = utils.getQueryElement( element );
601
+
602
+ if ( !queryElem ) {
603
+ console.error( 'Bad element for InfiniteScroll: ' + ( queryElem || element ) );
604
+ return;
605
+ }
606
+ element = queryElem;
607
+ // do not initialize twice on same element
608
+ if ( element.infiniteScrollGUID ) {
609
+ var instance = instances[ element.infiniteScrollGUID ];
610
+ instance.option( options );
611
+ return instance;
612
+ }
613
+
614
+ this.element = element;
615
+ // options
616
+ this.options = utils.extend( {}, InfiniteScroll.defaults );
617
+ this.option( options );
618
+ // add jQuery
619
+ if ( jQuery ) {
620
+ this.$element = jQuery( this.element );
621
+ }
622
+
623
+ this.create();
624
+ }
625
+
626
+ // defaults
627
+ InfiniteScroll.defaults = {
628
+ // path: null,
629
+ // hideNav: null,
630
+ // debug: false,
631
+ };
632
+
633
+ // create & destroy methods
634
+ InfiniteScroll.create = {};
635
+ InfiniteScroll.destroy = {};
636
+
637
+ var proto = InfiniteScroll.prototype;
638
+ // inherit EvEmitter
639
+ utils.extend( proto, EvEmitter.prototype );
640
+
641
+ // -------------------------- -------------------------- //
642
+
643
+ // globally unique identifiers
644
+ var GUID = 0;
645
+
646
+ proto.create = function() {
647
+ // create core
648
+ // add id for InfiniteScroll.data
649
+ var id = this.guid = ++GUID;
650
+ this.element.infiniteScrollGUID = id; // expando
651
+ instances[ id ] = this; // associate via id
652
+ // properties
653
+ this.pageIndex = 1; // default to first page
654
+ this.loadCount = 0;
655
+ this.updateGetPath();
656
+ // bail if getPath not set, or returns falsey #776
657
+ var hasPath = this.getPath && this.getPath();
658
+ if ( !hasPath ) {
659
+ console.error('Disabling InfiniteScroll');
660
+ return;
661
+ }
662
+ this.updateGetAbsolutePath();
663
+ this.log( 'initialized', [ this.element.className ] );
664
+ this.callOnInit();
665
+ // create features
666
+ for ( var method in InfiniteScroll.create ) {
667
+ InfiniteScroll.create[ method ].call( this );
668
+ }
669
+ };
670
+
671
+ proto.option = function( opts ) {
672
+ utils.extend( this.options, opts );
673
+ };
674
+
675
+ // call onInit option, used for binding events on init
676
+ proto.callOnInit = function() {
677
+ var onInit = this.options.onInit;
678
+ if ( onInit ) {
679
+ onInit.call( this, this );
680
+ }
681
+ };
682
+
683
+ // ----- events ----- //
684
+
685
+ proto.dispatchEvent = function( type, event, args ) {
686
+ this.log( type, args );
687
+ var emitArgs = event ? [ event ].concat( args ) : args;
688
+ this.emitEvent( type, emitArgs );
689
+ // trigger jQuery event
690
+ if ( !jQuery || !this.$element ) {
691
+ return;
692
+ }
693
+ // namespace jQuery event
694
+ type += '.infiniteScroll';
695
+ var $event = type;
696
+ if ( event ) {
697
+ // create jQuery event
698
+ var jQEvent = jQuery.Event( event );
699
+ jQEvent.type = type;
700
+ $event = jQEvent;
701
+ }
702
+ this.$element.trigger( $event, args );
703
+ };
704
+
705
+ var loggers = {
706
+ initialized: function( className ) {
707
+ return 'on ' + className;
708
+ },
709
+ request: function( path ) {
710
+ return 'URL: ' + path;
711
+ },
712
+ load: function( response, path ) {
713
+ return ( response.title || '' ) + '. URL: ' + path;
714
+ },
715
+ error: function( error, path ) {
716
+ return error + '. URL: ' + path;
717
+ },
718
+ append: function( response, path, items ) {
719
+ return items.length + ' items. URL: ' + path;
720
+ },
721
+ last: function( response, path ) {
722
+ return 'URL: ' + path;
723
+ },
724
+ history: function( title, path ) {
725
+ return 'URL: ' + path;
726
+ },
727
+ pageIndex: function( index, origin ) {
728
+ return 'current page determined to be: ' + index + ' from ' + origin;
729
+ },
730
+ };
731
+
732
+ // log events
733
+ proto.log = function( type, args ) {
734
+ if ( !this.options.debug ) {
735
+ return;
736
+ }
737
+ var message = '[InfiniteScroll] ' + type;
738
+ var logger = loggers[ type ];
739
+ if ( logger ) {
740
+ message += '. ' + logger.apply( this, args );
741
+ }
742
+ console.log( message );
743
+ };
744
+
745
+ // -------------------------- methods used amoung features -------------------------- //
746
+
747
+ proto.updateMeasurements = function() {
748
+ this.windowHeight = window.innerHeight;
749
+ var rect = this.element.getBoundingClientRect();
750
+ this.top = rect.top + window.pageYOffset;
751
+ };
752
+
753
+ proto.updateScroller = function() {
754
+ var elementScroll = this.options.elementScroll;
755
+ if ( !elementScroll ) {
756
+ // default, use window
757
+ this.scroller = window;
758
+ return;
759
+ }
760
+ // if true, set to element, otherwise use option
761
+ this.scroller = elementScroll === true ? this.element :
762
+ utils.getQueryElement( elementScroll );
763
+ if ( !this.scroller ) {
764
+ throw 'Unable to find elementScroll: ' + elementScroll;
765
+ }
766
+ };
767
+
768
+ // -------------------------- page path -------------------------- //
769
+
770
+ proto.updateGetPath = function() {
771
+ var optPath = this.options.path;
772
+ if ( !optPath ) {
773
+ console.error( 'InfiniteScroll path option required. Set as: ' + optPath );
774
+ return;
775
+ }
776
+ // function
777
+ var type = typeof optPath;
778
+ if ( type == 'function' ) {
779
+ this.getPath = optPath;
780
+ return;
781
+ }
782
+ // template string: '/pages/{{#}}.html'
783
+ var templateMatch = type == 'string' && optPath.match('{{#}}');
784
+ if ( templateMatch ) {
785
+ this.updateGetPathTemplate( optPath );
786
+ return;
787
+ }
788
+ // selector: '.next-page-selector'
789
+ this.updateGetPathSelector( optPath );
790
+ };
791
+
792
+ proto.updateGetPathTemplate = function( optPath ) {
793
+ // set getPath with template string
794
+ this.getPath = function() {
795
+ var nextIndex = this.pageIndex + 1;
796
+ return optPath.replace( '{{#}}', nextIndex );
797
+ }.bind( this );
798
+ // get pageIndex from location
799
+ // convert path option into regex to look for pattern in location
800
+ var regexString = optPath.replace( '{{#}}', '(\\d\\d?\\d?)' );
801
+ var templateRe = new RegExp( regexString );
802
+ var match = location.href.match( templateRe );
803
+ if ( match ) {
804
+ this.pageIndex = parseInt( match[1], 10 );
805
+ this.log( 'pageIndex', [ this.pageIndex, 'template string' ] );
806
+ }
807
+ };
808
+
809
+ var pathRegexes = [
810
+ // WordPress & Tumblr - example.com/page/2
811
+ // Jekyll - example.com/page2
812
+ /^(.*?\/?page\/?)(\d\d?\d?)(.*?$)/,
813
+ // Drupal - example.com/?page=1
814
+ /^(.*?\/?\?page=)(\d\d?\d?)(.*?$)/,
815
+ // catch all, last occurence of a number
816
+ /(.*?)(\d\d?\d?)(?!.*\d)(.*?$)/,
817
+ ];
818
+
819
+ proto.updateGetPathSelector = function( optPath ) {
820
+ // parse href of link: '.next-page-link'
821
+ var hrefElem = document.querySelector( optPath );
822
+ if ( !hrefElem ) {
823
+ console.error( 'Bad InfiniteScroll path option. Next link not found: ' +
824
+ optPath );
825
+ return;
826
+ }
827
+ var href = hrefElem.getAttribute('href');
828
+ // try matching href to pathRegexes patterns
829
+ var pathParts, regex;
830
+ for ( var i=0; href && i < pathRegexes.length; i++ ) {
831
+ regex = pathRegexes[i];
832
+ var match = href.match( regex );
833
+ if ( match ) {
834
+ pathParts = match.slice(1); // remove first part
835
+ break;
836
+ }
837
+ }
838
+ if ( !pathParts ) {
839
+ console.error( 'InfiniteScroll unable to parse next link href: ' + href );
840
+ return;
841
+ }
842
+ this.isPathSelector = true; // flag for checkLastPage()
843
+ this.getPath = function() {
844
+ var nextIndex = this.pageIndex + 1;
845
+ return pathParts[0] + nextIndex + pathParts[2];
846
+ }.bind( this );
847
+ // get pageIndex from href
848
+ this.pageIndex = parseInt( pathParts[1], 10 ) - 1;
849
+ this.log( 'pageIndex', [ this.pageIndex, 'next link' ] );
850
+ };
851
+
852
+ proto.updateGetAbsolutePath = function() {
853
+ var path = this.getPath();
854
+ // path doesn't start with http or /
855
+ var isAbsolute = path.match( /^http/ ) || path.match( /^\// );
856
+ if ( isAbsolute ) {
857
+ this.getAbsolutePath = this.getPath;
858
+ return;
859
+ }
860
+
861
+ var pathname = location.pathname;
862
+ // /foo/bar/index.html => /foo/bar
863
+ var directory = pathname.substring( 0, pathname.lastIndexOf('/') );
864
+
865
+ this.getAbsolutePath = function() {
866
+ return directory + '/' + this.getPath();
867
+ };
868
+ };
869
+
870
+ // -------------------------- nav -------------------------- //
871
+
872
+ // hide navigation
873
+ InfiniteScroll.create.hideNav = function() {
874
+ var nav = utils.getQueryElement( this.options.hideNav );
875
+ if ( !nav ) {
876
+ return;
877
+ }
878
+ nav.style.display = 'none';
879
+ this.nav = nav;
880
+ };
881
+
882
+ InfiniteScroll.destroy.hideNav = function() {
883
+ if ( this.nav ) {
884
+ this.nav.style.display = '';
885
+ }
886
+ };
887
+
888
+ // -------------------------- destroy -------------------------- //
889
+
890
+ proto.destroy = function() {
891
+ this.allOff(); // remove all event listeners
892
+ // call destroy methods
893
+ for ( var method in InfiniteScroll.destroy ) {
894
+ InfiniteScroll.destroy[ method ].call( this );
895
+ }
896
+
897
+ delete this.element.infiniteScrollGUID;
898
+ delete instances[ this.guid ];
899
+ // remove jQuery data. #807
900
+ if ( jQuery && this.$element ) {
901
+ jQuery.removeData( this.element, 'infiniteScroll' );
902
+ }
903
+ };
904
+
905
+ // -------------------------- utilities -------------------------- //
906
+
907
+ // https://remysharp.com/2010/07/21/throttling-function-calls
908
+ InfiniteScroll.throttle = function( fn, threshold ) {
909
+ threshold = threshold || 200;
910
+ var last, timeout;
911
+
912
+ return function() {
913
+ var now = +new Date();
914
+ var args = arguments;
915
+ var trigger = function() {
916
+ last = now;
917
+ fn.apply( this, args );
918
+ }.bind( this );
919
+ if ( last && now < last + threshold ) {
920
+ // hold on to it
921
+ clearTimeout( timeout );
922
+ timeout = setTimeout( trigger, threshold );
923
+ } else {
924
+ trigger();
925
+ }
926
+ };
927
+ };
928
+
929
+ InfiniteScroll.data = function( elem ) {
930
+ elem = utils.getQueryElement( elem );
931
+ var id = elem && elem.infiniteScrollGUID;
932
+ return id && instances[ id ];
933
+ };
934
+
935
+ // set internal jQuery, for Webpack + jQuery v3
936
+ InfiniteScroll.setJQuery = function( $ ) {
937
+ jQuery = $;
938
+ };
939
+
940
+ // -------------------------- setup -------------------------- //
941
+
942
+ utils.htmlInit( InfiniteScroll, 'infinite-scroll' );
943
+
944
+ // add noop _init method for jQuery Bridget. #768
945
+ proto._init = function() {};
946
+
947
+ if ( jQuery && jQuery.bridget ) {
948
+ jQuery.bridget( 'infiniteScroll', InfiniteScroll );
949
+ }
950
+
951
+ // -------------------------- -------------------------- //
952
+
953
+ return InfiniteScroll;
954
+
955
+ }));
956
+
957
+ // page-load
958
+ ( function( window, factory ) {
959
+ // universal module definition
960
+ /* globals define, module, require */
961
+ if ( typeof define == 'function' && define.amd ) {
962
+ // AMD
963
+ define( 'infinite-scroll/js/page-load',[
964
+ './core',
965
+ ], function( InfiniteScroll ) {
966
+ return factory( window, InfiniteScroll );
967
+ });
968
+ } else if ( typeof module == 'object' && module.exports ) {
969
+ // CommonJS
970
+ module.exports = factory(
971
+ window,
972
+ require('./core')
973
+ );
974
+ } else {
975
+ // browser global
976
+ factory(
977
+ window,
978
+ window.InfiniteScroll
979
+ );
980
+ }
981
+
982
+ }( window, function factory( window, InfiniteScroll ) {
983
+
984
+ var proto = InfiniteScroll.prototype;
985
+
986
+ // InfiniteScroll.defaults.append = false;
987
+ InfiniteScroll.defaults.loadOnScroll = true;
988
+ InfiniteScroll.defaults.checkLastPage = true;
989
+ InfiniteScroll.defaults.responseType = 'document';
990
+ // InfiniteScroll.defaults.prefill = false;
991
+ // InfiniteScroll.defaults.outlayer = null;
992
+
993
+ InfiniteScroll.create.pageLoad = function() {
994
+ this.canLoad = true;
995
+ this.on( 'scrollThreshold', this.onScrollThresholdLoad );
996
+ this.on( 'load', this.checkLastPage );
997
+ if ( this.options.outlayer ) {
998
+ this.on( 'append', this.onAppendOutlayer );
999
+ }
1000
+ };
1001
+
1002
+ proto.onScrollThresholdLoad = function() {
1003
+ if ( this.options.loadOnScroll ) {
1004
+ this.loadNextPage();
1005
+ }
1006
+ };
1007
+
1008
+ proto.loadNextPage = function() {
1009
+ if ( this.isLoading || !this.canLoad ) {
1010
+ return;
1011
+ }
1012
+
1013
+ var path = this.getAbsolutePath();
1014
+ this.isLoading = true;
1015
+
1016
+ var onLoad = function( response ) {
1017
+ this.onPageLoad( response, path );
1018
+ }.bind( this );
1019
+
1020
+ var onError = function( error ) {
1021
+ this.onPageError( error, path );
1022
+ }.bind( this );
1023
+
1024
+ request( path, this.options.responseType, onLoad, onError );
1025
+ this.dispatchEvent( 'request', null, [ path ] );
1026
+ };
1027
+
1028
+ proto.onPageLoad = function( response, path ) {
1029
+ // done loading if not appending
1030
+ if ( !this.options.append ) {
1031
+ this.isLoading = false;
1032
+ }
1033
+ this.pageIndex++;
1034
+ this.loadCount++;
1035
+ this.dispatchEvent( 'load', null, [ response, path ] );
1036
+ this.appendNextPage( response, path );
1037
+ return response;
1038
+ };
1039
+
1040
+ proto.appendNextPage = function( response, path ) {
1041
+ var optAppend = this.options.append;
1042
+ // do not append json
1043
+ var isDocument = this.options.responseType == 'document';
1044
+ if ( !isDocument || !optAppend ) {
1045
+ return;
1046
+ }
1047
+
1048
+ var items = response.querySelectorAll( optAppend );
1049
+ var fragment = getItemsFragment( items );
1050
+ var appendReady = function () {
1051
+ this.appendItems( items, fragment );
1052
+ this.isLoading = false;
1053
+ this.dispatchEvent( 'append', null, [ response, path, items ] );
1054
+ }.bind( this );
1055
+
1056
+ // TODO add hook for option to trigger appendReady
1057
+ if ( this.options.outlayer ) {
1058
+ this.appendOutlayerItems( fragment, appendReady );
1059
+ } else {
1060
+ appendReady();
1061
+ }
1062
+ };
1063
+
1064
+ proto.appendItems = function( items, fragment ) {
1065
+ if ( !items || !items.length ) {
1066
+ return;
1067
+ }
1068
+ // get fragment if not provided
1069
+ fragment = fragment || getItemsFragment( items );
1070
+ refreshScripts( fragment );
1071
+ this.element.appendChild( fragment );
1072
+ };
1073
+
1074
+ function getItemsFragment( items ) {
1075
+ // add items to fragment
1076
+ var fragment = document.createDocumentFragment();
1077
+ for ( var i=0; items && i < items.length; i++ ) {
1078
+ fragment.appendChild( items[i] );
1079
+ }
1080
+ return fragment;
1081
+ }
1082
+
1083
+ // replace <script>s with copies so they load
1084
+ // <script>s added by InfiniteScroll will not load
1085
+ // similar to https://stackoverflow.com/questions/610995
1086
+ function refreshScripts( fragment ) {
1087
+ var scripts = fragment.querySelectorAll('script');
1088
+ for ( var i=0; i < scripts.length; i++ ) {
1089
+ var script = scripts[i];
1090
+ var freshScript = document.createElement('script');
1091
+ copyAttributes( script, freshScript );
1092
+ // copy inner script code. #718, #782
1093
+ freshScript.innerHTML = script.innerHTML;
1094
+ script.parentNode.replaceChild( freshScript, script );
1095
+ }
1096
+ }
1097
+
1098
+ function copyAttributes( fromNode, toNode ) {
1099
+ var attrs = fromNode.attributes;
1100
+ for ( var i=0; i < attrs.length; i++ ) {
1101
+ var attr = attrs[i];
1102
+ toNode.setAttribute( attr.name, attr.value );
1103
+ }
1104
+ }
1105
+
1106
+ // ----- outlayer ----- //
1107
+
1108
+ proto.appendOutlayerItems = function( fragment, appendReady ) {
1109
+ var imagesLoaded = InfiniteScroll.imagesLoaded || window.imagesLoaded;
1110
+ if ( !imagesLoaded ) {
1111
+ console.error('[InfiniteScroll] imagesLoaded required for outlayer option');
1112
+ this.isLoading = false;
1113
+ return;
1114
+ }
1115
+ // append once images loaded
1116
+ imagesLoaded( fragment, appendReady );
1117
+ };
1118
+
1119
+ proto.onAppendOutlayer = function( response, path, items ) {
1120
+ this.options.outlayer.appended( items );
1121
+ };
1122
+
1123
+ // ----- checkLastPage ----- //
1124
+
1125
+ // check response for next element
1126
+ proto.checkLastPage = function( response, path ) {
1127
+ var checkLastPage = this.options.checkLastPage;
1128
+ if ( !checkLastPage ) {
1129
+ return;
1130
+ }
1131
+
1132
+ var pathOpt = this.options.path;
1133
+ // if path is function, check if next path is truthy
1134
+ if ( typeof pathOpt == 'function' ) {
1135
+ var nextPath = this.getPath();
1136
+ if ( !nextPath ) {
1137
+ this.lastPageReached( response, path );
1138
+ return;
1139
+ }
1140
+ }
1141
+ // get selector from checkLastPage or path option
1142
+ var selector;
1143
+ if ( typeof checkLastPage == 'string' ) {
1144
+ selector = checkLastPage;
1145
+ } else if ( this.isPathSelector ) {
1146
+ // path option is selector string
1147
+ selector = pathOpt;
1148
+ }
1149
+ // check last page for selector
1150
+ // bail if no selector or not document response
1151
+ if ( !selector || !response.querySelector ) {
1152
+ return;
1153
+ }
1154
+ // check if response has selector
1155
+ var nextElem = response.querySelector( selector );
1156
+ if ( !nextElem ) {
1157
+ this.lastPageReached( response, path );
1158
+ }
1159
+ };
1160
+
1161
+ proto.lastPageReached = function( response, path ) {
1162
+ this.canLoad = false;
1163
+ this.dispatchEvent( 'last', null, [ response, path ] );
1164
+ };
1165
+
1166
+ // ----- error ----- //
1167
+
1168
+ proto.onPageError = function( error, path ) {
1169
+ this.isLoading = false;
1170
+ this.canLoad = false;
1171
+ this.dispatchEvent( 'error', null, [ error, path ] );
1172
+ return error;
1173
+ };
1174
+
1175
+ // -------------------------- prefill -------------------------- //
1176
+
1177
+ InfiniteScroll.create.prefill = function() {
1178
+ if ( !this.options.prefill ) {
1179
+ return;
1180
+ }
1181
+ var append = this.options.append;
1182
+ if ( !append ) {
1183
+ console.error( 'append option required for prefill. Set as :' + append );
1184
+ return;
1185
+ }
1186
+ this.updateMeasurements();
1187
+ this.updateScroller();
1188
+ this.isPrefilling = true;
1189
+ this.on( 'append', this.prefill );
1190
+ this.once( 'error', this.stopPrefill );
1191
+ this.once( 'last', this.stopPrefill );
1192
+ this.prefill();
1193
+ };
1194
+
1195
+ proto.prefill = function() {
1196
+ var distance = this.getPrefillDistance();
1197
+ this.isPrefilling = distance >= 0;
1198
+ if ( this.isPrefilling ) {
1199
+ this.log('prefill');
1200
+ this.loadNextPage();
1201
+ } else {
1202
+ this.stopPrefill();
1203
+ }
1204
+ };
1205
+
1206
+ proto.getPrefillDistance = function() {
1207
+ // element scroll
1208
+ if ( this.options.elementScroll ) {
1209
+ return this.scroller.clientHeight - this.scroller.scrollHeight;
1210
+ }
1211
+ // window
1212
+ return this.windowHeight - this.element.clientHeight;
1213
+ };
1214
+
1215
+ proto.stopPrefill = function() {
1216
+ this.log('stopPrefill');
1217
+ this.off( 'append', this.prefill );
1218
+ };
1219
+
1220
+ // -------------------------- request -------------------------- //
1221
+
1222
+ function request( url, responseType, onLoad, onError ) {
1223
+ var req = new XMLHttpRequest();
1224
+ req.open( 'GET', url, true );
1225
+ // set responseType document to return DOM
1226
+ req.responseType = responseType || '';
1227
+
1228
+ // set X-Requested-With header to check that is ajax request
1229
+ req.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
1230
+
1231
+ req.onload = function() {
1232
+ if ( req.status == 200 ) {
1233
+ onLoad( req.response );
1234
+ } else {
1235
+ // not 200 OK, error
1236
+ var error = new Error( req.statusText );
1237
+ onError( error );
1238
+ }
1239
+ };
1240
+
1241
+ // Handle network errors
1242
+ req.onerror = function() {
1243
+ var error = new Error( 'Network error requesting ' + url );
1244
+ onError( error );
1245
+ };
1246
+
1247
+ req.send();
1248
+ }
1249
+
1250
+ // -------------------------- -------------------------- //
1251
+
1252
+ return InfiniteScroll;
1253
+
1254
+ }));
1255
+
1256
+ // scroll-watch
1257
+ ( function( window, factory ) {
1258
+ // universal module definition
1259
+ /* globals define, module, require */
1260
+ if ( typeof define == 'function' && define.amd ) {
1261
+ // AMD
1262
+ define( 'infinite-scroll/js/scroll-watch',[
1263
+ './core',
1264
+ 'fizzy-ui-utils/utils',
1265
+ ], function( InfiniteScroll, utils ) {
1266
+ return factory( window, InfiniteScroll, utils );
1267
+ });
1268
+ } else if ( typeof module == 'object' && module.exports ) {
1269
+ // CommonJS
1270
+ module.exports = factory(
1271
+ window,
1272
+ require('./core'),
1273
+ require('fizzy-ui-utils')
1274
+ );
1275
+ } else {
1276
+ // browser global
1277
+ factory(
1278
+ window,
1279
+ window.InfiniteScroll,
1280
+ window.fizzyUIUtils
1281
+ );
1282
+ }
1283
+
1284
+ }( window, function factory( window, InfiniteScroll, utils ) {
1285
+
1286
+ var proto = InfiniteScroll.prototype;
1287
+
1288
+ // default options
1289
+ InfiniteScroll.defaults.scrollThreshold = 400;
1290
+ // InfiniteScroll.defaults.elementScroll = null;
1291
+
1292
+ InfiniteScroll.create.scrollWatch = function() {
1293
+ // events
1294
+ this.pageScrollHandler = this.onPageScroll.bind( this );
1295
+ this.resizeHandler = this.onResize.bind( this );
1296
+
1297
+ var scrollThreshold = this.options.scrollThreshold;
1298
+ var isEnable = scrollThreshold || scrollThreshold === 0;
1299
+ if ( isEnable ) {
1300
+ this.enableScrollWatch();
1301
+ }
1302
+ };
1303
+
1304
+ InfiniteScroll.destroy.scrollWatch = function() {
1305
+ this.disableScrollWatch();
1306
+ };
1307
+
1308
+ proto.enableScrollWatch = function() {
1309
+ if ( this.isScrollWatching ) {
1310
+ return;
1311
+ }
1312
+ this.isScrollWatching = true;
1313
+ this.updateMeasurements();
1314
+ this.updateScroller();
1315
+ // TODO disable after error?
1316
+ this.on( 'last', this.disableScrollWatch );
1317
+ this.bindScrollWatchEvents( true );
1318
+ };
1319
+
1320
+ proto.disableScrollWatch = function() {
1321
+ if ( !this.isScrollWatching ) {
1322
+ return;
1323
+ }
1324
+ this.bindScrollWatchEvents( false );
1325
+ delete this.isScrollWatching;
1326
+ };
1327
+
1328
+ proto.bindScrollWatchEvents = function( isBind ) {
1329
+ var addRemove = isBind ? 'addEventListener' : 'removeEventListener';
1330
+ this.scroller[ addRemove ]( 'scroll', this.pageScrollHandler );
1331
+ window[ addRemove ]( 'resize', this.resizeHandler );
1332
+ };
1333
+
1334
+ proto.onPageScroll = InfiniteScroll.throttle( function() {
1335
+ var distance = this.getBottomDistance();
1336
+ if ( distance <= this.options.scrollThreshold ) {
1337
+ this.dispatchEvent('scrollThreshold');
1338
+ }
1339
+ });
1340
+
1341
+ proto.getBottomDistance = function() {
1342
+ if ( this.options.elementScroll ) {
1343
+ return this.getElementBottomDistance();
1344
+ } else {
1345
+ return this.getWindowBottomDistance();
1346
+ }
1347
+ };
1348
+
1349
+ proto.getWindowBottomDistance = function() {
1350
+ var bottom = this.top + this.element.clientHeight;
1351
+ var scrollY = window.pageYOffset + this.windowHeight;
1352
+ return bottom - scrollY;
1353
+ };
1354
+
1355
+ proto.getElementBottomDistance = function() {
1356
+ var bottom = this.scroller.scrollHeight;
1357
+ var scrollY = this.scroller.scrollTop + this.scroller.clientHeight;
1358
+ return bottom - scrollY;
1359
+ };
1360
+
1361
+ proto.onResize = function() {
1362
+ this.updateMeasurements();
1363
+ };
1364
+
1365
+ utils.debounceMethod( InfiniteScroll, 'onResize', 150 );
1366
+
1367
+ // -------------------------- -------------------------- //
1368
+
1369
+ return InfiniteScroll;
1370
+
1371
+ }));
1372
+
1373
+ // history
1374
+ ( function( window, factory ) {
1375
+ // universal module definition
1376
+ /* globals define, module, require */
1377
+ if ( typeof define == 'function' && define.amd ) {
1378
+ // AMD
1379
+ define( 'infinite-scroll/js/history',[
1380
+ './core',
1381
+ 'fizzy-ui-utils/utils',
1382
+ ], function( InfiniteScroll, utils ) {
1383
+ return factory( window, InfiniteScroll, utils );
1384
+ });
1385
+ } else if ( typeof module == 'object' && module.exports ) {
1386
+ // CommonJS
1387
+ module.exports = factory(
1388
+ window,
1389
+ require('./core'),
1390
+ require('fizzy-ui-utils')
1391
+ );
1392
+ } else {
1393
+ // browser global
1394
+ factory(
1395
+ window,
1396
+ window.InfiniteScroll,
1397
+ window.fizzyUIUtils
1398
+ );
1399
+ }
1400
+
1401
+ }( window, function factory( window, InfiniteScroll, utils ) {
1402
+
1403
+ var proto = InfiniteScroll.prototype;
1404
+
1405
+ InfiniteScroll.defaults.history = 'replace';
1406
+ // InfiniteScroll.defaults.historyTitle = false;
1407
+
1408
+ var link = document.createElement('a');
1409
+
1410
+ // ----- create/destroy ----- //
1411
+
1412
+ InfiniteScroll.create.history = function() {
1413
+ if ( !this.options.history ) {
1414
+ return;
1415
+ }
1416
+ // check for same origin
1417
+ link.href = this.getAbsolutePath();
1418
+ // MS Edge does not have origin on link https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/12236493/
1419
+ var linkOrigin = link.origin || link.protocol + '//' + link.host;
1420
+ var isSameOrigin = linkOrigin == location.origin;
1421
+ if ( !isSameOrigin ) {
1422
+ console.error( '[InfiniteScroll] cannot set history with different origin: ' +
1423
+ link.origin + ' on ' + location.origin +
1424
+ ' . History behavior disabled.' );
1425
+ return;
1426
+ }
1427
+
1428
+ // two ways to handle changing history
1429
+ if ( this.options.append ) {
1430
+ this.createHistoryAppend();
1431
+ } else {
1432
+ this.createHistoryPageLoad();
1433
+ }
1434
+ };
1435
+
1436
+ proto.createHistoryAppend = function() {
1437
+ this.updateMeasurements();
1438
+ this.updateScroller();
1439
+ // array of scroll positions of appended pages
1440
+ this.scrollPages = [
1441
+ {
1442
+ // first page
1443
+ top: 0,
1444
+ path: location.href,
1445
+ title: document.title,
1446
+ }
1447
+ ];
1448
+ this.scrollPageIndex = 0;
1449
+ // events
1450
+ this.scrollHistoryHandler = this.onScrollHistory.bind( this );
1451
+ this.unloadHandler = this.onUnload.bind( this );
1452
+ this.scroller.addEventListener( 'scroll', this.scrollHistoryHandler );
1453
+ this.on( 'append', this.onAppendHistory );
1454
+ this.bindHistoryAppendEvents( true );
1455
+ };
1456
+
1457
+ proto.bindHistoryAppendEvents = function( isBind ) {
1458
+ var addRemove = isBind ? 'addEventListener' : 'removeEventListener';
1459
+ this.scroller[ addRemove ]( 'scroll', this.scrollHistoryHandler );
1460
+ window[ addRemove ]( 'unload', this.unloadHandler );
1461
+ };
1462
+
1463
+ proto.createHistoryPageLoad = function() {
1464
+ this.on( 'load', this.onPageLoadHistory );
1465
+ };
1466
+
1467
+ InfiniteScroll.destroy.history =
1468
+ proto.destroyHistory = function() {
1469
+ var isHistoryAppend = this.options.history && this.options.append;
1470
+ if ( isHistoryAppend ) {
1471
+ this.bindHistoryAppendEvents( false );
1472
+ }
1473
+ };
1474
+
1475
+ // ----- append history ----- //
1476
+
1477
+ proto.onAppendHistory = function( response, path, items ) {
1478
+ // do not proceed if no items. #779
1479
+ if ( !items || !items.length ) {
1480
+ return;
1481
+ }
1482
+ var firstItem = items[0];
1483
+ var elemScrollY = this.getElementScrollY( firstItem );
1484
+ // resolve path
1485
+ link.href = path;
1486
+ // add page data to hash
1487
+ this.scrollPages.push({
1488
+ top: elemScrollY,
1489
+ path: link.href,
1490
+ title: response.title,
1491
+ });
1492
+ };
1493
+
1494
+ proto.getElementScrollY = function( elem ) {
1495
+ if ( this.options.elementScroll ) {
1496
+ return this.getElementElementScrollY( elem );
1497
+ } else {
1498
+ return this.getElementWindowScrollY( elem );
1499
+ }
1500
+ };
1501
+
1502
+ proto.getElementWindowScrollY = function( elem ) {
1503
+ var rect = elem.getBoundingClientRect();
1504
+ return rect.top + window.pageYOffset;
1505
+ };
1506
+
1507
+ // wow, stupid name
1508
+ proto.getElementElementScrollY = function( elem ) {
1509
+ return elem.offsetTop - this.top;
1510
+ };
1511
+
1512
+ proto.onScrollHistory = function() {
1513
+ // cycle through positions, find biggest without going over
1514
+ var scrollViewY = this.getScrollViewY();
1515
+ var pageIndex, page;
1516
+ for ( var i=0; i < this.scrollPages.length; i++ ) {
1517
+ var scrollPage = this.scrollPages[i];
1518
+ if ( scrollPage.top >= scrollViewY ) {
1519
+ break;
1520
+ }
1521
+ pageIndex = i;
1522
+ page = scrollPage;
1523
+ }
1524
+ // set history if changed
1525
+ if ( pageIndex != this.scrollPageIndex ) {
1526
+ this.scrollPageIndex = pageIndex;
1527
+ this.setHistory( page.title, page.path );
1528
+ }
1529
+ };
1530
+
1531
+ utils.debounceMethod( InfiniteScroll, 'onScrollHistory', 150 );
1532
+
1533
+ proto.getScrollViewY = function() {
1534
+ if ( this.options.elementScroll ) {
1535
+ return this.scroller.scrollTop + this.scroller.clientHeight/2;
1536
+ } else {
1537
+ return window.pageYOffset + this.windowHeight/2;
1538
+ }
1539
+ };
1540
+
1541
+ proto.setHistory = function( title, path ) {
1542
+ var optHistory = this.options.history;
1543
+ var historyMethod = optHistory && history[ optHistory + 'State' ];
1544
+ if ( !historyMethod ) {
1545
+ return;
1546
+ }
1547
+
1548
+ history[ optHistory + 'State' ]( null, title, path );
1549
+
1550
+ if ( this.options.historyTitle ) {
1551
+ document.title = title;
1552
+ }
1553
+
1554
+ this.dispatchEvent( 'history', null, [ title, path ] );
1555
+ };
1556
+
1557
+ // scroll to top to prevent initial scroll-reset after page refresh
1558
+ // https://stackoverflow.com/a/18633915/182183
1559
+ proto.onUnload = function() {
1560
+ var pageIndex = this.scrollPageIndex;
1561
+ if ( pageIndex === 0 ) {
1562
+ return;
1563
+ }
1564
+ // calculate where scroll position would be on refresh
1565
+ var scrollPage = this.scrollPages[ pageIndex ];
1566
+ var scrollY = window.pageYOffset - scrollPage.top + this.top;
1567
+ // disable scroll event before setting scroll #679
1568
+ this.destroyHistory();
1569
+ scrollTo( 0, scrollY );
1570
+ };
1571
+
1572
+ // ----- load history ----- //
1573
+
1574
+ // update URL
1575
+ proto.onPageLoadHistory = function( response, path ) {
1576
+ this.setHistory( response.title, path );
1577
+ };
1578
+
1579
+ // -------------------------- -------------------------- //
1580
+
1581
+ return InfiniteScroll;
1582
+
1583
+ }));
1584
+
1585
+ // button
1586
+ ( function( window, factory ) {
1587
+ // universal module definition
1588
+ /* globals define, module, require */
1589
+ if ( typeof define == 'function' && define.amd ) {
1590
+ // AMD
1591
+ define( 'infinite-scroll/js/button',[
1592
+ './core',
1593
+ 'fizzy-ui-utils/utils',
1594
+ ], function( InfiniteScroll, utils ) {
1595
+ return factory( window, InfiniteScroll, utils );
1596
+ });
1597
+ } else if ( typeof module == 'object' && module.exports ) {
1598
+ // CommonJS
1599
+ module.exports = factory(
1600
+ window,
1601
+ require('./core'),
1602
+ require('fizzy-ui-utils')
1603
+ );
1604
+ } else {
1605
+ // browser global
1606
+ factory(
1607
+ window,
1608
+ window.InfiniteScroll,
1609
+ window.fizzyUIUtils
1610
+ );
1611
+ }
1612
+
1613
+ }( window, function factory( window, InfiniteScroll, utils ) {
1614
+
1615
+ // InfiniteScroll.defaults.button = null;
1616
+
1617
+ InfiniteScroll.create.button = function() {
1618
+ var buttonElem = utils.getQueryElement( this.options.button );
1619
+ if ( buttonElem ) {
1620
+ this.button = new InfiniteScrollButton( buttonElem, this );
1621
+ return;
1622
+ }
1623
+ };
1624
+
1625
+ InfiniteScroll.destroy.button = function() {
1626
+ if ( this.button ) {
1627
+ this.button.destroy();
1628
+ }
1629
+ };
1630
+
1631
+ // -------------------------- InfiniteScrollButton -------------------------- //
1632
+
1633
+ function InfiniteScrollButton( element, infScroll ) {
1634
+ this.element = element;
1635
+ this.infScroll = infScroll;
1636
+ // events
1637
+ this.clickHandler = this.onClick.bind( this );
1638
+ this.element.addEventListener( 'click', this.clickHandler );
1639
+ infScroll.on( 'request', this.disable.bind( this ) );
1640
+ infScroll.on( 'load', this.enable.bind( this ) );
1641
+ infScroll.on( 'error', this.hide.bind( this ) );
1642
+ infScroll.on( 'last', this.hide.bind( this ) );
1643
+ }
1644
+
1645
+ InfiniteScrollButton.prototype.onClick = function( event ) {
1646
+ event.preventDefault();
1647
+ this.infScroll.loadNextPage();
1648
+ };
1649
+
1650
+ InfiniteScrollButton.prototype.enable = function() {
1651
+ this.element.removeAttribute('disabled');
1652
+ };
1653
+
1654
+ InfiniteScrollButton.prototype.disable = function() {
1655
+ this.element.disabled = 'disabled';
1656
+ };
1657
+
1658
+ InfiniteScrollButton.prototype.hide = function() {
1659
+ this.element.style.display = 'none';
1660
+ };
1661
+
1662
+ InfiniteScrollButton.prototype.destroy = function() {
1663
+ this.element.removeEventListener( 'click', this.clickHandler );
1664
+ };
1665
+
1666
+ // -------------------------- -------------------------- //
1667
+
1668
+ InfiniteScroll.Button = InfiniteScrollButton;
1669
+
1670
+ return InfiniteScroll;
1671
+
1672
+ }));
1673
+
1674
+ // status
1675
+ ( function( window, factory ) {
1676
+ // universal module definition
1677
+ /* globals define, module, require */
1678
+ if ( typeof define == 'function' && define.amd ) {
1679
+ // AMD
1680
+ define( 'infinite-scroll/js/status',[
1681
+ './core',
1682
+ 'fizzy-ui-utils/utils',
1683
+ ], function( InfiniteScroll, utils ) {
1684
+ return factory( window, InfiniteScroll, utils );
1685
+ });
1686
+ } else if ( typeof module == 'object' && module.exports ) {
1687
+ // CommonJS
1688
+ module.exports = factory(
1689
+ window,
1690
+ require('./core'),
1691
+ require('fizzy-ui-utils')
1692
+ );
1693
+ } else {
1694
+ // browser global
1695
+ factory(
1696
+ window,
1697
+ window.InfiniteScroll,
1698
+ window.fizzyUIUtils
1699
+ );
1700
+ }
1701
+
1702
+ }( window, function factory( window, InfiniteScroll, utils ) {
1703
+
1704
+ var proto = InfiniteScroll.prototype;
1705
+
1706
+ // InfiniteScroll.defaults.status = null;
1707
+
1708
+ InfiniteScroll.create.status = function() {
1709
+ var statusElem = utils.getQueryElement( this.options.status );
1710
+ if ( !statusElem ) {
1711
+ return;
1712
+ }
1713
+ // elements
1714
+ this.statusElement = statusElem;
1715
+ this.statusEventElements = {
1716
+ request: statusElem.querySelector('.infinite-scroll-request'),
1717
+ error: statusElem.querySelector('.infinite-scroll-error'),
1718
+ last: statusElem.querySelector('.infinite-scroll-last'),
1719
+ };
1720
+ // events
1721
+ this.on( 'request', this.showRequestStatus );
1722
+ this.on( 'error', this.showErrorStatus );
1723
+ this.on( 'last', this.showLastStatus );
1724
+ this.bindHideStatus('on');
1725
+ };
1726
+
1727
+ proto.bindHideStatus = function( bindMethod ) {
1728
+ var hideEvent = this.options.append ? 'append' : 'load';
1729
+ this[ bindMethod ]( hideEvent, this.hideAllStatus );
1730
+ };
1731
+
1732
+ proto.showRequestStatus = function() {
1733
+ this.showStatus('request');
1734
+ };
1735
+
1736
+ proto.showErrorStatus = function() {
1737
+ this.showStatus('error');
1738
+ };
1739
+
1740
+ proto.showLastStatus = function() {
1741
+ this.showStatus('last');
1742
+ // prevent last then append event race condition from showing last status #706
1743
+ this.bindHideStatus('off');
1744
+ };
1745
+
1746
+ proto.showStatus = function( eventName ) {
1747
+ show( this.statusElement );
1748
+ this.hideStatusEventElements();
1749
+ var eventElem = this.statusEventElements[ eventName ];
1750
+ show( eventElem );
1751
+ };
1752
+
1753
+ proto.hideAllStatus = function() {
1754
+ hide( this.statusElement );
1755
+ this.hideStatusEventElements();
1756
+ };
1757
+
1758
+ proto.hideStatusEventElements = function() {
1759
+ for ( var type in this.statusEventElements ) {
1760
+ var eventElem = this.statusEventElements[ type ];
1761
+ hide( eventElem );
1762
+ }
1763
+ };
1764
+
1765
+ // -------------------------- -------------------------- //
1766
+
1767
+ function hide( elem ) {
1768
+ setDisplay( elem, 'none' );
1769
+ }
1770
+
1771
+ function show( elem ) {
1772
+ setDisplay( elem, 'block' );
1773
+ }
1774
+
1775
+ function setDisplay( elem, value ) {
1776
+ if ( elem ) {
1777
+ elem.style.display = value;
1778
+ }
1779
+ }
1780
+
1781
+ // -------------------------- -------------------------- //
1782
+
1783
+ return InfiniteScroll;
1784
+
1785
+ }));
1786
+
1787
+ /*!
1788
+ * Infinite Scroll v3.0.5
1789
+ * Automatically add next page
1790
+ *
1791
+ * Licensed GPLv3 for open source use
1792
+ * or Infinite Scroll Commercial License for commercial use
1793
+ *
1794
+ * https://infinite-scroll.com
1795
+ * Copyright 2018 Metafizzy
1796
+ */
1797
+
1798
+ ( function( window, factory ) {
1799
+ // universal module definition
1800
+ /* globals define, module, require */
1801
+ if ( typeof define == 'function' && define.amd ) {
1802
+ // AMD
1803
+ define( [
1804
+ 'infinite-scroll/js/core',
1805
+ 'infinite-scroll/js/page-load',
1806
+ 'infinite-scroll/js/scroll-watch',
1807
+ 'infinite-scroll/js/history',
1808
+ 'infinite-scroll/js/button',
1809
+ 'infinite-scroll/js/status',
1810
+ ], factory );
1811
+ } else if ( typeof module == 'object' && module.exports ) {
1812
+ // CommonJS
1813
+ module.exports = factory(
1814
+ require('./core'),
1815
+ require('./page-load'),
1816
+ require('./scroll-watch'),
1817
+ require('./history'),
1818
+ require('./button'),
1819
+ require('./status')
1820
+ );
1821
+ }
1822
+
1823
+ })( window, function factory( InfiniteScroll ) {
1824
+ return InfiniteScroll;
1825
+ });
1826
+
1827
+ /*!
1828
+ * imagesLoaded v4.1.4
1829
+ * JavaScript is all like "You images are done yet or what?"
1830
+ * MIT License
1831
+ */
1832
+
1833
+ ( function( window, factory ) { 'use strict';
1834
+ // universal module definition
1835
+
1836
+ /*global define: false, module: false, require: false */
1837
+
1838
+ if ( typeof define == 'function' && define.amd ) {
1839
+ // AMD
1840
+ define( 'imagesloaded/imagesloaded',[
1841
+ 'ev-emitter/ev-emitter'
1842
+ ], function( EvEmitter ) {
1843
+ return factory( window, EvEmitter );
1844
+ });
1845
+ } else if ( typeof module == 'object' && module.exports ) {
1846
+ // CommonJS
1847
+ module.exports = factory(
1848
+ window,
1849
+ require('ev-emitter')
1850
+ );
1851
+ } else {
1852
+ // browser global
1853
+ window.imagesLoaded = factory(
1854
+ window,
1855
+ window.EvEmitter
1856
+ );
1857
+ }
1858
+
1859
+ })( typeof window !== 'undefined' ? window : this,
1860
+
1861
+ // -------------------------- factory -------------------------- //
1862
+
1863
+ function factory( window, EvEmitter ) {
1864
+
1865
+
1866
+
1867
+ var $ = window.jQuery;
1868
+ var console = window.console;
1869
+
1870
+ // -------------------------- helpers -------------------------- //
1871
+
1872
+ // extend objects
1873
+ function extend( a, b ) {
1874
+ for ( var prop in b ) {
1875
+ a[ prop ] = b[ prop ];
1876
+ }
1877
+ return a;
1878
+ }
1879
+
1880
+ var arraySlice = Array.prototype.slice;
1881
+
1882
+ // turn element or nodeList into an array
1883
+ function makeArray( obj ) {
1884
+ if ( Array.isArray( obj ) ) {
1885
+ // use object if already an array
1886
+ return obj;
1887
+ }
1888
+
1889
+ var isArrayLike = typeof obj == 'object' && typeof obj.length == 'number';
1890
+ if ( isArrayLike ) {
1891
+ // convert nodeList to array
1892
+ return arraySlice.call( obj );
1893
+ }
1894
+
1895
+ // array of single index
1896
+ return [ obj ];
1897
+ }
1898
+
1899
+ // -------------------------- imagesLoaded -------------------------- //
1900
+
1901
+ /**
1902
+ * @param {Array, Element, NodeList, String} elem
1903
+ * @param {Object or Function} options - if function, use as callback
1904
+ * @param {Function} onAlways - callback function
1905
+ */
1906
+ function ImagesLoaded( elem, options, onAlways ) {
1907
+ // coerce ImagesLoaded() without new, to be new ImagesLoaded()
1908
+ if ( !( this instanceof ImagesLoaded ) ) {
1909
+ return new ImagesLoaded( elem, options, onAlways );
1910
+ }
1911
+ // use elem as selector string
1912
+ var queryElem = elem;
1913
+ if ( typeof elem == 'string' ) {
1914
+ queryElem = document.querySelectorAll( elem );
1915
+ }
1916
+ // bail if bad element
1917
+ if ( !queryElem ) {
1918
+ console.error( 'Bad element for imagesLoaded ' + ( queryElem || elem ) );
1919
+ return;
1920
+ }
1921
+
1922
+ this.elements = makeArray( queryElem );
1923
+ this.options = extend( {}, this.options );
1924
+ // shift arguments if no options set
1925
+ if ( typeof options == 'function' ) {
1926
+ onAlways = options;
1927
+ } else {
1928
+ extend( this.options, options );
1929
+ }
1930
+
1931
+ if ( onAlways ) {
1932
+ this.on( 'always', onAlways );
1933
+ }
1934
+
1935
+ this.getImages();
1936
+
1937
+ if ( $ ) {
1938
+ // add jQuery Deferred object
1939
+ this.jqDeferred = new $.Deferred();
1940
+ }
1941
+
1942
+ // HACK check async to allow time to bind listeners
1943
+ setTimeout( this.check.bind( this ) );
1944
+ }
1945
+
1946
+ ImagesLoaded.prototype = Object.create( EvEmitter.prototype );
1947
+
1948
+ ImagesLoaded.prototype.options = {};
1949
+
1950
+ ImagesLoaded.prototype.getImages = function() {
1951
+ this.images = [];
1952
+
1953
+ // filter & find items if we have an item selector
1954
+ this.elements.forEach( this.addElementImages, this );
1955
+ };
1956
+
1957
+ /**
1958
+ * @param {Node} element
1959
+ */
1960
+ ImagesLoaded.prototype.addElementImages = function( elem ) {
1961
+ // filter siblings
1962
+ if ( elem.nodeName == 'IMG' ) {
1963
+ this.addImage( elem );
1964
+ }
1965
+ // get background image on element
1966
+ if ( this.options.background === true ) {
1967
+ this.addElementBackgroundImages( elem );
1968
+ }
1969
+
1970
+ // find children
1971
+ // no non-element nodes, #143
1972
+ var nodeType = elem.nodeType;
1973
+ if ( !nodeType || !elementNodeTypes[ nodeType ] ) {
1974
+ return;
1975
+ }
1976
+ var childImgs = elem.querySelectorAll('img');
1977
+ // concat childElems to filterFound array
1978
+ for ( var i=0; i < childImgs.length; i++ ) {
1979
+ var img = childImgs[i];
1980
+ this.addImage( img );
1981
+ }
1982
+
1983
+ // get child background images
1984
+ if ( typeof this.options.background == 'string' ) {
1985
+ var children = elem.querySelectorAll( this.options.background );
1986
+ for ( i=0; i < children.length; i++ ) {
1987
+ var child = children[i];
1988
+ this.addElementBackgroundImages( child );
1989
+ }
1990
+ }
1991
+ };
1992
+
1993
+ var elementNodeTypes = {
1994
+ 1: true,
1995
+ 9: true,
1996
+ 11: true
1997
+ };
1998
+
1999
+ ImagesLoaded.prototype.addElementBackgroundImages = function( elem ) {
2000
+ var style = getComputedStyle( elem );
2001
+ if ( !style ) {
2002
+ // Firefox returns null if in a hidden iframe https://bugzil.la/548397
2003
+ return;
2004
+ }
2005
+ // get url inside url("...")
2006
+ var reURL = /url\((['"])?(.*?)\1\)/gi;
2007
+ var matches = reURL.exec( style.backgroundImage );
2008
+ while ( matches !== null ) {
2009
+ var url = matches && matches[2];
2010
+ if ( url ) {
2011
+ this.addBackground( url, elem );
2012
+ }
2013
+ matches = reURL.exec( style.backgroundImage );
2014
+ }
2015
+ };
2016
+
2017
+ /**
2018
+ * @param {Image} img
2019
+ */
2020
+ ImagesLoaded.prototype.addImage = function( img ) {
2021
+ var loadingImage = new LoadingImage( img );
2022
+ this.images.push( loadingImage );
2023
+ };
2024
+
2025
+ ImagesLoaded.prototype.addBackground = function( url, elem ) {
2026
+ var background = new Background( url, elem );
2027
+ this.images.push( background );
2028
+ };
2029
+
2030
+ ImagesLoaded.prototype.check = function() {
2031
+ var _this = this;
2032
+ this.progressedCount = 0;
2033
+ this.hasAnyBroken = false;
2034
+ // complete if no images
2035
+ if ( !this.images.length ) {
2036
+ this.complete();
2037
+ return;
2038
+ }
2039
+
2040
+ function onProgress( image, elem, message ) {
2041
+ // HACK - Chrome triggers event before object properties have changed. #83
2042
+ setTimeout( function() {
2043
+ _this.progress( image, elem, message );
2044
+ });
2045
+ }
2046
+
2047
+ this.images.forEach( function( loadingImage ) {
2048
+ loadingImage.once( 'progress', onProgress );
2049
+ loadingImage.check();
2050
+ });
2051
+ };
2052
+
2053
+ ImagesLoaded.prototype.progress = function( image, elem, message ) {
2054
+ this.progressedCount++;
2055
+ this.hasAnyBroken = this.hasAnyBroken || !image.isLoaded;
2056
+ // progress event
2057
+ this.emitEvent( 'progress', [ this, image, elem ] );
2058
+ if ( this.jqDeferred && this.jqDeferred.notify ) {
2059
+ this.jqDeferred.notify( this, image );
2060
+ }
2061
+ // check if completed
2062
+ if ( this.progressedCount == this.images.length ) {
2063
+ this.complete();
2064
+ }
2065
+
2066
+ if ( this.options.debug && console ) {
2067
+ console.log( 'progress: ' + message, image, elem );
2068
+ }
2069
+ };
2070
+
2071
+ ImagesLoaded.prototype.complete = function() {
2072
+ var eventName = this.hasAnyBroken ? 'fail' : 'done';
2073
+ this.isComplete = true;
2074
+ this.emitEvent( eventName, [ this ] );
2075
+ this.emitEvent( 'always', [ this ] );
2076
+ if ( this.jqDeferred ) {
2077
+ var jqMethod = this.hasAnyBroken ? 'reject' : 'resolve';
2078
+ this.jqDeferred[ jqMethod ]( this );
2079
+ }
2080
+ };
2081
+
2082
+ // -------------------------- -------------------------- //
2083
+
2084
+ function LoadingImage( img ) {
2085
+ this.img = img;
2086
+ }
2087
+
2088
+ LoadingImage.prototype = Object.create( EvEmitter.prototype );
2089
+
2090
+ LoadingImage.prototype.check = function() {
2091
+ // If complete is true and browser supports natural sizes,
2092
+ // try to check for image status manually.
2093
+ var isComplete = this.getIsImageComplete();
2094
+ if ( isComplete ) {
2095
+ // report based on naturalWidth
2096
+ this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
2097
+ return;
2098
+ }
2099
+
2100
+ // If none of the checks above matched, simulate loading on detached element.
2101
+ this.proxyImage = new Image();
2102
+ this.proxyImage.addEventListener( 'load', this );
2103
+ this.proxyImage.addEventListener( 'error', this );
2104
+ // bind to image as well for Firefox. #191
2105
+ this.img.addEventListener( 'load', this );
2106
+ this.img.addEventListener( 'error', this );
2107
+ this.proxyImage.src = this.img.src;
2108
+ };
2109
+
2110
+ LoadingImage.prototype.getIsImageComplete = function() {
2111
+ // check for non-zero, non-undefined naturalWidth
2112
+ // fixes Safari+InfiniteScroll+Masonry bug infinite-scroll#671
2113
+ return this.img.complete && this.img.naturalWidth;
2114
+ };
2115
+
2116
+ LoadingImage.prototype.confirm = function( isLoaded, message ) {
2117
+ this.isLoaded = isLoaded;
2118
+ this.emitEvent( 'progress', [ this, this.img, message ] );
2119
+ };
2120
+
2121
+ // ----- events ----- //
2122
+
2123
+ // trigger specified handler for event type
2124
+ LoadingImage.prototype.handleEvent = function( event ) {
2125
+ var method = 'on' + event.type;
2126
+ if ( this[ method ] ) {
2127
+ this[ method ]( event );
2128
+ }
2129
+ };
2130
+
2131
+ LoadingImage.prototype.onload = function() {
2132
+ this.confirm( true, 'onload' );
2133
+ this.unbindEvents();
2134
+ };
2135
+
2136
+ LoadingImage.prototype.onerror = function() {
2137
+ this.confirm( false, 'onerror' );
2138
+ this.unbindEvents();
2139
+ };
2140
+
2141
+ LoadingImage.prototype.unbindEvents = function() {
2142
+ this.proxyImage.removeEventListener( 'load', this );
2143
+ this.proxyImage.removeEventListener( 'error', this );
2144
+ this.img.removeEventListener( 'load', this );
2145
+ this.img.removeEventListener( 'error', this );
2146
+ };
2147
+
2148
+ // -------------------------- Background -------------------------- //
2149
+
2150
+ function Background( url, element ) {
2151
+ this.url = url;
2152
+ this.element = element;
2153
+ this.img = new Image();
2154
+ }
2155
+
2156
+ // inherit LoadingImage prototype
2157
+ Background.prototype = Object.create( LoadingImage.prototype );
2158
+
2159
+ Background.prototype.check = function() {
2160
+ this.img.addEventListener( 'load', this );
2161
+ this.img.addEventListener( 'error', this );
2162
+ this.img.src = this.url;
2163
+ // check if image is already complete
2164
+ var isComplete = this.getIsImageComplete();
2165
+ if ( isComplete ) {
2166
+ this.confirm( this.img.naturalWidth !== 0, 'naturalWidth' );
2167
+ this.unbindEvents();
2168
+ }
2169
+ };
2170
+
2171
+ Background.prototype.unbindEvents = function() {
2172
+ this.img.removeEventListener( 'load', this );
2173
+ this.img.removeEventListener( 'error', this );
2174
+ };
2175
+
2176
+ Background.prototype.confirm = function( isLoaded, message ) {
2177
+ this.isLoaded = isLoaded;
2178
+ this.emitEvent( 'progress', [ this, this.element, message ] );
2179
+ };
2180
+
2181
+ // -------------------------- jQuery -------------------------- //
2182
+
2183
+ ImagesLoaded.makeJQueryPlugin = function( jQuery ) {
2184
+ jQuery = jQuery || window.jQuery;
2185
+ if ( !jQuery ) {
2186
+ return;
2187
+ }
2188
+ // set local variable
2189
+ $ = jQuery;
2190
+ // $().imagesLoaded()
2191
+ $.fn.imagesLoaded = function( options, callback ) {
2192
+ var instance = new ImagesLoaded( this, options, callback );
2193
+ return instance.jqDeferred.promise( $(this) );
2194
+ };
2195
+ };
2196
+ // try making plugin
2197
+ ImagesLoaded.makeJQueryPlugin();
2198
+
2199
+ // -------------------------- -------------------------- //
2200
+
2201
+ return ImagesLoaded;
2202
+
2203
+ });
2204
+
assets/infinitescroll/infinite-scroll.pkgd.min.js CHANGED
@@ -1,12 +1,12 @@
1
- /*!
2
- * Infinite Scroll PACKAGED v3.0.4
3
- * Automatically add next page
4
- *
5
- * Licensed GPLv3 for open source use
6
- * or Infinite Scroll Commercial License for commercial use
7
- *
8
- * https://infinite-scroll.com
9
- * Copyright 2018 Metafizzy
10
- */
11
-
12
- !function(t,e){"function"==typeof define&&define.amd?define("jquery-bridget/jquery-bridget",["jquery"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("jquery")):t.jQueryBridget=e(t,t.jQuery)}(window,function(t,e){"use strict";function i(i,r,l){function a(t,e,n){var o,r="$()."+i+'("'+e+'")';return t.each(function(t,a){var h=l.data(a,i);if(!h)return void s(i+" not initialized. Cannot call methods, i.e. "+r);var c=h[e];if(!c||"_"==e.charAt(0))return void s(r+" is not a valid method");var u=c.apply(h,n);o=void 0===o?u:o}),void 0!==o?o:t}function h(t,e){t.each(function(t,n){var o=l.data(n,i);o?(o.option(e),o._init()):(o=new r(n,e),l.data(n,i,o))})}l=l||e||t.jQuery,l&&(r.prototype.option||(r.prototype.option=function(t){l.isPlainObject(t)&&(this.options=l.extend(!0,this.options,t))}),l.fn[i]=function(t){if("string"==typeof t){var e=o.call(arguments,1);return a(this,t,e)}return h(this,t),this},n(l))}function n(t){!t||t&&t.bridget||(t.bridget=i)}var o=Array.prototype.slice,r=t.console,s="undefined"==typeof r?function(){}:function(t){r.error(t)};return n(e||t.jQuery),i}),function(t,e){"function"==typeof define&&define.amd?define("ev-emitter/ev-emitter",e):"object"==typeof module&&module.exports?module.exports=e():t.EvEmitter=e()}("undefined"!=typeof window?window:this,function(){function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var i=this._events=this._events||{},n=i[t]=i[t]||[];return n.indexOf(e)==-1&&n.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var i=this._onceEvents=this._onceEvents||{},n=i[t]=i[t]||{};return n[e]=!0,this}},e.off=function(t,e){var i=this._events&&this._events[t];if(i&&i.length){var n=i.indexOf(e);return n!=-1&&i.splice(n,1),this}},e.emitEvent=function(t,e){var i=this._events&&this._events[t];if(i&&i.length){i=i.slice(0),e=e||[];for(var n=this._onceEvents&&this._onceEvents[t],o=0;o<i.length;o++){var r=i[o],s=n&&n[r];s&&(this.off(t,r),delete n[r]),r.apply(this,e)}return this}},e.allOff=function(){delete this._events,delete this._onceEvents},t}),function(t,e){"use strict";"function"==typeof define&&define.amd?define("desandro-matches-selector/matches-selector",e):"object"==typeof module&&module.exports?module.exports=e():t.matchesSelector=e()}(window,function(){"use strict";var t=function(){var t=window.Element.prototype;if(t.matches)return"matches";if(t.matchesSelector)return"matchesSelector";for(var e=["webkit","moz","ms","o"],i=0;i<e.length;i++){var n=e[i],o=n+"MatchesSelector";if(t[o])return o}}();return function(e,i){return e[t](i)}}),function(t,e){"function"==typeof define&&define.amd?define("fizzy-ui-utils/utils",["desandro-matches-selector/matches-selector"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("desandro-matches-selector")):t.fizzyUIUtils=e(t,t.matchesSelector)}(window,function(t,e){var i={};i.extend=function(t,e){for(var i in e)t[i]=e[i];return t},i.modulo=function(t,e){return(t%e+e)%e};var n=Array.prototype.slice;i.makeArray=function(t){if(Array.isArray(t))return t;if(null===t||void 0===t)return[];var e="object"==typeof t&&"number"==typeof t.length;return e?n.call(t):[t]},i.removeFrom=function(t,e){var i=t.indexOf(e);i!=-1&&t.splice(i,1)},i.getParent=function(t,i){for(;t.parentNode&&t!=document.body;)if(t=t.parentNode,e(t,i))return t},i.getQueryElement=function(t){return"string"==typeof t?document.querySelector(t):t},i.handleEvent=function(t){var e="on"+t.type;this[e]&&this[e](t)},i.filterFindElements=function(t,n){t=i.makeArray(t);var o=[];return t.forEach(function(t){if(t instanceof HTMLElement){if(!n)return void o.push(t);e(t,n)&&o.push(t);for(var i=t.querySelectorAll(n),r=0;r<i.length;r++)o.push(i[r])}}),o},i.debounceMethod=function(t,e,i){i=i||100;var n=t.prototype[e],o=e+"Timeout";t.prototype[e]=function(){var t=this[o];clearTimeout(t);var e=arguments,r=this;this[o]=setTimeout(function(){n.apply(r,e),delete r[o]},i)}},i.docReady=function(t){var e=document.readyState;"complete"==e||"interactive"==e?setTimeout(t):document.addEventListener("DOMContentLoaded",t)},i.toDashed=function(t){return t.replace(/(.)([A-Z])/g,function(t,e,i){return e+"-"+i}).toLowerCase()};var o=t.console;return i.htmlInit=function(e,n){i.docReady(function(){var r=i.toDashed(n),s="data-"+r,l=document.querySelectorAll("["+s+"]"),a=document.querySelectorAll(".js-"+r),h=i.makeArray(l).concat(i.makeArray(a)),c=s+"-options",u=t.jQuery;h.forEach(function(t){var i,r=t.getAttribute(s)||t.getAttribute(c);try{i=r&&JSON.parse(r)}catch(l){return void(o&&o.error("Error parsing "+s+" on "+t.className+": "+l))}var a=new e(t,i);u&&u.data(t,n,a)})})},i}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/core",["ev-emitter/ev-emitter","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("ev-emitter"),require("fizzy-ui-utils")):t.InfiniteScroll=e(t,t.EvEmitter,t.fizzyUIUtils)}(window,function(t,e,i){function n(t,e){var s=i.getQueryElement(t);if(!s)return void console.error("Bad element for InfiniteScroll: "+(s||t));if(t=s,t.infiniteScrollGUID){var l=r[t.infiniteScrollGUID];return l.option(e),l}this.element=t,this.options=i.extend({},n.defaults),this.option(e),o&&(this.$element=o(this.element)),this.create()}var o=t.jQuery,r={};n.defaults={},n.create={},n.destroy={};var s=n.prototype;i.extend(s,e.prototype);var l=0;s.create=function(){var t=this.guid=++l;this.element.infiniteScrollGUID=t,r[t]=this,this.pageIndex=1,this.loadCount=0,this.updateGetPath();var e=this.getPath&&this.getPath();if(!e)return void console.error("Disabling InfiniteScroll");this.updateGetAbsolutePath(),this.log("initialized",[this.element.className]),this.callOnInit();for(var i in n.create)n.create[i].call(this)},s.option=function(t){i.extend(this.options,t)},s.callOnInit=function(){var t=this.options.onInit;t&&t.call(this,this)},s.dispatchEvent=function(t,e,i){this.log(t,i);var n=e?[e].concat(i):i;if(this.emitEvent(t,n),o&&this.$element){t+=".infiniteScroll";var r=t;if(e){var s=o.Event(e);s.type=t,r=s}this.$element.trigger(r,i)}};var a={initialized:function(t){return"on "+t},request:function(t){return"URL: "+t},load:function(t,e){return(t.title||"")+". URL: "+e},error:function(t,e){return t+". URL: "+e},append:function(t,e,i){return i.length+" items. URL: "+e},last:function(t,e){return"URL: "+e},history:function(t,e){return"URL: "+e},pageIndex:function(t,e){return"current page determined to be: "+t+" from "+e}};s.log=function(t,e){if(this.options.debug){var i="[InfiniteScroll] "+t,n=a[t];n&&(i+=". "+n.apply(this,e)),console.log(i)}},s.updateMeasurements=function(){this.windowHeight=t.innerHeight;var e=this.element.getBoundingClientRect();this.top=e.top+t.pageYOffset},s.updateScroller=function(){var e=this.options.elementScroll;if(!e)return void(this.scroller=t);if(this.scroller=e===!0?this.element:i.getQueryElement(e),!this.scroller)throw"Unable to find elementScroll: "+e},s.updateGetPath=function(){var t=this.options.path;if(!t)return void console.error("InfiniteScroll path option required. Set as: "+t);var e=typeof t;if("function"==e)return void(this.getPath=t);var i="string"==e&&t.match("{{#}}");return i?void this.updateGetPathTemplate(t):void this.updateGetPathSelector(t)},s.updateGetPathTemplate=function(t){this.getPath=function(){var e=this.pageIndex+1;return t.replace("{{#}}",e)}.bind(this);var e=t.replace("{{#}}","(\\d\\d?\\d?)"),i=new RegExp(e),n=location.href.match(i);n&&(this.pageIndex=parseInt(n[1],10),this.log("pageIndex",[this.pageIndex,"template string"]))};var h=[/^(.*?\/?page\/?)(\d\d?\d?)(.*?$)/,/^(.*?\/?\?page=)(\d\d?\d?)(.*?$)/,/(.*?)(\d\d?\d?)(?!.*\d)(.*?$)/];return s.updateGetPathSelector=function(t){var e=document.querySelector(t);if(!e)return void console.error("Bad InfiniteScroll path option. Next link not found: "+t);for(var i,n,o=e.getAttribute("href"),r=0;o&&r<h.length;r++){n=h[r];var s=o.match(n);if(s){i=s.slice(1);break}}return i?(this.isPathSelector=!0,this.getPath=function(){var t=this.pageIndex+1;return i[0]+t+i[2]}.bind(this),this.pageIndex=parseInt(i[1],10)-1,void this.log("pageIndex",[this.pageIndex,"next link"])):void console.error("InfiniteScroll unable to parse next link href: "+o)},s.updateGetAbsolutePath=function(){var t=this.getPath(),e=t.match(/^http/)||t.match(/^\//);if(e)return void(this.getAbsolutePath=this.getPath);var i=location.pathname,n=i.substring(0,i.lastIndexOf("/"));this.getAbsolutePath=function(){return n+"/"+this.getPath()}},n.create.hideNav=function(){var t=i.getQueryElement(this.options.hideNav);t&&(t.style.display="none",this.nav=t)},n.destroy.hideNav=function(){this.nav&&(this.nav.style.display="")},s.destroy=function(){this.allOff();for(var t in n.destroy)n.destroy[t].call(this);delete this.element.infiniteScrollGUID,delete r[this.guid]},n.throttle=function(t,e){e=e||200;var i,n;return function(){var o=+new Date,r=arguments,s=function(){i=o,t.apply(this,r)}.bind(this);i&&o<i+e?(clearTimeout(n),n=setTimeout(s,e)):s()}},n.data=function(t){t=i.getQueryElement(t);var e=t&&t.infiniteScrollGUID;return e&&r[e]},n.setJQuery=function(t){o=t},i.htmlInit(n,"infinite-scroll"),o&&o.bridget&&o.bridget("infiniteScroll",n),n}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/page-load",["./core"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core")):e(t,t.InfiniteScroll)}(window,function(t,e){function i(t){for(var e=document.createDocumentFragment(),i=0;t&&i<t.length;i++)e.appendChild(t[i]);return e}function n(t){for(var e=t.querySelectorAll("script"),i=0;i<e.length;i++){var n=e[i],r=document.createElement("script");o(n,r),r.innerHTML=n.innerHTML,n.parentNode.replaceChild(r,n)}}function o(t,e){for(var i=t.attributes,n=0;n<i.length;n++){var o=i[n];e.setAttribute(o.name,o.value)}}function r(t,e,i,n){var o=new XMLHttpRequest;o.open("GET",t,!0),o.responseType=e||"",o.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.onload=function(){if(200==o.status)i(o.response);else{var t=new Error(o.statusText);n(t)}},o.onerror=function(){var e=new Error("Network error requesting "+t);n(e)},o.send()}var s=e.prototype;return e.defaults.loadOnScroll=!0,e.defaults.checkLastPage=!0,e.defaults.responseType="document",e.create.pageLoad=function(){this.canLoad=!0,this.on("scrollThreshold",this.onScrollThresholdLoad),this.on("load",this.checkLastPage),this.options.outlayer&&this.on("append",this.onAppendOutlayer)},s.onScrollThresholdLoad=function(){this.options.loadOnScroll&&this.loadNextPage()},s.loadNextPage=function(){if(!this.isLoading&&this.canLoad){var t=this.getAbsolutePath();this.isLoading=!0;var e=function(e){this.onPageLoad(e,t)}.bind(this),i=function(e){this.onPageError(e,t)}.bind(this);r(t,this.options.responseType,e,i),this.dispatchEvent("request",null,[t])}},s.onPageLoad=function(t,e){return this.options.append||(this.isLoading=!1),this.pageIndex++,this.loadCount++,this.dispatchEvent("load",null,[t,e]),this.appendNextPage(t,e),t},s.appendNextPage=function(t,e){var n=this.options.append,o="document"==this.options.responseType;if(o&&n){var r=t.querySelectorAll(n),s=i(r),l=function(){this.appendItems(r,s),this.isLoading=!1,this.dispatchEvent("append",null,[t,e,r])}.bind(this);this.options.outlayer?this.appendOutlayerItems(s,l):l()}},s.appendItems=function(t,e){t&&t.length&&(e=e||i(t),n(e),this.element.appendChild(e))},s.appendOutlayerItems=function(i,n){var o=e.imagesLoaded||t.imagesLoaded;return o?void o(i,n):(console.error("[InfiniteScroll] imagesLoaded required for outlayer option"),void(this.isLoading=!1))},s.onAppendOutlayer=function(t,e,i){this.options.outlayer.appended(i)},s.checkLastPage=function(t,e){var i=this.options.checkLastPage;if(i){var n=this.options.path;if("function"==typeof n){var o=this.getPath();if(!o)return void this.lastPageReached(t,e)}var r;if("string"==typeof i?r=i:this.isPathSelector&&(r=n),r&&t.querySelector){var s=t.querySelector(r);s||this.lastPageReached(t,e)}}},s.lastPageReached=function(t,e){this.canLoad=!1,this.dispatchEvent("last",null,[t,e])},s.onPageError=function(t,e){return this.isLoading=!1,this.canLoad=!1,this.dispatchEvent("error",null,[t,e]),t},e.create.prefill=function(){if(this.options.prefill){var t=this.options.append;if(!t)return void console.error("append option required for prefill. Set as :"+t);this.updateMeasurements(),this.updateScroller(),this.isPrefilling=!0,this.on("append",this.prefill),this.once("error",this.stopPrefill),this.once("last",this.stopPrefill),this.prefill()}},s.prefill=function(){var t=this.getPrefillDistance();this.isPrefilling=t>=0,this.isPrefilling?(this.log("prefill"),this.loadNextPage()):this.stopPrefill()},s.getPrefillDistance=function(){return this.options.elementScroll?this.scroller.clientHeight-this.scroller.scrollHeight:this.windowHeight-this.element.clientHeight},s.stopPrefill=function(){this.log("stopPrefill"),this.off("append",this.prefill)},e}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/scroll-watch",["./core","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core"),require("fizzy-ui-utils")):e(t,t.InfiniteScroll,t.fizzyUIUtils)}(window,function(t,e,i){var n=e.prototype;return e.defaults.scrollThreshold=400,e.create.scrollWatch=function(){this.pageScrollHandler=this.onPageScroll.bind(this),this.resizeHandler=this.onResize.bind(this);var t=this.options.scrollThreshold,e=t||0===t;e&&this.enableScrollWatch()},e.destroy.scrollWatch=function(){this.disableScrollWatch()},n.enableScrollWatch=function(){this.isScrollWatching||(this.isScrollWatching=!0,this.updateMeasurements(),this.updateScroller(),this.on("last",this.disableScrollWatch),this.bindScrollWatchEvents(!0))},n.disableScrollWatch=function(){this.isScrollWatching&&(this.bindScrollWatchEvents(!1),delete this.isScrollWatching)},n.bindScrollWatchEvents=function(e){var i=e?"addEventListener":"removeEventListener";this.scroller[i]("scroll",this.pageScrollHandler),t[i]("resize",this.resizeHandler)},n.onPageScroll=e.throttle(function(){var t=this.getBottomDistance();t<=this.options.scrollThreshold&&this.dispatchEvent("scrollThreshold")}),n.getBottomDistance=function(){return this.options.elementScroll?this.getElementBottomDistance():this.getWindowBottomDistance()},n.getWindowBottomDistance=function(){var e=this.top+this.element.clientHeight,i=t.pageYOffset+this.windowHeight;return e-i},n.getElementBottomDistance=function(){var t=this.scroller.scrollHeight,e=this.scroller.scrollTop+this.scroller.clientHeight;return t-e},n.onResize=function(){this.updateMeasurements()},i.debounceMethod(e,"onResize",150),e}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/history",["./core","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core"),require("fizzy-ui-utils")):e(t,t.InfiniteScroll,t.fizzyUIUtils)}(window,function(t,e,i){var n=e.prototype;e.defaults.history="replace";var o=document.createElement("a");return e.create.history=function(){if(this.options.history){o.href=this.getAbsolutePath();var t=o.origin||o.protocol+"//"+o.host,e=t==location.origin;return e?void(this.options.append?this.createHistoryAppend():this.createHistoryPageLoad()):void console.error("[InfiniteScroll] cannot set history with different origin: "+o.origin+" on "+location.origin+" . History behavior disabled.")}},n.createHistoryAppend=function(){this.updateMeasurements(),this.updateScroller(),this.scrollPages=[{top:0,path:location.href,title:document.title}],this.scrollPageIndex=0,this.scrollHistoryHandler=this.onScrollHistory.bind(this),this.unloadHandler=this.onUnload.bind(this),this.scroller.addEventListener("scroll",this.scrollHistoryHandler),this.on("append",this.onAppendHistory),this.bindHistoryAppendEvents(!0)},n.bindHistoryAppendEvents=function(e){var i=e?"addEventListener":"removeEventListener";this.scroller[i]("scroll",this.scrollHistoryHandler),t[i]("unload",this.unloadHandler)},n.createHistoryPageLoad=function(){this.on("load",this.onPageLoadHistory)},e.destroy.history=n.destroyHistory=function(){var t=this.options.history&&this.options.append;t&&this.bindHistoryAppendEvents(!1)},n.onAppendHistory=function(t,e,i){if(i&&i.length){var n=i[0],r=this.getElementScrollY(n);o.href=e,this.scrollPages.push({top:r,path:o.href,title:t.title})}},n.getElementScrollY=function(t){return this.options.elementScroll?this.getElementElementScrollY(t):this.getElementWindowScrollY(t)},n.getElementWindowScrollY=function(e){var i=e.getBoundingClientRect();return i.top+t.pageYOffset},n.getElementElementScrollY=function(t){return t.offsetTop-this.top},n.onScrollHistory=function(){for(var t,e,i=this.getScrollViewY(),n=0;n<this.scrollPages.length;n++){var o=this.scrollPages[n];if(o.top>=i)break;t=n,e=o}t!=this.scrollPageIndex&&(this.scrollPageIndex=t,this.setHistory(e.title,e.path))},i.debounceMethod(e,"onScrollHistory",150),n.getScrollViewY=function(){return this.options.elementScroll?this.scroller.scrollTop+this.scroller.clientHeight/2:t.pageYOffset+this.windowHeight/2},n.setHistory=function(t,e){var i=this.options.history,n=i&&history[i+"State"];n&&(history[i+"State"](null,t,e),this.options.historyTitle&&(document.title=t),this.dispatchEvent("history",null,[t,e]))},n.onUnload=function(){var e=this.scrollPageIndex;if(0!==e){var i=this.scrollPages[e],n=t.pageYOffset-i.top+this.top;this.destroyHistory(),scrollTo(0,n)}},n.onPageLoadHistory=function(t,e){this.setHistory(t.title,e)},e}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/button",["./core","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core"),require("fizzy-ui-utils")):e(t,t.InfiniteScroll,t.fizzyUIUtils)}(window,function(t,e,i){function n(t,e){this.element=t,this.infScroll=e,this.clickHandler=this.onClick.bind(this),this.element.addEventListener("click",this.clickHandler),e.on("request",this.disable.bind(this)),e.on("load",this.enable.bind(this)),e.on("error",this.hide.bind(this)),e.on("last",this.hide.bind(this))}return e.create.button=function(){var t=i.getQueryElement(this.options.button);if(t)return void(this.button=new n(t,this))},e.destroy.button=function(){this.button&&this.button.destroy()},n.prototype.onClick=function(t){t.preventDefault(),this.infScroll.loadNextPage()},n.prototype.enable=function(){this.element.removeAttribute("disabled")},n.prototype.disable=function(){this.element.disabled="disabled"},n.prototype.hide=function(){this.element.style.display="none"},n.prototype.destroy=function(){this.element.removeEventListener("click",this.clickHandler)},e.Button=n,e}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/status",["./core","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core"),require("fizzy-ui-utils")):e(t,t.InfiniteScroll,t.fizzyUIUtils)}(window,function(t,e,i){function n(t){r(t,"none")}function o(t){r(t,"block")}function r(t,e){t&&(t.style.display=e)}var s=e.prototype;return e.create.status=function(){var t=i.getQueryElement(this.options.status);t&&(this.statusElement=t,this.statusEventElements={request:t.querySelector(".infinite-scroll-request"),error:t.querySelector(".infinite-scroll-error"),last:t.querySelector(".infinite-scroll-last")},this.on("request",this.showRequestStatus),this.on("error",this.showErrorStatus),this.on("last",this.showLastStatus),this.bindHideStatus("on"))},s.bindHideStatus=function(t){var e=this.options.append?"append":"load";this[t](e,this.hideAllStatus)},s.showRequestStatus=function(){this.showStatus("request")},s.showErrorStatus=function(){this.showStatus("error")},s.showLastStatus=function(){this.showStatus("last"),this.bindHideStatus("off")},s.showStatus=function(t){o(this.statusElement),this.hideStatusEventElements();var e=this.statusEventElements[t];o(e)},s.hideAllStatus=function(){n(this.statusElement),this.hideStatusEventElements()},s.hideStatusEventElements=function(){for(var t in this.statusEventElements){var e=this.statusEventElements[t];n(e)}},e}),function(t,e){"function"==typeof define&&define.amd?define(["infinite-scroll/js/core","infinite-scroll/js/page-load","infinite-scroll/js/scroll-watch","infinite-scroll/js/history","infinite-scroll/js/button","infinite-scroll/js/status"],e):"object"==typeof module&&module.exports&&(module.exports=e(require("./core"),require("./page-load"),require("./scroll-watch"),require("./history"),require("./button"),require("./status")))}(window,function(t){return t}),function(t,e){"use strict";"function"==typeof define&&define.amd?define("imagesloaded/imagesloaded",["ev-emitter/ev-emitter"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("ev-emitter")):t.imagesLoaded=e(t,t.EvEmitter)}("undefined"!=typeof window?window:this,function(t,e){function i(t,e){for(var i in e)t[i]=e[i];return t}function n(t){if(Array.isArray(t))return t;var e="object"==typeof t&&"number"==typeof t.length;return e?h.call(t):[t]}function o(t,e,r){if(!(this instanceof o))return new o(t,e,r);var s=t;return"string"==typeof t&&(s=document.querySelectorAll(t)),s?(this.elements=n(s),this.options=i({},this.options),"function"==typeof e?r=e:i(this.options,e),r&&this.on("always",r),this.getImages(),l&&(this.jqDeferred=new l.Deferred),void setTimeout(this.check.bind(this))):void a.error("Bad element for imagesLoaded "+(s||t))}function r(t){this.img=t}function s(t,e){this.url=t,this.element=e,this.img=new Image}var l=t.jQuery,a=t.console,h=Array.prototype.slice;o.prototype=Object.create(e.prototype),o.prototype.options={},o.prototype.getImages=function(){this.images=[],this.elements.forEach(this.addElementImages,this)},o.prototype.addElementImages=function(t){"IMG"==t.nodeName&&this.addImage(t),this.options.background===!0&&this.addElementBackgroundImages(t);var e=t.nodeType;if(e&&c[e]){for(var i=t.querySelectorAll("img"),n=0;n<i.length;n++){var o=i[n];this.addImage(o)}if("string"==typeof this.options.background){var r=t.querySelectorAll(this.options.background);for(n=0;n<r.length;n++){var s=r[n];this.addElementBackgroundImages(s)}}}};var c={1:!0,9:!0,11:!0};return o.prototype.addElementBackgroundImages=function(t){var e=getComputedStyle(t);if(e)for(var i=/url\((['"])?(.*?)\1\)/gi,n=i.exec(e.backgroundImage);null!==n;){var o=n&&n[2];o&&this.addBackground(o,t),n=i.exec(e.backgroundImage)}},o.prototype.addImage=function(t){var e=new r(t);this.images.push(e)},o.prototype.addBackground=function(t,e){var i=new s(t,e);this.images.push(i)},o.prototype.check=function(){function t(t,i,n){setTimeout(function(){e.progress(t,i,n)})}var e=this;return this.progressedCount=0,this.hasAnyBroken=!1,this.images.length?void this.images.forEach(function(e){e.once("progress",t),e.check()}):void this.complete()},o.prototype.progress=function(t,e,i){this.progressedCount++,this.hasAnyBroken=this.hasAnyBroken||!t.isLoaded,this.emitEvent("progress",[this,t,e]),this.jqDeferred&&this.jqDeferred.notify&&this.jqDeferred.notify(this,t),this.progressedCount==this.images.length&&this.complete(),this.options.debug&&a&&a.log("progress: "+i,t,e)},o.prototype.complete=function(){var t=this.hasAnyBroken?"fail":"done";if(this.isComplete=!0,this.emitEvent(t,[this]),this.emitEvent("always",[this]),this.jqDeferred){var e=this.hasAnyBroken?"reject":"resolve";this.jqDeferred[e](this)}},r.prototype=Object.create(e.prototype),r.prototype.check=function(){var t=this.getIsImageComplete();return t?void this.confirm(0!==this.img.naturalWidth,"naturalWidth"):(this.proxyImage=new Image,this.proxyImage.addEventListener("load",this),this.proxyImage.addEventListener("error",this),this.img.addEventListener("load",this),this.img.addEventListener("error",this),void(this.proxyImage.src=this.img.src))},r.prototype.getIsImageComplete=function(){return this.img.complete&&this.img.naturalWidth},r.prototype.confirm=function(t,e){this.isLoaded=t,this.emitEvent("progress",[this,this.img,e])},r.prototype.handleEvent=function(t){var e="on"+t.type;this[e]&&this[e](t)},r.prototype.onload=function(){this.confirm(!0,"onload"),this.unbindEvents()},r.prototype.onerror=function(){this.confirm(!1,"onerror"),this.unbindEvents()},r.prototype.unbindEvents=function(){this.proxyImage.removeEventListener("load",this),this.proxyImage.removeEventListener("error",this),this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},s.prototype=Object.create(r.prototype),s.prototype.check=function(){this.img.addEventListener("load",this),this.img.addEventListener("error",this),this.img.src=this.url;var t=this.getIsImageComplete();t&&(this.confirm(0!==this.img.naturalWidth,"naturalWidth"),this.unbindEvents())},s.prototype.unbindEvents=function(){this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},s.prototype.confirm=function(t,e){this.isLoaded=t,this.emitEvent("progress",[this,this.element,e])},o.makeJQueryPlugin=function(e){e=e||t.jQuery,e&&(l=e,l.fn.imagesLoaded=function(t,e){var i=new o(this,t,e);return i.jqDeferred.promise(l(this))})},o.makeJQueryPlugin(),o});
1
+ /*!
2
+ * Infinite Scroll PACKAGED v3.0.5
3
+ * Automatically add next page
4
+ *
5
+ * Licensed GPLv3 for open source use
6
+ * or Infinite Scroll Commercial License for commercial use
7
+ *
8
+ * https://infinite-scroll.com
9
+ * Copyright 2018 Metafizzy
10
+ */
11
+
12
+ !function(t,e){"function"==typeof define&&define.amd?define("jquery-bridget/jquery-bridget",["jquery"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("jquery")):t.jQueryBridget=e(t,t.jQuery)}(window,function(t,e){"use strict";function i(i,r,l){function a(t,e,n){var o,r="$()."+i+'("'+e+'")';return t.each(function(t,a){var h=l.data(a,i);if(!h)return void s(i+" not initialized. Cannot call methods, i.e. "+r);var c=h[e];if(!c||"_"==e.charAt(0))return void s(r+" is not a valid method");var u=c.apply(h,n);o=void 0===o?u:o}),void 0!==o?o:t}function h(t,e){t.each(function(t,n){var o=l.data(n,i);o?(o.option(e),o._init()):(o=new r(n,e),l.data(n,i,o))})}l=l||e||t.jQuery,l&&(r.prototype.option||(r.prototype.option=function(t){l.isPlainObject(t)&&(this.options=l.extend(!0,this.options,t))}),l.fn[i]=function(t){if("string"==typeof t){var e=o.call(arguments,1);return a(this,t,e)}return h(this,t),this},n(l))}function n(t){!t||t&&t.bridget||(t.bridget=i)}var o=Array.prototype.slice,r=t.console,s="undefined"==typeof r?function(){}:function(t){r.error(t)};return n(e||t.jQuery),i}),function(t,e){"function"==typeof define&&define.amd?define("ev-emitter/ev-emitter",e):"object"==typeof module&&module.exports?module.exports=e():t.EvEmitter=e()}("undefined"!=typeof window?window:this,function(){function t(){}var e=t.prototype;return e.on=function(t,e){if(t&&e){var i=this._events=this._events||{},n=i[t]=i[t]||[];return n.indexOf(e)==-1&&n.push(e),this}},e.once=function(t,e){if(t&&e){this.on(t,e);var i=this._onceEvents=this._onceEvents||{},n=i[t]=i[t]||{};return n[e]=!0,this}},e.off=function(t,e){var i=this._events&&this._events[t];if(i&&i.length){var n=i.indexOf(e);return n!=-1&&i.splice(n,1),this}},e.emitEvent=function(t,e){var i=this._events&&this._events[t];if(i&&i.length){i=i.slice(0),e=e||[];for(var n=this._onceEvents&&this._onceEvents[t],o=0;o<i.length;o++){var r=i[o],s=n&&n[r];s&&(this.off(t,r),delete n[r]),r.apply(this,e)}return this}},e.allOff=function(){delete this._events,delete this._onceEvents},t}),function(t,e){"use strict";"function"==typeof define&&define.amd?define("desandro-matches-selector/matches-selector",e):"object"==typeof module&&module.exports?module.exports=e():t.matchesSelector=e()}(window,function(){"use strict";var t=function(){var t=window.Element.prototype;if(t.matches)return"matches";if(t.matchesSelector)return"matchesSelector";for(var e=["webkit","moz","ms","o"],i=0;i<e.length;i++){var n=e[i],o=n+"MatchesSelector";if(t[o])return o}}();return function(e,i){return e[t](i)}}),function(t,e){"function"==typeof define&&define.amd?define("fizzy-ui-utils/utils",["desandro-matches-selector/matches-selector"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("desandro-matches-selector")):t.fizzyUIUtils=e(t,t.matchesSelector)}(window,function(t,e){var i={};i.extend=function(t,e){for(var i in e)t[i]=e[i];return t},i.modulo=function(t,e){return(t%e+e)%e};var n=Array.prototype.slice;i.makeArray=function(t){if(Array.isArray(t))return t;if(null===t||void 0===t)return[];var e="object"==typeof t&&"number"==typeof t.length;return e?n.call(t):[t]},i.removeFrom=function(t,e){var i=t.indexOf(e);i!=-1&&t.splice(i,1)},i.getParent=function(t,i){for(;t.parentNode&&t!=document.body;)if(t=t.parentNode,e(t,i))return t},i.getQueryElement=function(t){return"string"==typeof t?document.querySelector(t):t},i.handleEvent=function(t){var e="on"+t.type;this[e]&&this[e](t)},i.filterFindElements=function(t,n){t=i.makeArray(t);var o=[];return t.forEach(function(t){if(t instanceof HTMLElement){if(!n)return void o.push(t);e(t,n)&&o.push(t);for(var i=t.querySelectorAll(n),r=0;r<i.length;r++)o.push(i[r])}}),o},i.debounceMethod=function(t,e,i){i=i||100;var n=t.prototype[e],o=e+"Timeout";t.prototype[e]=function(){var t=this[o];clearTimeout(t);var e=arguments,r=this;this[o]=setTimeout(function(){n.apply(r,e),delete r[o]},i)}},i.docReady=function(t){var e=document.readyState;"complete"==e||"interactive"==e?setTimeout(t):document.addEventListener("DOMContentLoaded",t)},i.toDashed=function(t){return t.replace(/(.)([A-Z])/g,function(t,e,i){return e+"-"+i}).toLowerCase()};var o=t.console;return i.htmlInit=function(e,n){i.docReady(function(){var r=i.toDashed(n),s="data-"+r,l=document.querySelectorAll("["+s+"]"),a=document.querySelectorAll(".js-"+r),h=i.makeArray(l).concat(i.makeArray(a)),c=s+"-options",u=t.jQuery;h.forEach(function(t){var i,r=t.getAttribute(s)||t.getAttribute(c);try{i=r&&JSON.parse(r)}catch(l){return void(o&&o.error("Error parsing "+s+" on "+t.className+": "+l))}var a=new e(t,i);u&&u.data(t,n,a)})})},i}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/core",["ev-emitter/ev-emitter","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("ev-emitter"),require("fizzy-ui-utils")):t.InfiniteScroll=e(t,t.EvEmitter,t.fizzyUIUtils)}(window,function(t,e,i){function n(t,e){var s=i.getQueryElement(t);if(!s)return void console.error("Bad element for InfiniteScroll: "+(s||t));if(t=s,t.infiniteScrollGUID){var l=r[t.infiniteScrollGUID];return l.option(e),l}this.element=t,this.options=i.extend({},n.defaults),this.option(e),o&&(this.$element=o(this.element)),this.create()}var o=t.jQuery,r={};n.defaults={},n.create={},n.destroy={};var s=n.prototype;i.extend(s,e.prototype);var l=0;s.create=function(){var t=this.guid=++l;this.element.infiniteScrollGUID=t,r[t]=this,this.pageIndex=1,this.loadCount=0,this.updateGetPath();var e=this.getPath&&this.getPath();if(!e)return void console.error("Disabling InfiniteScroll");this.updateGetAbsolutePath(),this.log("initialized",[this.element.className]),this.callOnInit();for(var i in n.create)n.create[i].call(this)},s.option=function(t){i.extend(this.options,t)},s.callOnInit=function(){var t=this.options.onInit;t&&t.call(this,this)},s.dispatchEvent=function(t,e,i){this.log(t,i);var n=e?[e].concat(i):i;if(this.emitEvent(t,n),o&&this.$element){t+=".infiniteScroll";var r=t;if(e){var s=o.Event(e);s.type=t,r=s}this.$element.trigger(r,i)}};var a={initialized:function(t){return"on "+t},request:function(t){return"URL: "+t},load:function(t,e){return(t.title||"")+". URL: "+e},error:function(t,e){return t+". URL: "+e},append:function(t,e,i){return i.length+" items. URL: "+e},last:function(t,e){return"URL: "+e},history:function(t,e){return"URL: "+e},pageIndex:function(t,e){return"current page determined to be: "+t+" from "+e}};s.log=function(t,e){if(this.options.debug){var i="[InfiniteScroll] "+t,n=a[t];n&&(i+=". "+n.apply(this,e)),console.log(i)}},s.updateMeasurements=function(){this.windowHeight=t.innerHeight;var e=this.element.getBoundingClientRect();this.top=e.top+t.pageYOffset},s.updateScroller=function(){var e=this.options.elementScroll;if(!e)return void(this.scroller=t);if(this.scroller=e===!0?this.element:i.getQueryElement(e),!this.scroller)throw"Unable to find elementScroll: "+e},s.updateGetPath=function(){var t=this.options.path;if(!t)return void console.error("InfiniteScroll path option required. Set as: "+t);var e=typeof t;if("function"==e)return void(this.getPath=t);var i="string"==e&&t.match("{{#}}");return i?void this.updateGetPathTemplate(t):void this.updateGetPathSelector(t)},s.updateGetPathTemplate=function(t){this.getPath=function(){var e=this.pageIndex+1;return t.replace("{{#}}",e)}.bind(this);var e=t.replace("{{#}}","(\\d\\d?\\d?)"),i=new RegExp(e),n=location.href.match(i);n&&(this.pageIndex=parseInt(n[1],10),this.log("pageIndex",[this.pageIndex,"template string"]))};var h=[/^(.*?\/?page\/?)(\d\d?\d?)(.*?$)/,/^(.*?\/?\?page=)(\d\d?\d?)(.*?$)/,/(.*?)(\d\d?\d?)(?!.*\d)(.*?$)/];return s.updateGetPathSelector=function(t){var e=document.querySelector(t);if(!e)return void console.error("Bad InfiniteScroll path option. Next link not found: "+t);for(var i,n,o=e.getAttribute("href"),r=0;o&&r<h.length;r++){n=h[r];var s=o.match(n);if(s){i=s.slice(1);break}}return i?(this.isPathSelector=!0,this.getPath=function(){var t=this.pageIndex+1;return i[0]+t+i[2]}.bind(this),this.pageIndex=parseInt(i[1],10)-1,void this.log("pageIndex",[this.pageIndex,"next link"])):void console.error("InfiniteScroll unable to parse next link href: "+o)},s.updateGetAbsolutePath=function(){var t=this.getPath(),e=t.match(/^http/)||t.match(/^\//);if(e)return void(this.getAbsolutePath=this.getPath);var i=location.pathname,n=i.substring(0,i.lastIndexOf("/"));this.getAbsolutePath=function(){return n+"/"+this.getPath()}},n.create.hideNav=function(){var t=i.getQueryElement(this.options.hideNav);t&&(t.style.display="none",this.nav=t)},n.destroy.hideNav=function(){this.nav&&(this.nav.style.display="")},s.destroy=function(){this.allOff();for(var t in n.destroy)n.destroy[t].call(this);delete this.element.infiniteScrollGUID,delete r[this.guid],o&&this.$element&&o.removeData(this.element,"infiniteScroll")},n.throttle=function(t,e){e=e||200;var i,n;return function(){var o=+new Date,r=arguments,s=function(){i=o,t.apply(this,r)}.bind(this);i&&o<i+e?(clearTimeout(n),n=setTimeout(s,e)):s()}},n.data=function(t){t=i.getQueryElement(t);var e=t&&t.infiniteScrollGUID;return e&&r[e]},n.setJQuery=function(t){o=t},i.htmlInit(n,"infinite-scroll"),s._init=function(){},o&&o.bridget&&o.bridget("infiniteScroll",n),n}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/page-load",["./core"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core")):e(t,t.InfiniteScroll)}(window,function(t,e){function i(t){for(var e=document.createDocumentFragment(),i=0;t&&i<t.length;i++)e.appendChild(t[i]);return e}function n(t){for(var e=t.querySelectorAll("script"),i=0;i<e.length;i++){var n=e[i],r=document.createElement("script");o(n,r),r.innerHTML=n.innerHTML,n.parentNode.replaceChild(r,n)}}function o(t,e){for(var i=t.attributes,n=0;n<i.length;n++){var o=i[n];e.setAttribute(o.name,o.value)}}function r(t,e,i,n){var o=new XMLHttpRequest;o.open("GET",t,!0),o.responseType=e||"",o.setRequestHeader("X-Requested-With","XMLHttpRequest"),o.onload=function(){if(200==o.status)i(o.response);else{var t=new Error(o.statusText);n(t)}},o.onerror=function(){var e=new Error("Network error requesting "+t);n(e)},o.send()}var s=e.prototype;return e.defaults.loadOnScroll=!0,e.defaults.checkLastPage=!0,e.defaults.responseType="document",e.create.pageLoad=function(){this.canLoad=!0,this.on("scrollThreshold",this.onScrollThresholdLoad),this.on("load",this.checkLastPage),this.options.outlayer&&this.on("append",this.onAppendOutlayer)},s.onScrollThresholdLoad=function(){this.options.loadOnScroll&&this.loadNextPage()},s.loadNextPage=function(){if(!this.isLoading&&this.canLoad){var t=this.getAbsolutePath();this.isLoading=!0;var e=function(e){this.onPageLoad(e,t)}.bind(this),i=function(e){this.onPageError(e,t)}.bind(this);r(t,this.options.responseType,e,i),this.dispatchEvent("request",null,[t])}},s.onPageLoad=function(t,e){return this.options.append||(this.isLoading=!1),this.pageIndex++,this.loadCount++,this.dispatchEvent("load",null,[t,e]),this.appendNextPage(t,e),t},s.appendNextPage=function(t,e){var n=this.options.append,o="document"==this.options.responseType;if(o&&n){var r=t.querySelectorAll(n),s=i(r),l=function(){this.appendItems(r,s),this.isLoading=!1,this.dispatchEvent("append",null,[t,e,r])}.bind(this);this.options.outlayer?this.appendOutlayerItems(s,l):l()}},s.appendItems=function(t,e){t&&t.length&&(e=e||i(t),n(e),this.element.appendChild(e))},s.appendOutlayerItems=function(i,n){var o=e.imagesLoaded||t.imagesLoaded;return o?void o(i,n):(console.error("[InfiniteScroll] imagesLoaded required for outlayer option"),void(this.isLoading=!1))},s.onAppendOutlayer=function(t,e,i){this.options.outlayer.appended(i)},s.checkLastPage=function(t,e){var i=this.options.checkLastPage;if(i){var n=this.options.path;if("function"==typeof n){var o=this.getPath();if(!o)return void this.lastPageReached(t,e)}var r;if("string"==typeof i?r=i:this.isPathSelector&&(r=n),r&&t.querySelector){var s=t.querySelector(r);s||this.lastPageReached(t,e)}}},s.lastPageReached=function(t,e){this.canLoad=!1,this.dispatchEvent("last",null,[t,e])},s.onPageError=function(t,e){return this.isLoading=!1,this.canLoad=!1,this.dispatchEvent("error",null,[t,e]),t},e.create.prefill=function(){if(this.options.prefill){var t=this.options.append;if(!t)return void console.error("append option required for prefill. Set as :"+t);this.updateMeasurements(),this.updateScroller(),this.isPrefilling=!0,this.on("append",this.prefill),this.once("error",this.stopPrefill),this.once("last",this.stopPrefill),this.prefill()}},s.prefill=function(){var t=this.getPrefillDistance();this.isPrefilling=t>=0,this.isPrefilling?(this.log("prefill"),this.loadNextPage()):this.stopPrefill()},s.getPrefillDistance=function(){return this.options.elementScroll?this.scroller.clientHeight-this.scroller.scrollHeight:this.windowHeight-this.element.clientHeight},s.stopPrefill=function(){this.log("stopPrefill"),this.off("append",this.prefill)},e}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/scroll-watch",["./core","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core"),require("fizzy-ui-utils")):e(t,t.InfiniteScroll,t.fizzyUIUtils)}(window,function(t,e,i){var n=e.prototype;return e.defaults.scrollThreshold=400,e.create.scrollWatch=function(){this.pageScrollHandler=this.onPageScroll.bind(this),this.resizeHandler=this.onResize.bind(this);var t=this.options.scrollThreshold,e=t||0===t;e&&this.enableScrollWatch()},e.destroy.scrollWatch=function(){this.disableScrollWatch()},n.enableScrollWatch=function(){this.isScrollWatching||(this.isScrollWatching=!0,this.updateMeasurements(),this.updateScroller(),this.on("last",this.disableScrollWatch),this.bindScrollWatchEvents(!0))},n.disableScrollWatch=function(){this.isScrollWatching&&(this.bindScrollWatchEvents(!1),delete this.isScrollWatching)},n.bindScrollWatchEvents=function(e){var i=e?"addEventListener":"removeEventListener";this.scroller[i]("scroll",this.pageScrollHandler),t[i]("resize",this.resizeHandler)},n.onPageScroll=e.throttle(function(){var t=this.getBottomDistance();t<=this.options.scrollThreshold&&this.dispatchEvent("scrollThreshold")}),n.getBottomDistance=function(){return this.options.elementScroll?this.getElementBottomDistance():this.getWindowBottomDistance()},n.getWindowBottomDistance=function(){var e=this.top+this.element.clientHeight,i=t.pageYOffset+this.windowHeight;return e-i},n.getElementBottomDistance=function(){var t=this.scroller.scrollHeight,e=this.scroller.scrollTop+this.scroller.clientHeight;return t-e},n.onResize=function(){this.updateMeasurements()},i.debounceMethod(e,"onResize",150),e}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/history",["./core","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core"),require("fizzy-ui-utils")):e(t,t.InfiniteScroll,t.fizzyUIUtils)}(window,function(t,e,i){var n=e.prototype;e.defaults.history="replace";var o=document.createElement("a");return e.create.history=function(){if(this.options.history){o.href=this.getAbsolutePath();var t=o.origin||o.protocol+"//"+o.host,e=t==location.origin;return e?void(this.options.append?this.createHistoryAppend():this.createHistoryPageLoad()):void console.error("[InfiniteScroll] cannot set history with different origin: "+o.origin+" on "+location.origin+" . History behavior disabled.")}},n.createHistoryAppend=function(){this.updateMeasurements(),this.updateScroller(),this.scrollPages=[{top:0,path:location.href,title:document.title}],this.scrollPageIndex=0,this.scrollHistoryHandler=this.onScrollHistory.bind(this),this.unloadHandler=this.onUnload.bind(this),this.scroller.addEventListener("scroll",this.scrollHistoryHandler),this.on("append",this.onAppendHistory),this.bindHistoryAppendEvents(!0)},n.bindHistoryAppendEvents=function(e){var i=e?"addEventListener":"removeEventListener";this.scroller[i]("scroll",this.scrollHistoryHandler),t[i]("unload",this.unloadHandler)},n.createHistoryPageLoad=function(){this.on("load",this.onPageLoadHistory)},e.destroy.history=n.destroyHistory=function(){var t=this.options.history&&this.options.append;t&&this.bindHistoryAppendEvents(!1)},n.onAppendHistory=function(t,e,i){if(i&&i.length){var n=i[0],r=this.getElementScrollY(n);o.href=e,this.scrollPages.push({top:r,path:o.href,title:t.title})}},n.getElementScrollY=function(t){return this.options.elementScroll?this.getElementElementScrollY(t):this.getElementWindowScrollY(t)},n.getElementWindowScrollY=function(e){var i=e.getBoundingClientRect();return i.top+t.pageYOffset},n.getElementElementScrollY=function(t){return t.offsetTop-this.top},n.onScrollHistory=function(){for(var t,e,i=this.getScrollViewY(),n=0;n<this.scrollPages.length;n++){var o=this.scrollPages[n];if(o.top>=i)break;t=n,e=o}t!=this.scrollPageIndex&&(this.scrollPageIndex=t,this.setHistory(e.title,e.path))},i.debounceMethod(e,"onScrollHistory",150),n.getScrollViewY=function(){return this.options.elementScroll?this.scroller.scrollTop+this.scroller.clientHeight/2:t.pageYOffset+this.windowHeight/2},n.setHistory=function(t,e){var i=this.options.history,n=i&&history[i+"State"];n&&(history[i+"State"](null,t,e),this.options.historyTitle&&(document.title=t),this.dispatchEvent("history",null,[t,e]))},n.onUnload=function(){var e=this.scrollPageIndex;if(0!==e){var i=this.scrollPages[e],n=t.pageYOffset-i.top+this.top;this.destroyHistory(),scrollTo(0,n)}},n.onPageLoadHistory=function(t,e){this.setHistory(t.title,e)},e}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/button",["./core","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core"),require("fizzy-ui-utils")):e(t,t.InfiniteScroll,t.fizzyUIUtils)}(window,function(t,e,i){function n(t,e){this.element=t,this.infScroll=e,this.clickHandler=this.onClick.bind(this),this.element.addEventListener("click",this.clickHandler),e.on("request",this.disable.bind(this)),e.on("load",this.enable.bind(this)),e.on("error",this.hide.bind(this)),e.on("last",this.hide.bind(this))}return e.create.button=function(){var t=i.getQueryElement(this.options.button);if(t)return void(this.button=new n(t,this))},e.destroy.button=function(){this.button&&this.button.destroy()},n.prototype.onClick=function(t){t.preventDefault(),this.infScroll.loadNextPage()},n.prototype.enable=function(){this.element.removeAttribute("disabled")},n.prototype.disable=function(){this.element.disabled="disabled"},n.prototype.hide=function(){this.element.style.display="none"},n.prototype.destroy=function(){this.element.removeEventListener("click",this.clickHandler)},e.Button=n,e}),function(t,e){"function"==typeof define&&define.amd?define("infinite-scroll/js/status",["./core","fizzy-ui-utils/utils"],function(i,n){return e(t,i,n)}):"object"==typeof module&&module.exports?module.exports=e(t,require("./core"),require("fizzy-ui-utils")):e(t,t.InfiniteScroll,t.fizzyUIUtils)}(window,function(t,e,i){function n(t){r(t,"none")}function o(t){r(t,"block")}function r(t,e){t&&(t.style.display=e)}var s=e.prototype;return e.create.status=function(){var t=i.getQueryElement(this.options.status);t&&(this.statusElement=t,this.statusEventElements={request:t.querySelector(".infinite-scroll-request"),error:t.querySelector(".infinite-scroll-error"),last:t.querySelector(".infinite-scroll-last")},this.on("request",this.showRequestStatus),this.on("error",this.showErrorStatus),this.on("last",this.showLastStatus),this.bindHideStatus("on"))},s.bindHideStatus=function(t){var e=this.options.append?"append":"load";this[t](e,this.hideAllStatus)},s.showRequestStatus=function(){this.showStatus("request")},s.showErrorStatus=function(){this.showStatus("error")},s.showLastStatus=function(){this.showStatus("last"),this.bindHideStatus("off")},s.showStatus=function(t){o(this.statusElement),this.hideStatusEventElements();var e=this.statusEventElements[t];o(e)},s.hideAllStatus=function(){n(this.statusElement),this.hideStatusEventElements()},s.hideStatusEventElements=function(){for(var t in this.statusEventElements){var e=this.statusEventElements[t];n(e)}},e}),function(t,e){"function"==typeof define&&define.amd?define(["infinite-scroll/js/core","infinite-scroll/js/page-load","infinite-scroll/js/scroll-watch","infinite-scroll/js/history","infinite-scroll/js/button","infinite-scroll/js/status"],e):"object"==typeof module&&module.exports&&(module.exports=e(require("./core"),require("./page-load"),require("./scroll-watch"),require("./history"),require("./button"),require("./status")))}(window,function(t){return t}),function(t,e){"use strict";"function"==typeof define&&define.amd?define("imagesloaded/imagesloaded",["ev-emitter/ev-emitter"],function(i){return e(t,i)}):"object"==typeof module&&module.exports?module.exports=e(t,require("ev-emitter")):t.imagesLoaded=e(t,t.EvEmitter)}("undefined"!=typeof window?window:this,function(t,e){function i(t,e){for(var i in e)t[i]=e[i];return t}function n(t){if(Array.isArray(t))return t;var e="object"==typeof t&&"number"==typeof t.length;return e?h.call(t):[t]}function o(t,e,r){if(!(this instanceof o))return new o(t,e,r);var s=t;return"string"==typeof t&&(s=document.querySelectorAll(t)),s?(this.elements=n(s),this.options=i({},this.options),"function"==typeof e?r=e:i(this.options,e),r&&this.on("always",r),this.getImages(),l&&(this.jqDeferred=new l.Deferred),void setTimeout(this.check.bind(this))):void a.error("Bad element for imagesLoaded "+(s||t))}function r(t){this.img=t}function s(t,e){this.url=t,this.element=e,this.img=new Image}var l=t.jQuery,a=t.console,h=Array.prototype.slice;o.prototype=Object.create(e.prototype),o.prototype.options={},o.prototype.getImages=function(){this.images=[],this.elements.forEach(this.addElementImages,this)},o.prototype.addElementImages=function(t){"IMG"==t.nodeName&&this.addImage(t),this.options.background===!0&&this.addElementBackgroundImages(t);var e=t.nodeType;if(e&&c[e]){for(var i=t.querySelectorAll("img"),n=0;n<i.length;n++){var o=i[n];this.addImage(o)}if("string"==typeof this.options.background){var r=t.querySelectorAll(this.options.background);for(n=0;n<r.length;n++){var s=r[n];this.addElementBackgroundImages(s)}}}};var c={1:!0,9:!0,11:!0};return o.prototype.addElementBackgroundImages=function(t){var e=getComputedStyle(t);if(e)for(var i=/url\((['"])?(.*?)\1\)/gi,n=i.exec(e.backgroundImage);null!==n;){var o=n&&n[2];o&&this.addBackground(o,t),n=i.exec(e.backgroundImage)}},o.prototype.addImage=function(t){var e=new r(t);this.images.push(e)},o.prototype.addBackground=function(t,e){var i=new s(t,e);this.images.push(i)},o.prototype.check=function(){function t(t,i,n){setTimeout(function(){e.progress(t,i,n)})}var e=this;return this.progressedCount=0,this.hasAnyBroken=!1,this.images.length?void this.images.forEach(function(e){e.once("progress",t),e.check()}):void this.complete()},o.prototype.progress=function(t,e,i){this.progressedCount++,this.hasAnyBroken=this.hasAnyBroken||!t.isLoaded,this.emitEvent("progress",[this,t,e]),this.jqDeferred&&this.jqDeferred.notify&&this.jqDeferred.notify(this,t),this.progressedCount==this.images.length&&this.complete(),this.options.debug&&a&&a.log("progress: "+i,t,e)},o.prototype.complete=function(){var t=this.hasAnyBroken?"fail":"done";if(this.isComplete=!0,this.emitEvent(t,[this]),this.emitEvent("always",[this]),this.jqDeferred){var e=this.hasAnyBroken?"reject":"resolve";this.jqDeferred[e](this)}},r.prototype=Object.create(e.prototype),r.prototype.check=function(){var t=this.getIsImageComplete();return t?void this.confirm(0!==this.img.naturalWidth,"naturalWidth"):(this.proxyImage=new Image,this.proxyImage.addEventListener("load",this),this.proxyImage.addEventListener("error",this),this.img.addEventListener("load",this),this.img.addEventListener("error",this),void(this.proxyImage.src=this.img.src))},r.prototype.getIsImageComplete=function(){return this.img.complete&&this.img.naturalWidth},r.prototype.confirm=function(t,e){this.isLoaded=t,this.emitEvent("progress",[this,this.img,e])},r.prototype.handleEvent=function(t){var e="on"+t.type;this[e]&&this[e](t)},r.prototype.onload=function(){this.confirm(!0,"onload"),this.unbindEvents()},r.prototype.onerror=function(){this.confirm(!1,"onerror"),this.unbindEvents()},r.prototype.unbindEvents=function(){this.proxyImage.removeEventListener("load",this),this.proxyImage.removeEventListener("error",this),this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},s.prototype=Object.create(r.prototype),s.prototype.check=function(){this.img.addEventListener("load",this),this.img.addEventListener("error",this),this.img.src=this.url;var t=this.getIsImageComplete();t&&(this.confirm(0!==this.img.naturalWidth,"naturalWidth"),this.unbindEvents())},s.prototype.unbindEvents=function(){this.img.removeEventListener("load",this),this.img.removeEventListener("error",this)},s.prototype.confirm=function(t,e){this.isLoaded=t,this.emitEvent("progress",[this,this.element,e])},o.makeJQueryPlugin=function(e){e=e||t.jQuery,e&&(l=e,l.fn.imagesLoaded=function(t,e){var i=new o(this,t,e);return i.jqDeferred.promise(l(this))})},o.makeJQueryPlugin(),o});
assets/jstree/jstree.js CHANGED
@@ -1,8589 +1,8605 @@
1
- /*globals jQuery, define, module, exports, require, window, document, postMessage */
2
- (function (factory) {
3
- "use strict";
4
- if (typeof define === 'function' && define.amd) {
5
- define(['jquery'], factory);
6
- }
7
- else if(typeof module !== 'undefined' && module.exports) {
8
- module.exports = factory(require('jquery'));
9
- }
10
- else {
11
- factory(jQuery);
12
- }
13
- }(function ($, undefined) {
14
- "use strict";
15
- /*!
16
- * jsTree 3.3.5
17
- * http://jstree.com/
18
- *
19
- * Copyright (c) 2014 Ivan Bozhanov (http://vakata.com)
20
- *
21
- * Licensed same as jquery - under the terms of the MIT License
22
- * http://www.opensource.org/licenses/mit-license.php
23
- */
24
- /*!
25
- * if using jslint please allow for the jQuery global and use following options:
26
- * jslint: loopfunc: true, browser: true, ass: true, bitwise: true, continue: true, nomen: true, plusplus: true, regexp: true, unparam: true, todo: true, white: true
27
- */
28
- /*jshint -W083 */
29
-
30
- // prevent another load? maybe there is a better way?
31
- if($.jstree) {
32
- return;
33
- }
34
-
35
- /**
36
- * ### jsTree core functionality
37
- */
38
-
39
- // internal variables
40
- var instance_counter = 0,
41
- ccp_node = false,
42
- ccp_mode = false,
43
- ccp_inst = false,
44
- themes_loaded = [],
45
- src = $('script:last').attr('src'),
46
- document = window.document; // local variable is always faster to access then a global
47
-
48
- /**
49
- * holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
50
- * @name $.jstree
51
- */
52
- $.jstree = {
53
- /**
54
- * specifies the jstree version in use
55
- * @name $.jstree.version
56
- */
57
- version : '3.3.5',
58
- /**
59
- * holds all the default options used when creating new instances
60
- * @name $.jstree.defaults
61
- */
62
- defaults : {
63
- /**
64
- * configure which plugins will be active on an instance. Should be an array of strings, where each element is a plugin name. The default is `[]`
65
- * @name $.jstree.defaults.plugins
66
- */
67
- plugins : []
68
- },
69
- /**
70
- * stores all loaded jstree plugins (used internally)
71
- * @name $.jstree.plugins
72
- */
73
- plugins : {},
74
- path : src && src.indexOf('/') !== -1 ? src.replace(/\/[^\/]+$/,'') : '',
75
- idregex : /[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,
76
- root : '#'
77
- };
78
-
79
- /**
80
- * creates a jstree instance
81
- * @name $.jstree.create(el [, options])
82
- * @param {DOMElement|jQuery|String} el the element to create the instance on, can be jQuery extended or a selector
83
- * @param {Object} options options for this instance (extends `$.jstree.defaults`)
84
- * @return {jsTree} the new instance
85
- */
86
- $.jstree.create = function (el, options) {
87
- var tmp = new $.jstree.core(++instance_counter),
88
- opt = options;
89
- options = $.extend(true, {}, $.jstree.defaults, options);
90
- if(opt && opt.plugins) {
91
- options.plugins = opt.plugins;
92
- }
93
- $.each(options.plugins, function (i, k) {
94
- if(i !== 'core') {
95
- tmp = tmp.plugin(k, options[k]);
96
- }
97
- });
98
- $(el).data('jstree', tmp);
99
- tmp.init(el, options);
100
- return tmp;
101
- };
102
- /**
103
- * remove all traces of jstree from the DOM and destroy all instances
104
- * @name $.jstree.destroy()
105
- */
106
- $.jstree.destroy = function () {
107
- $('.jstree:jstree').jstree('destroy');
108
- $(document).off('.jstree');
109
- };
110
- /**
111
- * the jstree class constructor, used only internally
112
- * @private
113
- * @name $.jstree.core(id)
114
- * @param {Number} id this instance's index
115
- */
116
- $.jstree.core = function (id) {
117
- this._id = id;
118
- this._cnt = 0;
119
- this._wrk = null;
120
- this._data = {
121
- core : {
122
- themes : {
123
- name : false,
124
- dots : false,
125
- icons : false,
126
- ellipsis : false
127
- },
128
- selected : [],
129
- last_error : {},
130
- working : false,
131
- worker_queue : [],
132
- focused : null
133
- }
134
- };
135
- };
136
- /**
137
- * get a reference to an existing instance
138
- *
139
- * __Examples__
140
- *
141
- * // provided a container with an ID of "tree", and a nested node with an ID of "branch"
142
- * // all of there will return the same instance
143
- * $.jstree.reference('tree');
144
- * $.jstree.reference('#tree');
145
- * $.jstree.reference($('#tree'));
146
- * $.jstree.reference(document.getElementByID('tree'));
147
- * $.jstree.reference('branch');
148
- * $.jstree.reference('#branch');
149
- * $.jstree.reference($('#branch'));
150
- * $.jstree.reference(document.getElementByID('branch'));
151
- *
152
- * @name $.jstree.reference(needle)
153
- * @param {DOMElement|jQuery|String} needle
154
- * @return {jsTree|null} the instance or `null` if not found
155
- */
156
- $.jstree.reference = function (needle) {
157
- var tmp = null,
158
- obj = null;
159
- if(needle && needle.id && (!needle.tagName || !needle.nodeType)) { needle = needle.id; }
160
-
161
- if(!obj || !obj.length) {
162
- try { obj = $(needle); } catch (ignore) { }
163
- }
164
- if(!obj || !obj.length) {
165
- try { obj = $('#' + needle.replace($.jstree.idregex,'\\$&')); } catch (ignore) { }
166
- }
167
- if(obj && obj.length && (obj = obj.closest('.jstree')).length && (obj = obj.data('jstree'))) {
168
- tmp = obj;
169
- }
170
- else {
171
- $('.jstree').each(function () {
172
- var inst = $(this).data('jstree');
173
- if(inst && inst._model.data[needle]) {
174
- tmp = inst;
175
- return false;
176
- }
177
- });
178
- }
179
- return tmp;
180
- };
181
- /**
182
- * Create an instance, get an instance or invoke a command on a instance.
183
- *
184
- * If there is no instance associated with the current node a new one is created and `arg` is used to extend `$.jstree.defaults` for this new instance. There would be no return value (chaining is not broken).
185
- *
186
- * If there is an existing instance and `arg` is a string the command specified by `arg` is executed on the instance, with any additional arguments passed to the function. If the function returns a value it will be returned (chaining could break depending on function).
187
- *
188
- * If there is an existing instance and `arg` is not a string the instance itself is returned (similar to `$.jstree.reference`).
189
- *
190
- * In any other case - nothing is returned and chaining is not broken.
191
- *
192
- * __Examples__
193
- *
194
- * $('#tree1').jstree(); // creates an instance
195
- * $('#tree2').jstree({ plugins : [] }); // create an instance with some options
196
- * $('#tree1').jstree('open_node', '#branch_1'); // call a method on an existing instance, passing additional arguments
197
- * $('#tree2').jstree(); // get an existing instance (or create an instance)
198
- * $('#tree2').jstree(true); // get an existing instance (will not create new instance)
199
- * $('#branch_1').jstree().select_node('#branch_1'); // get an instance (using a nested element and call a method)
200
- *
201
- * @name $().jstree([arg])
202
- * @param {String|Object} arg
203
- * @return {Mixed}
204
- */
205
- $.fn.jstree = function (arg) {
206
- // check for string argument
207
- var is_method = (typeof arg === 'string'),
208
- args = Array.prototype.slice.call(arguments, 1),
209
- result = null;
210
- if(arg === true && !this.length) { return false; }
211
- this.each(function () {
212
- // get the instance (if there is one) and method (if it exists)
213
- var instance = $.jstree.reference(this),
214
- method = is_method && instance ? instance[arg] : null;
215
- // if calling a method, and method is available - execute on the instance
216
- result = is_method && method ?
217
- method.apply(instance, args) :
218
- null;
219
- // if there is no instance and no method is being called - create one
220
- if(!instance && !is_method && (arg === undefined || $.isPlainObject(arg))) {
221
- $.jstree.create(this, arg);
222
- }
223
- // if there is an instance and no method is called - return the instance
224
- if( (instance && !is_method) || arg === true ) {
225
- result = instance || false;
226
- }
227
- // if there was a method call which returned a result - break and return the value
228
- if(result !== null && result !== undefined) {
229
- return false;
230
- }
231
- });
232
- // if there was a method call with a valid return value - return that, otherwise continue the chain
233
- return result !== null && result !== undefined ?
234
- result : this;
235
- };
236
- /**
237
- * used to find elements containing an instance
238
- *
239
- * __Examples__
240
- *
241
- * $('div:jstree').each(function () {
242
- * $(this).jstree('destroy');
243
- * });
244
- *
245
- * @name $(':jstree')
246
- * @return {jQuery}
247
- */
248
- $.expr.pseudos.jstree = $.expr.createPseudo(function(search) {
249
- return function(a) {
250
- return $(a).hasClass('jstree') &&
251
- $(a).data('jstree') !== undefined;
252
- };
253
- });
254
-
255
- /**
256
- * stores all defaults for the core
257
- * @name $.jstree.defaults.core
258
- */
259
- $.jstree.defaults.core = {
260
- /**
261
- * data configuration
262
- *
263
- * If left as `false` the HTML inside the jstree container element is used to populate the tree (that should be an unordered list with list items).
264
- *
265
- * You can also pass in a HTML string or a JSON array here.
266
- *
267
- * It is possible to pass in a standard jQuery-like AJAX config and jstree will automatically determine if the response is JSON or HTML and use that to populate the tree.
268
- * In addition to the standard jQuery ajax options here you can suppy functions for `data` and `url`, the functions will be run in the current instance's scope and a param will be passed indicating which node is being loaded, the return value of those functions will be used.
269
- *
270
- * The last option is to specify a function, that function will receive the node being loaded as argument and a second param which is a function which should be called with the result.
271
- *
272
- * __Examples__
273
- *
274
- * // AJAX
275
- * $('#tree').jstree({
276
- * 'core' : {
277
- * 'data' : {
278
- * 'url' : '/get/children/',
279
- * 'data' : function (node) {
280
- * return { 'id' : node.id };
281
- * }
282
- * }
283
- * });
284
- *
285
- * // direct data
286
- * $('#tree').jstree({
287
- * 'core' : {
288
- * 'data' : [
289
- * 'Simple root node',
290
- * {
291
- * 'id' : 'node_2',
292
- * 'text' : 'Root node with options',
293
- * 'state' : { 'opened' : true, 'selected' : true },
294
- * 'children' : [ { 'text' : 'Child 1' }, 'Child 2']
295
- * }
296
- * ]
297
- * }
298
- * });
299
- *
300
- * // function
301
- * $('#tree').jstree({
302
- * 'core' : {
303
- * 'data' : function (obj, callback) {
304
- * callback.call(this, ['Root 1', 'Root 2']);
305
- * }
306
- * });
307
- *
308
- * @name $.jstree.defaults.core.data
309
- */
310
- data : false,
311
- /**
312
- * configure the various strings used throughout the tree
313
- *
314
- * You can use an object where the key is the string you need to replace and the value is your replacement.
315
- * Another option is to specify a function which will be called with an argument of the needed string and should return the replacement.
316
- * If left as `false` no replacement is made.
317
- *
318
- * __Examples__
319
- *
320
- * $('#tree').jstree({
321
- * 'core' : {
322
- * 'strings' : {
323
- * 'Loading ...' : 'Please wait ...'
324
- * }
325
- * }
326
- * });
327
- *
328
- * @name $.jstree.defaults.core.strings
329
- */
330
- strings : false,
331
- /**
332
- * determines what happens when a user tries to modify the structure of the tree
333
- * If left as `false` all operations like create, rename, delete, move or copy are prevented.
334
- * You can set this to `true` to allow all interactions or use a function to have better control.
335
- *
336
- * __Examples__
337
- *
338
- * $('#tree').jstree({
339
- * 'core' : {
340
- * 'check_callback' : function (operation, node, node_parent, node_position, more) {
341
- * // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node', 'copy_node' or 'edit'
342
- * // in case of 'rename_node' node_position is filled with the new node name
343
- * return operation === 'rename_node' ? true : false;
344
- * }
345
- * }
346
- * });
347
- *
348
- * @name $.jstree.defaults.core.check_callback
349
- */
350
- check_callback : false,
351
- /**
352
- * a callback called with a single object parameter in the instance's scope when something goes wrong (operation prevented, ajax failed, etc)
353
- * @name $.jstree.defaults.core.error
354
- */
355
- error : $.noop,
356
- /**
357
- * the open / close animation duration in milliseconds - set this to `false` to disable the animation (default is `200`)
358
- * @name $.jstree.defaults.core.animation
359
- */
360
- animation : 200,
361
- /**
362
- * a boolean indicating if multiple nodes can be selected
363
- * @name $.jstree.defaults.core.multiple
364
- */
365
- multiple : true,
366
- /**
367
- * theme configuration object
368
- * @name $.jstree.defaults.core.themes
369
- */
370
- themes : {
371
- /**
372
- * the name of the theme to use (if left as `false` the default theme is used)
373
- * @name $.jstree.defaults.core.themes.name
374
- */
375
- name : false,
376
- /**
377
- * the URL of the theme's CSS file, leave this as `false` if you have manually included the theme CSS (recommended). You can set this to `true` too which will try to autoload the theme.
378
- * @name $.jstree.defaults.core.themes.url
379
- */
380
- url : false,
381
- /**
382
- * the location of all jstree themes - only used if `url` is set to `true`
383
- * @name $.jstree.defaults.core.themes.dir
384
- */
385
- dir : false,
386
- /**
387
- * a boolean indicating if connecting dots are shown
388
- * @name $.jstree.defaults.core.themes.dots
389
- */
390
- dots : true,
391
- /**
392
- * a boolean indicating if node icons are shown
393
- * @name $.jstree.defaults.core.themes.icons
394
- */
395
- icons : true,
396
- /**
397
- * a boolean indicating if node ellipsis should be shown - this only works with a fixed with on the container
398
- * @name $.jstree.defaults.core.themes.ellipsis
399
- */
400
- ellipsis : false,
401
- /**
402
- * a boolean indicating if the tree background is striped
403
- * @name $.jstree.defaults.core.themes.stripes
404
- */
405
- stripes : false,
406
- /**
407
- * a string (or boolean `false`) specifying the theme variant to use (if the theme supports variants)
408
- * @name $.jstree.defaults.core.themes.variant
409
- */
410
- variant : false,
411
- /**
412
- * a boolean specifying if a reponsive version of the theme should kick in on smaller screens (if the theme supports it). Defaults to `false`.
413
- * @name $.jstree.defaults.core.themes.responsive
414
- */
415
- responsive : false
416
- },
417
- /**
418
- * if left as `true` all parents of all selected nodes will be opened once the tree loads (so that all selected nodes are visible to the user)
419
- * @name $.jstree.defaults.core.expand_selected_onload
420
- */
421
- expand_selected_onload : true,
422
- /**
423
- * if left as `true` web workers will be used to parse incoming JSON data where possible, so that the UI will not be blocked by large requests. Workers are however about 30% slower. Defaults to `true`
424
- * @name $.jstree.defaults.core.worker
425
- */
426
- worker : true,
427
- /**
428
- * Force node text to plain text (and escape HTML). Defaults to `false`
429
- * @name $.jstree.defaults.core.force_text
430
- */
431
- force_text : false,
432
- /**
433
- * Should the node should be toggled if the text is double clicked . Defaults to `true`
434
- * @name $.jstree.defaults.core.dblclick_toggle
435
- */
436
- dblclick_toggle : true,
437
- /**
438
- * Should the loaded nodes be part of the state. Defaults to `false`
439
- * @name $.jstree.defaults.core.loaded_state
440
- */
441
- loaded_state : false,
442
- /**
443
- * Should the last active node be focused when the tree container is blurred and the focused again. This helps working with screen readers. Defaults to `true`
444
- * @name $.jstree.defaults.core.restore_focus
445
- */
446
- restore_focus : true,
447
- /**
448
- * Default keyboard shortcuts (an object where each key is the button name or combo - like 'enter', 'ctrl-space', 'p', etc and the value is the function to execute in the instance's scope)
449
- * @name $.jstree.defaults.core.keyboard
450
- */
451
- keyboard : {
452
- 'ctrl-space': function (e) {
453
- // aria defines space only with Ctrl
454
- e.type = "click";
455
- $(e.currentTarget).trigger(e);
456
- },
457
- 'enter': function (e) {
458
- // enter
459
- e.type = "click";
460
- $(e.currentTarget).trigger(e);
461
- },
462
- 'left': function (e) {
463
- // left
464
- e.preventDefault();
465
- if(this.is_open(e.currentTarget)) {
466
- this.close_node(e.currentTarget);
467
- }
468
- else {
469
- var o = this.get_parent(e.currentTarget);
470
- if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
471
- }
472
- },
473
- 'up': function (e) {
474
- // up
475
- e.preventDefault();
476
- var o = this.get_prev_dom(e.currentTarget);
477
- if(o && o.length) { o.children('.jstree-anchor').focus(); }
478
- },
479
- 'right': function (e) {
480
- // right
481
- e.preventDefault();
482
- if(this.is_closed(e.currentTarget)) {
483
- this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
484
- }
485
- else if (this.is_open(e.currentTarget)) {
486
- var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
487
- if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
488
- }
489
- },
490
- 'down': function (e) {
491
- // down
492
- e.preventDefault();
493
- var o = this.get_next_dom(e.currentTarget);
494
- if(o && o.length) { o.children('.jstree-anchor').focus(); }
495
- },
496
- '*': function (e) {
497
- // aria defines * on numpad as open_all - not very common
498
- this.open_all();
499
- },
500
- 'home': function (e) {
501
- // home
502
- e.preventDefault();
503
- var o = this._firstChild(this.get_container_ul()[0]);
504
- if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
505
- },
506
- 'end': function (e) {
507
- // end
508
- e.preventDefault();
509
- this.element.find('.jstree-anchor').filter(':visible').last().focus();
510
- },
511
- 'f2': function (e) {
512
- // f2 - safe to include - if check_callback is false it will fail
513
- e.preventDefault();
514
- this.edit(e.currentTarget);
515
- }
516
- }
517
- };
518
- $.jstree.core.prototype = {
519
- /**
520
- * used to decorate an instance with a plugin. Used internally.
521
- * @private
522
- * @name plugin(deco [, opts])
523
- * @param {String} deco the plugin to decorate with
524
- * @param {Object} opts options for the plugin
525
- * @return {jsTree}
526
- */
527
- plugin : function (deco, opts) {
528
- var Child = $.jstree.plugins[deco];
529
- if(Child) {
530
- this._data[deco] = {};
531
- Child.prototype = this;
532
- return new Child(opts, this);
533
- }
534
- return this;
535
- },
536
- /**
537
- * initialize the instance. Used internally.
538
- * @private
539
- * @name init(el, optons)
540
- * @param {DOMElement|jQuery|String} el the element we are transforming
541
- * @param {Object} options options for this instance
542
- * @trigger init.jstree, loading.jstree, loaded.jstree, ready.jstree, changed.jstree
543
- */
544
- init : function (el, options) {
545
- this._model = {
546
- data : {},
547
- changed : [],
548
- force_full_redraw : false,
549
- redraw_timeout : false,
550
- default_state : {
551
- loaded : true,
552
- opened : false,
553
- selected : false,
554
- disabled : false
555
- }
556
- };
557
- this._model.data[$.jstree.root] = {
558
- id : $.jstree.root,
559
- parent : null,
560
- parents : [],
561
- children : [],
562
- children_d : [],
563
- state : { loaded : false }
564
- };
565
-
566
- this.element = $(el).addClass('jstree jstree-' + this._id);
567
- this.settings = options;
568
-
569
- this._data.core.ready = false;
570
- this._data.core.loaded = false;
571
- this._data.core.rtl = (this.element.css("direction") === "rtl");
572
- this.element[this._data.core.rtl ? 'addClass' : 'removeClass']("jstree-rtl");
573
- this.element.attr('role','tree');
574
- if(this.settings.core.multiple) {
575
- this.element.attr('aria-multiselectable', true);
576
- }
577
- if(!this.element.attr('tabindex')) {
578
- this.element.attr('tabindex','0');
579
- }
580
-
581
- this.bind();
582
- /**
583
- * triggered after all events are bound
584
- * @event
585
- * @name init.jstree
586
- */
587
- this.trigger("init");
588
-
589
- this._data.core.original_container_html = this.element.find(" > ul > li").clone(true);
590
- this._data.core.original_container_html
591
- .find("li").addBack()
592
- .contents().filter(function() {
593
- return this.nodeType === 3 && (!this.nodeValue || /^\s+$/.test(this.nodeValue));
594
- })
595
- .remove();
596
- this.element.html("<"+"ul class='jstree-container-ul jstree-children' role='group'><"+"li id='j"+this._id+"_loading' class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='tree-item'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
597
- this.element.attr('aria-activedescendant','j' + this._id + '_loading');
598
- this._data.core.li_height = this.get_container_ul().children("li").first().outerHeight() || 24;
599
- this._data.core.node = this._create_prototype_node();
600
- /**
601
- * triggered after the loading text is shown and before loading starts
602
- * @event
603
- * @name loading.jstree
604
- */
605
- this.trigger("loading");
606
- this.load_node($.jstree.root);
607
- },
608
- /**
609
- * destroy an instance
610
- * @name destroy()
611
- * @param {Boolean} keep_html if not set to `true` the container will be emptied, otherwise the current DOM elements will be kept intact
612
- */
613
- destroy : function (keep_html) {
614
- /**
615
- * triggered before the tree is destroyed
616
- * @event
617
- * @name destroy.jstree
618
- */
619
- this.trigger("destroy");
620
- if(this._wrk) {
621
- try {
622
- window.URL.revokeObjectURL(this._wrk);
623
- this._wrk = null;
624
- }
625
- catch (ignore) { }
626
- }
627
- if(!keep_html) { this.element.empty(); }
628
- this.teardown();
629
- },
630
- /**
631
- * Create a prototype node
632
- * @name _create_prototype_node()
633
- * @return {DOMElement}
634
- */
635
- _create_prototype_node : function () {
636
- var _node = document.createElement('LI'), _temp1, _temp2;
637
- _node.setAttribute('role', 'treeitem');
638
- _temp1 = document.createElement('I');
639
- _temp1.className = 'jstree-icon jstree-ocl';
640
- _temp1.setAttribute('role', 'presentation');
641
- _node.appendChild(_temp1);
642
- _temp1 = document.createElement('A');
643
- _temp1.className = 'jstree-anchor';
644
- _temp1.setAttribute('href','#');
645
- _temp1.setAttribute('tabindex','-1');
646
- _temp2 = document.createElement('I');
647
- _temp2.className = 'jstree-icon jstree-themeicon';
648
- _temp2.setAttribute('role', 'presentation');
649
- _temp1.appendChild(_temp2);
650
- _node.appendChild(_temp1);
651
- _temp1 = _temp2 = null;
652
-
653
- return _node;
654
- },
655
- _kbevent_to_func : function (e) {
656
- var keys = {
657
- 8: "Backspace", 9: "Tab", 13: "Return", 19: "Pause", 27: "Esc",
658
- 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home",
659
- 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "Print", 45: "Insert",
660
- 46: "Delete", 96: "Numpad0", 97: "Numpad1", 98: "Numpad2", 99 : "Numpad3",
661
- 100: "Numpad4", 101: "Numpad5", 102: "Numpad6", 103: "Numpad7",
662
- 104: "Numpad8", 105: "Numpad9", '-13': "NumpadEnter", 112: "F1",
663
- 113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7",
664
- 119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 144: "Numlock",
665
- 145: "Scrolllock", 16: 'Shift', 17: 'Ctrl', 18: 'Alt',
666
- 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
667
- 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
668
- 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
669
- 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
670
- 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
671
- 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
672
- 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
673
- 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*', 173: '-'
674
- };
675
- var parts = [];
676
- if (e.ctrlKey) { parts.push('ctrl'); }
677
- if (e.altKey) { parts.push('alt'); }
678
- if (e.shiftKey) { parts.push('shift'); }
679
- parts.push(keys[e.which] || e.which);
680
- parts = parts.sort().join('-').toLowerCase();
681
-
682
- var kb = this.settings.core.keyboard, i, tmp;
683
- for (i in kb) {
684
- if (kb.hasOwnProperty(i)) {
685
- tmp = i;
686
- if (tmp !== '-' && tmp !== '+') {
687
- tmp = tmp.replace('--', '-MINUS').replace('+-', '-MINUS').replace('++', '-PLUS').replace('-+', '-PLUS');
688
- tmp = tmp.split(/-|\+/).sort().join('-').replace('MINUS', '-').replace('PLUS', '+').toLowerCase();
689
- }
690
- if (tmp === parts) {
691
- return kb[i];
692
- }
693
- }
694
- }
695
- return null;
696
- },
697
- /**
698
- * part of the destroying of an instance. Used internally.
699
- * @private
700
- * @name teardown()
701
- */
702
- teardown : function () {
703
- this.unbind();
704
- this.element
705
- .removeClass('jstree')
706
- .removeData('jstree')
707
- .find("[class^='jstree']")
708
- .addBack()
709
- .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
710
- this.element = null;
711
- },
712
- /**
713
- * bind all events. Used internally.
714
- * @private
715
- * @name bind()
716
- */
717
- bind : function () {
718
- var word = '',
719
- tout = null,
720
- was_click = 0;
721
- this.element
722
- .on("dblclick.jstree", function (e) {
723
- if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
724
- if(document.selection && document.selection.empty) {
725
- document.selection.empty();
726
- }
727
- else {
728
- if(window.getSelection) {
729
- var sel = window.getSelection();
730
- try {
731
- sel.removeAllRanges();
732
- sel.collapse();
733
- } catch (ignore) { }
734
- }
735
- }
736
- })
737
- .on("mousedown.jstree", $.proxy(function (e) {
738
- if(e.target === this.element[0]) {
739
- e.preventDefault(); // prevent losing focus when clicking scroll arrows (FF, Chrome)
740
- was_click = +(new Date()); // ie does not allow to prevent losing focus
741
- }
742
- }, this))
743
- .on("mousedown.jstree", ".jstree-ocl", function (e) {
744
- e.preventDefault(); // prevent any node inside from losing focus when clicking the open/close icon
745
- })
746
- .on("click.jstree", ".jstree-ocl", $.proxy(function (e) {
747
- this.toggle_node(e.target);
748
- }, this))
749
- .on("dblclick.jstree", ".jstree-anchor", $.proxy(function (e) {
750
- if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
751
- if(this.settings.core.dblclick_toggle) {
752
- this.toggle_node(e.target);
753
- }
754
- }, this))
755
- .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
756
- e.preventDefault();
757
- if(e.currentTarget !== document.activeElement) { $(e.currentTarget).focus(); }
758
- this.activate_node(e.currentTarget, e);
759
- }, this))
760
- .on('keydown.jstree', '.jstree-anchor', $.proxy(function (e) {
761
- if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
762
- if(this._data.core.rtl) {
763
- if(e.which === 37) { e.which = 39; }
764
- else if(e.which === 39) { e.which = 37; }
765
- }
766
- var f = this._kbevent_to_func(e);
767
- if (f) {
768
- var r = f.call(this, e);
769
- if (r === false || r === true) {
770
- return r;
771
- }
772
- }
773
- }, this))
774
- .on("load_node.jstree", $.proxy(function (e, data) {
775
- if(data.status) {
776
- if(data.node.id === $.jstree.root && !this._data.core.loaded) {
777
- this._data.core.loaded = true;
778
- if(this._firstChild(this.get_container_ul()[0])) {
779
- this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
780
- }
781
- /**
782
- * triggered after the root node is loaded for the first time
783
- * @event
784
- * @name loaded.jstree
785
- */
786
- this.trigger("loaded");
787
- }
788
- if(!this._data.core.ready) {
789
- setTimeout($.proxy(function() {
790
- if(this.element && !this.get_container_ul().find('.jstree-loading').length) {
791
- this._data.core.ready = true;
792
- if(this._data.core.selected.length) {
793
- if(this.settings.core.expand_selected_onload) {
794
- var tmp = [], i, j;
795
- for(i = 0, j = this._data.core.selected.length; i < j; i++) {
796
- tmp = tmp.concat(this._model.data[this._data.core.selected[i]].parents);
797
- }
798
- tmp = $.vakata.array_unique(tmp);
799
- for(i = 0, j = tmp.length; i < j; i++) {
800
- this.open_node(tmp[i], false, 0);
801
- }
802
- }
803
- this.trigger('changed', { 'action' : 'ready', 'selected' : this._data.core.selected });
804
- }
805
- /**
806
- * triggered after all nodes are finished loading
807
- * @event
808
- * @name ready.jstree
809
- */
810
- this.trigger("ready");
811
- }
812
- }, this), 0);
813
- }
814
- }
815
- }, this))
816
- // quick searching when the tree is focused
817
- .on('keypress.jstree', $.proxy(function (e) {
818
- if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
819
- if(tout) { clearTimeout(tout); }
820
- tout = setTimeout(function () {
821
- word = '';
822
- }, 500);
823
-
824
- var chr = String.fromCharCode(e.which).toLowerCase(),
825
- col = this.element.find('.jstree-anchor').filter(':visible'),
826
- ind = col.index(document.activeElement) || 0,
827
- end = false;
828
- word += chr;
829
-
830
- // match for whole word from current node down (including the current node)
831
- if(word.length > 1) {
832
- col.slice(ind).each($.proxy(function (i, v) {
833
- if($(v).text().toLowerCase().indexOf(word) === 0) {
834
- $(v).focus();
835
- end = true;
836
- return false;
837
- }
838
- }, this));
839
- if(end) { return; }
840
-
841
- // match for whole word from the beginning of the tree
842
- col.slice(0, ind).each($.proxy(function (i, v) {
843
- if($(v).text().toLowerCase().indexOf(word) === 0) {
844
- $(v).focus();
845
- end = true;
846
- return false;
847
- }
848
- }, this));
849
- if(end) { return; }
850
- }
851
- // list nodes that start with that letter (only if word consists of a single char)
852
- if(new RegExp('^' + chr.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '+$').test(word)) {
853
- // search for the next node starting with that letter
854
- col.slice(ind + 1).each($.proxy(function (i, v) {
855
- if($(v).text().toLowerCase().charAt(0) === chr) {
856
- $(v).focus();
857
- end = true;
858
- return false;
859
- }
860
- }, this));
861
- if(end) { return; }
862
-
863
- // search from the beginning
864
- col.slice(0, ind + 1).each($.proxy(function (i, v) {
865
- if($(v).text().toLowerCase().charAt(0) === chr) {
866
- $(v).focus();
867
- end = true;
868
- return false;
869
- }
870
- }, this));
871
- if(end) { return; }
872
- }
873
- }, this))
874
- // THEME RELATED
875
- .on("init.jstree", $.proxy(function () {
876
- var s = this.settings.core.themes;
877
- this._data.core.themes.dots = s.dots;
878
- this._data.core.themes.stripes = s.stripes;
879
- this._data.core.themes.icons = s.icons;
880
- this._data.core.themes.ellipsis = s.ellipsis;
881
- this.set_theme(s.name || "default", s.url);
882
- this.set_theme_variant(s.variant);
883
- }, this))
884
- .on("loading.jstree", $.proxy(function () {
885
- this[ this._data.core.themes.dots ? "show_dots" : "hide_dots" ]();
886
- this[ this._data.core.themes.icons ? "show_icons" : "hide_icons" ]();
887
- this[ this._data.core.themes.stripes ? "show_stripes" : "hide_stripes" ]();
888
- this[ this._data.core.themes.ellipsis ? "show_ellipsis" : "hide_ellipsis" ]();
889
- }, this))
890
- .on('blur.jstree', '.jstree-anchor', $.proxy(function (e) {
891
- this._data.core.focused = null;
892
- $(e.currentTarget).filter('.jstree-hovered').mouseleave();
893
- this.element.attr('tabindex', '0');
894
- }, this))
895
- .on('focus.jstree', '.jstree-anchor', $.proxy(function (e) {
896
- var tmp = this.get_node(e.currentTarget);
897
- if(tmp && tmp.id) {
898
- this._data.core.focused = tmp.id;
899
- }
900
- this.element.find('.jstree-hovered').not(e.currentTarget).mouseleave();
901
- $(e.currentTarget).mouseenter();
902
- this.element.attr('tabindex', '-1');
903
- }, this))
904
- .on('focus.jstree', $.proxy(function () {
905
- if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
906
- was_click = 0;
907
- var act = this.get_node(this.element.attr('aria-activedescendant'), true);
908
- if(act) {
909
- act.find('> .jstree-anchor').focus();
910
- }
911
- }
912
- }, this))
913
- .on('mouseenter.jstree', '.jstree-anchor', $.proxy(function (e) {
914
- this.hover_node(e.currentTarget);
915
- }, this))
916
- .on('mouseleave.jstree', '.jstree-anchor', $.proxy(function (e) {
917
- this.dehover_node(e.currentTarget);
918
- }, this));
919
- },
920
- /**
921
- * part of the destroying of an instance. Used internally.
922
- * @private
923
- * @name unbind()
924
- */
925
- unbind : function () {
926
- this.element.off('.jstree');
927
- $(document).off('.jstree-' + this._id);
928
- },
929
- /**
930
- * trigger an event. Used internally.
931
- * @private
932
- * @name trigger(ev [, data])
933
- * @param {String} ev the name of the event to trigger
934
- * @param {Object} data additional data to pass with the event
935
- */
936
- trigger : function (ev, data) {
937
- if(!data) {
938
- data = {};
939
- }
940
- data.instance = this;
941
- this.element.triggerHandler(ev.replace('.jstree','') + '.jstree', data);
942
- },
943
- /**
944
- * returns the jQuery extended instance container
945
- * @name get_container()
946
- * @return {jQuery}
947
- */
948
- get_container : function () {
949
- return this.element;
950
- },
951
- /**
952
- * returns the jQuery extended main UL node inside the instance container. Used internally.
953
- * @private
954
- * @name get_container_ul()
955
- * @return {jQuery}
956
- */
957
- get_container_ul : function () {
958
- return this.element.children(".jstree-children").first();
959
- },
960
- /**
961
- * gets string replacements (localization). Used internally.
962
- * @private
963
- * @name get_string(key)
964
- * @param {String} key
965
- * @return {String}
966
- */
967
- get_string : function (key) {
968
- var a = this.settings.core.strings;
969
- if($.isFunction(a)) { return a.call(this, key); }
970
- if(a && a[key]) { return a[key]; }
971
- return key;
972
- },
973
- /**
974
- * gets the first child of a DOM node. Used internally.
975
- * @private
976
- * @name _firstChild(dom)
977
- * @param {DOMElement} dom
978
- * @return {DOMElement}
979
- */
980
- _firstChild : function (dom) {
981
- dom = dom ? dom.firstChild : null;
982
- while(dom !== null && dom.nodeType !== 1) {
983
- dom = dom.nextSibling;
984
- }
985
- return dom;
986
- },
987
- /**
988
- * gets the next sibling of a DOM node. Used internally.
989
- * @private
990
- * @name _nextSibling(dom)
991
- * @param {DOMElement} dom
992
- * @return {DOMElement}
993
- */
994
- _nextSibling : function (dom) {
995
- dom = dom ? dom.nextSibling : null;
996
- while(dom !== null && dom.nodeType !== 1) {
997
- dom = dom.nextSibling;
998
- }
999
- return dom;
1000
- },
1001
- /**
1002
- * gets the previous sibling of a DOM node. Used internally.
1003
- * @private
1004
- * @name _previousSibling(dom)
1005
- * @param {DOMElement} dom
1006
- * @return {DOMElement}
1007
- */
1008
- _previousSibling : function (dom) {
1009
- dom = dom ? dom.previousSibling : null;
1010
- while(dom !== null && dom.nodeType !== 1) {
1011
- dom = dom.previousSibling;
1012
- }
1013
- return dom;
1014
- },
1015
- /**
1016
- * get the JSON representation of a node (or the actual jQuery extended DOM node) by using any input (child DOM element, ID string, selector, etc)
1017
- * @name get_node(obj [, as_dom])
1018
- * @param {mixed} obj
1019
- * @param {Boolean} as_dom
1020
- * @return {Object|jQuery}
1021
- */
1022
- get_node : function (obj, as_dom) {
1023
- if(obj && obj.id) {
1024
- obj = obj.id;
1025
- }
1026
- var dom;
1027
- try {
1028
- if(this._model.data[obj]) {
1029
- obj = this._model.data[obj];
1030
- }
1031
- else if(typeof obj === "string" && this._model.data[obj.replace(/^#/, '')]) {
1032
- obj = this._model.data[obj.replace(/^#/, '')];
1033
- }
1034
- else if(typeof obj === "string" && (dom = $('#' + obj.replace($.jstree.idregex,'\\$&'), this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
1035
- obj = this._model.data[dom.closest('.jstree-node').attr('id')];
1036
- }
1037
- else if((dom = $(obj, this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
1038
- obj = this._model.data[dom.closest('.jstree-node').attr('id')];
1039
- }
1040
- else if((dom = $(obj, this.element)).length && dom.hasClass('jstree')) {
1041
- obj = this._model.data[$.jstree.root];
1042
- }
1043
- else {
1044
- return false;
1045
- }
1046
-
1047
- if(as_dom) {
1048
- obj = obj.id === $.jstree.root ? this.element : $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
1049
- }
1050
- return obj;
1051
- } catch (ex) { return false; }
1052
- },
1053
- /**
1054
- * get the path to a node, either consisting of node texts, or of node IDs, optionally glued together (otherwise an array)
1055
- * @name get_path(obj [, glue, ids])
1056
- * @param {mixed} obj the node
1057
- * @param {String} glue if you want the path as a string - pass the glue here (for example '/'), if a falsy value is supplied here, an array is returned
1058
- * @param {Boolean} ids if set to true build the path using ID, otherwise node text is used
1059
- * @return {mixed}
1060
- */
1061
- get_path : function (obj, glue, ids) {
1062
- obj = obj.parents ? obj : this.get_node(obj);
1063
- if(!obj || obj.id === $.jstree.root || !obj.parents) {
1064
- return false;
1065
- }
1066
- var i, j, p = [];
1067
- p.push(ids ? obj.id : obj.text);
1068
- for(i = 0, j = obj.parents.length; i < j; i++) {
1069
- p.push(ids ? obj.parents[i] : this.get_text(obj.parents[i]));
1070
- }
1071
- p = p.reverse().slice(1);
1072
- return glue ? p.join(glue) : p;
1073
- },
1074
- /**
1075
- * get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
1076
- * @name get_next_dom(obj [, strict])
1077
- * @param {mixed} obj
1078
- * @param {Boolean} strict
1079
- * @return {jQuery}
1080
- */
1081
- get_next_dom : function (obj, strict) {
1082
- var tmp;
1083
- obj = this.get_node(obj, true);
1084
- if(obj[0] === this.element[0]) {
1085
- tmp = this._firstChild(this.get_container_ul()[0]);
1086
- while (tmp && tmp.offsetHeight === 0) {
1087
- tmp = this._nextSibling(tmp);
1088
- }
1089
- return tmp ? $(tmp) : false;
1090
- }
1091
- if(!obj || !obj.length) {
1092
- return false;
1093
- }
1094
- if(strict) {
1095
- tmp = obj[0];
1096
- do {
1097
- tmp = this._nextSibling(tmp);
1098
- } while (tmp && tmp.offsetHeight === 0);
1099
- return tmp ? $(tmp) : false;
1100
- }
1101
- if(obj.hasClass("jstree-open")) {
1102
- tmp = this._firstChild(obj.children('.jstree-children')[0]);
1103
- while (tmp && tmp.offsetHeight === 0) {
1104
- tmp = this._nextSibling(tmp);
1105
- }
1106
- if(tmp !== null) {
1107
- return $(tmp);
1108
- }
1109
- }
1110
- tmp = obj[0];
1111
- do {
1112
- tmp = this._nextSibling(tmp);
1113
- } while (tmp && tmp.offsetHeight === 0);
1114
- if(tmp !== null) {
1115
- return $(tmp);
1116
- }
1117
- return obj.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first();
1118
- },
1119
- /**
1120
- * get the previous visible node that is above the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
1121
- * @name get_prev_dom(obj [, strict])
1122
- * @param {mixed} obj
1123
- * @param {Boolean} strict
1124
- * @return {jQuery}
1125
- */
1126
- get_prev_dom : function (obj, strict) {
1127
- var tmp;
1128
- obj = this.get_node(obj, true);
1129
- if(obj[0] === this.element[0]) {
1130
- tmp = this.get_container_ul()[0].lastChild;
1131
- while (tmp && tmp.offsetHeight === 0) {
1132
- tmp = this._previousSibling(tmp);
1133
- }
1134
- return tmp ? $(tmp) : false;
1135
- }
1136
- if(!obj || !obj.length) {
1137
- return false;
1138
- }
1139
- if(strict) {
1140
- tmp = obj[0];
1141
- do {
1142
- tmp = this._previousSibling(tmp);
1143
- } while (tmp && tmp.offsetHeight === 0);
1144
- return tmp ? $(tmp) : false;
1145
- }
1146
- tmp = obj[0];
1147
- do {
1148
- tmp = this._previousSibling(tmp);
1149
- } while (tmp && tmp.offsetHeight === 0);
1150
- if(tmp !== null) {
1151
- obj = $(tmp);
1152
- while(obj.hasClass("jstree-open")) {
1153
- obj = obj.children(".jstree-children").first().children(".jstree-node:visible:last");
1154
- }
1155
- return obj;
1156
- }
1157
- tmp = obj[0].parentNode.parentNode;
1158
- return tmp && tmp.className && tmp.className.indexOf('jstree-node') !== -1 ? $(tmp) : false;
1159
- },
1160
- /**
1161
- * get the parent ID of a node
1162
- * @name get_parent(obj)
1163
- * @param {mixed} obj
1164
- * @return {String}
1165
- */
1166
- get_parent : function (obj) {
1167
- obj = this.get_node(obj);
1168
- if(!obj || obj.id === $.jstree.root) {
1169
- return false;
1170
- }
1171
- return obj.parent;
1172
- },
1173
- /**
1174
- * get a jQuery collection of all the children of a node (node must be rendered), returns false on error
1175
- * @name get_children_dom(obj)
1176
- * @param {mixed} obj
1177
- * @return {jQuery}
1178
- */
1179
- get_children_dom : function (obj) {
1180
- obj = this.get_node(obj, true);
1181
- if(obj[0] === this.element[0]) {
1182
- return this.get_container_ul().children(".jstree-node");
1183
- }
1184
- if(!obj || !obj.length) {
1185
- return false;
1186
- }
1187
- return obj.children(".jstree-children").children(".jstree-node");
1188
- },
1189
- /**
1190
- * checks if a node has children
1191
- * @name is_parent(obj)
1192
- * @param {mixed} obj
1193
- * @return {Boolean}
1194
- */
1195
- is_parent : function (obj) {
1196
- obj = this.get_node(obj);
1197
- return obj && (obj.state.loaded === false || obj.children.length > 0);
1198
- },
1199
- /**
1200
- * checks if a node is loaded (its children are available)
1201
- * @name is_loaded(obj)
1202
- * @param {mixed} obj
1203
- * @return {Boolean}
1204
- */
1205
- is_loaded : function (obj) {
1206
- obj = this.get_node(obj);
1207
- return obj && obj.state.loaded;
1208
- },
1209
- /**
1210
- * check if a node is currently loading (fetching children)
1211
- * @name is_loading(obj)
1212
- * @param {mixed} obj
1213
- * @return {Boolean}
1214
- */
1215
- is_loading : function (obj) {
1216
- obj = this.get_node(obj);
1217
- return obj && obj.state && obj.state.loading;
1218
- },
1219
- /**
1220
- * check if a node is opened
1221
- * @name is_open(obj)
1222
- * @param {mixed} obj
1223
- * @return {Boolean}
1224
- */
1225
- is_open : function (obj) {
1226
- obj = this.get_node(obj);
1227
- return obj && obj.state.opened;
1228
- },
1229
- /**
1230
- * check if a node is in a closed state
1231
- * @name is_closed(obj)
1232
- * @param {mixed} obj
1233
- * @return {Boolean}
1234
- */
1235
- is_closed : function (obj) {
1236
- obj = this.get_node(obj);
1237
- return obj && this.is_parent(obj) && !obj.state.opened;
1238
- },
1239
- /**
1240
- * check if a node has no children
1241
- * @name is_leaf(obj)
1242
- * @param {mixed} obj
1243
- * @return {Boolean}
1244
- */
1245
- is_leaf : function (obj) {
1246
- return !this.is_parent(obj);
1247
- },
1248
- /**
1249
- * loads a node (fetches its children using the `core.data` setting). Multiple nodes can be passed to by using an array.
1250
- * @name load_node(obj [, callback])
1251
- * @param {mixed} obj
1252
- * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives two arguments - the node and a boolean status
1253
- * @return {Boolean}
1254
- * @trigger load_node.jstree
1255
- */
1256
- load_node : function (obj, callback) {
1257
- var k, l, i, j, c;
1258
- if($.isArray(obj)) {
1259
- this._load_nodes(obj.slice(), callback);
1260
- return true;
1261
- }
1262
- obj = this.get_node(obj);
1263
- if(!obj) {
1264
- if(callback) { callback.call(this, obj, false); }
1265
- return false;
1266
- }
1267
- // if(obj.state.loading) { } // the node is already loading - just wait for it to load and invoke callback? but if called implicitly it should be loaded again?
1268
- if(obj.state.loaded) {
1269
- obj.state.loaded = false;
1270
- for(i = 0, j = obj.parents.length; i < j; i++) {
1271
- this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
1272
- return $.inArray(v, obj.children_d) === -1;
1273
- });
1274
- }
1275
- for(k = 0, l = obj.children_d.length; k < l; k++) {
1276
- if(this._model.data[obj.children_d[k]].state.selected) {
1277
- c = true;
1278
- }
1279
- delete this._model.data[obj.children_d[k]];
1280
- }
1281
- if (c) {
1282
- this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
1283
- return $.inArray(v, obj.children_d) === -1;
1284
- });
1285
- }
1286
- obj.children = [];
1287
- obj.children_d = [];
1288
- if(c) {
1289
- this.trigger('changed', { 'action' : 'load_node', 'node' : obj, 'selected' : this._data.core.selected });
1290
- }
1291
- }
1292
- obj.state.failed = false;
1293
- obj.state.loading = true;
1294
- this.get_node(obj, true).addClass("jstree-loading").attr('aria-busy',true);
1295
- this._load_node(obj, $.proxy(function (status) {
1296
- obj = this._model.data[obj.id];
1297
- obj.state.loading = false;
1298
- obj.state.loaded = status;
1299
- obj.state.failed = !obj.state.loaded;
1300
- var dom = this.get_node(obj, true), i = 0, j = 0, m = this._model.data, has_children = false;
1301
- for(i = 0, j = obj.children.length; i < j; i++) {
1302
- if(m[obj.children[i]] && !m[obj.children[i]].state.hidden) {
1303
- has_children = true;
1304
- break;
1305
- }
1306
- }
1307
- if(obj.state.loaded && dom && dom.length) {
1308
- dom.removeClass('jstree-closed jstree-open jstree-leaf');
1309
- if (!has_children) {
1310
- dom.addClass('jstree-leaf');
1311
- }
1312
- else {
1313
- if (obj.id !== '#') {
1314
- dom.addClass(obj.state.opened ? 'jstree-open' : 'jstree-closed');
1315
- }
1316
- }
1317
- }
1318
- dom.removeClass("jstree-loading").attr('aria-busy',false);
1319
- /**
1320
- * triggered after a node is loaded
1321
- * @event
1322
- * @name load_node.jstree
1323
- * @param {Object} node the node that was loading
1324
- * @param {Boolean} status was the node loaded successfully
1325
- */
1326
- this.trigger('load_node', { "node" : obj, "status" : status });
1327
- if(callback) {
1328
- callback.call(this, obj, status);
1329
- }
1330
- }, this));
1331
- return true;
1332
- },
1333
- /**
1334
- * load an array of nodes (will also load unavailable nodes as soon as the appear in the structure). Used internally.
1335
- * @private
1336
- * @name _load_nodes(nodes [, callback])
1337
- * @param {array} nodes
1338
- * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives one argument - the array passed to _load_nodes
1339
- */
1340
- _load_nodes : function (nodes, callback, is_callback, force_reload) {
1341
- var r = true,
1342
- c = function () { this._load_nodes(nodes, callback, true); },
1343
- m = this._model.data, i, j, tmp = [];
1344
- for(i = 0, j = nodes.length; i < j; i++) {
1345
- if(m[nodes[i]] && ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || (!is_callback && force_reload) )) {
1346
- if(!this.is_loading(nodes[i])) {
1347
- this.load_node(nodes[i], c);
1348
- }
1349
- r = false;
1350
- }
1351
- }
1352
- if(r) {
1353
- for(i = 0, j = nodes.length; i < j; i++) {
1354
- if(m[nodes[i]] && m[nodes[i]].state.loaded) {
1355
- tmp.push(nodes[i]);
1356
- }
1357
- }
1358
- if(callback && !callback.done) {
1359
- callback.call(this, tmp);
1360
- callback.done = true;
1361
- }
1362
- }
1363
- },
1364
- /**
1365
- * loads all unloaded nodes
1366
- * @name load_all([obj, callback])
1367
- * @param {mixed} obj the node to load recursively, omit to load all nodes in the tree
1368
- * @param {function} callback a function to be executed once loading all the nodes is complete,
1369
- * @trigger load_all.jstree
1370
- */
1371
- load_all : function (obj, callback) {
1372
- if(!obj) { obj = $.jstree.root; }
1373
- obj = this.get_node(obj);
1374
- if(!obj) { return false; }
1375
- var to_load = [],
1376
- m = this._model.data,
1377
- c = m[obj.id].children_d,
1378
- i, j;
1379
- if(obj.state && !obj.state.loaded) {
1380
- to_load.push(obj.id);
1381
- }
1382
- for(i = 0, j = c.length; i < j; i++) {
1383
- if(m[c[i]] && m[c[i]].state && !m[c[i]].state.loaded) {
1384
- to_load.push(c[i]);
1385
- }
1386
- }
1387
- if(to_load.length) {
1388
- this._load_nodes(to_load, function () {
1389
- this.load_all(obj, callback);
1390
- });
1391
- }
1392
- else {
1393
- /**
1394
- * triggered after a load_all call completes
1395
- * @event
1396
- * @name load_all.jstree
1397
- * @param {Object} node the recursively loaded node
1398
- */
1399
- if(callback) { callback.call(this, obj); }
1400
- this.trigger('load_all', { "node" : obj });
1401
- }
1402
- },
1403
- /**
1404
- * handles the actual loading of a node. Used only internally.
1405
- * @private
1406
- * @name _load_node(obj [, callback])
1407
- * @param {mixed} obj
1408
- * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives one argument - a boolean status
1409
- * @return {Boolean}
1410
- */
1411
- _load_node : function (obj, callback) {
1412
- var s = this.settings.core.data, t;
1413
- var notTextOrCommentNode = function notTextOrCommentNode () {
1414
- return this.nodeType !== 3 && this.nodeType !== 8;
1415
- };
1416
- // use original HTML
1417
- if(!s) {
1418
- if(obj.id === $.jstree.root) {
1419
- return this._append_html_data(obj, this._data.core.original_container_html.clone(true), function (status) {
1420
- callback.call(this, status);
1421
- });
1422
- }
1423
- else {
1424
- return callback.call(this, false);
1425
- }
1426
- // return callback.call(this, obj.id === $.jstree.root ? this._append_html_data(obj, this._data.core.original_container_html.clone(true)) : false);
1427
- }
1428
- if($.isFunction(s)) {
1429
- return s.call(this, obj, $.proxy(function (d) {
1430
- if(d === false) {
1431
- callback.call(this, false);
1432
- }
1433
- else {
1434
- this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $($.parseHTML(d)).filter(notTextOrCommentNode) : d, function (status) {
1435
- callback.call(this, status);
1436
- });
1437
- }
1438
- // return d === false ? callback.call(this, false) : callback.call(this, this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $(d) : d));
1439
- }, this));
1440
- }
1441
- if(typeof s === 'object') {
1442
- if(s.url) {
1443
- s = $.extend(true, {}, s);
1444
- if($.isFunction(s.url)) {
1445
- s.url = s.url.call(this, obj);
1446
- }
1447
- if($.isFunction(s.data)) {
1448
- s.data = s.data.call(this, obj);
1449
- }
1450
- return $.ajax(s)
1451
- .done($.proxy(function (d,t,x) {
1452
- var type = x.getResponseHeader('Content-Type');
1453
- if((type && type.indexOf('json') !== -1) || typeof d === "object") {
1454
- return this._append_json_data(obj, d, function (status) { callback.call(this, status); });
1455
- //return callback.call(this, this._append_json_data(obj, d));
1456
- }
1457
- if((type && type.indexOf('html') !== -1) || typeof d === "string") {
1458
- return this._append_html_data(obj, $($.parseHTML(d)).filter(notTextOrCommentNode), function (status) { callback.call(this, status); });
1459
- // return callback.call(this, this._append_html_data(obj, $(d)));
1460
- }
1461
- this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'core', 'id' : 'core_04', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id, 'xhr' : x }) };
1462
- this.settings.core.error.call(this, this._data.core.last_error);
1463
- return callback.call(this, false);
1464
- }, this))
1465
- .fail($.proxy(function (f) {
1466
- this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'core', 'id' : 'core_04', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id, 'xhr' : f }) };
1467
- callback.call(this, false);
1468
- this.settings.core.error.call(this, this._data.core.last_error);
1469
- }, this));
1470
- }
1471
- if ($.isArray(s)) {
1472
- t = $.extend(true, [], s);
1473
- } else if ($.isPlainObject(s)) {
1474
- t = $.extend(true, {}, s);
1475
- } else {
1476
- t = s;
1477
- }
1478
- if(obj.id === $.jstree.root) {
1479
- return this._append_json_data(obj, t, function (status) {
1480
- callback.call(this, status);
1481
- });
1482
- }
1483
- else {
1484
- this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_05', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
1485
- this.settings.core.error.call(this, this._data.core.last_error);
1486
- return callback.call(this, false);
1487
- }
1488
- //return callback.call(this, (obj.id === $.jstree.root ? this._append_json_data(obj, t) : false) );
1489
- }
1490
- if(typeof s === 'string') {
1491
- if(obj.id === $.jstree.root) {
1492
- return this._append_html_data(obj, $($.parseHTML(s)).filter(notTextOrCommentNode), function (status) {
1493
- callback.call(this, status);
1494
- });
1495
- }
1496
- else {
1497
- this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_06', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
1498
- this.settings.core.error.call(this, this._data.core.last_error);
1499
- return callback.call(this, false);
1500
- }
1501
- //return callback.call(this, (obj.id === $.jstree.root ? this._append_html_data(obj, $(s)) : false) );
1502
- }
1503
- return callback.call(this, false);
1504
- },
1505
- /**
1506
- * adds a node to the list of nodes to redraw. Used only internally.
1507
- * @private
1508
- * @name _node_changed(obj [, callback])
1509
- * @param {mixed} obj
1510
- */
1511
- _node_changed : function (obj) {
1512
- obj = this.get_node(obj);
1513
- if (obj && $.inArray(obj.id, this._model.changed) === -1) {
1514
- this._model.changed.push(obj.id);
1515
- }
1516
- },
1517
- /**
1518
- * appends HTML content to the tree. Used internally.
1519
- * @private
1520
- * @name _append_html_data(obj, data)
1521
- * @param {mixed} obj the node to append to
1522
- * @param {String} data the HTML string to parse and append
1523
- * @trigger model.jstree, changed.jstree
1524
- */
1525
- _append_html_data : function (dom, data, cb) {
1526
- dom = this.get_node(dom);
1527
- dom.children = [];
1528
- dom.children_d = [];
1529
- var dat = data.is('ul') ? data.children() : data,
1530
- par = dom.id,
1531
- chd = [],
1532
- dpc = [],
1533
- m = this._model.data,
1534
- p = m[par],
1535
- s = this._data.core.selected.length,
1536
- tmp, i, j;
1537
- dat.each($.proxy(function (i, v) {
1538
- tmp = this._parse_model_from_html($(v), par, p.parents.concat());
1539
- if(tmp) {
1540
- chd.push(tmp);
1541
- dpc.push(tmp);
1542
- if(m[tmp].children_d.length) {
1543
- dpc = dpc.concat(m[tmp].children_d);
1544
- }
1545
- }
1546
- }, this));
1547
- p.children = chd;
1548
- p.children_d = dpc;
1549
- for(i = 0, j = p.parents.length; i < j; i++) {
1550
- m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1551
- }
1552
- /**
1553
- * triggered when new data is inserted to the tree model
1554
- * @event
1555
- * @name model.jstree
1556
- * @param {Array} nodes an array of node IDs
1557
- * @param {String} parent the parent ID of the nodes
1558
- */
1559
- this.trigger('model', { "nodes" : dpc, 'parent' : par });
1560
- if(par !== $.jstree.root) {
1561
- this._node_changed(par);
1562
- this.redraw();
1563
- }
1564
- else {
1565
- this.get_container_ul().children('.jstree-initial-node').remove();
1566
- this.redraw(true);
1567
- }
1568
- if(this._data.core.selected.length !== s) {
1569
- this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
1570
- }
1571
- cb.call(this, true);
1572
- },
1573
- /**
1574
- * appends JSON content to the tree. Used internally.
1575
- * @private
1576
- * @name _append_json_data(obj, data)
1577
- * @param {mixed} obj the node to append to
1578
- * @param {String} data the JSON object to parse and append
1579
- * @param {Boolean} force_processing internal param - do not set
1580
- * @trigger model.jstree, changed.jstree
1581
- */
1582
- _append_json_data : function (dom, data, cb, force_processing) {
1583
- if(this.element === null) { return; }
1584
- dom = this.get_node(dom);
1585
- dom.children = [];
1586
- dom.children_d = [];
1587
- // *%$@!!!
1588
- if(data.d) {
1589
- data = data.d;
1590
- if(typeof data === "string") {
1591
- data = JSON.parse(data);
1592
- }
1593
- }
1594
- if(!$.isArray(data)) { data = [data]; }
1595
- var w = null,
1596
- args = {
1597
- 'df' : this._model.default_state,
1598
- 'dat' : data,
1599
- 'par' : dom.id,
1600
- 'm' : this._model.data,
1601
- 't_id' : this._id,
1602
- 't_cnt' : this._cnt,
1603
- 'sel' : this._data.core.selected
1604
- },
1605
- func = function (data, undefined) {
1606
- if(data.data) { data = data.data; }
1607
- var dat = data.dat,
1608
- par = data.par,
1609
- chd = [],
1610
- dpc = [],
1611
- add = [],
1612
- df = data.df,
1613
- t_id = data.t_id,
1614
- t_cnt = data.t_cnt,
1615
- m = data.m,
1616
- p = m[par],
1617
- sel = data.sel,
1618
- tmp, i, j, rslt,
1619
- parse_flat = function (d, p, ps) {
1620
- if(!ps) { ps = []; }
1621
- else { ps = ps.concat(); }
1622
- if(p) { ps.unshift(p); }
1623
- var tid = d.id.toString(),
1624
- i, j, c, e,
1625
- tmp = {
1626
- id : tid,
1627
- text : d.text || '',
1628
- icon : d.icon !== undefined ? d.icon : true,
1629
- parent : p,
1630
- parents : ps,
1631
- children : d.children || [],
1632
- children_d : d.children_d || [],
1633
- data : d.data,
1634
- state : { },
1635
- li_attr : { id : false },
1636
- a_attr : { href : '#' },
1637
- original : false
1638
- };
1639
- for(i in df) {
1640
- if(df.hasOwnProperty(i)) {
1641
- tmp.state[i] = df[i];
1642
- }
1643
- }
1644
- if(d && d.data && d.data.jstree && d.data.jstree.icon) {
1645
- tmp.icon = d.data.jstree.icon;
1646
- }
1647
- if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
1648
- tmp.icon = true;
1649
- }
1650
- if(d && d.data) {
1651
- tmp.data = d.data;
1652
- if(d.data.jstree) {
1653
- for(i in d.data.jstree) {
1654
- if(d.data.jstree.hasOwnProperty(i)) {
1655
- tmp.state[i] = d.data.jstree[i];
1656
- }
1657
- }
1658
- }
1659
- }
1660
- if(d && typeof d.state === 'object') {
1661
- for (i in d.state) {
1662
- if(d.state.hasOwnProperty(i)) {
1663
- tmp.state[i] = d.state[i];
1664
- }
1665
- }
1666
- }
1667
- if(d && typeof d.li_attr === 'object') {
1668
- for (i in d.li_attr) {
1669
- if(d.li_attr.hasOwnProperty(i)) {
1670
- tmp.li_attr[i] = d.li_attr[i];
1671
- }
1672
- }
1673
- }
1674
- if(!tmp.li_attr.id) {
1675
- tmp.li_attr.id = tid;
1676
- }
1677
- if(d && typeof d.a_attr === 'object') {
1678
- for (i in d.a_attr) {
1679
- if(d.a_attr.hasOwnProperty(i)) {
1680
- tmp.a_attr[i] = d.a_attr[i];
1681
- }
1682
- }
1683
- }
1684
- if(d && d.children && d.children === true) {
1685
- tmp.state.loaded = false;
1686
- tmp.children = [];
1687
- tmp.children_d = [];
1688
- }
1689
- m[tmp.id] = tmp;
1690
- for(i = 0, j = tmp.children.length; i < j; i++) {
1691
- c = parse_flat(m[tmp.children[i]], tmp.id, ps);
1692
- e = m[c];
1693
- tmp.children_d.push(c);
1694
- if(e.children_d.length) {
1695
- tmp.children_d = tmp.children_d.concat(e.children_d);
1696
- }
1697
- }
1698
- delete d.data;
1699
- delete d.children;
1700
- m[tmp.id].original = d;
1701
- if(tmp.state.selected) {
1702
- add.push(tmp.id);
1703
- }
1704
- return tmp.id;
1705
- },
1706
- parse_nest = function (d, p, ps) {
1707
- if(!ps) { ps = []; }
1708
- else { ps = ps.concat(); }
1709
- if(p) { ps.unshift(p); }
1710
- var tid = false, i, j, c, e, tmp;
1711
- do {
1712
- tid = 'j' + t_id + '_' + (++t_cnt);
1713
- } while(m[tid]);
1714
-
1715
- tmp = {
1716
- id : false,
1717
- text : typeof d === 'string' ? d : '',
1718
- icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
1719
- parent : p,
1720
- parents : ps,
1721
- children : [],
1722
- children_d : [],
1723
- data : null,
1724
- state : { },
1725
- li_attr : { id : false },
1726
- a_attr : { href : '#' },
1727
- original : false
1728
- };
1729
- for(i in df) {
1730
- if(df.hasOwnProperty(i)) {
1731
- tmp.state[i] = df[i];
1732
- }
1733
- }
1734
- if(d && d.id) { tmp.id = d.id.toString(); }
1735
- if(d && d.text) { tmp.text = d.text; }
1736
- if(d && d.data && d.data.jstree && d.data.jstree.icon) {
1737
- tmp.icon = d.data.jstree.icon;
1738
- }
1739
- if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
1740
- tmp.icon = true;
1741
- }
1742
- if(d && d.data) {
1743
- tmp.data = d.data;
1744
- if(d.data.jstree) {
1745
- for(i in d.data.jstree) {
1746
- if(d.data.jstree.hasOwnProperty(i)) {
1747
- tmp.state[i] = d.data.jstree[i];
1748
- }
1749
- }
1750
- }
1751
- }
1752
- if(d && typeof d.state === 'object') {
1753
- for (i in d.state) {
1754
- if(d.state.hasOwnProperty(i)) {
1755
- tmp.state[i] = d.state[i];
1756
- }
1757
- }
1758
- }
1759
- if(d && typeof d.li_attr === 'object') {
1760
- for (i in d.li_attr) {
1761
- if(d.li_attr.hasOwnProperty(i)) {
1762
- tmp.li_attr[i] = d.li_attr[i];
1763
- }
1764
- }
1765
- }
1766
- if(tmp.li_attr.id && !tmp.id) {
1767
- tmp.id = tmp.li_attr.id.toString();
1768
- }
1769
- if(!tmp.id) {
1770
- tmp.id = tid;
1771
- }
1772
- if(!tmp.li_attr.id) {
1773
- tmp.li_attr.id = tmp.id;
1774
- }
1775
- if(d && typeof d.a_attr === 'object') {
1776
- for (i in d.a_attr) {
1777
- if(d.a_attr.hasOwnProperty(i)) {
1778
- tmp.a_attr[i] = d.a_attr[i];
1779
- }
1780
- }
1781
- }
1782
- if(d && d.children && d.children.length) {
1783
- for(i = 0, j = d.children.length; i < j; i++) {
1784
- c = parse_nest(d.children[i], tmp.id, ps);
1785
- e = m[c];
1786
- tmp.children.push(c);
1787
- if(e.children_d.length) {
1788
- tmp.children_d = tmp.children_d.concat(e.children_d);
1789
- }
1790
- }
1791
- tmp.children_d = tmp.children_d.concat(tmp.children);
1792
- }
1793
- if(d && d.children && d.children === true) {
1794
- tmp.state.loaded = false;
1795
- tmp.children = [];
1796
- tmp.children_d = [];
1797
- }
1798
- delete d.data;
1799
- delete d.children;
1800
- tmp.original = d;
1801
- m[tmp.id] = tmp;
1802
- if(tmp.state.selected) {
1803
- add.push(tmp.id);
1804
- }
1805
- return tmp.id;
1806
- };
1807
-
1808
- if(dat.length && dat[0].id !== undefined && dat[0].parent !== undefined) {
1809
- // Flat JSON support (for easy import from DB):
1810
- // 1) convert to object (foreach)
1811
- for(i = 0, j = dat.length; i < j; i++) {
1812
- if(!dat[i].children) {
1813
- dat[i].children = [];
1814
- }
1815
- if(!dat[i].state) {
1816
- dat[i].state = {};
1817
- }
1818
- m[dat[i].id.toString()] = dat[i];
1819
- }
1820
- // 2) populate children (foreach)
1821
- for(i = 0, j = dat.length; i < j; i++) {
1822
- if (!m[dat[i].parent.toString()]) {
1823
- this._data.core.last_error = { 'error' : 'parse', 'plugin' : 'core', 'id' : 'core_07', 'reason' : 'Node with invalid parent', 'data' : JSON.stringify({ 'id' : dat[i].id.toString(), 'parent' : dat[i].parent.toString() }) };
1824
- this.settings.core.error.call(this, this._data.core.last_error);
1825
- continue;
1826
- }
1827
-
1828
- m[dat[i].parent.toString()].children.push(dat[i].id.toString());
1829
- // populate parent.children_d
1830
- p.children_d.push(dat[i].id.toString());
1831
- }
1832
- // 3) normalize && populate parents and children_d with recursion
1833
- for(i = 0, j = p.children.length; i < j; i++) {
1834
- tmp = parse_flat(m[p.children[i]], par, p.parents.concat());
1835
- dpc.push(tmp);
1836
- if(m[tmp].children_d.length) {
1837
- dpc = dpc.concat(m[tmp].children_d);
1838
- }
1839
- }
1840
- for(i = 0, j = p.parents.length; i < j; i++) {
1841
- m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1842
- }
1843
- // ?) three_state selection - p.state.selected && t - (if three_state foreach(dat => ch) -> foreach(parents) if(parent.selected) child.selected = true;
1844
- rslt = {
1845
- 'cnt' : t_cnt,
1846
- 'mod' : m,
1847
- 'sel' : sel,
1848
- 'par' : par,
1849
- 'dpc' : dpc,
1850
- 'add' : add
1851
- };
1852
- }
1853
- else {
1854
- for(i = 0, j = dat.length; i < j; i++) {
1855
- tmp = parse_nest(dat[i], par, p.parents.concat());
1856
- if(tmp) {
1857
- chd.push(tmp);
1858
- dpc.push(tmp);
1859
- if(m[tmp].children_d.length) {
1860
- dpc = dpc.concat(m[tmp].children_d);
1861
- }
1862
- }
1863
- }
1864
- p.children = chd;
1865
- p.children_d = dpc;
1866
- for(i = 0, j = p.parents.length; i < j; i++) {
1867
- m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1868
- }
1869
- rslt = {
1870
- 'cnt' : t_cnt,
1871
- 'mod' : m,
1872
- 'sel' : sel,
1873
- 'par' : par,
1874
- 'dpc' : dpc,
1875
- 'add' : add
1876
- };
1877
- }
1878
- if(typeof window === 'undefined' || typeof window.document === 'undefined') {
1879
- postMessage(rslt);
1880
- }
1881
- else {
1882
- return rslt;
1883
- }
1884
- },
1885
- rslt = function (rslt, worker) {
1886
- if(this.element === null) { return; }
1887
- this._cnt = rslt.cnt;
1888
- var i, m = this._model.data;
1889
- for (i in m) {
1890
- if (m.hasOwnProperty(i) && m[i].state && m[i].state.loading && rslt.mod[i]) {
1891
- rslt.mod[i].state.loading = true;
1892
- }
1893
- }
1894
- this._model.data = rslt.mod; // breaks the reference in load_node - careful
1895
-
1896
- if(worker) {
1897
- var j, a = rslt.add, r = rslt.sel, s = this._data.core.selected.slice();
1898
- m = this._model.data;
1899
- // if selection was changed while calculating in worker
1900
- if(r.length !== s.length || $.vakata.array_unique(r.concat(s)).length !== r.length) {
1901
- // deselect nodes that are no longer selected
1902
- for(i = 0, j = r.length; i < j; i++) {
1903
- if($.inArray(r[i], a) === -1 && $.inArray(r[i], s) === -1) {
1904
- m[r[i]].state.selected = false;
1905
- }
1906
- }
1907
- // select nodes that were selected in the mean time
1908
- for(i = 0, j = s.length; i < j; i++) {
1909
- if($.inArray(s[i], r) === -1) {
1910
- m[s[i]].state.selected = true;
1911
- }
1912
- }
1913
- }
1914
- }
1915
- if(rslt.add.length) {
1916
- this._data.core.selected = this._data.core.selected.concat(rslt.add);
1917
- }
1918
-
1919
- this.trigger('model', { "nodes" : rslt.dpc, 'parent' : rslt.par });
1920
-
1921
- if(rslt.par !== $.jstree.root) {
1922
- this._node_changed(rslt.par);
1923
- this.redraw();
1924
- }
1925
- else {
1926
- // this.get_container_ul().children('.jstree-initial-node').remove();
1927
- this.redraw(true);
1928
- }
1929
- if(rslt.add.length) {
1930
- this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
1931
- }
1932
- cb.call(this, true);
1933
- };
1934
- if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
1935
- try {
1936
- if(this._wrk === null) {
1937
- this._wrk = window.URL.createObjectURL(
1938
- new window.Blob(
1939
- ['self.onmessage = ' + func.toString()],
1940
- {type:"text/javascript"}
1941
- )
1942
- );
1943
- }
1944
- if(!this._data.core.working || force_processing) {
1945
- this._data.core.working = true;
1946
- w = new window.Worker(this._wrk);
1947
- w.onmessage = $.proxy(function (e) {
1948
- rslt.call(this, e.data, true);
1949
- try { w.terminate(); w = null; } catch(ignore) { }
1950
- if(this._data.core.worker_queue.length) {
1951
- this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1952
- }
1953
- else {
1954
- this._data.core.working = false;
1955
- }
1956
- }, this);
1957
- if(!args.par) {
1958
- if(this._data.core.worker_queue.length) {
1959
- this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1960
- }
1961
- else {
1962
- this._data.core.working = false;
1963
- }
1964
- }
1965
- else {
1966
- w.postMessage(args);
1967
- }
1968
- }
1969
- else {
1970
- this._data.core.worker_queue.push([dom, data, cb, true]);
1971
- }
1972
- }
1973
- catch(e) {
1974
- rslt.call(this, func(args), false);
1975
- if(this._data.core.worker_queue.length) {
1976
- this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1977
- }
1978
- else {
1979
- this._data.core.working = false;
1980
- }
1981
- }
1982
- }
1983
- else {
1984
- rslt.call(this, func(args), false);
1985
- }
1986
- },
1987
- /**
1988
- * parses a node from a jQuery object and appends them to the in memory tree model. Used internally.
1989
- * @private
1990
- * @name _parse_model_from_html(d [, p, ps])
1991
- * @param {jQuery} d the jQuery object to parse
1992
- * @param {String} p the parent ID
1993
- * @param {Array} ps list of all parents
1994
- * @return {String} the ID of the object added to the model
1995
- */
1996
- _parse_model_from_html : function (d, p, ps) {
1997
- if(!ps) { ps = []; }
1998
- else { ps = [].concat(ps); }
1999
- if(p) { ps.unshift(p); }
2000
- var c, e, m = this._model.data,
2001
- data = {
2002
- id : false,
2003
- text : false,
2004
- icon : true,
2005
- parent : p,
2006
- parents : ps,
2007
- children : [],
2008
- children_d : [],
2009
- data : null,
2010
- state : { },
2011
- li_attr : { id : false },
2012
- a_attr : { href : '#' },
2013
- original : false
2014
- }, i, tmp, tid;
2015
- for(i in this._model.default_state) {
2016
- if(this._model.default_state.hasOwnProperty(i)) {
2017
- data.state[i] = this._model.default_state[i];
2018
- }
2019
- }
2020
- tmp = $.vakata.attributes(d, true);
2021
- $.each(tmp, function (i, v) {
2022
- v = $.trim(v);
2023
- if(!v.length) { return true; }
2024
- data.li_attr[i] = v;
2025
- if(i === 'id') {
2026
- data.id = v.toString();
2027
- }
2028
- });
2029
- tmp = d.children('a').first();
2030
- if(tmp.length) {
2031
- tmp = $.vakata.attributes(tmp, true);
2032
- $.each(tmp, function (i, v) {
2033
- v = $.trim(v);
2034
- if(v.length) {
2035
- data.a_attr[i] = v;
2036
- }
2037
- });
2038
- }
2039
- tmp = d.children("a").first().length ? d.children("a").first().clone() : d.clone();
2040
- tmp.children("ins, i, ul").remove();
2041
- tmp = tmp.html();
2042
- tmp = $('<div />').html(tmp);
2043
- data.text = this.settings.core.force_text ? tmp.text() : tmp.html();
2044
- tmp = d.data();
2045
- data.data = tmp ? $.extend(true, {}, tmp) : null;
2046
- data.state.opened = d.hasClass('jstree-open');
2047
- data.state.selected = d.children('a').hasClass('jstree-clicked');
2048
- data.state.disabled = d.children('a').hasClass('jstree-disabled');
2049
- if(data.data && data.data.jstree) {
2050
- for(i in data.data.jstree) {
2051
- if(data.data.jstree.hasOwnProperty(i)) {
2052
- data.state[i] = data.data.jstree[i];
2053
- }
2054
- }
2055
- }
2056
- tmp = d.children("a").children(".jstree-themeicon");
2057
- if(tmp.length) {
2058
- data.icon = tmp.hasClass('jstree-themeicon-hidden') ? false : tmp.attr('rel');
2059
- }
2060
- if(data.state.icon !== undefined) {
2061
- data.icon = data.state.icon;
2062
- }
2063
- if(data.icon === undefined || data.icon === null || data.icon === "") {
2064
- data.icon = true;
2065
- }
2066
- tmp = d.children("ul").children("li");
2067
- do {
2068
- tid = 'j' + this._id + '_' + (++this._cnt);
2069
- } while(m[tid]);
2070
- data.id = data.li_attr.id ? data.li_attr.id.toString() : tid;
2071
- if(tmp.length) {
2072
- tmp.each($.proxy(function (i, v) {
2073
- c = this._parse_model_from_html($(v), data.id, ps);
2074
- e = this._model.data[c];
2075
- data.children.push(c);
2076
- if(e.children_d.length) {
2077
- data.children_d = data.children_d.concat(e.children_d);
2078
- }
2079
- }, this));
2080
- data.children_d = data.children_d.concat(data.children);
2081
- }
2082
- else {
2083
- if(d.hasClass('jstree-closed')) {
2084
- data.state.loaded = false;
2085
- }
2086
- }
2087
- if(data.li_attr['class']) {
2088
- data.li_attr['class'] = data.li_attr['class'].replace('jstree-closed','').replace('jstree-open','');
2089
- }
2090
- if(data.a_attr['class']) {
2091
- data.a_attr['class'] = data.a_attr['class'].replace('jstree-clicked','').replace('jstree-disabled','');
2092
- }
2093
- m[data.id] = data;
2094
- if(data.state.selected) {
2095
- this._data.core.selected.push(data.id);
2096
- }
2097
- return data.id;
2098
- },
2099
- /**
2100
- * parses a node from a JSON object (used when dealing with flat data, which has no nesting of children, but has id and parent properties) and appends it to the in memory tree model. Used internally.
2101
- * @private
2102
- * @name _parse_model_from_flat_json(d [, p, ps])
2103
- * @param {Object} d the JSON object to parse
2104
- * @param {String} p the parent ID
2105
- * @param {Array} ps list of all parents
2106
- * @return {String} the ID of the object added to the model
2107
- */
2108
- _parse_model_from_flat_json : function (d, p, ps) {
2109
- if(!ps) { ps = []; }
2110
- else { ps = ps.concat(); }
2111
- if(p) { ps.unshift(p); }
2112
- var tid = d.id.toString(),
2113
- m = this._model.data,
2114
- df = this._model.default_state,
2115
- i, j, c, e,
2116
- tmp = {
2117
- id : tid,
2118
- text : d.text || '',
2119
- icon : d.icon !== undefined ? d.icon : true,
2120
- parent : p,
2121
- parents : ps,
2122
- children : d.children || [],
2123
- children_d : d.children_d || [],
2124
- data : d.data,
2125
- state : { },
2126
- li_attr : { id : false },
2127
- a_attr : { href : '#' },
2128
- original : false
2129
- };
2130
- for(i in df) {
2131
- if(df.hasOwnProperty(i)) {
2132
- tmp.state[i] = df[i];
2133
- }
2134
- }
2135
- if(d && d.data && d.data.jstree && d.data.jstree.icon) {
2136
- tmp.icon = d.data.jstree.icon;
2137
- }
2138
- if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
2139
- tmp.icon = true;
2140
- }
2141
- if(d && d.data) {
2142
- tmp.data = d.data;
2143
- if(d.data.jstree) {
2144
- for(i in d.data.jstree) {
2145
- if(d.data.jstree.hasOwnProperty(i)) {
2146
- tmp.state[i] = d.data.jstree[i];
2147
- }
2148
- }
2149
- }
2150
- }
2151
- if(d && typeof d.state === 'object') {
2152
- for (i in d.state) {
2153
- if(d.state.hasOwnProperty(i)) {
2154
- tmp.state[i] = d.state[i];
2155
- }
2156
- }
2157
- }
2158
- if(d && typeof d.li_attr === 'object') {
2159
- for (i in d.li_attr) {
2160
- if(d.li_attr.hasOwnProperty(i)) {
2161
- tmp.li_attr[i] = d.li_attr[i];
2162
- }
2163
- }
2164
- }
2165
- if(!tmp.li_attr.id) {
2166
- tmp.li_attr.id = tid;
2167
- }
2168
- if(d && typeof d.a_attr === 'object') {
2169
- for (i in d.a_attr) {
2170
- if(d.a_attr.hasOwnProperty(i)) {
2171
- tmp.a_attr[i] = d.a_attr[i];
2172
- }
2173
- }
2174
- }
2175
- if(d && d.children && d.children === true) {
2176
- tmp.state.loaded = false;
2177
- tmp.children = [];
2178
- tmp.children_d = [];
2179
- }
2180
- m[tmp.id] = tmp;
2181
- for(i = 0, j = tmp.children.length; i < j; i++) {
2182
- c = this._parse_model_from_flat_json(m[tmp.children[i]], tmp.id, ps);
2183
- e = m[c];
2184
- tmp.children_d.push(c);
2185
- if(e.children_d.length) {
2186
- tmp.children_d = tmp.children_d.concat(e.children_d);
2187
- }
2188
- }
2189
- delete d.data;
2190
- delete d.children;
2191
- m[tmp.id].original = d;
2192
- if(tmp.state.selected) {
2193
- this._data.core.selected.push(tmp.id);
2194
- }
2195
- return tmp.id;
2196
- },
2197
- /**
2198
- * parses a node from a JSON object and appends it to the in memory tree model. Used internally.
2199
- * @private
2200
- * @name _parse_model_from_json(d [, p, ps])
2201
- * @param {Object} d the JSON object to parse
2202
- * @param {String} p the parent ID
2203
- * @param {Array} ps list of all parents
2204
- * @return {String} the ID of the object added to the model
2205
- */
2206
- _parse_model_from_json : function (d, p, ps) {
2207
- if(!ps) { ps = []; }
2208
- else { ps = ps.concat(); }
2209
- if(p) { ps.unshift(p); }
2210
- var tid = false, i, j, c, e, m = this._model.data, df = this._model.default_state, tmp;
2211
- do {
2212
- tid = 'j' + this._id + '_' + (++this._cnt);
2213
- } while(m[tid]);
2214
-
2215
- tmp = {
2216
- id : false,
2217
- text : typeof d === 'string' ? d : '',
2218
- icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
2219
- parent : p,
2220
- parents : ps,
2221
- children : [],
2222
- children_d : [],
2223
- data : null,
2224
- state : { },
2225
- li_attr : { id : false },
2226
- a_attr : { href : '#' },
2227
- original : false
2228
- };
2229
- for(i in df) {
2230
- if(df.hasOwnProperty(i)) {
2231
- tmp.state[i] = df[i];
2232
- }
2233
- }
2234
- if(d && d.id) { tmp.id = d.id.toString(); }
2235
- if(d && d.text) { tmp.text = d.text; }
2236
- if(d && d.data && d.data.jstree && d.data.jstree.icon) {
2237
- tmp.icon = d.data.jstree.icon;
2238
- }
2239
- if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
2240
- tmp.icon = true;
2241
- }
2242
- if(d && d.data) {
2243
- tmp.data = d.data;
2244
- if(d.data.jstree) {
2245
- for(i in d.data.jstree) {
2246
- if(d.data.jstree.hasOwnProperty(i)) {
2247
- tmp.state[i] = d.data.jstree[i];
2248
- }
2249
- }
2250
- }
2251
- }
2252
- if(d && typeof d.state === 'object') {
2253
- for (i in d.state) {
2254
- if(d.state.hasOwnProperty(i)) {
2255
- tmp.state[i] = d.state[i];
2256
- }
2257
- }
2258
- }
2259
- if(d && typeof d.li_attr === 'object') {
2260
- for (i in d.li_attr) {
2261
- if(d.li_attr.hasOwnProperty(i)) {
2262
- tmp.li_attr[i] = d.li_attr[i];
2263
- }
2264
- }
2265
- }
2266
- if(tmp.li_attr.id && !tmp.id) {
2267
- tmp.id = tmp.li_attr.id.toString();
2268
- }
2269
- if(!tmp.id) {
2270
- tmp.id = tid;
2271
- }
2272
- if(!tmp.li_attr.id) {
2273
- tmp.li_attr.id = tmp.id;
2274
- }
2275
- if(d && typeof d.a_attr === 'object') {
2276
- for (i in d.a_attr) {
2277
- if(d.a_attr.hasOwnProperty(i)) {
2278
- tmp.a_attr[i] = d.a_attr[i];
2279
- }
2280
- }
2281
- }
2282
- if(d && d.children && d.children.length) {
2283
- for(i = 0, j = d.children.length; i < j; i++) {
2284
- c = this._parse_model_from_json(d.children[i], tmp.id, ps);
2285
- e = m[c];
2286
- tmp.children.push(c);
2287
- if(e.children_d.length) {
2288
- tmp.children_d = tmp.children_d.concat(e.children_d);
2289
- }
2290
- }
2291
- tmp.children_d = tmp.children_d.concat(tmp.children);
2292
- }
2293
- if(d && d.children && d.children === true) {
2294
- tmp.state.loaded = false;
2295
- tmp.children = [];
2296
- tmp.children_d = [];
2297
- }
2298
- delete d.data;
2299
- delete d.children;
2300
- tmp.original = d;
2301
- m[tmp.id] = tmp;
2302
- if(tmp.state.selected) {
2303
- this._data.core.selected.push(tmp.id);
2304
- }
2305
- return tmp.id;
2306
- },
2307
- /**
2308
- * redraws all nodes that need to be redrawn. Used internally.
2309
- * @private
2310
- * @name _redraw()
2311
- * @trigger redraw.jstree
2312
- */
2313
- _redraw : function () {
2314
- var nodes = this._model.force_full_redraw ? this._model.data[$.jstree.root].children.concat([]) : this._model.changed.concat([]),
2315
- f = document.createElement('UL'), tmp, i, j, fe = this._data.core.focused;
2316
- for(i = 0, j = nodes.length; i < j; i++) {
2317
- tmp = this.redraw_node(nodes[i], true, this._model.force_full_redraw);
2318
- if(tmp && this._model.force_full_redraw) {
2319
- f.appendChild(tmp);
2320
- }
2321
- }
2322
- if(this._model.force_full_redraw) {
2323
- f.className = this.get_container_ul()[0].className;
2324
- f.setAttribute('role','group');
2325
- this.element.empty().append(f);
2326
- //this.get_container_ul()[0].appendChild(f);
2327
- }
2328
- if(fe !== null) {
2329
- tmp = this.get_node(fe, true);
2330
- if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
2331
- tmp.children('.jstree-anchor').focus();
2332
- }
2333
- else {
2334
- this._data.core.focused = null;
2335
- }
2336
- }
2337
- this._model.force_full_redraw = false;
2338
- this._model.changed = [];
2339
- /**
2340
- * triggered after nodes are redrawn
2341
- * @event
2342
- * @name redraw.jstree
2343
- * @param {array} nodes the redrawn nodes
2344
- */
2345
- this.trigger('redraw', { "nodes" : nodes });
2346
- },
2347
- /**
2348
- * redraws all nodes that need to be redrawn or optionally - the whole tree
2349
- * @name redraw([full])
2350
- * @param {Boolean} full if set to `true` all nodes are redrawn.
2351
- */
2352
- redraw : function (full) {
2353
- if(full) {
2354
- this._model.force_full_redraw = true;
2355
- }
2356
- //if(this._model.redraw_timeout) {
2357
- // clearTimeout(this._model.redraw_timeout);
2358
- //}
2359
- //this._model.redraw_timeout = setTimeout($.proxy(this._redraw, this),0);
2360
- this._redraw();
2361
- },
2362
- /**
2363
- * redraws a single node's children. Used internally.
2364
- * @private
2365
- * @name draw_children(node)
2366
- * @param {mixed} node the node whose children will be redrawn
2367
- */
2368
- draw_children : function (node) {
2369
- var obj = this.get_node(node),
2370
- i = false,
2371
- j = false,
2372
- k = false,
2373
- d = document;
2374
- if(!obj) { return false; }
2375
- if(obj.id === $.jstree.root) { return this.redraw(true); }
2376
- node = this.get_node(node, true);
2377
- if(!node || !node.length) { return false; } // TODO: quick toggle
2378
-
2379
- node.children('.jstree-children').remove();
2380
- node = node[0];
2381
- if(obj.children.length && obj.state.loaded) {
2382
- k = d.createElement('UL');
2383
- k.setAttribute('role', 'group');
2384
- k.className = 'jstree-children';
2385
- for(i = 0, j = obj.children.length; i < j; i++) {
2386
- k.appendChild(this.redraw_node(obj.children[i], true, true));
2387
- }
2388
- node.appendChild(k);
2389
- }
2390
- },
2391
- /**
2392
- * redraws a single node. Used internally.
2393
- * @private
2394
- * @name redraw_node(node, deep, is_callback, force_render)
2395
- * @param {mixed} node the node to redraw
2396
- * @param {Boolean} deep should child nodes be redrawn too
2397
- * @param {Boolean} is_callback is this a recursion call
2398
- * @param {Boolean} force_render should children of closed parents be drawn anyway
2399
- */
2400
- redraw_node : function (node, deep, is_callback, force_render) {
2401
- var obj = this.get_node(node),
2402
- par = false,
2403
- ind = false,
2404
- old = false,
2405
- i = false,
2406
- j = false,
2407
- k = false,
2408
- c = '',
2409
- d = document,
2410
- m = this._model.data,
2411
- f = false,
2412
- s = false,
2413
- tmp = null,
2414
- t = 0,
2415
- l = 0,
2416
- has_children = false,
2417
- last_sibling = false;
2418
- if(!obj) { return false; }
2419
- if(obj.id === $.jstree.root) { return this.redraw(true); }
2420
- deep = deep || obj.children.length === 0;
2421
- node = !document.querySelector ? document.getElementById(obj.id) : this.element[0].querySelector('#' + ("0123456789".indexOf(obj.id[0]) !== -1 ? '\\3' + obj.id[0] + ' ' + obj.id.substr(1).replace($.jstree.idregex,'\\$&') : obj.id.replace($.jstree.idregex,'\\$&')) ); //, this.element);
2422
- if(!node) {
2423
- deep = true;
2424
- //node = d.createElement('LI');
2425
- if(!is_callback) {
2426
- par = obj.parent !== $.jstree.root ? $('#' + obj.parent.replace($.jstree.idregex,'\\$&'), this.element)[0] : null;
2427
- if(par !== null && (!par || !m[obj.parent].state.opened)) {
2428
- return false;
2429
- }
2430
- ind = $.inArray(obj.id, par === null ? m[$.jstree.root].children : m[obj.parent].children);
2431
- }
2432
- }
2433
- else {
2434
- node = $(node);
2435
- if(!is_callback) {
2436
- par = node.parent().parent()[0];
2437
- if(par === this.element[0]) {
2438
- par = null;
2439
- }
2440
- ind = node.index();
2441
- }
2442
- // m[obj.id].data = node.data(); // use only node's data, no need to touch jquery storage
2443
- if(!deep && obj.children.length && !node.children('.jstree-children').length) {
2444
- deep = true;
2445
- }
2446
- if(!deep) {
2447
- old = node.children('.jstree-children')[0];
2448
- }
2449
- f = node.children('.jstree-anchor')[0] === document.activeElement;
2450
- node.remove();
2451
- //node = d.createElement('LI');
2452
- //node = node[0];
2453
- }
2454
- node = this._data.core.node.cloneNode(true);
2455
- // node is DOM, deep is boolean
2456
-
2457
- c = 'jstree-node ';
2458
- for(i in obj.li_attr) {
2459
- if(obj.li_attr.hasOwnProperty(i)) {
2460
- if(i === 'id') { continue; }
2461
- if(i !== 'class') {
2462
- node.setAttribute(i, obj.li_attr[i]);
2463
- }
2464
- else {
2465
- c += obj.li_attr[i];
2466
- }
2467
- }
2468
- }
2469
- if(!obj.a_attr.id) {
2470
- obj.a_attr.id = obj.id + '_anchor';
2471
- }
2472
- node.setAttribute('aria-selected', !!obj.state.selected);
2473
- node.setAttribute('aria-level', obj.parents.length);
2474
- node.setAttribute('aria-labelledby', obj.a_attr.id);
2475
- if(obj.state.disabled) {
2476
- node.setAttribute('aria-disabled', true);
2477
- }
2478
-
2479
- for(i = 0, j = obj.children.length; i < j; i++) {
2480
- if(!m[obj.children[i]].state.hidden) {
2481
- has_children = true;
2482
- break;
2483
- }
2484
- }
2485
- if(obj.parent !== null && m[obj.parent] && !obj.state.hidden) {
2486
- i = $.inArray(obj.id, m[obj.parent].children);
2487
- last_sibling = obj.id;
2488
- if(i !== -1) {
2489
- i++;
2490
- for(j = m[obj.parent].children.length; i < j; i++) {
2491
- if(!m[m[obj.parent].children[i]].state.hidden) {
2492
- last_sibling = m[obj.parent].children[i];
2493
- }
2494
- if(last_sibling !== obj.id) {
2495
- break;
2496
- }
2497
- }
2498
- }
2499
- }
2500
-
2501
- if(obj.state.hidden) {
2502
- c += ' jstree-hidden';
2503
- }
2504
- if (obj.state.loading) {
2505
- c += ' jstree-loading';
2506
- }
2507
- if(obj.state.loaded && !has_children) {
2508
- c += ' jstree-leaf';
2509
- }
2510
- else {
2511
- c += obj.state.opened && obj.state.loaded ? ' jstree-open' : ' jstree-closed';
2512
- node.setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
2513
- }
2514
- if(last_sibling === obj.id) {
2515
- c += ' jstree-last';
2516
- }
2517
- node.id = obj.id;
2518
- node.className = c;
2519
- c = ( obj.state.selected ? ' jstree-clicked' : '') + ( obj.state.disabled ? ' jstree-disabled' : '');
2520
- for(j in obj.a_attr) {
2521
- if(obj.a_attr.hasOwnProperty(j)) {
2522
- if(j === 'href' && obj.a_attr[j] === '#') { continue; }
2523
- if(j !== 'class') {
2524
- node.childNodes[1].setAttribute(j, obj.a_attr[j]);
2525
- }
2526
- else {
2527
- c += ' ' + obj.a_attr[j];
2528
- }
2529
- }
2530
- }
2531
- if(c.length) {
2532
- node.childNodes[1].className = 'jstree-anchor ' + c;
2533
- }
2534
- if((obj.icon && obj.icon !== true) || obj.icon === false) {
2535
- if(obj.icon === false) {
2536
- node.childNodes[1].childNodes[0].className += ' jstree-themeicon-hidden';
2537
- }
2538
- else if(obj.icon.indexOf('/') === -1 && obj.icon.indexOf('.') === -1) {
2539
- node.childNodes[1].childNodes[0].className += ' ' + obj.icon + ' jstree-themeicon-custom';
2540
- }
2541
- else {
2542
- node.childNodes[1].childNodes[0].style.backgroundImage = 'url("'+obj.icon+'")';
2543
- node.childNodes[1].childNodes[0].style.backgroundPosition = 'center center';
2544
- node.childNodes[1].childNodes[0].style.backgroundSize = 'auto';
2545
- node.childNodes[1].childNodes[0].className += ' jstree-themeicon-custom';
2546
- }
2547
- }
2548
-
2549
- if(this.settings.core.force_text) {
2550
- node.childNodes[1].appendChild(d.createTextNode(obj.text));
2551
- }
2552
- else {
2553
- node.childNodes[1].innerHTML += obj.text;
2554
- }
2555
-
2556
-
2557
- if(deep && obj.children.length && (obj.state.opened || force_render) && obj.state.loaded) {
2558
- k = d.createElement('UL');
2559
- k.setAttribute('role', 'group');
2560
- k.className = 'jstree-children';
2561
- for(i = 0, j = obj.children.length; i < j; i++) {
2562
- k.appendChild(this.redraw_node(obj.children[i], deep, true));
2563
- }
2564
- node.appendChild(k);
2565
- }
2566
- if(old) {
2567
- node.appendChild(old);
2568
- }
2569
- if(!is_callback) {
2570
- // append back using par / ind
2571
- if(!par) {
2572
- par = this.element[0];
2573
- }
2574
- for(i = 0, j = par.childNodes.length; i < j; i++) {
2575
- if(par.childNodes[i] && par.childNodes[i].className && par.childNodes[i].className.indexOf('jstree-children') !== -1) {
2576
- tmp = par.childNodes[i];
2577
- break;
2578
- }
2579
- }
2580
- if(!tmp) {
2581
- tmp = d.createElement('UL');
2582
- tmp.setAttribute('role', 'group');
2583
- tmp.className = 'jstree-children';
2584
- par.appendChild(tmp);
2585
- }
2586
- par = tmp;
2587
-
2588
- if(ind < par.childNodes.length) {
2589
- par.insertBefore(node, par.childNodes[ind]);
2590
- }
2591
- else {
2592
- par.appendChild(node);
2593
- }
2594
- if(f) {
2595
- t = this.element[0].scrollTop;
2596
- l = this.element[0].scrollLeft;
2597
- node.childNodes[1].focus();
2598
- this.element[0].scrollTop = t;
2599
- this.element[0].scrollLeft = l;
2600
- }
2601
- }
2602
- if(obj.state.opened && !obj.state.loaded) {
2603
- obj.state.opened = false;
2604
- setTimeout($.proxy(function () {
2605
- this.open_node(obj.id, false, 0);
2606
- }, this), 0);
2607
- }
2608
- return node;
2609
- },
2610
- /**
2611
- * opens a node, revaling its children. If the node is not loaded it will be loaded and opened once ready.
2612
- * @name open_node(obj [, callback, animation])
2613
- * @param {mixed} obj the node to open
2614
- * @param {Function} callback a function to execute once the node is opened
2615
- * @param {Number} animation the animation duration in milliseconds when opening the node (overrides the `core.animation` setting). Use `false` for no animation.
2616
- * @trigger open_node.jstree, after_open.jstree, before_open.jstree
2617
- */
2618
- open_node : function (obj, callback, animation) {
2619
- var t1, t2, d, t;
2620
- if($.isArray(obj)) {
2621
- obj = obj.slice();
2622
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2623
- this.open_node(obj[t1], callback, animation);
2624
- }
2625
- return true;
2626
- }
2627
- obj = this.get_node(obj);
2628
- if(!obj || obj.id === $.jstree.root) {
2629
- return false;
2630
- }
2631
- animation = animation === undefined ? this.settings.core.animation : animation;
2632
- if(!this.is_closed(obj)) {
2633
- if(callback) {
2634
- callback.call(this, obj, false);
2635
- }
2636
- return false;
2637
- }
2638
- if(!this.is_loaded(obj)) {
2639
- if(this.is_loading(obj)) {
2640
- return setTimeout($.proxy(function () {
2641
- this.open_node(obj, callback, animation);
2642
- }, this), 500);
2643
- }
2644
- this.load_node(obj, function (o, ok) {
2645
- return ok ? this.open_node(o, callback, animation) : (callback ? callback.call(this, o, false) : false);
2646
- });
2647
- }
2648
- else {
2649
- d = this.get_node(obj, true);
2650
- t = this;
2651
- if(d.length) {
2652
- if(animation && d.children(".jstree-children").length) {
2653
- d.children(".jstree-children").stop(true, true);
2654
- }
2655
- if(obj.children.length && !this._firstChild(d.children('.jstree-children')[0])) {
2656
- this.draw_children(obj);
2657
- //d = this.get_node(obj, true);
2658
- }
2659
- if(!animation) {
2660
- this.trigger('before_open', { "node" : obj });
2661
- d[0].className = d[0].className.replace('jstree-closed', 'jstree-open');
2662
- d[0].setAttribute("aria-expanded", true);
2663
- }
2664
- else {
2665
- this.trigger('before_open', { "node" : obj });
2666
- d
2667
- .children(".jstree-children").css("display","none").end()
2668
- .removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded", true)
2669
- .children(".jstree-children").stop(true, true)
2670
- .slideDown(animation, function () {
2671
- this.style.display = "";
2672
- if (t.element) {
2673
- t.trigger("after_open", { "node" : obj });
2674
- }
2675
- });
2676
- }
2677
- }
2678
- obj.state.opened = true;
2679
- if(callback) {
2680
- callback.call(this, obj, true);
2681
- }
2682
- if(!d.length) {
2683
- /**
2684
- * triggered when a node is about to be opened (if the node is supposed to be in the DOM, it will be, but it won't be visible yet)
2685
- * @event
2686
- * @name before_open.jstree
2687
- * @param {Object} node the opened node
2688
- */
2689
- this.trigger('before_open', { "node" : obj });
2690
- }
2691
- /**
2692
- * triggered when a node is opened (if there is an animation it will not be completed yet)
2693
- * @event
2694
- * @name open_node.jstree
2695
- * @param {Object} node the opened node
2696
- */
2697
- this.trigger('open_node', { "node" : obj });
2698
- if(!animation || !d.length) {
2699
- /**
2700
- * triggered when a node is opened and the animation is complete
2701
- * @event
2702
- * @name after_open.jstree
2703
- * @param {Object} node the opened node
2704
- */
2705
- this.trigger("after_open", { "node" : obj });
2706
- }
2707
- return true;
2708
- }
2709
- },
2710
- /**
2711
- * opens every parent of a node (node should be loaded)
2712
- * @name _open_to(obj)
2713
- * @param {mixed} obj the node to reveal
2714
- * @private
2715
- */
2716
- _open_to : function (obj) {
2717
- obj = this.get_node(obj);
2718
- if(!obj || obj.id === $.jstree.root) {
2719
- return false;
2720
- }
2721
- var i, j, p = obj.parents;
2722
- for(i = 0, j = p.length; i < j; i+=1) {
2723
- if(i !== $.jstree.root) {
2724
- this.open_node(p[i], false, 0);
2725
- }
2726
- }
2727
- return $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
2728
- },
2729
- /**
2730
- * closes a node, hiding its children
2731
- * @name close_node(obj [, animation])
2732
- * @param {mixed} obj the node to close
2733
- * @param {Number} animation the animation duration in milliseconds when closing the node (overrides the `core.animation` setting). Use `false` for no animation.
2734
- * @trigger close_node.jstree, after_close.jstree
2735
- */
2736
- close_node : function (obj, animation) {
2737
- var t1, t2, t, d;
2738
- if($.isArray(obj)) {
2739
- obj = obj.slice();
2740
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2741
- this.close_node(obj[t1], animation);
2742
- }
2743
- return true;
2744
- }
2745
- obj = this.get_node(obj);
2746
- if(!obj || obj.id === $.jstree.root) {
2747
- return false;
2748
- }
2749
- if(this.is_closed(obj)) {
2750
- return false;
2751
- }
2752
- animation = animation === undefined ? this.settings.core.animation : animation;
2753
- t = this;
2754
- d = this.get_node(obj, true);
2755
-
2756
- obj.state.opened = false;
2757
- /**
2758
- * triggered when a node is closed (if there is an animation it will not be complete yet)
2759
- * @event
2760
- * @name close_node.jstree
2761
- * @param {Object} node the closed node
2762
- */
2763
- this.trigger('close_node',{ "node" : obj });
2764
- if(!d.length) {
2765
- /**
2766
- * triggered when a node is closed and the animation is complete
2767
- * @event
2768
- * @name after_close.jstree
2769
- * @param {Object} node the closed node
2770
- */
2771
- this.trigger("after_close", { "node" : obj });
2772
- }
2773
- else {
2774
- if(!animation) {
2775
- d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
2776
- d.attr("aria-expanded", false).children('.jstree-children').remove();
2777
- this.trigger("after_close", { "node" : obj });
2778
- }
2779
- else {
2780
- d
2781
- .children(".jstree-children").attr("style","display:block !important").end()
2782
- .removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
2783
- .children(".jstree-children").stop(true, true).slideUp(animation, function () {
2784
- this.style.display = "";
2785
- d.children('.jstree-children').remove();
2786
- if (t.element) {
2787
- t.trigger("after_close", { "node" : obj });
2788
- }
2789
- });
2790
- }
2791
- }
2792
- },
2793
- /**
2794
- * toggles a node - closing it if it is open, opening it if it is closed
2795
- * @name toggle_node(obj)
2796
- * @param {mixed} obj the node to toggle
2797
- */
2798
- toggle_node : function (obj) {
2799
- var t1, t2;
2800
- if($.isArray(obj)) {
2801
- obj = obj.slice();
2802
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2803
- this.toggle_node(obj[t1]);
2804
- }
2805
- return true;
2806
- }
2807
- if(this.is_closed(obj)) {
2808
- return this.open_node(obj);
2809
- }
2810
- if(this.is_open(obj)) {
2811
- return this.close_node(obj);
2812
- }
2813
- },
2814
- /**
2815
- * opens all nodes within a node (or the tree), revaling their children. If the node is not loaded it will be loaded and opened once ready.
2816
- * @name open_all([obj, animation, original_obj])
2817
- * @param {mixed} obj the node to open recursively, omit to open all nodes in the tree
2818
- * @param {Number} animation the animation duration in milliseconds when opening the nodes, the default is no animation
2819
- * @param {jQuery} reference to the node that started the process (internal use)
2820
- * @trigger open_all.jstree
2821
- */
2822
- open_all : function (obj, animation, original_obj) {
2823
- if(!obj) { obj = $.jstree.root; }
2824
- obj = this.get_node(obj);
2825
- if(!obj) { return false; }
2826
- var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true), i, j, _this;
2827
- if(!dom.length) {
2828
- for(i = 0, j = obj.children_d.length; i < j; i++) {
2829
- if(this.is_closed(this._model.data[obj.children_d[i]])) {
2830
- this._model.data[obj.children_d[i]].state.opened = true;
2831
- }
2832
- }
2833
- return this.trigger('open_all', { "node" : obj });
2834
- }
2835
- original_obj = original_obj || dom;
2836
- _this = this;
2837
- dom = this.is_closed(obj) ? dom.find('.jstree-closed').addBack() : dom.find('.jstree-closed');
2838
- dom.each(function () {
2839
- _this.open_node(
2840
- this,
2841
- function(node, status) { if(status && this.is_parent(node)) { this.open_all(node, animation, original_obj); } },
2842
- animation || 0
2843
- );
2844
- });
2845
- if(original_obj.find('.jstree-closed').length === 0) {
2846
- /**
2847
- * triggered when an `open_all` call completes
2848
- * @event
2849
- * @name open_all.jstree
2850
- * @param {Object} node the opened node
2851
- */
2852
- this.trigger('open_all', { "node" : this.get_node(original_obj) });
2853
- }
2854
- },
2855
- /**
2856
- * closes all nodes within a node (or the tree), revaling their children
2857
- * @name close_all([obj, animation])
2858
- * @param {mixed} obj the node to close recursively, omit to close all nodes in the tree
2859
- * @param {Number} animation the animation duration in milliseconds when closing the nodes, the default is no animation
2860
- * @trigger close_all.jstree
2861
- */
2862
- close_all : function (obj, animation) {
2863
- if(!obj) { obj = $.jstree.root; }
2864
- obj = this.get_node(obj);
2865
- if(!obj) { return false; }
2866
- var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true),
2867
- _this = this, i, j;
2868
- if(dom.length) {
2869
- dom = this.is_open(obj) ? dom.find('.jstree-open').addBack() : dom.find('.jstree-open');
2870
- $(dom.get().reverse()).each(function () { _this.close_node(this, animation || 0); });
2871
- }
2872
- for(i = 0, j = obj.children_d.length; i < j; i++) {
2873
- this._model.data[obj.children_d[i]].state.opened = false;
2874
- }
2875
- /**
2876
- * triggered when an `close_all` call completes
2877
- * @event
2878
- * @name close_all.jstree
2879
- * @param {Object} node the closed node
2880
- */
2881
- this.trigger('close_all', { "node" : obj });
2882
- },
2883
- /**
2884
- * checks if a node is disabled (not selectable)
2885
- * @name is_disabled(obj)
2886
- * @param {mixed} obj
2887
- * @return {Boolean}
2888
- */
2889
- is_disabled : function (obj) {
2890
- obj = this.get_node(obj);
2891
- return obj && obj.state && obj.state.disabled;
2892
- },
2893
- /**
2894
- * enables a node - so that it can be selected
2895
- * @name enable_node(obj)
2896
- * @param {mixed} obj the node to enable
2897
- * @trigger enable_node.jstree
2898
- */
2899
- enable_node : function (obj) {
2900
- var t1, t2;
2901
- if($.isArray(obj)) {
2902
- obj = obj.slice();
2903
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2904
- this.enable_node(obj[t1]);
2905
- }
2906
- return true;
2907
- }
2908
- obj = this.get_node(obj);
2909
- if(!obj || obj.id === $.jstree.root) {
2910
- return false;
2911
- }
2912
- obj.state.disabled = false;
2913
- this.get_node(obj,true).children('.jstree-anchor').removeClass('jstree-disabled').attr('aria-disabled', false);
2914
- /**
2915
- * triggered when an node is enabled
2916
- * @event
2917
- * @name enable_node.jstree
2918
- * @param {Object} node the enabled node
2919
- */
2920
- this.trigger('enable_node', { 'node' : obj });
2921
- },
2922
- /**
2923
- * disables a node - so that it can not be selected
2924
- * @name disable_node(obj)
2925
- * @param {mixed} obj the node to disable
2926
- * @trigger disable_node.jstree
2927
- */
2928
- disable_node : function (obj) {
2929
- var t1, t2;
2930
- if($.isArray(obj)) {
2931
- obj = obj.slice();
2932
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2933
- this.disable_node(obj[t1]);
2934
- }
2935
- return true;
2936
- }
2937
- obj = this.get_node(obj);
2938
- if(!obj || obj.id === $.jstree.root) {
2939
- return false;
2940
- }
2941
- obj.state.disabled = true;
2942
- this.get_node(obj,true).children('.jstree-anchor').addClass('jstree-disabled').attr('aria-disabled', true);
2943
- /**
2944
- * triggered when an node is disabled
2945
- * @event
2946
- * @name disable_node.jstree
2947
- * @param {Object} node the disabled node
2948
- */
2949
- this.trigger('disable_node', { 'node' : obj });
2950
- },
2951
- /**
2952
- * determines if a node is hidden
2953
- * @name is_hidden(obj)
2954
- * @param {mixed} obj the node
2955
- */
2956
- is_hidden : function (obj) {
2957
- obj = this.get_node(obj);
2958
- return obj.state.hidden === true;
2959
- },
2960
- /**
2961
- * hides a node - it is still in the structure but will not be visible
2962
- * @name hide_node(obj)
2963
- * @param {mixed} obj the node to hide
2964
- * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
2965
- * @trigger hide_node.jstree
2966
- */
2967
- hide_node : function (obj, skip_redraw) {
2968
- var t1, t2;
2969
- if($.isArray(obj)) {
2970
- obj = obj.slice();
2971
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2972
- this.hide_node(obj[t1], true);
2973
- }
2974
- if (!skip_redraw) {
2975
- this.redraw();
2976
- }
2977
- return true;
2978
- }
2979
- obj = this.get_node(obj);
2980
- if(!obj || obj.id === $.jstree.root) {
2981
- return false;
2982
- }
2983
- if(!obj.state.hidden) {
2984
- obj.state.hidden = true;
2985
- this._node_changed(obj.parent);
2986
- if(!skip_redraw) {
2987
- this.redraw();
2988
- }
2989
- /**
2990
- * triggered when an node is hidden
2991
- * @event
2992
- * @name hide_node.jstree
2993
- * @param {Object} node the hidden node
2994
- */
2995
- this.trigger('hide_node', { 'node' : obj });
2996
- }
2997
- },
2998
- /**
2999
- * shows a node
3000
- * @name show_node(obj)
3001
- * @param {mixed} obj the node to show
3002
- * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
3003
- * @trigger show_node.jstree
3004
- */
3005
- show_node : function (obj, skip_redraw) {
3006
- var t1, t2;
3007
- if($.isArray(obj)) {
3008
- obj = obj.slice();
3009
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3010
- this.show_node(obj[t1], true);
3011
- }
3012
- if (!skip_redraw) {
3013
- this.redraw();
3014
- }
3015
- return true;
3016
- }
3017
- obj = this.get_node(obj);
3018
- if(!obj || obj.id === $.jstree.root) {
3019
- return false;
3020
- }
3021
- if(obj.state.hidden) {
3022
- obj.state.hidden = false;
3023
- this._node_changed(obj.parent);
3024
- if(!skip_redraw) {
3025
- this.redraw();
3026
- }
3027
- /**
3028
- * triggered when an node is shown
3029
- * @event
3030
- * @name show_node.jstree
3031
- * @param {Object} node the shown node
3032
- */
3033
- this.trigger('show_node', { 'node' : obj });
3034
- }
3035
- },
3036
- /**
3037
- * hides all nodes
3038
- * @name hide_all()
3039
- * @trigger hide_all.jstree
3040
- */
3041
- hide_all : function (skip_redraw) {
3042
- var i, m = this._model.data, ids = [];
3043
- for(i in m) {
3044
- if(m.hasOwnProperty(i) && i !== $.jstree.root && !m[i].state.hidden) {
3045
- m[i].state.hidden = true;
3046
- ids.push(i);
3047
- }
3048
- }
3049
- this._model.force_full_redraw = true;
3050
- if(!skip_redraw) {
3051
- this.redraw();
3052
- }
3053
- /**
3054
- * triggered when all nodes are hidden
3055
- * @event
3056
- * @name hide_all.jstree
3057
- * @param {Array} nodes the IDs of all hidden nodes
3058
- */
3059
- this.trigger('hide_all', { 'nodes' : ids });
3060
- return ids;
3061
- },
3062
- /**
3063
- * shows all nodes
3064
- * @name show_all()
3065
- * @trigger show_all.jstree
3066
- */
3067
- show_all : function (skip_redraw) {
3068
- var i, m = this._model.data, ids = [];
3069
- for(i in m) {
3070
- if(m.hasOwnProperty(i) && i !== $.jstree.root && m[i].state.hidden) {
3071
- m[i].state.hidden = false;
3072
- ids.push(i);
3073
- }
3074
- }
3075
- this._model.force_full_redraw = true;
3076
- if(!skip_redraw) {
3077
- this.redraw();
3078
- }
3079
- /**
3080
- * triggered when all nodes are shown
3081
- * @event
3082
- * @name show_all.jstree
3083
- * @param {Array} nodes the IDs of all shown nodes
3084
- */
3085
- this.trigger('show_all', { 'nodes' : ids });
3086
- return ids;
3087
- },
3088
- /**
3089
- * called when a node is selected by the user. Used internally.
3090
- * @private
3091
- * @name activate_node(obj, e)
3092
- * @param {mixed} obj the node
3093
- * @param {Object} e the related event
3094
- * @trigger activate_node.jstree, changed.jstree
3095
- */
3096
- activate_node : function (obj, e) {
3097
- if(this.is_disabled(obj)) {
3098
- return false;
3099
- }
3100
- if(!e || typeof e !== 'object') {
3101
- e = {};
3102
- }
3103
-
3104
- // ensure last_clicked is still in the DOM, make it fresh (maybe it was moved?) and make sure it is still selected, if not - make last_clicked the last selected node
3105
- this._data.core.last_clicked = this._data.core.last_clicked && this._data.core.last_clicked.id !== undefined ? this.get_node(this._data.core.last_clicked.id) : null;
3106
- if(this._data.core.last_clicked && !this._data.core.last_clicked.state.selected) { this._data.core.last_clicked = null; }
3107
- if(!this._data.core.last_clicked && this._data.core.selected.length) { this._data.core.last_clicked = this.get_node(this._data.core.selected[this._data.core.selected.length - 1]); }
3108
-
3109
- if(!this.settings.core.multiple || (!e.metaKey && !e.ctrlKey && !e.shiftKey) || (e.shiftKey && (!this._data.core.last_clicked || !this.get_parent(obj) || this.get_parent(obj) !== this._data.core.last_clicked.parent ) )) {
3110
- if(!this.settings.core.multiple && (e.metaKey || e.ctrlKey || e.shiftKey) && this.is_selected(obj)) {
3111
- this.deselect_node(obj, false, e);
3112
- }
3113
- else {
3114
- this.deselect_all(true);
3115
- this.select_node(obj, false, false, e);
3116
- this._data.core.last_clicked = this.get_node(obj);
3117
- }
3118
- }
3119
- else {
3120
- if(e.shiftKey) {
3121
- var o = this.get_node(obj).id,
3122
- l = this._data.core.last_clicked.id,
3123
- p = this.get_node(this._data.core.last_clicked.parent).children,
3124
- c = false,
3125
- i, j;
3126
- for(i = 0, j = p.length; i < j; i += 1) {
3127
- // separate IFs work whem o and l are the same
3128
- if(p[i] === o) {
3129
- c = !c;
3130
- }
3131
- if(p[i] === l) {
3132
- c = !c;
3133
- }
3134
- if(!this.is_disabled(p[i]) && (c || p[i] === o || p[i] === l)) {
3135
- if (!this.is_hidden(p[i])) {
3136
- this.select_node(p[i], true, false, e);
3137
- }
3138
- }
3139
- else {
3140
- this.deselect_node(p[i], true, e);
3141
- }
3142
- }
3143
- this.trigger('changed', { 'action' : 'select_node', 'node' : this.get_node(obj), 'selected' : this._data.core.selected, 'event' : e });
3144
- }
3145
- else {
3146
- if(!this.is_selected(obj)) {
3147
- this.select_node(obj, false, false, e);
3148
- }
3149
- else {
3150
- this.deselect_node(obj, false, e);
3151
- }
3152
- }
3153
- }
3154
- /**
3155
- * triggered when an node is clicked or intercated with by the user
3156
- * @event
3157
- * @name activate_node.jstree
3158
- * @param {Object} node
3159
- * @param {Object} event the ooriginal event (if any) which triggered the call (may be an empty object)
3160
- */
3161
- this.trigger('activate_node', { 'node' : this.get_node(obj), 'event' : e });
3162
- },
3163
- /**
3164
- * applies the hover state on a node, called when a node is hovered by the user. Used internally.
3165
- * @private
3166
- * @name hover_node(obj)
3167
- * @param {mixed} obj
3168
- * @trigger hover_node.jstree
3169
- */
3170
- hover_node : function (obj) {
3171
- obj = this.get_node(obj, true);
3172
- if(!obj || !obj.length || obj.children('.jstree-hovered').length) {
3173
- return false;
3174
- }
3175
- var o = this.element.find('.jstree-hovered'), t = this.element;
3176
- if(o && o.length) { this.dehover_node(o); }
3177
-
3178
- obj.children('.jstree-anchor').addClass('jstree-hovered');
3179
- /**
3180
- * triggered when an node is hovered
3181
- * @event
3182
- * @name hover_node.jstree
3183
- * @param {Object} node
3184
- */
3185
- this.trigger('hover_node', { 'node' : this.get_node(obj) });
3186
- setTimeout(function () { t.attr('aria-activedescendant', obj[0].id); }, 0);
3187
- },
3188
- /**
3189
- * removes the hover state from a nodecalled when a node is no longer hovered by the user. Used internally.
3190
- * @private
3191
- * @name dehover_node(obj)
3192
- * @param {mixed} obj
3193
- * @trigger dehover_node.jstree
3194
- */
3195
- dehover_node : function (obj) {
3196
- obj = this.get_node(obj, true);
3197
- if(!obj || !obj.length || !obj.children('.jstree-hovered').length) {
3198
- return false;
3199
- }
3200
- obj.children('.jstree-anchor').removeClass('jstree-hovered');
3201
- /**
3202
- * triggered when an node is no longer hovered
3203
- * @event
3204
- * @name dehover_node.jstree
3205
- * @param {Object} node
3206
- */
3207
- this.trigger('dehover_node', { 'node' : this.get_node(obj) });
3208
- },
3209
- /**
3210
- * select a node
3211
- * @name select_node(obj [, supress_event, prevent_open])
3212
- * @param {mixed} obj an array can be used to select multiple nodes
3213
- * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3214
- * @param {Boolean} prevent_open if set to `true` parents of the selected node won't be opened
3215
- * @trigger select_node.jstree, changed.jstree
3216
- */
3217
- select_node : function (obj, supress_event, prevent_open, e) {
3218
- var dom, t1, t2, th;
3219
- if($.isArray(obj)) {
3220
- obj = obj.slice();
3221
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3222
- this.select_node(obj[t1], supress_event, prevent_open, e);
3223
- }
3224
- return true;
3225
- }
3226
- obj = this.get_node(obj);
3227
- if(!obj || obj.id === $.jstree.root) {
3228
- return false;
3229
- }
3230
- dom = this.get_node(obj, true);
3231
- if(!obj.state.selected) {
3232
- obj.state.selected = true;
3233
- this._data.core.selected.push(obj.id);
3234
- if(!prevent_open) {
3235
- dom = this._open_to(obj);
3236
- }
3237
- if(dom && dom.length) {
3238
- dom.attr('aria-selected', true).children('.jstree-anchor').addClass('jstree-clicked');
3239
- }
3240
- /**
3241
- * triggered when an node is selected
3242
- * @event
3243
- * @name select_node.jstree
3244
- * @param {Object} node
3245
- * @param {Array} selected the current selection
3246
- * @param {Object} event the event (if any) that triggered this select_node
3247
- */
3248
- this.trigger('select_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3249
- if(!supress_event) {
3250
- /**
3251
- * triggered when selection changes
3252
- * @event
3253
- * @name changed.jstree
3254
- * @param {Object} node
3255
- * @param {Object} action the action that caused the selection to change
3256
- * @param {Array} selected the current selection
3257
- * @param {Object} event the event (if any) that triggered this changed event
3258
- */
3259
- this.trigger('changed', { 'action' : 'select_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3260
- }
3261
- }
3262
- },
3263
- /**
3264
- * deselect a node
3265
- * @name deselect_node(obj [, supress_event])
3266
- * @param {mixed} obj an array can be used to deselect multiple nodes
3267
- * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3268
- * @trigger deselect_node.jstree, changed.jstree
3269
- */
3270
- deselect_node : function (obj, supress_event, e) {
3271
- var t1, t2, dom;
3272
- if($.isArray(obj)) {
3273
- obj = obj.slice();
3274
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3275
- this.deselect_node(obj[t1], supress_event, e);
3276
- }
3277
- return true;
3278
- }
3279
- obj = this.get_node(obj);
3280
- if(!obj || obj.id === $.jstree.root) {
3281
- return false;
3282
- }
3283
- dom = this.get_node(obj, true);
3284
- if(obj.state.selected) {
3285
- obj.state.selected = false;
3286
- this._data.core.selected = $.vakata.array_remove_item(this._data.core.selected, obj.id);
3287
- if(dom.length) {
3288
- dom.attr('aria-selected', false).children('.jstree-anchor').removeClass('jstree-clicked');
3289
- }
3290
- /**
3291
- * triggered when an node is deselected
3292
- * @event
3293
- * @name deselect_node.jstree
3294
- * @param {Object} node
3295
- * @param {Array} selected the current selection
3296
- * @param {Object} event the event (if any) that triggered this deselect_node
3297
- */
3298
- this.trigger('deselect_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3299
- if(!supress_event) {
3300
- this.trigger('changed', { 'action' : 'deselect_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3301
- }
3302
- }
3303
- },
3304
- /**
3305
- * select all nodes in the tree
3306
- * @name select_all([supress_event])
3307
- * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3308
- * @trigger select_all.jstree, changed.jstree
3309
- */
3310
- select_all : function (supress_event) {
3311
- var tmp = this._data.core.selected.concat([]), i, j;
3312
- this._data.core.selected = this._model.data[$.jstree.root].children_d.concat();
3313
- for(i = 0, j = this._data.core.selected.length; i < j; i++) {
3314
- if(this._model.data[this._data.core.selected[i]]) {
3315
- this._model.data[this._data.core.selected[i]].state.selected = true;
3316
- }
3317
- }
3318
- this.redraw(true);
3319
- /**
3320
- * triggered when all nodes are selected
3321
- * @event
3322
- * @name select_all.jstree
3323
- * @param {Array} selected the current selection
3324
- */
3325
- this.trigger('select_all', { 'selected' : this._data.core.selected });
3326
- if(!supress_event) {
3327
- this.trigger('changed', { 'action' : 'select_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
3328
- }
3329
- },
3330
- /**
3331
- * deselect all selected nodes
3332
- * @name deselect_all([supress_event])
3333
- * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3334
- * @trigger deselect_all.jstree, changed.jstree
3335
- */
3336
- deselect_all : function (supress_event) {
3337
- var tmp = this._data.core.selected.concat([]), i, j;
3338
- for(i = 0, j = this._data.core.selected.length; i < j; i++) {
3339
- if(this._model.data[this._data.core.selected[i]]) {
3340
- this._model.data[this._data.core.selected[i]].state.selected = false;
3341
- }
3342
- }
3343
- this._data.core.selected = [];
3344
- this.element.find('.jstree-clicked').removeClass('jstree-clicked').parent().attr('aria-selected', false);
3345
- /**
3346
- * triggered when all nodes are deselected
3347
- * @event
3348
- * @name deselect_all.jstree
3349
- * @param {Object} node the previous selection
3350
- * @param {Array} selected the current selection
3351
- */
3352
- this.trigger('deselect_all', { 'selected' : this._data.core.selected, 'node' : tmp });
3353
- if(!supress_event) {
3354
- this.trigger('changed', { 'action' : 'deselect_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
3355
- }
3356
- },
3357
- /**
3358
- * checks if a node is selected
3359
- * @name is_selected(obj)
3360
- * @param {mixed} obj
3361
- * @return {Boolean}
3362
- */
3363
- is_selected : function (obj) {
3364
- obj = this.get_node(obj);
3365
- if(!obj || obj.id === $.jstree.root) {
3366
- return false;
3367
- }
3368
- return obj.state.selected;
3369
- },
3370
- /**
3371
- * get an array of all selected nodes
3372
- * @name get_selected([full])
3373
- * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3374
- * @return {Array}
3375
- */
3376
- get_selected : function (full) {
3377
- return full ? $.map(this._data.core.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.core.selected.slice();
3378
- },
3379
- /**
3380
- * get an array of all top level selected nodes (ignoring children of selected nodes)
3381
- * @name get_top_selected([full])
3382
- * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3383
- * @return {Array}
3384
- */
3385
- get_top_selected : function (full) {
3386
- var tmp = this.get_selected(true),
3387
- obj = {}, i, j, k, l;
3388
- for(i = 0, j = tmp.length; i < j; i++) {
3389
- obj[tmp[i].id] = tmp[i];
3390
- }
3391
- for(i = 0, j = tmp.length; i < j; i++) {
3392
- for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
3393
- if(obj[tmp[i].children_d[k]]) {
3394
- delete obj[tmp[i].children_d[k]];
3395
- }
3396
- }
3397
- }
3398
- tmp = [];
3399
- for(i in obj) {
3400
- if(obj.hasOwnProperty(i)) {
3401
- tmp.push(i);
3402
- }
3403
- }
3404
- return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
3405
- },
3406
- /**
3407
- * get an array of all bottom level selected nodes (ignoring selected parents)
3408
- * @name get_bottom_selected([full])
3409
- * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3410
- * @return {Array}
3411
- */
3412
- get_bottom_selected : function (full) {
3413
- var tmp = this.get_selected(true),
3414
- obj = [], i, j;
3415
- for(i = 0, j = tmp.length; i < j; i++) {
3416
- if(!tmp[i].children.length) {
3417
- obj.push(tmp[i].id);
3418
- }
3419
- }
3420
- return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
3421
- },
3422
- /**
3423
- * gets the current state of the tree so that it can be restored later with `set_state(state)`. Used internally.
3424
- * @name get_state()
3425
- * @private
3426
- * @return {Object}
3427
- */
3428
- get_state : function () {
3429
- var state = {
3430
- 'core' : {
3431
- 'open' : [],
3432
- 'loaded' : [],
3433
- 'scroll' : {
3434
- 'left' : this.element.scrollLeft(),
3435
- 'top' : this.element.scrollTop()
3436
- },
3437
- /*!
3438
- 'themes' : {
3439
- 'name' : this.get_theme(),
3440
- 'icons' : this._data.core.themes.icons,
3441
- 'dots' : this._data.core.themes.dots
3442
- },
3443
- */
3444
- 'selected' : []
3445
- }
3446
- }, i;
3447
- for(i in this._model.data) {
3448
- if(this._model.data.hasOwnProperty(i)) {
3449
- if(i !== $.jstree.root) {
3450
- if(this._model.data[i].state.loaded && this.settings.core.loaded_state) {
3451
- state.core.loaded.push(i);
3452
- }
3453
- if(this._model.data[i].state.opened) {
3454
- state.core.open.push(i);
3455
- }
3456
- if(this._model.data[i].state.selected) {
3457
- state.core.selected.push(i);
3458
- }
3459
- }
3460
- }
3461
- }
3462
- return state;
3463
- },
3464
- /**
3465
- * sets the state of the tree. Used internally.
3466
- * @name set_state(state [, callback])
3467
- * @private
3468
- * @param {Object} state the state to restore. Keep in mind this object is passed by reference and jstree will modify it.
3469
- * @param {Function} callback an optional function to execute once the state is restored.
3470
- * @trigger set_state.jstree
3471
- */
3472
- set_state : function (state, callback) {
3473
- if(state) {
3474
- if(state.core && state.core.selected && state.core.initial_selection === undefined) {
3475
- state.core.initial_selection = this._data.core.selected.concat([]).sort().join(',');
3476
- }
3477
- if(state.core) {
3478
- var res, n, t, _this, i;
3479
- if(state.core.loaded) {
3480
- if(!this.settings.core.loaded_state || !$.isArray(state.core.loaded) || !state.core.loaded.length) {
3481
- delete state.core.loaded;
3482
- this.set_state(state, callback);
3483
- }
3484
- else {
3485
- this._load_nodes(state.core.loaded, function (nodes) {
3486
- delete state.core.loaded;
3487
- this.set_state(state, callback);
3488
- });
3489
- }
3490
- return false;
3491
- }
3492
- if(state.core.open) {
3493
- if(!$.isArray(state.core.open) || !state.core.open.length) {
3494
- delete state.core.open;
3495
- this.set_state(state, callback);
3496
- }
3497
- else {
3498
- this._load_nodes(state.core.open, function (nodes) {
3499
- this.open_node(nodes, false, 0);
3500
- delete state.core.open;
3501
- this.set_state(state, callback);
3502
- });
3503
- }
3504
- return false;
3505
- }
3506
- if(state.core.scroll) {
3507
- if(state.core.scroll && state.core.scroll.left !== undefined) {
3508
- this.element.scrollLeft(state.core.scroll.left);
3509
- }
3510
- if(state.core.scroll && state.core.scroll.top !== undefined) {
3511
- this.element.scrollTop(state.core.scroll.top);
3512
- }
3513
- delete state.core.scroll;
3514
- this.set_state(state, callback);
3515
- return false;
3516
- }
3517
- if(state.core.selected) {
3518
- _this = this;
3519
- if (state.core.initial_selection === undefined ||
3520
- state.core.initial_selection === this._data.core.selected.concat([]).sort().join(',')
3521
- ) {
3522
- this.deselect_all();
3523
- $.each(state.core.selected, function (i, v) {
3524
- _this.select_node(v, false, true);
3525
- });
3526
- }
3527
- delete state.core.initial_selection;
3528
- delete state.core.selected;
3529
- this.set_state(state, callback);
3530
- return false;
3531
- }
3532
- for(i in state) {
3533
- if(state.hasOwnProperty(i) && i !== "core" && $.inArray(i, this.settings.plugins) === -1) {
3534
- delete state[i];
3535
- }
3536
- }
3537
- if($.isEmptyObject(state.core)) {
3538
- delete state.core;
3539
- this.set_state(state, callback);
3540
- return false;
3541
- }
3542
- }
3543
- if($.isEmptyObject(state)) {
3544
- state = null;
3545
- if(callback) { callback.call(this); }
3546
- /**
3547
- * triggered when a `set_state` call completes
3548
- * @event
3549
- * @name set_state.jstree
3550
- */
3551
- this.trigger('set_state');
3552
- return false;
3553
- }
3554
- return true;
3555
- }
3556
- return false;
3557
- },
3558
- /**
3559
- * refreshes the tree - all nodes are reloaded with calls to `load_node`.
3560
- * @name refresh()
3561
- * @param {Boolean} skip_loading an option to skip showing the loading indicator
3562
- * @param {Mixed} forget_state if set to `true` state will not be reapplied, if set to a function (receiving the current state as argument) the result of that function will be used as state
3563
- * @trigger refresh.jstree
3564
- */
3565
- refresh : function (skip_loading, forget_state) {
3566
- this._data.core.state = forget_state === true ? {} : this.get_state();
3567
- if(forget_state && $.isFunction(forget_state)) { this._data.core.state = forget_state.call(this, this._data.core.state); }
3568
- this._cnt = 0;
3569
- this._model.data = {};
3570
- this._model.data[$.jstree.root] = {
3571
- id : $.jstree.root,
3572
- parent : null,
3573
- parents : [],
3574
- children : [],
3575
- children_d : [],
3576
- state : { loaded : false }
3577
- };
3578
- this._data.core.selected = [];
3579
- this._data.core.last_clicked = null;
3580
- this._data.core.focused = null;
3581
-
3582
- var c = this.get_container_ul()[0].className;
3583
- if(!skip_loading) {
3584
- this.element.html("<"+"ul class='"+c+"' role='group'><"+"li class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='treeitem' id='j"+this._id+"_loading'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
3585
- this.element.attr('aria-activedescendant','j'+this._id+'_loading');
3586
- }
3587
- this.load_node($.jstree.root, function (o, s) {
3588
- if(s) {
3589
- this.get_container_ul()[0].className = c;
3590
- if(this._firstChild(this.get_container_ul()[0])) {
3591
- this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
3592
- }
3593
- this.set_state($.extend(true, {}, this._data.core.state), function () {
3594
- /**
3595
- * triggered when a `refresh` call completes
3596
- * @event
3597
- * @name refresh.jstree
3598
- */
3599
- this.trigger('refresh');
3600
- });
3601
- }
3602
- this._data.core.state = null;
3603
- });
3604
- },
3605
- /**
3606
- * refreshes a node in the tree (reload its children) all opened nodes inside that node are reloaded with calls to `load_node`.
3607
- * @name refresh_node(obj)
3608
- * @param {mixed} obj the node
3609
- * @trigger refresh_node.jstree
3610
- */
3611
- refresh_node : function (obj) {
3612
- obj = this.get_node(obj);
3613
- if(!obj || obj.id === $.jstree.root) { return false; }
3614
- var opened = [], to_load = [], s = this._data.core.selected.concat([]);
3615
- to_load.push(obj.id);
3616
- if(obj.state.opened === true) { opened.push(obj.id); }
3617
- this.get_node(obj, true).find('.jstree-open').each(function() { to_load.push(this.id); opened.push(this.id); });
3618
- this._load_nodes(to_load, $.proxy(function (nodes) {
3619
- this.open_node(opened, false, 0);
3620
- this.select_node(s);
3621
- /**
3622
- * triggered when a node is refreshed
3623
- * @event
3624
- * @name refresh_node.jstree
3625
- * @param {Object} node - the refreshed node
3626
- * @param {Array} nodes - an array of the IDs of the nodes that were reloaded
3627
- */
3628
- this.trigger('refresh_node', { 'node' : obj, 'nodes' : nodes });
3629
- }, this), false, true);
3630
- },
3631
- /**
3632
- * set (change) the ID of a node
3633
- * @name set_id(obj, id)
3634
- * @param {mixed} obj the node
3635
- * @param {String} id the new ID
3636
- * @return {Boolean}
3637
- * @trigger set_id.jstree
3638
- */
3639
- set_id : function (obj, id) {
3640
- obj = this.get_node(obj);
3641
- if(!obj || obj.id === $.jstree.root) { return false; }
3642
- var i, j, m = this._model.data, old = obj.id;
3643
- id = id.toString();
3644
- // update parents (replace current ID with new one in children and children_d)
3645
- m[obj.parent].children[$.inArray(obj.id, m[obj.parent].children)] = id;
3646
- for(i = 0, j = obj.parents.length; i < j; i++) {
3647
- m[obj.parents[i]].children_d[$.inArray(obj.id, m[obj.parents[i]].children_d)] = id;
3648
- }
3649
- // update children (replace current ID with new one in parent and parents)
3650
- for(i = 0, j = obj.children.length; i < j; i++) {
3651
- m[obj.children[i]].parent = id;
3652
- }
3653
- for(i = 0, j = obj.children_d.length; i < j; i++) {
3654
- m[obj.children_d[i]].parents[$.inArray(obj.id, m[obj.children_d[i]].parents)] = id;
3655
- }
3656
- i = $.inArray(obj.id, this._data.core.selected);
3657
- if(i !== -1) { this._data.core.selected[i] = id; }
3658
- // update model and obj itself (obj.id, this._model.data[KEY])
3659
- i = this.get_node(obj.id, true);
3660
- if(i) {
3661
- i.attr('id', id); //.children('.jstree-anchor').attr('id', id + '_anchor').end().attr('aria-labelledby', id + '_anchor');
3662
- if(this.element.attr('aria-activedescendant') === obj.id) {
3663
- this.element.attr('aria-activedescendant', id);
3664
- }
3665
- }
3666
- delete m[obj.id];
3667
- obj.id = id;
3668
- obj.li_attr.id = id;
3669
- m[id] = obj;
3670
- /**
3671
- * triggered when a node id value is changed
3672
- * @event
3673
- * @name set_id.jstree
3674
- * @param {Object} node
3675
- * @param {String} old the old id
3676
- */
3677
- this.trigger('set_id',{ "node" : obj, "new" : obj.id, "old" : old });
3678
- return true;
3679
- },
3680
- /**
3681
- * get the text value of a node
3682
- * @name get_text(obj)
3683
- * @param {mixed} obj the node
3684
- * @return {String}
3685
- */
3686
- get_text : function (obj) {
3687
- obj = this.get_node(obj);
3688
- return (!obj || obj.id === $.jstree.root) ? false : obj.text;
3689
- },
3690
- /**
3691
- * set the text value of a node. Used internally, please use `rename_node(obj, val)`.
3692
- * @private
3693
- * @name set_text(obj, val)
3694
- * @param {mixed} obj the node, you can pass an array to set the text on multiple nodes
3695
- * @param {String} val the new text value
3696
- * @return {Boolean}
3697
- * @trigger set_text.jstree
3698
- */
3699
- set_text : function (obj, val) {
3700
- var t1, t2;
3701
- if($.isArray(obj)) {
3702
- obj = obj.slice();
3703
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3704
- this.set_text(obj[t1], val);
3705
- }
3706
- return true;
3707
- }
3708
- obj = this.get_node(obj);
3709
- if(!obj || obj.id === $.jstree.root) { return false; }
3710
- obj.text = val;
3711
- if(this.get_node(obj, true).length) {
3712
- this.redraw_node(obj.id);
3713
- }
3714
- /**
3715
- * triggered when a node text value is changed
3716
- * @event
3717
- * @name set_text.jstree
3718
- * @param {Object} obj
3719
- * @param {String} text the new value
3720
- */
3721
- this.trigger('set_text',{ "obj" : obj, "text" : val });
3722
- return true;
3723
- },
3724
- /**
3725
- * gets a JSON representation of a node (or the whole tree)
3726
- * @name get_json([obj, options])
3727
- * @param {mixed} obj
3728
- * @param {Object} options
3729
- * @param {Boolean} options.no_state do not return state information
3730
- * @param {Boolean} options.no_id do not return ID
3731
- * @param {Boolean} options.no_children do not include children
3732
- * @param {Boolean} options.no_data do not include node data
3733
- * @param {Boolean} options.no_li_attr do not include LI attributes
3734
- * @param {Boolean} options.no_a_attr do not include A attributes
3735
- * @param {Boolean} options.flat return flat JSON instead of nested
3736
- * @return {Object}
3737
- */
3738
- get_json : function (obj, options, flat) {
3739
- obj = this.get_node(obj || $.jstree.root);
3740
- if(!obj) { return false; }
3741
- if(options && options.flat && !flat) { flat = []; }
3742
- var tmp = {
3743
- 'id' : obj.id,
3744
- 'text' : obj.text,
3745
- 'icon' : this.get_icon(obj),
3746
- 'li_attr' : $.extend(true, {}, obj.li_attr),
3747
- 'a_attr' : $.extend(true, {}, obj.a_attr),
3748
- 'state' : {},
3749
- 'data' : options && options.no_data ? false : $.extend(true, $.isArray(obj.data)?[]:{}, obj.data)
3750
- //( this.get_node(obj, true).length ? this.get_node(obj, true).data() : obj.data ),
3751
- }, i, j;
3752
- if(options && options.flat) {
3753
- tmp.parent = obj.parent;
3754
- }
3755
- else {
3756
- tmp.children = [];
3757
- }
3758
- if(!options || !options.no_state) {
3759
- for(i in obj.state) {
3760
- if(obj.state.hasOwnProperty(i)) {
3761
- tmp.state[i] = obj.state[i];
3762
- }
3763
- }
3764
- } else {
3765
- delete tmp.state;
3766
- }
3767
- if(options && options.no_li_attr) {
3768
- delete tmp.li_attr;
3769
- }
3770
- if(options && options.no_a_attr) {
3771
- delete tmp.a_attr;
3772
- }
3773
- if(options && options.no_id) {
3774
- delete tmp.id;
3775
- if(tmp.li_attr && tmp.li_attr.id) {
3776
- delete tmp.li_attr.id;
3777
- }
3778
- if(tmp.a_attr && tmp.a_attr.id) {
3779
- delete tmp.a_attr.id;
3780
- }
3781
- }
3782
- if(options && options.flat && obj.id !== $.jstree.root) {
3783
- flat.push(tmp);
3784
- }
3785
- if(!options || !options.no_children) {
3786
- for(i = 0, j = obj.children.length; i < j; i++) {
3787
- if(options && options.flat) {
3788
- this.get_json(obj.children[i], options, flat);
3789
- }
3790
- else {
3791
- tmp.children.push(this.get_json(obj.children[i], options));
3792
- }
3793
- }
3794
- }
3795
- return options && options.flat ? flat : (obj.id === $.jstree.root ? tmp.children : tmp);
3796
- },
3797
- /**
3798
- * create a new node (do not confuse with load_node)
3799
- * @name create_node([par, node, pos, callback, is_loaded])
3800
- * @param {mixed} par the parent node (to create a root node use either "#" (string) or `null`)
3801
- * @param {mixed} node the data for the new node (a valid JSON object, or a simple string with the name)
3802
- * @param {mixed} pos the index at which to insert the node, "first" and "last" are also supported, default is "last"
3803
- * @param {Function} callback a function to be called once the node is created
3804
- * @param {Boolean} is_loaded internal argument indicating if the parent node was succesfully loaded
3805
- * @return {String} the ID of the newly create node
3806
- * @trigger model.jstree, create_node.jstree
3807
- */
3808
- create_node : function (par, node, pos, callback, is_loaded) {
3809
- if(par === null) { par = $.jstree.root; }
3810
- par = this.get_node(par);
3811
- if(!par) { return false; }
3812
- pos = pos === undefined ? "last" : pos;
3813
- if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
3814
- return this.load_node(par, function () { this.create_node(par, node, pos, callback, true); });
3815
- }
3816
- if(!node) { node = { "text" : this.get_string('New node') }; }
3817
- if(typeof node === "string") {
3818
- node = { "text" : node };
3819
- } else {
3820
- node = $.extend(true, {}, node);
3821
- }
3822
- if(node.text === undefined) { node.text = this.get_string('New node'); }
3823
- var tmp, dpc, i, j;
3824
-
3825
- if(par.id === $.jstree.root) {
3826
- if(pos === "before") { pos = "first"; }
3827
- if(pos === "after") { pos = "last"; }
3828
- }
3829
- switch(pos) {
3830
- case "before":
3831
- tmp = this.get_node(par.parent);
3832
- pos = $.inArray(par.id, tmp.children);
3833
- par = tmp;
3834
- break;
3835
- case "after" :
3836
- tmp = this.get_node(par.parent);
3837
- pos = $.inArray(par.id, tmp.children) + 1;
3838
- par = tmp;
3839
- break;
3840
- case "inside":
3841
- case "first":
3842
- pos = 0;
3843
- break;
3844
- case "last":
3845
- pos = par.children.length;
3846
- break;
3847
- default:
3848
- if(!pos) { pos = 0; }
3849
- break;
3850
- }
3851
- if(pos > par.children.length) { pos = par.children.length; }
3852
- if(!node.id) { node.id = true; }
3853
- if(!this.check("create_node", node, par, pos)) {
3854
- this.settings.core.error.call(this, this._data.core.last_error);
3855
- return false;
3856
- }
3857
- if(node.id === true) { delete node.id; }
3858
- node = this._parse_model_from_json(node, par.id, par.parents.concat());
3859
- if(!node) { return false; }
3860
- tmp = this.get_node(node);
3861
- dpc = [];
3862
- dpc.push(node);
3863
- dpc = dpc.concat(tmp.children_d);
3864
- this.trigger('model', { "nodes" : dpc, "parent" : par.id });
3865
-
3866
- par.children_d = par.children_d.concat(dpc);
3867
- for(i = 0, j = par.parents.length; i < j; i++) {
3868
- this._model.data[par.parents[i]].children_d = this._model.data[par.parents[i]].children_d.concat(dpc);
3869
- }
3870
- node = tmp;
3871
- tmp = [];
3872
- for(i = 0, j = par.children.length; i < j; i++) {
3873
- tmp[i >= pos ? i+1 : i] = par.children[i];
3874
- }
3875
- tmp[pos] = node.id;
3876
- par.children = tmp;
3877
-
3878
- this.redraw_node(par, true);
3879
- /**
3880
- * triggered when a node is created
3881
- * @event
3882
- * @name create_node.jstree
3883
- * @param {Object} node
3884
- * @param {String} parent the parent's ID
3885
- * @param {Number} position the position of the new node among the parent's children
3886
- */
3887
- this.trigger('create_node', { "node" : this.get_node(node), "parent" : par.id, "position" : pos });
3888
- if(callback) { callback.call(this, this.get_node(node)); }
3889
- return node.id;
3890
- },
3891
- /**
3892
- * set the text value of a node
3893
- * @name rename_node(obj, val)
3894
- * @param {mixed} obj the node, you can pass an array to rename multiple nodes to the same name
3895
- * @param {String} val the new text value
3896
- * @return {Boolean}
3897
- * @trigger rename_node.jstree
3898
- */
3899
- rename_node : function (obj, val) {
3900
- var t1, t2, old;
3901
- if($.isArray(obj)) {
3902
- obj = obj.slice();
3903
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3904
- this.rename_node(obj[t1], val);
3905
- }
3906
- return true;
3907
- }
3908
- obj = this.get_node(obj);
3909
- if(!obj || obj.id === $.jstree.root) { return false; }
3910
- old = obj.text;
3911
- if(!this.check("rename_node", obj, this.get_parent(obj), val)) {
3912
- this.settings.core.error.call(this, this._data.core.last_error);
3913
- return false;
3914
- }
3915
- this.set_text(obj, val); // .apply(this, Array.prototype.slice.call(arguments))
3916
- /**
3917
- * triggered when a node is renamed
3918
- * @event
3919
- * @name rename_node.jstree
3920
- * @param {Object} node
3921
- * @param {String} text the new value
3922
- * @param {String} old the old value
3923
- */
3924
- this.trigger('rename_node', { "node" : obj, "text" : val, "old" : old });
3925
- return true;
3926
- },
3927
- /**
3928
- * remove a node
3929
- * @name delete_node(obj)
3930
- * @param {mixed} obj the node, you can pass an array to delete multiple nodes
3931
- * @return {Boolean}
3932
- * @trigger delete_node.jstree, changed.jstree
3933
- */
3934
- delete_node : function (obj) {
3935
- var t1, t2, par, pos, tmp, i, j, k, l, c, top, lft;
3936
- if($.isArray(obj)) {
3937
- obj = obj.slice();
3938
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3939
- this.delete_node(obj[t1]);
3940
- }
3941
- return true;
3942
- }
3943
- obj = this.get_node(obj);
3944
- if(!obj || obj.id === $.jstree.root) { return false; }
3945
- par = this.get_node(obj.parent);
3946
- pos = $.inArray(obj.id, par.children);
3947
- c = false;
3948
- if(!this.check("delete_node", obj, par, pos)) {
3949
- this.settings.core.error.call(this, this._data.core.last_error);
3950
- return false;
3951
- }
3952
- if(pos !== -1) {
3953
- par.children = $.vakata.array_remove(par.children, pos);
3954
- }
3955
- tmp = obj.children_d.concat([]);
3956
- tmp.push(obj.id);
3957
- for(i = 0, j = obj.parents.length; i < j; i++) {
3958
- this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
3959
- return $.inArray(v, tmp) === -1;
3960
- });
3961
- }
3962
- for(k = 0, l = tmp.length; k < l; k++) {
3963
- if(this._model.data[tmp[k]].state.selected) {
3964
- c = true;
3965
- break;
3966
- }
3967
- }
3968
- if (c) {
3969
- this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
3970
- return $.inArray(v, tmp) === -1;
3971
- });
3972
- }
3973
- /**
3974
- * triggered when a node is deleted
3975
- * @event
3976
- * @name delete_node.jstree
3977
- * @param {Object} node
3978
- * @param {String} parent the parent's ID
3979
- */
3980
- this.trigger('delete_node', { "node" : obj, "parent" : par.id });
3981
- if(c) {
3982
- this.trigger('changed', { 'action' : 'delete_node', 'node' : obj, 'selected' : this._data.core.selected, 'parent' : par.id });
3983
- }
3984
- for(k = 0, l = tmp.length; k < l; k++) {
3985
- delete this._model.data[tmp[k]];
3986
- }
3987
- if($.inArray(this._data.core.focused, tmp) !== -1) {
3988
- this._data.core.focused = null;
3989
- top = this.element[0].scrollTop;
3990
- lft = this.element[0].scrollLeft;
3991
- if(par.id === $.jstree.root) {
3992
- if (this._model.data[$.jstree.root].children[0]) {
3993
- this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').focus();
3994
- }
3995
- }
3996
- else {
3997
- this.get_node(par, true).children('.jstree-anchor').focus();
3998
- }
3999
- this.element[0].scrollTop = top;
4000
- this.element[0].scrollLeft = lft;
4001
- }
4002
- this.redraw_node(par, true);
4003
- return true;
4004
- },
4005
- /**
4006
- * check if an operation is premitted on the tree. Used internally.
4007
- * @private
4008
- * @name check(chk, obj, par, pos)
4009
- * @param {String} chk the operation to check, can be "create_node", "rename_node", "delete_node", "copy_node" or "move_node"
4010
- * @param {mixed} obj the node
4011
- * @param {mixed} par the parent
4012
- * @param {mixed} pos the position to insert at, or if "rename_node" - the new name
4013
- * @param {mixed} more some various additional information, for example if a "move_node" operations is triggered by DND this will be the hovered node
4014
- * @return {Boolean}
4015
- */
4016
- check : function (chk, obj, par, pos, more) {
4017
- obj = obj && obj.id ? obj : this.get_node(obj);
4018
- par = par && par.id ? par : this.get_node(par);
4019
- var tmp = chk.match(/^move_node|copy_node|create_node$/i) ? par : obj,
4020
- chc = this.settings.core.check_callback;
4021
- if(chk === "move_node" || chk === "copy_node") {
4022
- if((!more || !more.is_multi) && (obj.id === par.id || (chk === "move_node" && $.inArray(obj.id, par.children) === pos) || $.inArray(par.id, obj.children_d) !== -1)) {
4023
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_01', 'reason' : 'Moving parent inside child', 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
4024
- return false;
4025
- }
4026
- }
4027
- if(tmp && tmp.data) { tmp = tmp.data; }
4028
- if(tmp && tmp.functions && (tmp.functions[chk] === false || tmp.functions[chk] === true)) {
4029
- if(tmp.functions[chk] === false) {
4030
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_02', 'reason' : 'Node data prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
4031
- }
4032
- return tmp.functions[chk];
4033
- }
4034
- if(chc === false || ($.isFunction(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
4035
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_03', 'reason' : 'User config for core.check_callback prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
4036
- return false;
4037
- }
4038
- return true;
4039
- },
4040
- /**
4041
- * get the last error
4042
- * @name last_error()
4043
- * @return {Object}
4044
- */
4045
- last_error : function () {
4046
- return this._data.core.last_error;
4047
- },
4048
- /**
4049
- * move a node to a new parent
4050
- * @name move_node(obj, par [, pos, callback, is_loaded])
4051
- * @param {mixed} obj the node to move, pass an array to move multiple nodes
4052
- * @param {mixed} par the new parent
4053
- * @param {mixed} pos the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer `0`
4054
- * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
4055
- * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
4056
- * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
4057
- * @param {Boolean} instance internal parameter indicating if the node comes from another instance
4058
- * @trigger move_node.jstree
4059
- */
4060
- move_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
4061
- var t1, t2, old_par, old_pos, new_par, old_ins, is_multi, dpc, tmp, i, j, k, l, p;
4062
-
4063
- par = this.get_node(par);
4064
- pos = pos === undefined ? 0 : pos;
4065
- if(!par) { return false; }
4066
- if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
4067
- return this.load_node(par, function () { this.move_node(obj, par, pos, callback, true, false, origin); });
4068
- }
4069
-
4070
- if($.isArray(obj)) {
4071
- if(obj.length === 1) {
4072
- obj = obj[0];
4073
- }
4074
- else {
4075
- //obj = obj.slice();
4076
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4077
- if((tmp = this.move_node(obj[t1], par, pos, callback, is_loaded, false, origin))) {
4078
- par = tmp;
4079
- pos = "after";
4080
- }
4081
- }
4082
- this.redraw();
4083
- return true;
4084
- }
4085
- }
4086
- obj = obj && obj.id ? obj : this.get_node(obj);
4087
-
4088
- if(!obj || obj.id === $.jstree.root) { return false; }
4089
-
4090
- old_par = (obj.parent || $.jstree.root).toString();
4091
- new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
4092
- old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
4093
- is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
4094
- 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;
4095
- if(old_ins && old_ins._id) {
4096
- obj = old_ins._model.data[obj.id];
4097
- }
4098
-
4099
- if(is_multi) {
4100
- if((tmp = this.copy_node(obj, par, pos, callback, is_loaded, false, origin))) {
4101
- if(old_ins) { old_ins.delete_node(obj); }
4102
- return tmp;
4103
- }
4104
- return false;
4105
- }
4106
- //var m = this._model.data;
4107
- if(par.id === $.jstree.root) {
4108
- if(pos === "before") { pos = "first"; }
4109
- if(pos === "after") { pos = "last"; }
4110
- }
4111
- switch(pos) {
4112
- case "before":
4113
- pos = $.inArray(par.id, new_par.children);
4114
- break;
4115
- case "after" :
4116
- pos = $.inArray(par.id, new_par.children) + 1;
4117
- break;
4118
- case "inside":
4119
- case "first":
4120
- pos = 0;
4121
- break;
4122
- case "last":
4123
- pos = new_par.children.length;
4124
- break;
4125
- default:
4126
- if(!pos) { pos = 0; }
4127
- break;
4128
- }
4129
- if(pos > new_par.children.length) { pos = new_par.children.length; }
4130
- if(!this.check("move_node", obj, new_par, pos, { 'core' : true, 'origin' : origin, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id) })) {
4131
- this.settings.core.error.call(this, this._data.core.last_error);
4132
- return false;
4133
- }
4134
- if(obj.parent === new_par.id) {
4135
- dpc = new_par.children.concat();
4136
- tmp = $.inArray(obj.id, dpc);
4137
- if(tmp !== -1) {
4138
- dpc = $.vakata.array_remove(dpc, tmp);
4139
- if(pos > tmp) { pos--; }
4140
- }
4141
- tmp = [];
4142
- for(i = 0, j = dpc.length; i < j; i++) {
4143
- tmp[i >= pos ? i+1 : i] = dpc[i];
4144
- }
4145
- tmp[pos] = obj.id;
4146
- new_par.children = tmp;
4147
- this._node_changed(new_par.id);
4148
- this.redraw(new_par.id === $.jstree.root);
4149
- }
4150
- else {
4151
- // clean old parent and up
4152
- tmp = obj.children_d.concat();
4153
- tmp.push(obj.id);
4154
- for(i = 0, j = obj.parents.length; i < j; i++) {
4155
- dpc = [];
4156
- p = old_ins._model.data[obj.parents[i]].children_d;
4157
- for(k = 0, l = p.length; k < l; k++) {
4158
- if($.inArray(p[k], tmp) === -1) {
4159
- dpc.push(p[k]);
4160
- }
4161
- }
4162
- old_ins._model.data[obj.parents[i]].children_d = dpc;
4163
- }
4164
- old_ins._model.data[old_par].children = $.vakata.array_remove_item(old_ins._model.data[old_par].children, obj.id);
4165
-
4166
- // insert into new parent and up
4167
- for(i = 0, j = new_par.parents.length; i < j; i++) {
4168
- this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(tmp);
4169
- }
4170
- dpc = [];
4171
- for(i = 0, j = new_par.children.length; i < j; i++) {
4172
- dpc[i >= pos ? i+1 : i] = new_par.children[i];
4173
- }
4174
- dpc[pos] = obj.id;
4175
- new_par.children = dpc;
4176
- new_par.children_d.push(obj.id);
4177
- new_par.children_d = new_par.children_d.concat(obj.children_d);
4178
-
4179
- // update object
4180
- obj.parent = new_par.id;
4181
- tmp = new_par.parents.concat();
4182
- tmp.unshift(new_par.id);
4183
- p = obj.parents.length;
4184
- obj.parents = tmp;
4185
-
4186
- // update object children
4187
- tmp = tmp.concat();
4188
- for(i = 0, j = obj.children_d.length; i < j; i++) {
4189
- this._model.data[obj.children_d[i]].parents = this._model.data[obj.children_d[i]].parents.slice(0,p*-1);
4190
- Array.prototype.push.apply(this._model.data[obj.children_d[i]].parents, tmp);
4191
- }
4192
-
4193
- if(old_par === $.jstree.root || new_par.id === $.jstree.root) {
4194
- this._model.force_full_redraw = true;
4195
- }
4196
- if(!this._model.force_full_redraw) {
4197
- this._node_changed(old_par);
4198
- this._node_changed(new_par.id);
4199
- }
4200
- if(!skip_redraw) {
4201
- this.redraw();
4202
- }
4203
- }
4204
- if(callback) { callback.call(this, obj, new_par, pos); }
4205
- /**
4206
- * triggered when a node is moved
4207
- * @event
4208
- * @name move_node.jstree
4209
- * @param {Object} node
4210
- * @param {String} parent the parent's ID
4211
- * @param {Number} position the position of the node among the parent's children
4212
- * @param {String} old_parent the old parent of the node
4213
- * @param {Number} old_position the old position of the node
4214
- * @param {Boolean} is_multi do the node and new parent belong to different instances
4215
- * @param {jsTree} old_instance the instance the node came from
4216
- * @param {jsTree} new_instance the instance of the new parent
4217
- */
4218
- this.trigger('move_node', { "node" : obj, "parent" : new_par.id, "position" : pos, "old_parent" : old_par, "old_position" : old_pos, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id), 'old_instance' : old_ins, 'new_instance' : this });
4219
- return obj.id;
4220
- },
4221
- /**
4222
- * copy a node to a new parent
4223
- * @name copy_node(obj, par [, pos, callback, is_loaded])
4224
- * @param {mixed} obj the node to copy, pass an array to copy multiple nodes
4225
- * @param {mixed} par the new parent
4226
- * @param {mixed} pos the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer `0`
4227
- * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
4228
- * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
4229
- * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
4230
- * @param {Boolean} instance internal parameter indicating if the node comes from another instance
4231
- * @trigger model.jstree copy_node.jstree
4232
- */
4233
- copy_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
4234
- var t1, t2, dpc, tmp, i, j, node, old_par, new_par, old_ins, is_multi;
4235
-
4236
- par = this.get_node(par);
4237
- pos = pos === undefined ? 0 : pos;
4238
- if(!par) { return false; }
4239
- if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
4240
- return this.load_node(par, function () { this.copy_node(obj, par, pos, callback, true, false, origin); });
4241
- }
4242
-
4243
- if($.isArray(obj)) {
4244
- if(obj.length === 1) {
4245
- obj = obj[0];
4246
- }
4247
- else {
4248
- //obj = obj.slice();
4249
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4250
- if((tmp = this.copy_node(obj[t1], par, pos, callback, is_loaded, true, origin))) {
4251
- par = tmp;
4252
- pos = "after";
4253
- }
4254
- }
4255
- this.redraw();
4256
- return true;
4257
- }
4258
- }
4259
- obj = obj && obj.id ? obj : this.get_node(obj);
4260
- if(!obj || obj.id === $.jstree.root) { return false; }
4261
-
4262
- old_par = (obj.parent || $.jstree.root).toString();
4263
- new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
4264
- old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
4265
- is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
4266
-
4267
- if(old_ins && old_ins._id) {
4268
- obj = old_ins._model.data[obj.id];
4269
- }
4270
-
4271
- if(par.id === $.jstree.root) {
4272
- if(pos === "before") { pos = "first"; }
4273
- if(pos === "after") { pos = "last"; }
4274
- }
4275
- switch(pos) {
4276
- case "before":
4277
- pos = $.inArray(par.id, new_par.children);
4278
- break;
4279
- case "after" :
4280
- pos = $.inArray(par.id, new_par.children) + 1;
4281
- break;
4282
- case "inside":
4283
- case "first":
4284
- pos = 0;
4285
- break;
4286
- case "last":
4287
- pos = new_par.children.length;
4288
- break;
4289
- default:
4290
- if(!pos) { pos = 0; }
4291
- break;
4292
- }
4293
- if(pos > new_par.children.length) { pos = new_par.children.length; }
4294
- if(!this.check("copy_node", obj, new_par, pos, { 'core' : true, 'origin' : origin, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id) })) {
4295
- this.settings.core.error.call(this, this._data.core.last_error);
4296
- return false;
4297
- }
4298
- node = old_ins ? old_ins.get_json(obj, { no_id : true, no_data : true, no_state : true }) : obj;
4299
- if(!node) { return false; }
4300
- if(node.id === true) { delete node.id; }
4301
- node = this._parse_model_from_json(node, new_par.id, new_par.parents.concat());
4302
- if(!node) { return false; }
4303
- tmp = this.get_node(node);
4304
- if(obj && obj.state && obj.state.loaded === false) { tmp.state.loaded = false; }
4305
- dpc = [];
4306
- dpc.push(node);
4307
- dpc = dpc.concat(tmp.children_d);
4308
- this.trigger('model', { "nodes" : dpc, "parent" : new_par.id });
4309
-
4310
- // insert into new parent and up
4311
- for(i = 0, j = new_par.parents.length; i < j; i++) {
4312
- this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(dpc);
4313
- }
4314
- dpc = [];
4315
- for(i = 0, j = new_par.children.length; i < j; i++) {
4316
- dpc[i >= pos ? i+1 : i] = new_par.children[i];
4317
- }
4318
- dpc[pos] = tmp.id;
4319
- new_par.children = dpc;
4320
- new_par.children_d.push(tmp.id);
4321
- new_par.children_d = new_par.children_d.concat(tmp.children_d);
4322
-
4323
- if(new_par.id === $.jstree.root) {
4324
- this._model.force_full_redraw = true;
4325
- }
4326
- if(!this._model.force_full_redraw) {
4327
- this._node_changed(new_par.id);
4328
- }
4329
- if(!skip_redraw) {
4330
- this.redraw(new_par.id === $.jstree.root);
4331
- }
4332
- if(callback) { callback.call(this, tmp, new_par, pos); }
4333
- /**
4334
- * triggered when a node is copied
4335
- * @event
4336
- * @name copy_node.jstree
4337
- * @param {Object} node the copied node
4338
- * @param {Object} original the original node
4339
- * @param {String} parent the parent's ID
4340
- * @param {Number} position the position of the node among the parent's children
4341
- * @param {String} old_parent the old parent of the node
4342
- * @param {Number} old_position the position of the original node
4343
- * @param {Boolean} is_multi do the node and new parent belong to different instances
4344
- * @param {jsTree} old_instance the instance the node came from
4345
- * @param {jsTree} new_instance the instance of the new parent
4346
- */
4347
- this.trigger('copy_node', { "node" : tmp, "original" : obj, "parent" : new_par.id, "position" : pos, "old_parent" : old_par, "old_position" : 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,'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id), 'old_instance' : old_ins, 'new_instance' : this });
4348
- return tmp.id;
4349
- },
4350
- /**
4351
- * cut a node (a later call to `paste(obj)` would move the node)
4352
- * @name cut(obj)
4353
- * @param {mixed} obj multiple objects can be passed using an array
4354
- * @trigger cut.jstree
4355
- */
4356
- cut : function (obj) {
4357
- if(!obj) { obj = this._data.core.selected.concat(); }
4358
- if(!$.isArray(obj)) { obj = [obj]; }
4359
- if(!obj.length) { return false; }
4360
- var tmp = [], o, t1, t2;
4361
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4362
- o = this.get_node(obj[t1]);
4363
- if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
4364
- }
4365
- if(!tmp.length) { return false; }
4366
- ccp_node = tmp;
4367
- ccp_inst = this;
4368
- ccp_mode = 'move_node';
4369
- /**
4370
- * triggered when nodes are added to the buffer for moving
4371
- * @event
4372
- * @name cut.jstree
4373
- * @param {Array} node
4374
- */
4375
- this.trigger('cut', { "node" : obj });
4376
- },
4377
- /**
4378
- * copy a node (a later call to `paste(obj)` would copy the node)
4379
- * @name copy(obj)
4380
- * @param {mixed} obj multiple objects can be passed using an array
4381
- * @trigger copy.jstree
4382
- */
4383
- copy : function (obj) {
4384
- if(!obj) { obj = this._data.core.selected.concat(); }
4385
- if(!$.isArray(obj)) { obj = [obj]; }
4386
- if(!obj.length) { return false; }
4387
- var tmp = [], o, t1, t2;
4388
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4389
- o = this.get_node(obj[t1]);
4390
- if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
4391
- }
4392
- if(!tmp.length) { return false; }
4393
- ccp_node = tmp;
4394
- ccp_inst = this;
4395
- ccp_mode = 'copy_node';
4396
- /**
4397
- * triggered when nodes are added to the buffer for copying
4398
- * @event
4399
- * @name copy.jstree
4400
- * @param {Array} node
4401
- */
4402
- this.trigger('copy', { "node" : obj });
4403
- },
4404
- /**
4405
- * get the current buffer (any nodes that are waiting for a paste operation)
4406
- * @name get_buffer()
4407
- * @return {Object} an object consisting of `mode` ("copy_node" or "move_node"), `node` (an array of objects) and `inst` (the instance)
4408
- */
4409
- get_buffer : function () {
4410
- return { 'mode' : ccp_mode, 'node' : ccp_node, 'inst' : ccp_inst };
4411
- },
4412
- /**
4413
- * check if there is something in the buffer to paste
4414
- * @name can_paste()
4415
- * @return {Boolean}
4416
- */
4417
- can_paste : function () {
4418
- return ccp_mode !== false && ccp_node !== false; // && ccp_inst._model.data[ccp_node];
4419
- },
4420
- /**
4421
- * copy or move the previously cut or copied nodes to a new parent
4422
- * @name paste(obj [, pos])
4423
- * @param {mixed} obj the new parent
4424
- * @param {mixed} pos the position to insert at (besides integer, "first" and "last" are supported), defaults to integer `0`
4425
- * @trigger paste.jstree
4426
- */
4427
- paste : function (obj, pos) {
4428
- obj = this.get_node(obj);
4429
- if(!obj || !ccp_mode || !ccp_mode.match(/^(copy_node|move_node)$/) || !ccp_node) { return false; }
4430
- if(this[ccp_mode](ccp_node, obj, pos, false, false, false, ccp_inst)) {
4431
- /**
4432
- * triggered when paste is invoked
4433
- * @event
4434
- * @name paste.jstree
4435
- * @param {String} parent the ID of the receiving node
4436
- * @param {Array} node the nodes in the buffer
4437
- * @param {String} mode the performed operation - "copy_node" or "move_node"
4438
- */
4439
- this.trigger('paste', { "parent" : obj.id, "node" : ccp_node, "mode" : ccp_mode });
4440
- }
4441
- ccp_node = false;
4442
- ccp_mode = false;
4443
- ccp_inst = false;
4444
- },
4445
- /**
4446
- * clear the buffer of previously copied or cut nodes
4447
- * @name clear_buffer()
4448
- * @trigger clear_buffer.jstree
4449
- */
4450
- clear_buffer : function () {
4451
- ccp_node = false;
4452
- ccp_mode = false;
4453
- ccp_inst = false;
4454
- /**
4455
- * triggered when the copy / cut buffer is cleared
4456
- * @event
4457
- * @name clear_buffer.jstree
4458
- */
4459
- this.trigger('clear_buffer');
4460
- },
4461
- /**
4462
- * put a node in edit mode (input field to rename the node)
4463
- * @name edit(obj [, default_text, callback])
4464
- * @param {mixed} obj
4465
- * @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)
4466
- * @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, a status parameter (true if the rename is successful, false otherwise) and a boolean indicating if the user cancelled the edit. You can access the node's title using .text
4467
- */
4468
- edit : function (obj, default_text, callback) {
4469
- var rtl, w, a, s, t, h1, h2, fn, tmp, cancel = false;
4470
- obj = this.get_node(obj);
4471
- if(!obj) { return false; }
4472
- if(!this.check("edit", obj, this.get_parent(obj))) {
4473
- this.settings.core.error.call(this, this._data.core.last_error);
4474
- return false;
4475
- }
4476
- tmp = obj;
4477
- default_text = typeof default_text === 'string' ? default_text : obj.text;
4478
- this.set_text(obj, "");
4479
- obj = this._open_to(obj);
4480
- tmp.text = default_text;
4481
-
4482
- rtl = this._data.core.rtl;
4483
- w = this.element.width();
4484
- this._data.core.focused = tmp.id;
4485
- a = obj.children('.jstree-anchor').focus();
4486
- s = $('<span>');
4487
- /*!
4488
- oi = obj.children("i:visible"),
4489
- ai = a.children("i:visible"),
4490
- w1 = oi.width() * oi.length,
4491
- w2 = ai.width() * ai.length,
4492
- */
4493
- t = default_text;
4494
- h1 = $("<"+"div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo("body");
4495
- h2 = $("<"+"input />", {
4496
- "value" : t,
4497
- "class" : "jstree-rename-input",
4498
- // "size" : t.length,
4499
- "css" : {
4500
- "padding" : "0",
4501
- "border" : "1px solid silver",
4502
- "box-sizing" : "border-box",
4503
- "display" : "inline-block",
4504
- "height" : (this._data.core.li_height) + "px",
4505
- "lineHeight" : (this._data.core.li_height) + "px",
4506
- "width" : "150px" // will be set a bit further down
4507
- },
4508
- "blur" : $.proxy(function (e) {
4509
- e.stopImmediatePropagation();
4510
- e.preventDefault();
4511
- var i = s.children(".jstree-rename-input"),
4512
- v = i.val(),
4513
- f = this.settings.core.force_text,
4514
- nv;
4515
- if(v === "") { v = t; }
4516
- h1.remove();
4517
- s.replaceWith(a);
4518
- s.remove();
4519
- t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
4520
- this.set_text(obj, t);
4521
- nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
4522
- if(!nv) {
4523
- this.set_text(obj, t); // move this up? and fix #483
4524
- }
4525
- this._data.core.focused = tmp.id;
4526
- setTimeout($.proxy(function () {
4527
- var node = this.get_node(tmp.id, true);
4528
- if(node.length) {
4529
- this._data.core.focused = tmp.id;
4530
- node.children('.jstree-anchor').focus();
4531
- }
4532
- }, this), 0);
4533
- if(callback) {
4534
- callback.call(this, tmp, nv, cancel);
4535
- }
4536
- h2 = null;
4537
- }, this),
4538
- "keydown" : function (e) {
4539
- var key = e.which;
4540
- if(key === 27) {
4541
- cancel = true;
4542
- this.value = t;
4543
- }
4544
- if(key === 27 || key === 13 || key === 37 || key === 38 || key === 39 || key === 40 || key === 32) {
4545
- e.stopImmediatePropagation();
4546
- }
4547
- if(key === 27 || key === 13) {
4548
- e.preventDefault();
4549
- this.blur();
4550
- }
4551
- },
4552
- "click" : function (e) { e.stopImmediatePropagation(); },
4553
- "mousedown" : function (e) { e.stopImmediatePropagation(); },
4554
- "keyup" : function (e) {
4555
- h2.width(Math.min(h1.text("pW" + this.value).width(),w));
4556
- },
4557
- "keypress" : function(e) {
4558
- if(e.which === 13) { return false; }
4559
- }
4560
- });
4561
- fn = {
4562
- fontFamily : a.css('fontFamily') || '',
4563
- fontSize : a.css('fontSize') || '',
4564
- fontWeight : a.css('fontWeight') || '',
4565
- fontStyle : a.css('fontStyle') || '',
4566
- fontStretch : a.css('fontStretch') || '',
4567
- fontVariant : a.css('fontVariant') || '',
4568
- letterSpacing : a.css('letterSpacing') || '',
4569
- wordSpacing : a.css('wordSpacing') || ''
4570
- };
4571
- s.attr('class', a.attr('class')).append(a.contents().clone()).append(h2);
4572
- a.replaceWith(s);
4573
- h1.css(fn);
4574
- h2.css(fn).width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
4575
- $(document).one('mousedown.jstree touchstart.jstree dnd_start.vakata', function (e) {
4576
- if (h2 && e.target !== h2) {
4577
- $(h2).blur();
4578
- }
4579
- });
4580
- },
4581
-
4582
-
4583
- /**
4584
- * changes the theme
4585
- * @name set_theme(theme_name [, theme_url])
4586
- * @param {String} theme_name the name of the new theme to apply
4587
- * @param {mixed} theme_url the location of the CSS file for this theme. Omit or set to `false` if you manually included the file. Set to `true` to autoload from the `core.themes.dir` directory.
4588
- * @trigger set_theme.jstree
4589
- */
4590
- set_theme : function (theme_name, theme_url) {
4591
- if(!theme_name) { return false; }
4592
- if(theme_url === true) {
4593
- var dir = this.settings.core.themes.dir;
4594
- if(!dir) { dir = $.jstree.path + '/themes'; }
4595
- theme_url = dir + '/' + theme_name + '/style.css';
4596
- }
4597
- if(theme_url && $.inArray(theme_url, themes_loaded) === -1) {
4598
- $('head').append('<'+'link rel="stylesheet" href="' + theme_url + '" type="text/css" />');
4599
- themes_loaded.push(theme_url);
4600
- }
4601
- if(this._data.core.themes.name) {
4602
- this.element.removeClass('jstree-' + this._data.core.themes.name);
4603
- }
4604
- this._data.core.themes.name = theme_name;
4605
- this.element.addClass('jstree-' + theme_name);
4606
- this.element[this.settings.core.themes.responsive ? 'addClass' : 'removeClass' ]('jstree-' + theme_name + '-responsive');
4607
- /**
4608
- * triggered when a theme is set
4609
- * @event
4610
- * @name set_theme.jstree
4611
- * @param {String} theme the new theme
4612
- */
4613
- this.trigger('set_theme', { 'theme' : theme_name });
4614
- },
4615
- /**
4616
- * gets the name of the currently applied theme name
4617
- * @name get_theme()
4618
- * @return {String}
4619
- */
4620
- get_theme : function () { return this._data.core.themes.name; },
4621
- /**
4622
- * changes the theme variant (if the theme has variants)
4623
- * @name set_theme_variant(variant_name)
4624
- * @param {String|Boolean} variant_name the variant to apply (if `false` is used the current variant is removed)
4625
- */
4626
- set_theme_variant : function (variant_name) {
4627
- if(this._data.core.themes.variant) {
4628
- this.element.removeClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
4629
- }
4630
- this._data.core.themes.variant = variant_name;
4631
- if(variant_name) {
4632
- this.element.addClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
4633
- }
4634
- },
4635
- /**
4636
- * gets the name of the currently applied theme variant
4637
- * @name get_theme()
4638
- * @return {String}
4639
- */
4640
- get_theme_variant : function () { return this._data.core.themes.variant; },
4641
- /**
4642
- * shows a striped background on the container (if the theme supports it)
4643
- * @name show_stripes()
4644
- */
4645
- show_stripes : function () {
4646
- this._data.core.themes.stripes = true;
4647
- this.get_container_ul().addClass("jstree-striped");
4648
- /**
4649
- * triggered when stripes are shown
4650
- * @event
4651
- * @name show_stripes.jstree
4652
- */
4653
- this.trigger('show_stripes');
4654
- },
4655
- /**
4656
- * hides the striped background on the container
4657
- * @name hide_stripes()
4658
- */
4659
- hide_stripes : function () {
4660
- this._data.core.themes.stripes = false;
4661
- this.get_container_ul().removeClass("jstree-striped");
4662
- /**
4663
- * triggered when stripes are hidden
4664
- * @event
4665
- * @name hide_stripes.jstree
4666
- */
4667
- this.trigger('hide_stripes');
4668
- },
4669
- /**
4670
- * toggles the striped background on the container
4671
- * @name toggle_stripes()
4672
- */
4673
- toggle_stripes : function () { if(this._data.core.themes.stripes) { this.hide_stripes(); } else { this.show_stripes(); } },
4674
- /**
4675
- * shows the connecting dots (if the theme supports it)
4676
- * @name show_dots()
4677
- */
4678
- show_dots : function () {
4679
- this._data.core.themes.dots = true;
4680
- this.get_container_ul().removeClass("jstree-no-dots");
4681
- /**
4682
- * triggered when dots are shown
4683
- * @event
4684
- * @name show_dots.jstree
4685
- */
4686
- this.trigger('show_dots');
4687
- },
4688
- /**
4689
- * hides the connecting dots
4690
- * @name hide_dots()
4691
- */
4692
- hide_dots : function () {
4693
- this._data.core.themes.dots = false;
4694
- this.get_container_ul().addClass("jstree-no-dots");
4695
- /**
4696
- * triggered when dots are hidden
4697
- * @event
4698
- * @name hide_dots.jstree
4699
- */
4700
- this.trigger('hide_dots');
4701
- },
4702
- /**
4703
- * toggles the connecting dots
4704
- * @name toggle_dots()
4705
- */
4706
- toggle_dots : function () { if(this._data.core.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
4707
- /**
4708
- * show the node icons
4709
- * @name show_icons()
4710
- */
4711
- show_icons : function () {
4712
- this._data.core.themes.icons = true;
4713
- this.get_container_ul().removeClass("jstree-no-icons");
4714
- /**
4715
- * triggered when icons are shown
4716
- * @event
4717
- * @name show_icons.jstree
4718
- */
4719
- this.trigger('show_icons');
4720
- },
4721
- /**
4722
- * hide the node icons
4723
- * @name hide_icons()
4724
- */
4725
- hide_icons : function () {
4726
- this._data.core.themes.icons = false;
4727
- this.get_container_ul().addClass("jstree-no-icons");
4728
- /**
4729
- * triggered when icons are hidden
4730
- * @event
4731
- * @name hide_icons.jstree
4732
- */
4733
- this.trigger('hide_icons');
4734
- },
4735
- /**
4736
- * toggle the node icons
4737
- * @name toggle_icons()
4738
- */
4739
- toggle_icons : function () { if(this._data.core.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
4740
- /**
4741
- * show the node ellipsis
4742
- * @name show_icons()
4743
- */
4744
- show_ellipsis : function () {
4745
- this._data.core.themes.ellipsis = true;
4746
- this.get_container_ul().addClass("jstree-ellipsis");
4747
- /**
4748
- * triggered when ellisis is shown
4749
- * @event
4750
- * @name show_ellipsis.jstree
4751
- */
4752
- this.trigger('show_ellipsis');
4753
- },
4754
- /**
4755
- * hide the node ellipsis
4756
- * @name hide_ellipsis()
4757
- */
4758
- hide_ellipsis : function () {
4759
- this._data.core.themes.ellipsis = false;
4760
- this.get_container_ul().removeClass("jstree-ellipsis");
4761
- /**
4762
- * triggered when ellisis is hidden
4763
- * @event
4764
- * @name hide_ellipsis.jstree
4765
- */
4766
- this.trigger('hide_ellipsis');
4767
- },
4768
- /**
4769
- * toggle the node ellipsis
4770
- * @name toggle_icons()
4771
- */
4772
- toggle_ellipsis : function () { if(this._data.core.themes.ellipsis) { this.hide_ellipsis(); } else { this.show_ellipsis(); } },
4773
- /**
4774
- * set the node icon for a node
4775
- * @name set_icon(obj, icon)
4776
- * @param {mixed} obj
4777
- * @param {String} icon the new icon - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
4778
- */
4779
- set_icon : function (obj, icon) {
4780
- var t1, t2, dom, old;
4781
- if($.isArray(obj)) {
4782
- obj = obj.slice();
4783
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4784
- this.set_icon(obj[t1], icon);
4785
- }
4786
- return true;
4787
- }
4788
- obj = this.get_node(obj);
4789
- if(!obj || obj.id === $.jstree.root) { return false; }
4790
- old = obj.icon;
4791
- obj.icon = icon === true || icon === null || icon === undefined || icon === '' ? true : icon;
4792
- dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
4793
- if(icon === false) {
4794
- dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
4795
- this.hide_icon(obj);
4796
- }
4797
- else if(icon === true || icon === null || icon === undefined || icon === '') {
4798
- dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
4799
- if(old === false) { this.show_icon(obj); }
4800
- }
4801
- else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
4802
- dom.removeClass(old).css("background","");
4803
- dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
4804
- if(old === false) { this.show_icon(obj); }
4805
- }
4806
- else {
4807
- dom.removeClass(old).css("background","");
4808
- dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
4809
- if(old === false) { this.show_icon(obj); }
4810
- }
4811
- return true;
4812
- },
4813
- /**
4814
- * get the node icon for a node
4815
- * @name get_icon(obj)
4816
- * @param {mixed} obj
4817
- * @return {String}
4818
- */
4819
- get_icon : function (obj) {
4820
- obj = this.get_node(obj);
4821
- return (!obj || obj.id === $.jstree.root) ? false : obj.icon;
4822
- },
4823
- /**
4824
- * hide the icon on an individual node
4825
- * @name hide_icon(obj)
4826
- * @param {mixed} obj
4827
- */
4828
- hide_icon : function (obj) {
4829
- var t1, t2;
4830
- if($.isArray(obj)) {
4831
- obj = obj.slice();
4832
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4833
- this.hide_icon(obj[t1]);
4834
- }
4835
- return true;
4836
- }
4837
- obj = this.get_node(obj);
4838
- if(!obj || obj === $.jstree.root) { return false; }
4839
- obj.icon = false;
4840
- this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon").addClass('jstree-themeicon-hidden');
4841
- return true;
4842
- },
4843
- /**
4844
- * show the icon on an individual node
4845
- * @name show_icon(obj)
4846
- * @param {mixed} obj
4847
- */
4848
- show_icon : function (obj) {
4849
- var t1, t2, dom;
4850
- if($.isArray(obj)) {
4851
- obj = obj.slice();
4852
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4853
- this.show_icon(obj[t1]);
4854
- }
4855
- return true;
4856
- }
4857
- obj = this.get_node(obj);
4858
- if(!obj || obj === $.jstree.root) { return false; }
4859
- dom = this.get_node(obj, true);
4860
- obj.icon = dom.length ? dom.children(".jstree-anchor").children(".jstree-themeicon").attr('rel') : true;
4861
- if(!obj.icon) { obj.icon = true; }
4862
- dom.children(".jstree-anchor").children(".jstree-themeicon").removeClass('jstree-themeicon-hidden');
4863
- return true;
4864
- }
4865
- };
4866
-
4867
- // helpers
4868
- $.vakata = {};
4869
- // collect attributes
4870
- $.vakata.attributes = function(node, with_values) {
4871
- node = $(node)[0];
4872
- var attr = with_values ? {} : [];
4873
- if(node && node.attributes) {
4874
- $.each(node.attributes, function (i, v) {
4875
- if($.inArray(v.name.toLowerCase(),['style','contenteditable','hasfocus','tabindex']) !== -1) { return; }
4876
- if(v.value !== null && $.trim(v.value) !== '') {
4877
- if(with_values) { attr[v.name] = v.value; }
4878
- else { attr.push(v.name); }
4879
- }
4880
- });
4881
- }
4882
- return attr;
4883
- };
4884
- $.vakata.array_unique = function(array) {
4885
- var a = [], i, j, l, o = {};
4886
- for(i = 0, l = array.length; i < l; i++) {
4887
- if(o[array[i]] === undefined) {
4888
- a.push(array[i]);
4889
- o[array[i]] = true;
4890
- }
4891
- }
4892
- return a;
4893
- };
4894
- // remove item from array
4895
- $.vakata.array_remove = function(array, from) {
4896
- array.splice(from, 1);
4897
- return array;
4898
- //var rest = array.slice((to || from) + 1 || array.length);
4899
- //array.length = from < 0 ? array.length + from : from;
4900
- //array.push.apply(array, rest);
4901
- //return array;
4902
- };
4903
- // remove item from array
4904
- $.vakata.array_remove_item = function(array, item) {
4905
- var tmp = $.inArray(item, array);
4906
- return tmp !== -1 ? $.vakata.array_remove(array, tmp) : array;
4907
- };
4908
- $.vakata.array_filter = function(c,a,b,d,e) {
4909
- if (c.filter) {
4910
- return c.filter(a, b);
4911
- }
4912
- d=[];
4913
- for (e in c) {
4914
- if (~~e+''===e+'' && e>=0 && a.call(b,c[e],+e,c)) {
4915
- d.push(c[e]);
4916
- }
4917
- }
4918
- return d;
4919
- };
4920
-
4921
-
4922
- /**
4923
- * ### Changed plugin
4924
- *
4925
- * This plugin adds more information to the `changed.jstree` event. The new data is contained in the `changed` event data property, and contains a lists of `selected` and `deselected` nodes.
4926
- */
4927
-
4928
- $.jstree.plugins.changed = function (options, parent) {
4929
- var last = [];
4930
- this.trigger = function (ev, data) {
4931
- var i, j;
4932
- if(!data) {
4933
- data = {};
4934
- }
4935
- if(ev.replace('.jstree','') === 'changed') {
4936
- data.changed = { selected : [], deselected : [] };
4937
- var tmp = {};
4938
- for(i = 0, j = last.length; i < j; i++) {
4939
- tmp[last[i]] = 1;
4940
- }
4941
- for(i = 0, j = data.selected.length; i < j; i++) {
4942
- if(!tmp[data.selected[i]]) {
4943
- data.changed.selected.push(data.selected[i]);
4944
- }
4945
- else {
4946
- tmp[data.selected[i]] = 2;
4947
- }
4948
- }
4949
- for(i = 0, j = last.length; i < j; i++) {
4950
- if(tmp[last[i]] === 1) {
4951
- data.changed.deselected.push(last[i]);
4952
- }
4953
- }
4954
- last = data.selected.slice();
4955
- }
4956
- /**
4957
- * triggered when selection changes (the "changed" plugin enhances the original event with more data)
4958
- * @event
4959
- * @name changed.jstree
4960
- * @param {Object} node
4961
- * @param {Object} action the action that caused the selection to change
4962
- * @param {Array} selected the current selection
4963
- * @param {Object} changed an object containing two properties `selected` and `deselected` - both arrays of node IDs, which were selected or deselected since the last changed event
4964
- * @param {Object} event the event (if any) that triggered this changed event
4965
- * @plugin changed
4966
- */
4967
- parent.trigger.call(this, ev, data);
4968
- };
4969
- this.refresh = function (skip_loading, forget_state) {
4970
- last = [];
4971
- return parent.refresh.apply(this, arguments);
4972
- };
4973
- };
4974
-
4975
- /**
4976
- * ### Checkbox plugin
4977
- *
4978
- * This plugin renders checkbox icons in front of each node, making multiple selection much easier.
4979
- * It also supports tri-state behavior, meaning that if a node has a few of its children checked it will be rendered as undetermined, and state will be propagated up.
4980
- */
4981
-
4982
- var _i = document.createElement('I');
4983
- _i.className = 'jstree-icon jstree-checkbox';
4984
- _i.setAttribute('role', 'presentation');
4985
- /**
4986
- * stores all defaults for the checkbox plugin
4987
- * @name $.jstree.defaults.checkbox
4988
- * @plugin checkbox
4989
- */
4990
- $.jstree.defaults.checkbox = {
4991
- /**
4992
- * a boolean indicating if checkboxes should be visible (can be changed at a later time using `show_checkboxes()` and `hide_checkboxes`). Defaults to `true`.
4993
- * @name $.jstree.defaults.checkbox.visible
4994
- * @plugin checkbox
4995
- */
4996
- visible : true,
4997
- /**
4998
- * a boolean indicating if checkboxes should cascade down and have an undetermined state. Defaults to `true`.
4999
- * @name $.jstree.defaults.checkbox.three_state
5000
- * @plugin checkbox
5001
- */
5002
- three_state : true,
5003
- /**
5004
- * a boolean indicating if clicking anywhere on the node should act as clicking on the checkbox. Defaults to `true`.
5005
- * @name $.jstree.defaults.checkbox.whole_node
5006
- * @plugin checkbox
5007
- */
5008
- whole_node : true,
5009
- /**
5010
- * a boolean indicating if the selected style of a node should be kept, or removed. Defaults to `true`.
5011
- * @name $.jstree.defaults.checkbox.keep_selected_style
5012
- * @plugin checkbox
5013
- */
5014
- keep_selected_style : true,
5015
- /**
5016
- * This setting controls how cascading and undetermined nodes are applied.
5017
- * If 'up' is in the string - cascading up is enabled, if 'down' is in the string - cascading down is enabled, if 'undetermined' is in the string - undetermined nodes will be used.
5018
- * If `three_state` is set to `true` this setting is automatically set to 'up+down+undetermined'. Defaults to ''.
5019
- * @name $.jstree.defaults.checkbox.cascade
5020
- * @plugin checkbox
5021
- */
5022
- cascade : '',
5023
- /**
5024
- * This setting controls if checkbox are bound to the general tree selection or to an internal array maintained by the checkbox plugin. Defaults to `true`, only set to `false` if you know exactly what you are doing.
5025
- * @name $.jstree.defaults.checkbox.tie_selection
5026
- * @plugin checkbox
5027
- */
5028
- tie_selection : true,
5029
-
5030
- /**
5031
- * This setting controls if cascading down affects disabled checkboxes
5032
- * @name $.jstree.defaults.checkbox.cascade_to_disabled
5033
- * @plugin checkbox
5034
- */
5035
- cascade_to_disabled : true,
5036
-
5037
- /**
5038
- * This setting controls if cascading down affects hidden checkboxes
5039
- * @name $.jstree.defaults.checkbox.cascade_to_hidden
5040
- * @plugin checkbox
5041
- */
5042
- cascade_to_hidden : true
5043
- };
5044
- $.jstree.plugins.checkbox = function (options, parent) {
5045
- this.bind = function () {
5046
- parent.bind.call(this);
5047
- this._data.checkbox.uto = false;
5048
- this._data.checkbox.selected = [];
5049
- if(this.settings.checkbox.three_state) {
5050
- this.settings.checkbox.cascade = 'up+down+undetermined';
5051
- }
5052
- this.element
5053
- .on("init.jstree", $.proxy(function () {
5054
- this._data.checkbox.visible = this.settings.checkbox.visible;
5055
- if(!this.settings.checkbox.keep_selected_style) {
5056
- this.element.addClass('jstree-checkbox-no-clicked');
5057
- }
5058
- if(this.settings.checkbox.tie_selection) {
5059
- this.element.addClass('jstree-checkbox-selection');
5060
- }
5061
- }, this))
5062
- .on("loading.jstree", $.proxy(function () {
5063
- this[ this._data.checkbox.visible ? 'show_checkboxes' : 'hide_checkboxes' ]();
5064
- }, this));
5065
- if(this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
5066
- this.element
5067
- .on('changed.jstree uncheck_node.jstree check_node.jstree uncheck_all.jstree check_all.jstree move_node.jstree copy_node.jstree redraw.jstree open_node.jstree', $.proxy(function () {
5068
- // only if undetermined is in setting
5069
- if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
5070
- this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
5071
- }, this));
5072
- }
5073
- if(!this.settings.checkbox.tie_selection) {
5074
- this.element
5075
- .on('model.jstree', $.proxy(function (e, data) {
5076
- var m = this._model.data,
5077
- p = m[data.parent],
5078
- dpc = data.nodes,
5079
- i, j;
5080
- for(i = 0, j = dpc.length; i < j; i++) {
5081
- m[dpc[i]].state.checked = m[dpc[i]].state.checked || (m[dpc[i]].original && m[dpc[i]].original.state && m[dpc[i]].original.state.checked);
5082
- if(m[dpc[i]].state.checked) {
5083
- this._data.checkbox.selected.push(dpc[i]);
5084
- }
5085
- }
5086
- }, this));
5087
- }
5088
- if(this.settings.checkbox.cascade.indexOf('up') !== -1 || this.settings.checkbox.cascade.indexOf('down') !== -1) {
5089
- this.element
5090
- .on('model.jstree', $.proxy(function (e, data) {
5091
- var m = this._model.data,
5092
- p = m[data.parent],
5093
- dpc = data.nodes,
5094
- chd = [],
5095
- c, i, j, k, l, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection;
5096
-
5097
- if(s.indexOf('down') !== -1) {
5098
- // apply down
5099
- if(p.state[ t ? 'selected' : 'checked' ]) {
5100
- for(i = 0, j = dpc.length; i < j; i++) {
5101
- m[dpc[i]].state[ t ? 'selected' : 'checked' ] = true;
5102
- }
5103
-
5104
- this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(dpc);
5105
- }
5106
- else {
5107
- for(i = 0, j = dpc.length; i < j; i++) {
5108
- if(m[dpc[i]].state[ t ? 'selected' : 'checked' ]) {
5109
- for(k = 0, l = m[dpc[i]].children_d.length; k < l; k++) {
5110
- m[m[dpc[i]].children_d[k]].state[ t ? 'selected' : 'checked' ] = true;
5111
- }
5112
- this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(m[dpc[i]].children_d);
5113
- }
5114
- }
5115
- }
5116
- }
5117
-
5118
- if(s.indexOf('up') !== -1) {
5119
- // apply up
5120
- for(i = 0, j = p.children_d.length; i < j; i++) {
5121
- if(!m[p.children_d[i]].children.length) {
5122
- chd.push(m[p.children_d[i]].parent);
5123
- }
5124
- }
5125
- chd = $.vakata.array_unique(chd);
5126
- for(k = 0, l = chd.length; k < l; k++) {
5127
- p = m[chd[k]];
5128
- while(p && p.id !== $.jstree.root) {
5129
- c = 0;
5130
- for(i = 0, j = p.children.length; i < j; i++) {
5131
- c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
5132
- }
5133
- if(c === j) {
5134
- p.state[ t ? 'selected' : 'checked' ] = true;
5135
- this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5136
- tmp = this.get_node(p, true);
5137
- if(tmp && tmp.length) {
5138
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass( t ? 'jstree-clicked' : 'jstree-checked');
5139
- }
5140
- }
5141
- else {
5142
- break;
5143
- }
5144
- p = this.get_node(p.parent);
5145
- }
5146
- }
5147
- }
5148
-
5149
- this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected);
5150
- }, this))
5151
- .on(this.settings.checkbox.tie_selection ? 'select_node.jstree' : 'check_node.jstree', $.proxy(function (e, data) {
5152
- var self = this,
5153
- obj = data.node,
5154
- m = this._model.data,
5155
- par = this.get_node(obj.parent),
5156
- i, j, c, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
5157
- sel = {}, cur = this._data[ t ? 'core' : 'checkbox' ].selected;
5158
-
5159
- for (i = 0, j = cur.length; i < j; i++) {
5160
- sel[cur[i]] = true;
5161
- }
5162
-
5163
- // apply down
5164
- if(s.indexOf('down') !== -1) {
5165
- //this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected.concat(obj.children_d));
5166
- var selectedIds = this._cascade_new_checked_state(obj.id, true);
5167
- var temp = obj.children_d.concat(obj.id);
5168
- for (i = 0, j = temp.length; i < j; i++) {
5169
- if (selectedIds.indexOf(temp[i]) > -1) {
5170
- sel[temp[i]] = true;
5171
- }
5172
- else {
5173
- delete sel[temp[i]];
5174
- }
5175
- }
5176
- }
5177
-
5178
- // apply up
5179
- if(s.indexOf('up') !== -1) {
5180
- while(par && par.id !== $.jstree.root) {
5181
- c = 0;
5182
- for(i = 0, j = par.children.length; i < j; i++) {
5183
- c += m[par.children[i]].state[ t ? 'selected' : 'checked' ];
5184
- }
5185
- if(c === j) {
5186
- par.state[ t ? 'selected' : 'checked' ] = true;
5187
- sel[par.id] = true;
5188
- //this._data[ t ? 'core' : 'checkbox' ].selected.push(par.id);
5189
- tmp = this.get_node(par, true);
5190
- if(tmp && tmp.length) {
5191
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5192
- }
5193
- }
5194
- else {
5195
- break;
5196
- }
5197
- par = this.get_node(par.parent);
5198
- }
5199
- }
5200
-
5201
- cur = [];
5202
- for (i in sel) {
5203
- if (sel.hasOwnProperty(i)) {
5204
- cur.push(i);
5205
- }
5206
- }
5207
- this._data[ t ? 'core' : 'checkbox' ].selected = cur;
5208
- }, this))
5209
- .on(this.settings.checkbox.tie_selection ? 'deselect_all.jstree' : 'uncheck_all.jstree', $.proxy(function (e, data) {
5210
- var obj = this.get_node($.jstree.root),
5211
- m = this._model.data,
5212
- i, j, tmp;
5213
- for(i = 0, j = obj.children_d.length; i < j; i++) {
5214
- tmp = m[obj.children_d[i]];
5215
- if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
5216
- tmp.original.state.undetermined = false;
5217
- }
5218
- }
5219
- }, this))
5220
- .on(this.settings.checkbox.tie_selection ? 'deselect_node.jstree' : 'uncheck_node.jstree', $.proxy(function (e, data) {
5221
- var self = this,
5222
- obj = data.node,
5223
- dom = this.get_node(obj, true),
5224
- i, j, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
5225
- cur = this._data[ t ? 'core' : 'checkbox' ].selected, sel = {},
5226
- stillSelectedIds = [],
5227
- allIds = obj.children_d.concat(obj.id);
5228
-
5229
- // apply down
5230
- if(s.indexOf('down') !== -1) {
5231
- var selectedIds = this._cascade_new_checked_state(obj.id, false);
5232
-
5233
- cur = cur.filter(function(id) {
5234
- return allIds.indexOf(id) === -1 || selectedIds.indexOf(id) > -1;
5235
- });
5236
- }
5237
-
5238
- // only apply up if cascade up is enabled and if this node is not selected
5239
- // (if all child nodes are disabled and cascade_to_disabled === false then this node will till be selected).
5240
- if(s.indexOf('up') !== -1 && cur.indexOf(obj.id) === -1) {
5241
- for(i = 0, j = obj.parents.length; i < j; i++) {
5242
- tmp = this._model.data[obj.parents[i]];
5243
- tmp.state[ t ? 'selected' : 'checked' ] = false;
5244
- if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
5245
- tmp.original.state.undetermined = false;
5246
- }
5247
- tmp = this.get_node(obj.parents[i], true);
5248
- if(tmp && tmp.length) {
5249
- tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5250
- }
5251
- }
5252
-
5253
- cur = cur.filter(function(id) {
5254
- return obj.parents.indexOf(id) === -1;
5255
- });
5256
- }
5257
-
5258
- this._data[ t ? 'core' : 'checkbox' ].selected = cur;
5259
- }, this));
5260
- }
5261
- if(this.settings.checkbox.cascade.indexOf('up') !== -1) {
5262
- this.element
5263
- .on('delete_node.jstree', $.proxy(function (e, data) {
5264
- // apply up (whole handler)
5265
- var p = this.get_node(data.parent),
5266
- m = this._model.data,
5267
- i, j, c, tmp, t = this.settings.checkbox.tie_selection;
5268
- while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
5269
- c = 0;
5270
- for(i = 0, j = p.children.length; i < j; i++) {
5271
- c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
5272
- }
5273
- if(j > 0 && c === j) {
5274
- p.state[ t ? 'selected' : 'checked' ] = true;
5275
- this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5276
- tmp = this.get_node(p, true);
5277
- if(tmp && tmp.length) {
5278
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5279
- }
5280
- }
5281
- else {
5282
- break;
5283
- }
5284
- p = this.get_node(p.parent);
5285
- }
5286
- }, this))
5287
- .on('move_node.jstree', $.proxy(function (e, data) {
5288
- // apply up (whole handler)
5289
- var is_multi = data.is_multi,
5290
- old_par = data.old_parent,
5291
- new_par = this.get_node(data.parent),
5292
- m = this._model.data,
5293
- p, c, i, j, tmp, t = this.settings.checkbox.tie_selection;
5294
- if(!is_multi) {
5295
- p = this.get_node(old_par);
5296
- while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
5297
- c = 0;
5298
- for(i = 0, j = p.children.length; i < j; i++) {
5299
- c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
5300
- }
5301
- if(j > 0 && c === j) {
5302
- p.state[ t ? 'selected' : 'checked' ] = true;
5303
- this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5304
- tmp = this.get_node(p, true);
5305
- if(tmp && tmp.length) {
5306
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5307
- }
5308
- }
5309
- else {
5310
- break;
5311
- }
5312
- p = this.get_node(p.parent);
5313
- }
5314
- }
5315
- p = new_par;
5316
- while(p && p.id !== $.jstree.root) {
5317
- c = 0;
5318
- for(i = 0, j = p.children.length; i < j; i++) {
5319
- c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
5320
- }
5321
- if(c === j) {
5322
- if(!p.state[ t ? 'selected' : 'checked' ]) {
5323
- p.state[ t ? 'selected' : 'checked' ] = true;
5324
- this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5325
- tmp = this.get_node(p, true);
5326
- if(tmp && tmp.length) {
5327
- tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5328
- }
5329
- }
5330
- }
5331
- else {
5332
- if(p.state[ t ? 'selected' : 'checked' ]) {
5333
- p.state[ t ? 'selected' : 'checked' ] = false;
5334
- this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_remove_item(this._data[ t ? 'core' : 'checkbox' ].selected, p.id);
5335
- tmp = this.get_node(p, true);
5336
- if(tmp && tmp.length) {
5337
- tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5338
- }
5339
- }
5340
- else {
5341
- break;
5342
- }
5343
- }
5344
- p = this.get_node(p.parent);
5345
- }
5346
- }, this));
5347
- }
5348
- };
5349
- /**
5350
- * get an array of all nodes whose state is "undetermined"
5351
- * @name get_undetermined([full])
5352
- * @param {boolean} full: if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
5353
- * @return {Array}
5354
- * @plugin checkbox
5355
- */
5356
- this.get_undetermined = function (full) {
5357
- if (this.settings.checkbox.cascade.indexOf('undetermined') === -1) {
5358
- return [];
5359
- }
5360
- 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, r = [];
5361
- for(i = 0, j = s.length; i < j; i++) {
5362
- if(m[s[i]] && m[s[i]].parents) {
5363
- for(k = 0, l = m[s[i]].parents.length; k < l; k++) {
5364
- if(o[m[s[i]].parents[k]] !== undefined) {
5365
- break;
5366
- }
5367
- if(m[s[i]].parents[k] !== $.jstree.root) {
5368
- o[m[s[i]].parents[k]] = true;
5369
- p.push(m[s[i]].parents[k]);
5370
- }
5371
- }
5372
- }
5373
- }
5374
- // attempt for server side undetermined state
5375
- this.element.find('.jstree-closed').not(':has(.jstree-children)')
5376
- .each(function () {
5377
- var tmp = tt.get_node(this), tmp2;
5378
-
5379
- if(!tmp) { return; }
5380
-
5381
- if(!tmp.state.loaded) {
5382
- if(tmp.original && tmp.original.state && tmp.original.state.undetermined && tmp.original.state.undetermined === true) {
5383
- if(o[tmp.id] === undefined && tmp.id !== $.jstree.root) {
5384
- o[tmp.id] = true;
5385
- p.push(tmp.id);
5386
- }
5387
- for(k = 0, l = tmp.parents.length; k < l; k++) {
5388
- if(o[tmp.parents[k]] === undefined && tmp.parents[k] !== $.jstree.root) {
5389
- o[tmp.parents[k]] = true;
5390
- p.push(tmp.parents[k]);
5391
- }
5392
- }
5393
- }
5394
- }
5395
- else {
5396
- for(i = 0, j = tmp.children_d.length; i < j; i++) {
5397
- tmp2 = m[tmp.children_d[i]];
5398
- if(!tmp2.state.loaded && tmp2.original && tmp2.original.state && tmp2.original.state.undetermined && tmp2.original.state.undetermined === true) {
5399
- if(o[tmp2.id] === undefined && tmp2.id !== $.jstree.root) {
5400
- o[tmp2.id] = true;
5401
- p.push(tmp2.id);
5402
- }
5403
- for(k = 0, l = tmp2.parents.length; k < l; k++) {
5404
- if(o[tmp2.parents[k]] === undefined && tmp2.parents[k] !== $.jstree.root) {
5405
- o[tmp2.parents[k]] = true;
5406
- p.push(tmp2.parents[k]);
5407
- }
5408
- }
5409
- }
5410
- }
5411
- }
5412
- });
5413
- for (i = 0, j = p.length; i < j; i++) {
5414
- if(!m[p[i]].state[ t ? 'selected' : 'checked' ]) {
5415
- r.push(full ? m[p[i]] : p[i]);
5416
- }
5417
- }
5418
- return r;
5419
- };
5420
- /**
5421
- * set the undetermined state where and if necessary. Used internally.
5422
- * @private
5423
- * @name _undetermined()
5424
- * @plugin checkbox
5425
- */
5426
- this._undetermined = function () {
5427
- if(this.element === null) { return; }
5428
- var p = this.get_undetermined(false), i, j, s;
5429
-
5430
- this.element.find('.jstree-undetermined').removeClass('jstree-undetermined');
5431
- for (i = 0, j = p.length; i < j; i++) {
5432
- s = this.get_node(p[i], true);
5433
- if(s && s.length) {
5434
- s.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-undetermined');
5435
- }
5436
- }
5437
- };
5438
- this.redraw_node = function(obj, deep, is_callback, force_render) {
5439
- obj = parent.redraw_node.apply(this, arguments);
5440
- if(obj) {
5441
- var i, j, tmp = null, icon = null;
5442
- for(i = 0, j = obj.childNodes.length; i < j; i++) {
5443
- if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
5444
- tmp = obj.childNodes[i];
5445
- break;
5446
- }
5447
- }
5448
- if(tmp) {
5449
- if(!this.settings.checkbox.tie_selection && this._model.data[obj.id].state.checked) { tmp.className += ' jstree-checked'; }
5450
- icon = _i.cloneNode(false);
5451
- if(this._model.data[obj.id].state.checkbox_disabled) { icon.className += ' jstree-checkbox-disabled'; }
5452
- tmp.insertBefore(icon, tmp.childNodes[0]);
5453
- }
5454
- }
5455
- if(!is_callback && this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
5456
- if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
5457
- this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
5458
- }
5459
- return obj;
5460
- };
5461
- /**
5462
- * show the node checkbox icons
5463
- * @name show_checkboxes()
5464
- * @plugin checkbox
5465
- */
5466
- this.show_checkboxes = function () { this._data.core.themes.checkboxes = true; this.get_container_ul().removeClass("jstree-no-checkboxes"); };
5467
- /**
5468
- * hide the node checkbox icons
5469
- * @name hide_checkboxes()
5470
- * @plugin checkbox
5471
- */
5472
- this.hide_checkboxes = function () { this._data.core.themes.checkboxes = false; this.get_container_ul().addClass("jstree-no-checkboxes"); };
5473
- /**
5474
- * toggle the node icons
5475
- * @name toggle_checkboxes()
5476
- * @plugin checkbox
5477
- */
5478
- this.toggle_checkboxes = function () { if(this._data.core.themes.checkboxes) { this.hide_checkboxes(); } else { this.show_checkboxes(); } };
5479
- /**
5480
- * checks if a node is in an undetermined state
5481
- * @name is_undetermined(obj)
5482
- * @param {mixed} obj
5483
- * @return {Boolean}
5484
- */
5485
- this.is_undetermined = function (obj) {
5486
- obj = this.get_node(obj);
5487
- var s = this.settings.checkbox.cascade, i, j, t = this.settings.checkbox.tie_selection, d = this._data[ t ? 'core' : 'checkbox' ].selected, m = this._model.data;
5488
- if(!obj || obj.state[ t ? 'selected' : 'checked' ] === true || s.indexOf('undetermined') === -1 || (s.indexOf('down') === -1 && s.indexOf('up') === -1)) {
5489
- return false;
5490
- }
5491
- if(!obj.state.loaded && obj.original.state.undetermined === true) {
5492
- return true;
5493
- }
5494
- for(i = 0, j = obj.children_d.length; i < j; i++) {
5495
- if($.inArray(obj.children_d[i], d) !== -1 || (!m[obj.children_d[i]].state.loaded && m[obj.children_d[i]].original.state.undetermined)) {
5496
- return true;
5497
- }
5498
- }
5499
- return false;
5500
- };
5501
- /**
5502
- * disable a node's checkbox
5503
- * @name disable_checkbox(obj)
5504
- * @param {mixed} obj an array can be used too
5505
- * @trigger disable_checkbox.jstree
5506
- * @plugin checkbox
5507
- */
5508
- this.disable_checkbox = function (obj) {
5509
- var t1, t2, dom;
5510
- if($.isArray(obj)) {
5511
- obj = obj.slice();
5512
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5513
- this.disable_checkbox(obj[t1]);
5514
- }
5515
- return true;
5516
- }
5517
- obj = this.get_node(obj);
5518
- if(!obj || obj.id === $.jstree.root) {
5519
- return false;
5520
- }
5521
- dom = this.get_node(obj, true);
5522
- if(!obj.state.checkbox_disabled) {
5523
- obj.state.checkbox_disabled = true;
5524
- if(dom && dom.length) {
5525
- dom.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-checkbox-disabled');
5526
- }
5527
- /**
5528
- * triggered when an node's checkbox is disabled
5529
- * @event
5530
- * @name disable_checkbox.jstree
5531
- * @param {Object} node
5532
- * @plugin checkbox
5533
- */
5534
- this.trigger('disable_checkbox', { 'node' : obj });
5535
- }
5536
- };
5537
- /**
5538
- * enable a node's checkbox
5539
- * @name disable_checkbox(obj)
5540
- * @param {mixed} obj an array can be used too
5541
- * @trigger enable_checkbox.jstree
5542
- * @plugin checkbox
5543
- */
5544
- this.enable_checkbox = function (obj) {
5545
- var t1, t2, dom;
5546
- if($.isArray(obj)) {
5547
- obj = obj.slice();
5548
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5549
- this.enable_checkbox(obj[t1]);
5550
- }
5551
- return true;
5552
- }
5553
- obj = this.get_node(obj);
5554
- if(!obj || obj.id === $.jstree.root) {
5555
- return false;
5556
- }
5557
- dom = this.get_node(obj, true);
5558
- if(obj.state.checkbox_disabled) {
5559
- obj.state.checkbox_disabled = false;
5560
- if(dom && dom.length) {
5561
- dom.children('.jstree-anchor').children('.jstree-checkbox').removeClass('jstree-checkbox-disabled');
5562
- }
5563
- /**
5564
- * triggered when an node's checkbox is enabled
5565
- * @event
5566
- * @name enable_checkbox.jstree
5567
- * @param {Object} node
5568
- * @plugin checkbox
5569
- */
5570
- this.trigger('enable_checkbox', { 'node' : obj });
5571
- }
5572
- };
5573
-
5574
- this.activate_node = function (obj, e) {
5575
- if($(e.target).hasClass('jstree-checkbox-disabled')) {
5576
- return false;
5577
- }
5578
- if(this.settings.checkbox.tie_selection && (this.settings.checkbox.whole_node || $(e.target).hasClass('jstree-checkbox'))) {
5579
- e.ctrlKey = true;
5580
- }
5581
- if(this.settings.checkbox.tie_selection || (!this.settings.checkbox.whole_node && !$(e.target).hasClass('jstree-checkbox'))) {
5582
- return parent.activate_node.call(this, obj, e);
5583
- }
5584
- if(this.is_disabled(obj)) {
5585
- return false;
5586
- }
5587
- if(this.is_checked(obj)) {
5588
- this.uncheck_node(obj, e);
5589
- }
5590
- else {
5591
- this.check_node(obj, e);
5592
- }
5593
- this.trigger('activate_node', { 'node' : this.get_node(obj) });
5594
- };
5595
-
5596
- /**
5597
- * Cascades checked state to a node and all its descendants. This function does NOT affect hidden and disabled nodes (or their descendants).
5598
- * However if these unaffected nodes are already selected their ids will be included in the returned array.
5599
- * @private
5600
- * @param {string} id the node ID
5601
- * @param {bool} checkedState should the nodes be checked or not
5602
- * @returns {Array} Array of all node id's (in this tree branch) that are checked.
5603
- */
5604
- this._cascade_new_checked_state = function (id, checkedState) {
5605
- var self = this;
5606
- var t = this.settings.checkbox.tie_selection;
5607
- var node = this._model.data[id];
5608
- var selectedNodeIds = [];
5609
- var selectedChildrenIds = [], i, j, selectedChildIds;
5610
-
5611
- if (
5612
- (this.settings.checkbox.cascade_to_disabled || !node.state.disabled) &&
5613
- (this.settings.checkbox.cascade_to_hidden || !node.state.hidden)
5614
- ) {
5615
- //First try and check/uncheck the children
5616
- if (node.children) {
5617
- for (i = 0, j = node.children.length; i < j; i++) {
5618
- var childId = node.children[i];
5619
- selectedChildIds = self._cascade_new_checked_state(childId, checkedState);
5620
- selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
5621
- if (selectedChildIds.indexOf(childId) > -1) {
5622
- selectedChildrenIds.push(childId);
5623
- }
5624
- }
5625
- }
5626
-
5627
- var dom = self.get_node(node, true);
5628
-
5629
- //A node's state is undetermined if some but not all of it's children are checked/selected .
5630
- var undetermined = selectedChildrenIds.length > 0 && selectedChildrenIds.length < node.children.length;
5631
-
5632
- if(node.original && node.original.state && node.original.state.undetermined) {
5633
- node.original.state.undetermined = undetermined;
5634
- }
5635
-
5636
- //If a node is undetermined then remove selected class
5637
- if (undetermined) {
5638
- node.state[ t ? 'selected' : 'checked' ] = false;
5639
- dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5640
- }
5641
- //Otherwise, if the checkedState === true (i.e. the node is being checked now) and all of the node's children are checked (if it has any children),
5642
- //check the node and style it correctly.
5643
- else if (checkedState && selectedChildrenIds.length === node.children.length) {
5644
- node.state[ t ? 'selected' : 'checked' ] = checkedState;
5645
- selectedNodeIds.push(node.id);
5646
-
5647
- dom.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5648
- }
5649
- else {
5650
- node.state[ t ? 'selected' : 'checked' ] = false;
5651
- dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5652
- }
5653
- }
5654
- else {
5655
- selectedChildIds = this.get_checked_descendants(id);
5656
-
5657
- if (node.state[ t ? 'selected' : 'checked' ]) {
5658
- selectedChildIds.push(node.id);
5659
- }
5660
-
5661
- selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
5662
- }
5663
-
5664
- return selectedNodeIds;
5665
- };
5666
-
5667
- /**
5668
- * Gets ids of nodes selected in branch (of tree) specified by id (does not include the node specified by id)
5669
- * @name get_checked_descendants(obj)
5670
- * @param {string} id the node ID
5671
- * @return {Array} array of IDs
5672
- * @plugin checkbox
5673
- */
5674
- this.get_checked_descendants = function (id) {
5675
- var self = this;
5676
- var t = self.settings.checkbox.tie_selection;
5677
- var node = self._model.data[id];
5678
-
5679
- return node.children_d.filter(function(_id) {
5680
- return self._model.data[_id].state[ t ? 'selected' : 'checked' ];
5681
- });
5682
- };
5683
-
5684
- /**
5685
- * check a node (only if tie_selection in checkbox settings is false, otherwise select_node will be called internally)
5686
- * @name check_node(obj)
5687
- * @param {mixed} obj an array can be used to check multiple nodes
5688
- * @trigger check_node.jstree
5689
- * @plugin checkbox
5690
- */
5691
- this.check_node = function (obj, e) {
5692
- if(this.settings.checkbox.tie_selection) { return this.select_node(obj, false, true, e); }
5693
- var dom, t1, t2, th;
5694
- if($.isArray(obj)) {
5695
- obj = obj.slice();
5696
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5697
- this.check_node(obj[t1], e);
5698
- }
5699
- return true;
5700
- }
5701
- obj = this.get_node(obj);
5702
- if(!obj || obj.id === $.jstree.root) {
5703
- return false;
5704
- }
5705
- dom = this.get_node(obj, true);
5706
- if(!obj.state.checked) {
5707
- obj.state.checked = true;
5708
- this._data.checkbox.selected.push(obj.id);
5709
- if(dom && dom.length) {
5710
- dom.children('.jstree-anchor').addClass('jstree-checked');
5711
- }
5712
- /**
5713
- * triggered when an node is checked (only if tie_selection in checkbox settings is false)
5714
- * @event
5715
- * @name check_node.jstree
5716
- * @param {Object} node
5717
- * @param {Array} selected the current selection
5718
- * @param {Object} event the event (if any) that triggered this check_node
5719
- * @plugin checkbox
5720
- */
5721
- this.trigger('check_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
5722
- }
5723
- };
5724
- /**
5725
- * uncheck a node (only if tie_selection in checkbox settings is false, otherwise deselect_node will be called internally)
5726
- * @name uncheck_node(obj)
5727
- * @param {mixed} obj an array can be used to uncheck multiple nodes
5728
- * @trigger uncheck_node.jstree
5729
- * @plugin checkbox
5730
- */
5731
- this.uncheck_node = function (obj, e) {
5732
- if(this.settings.checkbox.tie_selection) { return this.deselect_node(obj, false, e); }
5733
- var t1, t2, dom;
5734
- if($.isArray(obj)) {
5735
- obj = obj.slice();
5736
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5737
- this.uncheck_node(obj[t1], e);
5738
- }
5739
- return true;
5740
- }
5741
- obj = this.get_node(obj);
5742
- if(!obj || obj.id === $.jstree.root) {
5743
- return false;
5744
- }
5745
- dom = this.get_node(obj, true);
5746
- if(obj.state.checked) {
5747
- obj.state.checked = false;
5748
- this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, obj.id);
5749
- if(dom.length) {
5750
- dom.children('.jstree-anchor').removeClass('jstree-checked');
5751
- }
5752
- /**
5753
- * triggered when an node is unchecked (only if tie_selection in checkbox settings is false)
5754
- * @event
5755
- * @name uncheck_node.jstree
5756
- * @param {Object} node
5757
- * @param {Array} selected the current selection
5758
- * @param {Object} event the event (if any) that triggered this uncheck_node
5759
- * @plugin checkbox
5760
- */
5761
- this.trigger('uncheck_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
5762
- }
5763
- };
5764
-
5765
- /**
5766
- * checks all nodes in the tree (only if tie_selection in checkbox settings is false, otherwise select_all will be called internally)
5767
- * @name check_all()
5768
- * @trigger check_all.jstree, changed.jstree
5769
- * @plugin checkbox
5770
- */
5771
- this.check_all = function () {
5772
- if(this.settings.checkbox.tie_selection) { return this.select_all(); }
5773
- var tmp = this._data.checkbox.selected.concat([]), i, j;
5774
- this._data.checkbox.selected = this._model.data[$.jstree.root].children_d.concat();
5775
- for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
5776
- if(this._model.data[this._data.checkbox.selected[i]]) {
5777
- this._model.data[this._data.checkbox.selected[i]].state.checked = true;
5778
- }
5779
- }
5780
- this.redraw(true);
5781
- /**
5782
- * triggered when all nodes are checked (only if tie_selection in checkbox settings is false)
5783
- * @event
5784
- * @name check_all.jstree
5785
- * @param {Array} selected the current selection
5786
- * @plugin checkbox
5787
- */
5788
- this.trigger('check_all', { 'selected' : this._data.checkbox.selected });
5789
- };
5790
- /**
5791
- * uncheck all checked nodes (only if tie_selection in checkbox settings is false, otherwise deselect_all will be called internally)
5792
- * @name uncheck_all()
5793
- * @trigger uncheck_all.jstree
5794
- * @plugin checkbox
5795
- */
5796
- this.uncheck_all = function () {
5797
- if(this.settings.checkbox.tie_selection) { return this.deselect_all(); }
5798
- var tmp = this._data.checkbox.selected.concat([]), i, j;
5799
- for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
5800
- if(this._model.data[this._data.checkbox.selected[i]]) {
5801
- this._model.data[this._data.checkbox.selected[i]].state.checked = false;
5802
- }
5803
- }
5804
- this._data.checkbox.selected = [];
5805
- this.element.find('.jstree-checked').removeClass('jstree-checked');
5806
- /**
5807
- * triggered when all nodes are unchecked (only if tie_selection in checkbox settings is false)
5808
- * @event
5809
- * @name uncheck_all.jstree
5810
- * @param {Object} node the previous selection
5811
- * @param {Array} selected the current selection
5812
- * @plugin checkbox
5813
- */
5814
- this.trigger('uncheck_all', { 'selected' : this._data.checkbox.selected, 'node' : tmp });
5815
- };
5816
- /**
5817
- * checks if a node is checked (if tie_selection is on in the settings this function will return the same as is_selected)
5818
- * @name is_checked(obj)
5819
- * @param {mixed} obj
5820
- * @return {Boolean}
5821
- * @plugin checkbox
5822
- */
5823
- this.is_checked = function (obj) {
5824
- if(this.settings.checkbox.tie_selection) { return this.is_selected(obj); }
5825
- obj = this.get_node(obj);
5826
- if(!obj || obj.id === $.jstree.root) { return false; }
5827
- return obj.state.checked;
5828
- };
5829
- /**
5830
- * get an array of all checked nodes (if tie_selection is on in the settings this function will return the same as get_selected)
5831
- * @name get_checked([full])
5832
- * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
5833
- * @return {Array}
5834
- * @plugin checkbox
5835
- */
5836
- this.get_checked = function (full) {
5837
- if(this.settings.checkbox.tie_selection) { return this.get_selected(full); }
5838
- return full ? $.map(this._data.checkbox.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.checkbox.selected;
5839
- };
5840
- /**
5841
- * get an array of all top level checked nodes (ignoring children of checked nodes) (if tie_selection is on in the settings this function will return the same as get_top_selected)
5842
- * @name get_top_checked([full])
5843
- * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
5844
- * @return {Array}
5845
- * @plugin checkbox
5846
- */
5847
- this.get_top_checked = function (full) {
5848
- if(this.settings.checkbox.tie_selection) { return this.get_top_selected(full); }
5849
- var tmp = this.get_checked(true),
5850
- obj = {}, i, j, k, l;
5851
- for(i = 0, j = tmp.length; i < j; i++) {
5852
- obj[tmp[i].id] = tmp[i];
5853
- }
5854
- for(i = 0, j = tmp.length; i < j; i++) {
5855
- for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
5856
- if(obj[tmp[i].children_d[k]]) {
5857
- delete obj[tmp[i].children_d[k]];
5858
- }
5859
- }
5860
- }
5861
- tmp = [];
5862
- for(i in obj) {
5863
- if(obj.hasOwnProperty(i)) {
5864
- tmp.push(i);
5865
- }
5866
- }
5867
- return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
5868
- };
5869
- /**
5870
- * get an array of all bottom level checked nodes (ignoring selected parents) (if tie_selection is on in the settings this function will return the same as get_bottom_selected)
5871
- * @name get_bottom_checked([full])
5872
- * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
5873
- * @return {Array}
5874
- * @plugin checkbox
5875
- */
5876
- this.get_bottom_checked = function (full) {
5877
- if(this.settings.checkbox.tie_selection) { return this.get_bottom_selected(full); }
5878
- var tmp = this.get_checked(true),
5879
- obj = [], i, j;
5880
- for(i = 0, j = tmp.length; i < j; i++) {
5881
- if(!tmp[i].children.length) {
5882
- obj.push(tmp[i].id);
5883
- }
5884
- }
5885
- return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
5886
- };
5887
- this.load_node = function (obj, callback) {
5888
- var k, l, i, j, c, tmp;
5889
- if(!$.isArray(obj) && !this.settings.checkbox.tie_selection) {
5890
- tmp = this.get_node(obj);
5891
- if(tmp && tmp.state.loaded) {
5892
- for(k = 0, l = tmp.children_d.length; k < l; k++) {
5893
- if(this._model.data[tmp.children_d[k]].state.checked) {
5894
- c = true;
5895
- this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, tmp.children_d[k]);
5896
- }
5897
- }
5898
- }
5899
- }
5900
- return parent.load_node.apply(this, arguments);
5901
- };
5902
- this.get_state = function () {
5903
- var state = parent.get_state.apply(this, arguments);
5904
- if(this.settings.checkbox.tie_selection) { return state; }
5905
- state.checkbox = this._data.checkbox.selected.slice();
5906
- return state;
5907
- };
5908
- this.set_state = function (state, callback) {
5909
- var res = parent.set_state.apply(this, arguments);
5910
- if(res && state.checkbox) {
5911
- if(!this.settings.checkbox.tie_selection) {
5912
- this.uncheck_all();
5913
- var _this = this;
5914
- $.each(state.checkbox, function (i, v) {
5915
- _this.check_node(v);
5916
- });
5917
- }
5918
- delete state.checkbox;
5919
- this.set_state(state, callback);
5920
- return false;
5921
- }
5922
- return res;
5923
- };
5924
- this.refresh = function (skip_loading, forget_state) {
5925
- if(!this.settings.checkbox.tie_selection) {
5926
- this._data.checkbox.selected = [];
5927
- }
5928
- return parent.refresh.apply(this, arguments);
5929
- };
5930
- };
5931
-
5932
- // include the checkbox plugin by default
5933
- // $.jstree.defaults.plugins.push("checkbox");
5934
-
5935
-
5936
- /**
5937
- * ### Conditionalselect plugin
5938
- *
5939
- * This plugin allows defining a callback to allow or deny node selection by user input (activate node method).
5940
- */
5941
-
5942
- /**
5943
- * a callback (function) which is invoked in the instance's scope and receives two arguments - the node and the event that triggered the `activate_node` call. Returning false prevents working with the node, returning true allows invoking activate_node. Defaults to returning `true`.
5944
- * @name $.jstree.defaults.checkbox.visible
5945
- * @plugin checkbox
5946
- */
5947
- $.jstree.defaults.conditionalselect = function () { return true; };
5948
- $.jstree.plugins.conditionalselect = function (options, parent) {
5949
- // own function
5950
- this.activate_node = function (obj, e) {
5951
- if(this.settings.conditionalselect.call(this, this.get_node(obj), e)) {
5952
- return parent.activate_node.call(this, obj, e);
5953
- }
5954
- };
5955
- };
5956
-
5957
-
5958
- /**
5959
- * ### Contextmenu plugin
5960
- *
5961
- * Shows a context menu when a node is right-clicked.
5962
- */
5963
-
5964
- /**
5965
- * stores all defaults for the contextmenu plugin
5966
- * @name $.jstree.defaults.contextmenu
5967
- * @plugin contextmenu
5968
- */
5969
- $.jstree.defaults.contextmenu = {
5970
- /**
5971
- * a boolean indicating if the node should be selected when the context menu is invoked on it. Defaults to `true`.
5972
- * @name $.jstree.defaults.contextmenu.select_node
5973
- * @plugin contextmenu
5974
- */
5975
- select_node : true,
5976
- /**
5977
- * a boolean indicating if the menu should be shown aligned with the node. Defaults to `true`, otherwise the mouse coordinates are used.
5978
- * @name $.jstree.defaults.contextmenu.show_at_node
5979
- * @plugin contextmenu
5980
- */
5981
- show_at_node : true,
5982
- /**
5983
- * an object of actions, or a function that accepts a node and a callback function and calls the callback function with an object of actions available for that node (you can also return the items too).
5984
- *
5985
- * Each action consists of a key (a unique name) and a value which is an object with the following properties (only label and action are required). Once a menu item is activated the `action` function will be invoked with an object containing the following keys: item - the contextmenu item definition as seen below, reference - the DOM node that was used (the tree node), element - the contextmenu DOM element, position - an object with x/y properties indicating the position of the menu.
5986
- *
5987
- * * `separator_before` - a boolean indicating if there should be a separator before this item
5988
- * * `separator_after` - a boolean indicating if there should be a separator after this item
5989
- * * `_disabled` - a boolean indicating if this action should be disabled
5990
- * * `label` - a string - the name of the action (could be a function returning a string)
5991
- * * `title` - a string - an optional tooltip for the item
5992
- * * `action` - a function to be executed if this item is chosen, the function will receive
5993
- * * `icon` - a string, can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
5994
- * * `shortcut` - keyCode which will trigger the action if the menu is open (for example `113` for rename, which equals F2)
5995
- * * `shortcut_label` - shortcut label (like for example `F2` for rename)
5996
- * * `submenu` - an object with the same structure as $.jstree.defaults.contextmenu.items which can be used to create a submenu - each key will be rendered as a separate option in a submenu that will appear once the current item is hovered
5997
- *
5998
- * @name $.jstree.defaults.contextmenu.items
5999
- * @plugin contextmenu
6000
- */
6001
- items : function (o, cb) { // Could be an object directly
6002
- return {
6003
- "create" : {
6004
- "separator_before" : false,
6005
- "separator_after" : true,
6006
- "_disabled" : false, //(this.check("create_node", data.reference, {}, "last")),
6007
- "label" : "Create",
6008
- "action" : function (data) {
6009
- var inst = $.jstree.reference(data.reference),
6010
- obj = inst.get_node(data.reference);
6011
- inst.create_node(obj, {}, "last", function (new_node) {
6012
- try {
6013
- inst.edit(new_node);
6014
- } catch (ex) {
6015
- setTimeout(function () { inst.edit(new_node); },0);
6016
- }
6017
- });
6018
- }
6019
- },
6020
- "rename" : {
6021
- "separator_before" : false,
6022
- "separator_after" : false,
6023
- "_disabled" : false, //(this.check("rename_node", data.reference, this.get_parent(data.reference), "")),
6024
- "label" : "Rename",
6025
- /*!
6026
- "shortcut" : 113,
6027
- "shortcut_label" : 'F2',
6028
- "icon" : "glyphicon glyphicon-leaf",
6029
- */
6030
- "action" : function (data) {
6031
- var inst = $.jstree.reference(data.reference),
6032
- obj = inst.get_node(data.reference);
6033
- inst.edit(obj);
6034
- }
6035
- },
6036
- "remove" : {
6037
- "separator_before" : false,
6038
- "icon" : false,
6039
- "separator_after" : false,
6040
- "_disabled" : false, //(this.check("delete_node", data.reference, this.get_parent(data.reference), "")),
6041
- "label" : "Delete",
6042
- "action" : function (data) {
6043
- var inst = $.jstree.reference(data.reference),
6044
- obj = inst.get_node(data.reference);
6045
- if(inst.is_selected(obj)) {
6046
- inst.delete_node(inst.get_selected());
6047
- }
6048
- else {
6049
- inst.delete_node(obj);
6050
- }
6051
- }
6052
- },
6053
- "ccp" : {
6054
- "separator_before" : true,
6055
- "icon" : false,
6056
- "separator_after" : false,
6057
- "label" : "Edit",
6058
- "action" : false,
6059
- "submenu" : {
6060
- "cut" : {
6061
- "separator_before" : false,
6062
- "separator_after" : false,
6063
- "label" : "Cut",
6064
- "action" : function (data) {
6065
- var inst = $.jstree.reference(data.reference),
6066
- obj = inst.get_node(data.reference);
6067
- if(inst.is_selected(obj)) {
6068
- inst.cut(inst.get_top_selected());
6069
- }
6070
- else {
6071
- inst.cut(obj);
6072
- }
6073
- }
6074
- },
6075
- "copy" : {
6076
- "separator_before" : false,
6077
- "icon" : false,
6078
- "separator_after" : false,
6079
- "label" : "Copy",
6080
- "action" : function (data) {
6081
- var inst = $.jstree.reference(data.reference),
6082
- obj = inst.get_node(data.reference);
6083
- if(inst.is_selected(obj)) {
6084
- inst.copy(inst.get_top_selected());
6085
- }
6086
- else {
6087
- inst.copy(obj);
6088
- }
6089
- }
6090
- },
6091
- "paste" : {
6092
- "separator_before" : false,
6093
- "icon" : false,
6094
- "_disabled" : function (data) {
6095
- return !$.jstree.reference(data.reference).can_paste();
6096
- },
6097
- "separator_after" : false,
6098
- "label" : "Paste",
6099
- "action" : function (data) {
6100
- var inst = $.jstree.reference(data.reference),
6101
- obj = inst.get_node(data.reference);
6102
- inst.paste(obj);
6103
- }
6104
- }
6105
- }
6106
- }
6107
- };
6108
- }
6109
- };
6110
-
6111
- $.jstree.plugins.contextmenu = function (options, parent) {
6112
- this.bind = function () {
6113
- parent.bind.call(this);
6114
-
6115
- var last_ts = 0, cto = null, ex, ey;
6116
- this.element
6117
- .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
6118
- this.get_container_ul().addClass('jstree-contextmenu');
6119
- }, this))
6120
- .on("contextmenu.jstree", ".jstree-anchor", $.proxy(function (e, data) {
6121
- if (e.target.tagName.toLowerCase() === 'input') {
6122
- return;
6123
- }
6124
- e.preventDefault();
6125
- last_ts = e.ctrlKey ? +new Date() : 0;
6126
- if(data || cto) {
6127
- last_ts = (+new Date()) + 10000;
6128
- }
6129
- if(cto) {
6130
- clearTimeout(cto);
6131
- }
6132
- if(!this.is_loading(e.currentTarget)) {
6133
- this.show_contextmenu(e.currentTarget, e.pageX, e.pageY, e);
6134
- }
6135
- }, this))
6136
- .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
6137
- if(this._data.contextmenu.visible && (!last_ts || (+new Date()) - last_ts > 250)) { // work around safari & macOS ctrl+click
6138
- $.vakata.context.hide();
6139
- }
6140
- last_ts = 0;
6141
- }, this))
6142
- .on("touchstart.jstree", ".jstree-anchor", function (e) {
6143
- if(!e.originalEvent || !e.originalEvent.changedTouches || !e.originalEvent.changedTouches[0]) {
6144
- return;
6145
- }
6146
- ex = e.originalEvent.changedTouches[0].clientX;
6147
- ey = e.originalEvent.changedTouches[0].clientY;
6148
- cto = setTimeout(function () {
6149
- $(e.currentTarget).trigger('contextmenu', true);
6150
- }, 750);
6151
- })
6152
- .on('touchmove.vakata.jstree', function (e) {
6153
- if(cto && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0] && (Math.abs(ex - e.originalEvent.changedTouches[0].clientX) > 10 || Math.abs(ey - e.originalEvent.changedTouches[0].clientY) > 10)) {
6154
- clearTimeout(cto);
6155
- $.vakata.context.hide();
6156
- }
6157
- })
6158
- .on('touchend.vakata.jstree', function (e) {
6159
- if(cto) {
6160
- clearTimeout(cto);
6161
- }
6162
- });
6163
-
6164
- /*!
6165
- if(!('oncontextmenu' in document.body) && ('ontouchstart' in document.body)) {
6166
- var el = null, tm = null;
6167
- this.element
6168
- .on("touchstart", ".jstree-anchor", function (e) {
6169
- el = e.currentTarget;
6170
- tm = +new Date();
6171
- $(document).one("touchend", function (e) {
6172
- e.target = document.elementFromPoint(e.originalEvent.targetTouches[0].pageX - window.pageXOffset, e.originalEvent.targetTouches[0].pageY - window.pageYOffset);
6173
- e.currentTarget = e.target;
6174
- tm = ((+(new Date())) - tm);
6175
- if(e.target === el && tm > 600 && tm < 1000) {
6176
- e.preventDefault();
6177
- $(el).trigger('contextmenu', e);
6178
- }
6179
- el = null;
6180
- tm = null;
6181
- });
6182
- });
6183
- }
6184
- */
6185
- $(document).on("context_hide.vakata.jstree", $.proxy(function (e, data) {
6186
- this._data.contextmenu.visible = false;
6187
- $(data.reference).removeClass('jstree-context');
6188
- }, this));
6189
- };
6190
- this.teardown = function () {
6191
- if(this._data.contextmenu.visible) {
6192
- $.vakata.context.hide();
6193
- }
6194
- parent.teardown.call(this);
6195
- };
6196
-
6197
- /**
6198
- * prepare and show the context menu for a node
6199
- * @name show_contextmenu(obj [, x, y])
6200
- * @param {mixed} obj the node
6201
- * @param {Number} x the x-coordinate relative to the document to show the menu at
6202
- * @param {Number} y the y-coordinate relative to the document to show the menu at
6203
- * @param {Object} e the event if available that triggered the contextmenu
6204
- * @plugin contextmenu
6205
- * @trigger show_contextmenu.jstree
6206
- */
6207
- this.show_contextmenu = function (obj, x, y, e) {
6208
- obj = this.get_node(obj);
6209
- if(!obj || obj.id === $.jstree.root) { return false; }
6210
- var s = this.settings.contextmenu,
6211
- d = this.get_node(obj, true),
6212
- a = d.children(".jstree-anchor"),
6213
- o = false,
6214
- i = false;
6215
- if(s.show_at_node || x === undefined || y === undefined) {
6216
- o = a.offset();
6217
- x = o.left;
6218
- y = o.top + this._data.core.li_height;
6219
- }
6220
- if(this.settings.contextmenu.select_node && !this.is_selected(obj)) {
6221
- this.activate_node(obj, e);
6222
- }
6223
-
6224
- i = s.items;
6225
- if($.isFunction(i)) {
6226
- i = i.call(this, obj, $.proxy(function (i) {
6227
- this._show_contextmenu(obj, x, y, i);
6228
- }, this));
6229
- }
6230
- if($.isPlainObject(i)) {
6231
- this._show_contextmenu(obj, x, y, i);
6232
- }
6233
- };
6234
- /**
6235
- * show the prepared context menu for a node
6236
- * @name _show_contextmenu(obj, x, y, i)
6237
- * @param {mixed} obj the node
6238
- * @param {Number} x the x-coordinate relative to the document to show the menu at
6239
- * @param {Number} y the y-coordinate relative to the document to show the menu at
6240
- * @param {Number} i the object of items to show
6241
- * @plugin contextmenu
6242
- * @trigger show_contextmenu.jstree
6243
- * @private
6244
- */
6245
- this._show_contextmenu = function (obj, x, y, i) {
6246
- var d = this.get_node(obj, true),
6247
- a = d.children(".jstree-anchor");
6248
- $(document).one("context_show.vakata.jstree", $.proxy(function (e, data) {
6249
- var cls = 'jstree-contextmenu jstree-' + this.get_theme() + '-contextmenu';
6250
- $(data.element).addClass(cls);
6251
- a.addClass('jstree-context');
6252
- }, this));
6253
- this._data.contextmenu.visible = true;
6254
- $.vakata.context.show(a, { 'x' : x, 'y' : y }, i);
6255
- /**
6256
- * triggered when the contextmenu is shown for a node
6257
- * @event
6258
- * @name show_contextmenu.jstree
6259
- * @param {Object} node the node
6260
- * @param {Number} x the x-coordinate of the menu relative to the document
6261
- * @param {Number} y the y-coordinate of the menu relative to the document
6262
- * @plugin contextmenu
6263
- */
6264
- this.trigger('show_contextmenu', { "node" : obj, "x" : x, "y" : y });
6265
- };
6266
- };
6267
-
6268
- // contextmenu helper
6269
- (function ($) {
6270
- var right_to_left = false,
6271
- vakata_context = {
6272
- element : false,
6273
- reference : false,
6274
- position_x : 0,
6275
- position_y : 0,
6276
- items : [],
6277
- html : "",
6278
- is_visible : false
6279
- };
6280
-
6281
- $.vakata.context = {
6282
- settings : {
6283
- hide_onmouseleave : 0,
6284
- icons : true
6285
- },
6286
- _trigger : function (event_name) {
6287
- $(document).triggerHandler("context_" + event_name + ".vakata", {
6288
- "reference" : vakata_context.reference,
6289
- "element" : vakata_context.element,
6290
- "position" : {
6291
- "x" : vakata_context.position_x,
6292
- "y" : vakata_context.position_y
6293
- }
6294
- });
6295
- },
6296
- _execute : function (i) {
6297
- i = vakata_context.items[i];
6298
- return i && (!i._disabled || ($.isFunction(i._disabled) && !i._disabled({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }))) && i.action ? i.action.call(null, {
6299
- "item" : i,
6300
- "reference" : vakata_context.reference,
6301
- "element" : vakata_context.element,
6302
- "position" : {
6303
- "x" : vakata_context.position_x,
6304
- "y" : vakata_context.position_y
6305
- }
6306
- }) : false;
6307
- },
6308
- _parse : function (o, is_callback) {
6309
- if(!o) { return false; }
6310
- if(!is_callback) {
6311
- vakata_context.html = "";
6312
- vakata_context.items = [];
6313
- }
6314
- var str = "",
6315
- sep = false,
6316
- tmp;
6317
-
6318
- if(is_callback) { str += "<"+"ul>"; }
6319
- $.each(o, function (i, val) {
6320
- if(!val) { return true; }
6321
- vakata_context.items.push(val);
6322
- if(!sep && val.separator_before) {
6323
- str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
6324
- }
6325
- sep = false;
6326
- str += "<"+"li class='" + (val._class || "") + (val._disabled === true || ($.isFunction(val._disabled) && val._disabled({ "item" : val, "reference" : vakata_context.reference, "element" : vakata_context.element })) ? " vakata-contextmenu-disabled " : "") + "' "+(val.shortcut?" data-shortcut='"+val.shortcut+"' ":'')+">";
6327
- str += "<"+"a href='#' rel='" + (vakata_context.items.length - 1) + "' " + (val.title ? "title='" + val.title + "'" : "") + ">";
6328
- if($.vakata.context.settings.icons) {
6329
- str += "<"+"i ";
6330
- if(val.icon) {
6331
- if(val.icon.indexOf("/") !== -1 || val.icon.indexOf(".") !== -1) { str += " style='background:url(\"" + val.icon + "\") center center no-repeat' "; }
6332
- else { str += " class='" + val.icon + "' "; }
6333
- }
6334
- str += "><"+"/i><"+"span class='vakata-contextmenu-sep'>&#160;<"+"/span>";
6335
- }
6336
- str += ($.isFunction(val.label) ? val.label({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }) : val.label) + (val.shortcut?' <span class="vakata-contextmenu-shortcut vakata-contextmenu-shortcut-'+val.shortcut+'">'+ (val.shortcut_label || '') +'</span>':'') + "<"+"/a>";
6337
- if(val.submenu) {
6338
- tmp = $.vakata.context._parse(val.submenu, true);
6339
- if(tmp) { str += tmp; }
6340
- }
6341
- str += "<"+"/li>";
6342
- if(val.separator_after) {
6343
- str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
6344
- sep = true;
6345
- }
6346
- });
6347
- str = str.replace(/<li class\='vakata-context-separator'\><\/li\>$/,"");
6348
- if(is_callback) { str += "</ul>"; }
6349
- /**
6350
- * triggered on the document when the contextmenu is parsed (HTML is built)
6351
- * @event
6352
- * @plugin contextmenu
6353
- * @name context_parse.vakata
6354
- * @param {jQuery} reference the element that was right clicked
6355
- * @param {jQuery} element the DOM element of the menu itself
6356
- * @param {Object} position the x & y coordinates of the menu
6357
- */
6358
- if(!is_callback) { vakata_context.html = str; $.vakata.context._trigger("parse"); }
6359
- return str.length > 10 ? str : false;
6360
- },
6361
- _show_submenu : function (o) {
6362
- o = $(o);
6363
- if(!o.length || !o.children("ul").length) { return; }
6364
- var e = o.children("ul"),
6365
- xl = o.offset().left,
6366
- x = xl + o.outerWidth(),
6367
- y = o.offset().top,
6368
- w = e.width(),
6369
- h = e.height(),
6370
- dw = $(window).width() + $(window).scrollLeft(),
6371
- dh = $(window).height() + $(window).scrollTop();
6372
- // може да се спести е една проверка - дали няма някой от класовете вече нагоре
6373
- if(right_to_left) {
6374
- o[x - (w + 10 + o.outerWidth()) < 0 ? "addClass" : "removeClass"]("vakata-context-left");
6375
- }
6376
- else {
6377
- o[x + w > dw && xl > dw - x ? "addClass" : "removeClass"]("vakata-context-right");
6378
- }
6379
- if(y + h + 10 > dh) {
6380
- e.css("bottom","-1px");
6381
- }
6382
-
6383
- //if does not fit - stick it to the side
6384
- if (o.hasClass('vakata-context-right')) {
6385
- if (xl < w) {
6386
- e.css("margin-right", xl - w);
6387
- }
6388
- } else {
6389
- if (dw - x < w) {
6390
- e.css("margin-left", dw - x - w);
6391
- }
6392
- }
6393
-
6394
- e.show();
6395
- },
6396
- show : function (reference, position, data) {
6397
- var o, e, x, y, w, h, dw, dh, cond = true;
6398
- if(vakata_context.element && vakata_context.element.length) {
6399
- vakata_context.element.width('');
6400
- }
6401
- switch(cond) {
6402
- case (!position && !reference):
6403
- return false;
6404
- case (!!position && !!reference):
6405
- vakata_context.reference = reference;
6406
- vakata_context.position_x = position.x;
6407
- vakata_context.position_y = position.y;
6408
- break;
6409
- case (!position && !!reference):
6410
- vakata_context.reference = reference;
6411
- o = reference.offset();
6412
- vakata_context.position_x = o.left + reference.outerHeight();
6413
- vakata_context.position_y = o.top;
6414
- break;
6415
- case (!!position && !reference):
6416
- vakata_context.position_x = position.x;
6417
- vakata_context.position_y = position.y;
6418
- break;
6419
- }
6420
- if(!!reference && !data && $(reference).data('vakata_contextmenu')) {
6421
- data = $(reference).data('vakata_contextmenu');
6422
- }
6423
- if($.vakata.context._parse(data)) {
6424
- vakata_context.element.html(vakata_context.html);
6425
- }
6426
- if(vakata_context.items.length) {
6427
- vakata_context.element.appendTo("body");
6428
- e = vakata_context.element;
6429
- x = vakata_context.position_x;
6430
- y = vakata_context.position_y;
6431
- w = e.width();
6432
- h = e.height();
6433
- dw = $(window).width() + $(window).scrollLeft();
6434
- dh = $(window).height() + $(window).scrollTop();
6435
- if(right_to_left) {
6436
- x -= (e.outerWidth() - $(reference).outerWidth());
6437
- if(x < $(window).scrollLeft() + 20) {
6438
- x = $(window).scrollLeft() + 20;
6439
- }
6440
- }
6441
- if(x + w + 20 > dw) {
6442
- x = dw - (w + 20);
6443
- }
6444
- if(y + h + 20 > dh) {
6445
- y = dh - (h + 20);
6446
- }
6447
-
6448
- vakata_context.element
6449
- .css({ "left" : x, "top" : y })
6450
- .show()
6451
- .find('a').first().focus().parent().addClass("vakata-context-hover");
6452
- vakata_context.is_visible = true;
6453
- /**
6454
- * triggered on the document when the contextmenu is shown
6455
- * @event
6456
- * @plugin contextmenu
6457
- * @name context_show.vakata
6458
- * @param {jQuery} reference the element that was right clicked
6459
- * @param {jQuery} element the DOM element of the menu itself
6460
- * @param {Object} position the x & y coordinates of the menu
6461
- */
6462
- $.vakata.context._trigger("show");
6463
- }
6464
- },
6465
- hide : function () {
6466
- if(vakata_context.is_visible) {
6467
- vakata_context.element.hide().find("ul").hide().end().find(':focus').blur().end().detach();
6468
- vakata_context.is_visible = false;
6469
- /**
6470
- * triggered on the document when the contextmenu is hidden
6471
- * @event
6472
- * @plugin contextmenu
6473
- * @name context_hide.vakata
6474
- * @param {jQuery} reference the element that was right clicked
6475
- * @param {jQuery} element the DOM element of the menu itself
6476
- * @param {Object} position the x & y coordinates of the menu
6477
- */
6478
- $.vakata.context._trigger("hide");
6479
- }
6480
- }
6481
- };
6482
- $(function () {
6483
- right_to_left = $("body").css("direction") === "rtl";
6484
- var to = false;
6485
-
6486
- vakata_context.element = $("<ul class='vakata-context'></ul>");
6487
- vakata_context.element
6488
- .on("mouseenter", "li", function (e) {
6489
- e.stopImmediatePropagation();
6490
-
6491
- if($.contains(this, e.relatedTarget)) {
6492
- // премахнато заради delegate mouseleave по-долу
6493
- // $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
6494
- return;
6495
- }
6496
-
6497
- if(to) { clearTimeout(to); }
6498
- vakata_context.element.find(".vakata-context-hover").removeClass("vakata-context-hover").end();
6499
-
6500
- $(this)
6501
- .siblings().find("ul").hide().end().end()
6502
- .parentsUntil(".vakata-context", "li").addBack().addClass("vakata-context-hover");
6503
- $.vakata.context._show_submenu(this);
6504
- })
6505
- // тестово - дали не натоварва?
6506
- .on("mouseleave", "li", function (e) {
6507
- if($.contains(this, e.relatedTarget)) { return; }
6508
- $(this).find(".vakata-context-hover").addBack().removeClass("vakata-context-hover");
6509
- })
6510
- .on("mouseleave", function (e) {
6511
- $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
6512
- if($.vakata.context.settings.hide_onmouseleave) {
6513
- to = setTimeout(
6514
- (function (t) {
6515
- return function () { $.vakata.context.hide(); };
6516
- }(this)), $.vakata.context.settings.hide_onmouseleave);
6517
- }
6518
- })
6519
- .on("click", "a", function (e) {
6520
- e.preventDefault();
6521
- //})
6522
- //.on("mouseup", "a", function (e) {
6523
- if(!$(this).blur().parent().hasClass("vakata-context-disabled") && $.vakata.context._execute($(this).attr("rel")) !== false) {
6524
- $.vakata.context.hide();
6525
- }
6526
- })
6527
- .on('keydown', 'a', function (e) {
6528
- var o = null;
6529
- switch(e.which) {
6530
- case 13:
6531
- case 32:
6532
- e.type = "click";
6533
- e.preventDefault();
6534
- $(e.currentTarget).trigger(e);
6535
- break;
6536
- case 37:
6537
- if(vakata_context.is_visible) {
6538
- vakata_context.element.find(".vakata-context-hover").last().closest("li").first().find("ul").hide().find(".vakata-context-hover").removeClass("vakata-context-hover").end().end().children('a').focus();
6539
- e.stopImmediatePropagation();
6540
- e.preventDefault();
6541
- }
6542
- break;
6543
- case 38:
6544
- if(vakata_context.is_visible) {
6545
- o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first();
6546
- if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last(); }
6547
- o.addClass("vakata-context-hover").children('a').focus();
6548
- e.stopImmediatePropagation();
6549
- e.preventDefault();
6550
- }
6551
- break;
6552
- case 39:
6553
- if(vakata_context.is_visible) {
6554
- vakata_context.element.find(".vakata-context-hover").last().children("ul").show().children("li:not(.vakata-context-separator)").removeClass("vakata-context-hover").first().addClass("vakata-context-hover").children('a').focus();
6555
- e.stopImmediatePropagation();
6556
- e.preventDefault();
6557
- }
6558
- break;
6559
- case 40:
6560
- if(vakata_context.is_visible) {
6561
- o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").nextAll("li:not(.vakata-context-separator)").first();
6562
- if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").first(); }
6563
- o.addClass("vakata-context-hover").children('a').focus();
6564
- e.stopImmediatePropagation();
6565
- e.preventDefault();
6566
- }
6567
- break;
6568
- case 27:
6569
- $.vakata.context.hide();
6570
- e.preventDefault();
6571
- break;
6572
- default:
6573
- //console.log(e.which);
6574
- break;
6575
- }
6576
- })
6577
- .on('keydown', function (e) {
6578
- e.preventDefault();
6579
- var a = vakata_context.element.find('.vakata-contextmenu-shortcut-' + e.which).parent();
6580
- if(a.parent().not('.vakata-context-disabled')) {
6581
- a.click();
6582
- }
6583
- });
6584
-
6585
- $(document)
6586
- .on("mousedown.vakata.jstree", function (e) {
6587
- if(vakata_context.is_visible && vakata_context.element[0] !== e.target && !$.contains(vakata_context.element[0], e.target)) {
6588
- $.vakata.context.hide();
6589
- }
6590
- })
6591
- .on("context_show.vakata.jstree", function (e, data) {
6592
- vakata_context.element.find("li:has(ul)").children("a").addClass("vakata-context-parent");
6593
- if(right_to_left) {
6594
- vakata_context.element.addClass("vakata-context-rtl").css("direction", "rtl");
6595
- }
6596
- // also apply a RTL class?
6597
- vakata_context.element.find("ul").hide().end();
6598
- });
6599
- });
6600
- }($));
6601
- // $.jstree.defaults.plugins.push("contextmenu");
6602
-
6603
-
6604
- /**
6605
- * ### Drag'n'drop plugin
6606
- *
6607
- * Enables dragging and dropping of nodes in the tree, resulting in a move or copy operations.
6608
- */
6609
-
6610
- /**
6611
- * stores all defaults for the drag'n'drop plugin
6612
- * @name $.jstree.defaults.dnd
6613
- * @plugin dnd
6614
- */
6615
- $.jstree.defaults.dnd = {
6616
- /**
6617
- * a boolean indicating if a copy should be possible while dragging (by pressint the meta key or Ctrl). Defaults to `true`.
6618
- * @name $.jstree.defaults.dnd.copy
6619
- * @plugin dnd
6620
- */
6621
- copy : true,
6622
- /**
6623
- * a number indicating how long a node should remain hovered while dragging to be opened. Defaults to `500`.
6624
- * @name $.jstree.defaults.dnd.open_timeout
6625
- * @plugin dnd
6626
- */
6627
- open_timeout : 500,
6628
- /**
6629
- * a function invoked each time a node is about to be dragged, invoked in the tree's scope and receives the nodes about to be dragged as an argument (array) and the event that started the drag - return `false` to prevent dragging
6630
- * @name $.jstree.defaults.dnd.is_draggable
6631
- * @plugin dnd
6632
- */
6633
- is_draggable : true,
6634
- /**
6635
- * a boolean indicating if checks should constantly be made while the user is dragging the node (as opposed to checking only on drop), default is `true`
6636
- * @name $.jstree.defaults.dnd.check_while_dragging
6637
- * @plugin dnd
6638
- */
6639
- check_while_dragging : true,
6640
- /**
6641
- * a boolean indicating if nodes from this tree should only be copied with dnd (as opposed to moved), default is `false`
6642
- * @name $.jstree.defaults.dnd.always_copy
6643
- * @plugin dnd
6644
- */
6645
- always_copy : false,
6646
- /**
6647
- * when dropping a node "inside", this setting indicates the position the node should go to - it can be an integer or a string: "first" (same as 0) or "last", default is `0`
6648
- * @name $.jstree.defaults.dnd.inside_pos
6649
- * @plugin dnd
6650
- */
6651
- inside_pos : 0,
6652
- /**
6653
- * when starting the drag on a node that is selected this setting controls if all selected nodes are dragged or only the single node, default is `true`, which means all selected nodes are dragged when the drag is started on a selected node
6654
- * @name $.jstree.defaults.dnd.drag_selection
6655
- * @plugin dnd
6656
- */
6657
- drag_selection : true,
6658
- /**
6659
- * controls whether dnd works on touch devices. If left as boolean true dnd will work the same as in desktop browsers, which in some cases may impair scrolling. If set to boolean false dnd will not work on touch devices. There is a special third option - string "selected" which means only selected nodes can be dragged on touch devices.
6660
- * @name $.jstree.defaults.dnd.touch
6661
- * @plugin dnd
6662
- */
6663
- touch : true,
6664
- /**
6665
- * controls whether items can be dropped anywhere on the node, not just on the anchor, by default only the node anchor is a valid drop target. Works best with the wholerow plugin. If enabled on mobile depending on the interface it might be hard for the user to cancel the drop, since the whole tree container will be a valid drop target.
6666
- * @name $.jstree.defaults.dnd.large_drop_target
6667
- * @plugin dnd
6668
- */
6669
- large_drop_target : false,
6670
- /**
6671
- * controls whether a drag can be initiated from any part of the node and not just the text/icon part, works best with the wholerow plugin. Keep in mind it can cause problems with tree scrolling on mobile depending on the interface - in that case set the touch option to "selected".
6672
- * @name $.jstree.defaults.dnd.large_drag_target
6673
- * @plugin dnd
6674
- */
6675
- large_drag_target : false,
6676
- /**
6677
- * controls whether use HTML5 dnd api instead of classical. That will allow better integration of dnd events with other HTML5 controls.
6678
- * @reference http://caniuse.com/#feat=dragndrop
6679
- * @name $.jstree.defaults.dnd.use_html5
6680
- * @plugin dnd
6681
- */
6682
- use_html5: false
6683
- };
6684
- var drg, elm;
6685
- // TODO: now check works by checking for each node individually, how about max_children, unique, etc?
6686
- $.jstree.plugins.dnd = function (options, parent) {
6687
- this.init = function (el, options) {
6688
- parent.init.call(this, el, options);
6689
- this.settings.dnd.use_html5 = this.settings.dnd.use_html5 && ('draggable' in document.createElement('span'));
6690
- };
6691
- this.bind = function () {
6692
- parent.bind.call(this);
6693
-
6694
- this.element
6695
- .on(this.settings.dnd.use_html5 ? 'dragstart.jstree' : 'mousedown.jstree touchstart.jstree', this.settings.dnd.large_drag_target ? '.jstree-node' : '.jstree-anchor', $.proxy(function (e) {
6696
- if(this.settings.dnd.large_drag_target && $(e.target).closest('.jstree-node')[0] !== e.currentTarget) {
6697
- return true;
6698
- }
6699
- if(e.type === "touchstart" && (!this.settings.dnd.touch || (this.settings.dnd.touch === 'selected' && !$(e.currentTarget).closest('.jstree-node').children('.jstree-anchor').hasClass('jstree-clicked')))) {
6700
- return true;
6701
- }
6702
- var obj = this.get_node(e.target),
6703
- mlt = this.is_selected(obj) && this.settings.dnd.drag_selection ? this.get_top_selected().length : 1,
6704
- txt = (mlt > 1 ? mlt + ' ' + this.get_string('nodes') : this.get_text(e.currentTarget));
6705
- if(this.settings.core.force_text) {
6706
- txt = $.vakata.html.escape(txt);
6707
- }
6708
- if(obj && obj.id && obj.id !== $.jstree.root && (e.which === 1 || e.type === "touchstart" || e.type === "dragstart") &&
6709
- (this.settings.dnd.is_draggable === true || ($.isFunction(this.settings.dnd.is_draggable) && this.settings.dnd.is_draggable.call(this, (mlt > 1 ? this.get_top_selected(true) : [obj]), e)))
6710
- ) {
6711
- drg = { 'jstree' : true, 'origin' : this, 'obj' : this.get_node(obj,true), 'nodes' : mlt > 1 ? this.get_top_selected() : [obj.id] };
6712
- elm = e.currentTarget;
6713
- if (this.settings.dnd.use_html5) {
6714
- $.vakata.dnd._trigger('start', e, { 'helper': $(), 'element': elm, 'data': drg });
6715
- } else {
6716
- this.element.trigger('mousedown.jstree');
6717
- return $.vakata.dnd.start(e, drg, '<div id="jstree-dnd" class="jstree-' + this.get_theme() + ' jstree-' + this.get_theme() + '-' + this.get_theme_variant() + ' ' + ( this.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ) + '"><i class="jstree-icon jstree-er"></i>' + txt + '<ins class="jstree-copy" style="display:none;">+</ins></div>');
6718
- }
6719
- }
6720
- }, this));
6721
- if (this.settings.dnd.use_html5) {
6722
- this.element
6723
- .on('dragover.jstree', function (e) {
6724
- e.preventDefault();
6725
- $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
6726
- return false;
6727
- })
6728
- //.on('dragenter.jstree', this.settings.dnd.large_drop_target ? '.jstree-node' : '.jstree-anchor', $.proxy(function (e) {
6729
- // e.preventDefault();
6730
- // $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
6731
- // return false;
6732
- // }, this))
6733
- .on('drop.jstree', $.proxy(function (e) {
6734
- e.preventDefault();
6735
- $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
6736
- return false;
6737
- }, this));
6738
- }
6739
- };
6740
- this.redraw_node = function(obj, deep, callback, force_render) {
6741
- obj = parent.redraw_node.apply(this, arguments);
6742
- if (obj && this.settings.dnd.use_html5) {
6743
- if (this.settings.dnd.large_drag_target) {
6744
- obj.setAttribute('draggable', true);
6745
- } else {
6746
- var i, j, tmp = null;
6747
- for(i = 0, j = obj.childNodes.length; i < j; i++) {
6748
- if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
6749
- tmp = obj.childNodes[i];
6750
- break;
6751
- }
6752
- }
6753
- if(tmp) {
6754
- tmp.setAttribute('draggable', true);
6755
- }
6756
- }
6757
- }
6758
- return obj;
6759
- };
6760
- };
6761
-
6762
- $(function() {
6763
- // bind only once for all instances
6764
- var lastmv = false,
6765
- laster = false,
6766
- lastev = false,
6767
- opento = false,
6768
- marker = $('<div id="jstree-marker">&#160;</div>').hide(); //.appendTo('body');
6769
-
6770
- $(document)
6771
- .on('dnd_start.vakata.jstree', function (e, data) {
6772
- lastmv = false;
6773
- lastev = false;
6774
- if(!data || !data.data || !data.data.jstree) { return; }
6775
- marker.appendTo('body'); //.show();
6776
- })
6777
- .on('dnd_move.vakata.jstree', function (e, data) {
6778
- var isDifferentNode = data.event.target !== lastev.target;
6779
- if(opento) {
6780
- if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
6781
- clearTimeout(opento);
6782
- }
6783
- }
6784
- if(!data || !data.data || !data.data.jstree) { return; }
6785
-
6786
- // if we are hovering the marker image do nothing (can happen on "inside" drags)
6787
- if(data.event.target.id && data.event.target.id === 'jstree-marker') {
6788
- return;
6789
- }
6790
- lastev = data.event;
6791
-
6792
- var ins = $.jstree.reference(data.event.target),
6793
- ref = false,
6794
- off = false,
6795
- rel = false,
6796
- tmp, l, t, h, p, i, o, ok, t1, t2, op, ps, pr, ip, tm, is_copy, pn;
6797
- // if we are over an instance
6798
- if(ins && ins._data && ins._data.dnd) {
6799
- marker.attr('class', 'jstree-' + ins.get_theme() + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ));
6800
- is_copy = data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)));
6801
- data.helper
6802
- .children().attr('class', 'jstree-' + ins.get_theme() + ' jstree-' + ins.get_theme() + '-' + ins.get_theme_variant() + ' ' + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ))
6803
- .find('.jstree-copy').first()[ is_copy ? 'show' : 'hide' ]();
6804
-
6805
- // if are hovering the container itself add a new root node
6806
- //console.log(data.event);
6807
- if( (data.event.target === ins.element[0] || data.event.target === ins.get_container_ul()[0]) && ins.get_container_ul().children().length === 0) {
6808
- ok = true;
6809
- for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
6810
- ok = ok && ins.check( (data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)) ) ? "copy_node" : "move_node"), (data.data.origin && data.data.origin !== ins ? data.data.origin.get_node(data.data.nodes[t1]) : data.data.nodes[t1]), $.jstree.root, 'last', { 'dnd' : true, 'ref' : ins.get_node($.jstree.root), 'pos' : 'i', 'origin' : data.data.origin, 'is_multi' : (data.data.origin && data.data.origin !== ins), 'is_foreign' : (!data.data.origin) });
6811
- if(!ok) { break; }
6812
- }
6813
- if(ok) {
6814
- lastmv = { 'ins' : ins, 'par' : $.jstree.root, 'pos' : 'last' };
6815
- marker.hide();
6816
- data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
6817
- if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
6818
- data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
6819
- }
6820
- return;
6821
- }
6822
- }
6823
- else {
6824
- // if we are hovering a tree node
6825
- ref = ins.settings.dnd.large_drop_target ? $(data.event.target).closest('.jstree-node').children('.jstree-anchor') : $(data.event.target).closest('.jstree-anchor');
6826
- if(ref && ref.length && ref.parent().is('.jstree-closed, .jstree-open, .jstree-leaf')) {
6827
- off = ref.offset();
6828
- rel = (data.event.pageY !== undefined ? data.event.pageY : data.event.originalEvent.pageY) - off.top;
6829
- h = ref.outerHeight();
6830
- if(rel < h / 3) {
6831
- o = ['b', 'i', 'a'];
6832
- }
6833
- else if(rel > h - h / 3) {
6834
- o = ['a', 'i', 'b'];
6835
- }
6836
- else {
6837
- o = rel > h / 2 ? ['i', 'a', 'b'] : ['i', 'b', 'a'];
6838
- }
6839
- $.each(o, function (j, v) {
6840
- switch(v) {
6841
- case 'b':
6842
- l = off.left - 6;
6843
- t = off.top;
6844
- p = ins.get_parent(ref);
6845
- i = ref.parent().index();
6846
- break;
6847
- case 'i':
6848
- ip = ins.settings.dnd.inside_pos;
6849
- tm = ins.get_node(ref.parent());
6850
- l = off.left - 2;
6851
- t = off.top + h / 2 + 1;
6852
- p = tm.id;
6853
- i = ip === 'first' ? 0 : (ip === 'last' ? tm.children.length : Math.min(ip, tm.children.length));
6854
- break;
6855
- case 'a':
6856
- l = off.left - 6;
6857
- t = off.top + h;
6858
- p = ins.get_parent(ref);
6859
- i = ref.parent().index() + 1;
6860
- break;
6861
- }
6862
- ok = true;
6863
- for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
6864
- op = data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey))) ? "copy_node" : "move_node";
6865
- ps = i;
6866
- if(op === "move_node" && v === 'a' && (data.data.origin && data.data.origin === ins) && p === ins.get_parent(data.data.nodes[t1])) {
6867
- pr = ins.get_node(p);
6868
- if(ps > $.inArray(data.data.nodes[t1], pr.children)) {
6869
- ps -= 1;
6870
- }
6871
- }
6872
- ok = ok && ( (ins && ins.settings && ins.settings.dnd && ins.settings.dnd.check_while_dragging === false) || ins.check(op, (data.data.origin && data.data.origin !== ins ? data.data.origin.get_node(data.data.nodes[t1]) : data.data.nodes[t1]), p, ps, { 'dnd' : true, 'ref' : ins.get_node(ref.parent()), 'pos' : v, 'origin' : data.data.origin, 'is_multi' : (data.data.origin && data.data.origin !== ins), 'is_foreign' : (!data.data.origin) }) );
6873
- if(!ok) {
6874
- if(ins && ins.last_error) { laster = ins.last_error(); }
6875
- break;
6876
- }
6877
- }
6878
- if(v === 'i' && ref.parent().is('.jstree-closed') && ins.settings.dnd.open_timeout) {
6879
- if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
6880
- if (opento) { clearTimeout(opento); }
6881
- opento = setTimeout((function (x, z) { return function () { x.open_node(z); }; }(ins, ref)), ins.settings.dnd.open_timeout);
6882
- }
6883
- }
6884
- if(ok) {
6885
- pn = ins.get_node(p, true);
6886
- if (!pn.hasClass('.jstree-dnd-parent')) {
6887
- $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
6888
- pn.addClass('jstree-dnd-parent');
6889
- }
6890
- lastmv = { 'ins' : ins, 'par' : p, 'pos' : v === 'i' && ip === 'last' && i === 0 && !ins.is_loaded(tm) ? 'last' : i };
6891
- marker.css({ 'left' : l + 'px', 'top' : t + 'px' }).show();
6892
- data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
6893
- if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
6894
- data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
6895
- }
6896
- laster = {};
6897
- o = true;
6898
- return false;
6899
- }
6900
- });
6901
- if(o === true) { return; }
6902
- }
6903
- }
6904
- }
6905
- $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
6906
- lastmv = false;
6907
- data.helper.find('.jstree-icon').removeClass('jstree-ok').addClass('jstree-er');
6908
- if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
6909
- data.event.originalEvent.dataTransfer.dropEffect = 'none';
6910
- }
6911
- marker.hide();
6912
- })
6913
- .on('dnd_scroll.vakata.jstree', function (e, data) {
6914
- if(!data || !data.data || !data.data.jstree) { return; }
6915
- marker.hide();
6916
- lastmv = false;
6917
- lastev = false;
6918
- data.helper.find('.jstree-icon').first().removeClass('jstree-ok').addClass('jstree-er');
6919
- })
6920
- .on('dnd_stop.vakata.jstree', function (e, data) {
6921
- $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
6922
- if(opento) { clearTimeout(opento); }
6923
- if(!data || !data.data || !data.data.jstree) { return; }
6924
- marker.hide().detach();
6925
- var i, j, nodes = [];
6926
- if(lastmv) {
6927
- for(i = 0, j = data.data.nodes.length; i < j; i++) {
6928
- nodes[i] = data.data.origin ? data.data.origin.get_node(data.data.nodes[i]) : data.data.nodes[i];
6929
- }
6930
- lastmv.ins[ data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey))) ? 'copy_node' : 'move_node' ](nodes, lastmv.par, lastmv.pos, false, false, false, data.data.origin);
6931
- }
6932
- else {
6933
- i = $(data.event.target).closest('.jstree');
6934
- if(i.length && laster && laster.error && laster.error === 'check') {
6935
- i = i.jstree(true);
6936
- if(i) {
6937
- i.settings.core.error.call(this, laster);
6938
- }
6939
- }
6940
- }
6941
- lastev = false;
6942
- lastmv = false;
6943
- })
6944
- .on('keyup.jstree keydown.jstree', function (e, data) {
6945
- data = $.vakata.dnd._get();
6946
- if(data && data.data && data.data.jstree) {
6947
- if (e.type === "keyup" && e.which === 27) {
6948
- if (opento) { clearTimeout(opento); }
6949
- lastmv = false;
6950
- laster = false;
6951
- lastev = false;
6952
- opento = false;
6953
- marker.hide().detach();
6954
- $.vakata.dnd._clean();
6955
- } else {
6956
- data.helper.find('.jstree-copy').first()[ data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (e.metaKey || e.ctrlKey))) ? 'show' : 'hide' ]();
6957
- if(lastev) {
6958
- lastev.metaKey = e.metaKey;
6959
- lastev.ctrlKey = e.ctrlKey;
6960
- $.vakata.dnd._trigger('move', lastev);
6961
- }
6962
- }
6963
- }
6964
- });
6965
- });
6966
-
6967
- // helpers
6968
- (function ($) {
6969
- $.vakata.html = {
6970
- div : $('<div />'),
6971
- escape : function (str) {
6972
- return $.vakata.html.div.text(str).html();
6973
- },
6974
- strip : function (str) {
6975
- return $.vakata.html.div.empty().append($.parseHTML(str)).text();
6976
- }
6977
- };
6978
- // private variable
6979
- var vakata_dnd = {
6980
- element : false,
6981
- target : false,
6982
- is_down : false,
6983
- is_drag : false,
6984
- helper : false,
6985
- helper_w: 0,
6986
- data : false,
6987
- init_x : 0,
6988
- init_y : 0,
6989
- scroll_l: 0,
6990
- scroll_t: 0,
6991
- scroll_e: false,
6992
- scroll_i: false,
6993
- is_touch: false
6994
- };
6995
- $.vakata.dnd = {
6996
- settings : {
6997
- scroll_speed : 10,
6998
- scroll_proximity : 20,
6999
- helper_left : 5,
7000
- helper_top : 10,
7001
- threshold : 5,
7002
- threshold_touch : 10
7003
- },
7004
- _trigger : function (event_name, e, data) {
7005
- if (data === undefined) {
7006
- data = $.vakata.dnd._get();
7007
- }
7008
- data.event = e;
7009
- $(document).triggerHandler("dnd_" + event_name + ".vakata", data);
7010
- },
7011
- _get : function () {
7012
- return {
7013
- "data" : vakata_dnd.data,
7014
- "element" : vakata_dnd.element,
7015
- "helper" : vakata_dnd.helper
7016
- };
7017
- },
7018
- _clean : function () {
7019
- if(vakata_dnd.helper) { vakata_dnd.helper.remove(); }
7020
- if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
7021
- vakata_dnd = {
7022
- element : false,
7023
- target : false,
7024
- is_down : false,
7025
- is_drag : false,
7026
- helper : false,
7027
- helper_w: 0,
7028
- data : false,
7029
- init_x : 0,
7030
- init_y : 0,
7031
- scroll_l: 0,
7032
- scroll_t: 0,
7033
- scroll_e: false,
7034
- scroll_i: false,
7035
- is_touch: false
7036
- };
7037
- $(document).off("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
7038
- $(document).off("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
7039
- },
7040
- _scroll : function (init_only) {
7041
- if(!vakata_dnd.scroll_e || (!vakata_dnd.scroll_l && !vakata_dnd.scroll_t)) {
7042
- if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
7043
- return false;
7044
- }
7045
- if(!vakata_dnd.scroll_i) {
7046
- vakata_dnd.scroll_i = setInterval($.vakata.dnd._scroll, 100);
7047
- return false;
7048
- }
7049
- if(init_only === true) { return false; }
7050
-
7051
- var i = vakata_dnd.scroll_e.scrollTop(),
7052
- j = vakata_dnd.scroll_e.scrollLeft();
7053
- vakata_dnd.scroll_e.scrollTop(i + vakata_dnd.scroll_t * $.vakata.dnd.settings.scroll_speed);
7054
- vakata_dnd.scroll_e.scrollLeft(j + vakata_dnd.scroll_l * $.vakata.dnd.settings.scroll_speed);
7055
- if(i !== vakata_dnd.scroll_e.scrollTop() || j !== vakata_dnd.scroll_e.scrollLeft()) {
7056
- /**
7057
- * triggered on the document when a drag causes an element to scroll
7058
- * @event
7059
- * @plugin dnd
7060
- * @name dnd_scroll.vakata
7061
- * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
7062
- * @param {DOM} element the DOM element being dragged
7063
- * @param {jQuery} helper the helper shown next to the mouse
7064
- * @param {jQuery} event the element that is scrolling
7065
- */
7066
- $.vakata.dnd._trigger("scroll", vakata_dnd.scroll_e);
7067
- }
7068
- },
7069
- start : function (e, data, html) {
7070
- if(e.type === "touchstart" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
7071
- e.pageX = e.originalEvent.changedTouches[0].pageX;
7072
- e.pageY = e.originalEvent.changedTouches[0].pageY;
7073
- e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
7074
- }
7075
- if(vakata_dnd.is_drag) { $.vakata.dnd.stop({}); }
7076
- try {
7077
- e.currentTarget.unselectable = "on";
7078
- e.currentTarget.onselectstart = function() { return false; };
7079
- if(e.currentTarget.style) {
7080
- e.currentTarget.style.touchAction = "none";
7081
- e.currentTarget.style.msTouchAction = "none";
7082
- e.currentTarget.style.MozUserSelect = "none";
7083
- }
7084
- } catch(ignore) { }
7085
- vakata_dnd.init_x = e.pageX;
7086
- vakata_dnd.init_y = e.pageY;
7087
- vakata_dnd.data = data;
7088
- vakata_dnd.is_down = true;
7089
- vakata_dnd.element = e.currentTarget;
7090
- vakata_dnd.target = e.target;
7091
- vakata_dnd.is_touch = e.type === "touchstart";
7092
- if(html !== false) {
7093
- vakata_dnd.helper = $("<div id='vakata-dnd'></div>").html(html).css({
7094
- "display" : "block",
7095
- "margin" : "0",
7096
- "padding" : "0",
7097
- "position" : "absolute",
7098
- "top" : "-2000px",
7099
- "lineHeight" : "16px",
7100
- "zIndex" : "10000"
7101
- });
7102
- }
7103
- $(document).on("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
7104
- $(document).on("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
7105
- return false;
7106
- },
7107
- drag : function (e) {
7108
- if(e.type === "touchmove" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
7109
- e.pageX = e.originalEvent.changedTouches[0].pageX;
7110
- e.pageY = e.originalEvent.changedTouches[0].pageY;
7111
- e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
7112
- }
7113
- if(!vakata_dnd.is_down) { return; }
7114
- if(!vakata_dnd.is_drag) {
7115
- if(
7116
- Math.abs(e.pageX - vakata_dnd.init_x) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold) ||
7117
- Math.abs(e.pageY - vakata_dnd.init_y) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold)
7118
- ) {
7119
- if(vakata_dnd.helper) {
7120
- vakata_dnd.helper.appendTo("body");
7121
- vakata_dnd.helper_w = vakata_dnd.helper.outerWidth();
7122
- }
7123
- vakata_dnd.is_drag = true;
7124
- $(vakata_dnd.target).one('click.vakata', false);
7125
- /**
7126
- * triggered on the document when a drag starts
7127
- * @event
7128
- * @plugin dnd
7129
- * @name dnd_start.vakata
7130
- * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
7131
- * @param {DOM} element the DOM element being dragged
7132
- * @param {jQuery} helper the helper shown next to the mouse
7133
- * @param {Object} event the event that caused the start (probably mousemove)
7134
- */
7135
- $.vakata.dnd._trigger("start", e);
7136
- }
7137
- else { return; }
7138
- }
7139
-
7140
- var d = false, w = false,
7141
- dh = false, wh = false,
7142
- dw = false, ww = false,
7143
- dt = false, dl = false,
7144
- ht = false, hl = false;
7145
-
7146
- vakata_dnd.scroll_t = 0;
7147
- vakata_dnd.scroll_l = 0;
7148
- vakata_dnd.scroll_e = false;
7149
- $($(e.target).parentsUntil("body").addBack().get().reverse())
7150
- .filter(function () {
7151
- return (/^auto|scroll$/).test($(this).css("overflow")) &&
7152
- (this.scrollHeight > this.offsetHeight || this.scrollWidth > this.offsetWidth);
7153
- })
7154
- .each(function () {
7155
- var t = $(this), o = t.offset();
7156
- if(this.scrollHeight > this.offsetHeight) {
7157
- if(o.top + t.height() - e.pageY < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
7158
- if(e.pageY - o.top < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
7159
- }
7160
- if(this.scrollWidth > this.offsetWidth) {
7161
- if(o.left + t.width() - e.pageX < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
7162
- if(e.pageX - o.left < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
7163
- }
7164
- if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
7165
- vakata_dnd.scroll_e = $(this);
7166
- return false;
7167
- }
7168
- });
7169
-
7170
- if(!vakata_dnd.scroll_e) {
7171
- d = $(document); w = $(window);
7172
- dh = d.height(); wh = w.height();
7173
- dw = d.width(); ww = w.width();
7174
- dt = d.scrollTop(); dl = d.scrollLeft();
7175
- if(dh > wh && e.pageY - dt < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
7176
- if(dh > wh && wh - (e.pageY - dt) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
7177
- if(dw > ww && e.pageX - dl < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
7178
- if(dw > ww && ww - (e.pageX - dl) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
7179
- if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
7180
- vakata_dnd.scroll_e = d;
7181
- }
7182
- }
7183
- if(vakata_dnd.scroll_e) { $.vakata.dnd._scroll(true); }
7184
-
7185
- if(vakata_dnd.helper) {
7186
- ht = parseInt(e.pageY + $.vakata.dnd.settings.helper_top, 10);
7187
- hl = parseInt(e.pageX + $.vakata.dnd.settings.helper_left, 10);
7188
- if(dh && ht + 25 > dh) { ht = dh - 50; }
7189
- if(dw && hl + vakata_dnd.helper_w > dw) { hl = dw - (vakata_dnd.helper_w + 2); }
7190
- vakata_dnd.helper.css({
7191
- left : hl + "px",
7192
- top : ht + "px"
7193
- });
7194
- }
7195
- /**
7196
- * triggered on the document when a drag is in progress
7197
- * @event
7198
- * @plugin dnd
7199
- * @name dnd_move.vakata
7200
- * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
7201
- * @param {DOM} element the DOM element being dragged
7202
- * @param {jQuery} helper the helper shown next to the mouse
7203
- * @param {Object} event the event that caused this to trigger (most likely mousemove)
7204
- */
7205
- $.vakata.dnd._trigger("move", e);
7206
- return false;
7207
- },
7208
- stop : function (e) {
7209
- if(e.type === "touchend" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
7210
- e.pageX = e.originalEvent.changedTouches[0].pageX;
7211
- e.pageY = e.originalEvent.changedTouches[0].pageY;
7212
- e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
7213
- }
7214
- if(vakata_dnd.is_drag) {
7215
- /**
7216
- * triggered on the document when a drag stops (the dragged element is dropped)
7217
- * @event
7218
- * @plugin dnd
7219
- * @name dnd_stop.vakata
7220
- * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
7221
- * @param {DOM} element the DOM element being dragged
7222
- * @param {jQuery} helper the helper shown next to the mouse
7223
- * @param {Object} event the event that caused the stop
7224
- */
7225
- if (e.target !== vakata_dnd.target) {
7226
- $(vakata_dnd.target).off('click.vakata');
7227
- }
7228
- $.vakata.dnd._trigger("stop", e);
7229
- }
7230
- else {
7231
- if(e.type === "touchend" && e.target === vakata_dnd.target) {
7232
- var to = setTimeout(function () { $(e.target).click(); }, 100);
7233
- $(e.target).one('click', function() { if(to) { clearTimeout(to); } });
7234
- }
7235
- }
7236
- $.vakata.dnd._clean();
7237
- return false;
7238
- }
7239
- };
7240
- }($));
7241
-
7242
- // include the dnd plugin by default
7243
- // $.jstree.defaults.plugins.push("dnd");
7244
-
7245
-
7246
- /**
7247
- * ### Massload plugin
7248
- *
7249
- * Adds massload functionality to jsTree, so that multiple nodes can be loaded in a single request (only useful with lazy loading).
7250
- */
7251
-
7252
- /**
7253
- * massload configuration
7254
- *
7255
- * It is possible to set this to a standard jQuery-like AJAX config.
7256
- * In addition to the standard jQuery ajax options here you can supply functions for `data` and `url`, the functions will be run in the current instance's scope and a param will be passed indicating which node IDs need to be loaded, the return value of those functions will be used.
7257
- *
7258
- * You can also set this to a function, that function will receive the node IDs being loaded as argument and a second param which is a function (callback) which should be called with the result.
7259
- *
7260
- * Both the AJAX and the function approach rely on the same return value - an object where the keys are the node IDs, and the value is the children of that node as an array.
7261
- *
7262
- * {
7263
- * "id1" : [{ "text" : "Child of ID1", "id" : "c1" }, { "text" : "Another child of ID1", "id" : "c2" }],
7264
- * "id2" : [{ "text" : "Child of ID2", "id" : "c3" }]
7265
- * }
7266
- *
7267
- * @name $.jstree.defaults.massload
7268
- * @plugin massload
7269
- */
7270
- $.jstree.defaults.massload = null;
7271
- $.jstree.plugins.massload = function (options, parent) {
7272
- this.init = function (el, options) {
7273
- this._data.massload = {};
7274
- parent.init.call(this, el, options);
7275
- };
7276
- this._load_nodes = function (nodes, callback, is_callback, force_reload) {
7277
- var s = this.settings.massload,
7278
- nodesString = JSON.stringify(nodes),
7279
- toLoad = [],
7280
- m = this._model.data,
7281
- i, j, dom;
7282
- if (!is_callback) {
7283
- for(i = 0, j = nodes.length; i < j; i++) {
7284
- if(!m[nodes[i]] || ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || force_reload) ) {
7285
- toLoad.push(nodes[i]);
7286
- dom = this.get_node(nodes[i], true);
7287
- if (dom && dom.length) {
7288
- dom.addClass("jstree-loading").attr('aria-busy',true);
7289
- }
7290
- }
7291
- }
7292
- this._data.massload = {};
7293
- if (toLoad.length) {
7294
- if($.isFunction(s)) {
7295
- return s.call(this, toLoad, $.proxy(function (data) {
7296
- var i, j;
7297
- if(data) {
7298
- for(i in data) {
7299
- if(data.hasOwnProperty(i)) {
7300
- this._data.massload[i] = data[i];
7301
- }
7302
- }
7303
- }
7304
- for(i = 0, j = nodes.length; i < j; i++) {
7305
- dom = this.get_node(nodes[i], true);
7306
- if (dom && dom.length) {
7307
- dom.removeClass("jstree-loading").attr('aria-busy',false);
7308
- }
7309
- }
7310
- parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7311
- }, this));
7312
- }
7313
- if(typeof s === 'object' && s && s.url) {
7314
- s = $.extend(true, {}, s);
7315
- if($.isFunction(s.url)) {
7316
- s.url = s.url.call(this, toLoad);
7317
- }
7318
- if($.isFunction(s.data)) {
7319
- s.data = s.data.call(this, toLoad);
7320
- }
7321
- return $.ajax(s)
7322
- .done($.proxy(function (data,t,x) {
7323
- var i, j;
7324
- if(data) {
7325
- for(i in data) {
7326
- if(data.hasOwnProperty(i)) {
7327
- this._data.massload[i] = data[i];
7328
- }
7329
- }
7330
- }
7331
- for(i = 0, j = nodes.length; i < j; i++) {
7332
- dom = this.get_node(nodes[i], true);
7333
- if (dom && dom.length) {
7334
- dom.removeClass("jstree-loading").attr('aria-busy',false);
7335
- }
7336
- }
7337
- parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7338
- }, this))
7339
- .fail($.proxy(function (f) {
7340
- parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7341
- }, this));
7342
- }
7343
- }
7344
- }
7345
- return parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7346
- };
7347
- this._load_node = function (obj, callback) {
7348
- var data = this._data.massload[obj.id],
7349
- rslt = null, dom;
7350
- if(data) {
7351
- rslt = this[typeof data === 'string' ? '_append_html_data' : '_append_json_data'](
7352
- obj,
7353
- typeof data === 'string' ? $($.parseHTML(data)).filter(function () { return this.nodeType !== 3; }) : data,
7354
- function (status) { callback.call(this, status); }
7355
- );
7356
- dom = this.get_node(obj.id, true);
7357
- if (dom && dom.length) {
7358
- dom.removeClass("jstree-loading").attr('aria-busy',false);
7359
- }
7360
- delete this._data.massload[obj.id];
7361
- return rslt;
7362
- }
7363
- return parent._load_node.call(this, obj, callback);
7364
- };
7365
- };
7366
-
7367
- /**
7368
- * ### Search plugin
7369
- *
7370
- * Adds search functionality to jsTree.
7371
- */
7372
-
7373
- /**
7374
- * stores all defaults for the search plugin
7375
- * @name $.jstree.defaults.search
7376
- * @plugin search
7377
- */
7378
- $.jstree.defaults.search = {
7379
- /**
7380
- * a jQuery-like AJAX config, which jstree uses if a server should be queried for results.
7381
- *
7382
- * A `str` (which is the search string) parameter will be added with the request, an optional `inside` parameter will be added if the search is limited to a node id. The expected result is a JSON array with nodes that need to be opened so that matching nodes will be revealed.
7383
- * Leave this setting as `false` to not query the server. You can also set this to a function, which will be invoked in the instance's scope and receive 3 parameters - the search string, the callback to call with the array of nodes to load, and the optional node ID to limit the search to
7384
- * @name $.jstree.defaults.search.ajax
7385
- * @plugin search
7386
- */
7387
- ajax : false,
7388
- /**
7389
- * Indicates if the search should be fuzzy or not (should `chnd3` match `child node 3`). Default is `false`.
7390
- * @name $.jstree.defaults.search.fuzzy
7391
- * @plugin search
7392
- */
7393
- fuzzy : false,
7394
- /**
7395
- * Indicates if the search should be case sensitive. Default is `false`.
7396
- * @name $.jstree.defaults.search.case_sensitive
7397
- * @plugin search
7398
- */
7399
- case_sensitive : false,
7400
- /**
7401
- * Indicates if the tree should be filtered (by default) to show only matching nodes (keep in mind this can be a heavy on large trees in old browsers).
7402
- * This setting can be changed at runtime when calling the search method. Default is `false`.
7403
- * @name $.jstree.defaults.search.show_only_matches
7404
- * @plugin search
7405
- */
7406
- show_only_matches : false,
7407
- /**
7408
- * Indicates if the children of matched element are shown (when show_only_matches is true)
7409
- * This setting can be changed at runtime when calling the search method. Default is `false`.
7410
- * @name $.jstree.defaults.search.show_only_matches_children
7411
- * @plugin search
7412
- */
7413
- show_only_matches_children : false,
7414
- /**
7415
- * 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`.
7416
- * @name $.jstree.defaults.search.close_opened_onclear
7417
- * @plugin search
7418
- */
7419
- close_opened_onclear : true,
7420
- /**
7421
- * Indicates if only leaf nodes should be included in search results. Default is `false`.
7422
- * @name $.jstree.defaults.search.search_leaves_only
7423
- * @plugin search
7424
- */
7425
- search_leaves_only : false,
7426
- /**
7427
- * If set to a function it wil be called in the instance's scope with two arguments - search string and node (where node will be every node in the structure, so use with caution).
7428
- * If the function returns a truthy value the node will be considered a match (it might not be displayed if search_only_leaves is set to true and the node is not a leaf). Default is `false`.
7429
- * @name $.jstree.defaults.search.search_callback
7430
- * @plugin search
7431
- */
7432
- search_callback : false
7433
- };
7434
-
7435
- $.jstree.plugins.search = function (options, parent) {
7436
- this.bind = function () {
7437
- parent.bind.call(this);
7438
-
7439
- this._data.search.str = "";
7440
- this._data.search.dom = $();
7441
- this._data.search.res = [];
7442
- this._data.search.opn = [];
7443
- this._data.search.som = false;
7444
- this._data.search.smc = false;
7445
- this._data.search.hdn = [];
7446
-
7447
- this.element
7448
- .on("search.jstree", $.proxy(function (e, data) {
7449
- if(this._data.search.som && data.res.length) {
7450
- var m = this._model.data, i, j, p = [], k, l;
7451
- for(i = 0, j = data.res.length; i < j; i++) {
7452
- if(m[data.res[i]] && !m[data.res[i]].state.hidden) {
7453
- p.push(data.res[i]);
7454
- p = p.concat(m[data.res[i]].parents);
7455
- if(this._data.search.smc) {
7456
- for (k = 0, l = m[data.res[i]].children_d.length; k < l; k++) {
7457
- if (m[m[data.res[i]].children_d[k]] && !m[m[data.res[i]].children_d[k]].state.hidden) {
7458
- p.push(m[data.res[i]].children_d[k]);
7459
- }
7460
- }
7461
- }
7462
- }
7463
- }
7464
- p = $.vakata.array_remove_item($.vakata.array_unique(p), $.jstree.root);
7465
- this._data.search.hdn = this.hide_all(true);
7466
- this.show_node(p, true);
7467
- this.redraw(true);
7468
- }
7469
- }, this))
7470
- .on("clear_search.jstree", $.proxy(function (e, data) {
7471
- if(this._data.search.som && data.res.length) {
7472
- this.show_node(this._data.search.hdn, true);
7473
- this.redraw(true);
7474
- }
7475
- }, this));
7476
- };
7477
- /**
7478
- * used to search the tree nodes for a given string
7479
- * @name search(str [, skip_async])
7480
- * @param {String} str the search string
7481
- * @param {Boolean} skip_async if set to true server will not be queried even if configured
7482
- * @param {Boolean} show_only_matches if set to true only matching nodes will be shown (keep in mind this can be very slow on large trees or old browsers)
7483
- * @param {mixed} inside an optional node to whose children to limit the search
7484
- * @param {Boolean} append if set to true the results of this search are appended to the previous search
7485
- * @plugin search
7486
- * @trigger search.jstree
7487
- */
7488
- this.search = function (str, skip_async, show_only_matches, inside, append, show_only_matches_children) {
7489
- if(str === false || $.trim(str.toString()) === "") {
7490
- return this.clear_search();
7491
- }
7492
- inside = this.get_node(inside);
7493
- inside = inside && inside.id ? inside.id : null;
7494
- str = str.toString();
7495
- var s = this.settings.search,
7496
- a = s.ajax ? s.ajax : false,
7497
- m = this._model.data,
7498
- f = null,
7499
- r = [],
7500
- p = [], i, j;
7501
- if(this._data.search.res.length && !append) {
7502
- this.clear_search();
7503
- }
7504
- if(show_only_matches === undefined) {
7505
- show_only_matches = s.show_only_matches;
7506
- }
7507
- if(show_only_matches_children === undefined) {
7508
- show_only_matches_children = s.show_only_matches_children;
7509
- }
7510
- if(!skip_async && a !== false) {
7511
- if($.isFunction(a)) {
7512
- return a.call(this, str, $.proxy(function (d) {
7513
- if(d && d.d) { d = d.d; }
7514
- this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
7515
- this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
7516
- });
7517
- }, this), inside);
7518
- }
7519
- else {
7520
- a = $.extend({}, a);
7521
- if(!a.data) { a.data = {}; }
7522
- a.data.str = str;
7523
- if(inside) {
7524
- a.data.inside = inside;
7525
- }
7526
- if (this._data.search.lastRequest) {
7527
- this._data.search.lastRequest.abort();
7528
- }
7529
- this._data.search.lastRequest = $.ajax(a)
7530
- .fail($.proxy(function () {
7531
- this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'search', 'id' : 'search_01', 'reason' : 'Could not load search parents', 'data' : JSON.stringify(a) };
7532
- this.settings.core.error.call(this, this._data.core.last_error);
7533
- }, this))
7534
- .done($.proxy(function (d) {
7535
- if(d && d.d) { d = d.d; }
7536
- this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
7537
- this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
7538
- });
7539
- }, this));
7540
- return this._data.search.lastRequest;
7541
- }
7542
- }
7543
- if(!append) {
7544
- this._data.search.str = str;
7545
- this._data.search.dom = $();
7546
- this._data.search.res = [];
7547
- this._data.search.opn = [];
7548
- this._data.search.som = show_only_matches;
7549
- this._data.search.smc = show_only_matches_children;
7550
- }
7551
-
7552
- f = new $.vakata.search(str, true, { caseSensitive : s.case_sensitive, fuzzy : s.fuzzy });
7553
- $.each(m[inside ? inside : $.jstree.root].children_d, function (ii, i) {
7554
- var v = m[i];
7555
- if(v.text && !v.state.hidden && (!s.search_leaves_only || (v.state.loaded && v.children.length === 0)) && ( (s.search_callback && s.search_callback.call(this, str, v)) || (!s.search_callback && f.search(v.text).isMatch) ) ) {
7556
- r.push(i);
7557
- p = p.concat(v.parents);
7558
- }
7559
- });
7560
- if(r.length) {
7561
- p = $.vakata.array_unique(p);
7562
- for(i = 0, j = p.length; i < j; i++) {
7563
- if(p[i] !== $.jstree.root && m[p[i]] && this.open_node(p[i], null, 0) === true) {
7564
- this._data.search.opn.push(p[i]);
7565
- }
7566
- }
7567
- if(!append) {
7568
- this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(r, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #')));
7569
- this._data.search.res = r;
7570
- }
7571
- else {
7572
- this._data.search.dom = this._data.search.dom.add($(this.element[0].querySelectorAll('#' + $.map(r, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #'))));
7573
- this._data.search.res = $.vakata.array_unique(this._data.search.res.concat(r));
7574
- }
7575
- this._data.search.dom.children(".jstree-anchor").addClass('jstree-search');
7576
- }
7577
- /**
7578
- * triggered after search is complete
7579
- * @event
7580
- * @name search.jstree
7581
- * @param {jQuery} nodes a jQuery collection of matching nodes
7582
- * @param {String} str the search string
7583
- * @param {Array} res a collection of objects represeing the matching nodes
7584
- * @plugin search
7585
- */
7586
- this.trigger('search', { nodes : this._data.search.dom, str : str, res : this._data.search.res, show_only_matches : show_only_matches });
7587
- };
7588
- /**
7589
- * used to clear the last search (removes classes and shows all nodes if filtering is on)
7590
- * @name clear_search()
7591
- * @plugin search
7592
- * @trigger clear_search.jstree
7593
- */
7594
- this.clear_search = function () {
7595
- if(this.settings.search.close_opened_onclear) {
7596
- this.close_node(this._data.search.opn, 0);
7597
- }
7598
- /**
7599
- * triggered after search is complete
7600
- * @event
7601
- * @name clear_search.jstree
7602
- * @param {jQuery} nodes a jQuery collection of matching nodes (the result from the last search)
7603
- * @param {String} str the search string (the last search string)
7604
- * @param {Array} res a collection of objects represeing the matching nodes (the result from the last search)
7605
- * @plugin search
7606
- */
7607
- this.trigger('clear_search', { 'nodes' : this._data.search.dom, str : this._data.search.str, res : this._data.search.res });
7608
- if(this._data.search.res.length) {
7609
- this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(this._data.search.res, function (v) {
7610
- return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&');
7611
- }).join(', #')));
7612
- this._data.search.dom.children(".jstree-anchor").removeClass("jstree-search");
7613
- }
7614
- this._data.search.str = "";
7615
- this._data.search.res = [];
7616
- this._data.search.opn = [];
7617
- this._data.search.dom = $();
7618
- };
7619
-
7620
- this.redraw_node = function(obj, deep, callback, force_render) {
7621
- obj = parent.redraw_node.apply(this, arguments);
7622
- if(obj) {
7623
- if($.inArray(obj.id, this._data.search.res) !== -1) {
7624
- var i, j, tmp = null;
7625
- for(i = 0, j = obj.childNodes.length; i < j; i++) {
7626
- if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
7627
- tmp = obj.childNodes[i];
7628
- break;
7629
- }
7630
- }
7631
- if(tmp) {
7632
- tmp.className += ' jstree-search';
7633
- }
7634
- }
7635
- }
7636
- return obj;
7637
- };
7638
- };
7639
-
7640
- // helpers
7641
- (function ($) {
7642
- // from http://kiro.me/projects/fuse.html
7643
- $.vakata.search = function(pattern, txt, options) {
7644
- options = options || {};
7645
- options = $.extend({}, $.vakata.search.defaults, options);
7646
- if(options.fuzzy !== false) {
7647
- options.fuzzy = true;
7648
- }
7649
- pattern = options.caseSensitive ? pattern : pattern.toLowerCase();
7650
- var MATCH_LOCATION = options.location,
7651
- MATCH_DISTANCE = options.distance,
7652
- MATCH_THRESHOLD = options.threshold,
7653
- patternLen = pattern.length,
7654
- matchmask, pattern_alphabet, match_bitapScore, search;
7655
- if(patternLen > 32) {
7656
- options.fuzzy = false;
7657
- }
7658
- if(options.fuzzy) {
7659
- matchmask = 1 << (patternLen - 1);
7660
- pattern_alphabet = (function () {
7661
- var mask = {},
7662
- i = 0;
7663
- for (i = 0; i < patternLen; i++) {
7664
- mask[pattern.charAt(i)] = 0;
7665
- }
7666
- for (i = 0; i < patternLen; i++) {
7667
- mask[pattern.charAt(i)] |= 1 << (patternLen - i - 1);
7668
- }
7669
- return mask;
7670
- }());
7671
- match_bitapScore = function (e, x) {
7672
- var accuracy = e / patternLen,
7673
- proximity = Math.abs(MATCH_LOCATION - x);
7674
- if(!MATCH_DISTANCE) {
7675
- return proximity ? 1.0 : accuracy;
7676
- }
7677
- return accuracy + (proximity / MATCH_DISTANCE);
7678
- };
7679
- }
7680
- search = function (text) {
7681
- text = options.caseSensitive ? text : text.toLowerCase();
7682
- if(pattern === text || text.indexOf(pattern) !== -1) {
7683
- return {
7684
- isMatch: true,
7685
- score: 0
7686
- };
7687
- }
7688
- if(!options.fuzzy) {
7689
- return {
7690
- isMatch: false,
7691
- score: 1
7692
- };
7693
- }
7694
- var i, j,
7695
- textLen = text.length,
7696
- scoreThreshold = MATCH_THRESHOLD,
7697
- bestLoc = text.indexOf(pattern, MATCH_LOCATION),
7698
- binMin, binMid,
7699
- binMax = patternLen + textLen,
7700
- lastRd, start, finish, rd, charMatch,
7701
- score = 1,
7702
- locations = [];
7703
- if (bestLoc !== -1) {
7704
- scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
7705
- bestLoc = text.lastIndexOf(pattern, MATCH_LOCATION + patternLen);
7706
- if (bestLoc !== -1) {
7707
- scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
7708
- }
7709
- }
7710
- bestLoc = -1;
7711
- for (i = 0; i < patternLen; i++) {
7712
- binMin = 0;
7713
- binMid = binMax;
7714
- while (binMin < binMid) {
7715
- if (match_bitapScore(i, MATCH_LOCATION + binMid) <= scoreThreshold) {
7716
- binMin = binMid;
7717
- } else {
7718
- binMax = binMid;
7719
- }
7720
- binMid = Math.floor((binMax - binMin) / 2 + binMin);
7721
- }
7722
- binMax = binMid;
7723
- start = Math.max(1, MATCH_LOCATION - binMid + 1);
7724
- finish = Math.min(MATCH_LOCATION + binMid, textLen) + patternLen;
7725
- rd = new Array(finish + 2);
7726
- rd[finish + 1] = (1 << i) - 1;
7727
- for (j = finish; j >= start; j--) {
7728
- charMatch = pattern_alphabet[text.charAt(j - 1)];
7729
- if (i === 0) {
7730
- rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
7731
- } else {
7732
- rd[j] = ((rd[j + 1] << 1) | 1) & charMatch | (((lastRd[j + 1] | lastRd[j]) << 1) | 1) | lastRd[j + 1];
7733
- }
7734
- if (rd[j] & matchmask) {
7735
- score = match_bitapScore(i, j - 1);
7736
- if (score <= scoreThreshold) {
7737
- scoreThreshold = score;
7738
- bestLoc = j - 1;
7739
- locations.push(bestLoc);
7740
- if (bestLoc > MATCH_LOCATION) {
7741
- start = Math.max(1, 2 * MATCH_LOCATION - bestLoc);
7742
- } else {
7743
- break;
7744
- }
7745
- }
7746
- }
7747
- }
7748
- if (match_bitapScore(i + 1, MATCH_LOCATION) > scoreThreshold) {
7749
- break;
7750
- }
7751
- lastRd = rd;
7752
- }
7753
- return {
7754
- isMatch: bestLoc >= 0,
7755
- score: score
7756
- };
7757
- };
7758
- return txt === true ? { 'search' : search } : search(txt);
7759
- };
7760
- $.vakata.search.defaults = {
7761
- location : 0,
7762
- distance : 100,
7763
- threshold : 0.6,
7764
- fuzzy : false,
7765
- caseSensitive : false
7766
- };
7767
- }($));
7768
-
7769
- // include the search plugin by default
7770
- // $.jstree.defaults.plugins.push("search");
7771
-
7772
-
7773
- /**
7774
- * ### Sort plugin
7775
- *
7776
- * Automatically sorts all siblings in the tree according to a sorting function.
7777
- */
7778
-
7779
- /**
7780
- * the settings function used to sort the nodes.
7781
- * It is executed in the tree's context, accepts two nodes as arguments and should return `1` or `-1`.
7782
- * @name $.jstree.defaults.sort
7783
- * @plugin sort
7784
- */
7785
- $.jstree.defaults.sort = function (a, b) {
7786
- //return this.get_type(a) === this.get_type(b) ? (this.get_text(a) > this.get_text(b) ? 1 : -1) : this.get_type(a) >= this.get_type(b);
7787
- return this.get_text(a) > this.get_text(b) ? 1 : -1;
7788
- };
7789
- $.jstree.plugins.sort = function (options, parent) {
7790
- this.bind = function () {
7791
- parent.bind.call(this);
7792
- this.element
7793
- .on("model.jstree", $.proxy(function (e, data) {
7794
- this.sort(data.parent, true);
7795
- }, this))
7796
- .on("rename_node.jstree create_node.jstree", $.proxy(function (e, data) {
7797
- this.sort(data.parent || data.node.parent, false);
7798
- this.redraw_node(data.parent || data.node.parent, true);
7799
- }, this))
7800
- .on("move_node.jstree copy_node.jstree", $.proxy(function (e, data) {
7801
- this.sort(data.parent, false);
7802
- this.redraw_node(data.parent, true);
7803
- }, this));
7804
- };
7805
- /**
7806
- * used to sort a node's children
7807
- * @private
7808
- * @name sort(obj [, deep])
7809
- * @param {mixed} obj the node
7810
- * @param {Boolean} deep if set to `true` nodes are sorted recursively.
7811
- * @plugin sort
7812
- * @trigger search.jstree
7813
- */
7814
- this.sort = function (obj, deep) {
7815
- var i, j;
7816
- obj = this.get_node(obj);
7817
- if(obj && obj.children && obj.children.length) {
7818
- obj.children.sort($.proxy(this.settings.sort, this));
7819
- if(deep) {
7820
- for(i = 0, j = obj.children_d.length; i < j; i++) {
7821
- this.sort(obj.children_d[i], false);
7822
- }
7823
- }
7824
- }
7825
- };
7826
- };
7827
-
7828
- // include the sort plugin by default
7829
- // $.jstree.defaults.plugins.push("sort");
7830
-
7831
- /**
7832
- * ### State plugin
7833
- *
7834
- * Saves the state of the tree (selected nodes, opened nodes) on the user's computer using available options (localStorage, cookies, etc)
7835
- */
7836
-
7837
- var to = false;
7838
- /**
7839
- * stores all defaults for the state plugin
7840
- * @name $.jstree.defaults.state
7841
- * @plugin state
7842
- */
7843
- $.jstree.defaults.state = {
7844
- /**
7845
- * A string for the key to use when saving the current tree (change if using multiple trees in your project). Defaults to `jstree`.
7846
- * @name $.jstree.defaults.state.key
7847
- * @plugin state
7848
- */
7849
- key : 'jstree',
7850
- /**
7851
- * A space separated list of events that trigger a state save. Defaults to `changed.jstree open_node.jstree close_node.jstree`.
7852
- * @name $.jstree.defaults.state.events
7853
- * @plugin state
7854
- */
7855
- events : 'changed.jstree open_node.jstree close_node.jstree check_node.jstree uncheck_node.jstree',
7856
- /**
7857
- * Time in milliseconds after which the state will expire. Defaults to 'false' meaning - no expire.
7858
- * @name $.jstree.defaults.state.ttl
7859
- * @plugin state
7860
- */
7861
- ttl : false,
7862
- /**
7863
- * A function that will be executed prior to restoring state with one argument - the state object. Can be used to clear unwanted parts of the state.
7864
- * @name $.jstree.defaults.state.filter
7865
- * @plugin state
7866
- */
7867
- filter : false,
7868
- /**
7869
- * Should loaded nodes be restored (setting this to true means that it is possible that the whole tree will be loaded for some users - use with caution). Defaults to `false`
7870
- * @name $.jstree.defaults.state.preserve_loaded
7871
- * @plugin state
7872
- */
7873
- preserve_loaded : false
7874
- };
7875
- $.jstree.plugins.state = function (options, parent) {
7876
- this.bind = function () {
7877
- parent.bind.call(this);
7878
- var bind = $.proxy(function () {
7879
- this.element.on(this.settings.state.events, $.proxy(function () {
7880
- if(to) { clearTimeout(to); }
7881
- to = setTimeout($.proxy(function () { this.save_state(); }, this), 100);
7882
- }, this));
7883
- /**
7884
- * triggered when the state plugin is finished restoring the state (and immediately after ready if there is no state to restore).
7885
- * @event
7886
- * @name state_ready.jstree
7887
- * @plugin state
7888
- */
7889
- this.trigger('state_ready');
7890
- }, this);
7891
- this.element
7892
- .on("ready.jstree", $.proxy(function (e, data) {
7893
- this.element.one("restore_state.jstree", bind);
7894
- if(!this.restore_state()) { bind(); }
7895
- }, this));
7896
- };
7897
- /**
7898
- * save the state
7899
- * @name save_state()
7900
- * @plugin state
7901
- */
7902
- this.save_state = function () {
7903
- var tm = this.get_state();
7904
- if (!this.settings.state.preserve_loaded) {
7905
- delete tm.core.loaded;
7906
- }
7907
- var st = { 'state' : tm, 'ttl' : this.settings.state.ttl, 'sec' : +(new Date()) };
7908
- $.vakata.storage.set(this.settings.state.key, JSON.stringify(st));
7909
- };
7910
- /**
7911
- * restore the state from the user's computer
7912
- * @name restore_state()
7913
- * @plugin state
7914
- */
7915
- this.restore_state = function () {
7916
- var k = $.vakata.storage.get(this.settings.state.key);
7917
- if(!!k) { try { k = JSON.parse(k); } catch(ex) { return false; } }
7918
- if(!!k && k.ttl && k.sec && +(new Date()) - k.sec > k.ttl) { return false; }
7919
- if(!!k && k.state) { k = k.state; }
7920
- if(!!k && $.isFunction(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); }
7921
- if(!!k) {
7922
- if (!this.settings.state.preserve_loaded) {
7923
- delete k.core.loaded;
7924
- }
7925
- this.element.one("set_state.jstree", function (e, data) { data.instance.trigger('restore_state', { 'state' : $.extend(true, {}, k) }); });
7926
- this.set_state(k);
7927
- return true;
7928
- }
7929
- return false;
7930
- };
7931
- /**
7932
- * clear the state on the user's computer
7933
- * @name clear_state()
7934
- * @plugin state
7935
- */
7936
- this.clear_state = function () {
7937
- return $.vakata.storage.del(this.settings.state.key);
7938
- };
7939
- };
7940
-
7941
- (function ($, undefined) {
7942
- $.vakata.storage = {
7943
- // simply specifying the functions in FF throws an error
7944
- set : function (key, val) { return window.localStorage.setItem(key, val); },
7945
- get : function (key) { return window.localStorage.getItem(key); },
7946
- del : function (key) { return window.localStorage.removeItem(key); }
7947
- };
7948
- }($));
7949
-
7950
- // include the state plugin by default
7951
- // $.jstree.defaults.plugins.push("state");
7952
-
7953
- /**
7954
- * ### Types plugin
7955
- *
7956
- * Makes it possible to add predefined types for groups of nodes, which make it possible to easily control nesting rules and icon for each group.
7957
- */
7958
-
7959
- /**
7960
- * An object storing all types as key value pairs, where the key is the type name and the value is an object that could contain following keys (all optional).
7961
- *
7962
- * * `max_children` the maximum number of immediate children this node type can have. Do not specify or set to `-1` for unlimited.
7963
- * * `max_depth` the maximum number of nesting this node type can have. A value of `1` would mean that the node can have children, but no grandchildren. Do not specify or set to `-1` for unlimited.
7964
- * * `valid_children` an array of node type strings, that nodes of this type can have as children. Do not specify or set to `-1` for no limits.
7965
- * * `icon` a string - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class. Omit to use the default icon from your theme.
7966
- * * `li_attr` an object of values which will be used to add HTML attributes on the resulting LI DOM node (merged with the node's own data)
7967
- * * `a_attr` an object of values which will be used to add HTML attributes on the resulting A DOM node (merged with the node's own data)
7968
- *
7969
- * There are two predefined types:
7970
- *
7971
- * * `#` represents the root of the tree, for example `max_children` would control the maximum number of root nodes.
7972
- * * `default` represents the default node - any settings here will be applied to all nodes that do not have a type specified.
7973
- *
7974
- * @name $.jstree.defaults.types
7975
- * @plugin types
7976
- */
7977
- $.jstree.defaults.types = {
7978
- 'default' : {}
7979
- };
7980
- $.jstree.defaults.types[$.jstree.root] = {};
7981
-
7982
- $.jstree.plugins.types = function (options, parent) {
7983
- this.init = function (el, options) {
7984
- var i, j;
7985
- if(options && options.types && options.types['default']) {
7986
- for(i in options.types) {
7987
- if(i !== "default" && i !== $.jstree.root && options.types.hasOwnProperty(i)) {
7988
- for(j in options.types['default']) {
7989
- if(options.types['default'].hasOwnProperty(j) && options.types[i][j] === undefined) {
7990
- options.types[i][j] = options.types['default'][j];
7991
- }
7992
- }
7993
- }
7994
- }
7995
- }
7996
- parent.init.call(this, el, options);
7997
- this._model.data[$.jstree.root].type = $.jstree.root;
7998
- };
7999
- this.refresh = function (skip_loading, forget_state) {
8000
- parent.refresh.call(this, skip_loading, forget_state);
8001
- this._model.data[$.jstree.root].type = $.jstree.root;
8002
- };
8003
- this.bind = function () {
8004
- this.element
8005
- .on('model.jstree', $.proxy(function (e, data) {
8006
- var m = this._model.data,
8007
- dpc = data.nodes,
8008
- t = this.settings.types,
8009
- i, j, c = 'default', k;
8010
- for(i = 0, j = dpc.length; i < j; i++) {
8011
- c = 'default';
8012
- if(m[dpc[i]].original && m[dpc[i]].original.type && t[m[dpc[i]].original.type]) {
8013
- c = m[dpc[i]].original.type;
8014
- }
8015
- if(m[dpc[i]].data && m[dpc[i]].data.jstree && m[dpc[i]].data.jstree.type && t[m[dpc[i]].data.jstree.type]) {
8016
- c = m[dpc[i]].data.jstree.type;
8017
- }
8018
- m[dpc[i]].type = c;
8019
- if(m[dpc[i]].icon === true && t[c].icon !== undefined) {
8020
- m[dpc[i]].icon = t[c].icon;
8021
- }
8022
- if(t[c].li_attr !== undefined && typeof t[c].li_attr === 'object') {
8023
- for (k in t[c].li_attr) {
8024
- if (t[c].li_attr.hasOwnProperty(k)) {
8025
- if (k === 'id') {
8026
- continue;
8027
- }
8028
- else if (m[dpc[i]].li_attr[k] === undefined) {
8029
- m[dpc[i]].li_attr[k] = t[c].li_attr[k];
8030
- }
8031
- else if (k === 'class') {
8032
- m[dpc[i]].li_attr['class'] = t[c].li_attr['class'] + ' ' + m[dpc[i]].li_attr['class'];
8033
- }
8034
- }
8035
- }
8036
- }
8037
- if(t[c].a_attr !== undefined && typeof t[c].a_attr === 'object') {
8038
- for (k in t[c].a_attr) {
8039
- if (t[c].a_attr.hasOwnProperty(k)) {
8040
- if (k === 'id') {
8041
- continue;
8042
- }
8043
- else if (m[dpc[i]].a_attr[k] === undefined) {
8044
- m[dpc[i]].a_attr[k] = t[c].a_attr[k];
8045
- }
8046
- else if (k === 'href' && m[dpc[i]].a_attr[k] === '#') {
8047
- m[dpc[i]].a_attr['href'] = t[c].a_attr['href'];
8048
- }
8049
- else if (k === 'class') {
8050
- m[dpc[i]].a_attr['class'] = t[c].a_attr['class'] + ' ' + m[dpc[i]].a_attr['class'];
8051
- }
8052
- }
8053
- }
8054
- }
8055
- }
8056
- m[$.jstree.root].type = $.jstree.root;
8057
- }, this));
8058
- parent.bind.call(this);
8059
- };
8060
- this.get_json = function (obj, options, flat) {
8061
- var i, j,
8062
- m = this._model.data,
8063
- opt = options ? $.extend(true, {}, options, {no_id:false}) : {},
8064
- tmp = parent.get_json.call(this, obj, opt, flat);
8065
- if(tmp === false) { return false; }
8066
- if($.isArray(tmp)) {
8067
- for(i = 0, j = tmp.length; i < j; i++) {
8068
- tmp[i].type = tmp[i].id && m[tmp[i].id] && m[tmp[i].id].type ? m[tmp[i].id].type : "default";
8069
- if(options && options.no_id) {
8070
- delete tmp[i].id;
8071
- if(tmp[i].li_attr && tmp[i].li_attr.id) {
8072
- delete tmp[i].li_attr.id;
8073
- }
8074
- if(tmp[i].a_attr && tmp[i].a_attr.id) {
8075
- delete tmp[i].a_attr.id;
8076
- }
8077
- }
8078
- }
8079
- }
8080
- else {
8081
- tmp.type = tmp.id && m[tmp.id] && m[tmp.id].type ? m[tmp.id].type : "default";
8082
- if(options && options.no_id) {
8083
- tmp = this._delete_ids(tmp);
8084
- }
8085
- }
8086
- return tmp;
8087
- };
8088
- this._delete_ids = function (tmp) {
8089
- if($.isArray(tmp)) {
8090
- for(var i = 0, j = tmp.length; i < j; i++) {
8091
- tmp[i] = this._delete_ids(tmp[i]);
8092
- }
8093
- return tmp;
8094
- }
8095
- delete tmp.id;
8096
- if(tmp.li_attr && tmp.li_attr.id) {
8097
- delete tmp.li_attr.id;
8098
- }
8099
- if(tmp.a_attr && tmp.a_attr.id) {
8100
- delete tmp.a_attr.id;
8101
- }
8102
- if(tmp.children && $.isArray(tmp.children)) {
8103
- tmp.children = this._delete_ids(tmp.children);
8104
- }
8105
- return tmp;
8106
- };
8107
- this.check = function (chk, obj, par, pos, more) {
8108
- if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
8109
- obj = obj && obj.id ? obj : this.get_node(obj);
8110
- par = par && par.id ? par : this.get_node(par);
8111
- var m = obj && obj.id ? (more && more.origin ? more.origin : $.jstree.reference(obj.id)) : null, tmp, d, i, j;
8112
- m = m && m._model && m._model.data ? m._model.data : null;
8113
- switch(chk) {
8114
- case "create_node":
8115
- case "move_node":
8116
- case "copy_node":
8117
- if(chk !== 'move_node' || $.inArray(obj.id, par.children) === -1) {
8118
- tmp = this.get_rules(par);
8119
- if(tmp.max_children !== undefined && tmp.max_children !== -1 && tmp.max_children === par.children.length) {
8120
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_01', 'reason' : 'max_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8121
- return false;
8122
- }
8123
- if(tmp.valid_children !== undefined && tmp.valid_children !== -1 && $.inArray((obj.type || 'default'), tmp.valid_children) === -1) {
8124
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_02', 'reason' : 'valid_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8125
- return false;
8126
- }
8127
- if(m && obj.children_d && obj.parents) {
8128
- d = 0;
8129
- for(i = 0, j = obj.children_d.length; i < j; i++) {
8130
- d = Math.max(d, m[obj.children_d[i]].parents.length);
8131
- }
8132
- d = d - obj.parents.length + 1;
8133
- }
8134
- if(d <= 0 || d === undefined) { d = 1; }
8135
- do {
8136
- if(tmp.max_depth !== undefined && tmp.max_depth !== -1 && tmp.max_depth < d) {
8137
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_03', 'reason' : 'max_depth prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8138
- return false;
8139
- }
8140
- par = this.get_node(par.parent);
8141
- tmp = this.get_rules(par);
8142
- d++;
8143
- } while(par);
8144
- }
8145
- break;
8146
- }
8147
- return true;
8148
- };
8149
- /**
8150
- * used to retrieve the type settings object for a node
8151
- * @name get_rules(obj)
8152
- * @param {mixed} obj the node to find the rules for
8153
- * @return {Object}
8154
- * @plugin types
8155
- */
8156
- this.get_rules = function (obj) {
8157
- obj = this.get_node(obj);
8158
- if(!obj) { return false; }
8159
- var tmp = this.get_type(obj, true);
8160
- if(tmp.max_depth === undefined) { tmp.max_depth = -1; }
8161
- if(tmp.max_children === undefined) { tmp.max_children = -1; }
8162
- if(tmp.valid_children === undefined) { tmp.valid_children = -1; }
8163
- return tmp;
8164
- };
8165
- /**
8166
- * used to retrieve the type string or settings object for a node
8167
- * @name get_type(obj [, rules])
8168
- * @param {mixed} obj the node to find the rules for
8169
- * @param {Boolean} rules if set to `true` instead of a string the settings object will be returned
8170
- * @return {String|Object}
8171
- * @plugin types
8172
- */
8173
- this.get_type = function (obj, rules) {
8174
- obj = this.get_node(obj);
8175
- return (!obj) ? false : ( rules ? $.extend({ 'type' : obj.type }, this.settings.types[obj.type]) : obj.type);
8176
- };
8177
- /**
8178
- * used to change a node's type
8179
- * @name set_type(obj, type)
8180
- * @param {mixed} obj the node to change
8181
- * @param {String} type the new type
8182
- * @plugin types
8183
- */
8184
- this.set_type = function (obj, type) {
8185
- var m = this._model.data, t, t1, t2, old_type, old_icon, k, d, a;
8186
- if($.isArray(obj)) {
8187
- obj = obj.slice();
8188
- for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
8189
- this.set_type(obj[t1], type);
8190
- }
8191
- return true;
8192
- }
8193
- t = this.settings.types;
8194
- obj = this.get_node(obj);
8195
- if(!t[type] || !obj) { return false; }
8196
- d = this.get_node(obj, true);
8197
- if (d && d.length) {
8198
- a = d.children('.jstree-anchor');
8199
- }
8200
- old_type = obj.type;
8201
- old_icon = this.get_icon(obj);
8202
- obj.type = type;
8203
- if(old_icon === true || !t[old_type] || (t[old_type].icon !== undefined && old_icon === t[old_type].icon)) {
8204
- this.set_icon(obj, t[type].icon !== undefined ? t[type].icon : true);
8205
- }
8206
-
8207
- // remove old type props
8208
- if(t[old_type] && t[old_type].li_attr !== undefined && typeof t[old_type].li_attr === 'object') {
8209
- for (k in t[old_type].li_attr) {
8210
- if (t[old_type].li_attr.hasOwnProperty(k)) {
8211
- if (k === 'id') {
8212
- continue;
8213
- }
8214
- else if (k === 'class') {
8215
- m[obj.id].li_attr['class'] = (m[obj.id].li_attr['class'] || '').replace(t[old_type].li_attr[k], '');
8216
- if (d) { d.removeClass(t[old_type].li_attr[k]); }
8217
- }
8218
- else if (m[obj.id].li_attr[k] === t[old_type].li_attr[k]) {
8219
- m[obj.id].li_attr[k] = null;
8220
- if (d) { d.removeAttr(k); }
8221
- }
8222
- }
8223
- }
8224
- }
8225
- if(t[old_type] && t[old_type].a_attr !== undefined && typeof t[old_type].a_attr === 'object') {
8226
- for (k in t[old_type].a_attr) {
8227
- if (t[old_type].a_attr.hasOwnProperty(k)) {
8228
- if (k === 'id') {
8229
- continue;
8230
- }
8231
- else if (k === 'class') {
8232
- m[obj.id].a_attr['class'] = (m[obj.id].a_attr['class'] || '').replace(t[old_type].a_attr[k], '');
8233
- if (a) { a.removeClass(t[old_type].a_attr[k]); }
8234
- }
8235
- else if (m[obj.id].a_attr[k] === t[old_type].a_attr[k]) {
8236
- if (k === 'href') {
8237
- m[obj.id].a_attr[k] = '#';
8238
- if (a) { a.attr('href', '#'); }
8239
- }
8240
- else {
8241
- delete m[obj.id].a_attr[k];
8242
- if (a) { a.removeAttr(k); }
8243
- }
8244
- }
8245
- }
8246
- }
8247
- }
8248
-
8249
- // add new props
8250
- if(t[type].li_attr !== undefined && typeof t[type].li_attr === 'object') {
8251
- for (k in t[type].li_attr) {
8252
- if (t[type].li_attr.hasOwnProperty(k)) {
8253
- if (k === 'id') {
8254
- continue;
8255
- }
8256
- else if (m[obj.id].li_attr[k] === undefined) {
8257
- m[obj.id].li_attr[k] = t[type].li_attr[k];
8258
- if (d) {
8259
- if (k === 'class') {
8260
- d.addClass(t[type].li_attr[k]);
8261
- }
8262
- else {
8263
- d.attr(k, t[type].li_attr[k]);
8264
- }
8265
- }
8266
- }
8267
- else if (k === 'class') {
8268
- m[obj.id].li_attr['class'] = t[type].li_attr[k] + ' ' + m[obj.id].li_attr['class'];
8269
- if (d) { d.addClass(t[type].li_attr[k]); }
8270
- }
8271
- }
8272
- }
8273
- }
8274
- if(t[type].a_attr !== undefined && typeof t[type].a_attr === 'object') {
8275
- for (k in t[type].a_attr) {
8276
- if (t[type].a_attr.hasOwnProperty(k)) {
8277
- if (k === 'id') {
8278
- continue;
8279
- }
8280
- else if (m[obj.id].a_attr[k] === undefined) {
8281
- m[obj.id].a_attr[k] = t[type].a_attr[k];
8282
- if (a) {
8283
- if (k === 'class') {
8284
- a.addClass(t[type].a_attr[k]);
8285
- }
8286
- else {
8287
- a.attr(k, t[type].a_attr[k]);
8288
- }
8289
- }
8290
- }
8291
- else if (k === 'href' && m[obj.id].a_attr[k] === '#') {
8292
- m[obj.id].a_attr['href'] = t[type].a_attr['href'];
8293
- if (a) { a.attr('href', t[type].a_attr['href']); }
8294
- }
8295
- else if (k === 'class') {
8296
- m[obj.id].a_attr['class'] = t[type].a_attr['class'] + ' ' + m[obj.id].a_attr['class'];
8297
- if (a) { a.addClass(t[type].a_attr[k]); }
8298
- }
8299
- }
8300
- }
8301
- }
8302
-
8303
- return true;
8304
- };
8305
- };
8306
- // include the types plugin by default
8307
- // $.jstree.defaults.plugins.push("types");
8308
-
8309
-
8310
- /**
8311
- * ### Unique plugin
8312
- *
8313
- * Enforces that no nodes with the same name can coexist as siblings.
8314
- */
8315
-
8316
- /**
8317
- * stores all defaults for the unique plugin
8318
- * @name $.jstree.defaults.unique
8319
- * @plugin unique
8320
- */
8321
- $.jstree.defaults.unique = {
8322
- /**
8323
- * Indicates if the comparison should be case sensitive. Default is `false`.
8324
- * @name $.jstree.defaults.unique.case_sensitive
8325
- * @plugin unique
8326
- */
8327
- case_sensitive : false,
8328
- /**
8329
- * Indicates if white space should be trimmed before the comparison. Default is `false`.
8330
- * @name $.jstree.defaults.unique.trim_whitespace
8331
- * @plugin unique
8332
- */
8333
- trim_whitespace : false,
8334
- /**
8335
- * A callback executed in the instance's scope when a new node is created and the name is already taken, the two arguments are the conflicting name and the counter. The default will produce results like `New node (2)`.
8336
- * @name $.jstree.defaults.unique.duplicate
8337
- * @plugin unique
8338
- */
8339
- duplicate : function (name, counter) {
8340
- return name + ' (' + counter + ')';
8341
- }
8342
- };
8343
-
8344
- $.jstree.plugins.unique = function (options, parent) {
8345
- this.check = function (chk, obj, par, pos, more) {
8346
- if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
8347
- obj = obj && obj.id ? obj : this.get_node(obj);
8348
- par = par && par.id ? par : this.get_node(par);
8349
- if(!par || !par.children) { return true; }
8350
- var n = chk === "rename_node" ? pos : obj.text,
8351
- c = [],
8352
- s = this.settings.unique.case_sensitive,
8353
- w = this.settings.unique.trim_whitespace,
8354
- m = this._model.data, i, j, t;
8355
- for(i = 0, j = par.children.length; i < j; i++) {
8356
- t = m[par.children[i]].text;
8357
- if (!s) {
8358
- t = t.toLowerCase();
8359
- }
8360
- if (w) {
8361
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8362
- }
8363
- c.push(t);
8364
- }
8365
- if(!s) { n = n.toLowerCase(); }
8366
- if (w) { n = n.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }
8367
- switch(chk) {
8368
- case "delete_node":
8369
- return true;
8370
- case "rename_node":
8371
- t = obj.text || '';
8372
- if (!s) {
8373
- t = t.toLowerCase();
8374
- }
8375
- if (w) {
8376
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8377
- }
8378
- i = ($.inArray(n, c) === -1 || (obj.text && t === n));
8379
- if(!i) {
8380
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_01', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8381
- }
8382
- return i;
8383
- case "create_node":
8384
- i = ($.inArray(n, c) === -1);
8385
- if(!i) {
8386
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_04', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8387
- }
8388
- return i;
8389
- case "copy_node":
8390
- i = ($.inArray(n, c) === -1);
8391
- if(!i) {
8392
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_02', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8393
- }
8394
- return i;
8395
- case "move_node":
8396
- i = ( (obj.parent === par.id && (!more || !more.is_multi)) || $.inArray(n, c) === -1);
8397
- if(!i) {
8398
- this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_03', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8399
- }
8400
- return i;
8401
- }
8402
- return true;
8403
- };
8404
- this.create_node = function (par, node, pos, callback, is_loaded) {
8405
- if(!node || node.text === undefined) {
8406
- if(par === null) {
8407
- par = $.jstree.root;
8408
- }
8409
- par = this.get_node(par);
8410
- if(!par) {
8411
- return parent.create_node.call(this, par, node, pos, callback, is_loaded);
8412
- }
8413
- pos = pos === undefined ? "last" : pos;
8414
- if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
8415
- return parent.create_node.call(this, par, node, pos, callback, is_loaded);
8416
- }
8417
- if(!node) { node = {}; }
8418
- var tmp, n, dpc, i, j, m = this._model.data, s = this.settings.unique.case_sensitive, w = this.settings.unique.trim_whitespace, cb = this.settings.unique.duplicate, t;
8419
- n = tmp = this.get_string('New node');
8420
- dpc = [];
8421
- for(i = 0, j = par.children.length; i < j; i++) {
8422
- t = m[par.children[i]].text;
8423
- if (!s) {
8424
- t = t.toLowerCase();
8425
- }
8426
- if (w) {
8427
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8428
- }
8429
- dpc.push(t);
8430
- }
8431
- i = 1;
8432
- t = n;
8433
- if (!s) {
8434
- t = t.toLowerCase();
8435
- }
8436
- if (w) {
8437
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8438
- }
8439
- while($.inArray(t, dpc) !== -1) {
8440
- n = cb.call(this, tmp, (++i)).toString();
8441
- t = n;
8442
- if (!s) {
8443
- t = t.toLowerCase();
8444
- }
8445
- if (w) {
8446
- t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8447
- }
8448
- }
8449
- node.text = n;
8450
- }
8451
- return parent.create_node.call(this, par, node, pos, callback, is_loaded);
8452
- };
8453
- };
8454
-
8455
- // include the unique plugin by default
8456
- // $.jstree.defaults.plugins.push("unique");
8457
-
8458
-
8459
- /**
8460
- * ### Wholerow plugin
8461
- *
8462
- * Makes each node appear block level. Making selection easier. May cause slow down for large trees in old browsers.
8463
- */
8464
-
8465
- var div = document.createElement('DIV');
8466
- div.setAttribute('unselectable','on');
8467
- div.setAttribute('role','presentation');
8468
- div.className = 'jstree-wholerow';
8469
- div.innerHTML = '&#160;';
8470
- $.jstree.plugins.wholerow = function (options, parent) {
8471
- this.bind = function () {
8472
- parent.bind.call(this);
8473
-
8474
- this.element
8475
- .on('ready.jstree set_state.jstree', $.proxy(function () {
8476
- this.hide_dots();
8477
- }, this))
8478
- .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
8479
- //div.style.height = this._data.core.li_height + 'px';
8480
- this.get_container_ul().addClass('jstree-wholerow-ul');
8481
- }, this))
8482
- .on("deselect_all.jstree", $.proxy(function (e, data) {
8483
- this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
8484
- }, this))
8485
- .on("changed.jstree", $.proxy(function (e, data) {
8486
- this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
8487
- var tmp = false, i, j;
8488
- for(i = 0, j = data.selected.length; i < j; i++) {
8489
- tmp = this.get_node(data.selected[i], true);
8490
- if(tmp && tmp.length) {
8491
- tmp.children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
8492
- }
8493
- }
8494
- }, this))
8495
- .on("open_node.jstree", $.proxy(function (e, data) {
8496
- this.get_node(data.node, true).find('.jstree-clicked').parent().children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
8497
- }, this))
8498
- .on("hover_node.jstree dehover_node.jstree", $.proxy(function (e, data) {
8499
- if(e.type === "hover_node" && this.is_disabled(data.node)) { return; }
8500
- this.get_node(data.node, true).children('.jstree-wholerow')[e.type === "hover_node"?"addClass":"removeClass"]('jstree-wholerow-hovered');
8501
- }, this))
8502
- .on("contextmenu.jstree", ".jstree-wholerow", $.proxy(function (e) {
8503
- if (this._data.contextmenu) {
8504
- e.preventDefault();
8505
- var tmp = $.Event('contextmenu', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey, pageX : e.pageX, pageY : e.pageY });
8506
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp);
8507
- }
8508
- }, this))
8509
- /*!
8510
- .on("mousedown.jstree touchstart.jstree", ".jstree-wholerow", function (e) {
8511
- if(e.target === e.currentTarget) {
8512
- var a = $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor");
8513
- e.target = a[0];
8514
- a.trigger(e);
8515
- }
8516
- })
8517
- */
8518
- .on("click.jstree", ".jstree-wholerow", function (e) {
8519
- e.stopImmediatePropagation();
8520
- var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8521
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8522
- })
8523
- .on("dblclick.jstree", ".jstree-wholerow", function (e) {
8524
- e.stopImmediatePropagation();
8525
- var tmp = $.Event('dblclick', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8526
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8527
- })
8528
- .on("click.jstree", ".jstree-leaf > .jstree-ocl", $.proxy(function (e) {
8529
- e.stopImmediatePropagation();
8530
- var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8531
- $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8532
- }, this))
8533
- .on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", $.proxy(function (e) {
8534
- e.stopImmediatePropagation();
8535
- if(!this.is_disabled(e.currentTarget)) {
8536
- this.hover_node(e.currentTarget);
8537
- }
8538
- return false;
8539
- }, this))
8540
- .on("mouseleave.jstree", ".jstree-node", $.proxy(function (e) {
8541
- this.dehover_node(e.currentTarget);
8542
- }, this));
8543
- };
8544
- this.teardown = function () {
8545
- if(this.settings.wholerow) {
8546
- this.element.find(".jstree-wholerow").remove();
8547
- }
8548
- parent.teardown.call(this);
8549
- };
8550
- this.redraw_node = function(obj, deep, callback, force_render) {
8551
- obj = parent.redraw_node.apply(this, arguments);
8552
- if(obj) {
8553
- var tmp = div.cloneNode(true);
8554
- //tmp.style.height = this._data.core.li_height + 'px';
8555
- if($.inArray(obj.id, this._data.core.selected) !== -1) { tmp.className += ' jstree-wholerow-clicked'; }
8556
- if(this._data.core.focused && this._data.core.focused === obj.id) { tmp.className += ' jstree-wholerow-hovered'; }
8557
- obj.insertBefore(tmp, obj.childNodes[0]);
8558
- }
8559
- return obj;
8560
- };
8561
- };
8562
- // include the wholerow plugin by default
8563
- // $.jstree.defaults.plugins.push("wholerow");
8564
- if(document.registerElement && Object && Object.create) {
8565
- var proto = Object.create(HTMLElement.prototype);
8566
- proto.createdCallback = function () {
8567
- var c = { core : {}, plugins : [] }, i;
8568
- for(i in $.jstree.plugins) {
8569
- if($.jstree.plugins.hasOwnProperty(i) && this.attributes[i]) {
8570
- c.plugins.push(i);
8571
- if(this.getAttribute(i) && JSON.parse(this.getAttribute(i))) {
8572
- c[i] = JSON.parse(this.getAttribute(i));
8573
- }
8574
- }
8575
- }
8576
- for(i in $.jstree.defaults.core) {
8577
- if($.jstree.defaults.core.hasOwnProperty(i) && this.attributes[i]) {
8578
- c.core[i] = JSON.parse(this.getAttribute(i)) || this.getAttribute(i);
8579
- }
8580
- }
8581
- $(this).jstree(c);
8582
- };
8583
- // proto.attributeChangedCallback = function (name, previous, value) { };
8584
- try {
8585
- document.registerElement("vakata-jstree", { prototype: proto });
8586
- } catch(ignore) { }
8587
- }
8588
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8589
  }));
1
+ /*globals jQuery, define, module, exports, require, window, document, postMessage */
2
+ (function (factory) {
3
+ "use strict";
4
+ if (typeof define === 'function' && define.amd) {
5
+ define(['jquery'], factory);
6
+ }
7
+ else if(typeof module !== 'undefined' && module.exports) {
8
+ module.exports = factory(require('jquery'));
9
+ }
10
+ else {
11
+ factory(jQuery);
12
+ }
13
+ }(function ($, undefined) {
14
+ "use strict";
15
+ /*!
16
+ * jsTree 3.3.7
17
+ * http://jstree.com/
18
+ *
19
+ * Copyright (c) 2014 Ivan Bozhanov (http://vakata.com)
20
+ *
21
+ * Licensed same as jquery - under the terms of the MIT License
22
+ * http://www.opensource.org/licenses/mit-license.php
23
+ */
24
+ /*!
25
+ * if using jslint please allow for the jQuery global and use following options:
26
+ * jslint: loopfunc: true, browser: true, ass: true, bitwise: true, continue: true, nomen: true, plusplus: true, regexp: true, unparam: true, todo: true, white: true
27
+ */
28
+ /*jshint -W083 */
29
+
30
+ // prevent another load? maybe there is a better way?
31
+ if($.jstree) {
32
+ return;
33
+ }
34
+
35
+ /**
36
+ * ### jsTree core functionality
37
+ */
38
+
39
+ // internal variables
40
+ var instance_counter = 0,
41
+ ccp_node = false,
42
+ ccp_mode = false,
43
+ ccp_inst = false,
44
+ themes_loaded = [],
45
+ src = $('script:last').attr('src'),
46
+ document = window.document; // local variable is always faster to access then a global
47
+
48
+ /**
49
+ * holds all jstree related functions and variables, including the actual class and methods to create, access and manipulate instances.
50
+ * @name $.jstree
51
+ */
52
+ $.jstree = {
53
+ /**
54
+ * specifies the jstree version in use
55
+ * @name $.jstree.version
56
+ */
57
+ version : '3.3.7',
58
+ /**
59
+ * holds all the default options used when creating new instances
60
+ * @name $.jstree.defaults
61
+ */
62
+ defaults : {
63
+ /**
64
+ * configure which plugins will be active on an instance. Should be an array of strings, where each element is a plugin name. The default is `[]`
65
+ * @name $.jstree.defaults.plugins
66
+ */
67
+ plugins : []
68
+ },
69
+ /**
70
+ * stores all loaded jstree plugins (used internally)
71
+ * @name $.jstree.plugins
72
+ */
73
+ plugins : {},
74
+ path : src && src.indexOf('/') !== -1 ? src.replace(/\/[^\/]+$/,'') : '',
75
+ idregex : /[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,
76
+ root : '#'
77
+ };
78
+
79
+ /**
80
+ * creates a jstree instance
81
+ * @name $.jstree.create(el [, options])
82
+ * @param {DOMElement|jQuery|String} el the element to create the instance on, can be jQuery extended or a selector
83
+ * @param {Object} options options for this instance (extends `$.jstree.defaults`)
84
+ * @return {jsTree} the new instance
85
+ */
86
+ $.jstree.create = function (el, options) {
87
+ var tmp = new $.jstree.core(++instance_counter),
88
+ opt = options;
89
+ options = $.extend(true, {}, $.jstree.defaults, options);
90
+ if(opt && opt.plugins) {
91
+ options.plugins = opt.plugins;
92
+ }
93
+ $.each(options.plugins, function (i, k) {
94
+ if(i !== 'core') {
95
+ tmp = tmp.plugin(k, options[k]);
96
+ }
97
+ });
98
+ $(el).data('jstree', tmp);
99
+ tmp.init(el, options);
100
+ return tmp;
101
+ };
102
+ /**
103
+ * remove all traces of jstree from the DOM and destroy all instances
104
+ * @name $.jstree.destroy()
105
+ */
106
+ $.jstree.destroy = function () {
107
+ $('.jstree:jstree').jstree('destroy');
108
+ $(document).off('.jstree');
109
+ };
110
+ /**
111
+ * the jstree class constructor, used only internally
112
+ * @private
113
+ * @name $.jstree.core(id)
114
+ * @param {Number} id this instance's index
115
+ */
116
+ $.jstree.core = function (id) {
117
+ this._id = id;
118
+ this._cnt = 0;
119
+ this._wrk = null;
120
+ this._data = {
121
+ core : {
122
+ themes : {
123
+ name : false,
124
+ dots : false,
125
+ icons : false,
126
+ ellipsis : false
127
+ },
128
+ selected : [],
129
+ last_error : {},
130
+ working : false,
131
+ worker_queue : [],
132
+ focused : null
133
+ }
134
+ };
135
+ };
136
+ /**
137
+ * get a reference to an existing instance
138
+ *
139
+ * __Examples__
140
+ *
141
+ * // provided a container with an ID of "tree", and a nested node with an ID of "branch"
142
+ * // all of there will return the same instance
143
+ * $.jstree.reference('tree');
144
+ * $.jstree.reference('#tree');
145
+ * $.jstree.reference($('#tree'));
146
+ * $.jstree.reference(document.getElementByID('tree'));
147
+ * $.jstree.reference('branch');
148
+ * $.jstree.reference('#branch');
149
+ * $.jstree.reference($('#branch'));
150
+ * $.jstree.reference(document.getElementByID('branch'));
151
+ *
152
+ * @name $.jstree.reference(needle)
153
+ * @param {DOMElement|jQuery|String} needle
154
+ * @return {jsTree|null} the instance or `null` if not found
155
+ */
156
+ $.jstree.reference = function (needle) {
157
+ var tmp = null,
158
+ obj = null;
159
+ if(needle && needle.id && (!needle.tagName || !needle.nodeType)) { needle = needle.id; }
160
+
161
+ if(!obj || !obj.length) {
162
+ try { obj = $(needle); } catch (ignore) { }
163
+ }
164
+ if(!obj || !obj.length) {
165
+ try { obj = $('#' + needle.replace($.jstree.idregex,'\\$&')); } catch (ignore) { }
166
+ }
167
+ if(obj && obj.length && (obj = obj.closest('.jstree')).length && (obj = obj.data('jstree'))) {
168
+ tmp = obj;
169
+ }
170
+ else {
171
+ $('.jstree').each(function () {
172
+ var inst = $(this).data('jstree');
173
+ if(inst && inst._model.data[needle]) {
174
+ tmp = inst;
175
+ return false;
176
+ }
177
+ });
178
+ }
179
+ return tmp;
180
+ };
181
+ /**
182
+ * Create an instance, get an instance or invoke a command on a instance.
183
+ *
184
+ * If there is no instance associated with the current node a new one is created and `arg` is used to extend `$.jstree.defaults` for this new instance. There would be no return value (chaining is not broken).
185
+ *
186
+ * If there is an existing instance and `arg` is a string the command specified by `arg` is executed on the instance, with any additional arguments passed to the function. If the function returns a value it will be returned (chaining could break depending on function).
187
+ *
188
+ * If there is an existing instance and `arg` is not a string the instance itself is returned (similar to `$.jstree.reference`).
189
+ *
190
+ * In any other case - nothing is returned and chaining is not broken.
191
+ *
192
+ * __Examples__
193
+ *
194
+ * $('#tree1').jstree(); // creates an instance
195
+ * $('#tree2').jstree({ plugins : [] }); // create an instance with some options
196
+ * $('#tree1').jstree('open_node', '#branch_1'); // call a method on an existing instance, passing additional arguments
197
+ * $('#tree2').jstree(); // get an existing instance (or create an instance)
198
+ * $('#tree2').jstree(true); // get an existing instance (will not create new instance)
199
+ * $('#branch_1').jstree().select_node('#branch_1'); // get an instance (using a nested element and call a method)
200
+ *
201
+ * @name $().jstree([arg])
202
+ * @param {String|Object} arg
203
+ * @return {Mixed}
204
+ */
205
+ $.fn.jstree = function (arg) {
206
+ // check for string argument
207
+ var is_method = (typeof arg === 'string'),
208
+ args = Array.prototype.slice.call(arguments, 1),
209
+ result = null;
210
+ if(arg === true && !this.length) { return false; }
211
+ this.each(function () {
212
+ // get the instance (if there is one) and method (if it exists)
213
+ var instance = $.jstree.reference(this),
214
+ method = is_method && instance ? instance[arg] : null;
215
+ // if calling a method, and method is available - execute on the instance
216
+ result = is_method && method ?
217
+ method.apply(instance, args) :
218
+ null;
219
+ // if there is no instance and no method is being called - create one
220
+ if(!instance && !is_method && (arg === undefined || $.isPlainObject(arg))) {
221
+ $.jstree.create(this, arg);
222
+ }
223
+ // if there is an instance and no method is called - return the instance
224
+ if( (instance && !is_method) || arg === true ) {
225
+ result = instance || false;
226
+ }
227
+ // if there was a method call which returned a result - break and return the value
228
+ if(result !== null && result !== undefined) {
229
+ return false;
230
+ }
231
+ });
232
+ // if there was a method call with a valid return value - return that, otherwise continue the chain
233
+ return result !== null && result !== undefined ?
234
+ result : this;
235
+ };
236
+ /**
237
+ * used to find elements containing an instance
238
+ *
239
+ * __Examples__
240
+ *
241
+ * $('div:jstree').each(function () {
242
+ * $(this).jstree('destroy');
243
+ * });
244
+ *
245
+ * @name $(':jstree')
246
+ * @return {jQuery}
247
+ */
248
+ $.expr.pseudos.jstree = $.expr.createPseudo(function(search) {
249
+ return function(a) {
250
+ return $(a).hasClass('jstree') &&
251
+ $(a).data('jstree') !== undefined;
252
+ };
253
+ });
254
+
255
+ /**
256
+ * stores all defaults for the core
257
+ * @name $.jstree.defaults.core
258
+ */
259
+ $.jstree.defaults.core = {
260
+ /**
261
+ * data configuration
262
+ *
263
+ * If left as `false` the HTML inside the jstree container element is used to populate the tree (that should be an unordered list with list items).
264
+ *
265
+ * You can also pass in a HTML string or a JSON array here.
266
+ *
267
+ * It is possible to pass in a standard jQuery-like AJAX config and jstree will automatically determine if the response is JSON or HTML and use that to populate the tree.
268
+ * In addition to the standard jQuery ajax options here you can suppy functions for `data` and `url`, the functions will be run in the current instance's scope and a param will be passed indicating which node is being loaded, the return value of those functions will be used.
269
+ *
270
+ * The last option is to specify a function, that function will receive the node being loaded as argument and a second param which is a function which should be called with the result.
271
+ *
272
+ * __Examples__
273
+ *
274
+ * // AJAX
275
+ * $('#tree').jstree({
276
+ * 'core' : {
277
+ * 'data' : {
278
+ * 'url' : '/get/children/',
279
+ * 'data' : function (node) {
280
+ * return { 'id' : node.id };
281
+ * }
282
+ * }
283
+ * });
284
+ *
285
+ * // direct data
286
+ * $('#tree').jstree({
287
+ * 'core' : {
288
+ * 'data' : [
289
+ * 'Simple root node',
290
+ * {
291
+ * 'id' : 'node_2',
292
+ * 'text' : 'Root node with options',
293
+ * 'state' : { 'opened' : true, 'selected' : true },
294
+ * 'children' : [ { 'text' : 'Child 1' }, 'Child 2']
295
+ * }
296
+ * ]
297
+ * }
298
+ * });
299
+ *
300
+ * // function
301
+ * $('#tree').jstree({
302
+ * 'core' : {
303
+ * 'data' : function (obj, callback) {
304
+ * callback.call(this, ['Root 1', 'Root 2']);
305
+ * }
306
+ * });
307
+ *
308
+ * @name $.jstree.defaults.core.data
309
+ */
310
+ data : false,
311
+ /**
312
+ * configure the various strings used throughout the tree
313
+ *
314
+ * You can use an object where the key is the string you need to replace and the value is your replacement.
315
+ * Another option is to specify a function which will be called with an argument of the needed string and should return the replacement.
316
+ * If left as `false` no replacement is made.
317
+ *
318
+ * __Examples__
319
+ *
320
+ * $('#tree').jstree({
321
+ * 'core' : {
322
+ * 'strings' : {
323
+ * 'Loading ...' : 'Please wait ...'
324
+ * }
325
+ * }
326
+ * });
327
+ *
328
+ * @name $.jstree.defaults.core.strings
329
+ */
330
+ strings : false,
331
+ /**
332
+ * determines what happens when a user tries to modify the structure of the tree
333
+ * If left as `false` all operations like create, rename, delete, move or copy are prevented.
334
+ * You can set this to `true` to allow all interactions or use a function to have better control.
335
+ *
336
+ * __Examples__
337
+ *
338
+ * $('#tree').jstree({
339
+ * 'core' : {
340
+ * 'check_callback' : function (operation, node, node_parent, node_position, more) {
341
+ * // operation can be 'create_node', 'rename_node', 'delete_node', 'move_node', 'copy_node' or 'edit'
342
+ * // in case of 'rename_node' node_position is filled with the new node name
343
+ * return operation === 'rename_node' ? true : false;
344
+ * }
345
+ * }
346
+ * });
347
+ *
348
+ * @name $.jstree.defaults.core.check_callback
349
+ */
350
+ check_callback : false,
351
+ /**
352
+ * a callback called with a single object parameter in the instance's scope when something goes wrong (operation prevented, ajax failed, etc)
353
+ * @name $.jstree.defaults.core.error
354
+ */
355
+ error : $.noop,
356
+ /**
357
+ * the open / close animation duration in milliseconds - set this to `false` to disable the animation (default is `200`)
358
+ * @name $.jstree.defaults.core.animation
359
+ */
360
+ animation : 200,
361
+ /**
362
+ * a boolean indicating if multiple nodes can be selected
363
+ * @name $.jstree.defaults.core.multiple
364
+ */
365
+ multiple : true,
366
+ /**
367
+ * theme configuration object
368
+ * @name $.jstree.defaults.core.themes
369
+ */
370
+ themes : {
371
+ /**
372
+ * the name of the theme to use (if left as `false` the default theme is used)
373
+ * @name $.jstree.defaults.core.themes.name
374
+ */
375
+ name : false,
376
+ /**
377
+ * the URL of the theme's CSS file, leave this as `false` if you have manually included the theme CSS (recommended). You can set this to `true` too which will try to autoload the theme.
378
+ * @name $.jstree.defaults.core.themes.url
379
+ */
380
+ url : false,
381
+ /**
382
+ * the location of all jstree themes - only used if `url` is set to `true`
383
+ * @name $.jstree.defaults.core.themes.dir
384
+ */
385
+ dir : false,
386
+ /**
387
+ * a boolean indicating if connecting dots are shown
388
+ * @name $.jstree.defaults.core.themes.dots
389
+ */
390
+ dots : true,
391
+ /**
392
+ * a boolean indicating if node icons are shown
393
+ * @name $.jstree.defaults.core.themes.icons
394
+ */
395
+ icons : true,
396
+ /**
397
+ * a boolean indicating if node ellipsis should be shown - this only works with a fixed with on the container
398
+ * @name $.jstree.defaults.core.themes.ellipsis
399
+ */
400
+ ellipsis : false,
401
+ /**
402
+ * a boolean indicating if the tree background is striped
403
+ * @name $.jstree.defaults.core.themes.stripes
404
+ */
405
+ stripes : false,
406
+ /**
407
+ * a string (or boolean `false`) specifying the theme variant to use (if the theme supports variants)
408
+ * @name $.jstree.defaults.core.themes.variant
409
+ */
410
+ variant : false,
411
+ /**
412
+ * a boolean specifying if a reponsive version of the theme should kick in on smaller screens (if the theme supports it). Defaults to `false`.
413
+ * @name $.jstree.defaults.core.themes.responsive
414
+ */
415
+ responsive : false
416
+ },
417
+ /**
418
+ * if left as `true` all parents of all selected nodes will be opened once the tree loads (so that all selected nodes are visible to the user)
419
+ * @name $.jstree.defaults.core.expand_selected_onload
420
+ */
421
+ expand_selected_onload : true,
422
+ /**
423
+ * if left as `true` web workers will be used to parse incoming JSON data where possible, so that the UI will not be blocked by large requests. Workers are however about 30% slower. Defaults to `true`
424
+ * @name $.jstree.defaults.core.worker
425
+ */
426
+ worker : true,
427
+ /**
428
+ * Force node text to plain text (and escape HTML). Defaults to `false`
429
+ * @name $.jstree.defaults.core.force_text
430
+ */
431
+ force_text : false,
432
+ /**
433
+ * Should the node be toggled if the text is double clicked. Defaults to `true`
434
+ * @name $.jstree.defaults.core.dblclick_toggle
435
+ */
436
+ dblclick_toggle : true,
437
+ /**
438
+ * Should the loaded nodes be part of the state. Defaults to `false`
439
+ * @name $.jstree.defaults.core.loaded_state
440
+ */
441
+ loaded_state : false,
442
+ /**
443
+ * Should the last active node be focused when the tree container is blurred and the focused again. This helps working with screen readers. Defaults to `true`
444
+ * @name $.jstree.defaults.core.restore_focus
445
+ */
446
+ restore_focus : true,
447
+ /**
448
+ * Default keyboard shortcuts (an object where each key is the button name or combo - like 'enter', 'ctrl-space', 'p', etc and the value is the function to execute in the instance's scope)
449
+ * @name $.jstree.defaults.core.keyboard
450
+ */
451
+ keyboard : {
452
+ 'ctrl-space': function (e) {
453
+ // aria defines space only with Ctrl
454
+ e.type = "click";
455
+ $(e.currentTarget).trigger(e);
456
+ },
457
+ 'enter': function (e) {
458
+ // enter
459
+ e.type = "click";
460
+ $(e.currentTarget).trigger(e);
461
+ },
462
+ 'left': function (e) {
463
+ // left
464
+ e.preventDefault();
465
+ if(this.is_open(e.currentTarget)) {
466
+ this.close_node(e.currentTarget);
467
+ }
468
+ else {
469
+ var o = this.get_parent(e.currentTarget);
470
+ if(o && o.id !== $.jstree.root) { this.get_node(o, true).children('.jstree-anchor').focus(); }
471
+ }
472
+ },
473
+ 'up': function (e) {
474
+ // up
475
+ e.preventDefault();
476
+ var o = this.get_prev_dom(e.currentTarget);
477
+ if(o && o.length) { o.children('.jstree-anchor').focus(); }
478
+ },
479
+ 'right': function (e) {
480
+ // right
481
+ e.preventDefault();
482
+ if(this.is_closed(e.currentTarget)) {
483
+ this.open_node(e.currentTarget, function (o) { this.get_node(o, true).children('.jstree-anchor').focus(); });
484
+ }
485
+ else if (this.is_open(e.currentTarget)) {
486
+ var o = this.get_node(e.currentTarget, true).children('.jstree-children')[0];
487
+ if(o) { $(this._firstChild(o)).children('.jstree-anchor').focus(); }
488
+ }
489
+ },
490
+ 'down': function (e) {
491
+ // down
492
+ e.preventDefault();
493
+ var o = this.get_next_dom(e.currentTarget);
494
+ if(o && o.length) { o.children('.jstree-anchor').focus(); }
495
+ },
496
+ '*': function (e) {
497
+ // aria defines * on numpad as open_all - not very common
498
+ this.open_all();
499
+ },
500
+ 'home': function (e) {
501
+ // home
502
+ e.preventDefault();
503
+ var o = this._firstChild(this.get_container_ul()[0]);
504
+ if(o) { $(o).children('.jstree-anchor').filter(':visible').focus(); }
505
+ },
506
+ 'end': function (e) {
507
+ // end
508
+ e.preventDefault();
509
+ this.element.find('.jstree-anchor').filter(':visible').last().focus();
510
+ },
511
+ 'f2': function (e) {
512
+ // f2 - safe to include - if check_callback is false it will fail
513
+ e.preventDefault();
514
+ this.edit(e.currentTarget);
515
+ }
516
+ }
517
+ };
518
+ $.jstree.core.prototype = {
519
+ /**
520
+ * used to decorate an instance with a plugin. Used internally.
521
+ * @private
522
+ * @name plugin(deco [, opts])
523
+ * @param {String} deco the plugin to decorate with
524
+ * @param {Object} opts options for the plugin
525
+ * @return {jsTree}
526
+ */
527
+ plugin : function (deco, opts) {
528
+ var Child = $.jstree.plugins[deco];
529
+ if(Child) {
530
+ this._data[deco] = {};
531
+ Child.prototype = this;
532
+ return new Child(opts, this);
533
+ }
534
+ return this;
535
+ },
536
+ /**
537
+ * initialize the instance. Used internally.
538
+ * @private
539
+ * @name init(el, optons)
540
+ * @param {DOMElement|jQuery|String} el the element we are transforming
541
+ * @param {Object} options options for this instance
542
+ * @trigger init.jstree, loading.jstree, loaded.jstree, ready.jstree, changed.jstree
543
+ */
544
+ init : function (el, options) {
545
+ this._model = {
546
+ data : {},
547
+ changed : [],
548
+ force_full_redraw : false,
549
+ redraw_timeout : false,
550
+ default_state : {
551
+ loaded : true,
552
+ opened : false,
553
+ selected : false,
554
+ disabled : false
555
+ }
556
+ };
557
+ this._model.data[$.jstree.root] = {
558
+ id : $.jstree.root,
559
+ parent : null,
560
+ parents : [],
561
+ children : [],
562
+ children_d : [],
563
+ state : { loaded : false }
564
+ };
565
+
566
+ this.element = $(el).addClass('jstree jstree-' + this._id);
567
+ this.settings = options;
568
+
569
+ this._data.core.ready = false;
570
+ this._data.core.loaded = false;
571
+ this._data.core.rtl = (this.element.css("direction") === "rtl");
572
+ this.element[this._data.core.rtl ? 'addClass' : 'removeClass']("jstree-rtl");
573
+ this.element.attr('role','tree');
574
+ if(this.settings.core.multiple) {
575
+ this.element.attr('aria-multiselectable', true);
576
+ }
577
+ if(!this.element.attr('tabindex')) {
578
+ this.element.attr('tabindex','0');
579
+ }
580
+
581
+ this.bind();
582
+ /**
583
+ * triggered after all events are bound
584
+ * @event
585
+ * @name init.jstree
586
+ */
587
+ this.trigger("init");
588
+
589
+ this._data.core.original_container_html = this.element.find(" > ul > li").clone(true);
590
+ this._data.core.original_container_html
591
+ .find("li").addBack()
592
+ .contents().filter(function() {
593
+ return this.nodeType === 3 && (!this.nodeValue || /^\s+$/.test(this.nodeValue));
594
+ })
595
+ .remove();
596
+ this.element.html("<"+"ul class='jstree-container-ul jstree-children' role='group'><"+"li id='j"+this._id+"_loading' class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='tree-item'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
597
+ this.element.attr('aria-activedescendant','j' + this._id + '_loading');
598
+ this._data.core.li_height = this.get_container_ul().children("li").first().outerHeight() || 24;
599
+ this._data.core.node = this._create_prototype_node();
600
+ /**
601
+ * triggered after the loading text is shown and before loading starts
602
+ * @event
603
+ * @name loading.jstree
604
+ */
605
+ this.trigger("loading");
606
+ this.load_node($.jstree.root);
607
+ },
608
+ /**
609
+ * destroy an instance
610
+ * @name destroy()
611
+ * @param {Boolean} keep_html if not set to `true` the container will be emptied, otherwise the current DOM elements will be kept intact
612
+ */
613
+ destroy : function (keep_html) {
614
+ /**
615
+ * triggered before the tree is destroyed
616
+ * @event
617
+ * @name destroy.jstree
618
+ */
619
+ this.trigger("destroy");
620
+ if(this._wrk) {
621
+ try {
622
+ window.URL.revokeObjectURL(this._wrk);
623
+ this._wrk = null;
624
+ }
625
+ catch (ignore) { }
626
+ }
627
+ if(!keep_html) { this.element.empty(); }
628
+ this.teardown();
629
+ },
630
+ /**
631
+ * Create a prototype node
632
+ * @name _create_prototype_node()
633
+ * @return {DOMElement}
634
+ */
635
+ _create_prototype_node : function () {
636
+ var _node = document.createElement('LI'), _temp1, _temp2;
637
+ _node.setAttribute('role', 'treeitem');
638
+ _temp1 = document.createElement('I');
639
+ _temp1.className = 'jstree-icon jstree-ocl';
640
+ _temp1.setAttribute('role', 'presentation');
641
+ _node.appendChild(_temp1);
642
+ _temp1 = document.createElement('A');
643
+ _temp1.className = 'jstree-anchor';
644
+ _temp1.setAttribute('href','#');
645
+ _temp1.setAttribute('tabindex','-1');
646
+ _temp2 = document.createElement('I');
647
+ _temp2.className = 'jstree-icon jstree-themeicon';
648
+ _temp2.setAttribute('role', 'presentation');
649
+ _temp1.appendChild(_temp2);
650
+ _node.appendChild(_temp1);
651
+ _temp1 = _temp2 = null;
652
+
653
+ return _node;
654
+ },
655
+ _kbevent_to_func : function (e) {
656
+ var keys = {
657
+ 8: "Backspace", 9: "Tab", 13: "Return", 19: "Pause", 27: "Esc",
658
+ 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End", 36: "Home",
659
+ 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "Print", 45: "Insert",
660
+ 46: "Delete", 96: "Numpad0", 97: "Numpad1", 98: "Numpad2", 99 : "Numpad3",
661
+ 100: "Numpad4", 101: "Numpad5", 102: "Numpad6", 103: "Numpad7",
662
+ 104: "Numpad8", 105: "Numpad9", '-13': "NumpadEnter", 112: "F1",
663
+ 113: "F2", 114: "F3", 115: "F4", 116: "F5", 117: "F6", 118: "F7",
664
+ 119: "F8", 120: "F9", 121: "F10", 122: "F11", 123: "F12", 144: "Numlock",
665
+ 145: "Scrolllock", 16: 'Shift', 17: 'Ctrl', 18: 'Alt',
666
+ 48: '0', 49: '1', 50: '2', 51: '3', 52: '4', 53: '5',
667
+ 54: '6', 55: '7', 56: '8', 57: '9', 59: ';', 61: '=', 65: 'a',
668
+ 66: 'b', 67: 'c', 68: 'd', 69: 'e', 70: 'f', 71: 'g', 72: 'h',
669
+ 73: 'i', 74: 'j', 75: 'k', 76: 'l', 77: 'm', 78: 'n', 79: 'o',
670
+ 80: 'p', 81: 'q', 82: 'r', 83: 's', 84: 't', 85: 'u', 86: 'v',
671
+ 87: 'w', 88: 'x', 89: 'y', 90: 'z', 107: '+', 109: '-', 110: '.',
672
+ 186: ';', 187: '=', 188: ',', 189: '-', 190: '.', 191: '/', 192: '`',
673
+ 219: '[', 220: '\\',221: ']', 222: "'", 111: '/', 106: '*', 173: '-'
674
+ };
675
+ var parts = [];
676
+ if (e.ctrlKey) { parts.push('ctrl'); }
677
+ if (e.altKey) { parts.push('alt'); }
678
+ if (e.shiftKey) { parts.push('shift'); }
679
+ parts.push(keys[e.which] || e.which);
680
+ parts = parts.sort().join('-').toLowerCase();
681
+
682
+ var kb = this.settings.core.keyboard, i, tmp;
683
+ for (i in kb) {
684
+ if (kb.hasOwnProperty(i)) {
685
+ tmp = i;
686
+ if (tmp !== '-' && tmp !== '+') {
687
+ tmp = tmp.replace('--', '-MINUS').replace('+-', '-MINUS').replace('++', '-PLUS').replace('-+', '-PLUS');
688
+ tmp = tmp.split(/-|\+/).sort().join('-').replace('MINUS', '-').replace('PLUS', '+').toLowerCase();
689
+ }
690
+ if (tmp === parts) {
691
+ return kb[i];
692
+ }
693
+ }
694
+ }
695
+ return null;
696
+ },
697
+ /**
698
+ * part of the destroying of an instance. Used internally.
699
+ * @private
700
+ * @name teardown()
701
+ */
702
+ teardown : function () {
703
+ this.unbind();
704
+ this.element
705
+ .removeClass('jstree')
706
+ .removeData('jstree')
707
+ .find("[class^='jstree']")
708
+ .addBack()
709
+ .attr("class", function () { return this.className.replace(/jstree[^ ]*|$/ig,''); });
710
+ this.element = null;
711
+ },
712
+ /**
713
+ * bind all events. Used internally.
714
+ * @private
715
+ * @name bind()
716
+ */
717
+ bind : function () {
718
+ var word = '',
719
+ tout = null,
720
+ was_click = 0;
721
+ this.element
722
+ .on("dblclick.jstree", function (e) {
723
+ if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
724
+ if(document.selection && document.selection.empty) {
725
+ document.selection.empty();
726
+ }
727
+ else {
728
+ if(window.getSelection) {
729
+ var sel = window.getSelection();
730
+ try {
731
+ sel.removeAllRanges();
732
+ sel.collapse();
733
+ } catch (ignore) { }
734
+ }
735
+ }
736
+ })
737
+ .on("mousedown.jstree", $.proxy(function (e) {
738
+ if(e.target === this.element[0]) {
739
+ e.preventDefault(); // prevent losing focus when clicking scroll arrows (FF, Chrome)
740
+ was_click = +(new Date()); // ie does not allow to prevent losing focus
741
+ }
742
+ }, this))
743
+ .on("mousedown.jstree", ".jstree-ocl", function (e) {
744
+ e.preventDefault(); // prevent any node inside from losing focus when clicking the open/close icon
745
+ })
746
+ .on("click.jstree", ".jstree-ocl", $.proxy(function (e) {
747
+ this.toggle_node(e.target);
748
+ }, this))
749
+ .on("dblclick.jstree", ".jstree-anchor", $.proxy(function (e) {
750
+ if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
751
+ if(this.settings.core.dblclick_toggle) {
752
+ this.toggle_node(e.target);
753
+ }
754
+ }, this))
755
+ .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
756
+ e.preventDefault();
757
+ if(e.currentTarget !== document.activeElement) { $(e.currentTarget).focus(); }
758
+ this.activate_node(e.currentTarget, e);
759
+ }, this))
760
+ .on('keydown.jstree', '.jstree-anchor', $.proxy(function (e) {
761
+ if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
762
+ if(this._data.core.rtl) {
763
+ if(e.which === 37) { e.which = 39; }
764
+ else if(e.which === 39) { e.which = 37; }
765
+ }
766
+ var f = this._kbevent_to_func(e);
767
+ if (f) {
768
+ var r = f.call(this, e);
769
+ if (r === false || r === true) {
770
+ return r;
771
+ }
772
+ }
773
+ }, this))
774
+ .on("load_node.jstree", $.proxy(function (e, data) {
775
+ if(data.status) {
776
+ if(data.node.id === $.jstree.root && !this._data.core.loaded) {
777
+ this._data.core.loaded = true;
778
+ if(this._firstChild(this.get_container_ul()[0])) {
779
+ this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
780
+ }
781
+ /**
782
+ * triggered after the root node is loaded for the first time
783
+ * @event
784
+ * @name loaded.jstree
785
+ */
786
+ this.trigger("loaded");
787
+ }
788
+ if(!this._data.core.ready) {
789
+ setTimeout($.proxy(function() {
790
+ if(this.element && !this.get_container_ul().find('.jstree-loading').length) {
791
+ this._data.core.ready = true;
792
+ if(this._data.core.selected.length) {
793
+ if(this.settings.core.expand_selected_onload) {
794
+ var tmp = [], i, j;
795
+ for(i = 0, j = this._data.core.selected.length; i < j; i++) {
796
+ tmp = tmp.concat(this._model.data[this._data.core.selected[i]].parents);
797
+ }
798
+ tmp = $.vakata.array_unique(tmp);
799
+ for(i = 0, j = tmp.length; i < j; i++) {
800
+ this.open_node(tmp[i], false, 0);
801
+ }
802
+ }
803
+ this.trigger('changed', { 'action' : 'ready', 'selected' : this._data.core.selected });
804
+ }
805
+ /**
806
+ * triggered after all nodes are finished loading
807
+ * @event
808
+ * @name ready.jstree
809
+ */
810
+ this.trigger("ready");
811
+ }
812
+ }, this), 0);
813
+ }
814
+ }
815
+ }, this))
816
+ // quick searching when the tree is focused
817
+ .on('keypress.jstree', $.proxy(function (e) {
818
+ if(e.target.tagName && e.target.tagName.toLowerCase() === "input") { return true; }
819
+ if(tout) { clearTimeout(tout); }
820
+ tout = setTimeout(function () {
821
+ word = '';
822
+ }, 500);
823
+
824
+ var chr = String.fromCharCode(e.which).toLowerCase(),
825
+ col = this.element.find('.jstree-anchor').filter(':visible'),
826
+ ind = col.index(document.activeElement) || 0,
827
+ end = false;
828
+ word += chr;
829
+
830
+ // match for whole word from current node down (including the current node)
831
+ if(word.length > 1) {
832
+ col.slice(ind).each($.proxy(function (i, v) {
833
+ if($(v).text().toLowerCase().indexOf(word) === 0) {
834
+ $(v).focus();
835
+ end = true;
836
+ return false;
837
+ }
838
+ }, this));
839
+ if(end) { return; }
840
+
841
+ // match for whole word from the beginning of the tree
842
+ col.slice(0, ind).each($.proxy(function (i, v) {
843
+ if($(v).text().toLowerCase().indexOf(word) === 0) {
844
+ $(v).focus();
845
+ end = true;
846
+ return false;
847
+ }
848
+ }, this));
849
+ if(end) { return; }
850
+ }
851
+ // list nodes that start with that letter (only if word consists of a single char)
852
+ if(new RegExp('^' + chr.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') + '+$').test(word)) {
853
+ // search for the next node starting with that letter
854
+ col.slice(ind + 1).each($.proxy(function (i, v) {
855
+ if($(v).text().toLowerCase().charAt(0) === chr) {
856
+ $(v).focus();
857
+ end = true;
858
+ return false;
859
+ }
860
+ }, this));
861
+ if(end) { return; }
862
+
863
+ // search from the beginning
864
+ col.slice(0, ind + 1).each($.proxy(function (i, v) {
865
+ if($(v).text().toLowerCase().charAt(0) === chr) {
866
+ $(v).focus();
867
+ end = true;
868
+ return false;
869
+ }
870
+ }, this));
871
+ if(end) { return; }
872
+ }
873
+ }, this))
874
+ // THEME RELATED
875
+ .on("init.jstree", $.proxy(function () {
876
+ var s = this.settings.core.themes;
877
+ this._data.core.themes.dots = s.dots;
878
+ this._data.core.themes.stripes = s.stripes;
879
+ this._data.core.themes.icons = s.icons;
880
+ this._data.core.themes.ellipsis = s.ellipsis;
881
+ this.set_theme(s.name || "default", s.url);
882
+ this.set_theme_variant(s.variant);
883
+ }, this))
884
+ .on("loading.jstree", $.proxy(function () {
885
+ this[ this._data.core.themes.dots ? "show_dots" : "hide_dots" ]();
886
+ this[ this._data.core.themes.icons ? "show_icons" : "hide_icons" ]();
887
+ this[ this._data.core.themes.stripes ? "show_stripes" : "hide_stripes" ]();
888
+ this[ this._data.core.themes.ellipsis ? "show_ellipsis" : "hide_ellipsis" ]();
889
+ }, this))
890
+ .on('blur.jstree', '.jstree-anchor', $.proxy(function (e) {
891
+ this._data.core.focused = null;
892
+ $(e.currentTarget).filter('.jstree-hovered').mouseleave();
893
+ this.element.attr('tabindex', '0');
894
+ }, this))
895
+ .on('focus.jstree', '.jstree-anchor', $.proxy(function (e) {
896
+ var tmp = this.get_node(e.currentTarget);
897
+ if(tmp && tmp.id) {
898
+ this._data.core.focused = tmp.id;
899
+ }
900
+ this.element.find('.jstree-hovered').not(e.currentTarget).mouseleave();
901
+ $(e.currentTarget).mouseenter();
902
+ this.element.attr('tabindex', '-1');
903
+ }, this))
904
+ .on('focus.jstree', $.proxy(function () {
905
+ if(+(new Date()) - was_click > 500 && !this._data.core.focused && this.settings.core.restore_focus) {
906
+ was_click = 0;
907
+ var act = this.get_node(this.element.attr('aria-activedescendant'), true);
908
+ if(act) {
909
+ act.find('> .jstree-anchor').focus();
910
+ }
911
+ }
912
+ }, this))
913
+ .on('mouseenter.jstree', '.jstree-anchor', $.proxy(function (e) {
914
+ this.hover_node(e.currentTarget);
915
+ }, this))
916
+ .on('mouseleave.jstree', '.jstree-anchor', $.proxy(function (e) {
917
+ this.dehover_node(e.currentTarget);
918
+ }, this));
919
+ },
920
+ /**
921
+ * part of the destroying of an instance. Used internally.
922
+ * @private
923
+ * @name unbind()
924
+ */
925
+ unbind : function () {
926
+ this.element.off('.jstree');
927
+ $(document).off('.jstree-' + this._id);
928
+ },
929
+ /**
930
+ * trigger an event. Used internally.
931
+ * @private
932
+ * @name trigger(ev [, data])
933
+ * @param {String} ev the name of the event to trigger
934
+ * @param {Object} data additional data to pass with the event
935
+ */
936
+ trigger : function (ev, data) {
937
+ if(!data) {
938
+ data = {};
939
+ }
940
+ data.instance = this;
941
+ this.element.triggerHandler(ev.replace('.jstree','') + '.jstree', data);
942
+ },
943
+ /**
944
+ * returns the jQuery extended instance container
945
+ * @name get_container()
946
+ * @return {jQuery}
947
+ */
948
+ get_container : function () {
949
+ return this.element;
950
+ },
951
+ /**
952
+ * returns the jQuery extended main UL node inside the instance container. Used internally.
953
+ * @private
954
+ * @name get_container_ul()
955
+ * @return {jQuery}
956
+ */
957
+ get_container_ul : function () {
958
+ return this.element.children(".jstree-children").first();
959
+ },
960
+ /**
961
+ * gets string replacements (localization). Used internally.
962
+ * @private
963
+ * @name get_string(key)
964
+ * @param {String} key
965
+ * @return {String}
966
+ */
967
+ get_string : function (key) {
968
+ var a = this.settings.core.strings;
969
+ if($.isFunction(a)) { return a.call(this, key); }
970
+ if(a && a[key]) { return a[key]; }
971
+ return key;
972
+ },
973
+ /**
974
+ * gets the first child of a DOM node. Used internally.
975
+ * @private
976
+ * @name _firstChild(dom)
977
+ * @param {DOMElement} dom
978
+ * @return {DOMElement}
979
+ */
980
+ _firstChild : function (dom) {
981
+ dom = dom ? dom.firstChild : null;
982
+ while(dom !== null && dom.nodeType !== 1) {
983
+ dom = dom.nextSibling;
984
+ }
985
+ return dom;
986
+ },
987
+ /**
988
+ * gets the next sibling of a DOM node. Used internally.
989
+ * @private
990
+ * @name _nextSibling(dom)
991
+ * @param {DOMElement} dom
992
+ * @return {DOMElement}
993
+ */
994
+ _nextSibling : function (dom) {
995
+ dom = dom ? dom.nextSibling : null;
996
+ while(dom !== null && dom.nodeType !== 1) {
997
+ dom = dom.nextSibling;
998
+ }
999
+ return dom;
1000
+ },
1001
+ /**
1002
+ * gets the previous sibling of a DOM node. Used internally.
1003
+ * @private
1004
+ * @name _previousSibling(dom)
1005
+ * @param {DOMElement} dom
1006
+ * @return {DOMElement}
1007
+ */
1008
+ _previousSibling : function (dom) {
1009
+ dom = dom ? dom.previousSibling : null;
1010
+ while(dom !== null && dom.nodeType !== 1) {
1011
+ dom = dom.previousSibling;
1012
+ }
1013
+ return dom;
1014
+ },
1015
+ /**
1016
+ * get the JSON representation of a node (or the actual jQuery extended DOM node) by using any input (child DOM element, ID string, selector, etc)
1017
+ * @name get_node(obj [, as_dom])
1018
+ * @param {mixed} obj
1019
+ * @param {Boolean} as_dom
1020
+ * @return {Object|jQuery}
1021
+ */
1022
+ get_node : function (obj, as_dom) {
1023
+ if(obj && obj.id) {
1024
+ obj = obj.id;
1025
+ }
1026
+ if (obj instanceof jQuery && obj.length && obj[0].id) {
1027
+ obj = obj[0].id;
1028
+ }
1029
+ var dom;
1030
+ try {
1031
+ if(this._model.data[obj]) {
1032
+ obj = this._model.data[obj];
1033
+ }
1034
+ else if(typeof obj === "string" && this._model.data[obj.replace(/^#/, '')]) {
1035
+ obj = this._model.data[obj.replace(/^#/, '')];
1036
+ }
1037
+ else if(typeof obj === "string" && (dom = $('#' + obj.replace($.jstree.idregex,'\\$&'), this.element)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
1038
+ obj = this._model.data[dom.closest('.jstree-node').attr('id')];
1039
+ }
1040
+ else if((dom = this.element.find(obj)).length && this._model.data[dom.closest('.jstree-node').attr('id')]) {
1041
+ obj = this._model.data[dom.closest('.jstree-node').attr('id')];
1042
+ }
1043
+ else if((dom = this.element.find(obj)).length && dom.hasClass('jstree')) {
1044
+ obj = this._model.data[$.jstree.root];
1045
+ }
1046
+ else {
1047
+ return false;
1048
+ }
1049
+
1050
+ if(as_dom) {
1051
+ obj = obj.id === $.jstree.root ? this.element : $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
1052
+ }
1053
+ return obj;
1054
+ } catch (ex) { return false; }
1055
+ },
1056
+ /**
1057
+ * get the path to a node, either consisting of node texts, or of node IDs, optionally glued together (otherwise an array)
1058
+ * @name get_path(obj [, glue, ids])
1059
+ * @param {mixed} obj the node
1060
+ * @param {String} glue if you want the path as a string - pass the glue here (for example '/'), if a falsy value is supplied here, an array is returned
1061
+ * @param {Boolean} ids if set to true build the path using ID, otherwise node text is used
1062
+ * @return {mixed}
1063
+ */
1064
+ get_path : function (obj, glue, ids) {
1065
+ obj = obj.parents ? obj : this.get_node(obj);
1066
+ if(!obj || obj.id === $.jstree.root || !obj.parents) {
1067
+ return false;
1068
+ }
1069
+ var i, j, p = [];
1070
+ p.push(ids ? obj.id : obj.text);
1071
+ for(i = 0, j = obj.parents.length; i < j; i++) {
1072
+ p.push(ids ? obj.parents[i] : this.get_text(obj.parents[i]));
1073
+ }
1074
+ p = p.reverse().slice(1);
1075
+ return glue ? p.join(glue) : p;
1076
+ },
1077
+ /**
1078
+ * get the next visible node that is below the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
1079
+ * @name get_next_dom(obj [, strict])
1080
+ * @param {mixed} obj
1081
+ * @param {Boolean} strict
1082
+ * @return {jQuery}
1083
+ */
1084
+ get_next_dom : function (obj, strict) {
1085
+ var tmp;
1086
+ obj = this.get_node(obj, true);
1087
+ if(obj[0] === this.element[0]) {
1088
+ tmp = this._firstChild(this.get_container_ul()[0]);
1089
+ while (tmp && tmp.offsetHeight === 0) {
1090
+ tmp = this._nextSibling(tmp);
1091
+ }
1092
+ return tmp ? $(tmp) : false;
1093
+ }
1094
+ if(!obj || !obj.length) {
1095
+ return false;
1096
+ }
1097
+ if(strict) {
1098
+ tmp = obj[0];
1099
+ do {
1100
+ tmp = this._nextSibling(tmp);
1101
+ } while (tmp && tmp.offsetHeight === 0);
1102
+ return tmp ? $(tmp) : false;
1103
+ }
1104
+ if(obj.hasClass("jstree-open")) {
1105
+ tmp = this._firstChild(obj.children('.jstree-children')[0]);
1106
+ while (tmp && tmp.offsetHeight === 0) {
1107
+ tmp = this._nextSibling(tmp);
1108
+ }
1109
+ if(tmp !== null) {
1110
+ return $(tmp);
1111
+ }
1112
+ }
1113
+ tmp = obj[0];
1114
+ do {
1115
+ tmp = this._nextSibling(tmp);
1116
+ } while (tmp && tmp.offsetHeight === 0);
1117
+ if(tmp !== null) {
1118
+ return $(tmp);
1119
+ }
1120
+ return obj.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first();
1121
+ },
1122
+ /**
1123
+ * get the previous visible node that is above the `obj` node. If `strict` is set to `true` only sibling nodes are returned.
1124
+ * @name get_prev_dom(obj [, strict])
1125
+ * @param {mixed} obj
1126
+ * @param {Boolean} strict
1127
+ * @return {jQuery}
1128
+ */
1129
+ get_prev_dom : function (obj, strict) {
1130
+ var tmp;
1131
+ obj = this.get_node(obj, true);
1132
+ if(obj[0] === this.element[0]) {
1133
+ tmp = this.get_container_ul()[0].lastChild;
1134
+ while (tmp && tmp.offsetHeight === 0) {
1135
+ tmp = this._previousSibling(tmp);
1136
+ }
1137
+ return tmp ? $(tmp) : false;
1138
+ }
1139
+ if(!obj || !obj.length) {
1140
+ return false;
1141
+ }
1142
+ if(strict) {
1143
+ tmp = obj[0];
1144
+ do {
1145
+ tmp = this._previousSibling(tmp);
1146
+ } while (tmp && tmp.offsetHeight === 0);
1147
+ return tmp ? $(tmp) : false;
1148
+ }
1149
+ tmp = obj[0];
1150
+ do {
1151
+ tmp = this._previousSibling(tmp);
1152
+ } while (tmp && tmp.offsetHeight === 0);
1153
+ if(tmp !== null) {
1154
+ obj = $(tmp);
1155
+ while(obj.hasClass("jstree-open")) {
1156
+ obj = obj.children(".jstree-children").first().children(".jstree-node:visible:last");
1157
+ }
1158
+ return obj;
1159
+ }
1160
+ tmp = obj[0].parentNode.parentNode;
1161
+ return tmp && tmp.className && tmp.className.indexOf('jstree-node') !== -1 ? $(tmp) : false;
1162
+ },
1163
+ /**
1164
+ * get the parent ID of a node
1165
+ * @name get_parent(obj)
1166
+ * @param {mixed} obj
1167
+ * @return {String}
1168
+ */
1169
+ get_parent : function (obj) {
1170
+ obj = this.get_node(obj);
1171
+ if(!obj || obj.id === $.jstree.root) {
1172
+ return false;
1173
+ }
1174
+ return obj.parent;
1175
+ },
1176
+ /**
1177
+ * get a jQuery collection of all the children of a node (node must be rendered), returns false on error
1178
+ * @name get_children_dom(obj)
1179
+ * @param {mixed} obj
1180
+ * @return {jQuery}
1181
+ */
1182
+ get_children_dom : function (obj) {
1183
+ obj = this.get_node(obj, true);
1184
+ if(obj[0] === this.element[0]) {
1185
+ return this.get_container_ul().children(".jstree-node");
1186
+ }
1187
+ if(!obj || !obj.length) {
1188
+ return false;
1189
+ }
1190
+ return obj.children(".jstree-children").children(".jstree-node");
1191
+ },
1192
+ /**
1193
+ * checks if a node has children
1194
+ * @name is_parent(obj)
1195
+ * @param {mixed} obj
1196
+ * @return {Boolean}
1197
+ */
1198
+ is_parent : function (obj) {
1199
+ obj = this.get_node(obj);
1200
+ return obj && (obj.state.loaded === false || obj.children.length > 0);
1201
+ },
1202
+ /**
1203
+ * checks if a node is loaded (its children are available)
1204
+ * @name is_loaded(obj)
1205
+ * @param {mixed} obj
1206
+ * @return {Boolean}
1207
+ */
1208
+ is_loaded : function (obj) {
1209
+ obj = this.get_node(obj);
1210
+ return obj && obj.state.loaded;
1211
+ },
1212
+ /**
1213
+ * check if a node is currently loading (fetching children)
1214
+ * @name is_loading(obj)
1215
+ * @param {mixed} obj
1216
+ * @return {Boolean}
1217
+ */
1218
+ is_loading : function (obj) {
1219
+ obj = this.get_node(obj);
1220
+ return obj && obj.state && obj.state.loading;
1221
+ },
1222
+ /**
1223
+ * check if a node is opened
1224
+ * @name is_open(obj)
1225
+ * @param {mixed} obj
1226
+ * @return {Boolean}
1227
+ */
1228
+ is_open : function (obj) {
1229
+ obj = this.get_node(obj);
1230
+ return obj && obj.state.opened;
1231
+ },
1232
+ /**
1233
+ * check if a node is in a closed state
1234
+ * @name is_closed(obj)
1235
+ * @param {mixed} obj
1236
+ * @return {Boolean}
1237
+ */
1238
+ is_closed : function (obj) {
1239
+ obj = this.get_node(obj);
1240
+ return obj && this.is_parent(obj) && !obj.state.opened;
1241
+ },
1242
+ /**
1243
+ * check if a node has no children
1244
+ * @name is_leaf(obj)
1245
+ * @param {mixed} obj
1246
+ * @return {Boolean}
1247
+ */
1248
+ is_leaf : function (obj) {
1249
+ return !this.is_parent(obj);
1250
+ },
1251
+ /**
1252
+ * loads a node (fetches its children using the `core.data` setting). Multiple nodes can be passed to by using an array.
1253
+ * @name load_node(obj [, callback])
1254
+ * @param {mixed} obj
1255
+ * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives two arguments - the node and a boolean status
1256
+ * @return {Boolean}
1257
+ * @trigger load_node.jstree
1258
+ */
1259
+ load_node : function (obj, callback) {
1260
+ var k, l, i, j, c;
1261
+ if($.isArray(obj)) {
1262
+ this._load_nodes(obj.slice(), callback);
1263
+ return true;
1264
+ }
1265
+ obj = this.get_node(obj);
1266
+ if(!obj) {
1267
+ if(callback) { callback.call(this, obj, false); }
1268
+ return false;
1269
+ }
1270
+ // if(obj.state.loading) { } // the node is already loading - just wait for it to load and invoke callback? but if called implicitly it should be loaded again?
1271
+ if(obj.state.loaded) {
1272
+ obj.state.loaded = false;
1273
+ for(i = 0, j = obj.parents.length; i < j; i++) {
1274
+ this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
1275
+ return $.inArray(v, obj.children_d) === -1;
1276
+ });
1277
+ }
1278
+ for(k = 0, l = obj.children_d.length; k < l; k++) {
1279
+ if(this._model.data[obj.children_d[k]].state.selected) {
1280
+ c = true;
1281
+ }
1282
+ delete this._model.data[obj.children_d[k]];
1283
+ }
1284
+ if (c) {
1285
+ this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
1286
+ return $.inArray(v, obj.children_d) === -1;
1287
+ });
1288
+ }
1289
+ obj.children = [];
1290
+ obj.children_d = [];
1291
+ if(c) {
1292
+ this.trigger('changed', { 'action' : 'load_node', 'node' : obj, 'selected' : this._data.core.selected });
1293
+ }
1294
+ }
1295
+ obj.state.failed = false;
1296
+ obj.state.loading = true;
1297
+ this.get_node(obj, true).addClass("jstree-loading").attr('aria-busy',true);
1298
+ this._load_node(obj, $.proxy(function (status) {
1299
+ obj = this._model.data[obj.id];
1300
+ obj.state.loading = false;
1301
+ obj.state.loaded = status;
1302
+ obj.state.failed = !obj.state.loaded;
1303
+ var dom = this.get_node(obj, true), i = 0, j = 0, m = this._model.data, has_children = false;
1304
+ for(i = 0, j = obj.children.length; i < j; i++) {
1305
+ if(m[obj.children[i]] && !m[obj.children[i]].state.hidden) {
1306
+ has_children = true;
1307
+ break;
1308
+ }
1309
+ }
1310
+ if(obj.state.loaded && dom && dom.length) {
1311
+ dom.removeClass('jstree-closed jstree-open jstree-leaf');
1312
+ if (!has_children) {
1313
+ dom.addClass('jstree-leaf');
1314
+ }
1315
+ else {
1316
+ if (obj.id !== '#') {
1317
+ dom.addClass(obj.state.opened ? 'jstree-open' : 'jstree-closed');
1318
+ }
1319
+ }
1320
+ }
1321
+ dom.removeClass("jstree-loading").attr('aria-busy',false);
1322
+ /**
1323
+ * triggered after a node is loaded
1324
+ * @event
1325
+ * @name load_node.jstree
1326
+ * @param {Object} node the node that was loading
1327
+ * @param {Boolean} status was the node loaded successfully
1328
+ */
1329
+ this.trigger('load_node', { "node" : obj, "status" : status });
1330
+ if(callback) {
1331
+ callback.call(this, obj, status);
1332
+ }
1333
+ }, this));
1334
+ return true;
1335
+ },
1336
+ /**
1337
+ * load an array of nodes (will also load unavailable nodes as soon as they appear in the structure). Used internally.
1338
+ * @private
1339
+ * @name _load_nodes(nodes [, callback])
1340
+ * @param {array} nodes
1341
+ * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives one argument - the array passed to _load_nodes
1342
+ */
1343
+ _load_nodes : function (nodes, callback, is_callback, force_reload) {
1344
+ var r = true,
1345
+ c = function () { this._load_nodes(nodes, callback, true); },
1346
+ m = this._model.data, i, j, tmp = [];
1347
+ for(i = 0, j = nodes.length; i < j; i++) {
1348
+ if(m[nodes[i]] && ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || (!is_callback && force_reload) )) {
1349
+ if(!this.is_loading(nodes[i])) {
1350
+ this.load_node(nodes[i], c);
1351
+ }
1352
+ r = false;
1353
+ }
1354
+ }
1355
+ if(r) {
1356
+ for(i = 0, j = nodes.length; i < j; i++) {
1357
+ if(m[nodes[i]] && m[nodes[i]].state.loaded) {
1358
+ tmp.push(nodes[i]);
1359
+ }
1360
+ }
1361
+ if(callback && !callback.done) {
1362
+ callback.call(this, tmp);
1363
+ callback.done = true;
1364
+ }
1365
+ }
1366
+ },
1367
+ /**
1368
+ * loads all unloaded nodes
1369
+ * @name load_all([obj, callback])
1370
+ * @param {mixed} obj the node to load recursively, omit to load all nodes in the tree
1371
+ * @param {function} callback a function to be executed once loading all the nodes is complete,
1372
+ * @trigger load_all.jstree
1373
+ */
1374
+ load_all : function (obj, callback) {
1375
+ if(!obj) { obj = $.jstree.root; }
1376
+ obj = this.get_node(obj);
1377
+ if(!obj) { return false; }
1378
+ var to_load = [],
1379
+ m = this._model.data,
1380
+ c = m[obj.id].children_d,
1381
+ i, j;
1382
+ if(obj.state && !obj.state.loaded) {
1383
+ to_load.push(obj.id);
1384
+ }
1385
+ for(i = 0, j = c.length; i < j; i++) {
1386
+ if(m[c[i]] && m[c[i]].state && !m[c[i]].state.loaded) {
1387
+ to_load.push(c[i]);
1388
+ }
1389
+ }
1390
+ if(to_load.length) {
1391
+ this._load_nodes(to_load, function () {
1392
+ this.load_all(obj, callback);
1393
+ });
1394
+ }
1395
+ else {
1396
+ /**
1397
+ * triggered after a load_all call completes
1398
+ * @event
1399
+ * @name load_all.jstree
1400
+ * @param {Object} node the recursively loaded node
1401
+ */
1402
+ if(callback) { callback.call(this, obj); }
1403
+ this.trigger('load_all', { "node" : obj });
1404
+ }
1405
+ },
1406
+ /**
1407
+ * handles the actual loading of a node. Used only internally.
1408
+ * @private
1409
+ * @name _load_node(obj [, callback])
1410
+ * @param {mixed} obj
1411
+ * @param {function} callback a function to be executed once loading is complete, the function is executed in the instance's scope and receives one argument - a boolean status
1412
+ * @return {Boolean}
1413
+ */
1414
+ _load_node : function (obj, callback) {
1415
+ var s = this.settings.core.data, t;
1416
+ var notTextOrCommentNode = function notTextOrCommentNode () {
1417
+ return this.nodeType !== 3 && this.nodeType !== 8;
1418
+ };
1419
+ // use original HTML
1420
+ if(!s) {
1421
+ if(obj.id === $.jstree.root) {
1422
+ return this._append_html_data(obj, this._data.core.original_container_html.clone(true), function (status) {
1423
+ callback.call(this, status);
1424
+ });
1425
+ }
1426
+ else {
1427
+ return callback.call(this, false);
1428
+ }
1429
+ // return callback.call(this, obj.id === $.jstree.root ? this._append_html_data(obj, this._data.core.original_container_html.clone(true)) : false);
1430
+ }
1431
+ if($.isFunction(s)) {
1432
+ return s.call(this, obj, $.proxy(function (d) {
1433
+ if(d === false) {
1434
+ callback.call(this, false);
1435
+ }
1436
+ else {
1437
+ this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $($.parseHTML(d)).filter(notTextOrCommentNode) : d, function (status) {
1438
+ callback.call(this, status);
1439
+ });
1440
+ }
1441
+ // return d === false ? callback.call(this, false) : callback.call(this, this[typeof d === 'string' ? '_append_html_data' : '_append_json_data'](obj, typeof d === 'string' ? $(d) : d));
1442
+ }, this));
1443
+ }
1444
+ if(typeof s === 'object') {
1445
+ if(s.url) {
1446
+ s = $.extend(true, {}, s);
1447
+ if($.isFunction(s.url)) {
1448
+ s.url = s.url.call(this, obj);
1449
+ }
1450
+ if($.isFunction(s.data)) {
1451
+ s.data = s.data.call(this, obj);
1452
+ }
1453
+ return $.ajax(s)
1454
+ .done($.proxy(function (d,t,x) {
1455
+ var type = x.getResponseHeader('Content-Type');
1456
+ if((type && type.indexOf('json') !== -1) || typeof d === "object") {
1457
+ return this._append_json_data(obj, d, function (status) { callback.call(this, status); });
1458
+ //return callback.call(this, this._append_json_data(obj, d));
1459
+ }
1460
+ if((type && type.indexOf('html') !== -1) || typeof d === "string") {
1461
+ return this._append_html_data(obj, $($.parseHTML(d)).filter(notTextOrCommentNode), function (status) { callback.call(this, status); });
1462
+ // return callback.call(this, this._append_html_data(obj, $(d)));
1463
+ }
1464
+ this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'core', 'id' : 'core_04', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id, 'xhr' : x }) };
1465
+ this.settings.core.error.call(this, this._data.core.last_error);
1466
+ return callback.call(this, false);
1467
+ }, this))
1468
+ .fail($.proxy(function (f) {
1469
+ this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'core', 'id' : 'core_04', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id, 'xhr' : f }) };
1470
+ callback.call(this, false);
1471
+ this.settings.core.error.call(this, this._data.core.last_error);
1472
+ }, this));
1473
+ }
1474
+ if ($.isArray(s)) {
1475
+ t = $.extend(true, [], s);
1476
+ } else if ($.isPlainObject(s)) {
1477
+ t = $.extend(true, {}, s);
1478
+ } else {
1479
+ t = s;
1480
+ }
1481
+ if(obj.id === $.jstree.root) {
1482
+ return this._append_json_data(obj, t, function (status) {
1483
+ callback.call(this, status);
1484
+ });
1485
+ }
1486
+ else {
1487
+ this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_05', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
1488
+ this.settings.core.error.call(this, this._data.core.last_error);
1489
+ return callback.call(this, false);
1490
+ }
1491
+ //return callback.call(this, (obj.id === $.jstree.root ? this._append_json_data(obj, t) : false) );
1492
+ }
1493
+ if(typeof s === 'string') {
1494
+ if(obj.id === $.jstree.root) {
1495
+ return this._append_html_data(obj, $($.parseHTML(s)).filter(notTextOrCommentNode), function (status) {
1496
+ callback.call(this, status);
1497
+ });
1498
+ }
1499
+ else {
1500
+ this._data.core.last_error = { 'error' : 'nodata', 'plugin' : 'core', 'id' : 'core_06', 'reason' : 'Could not load node', 'data' : JSON.stringify({ 'id' : obj.id }) };
1501
+ this.settings.core.error.call(this, this._data.core.last_error);
1502
+ return callback.call(this, false);
1503
+ }
1504
+ //return callback.call(this, (obj.id === $.jstree.root ? this._append_html_data(obj, $(s)) : false) );
1505
+ }
1506
+ return callback.call(this, false);
1507
+ },
1508
+ /**
1509
+ * adds a node to the list of nodes to redraw. Used only internally.
1510
+ * @private
1511
+ * @name _node_changed(obj [, callback])
1512
+ * @param {mixed} obj
1513
+ */
1514
+ _node_changed : function (obj) {
1515
+ obj = this.get_node(obj);
1516
+ if (obj && $.inArray(obj.id, this._model.changed) === -1) {
1517
+ this._model.changed.push(obj.id);
1518
+ }
1519
+ },
1520
+ /**
1521
+ * appends HTML content to the tree. Used internally.
1522
+ * @private
1523
+ * @name _append_html_data(obj, data)
1524
+ * @param {mixed} obj the node to append to
1525
+ * @param {String} data the HTML string to parse and append
1526
+ * @trigger model.jstree, changed.jstree
1527
+ */
1528
+ _append_html_data : function (dom, data, cb) {
1529
+ dom = this.get_node(dom);
1530
+ dom.children = [];
1531
+ dom.children_d = [];
1532
+ var dat = data.is('ul') ? data.children() : data,
1533
+ par = dom.id,
1534
+ chd = [],
1535
+ dpc = [],
1536
+ m = this._model.data,
1537
+ p = m[par],
1538
+ s = this._data.core.selected.length,
1539
+ tmp, i, j;
1540
+ dat.each($.proxy(function (i, v) {
1541
+ tmp = this._parse_model_from_html($(v), par, p.parents.concat());
1542
+ if(tmp) {
1543
+ chd.push(tmp);
1544
+ dpc.push(tmp);
1545
+ if(m[tmp].children_d.length) {
1546
+ dpc = dpc.concat(m[tmp].children_d);
1547
+ }
1548
+ }
1549
+ }, this));
1550
+ p.children = chd;
1551
+ p.children_d = dpc;
1552
+ for(i = 0, j = p.parents.length; i < j; i++) {
1553
+ m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1554
+ }
1555
+ /**
1556
+ * triggered when new data is inserted to the tree model
1557
+ * @event
1558
+ * @name model.jstree
1559
+ * @param {Array} nodes an array of node IDs
1560
+ * @param {String} parent the parent ID of the nodes
1561
+ */
1562
+ this.trigger('model', { "nodes" : dpc, 'parent' : par });
1563
+ if(par !== $.jstree.root) {
1564
+ this._node_changed(par);
1565
+ this.redraw();
1566
+ }
1567
+ else {
1568
+ this.get_container_ul().children('.jstree-initial-node').remove();
1569
+ this.redraw(true);
1570
+ }
1571
+ if(this._data.core.selected.length !== s) {
1572
+ this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
1573
+ }
1574
+ cb.call(this, true);
1575
+ },
1576
+ /**
1577
+ * appends JSON content to the tree. Used internally.
1578
+ * @private
1579
+ * @name _append_json_data(obj, data)
1580
+ * @param {mixed} obj the node to append to
1581
+ * @param {String} data the JSON object to parse and append
1582
+ * @param {Boolean} force_processing internal param - do not set
1583
+ * @trigger model.jstree, changed.jstree
1584
+ */
1585
+ _append_json_data : function (dom, data, cb, force_processing) {
1586
+ if(this.element === null) { return; }
1587
+ dom = this.get_node(dom);
1588
+ dom.children = [];
1589
+ dom.children_d = [];
1590
+ // *%$@!!!
1591
+ if(data.d) {
1592
+ data = data.d;
1593
+ if(typeof data === "string") {
1594
+ data = JSON.parse(data);
1595
+ }
1596
+ }
1597
+ if(!$.isArray(data)) { data = [data]; }
1598
+ var w = null,
1599
+ args = {
1600
+ 'df' : this._model.default_state,
1601
+ 'dat' : data,
1602
+ 'par' : dom.id,
1603
+ 'm' : this._model.data,
1604
+ 't_id' : this._id,
1605
+ 't_cnt' : this._cnt,
1606
+ 'sel' : this._data.core.selected
1607
+ },
1608
+ func = function (data, undefined) {
1609
+ if(data.data) { data = data.data; }
1610
+ var dat = data.dat,
1611
+ par = data.par,
1612
+ chd = [],
1613
+ dpc = [],
1614
+ add = [],
1615
+ df = data.df,
1616
+ t_id = data.t_id,
1617
+ t_cnt = data.t_cnt,
1618
+ m = data.m,
1619
+ p = m[par],
1620
+ sel = data.sel,
1621
+ tmp, i, j, rslt,
1622
+ parse_flat = function (d, p, ps) {
1623
+ if(!ps) { ps = []; }
1624
+ else { ps = ps.concat(); }
1625
+ if(p) { ps.unshift(p); }
1626
+ var tid = d.id.toString(),
1627
+ i, j, c, e,
1628
+ tmp = {
1629
+ id : tid,
1630
+ text : d.text || '',
1631
+ icon : d.icon !== undefined ? d.icon : true,
1632
+ parent : p,
1633
+ parents : ps,
1634
+ children : d.children || [],
1635
+ children_d : d.children_d || [],
1636
+ data : d.data,
1637
+ state : { },
1638
+ li_attr : { id : false },
1639
+ a_attr : { href : '#' },
1640
+ original : false
1641
+ };
1642
+ for(i in df) {
1643
+ if(df.hasOwnProperty(i)) {
1644
+ tmp.state[i] = df[i];
1645
+ }
1646
+ }
1647
+ if(d && d.data && d.data.jstree && d.data.jstree.icon) {
1648
+ tmp.icon = d.data.jstree.icon;
1649
+ }
1650
+ if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
1651
+ tmp.icon = true;
1652
+ }
1653
+ if(d && d.data) {
1654
+ tmp.data = d.data;
1655
+ if(d.data.jstree) {
1656
+ for(i in d.data.jstree) {
1657
+ if(d.data.jstree.hasOwnProperty(i)) {
1658
+ tmp.state[i] = d.data.jstree[i];
1659
+ }
1660
+ }
1661
+ }
1662
+ }
1663
+ if(d && typeof d.state === 'object') {
1664
+ for (i in d.state) {
1665
+ if(d.state.hasOwnProperty(i)) {
1666
+ tmp.state[i] = d.state[i];
1667
+ }
1668
+ }
1669
+ }
1670
+ if(d && typeof d.li_attr === 'object') {
1671
+ for (i in d.li_attr) {
1672
+ if(d.li_attr.hasOwnProperty(i)) {
1673
+ tmp.li_attr[i] = d.li_attr[i];
1674
+ }
1675
+ }
1676
+ }
1677
+ if(!tmp.li_attr.id) {
1678
+ tmp.li_attr.id = tid;
1679
+ }
1680
+ if(d && typeof d.a_attr === 'object') {
1681
+ for (i in d.a_attr) {
1682
+ if(d.a_attr.hasOwnProperty(i)) {
1683
+ tmp.a_attr[i] = d.a_attr[i];
1684
+ }
1685
+ }
1686
+ }
1687
+ if(d && d.children && d.children === true) {
1688
+ tmp.state.loaded = false;
1689
+ tmp.children = [];
1690
+ tmp.children_d = [];
1691
+ }
1692
+ m[tmp.id] = tmp;
1693
+ for(i = 0, j = tmp.children.length; i < j; i++) {
1694
+ c = parse_flat(m[tmp.children[i]], tmp.id, ps);
1695
+ e = m[c];
1696
+ tmp.children_d.push(c);
1697
+ if(e.children_d.length) {
1698
+ tmp.children_d = tmp.children_d.concat(e.children_d);
1699
+ }
1700
+ }
1701
+ delete d.data;
1702
+ delete d.children;
1703
+ m[tmp.id].original = d;
1704
+ if(tmp.state.selected) {
1705
+ add.push(tmp.id);
1706
+ }
1707
+ return tmp.id;
1708
+ },
1709
+ parse_nest = function (d, p, ps) {
1710
+ if(!ps) { ps = []; }
1711
+ else { ps = ps.concat(); }
1712
+ if(p) { ps.unshift(p); }
1713
+ var tid = false, i, j, c, e, tmp;
1714
+ do {
1715
+ tid = 'j' + t_id + '_' + (++t_cnt);
1716
+ } while(m[tid]);
1717
+
1718
+ tmp = {
1719
+ id : false,
1720
+ text : typeof d === 'string' ? d : '',
1721
+ icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
1722
+ parent : p,
1723
+ parents : ps,
1724
+ children : [],
1725
+ children_d : [],
1726
+ data : null,
1727
+ state : { },
1728
+ li_attr : { id : false },
1729
+ a_attr : { href : '#' },
1730
+ original : false
1731
+ };
1732
+ for(i in df) {
1733
+ if(df.hasOwnProperty(i)) {
1734
+ tmp.state[i] = df[i];
1735
+ }
1736
+ }
1737
+ if(d && d.id) { tmp.id = d.id.toString(); }
1738
+ if(d && d.text) { tmp.text = d.text; }
1739
+ if(d && d.data && d.data.jstree && d.data.jstree.icon) {
1740
+ tmp.icon = d.data.jstree.icon;
1741
+ }
1742
+ if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
1743
+ tmp.icon = true;
1744
+ }
1745
+ if(d && d.data) {
1746
+ tmp.data = d.data;
1747
+ if(d.data.jstree) {
1748
+ for(i in d.data.jstree) {
1749
+ if(d.data.jstree.hasOwnProperty(i)) {
1750
+ tmp.state[i] = d.data.jstree[i];
1751
+ }
1752
+ }
1753
+ }
1754
+ }
1755
+ if(d && typeof d.state === 'object') {
1756
+ for (i in d.state) {
1757
+ if(d.state.hasOwnProperty(i)) {
1758
+ tmp.state[i] = d.state[i];
1759
+ }
1760
+ }
1761
+ }
1762
+ if(d && typeof d.li_attr === 'object') {
1763
+ for (i in d.li_attr) {
1764
+ if(d.li_attr.hasOwnProperty(i)) {
1765
+ tmp.li_attr[i] = d.li_attr[i];
1766
+ }
1767
+ }
1768
+ }
1769
+ if(tmp.li_attr.id && !tmp.id) {
1770
+ tmp.id = tmp.li_attr.id.toString();
1771
+ }
1772
+ if(!tmp.id) {
1773
+ tmp.id = tid;
1774
+ }
1775
+ if(!tmp.li_attr.id) {
1776
+ tmp.li_attr.id = tmp.id;
1777
+ }
1778
+ if(d && typeof d.a_attr === 'object') {
1779
+ for (i in d.a_attr) {
1780
+ if(d.a_attr.hasOwnProperty(i)) {
1781
+ tmp.a_attr[i] = d.a_attr[i];
1782
+ }
1783
+ }
1784
+ }
1785
+ if(d && d.children && d.children.length) {
1786
+ for(i = 0, j = d.children.length; i < j; i++) {
1787
+ c = parse_nest(d.children[i], tmp.id, ps);
1788
+ e = m[c];
1789
+ tmp.children.push(c);
1790
+ if(e.children_d.length) {
1791
+ tmp.children_d = tmp.children_d.concat(e.children_d);
1792
+ }
1793
+ }
1794
+ tmp.children_d = tmp.children_d.concat(tmp.children);
1795
+ }
1796
+ if(d && d.children && d.children === true) {
1797
+ tmp.state.loaded = false;
1798
+ tmp.children = [];
1799
+ tmp.children_d = [];
1800
+ }
1801
+ delete d.data;
1802
+ delete d.children;
1803
+ tmp.original = d;
1804
+ m[tmp.id] = tmp;
1805
+ if(tmp.state.selected) {
1806
+ add.push(tmp.id);
1807
+ }
1808
+ return tmp.id;
1809
+ };
1810
+
1811
+ if(dat.length && dat[0].id !== undefined && dat[0].parent !== undefined) {
1812
+ // Flat JSON support (for easy import from DB):
1813
+ // 1) convert to object (foreach)
1814
+ for(i = 0, j = dat.length; i < j; i++) {
1815
+ if(!dat[i].children) {
1816
+ dat[i].children = [];
1817
+ }
1818
+ if(!dat[i].state) {
1819
+ dat[i].state = {};
1820
+ }
1821
+ m[dat[i].id.toString()] = dat[i];
1822
+ }
1823
+ // 2) populate children (foreach)
1824
+ for(i = 0, j = dat.length; i < j; i++) {
1825
+ if (!m[dat[i].parent.toString()]) {
1826
+ this._data.core.last_error = { 'error' : 'parse', 'plugin' : 'core', 'id' : 'core_07', 'reason' : 'Node with invalid parent', 'data' : JSON.stringify({ 'id' : dat[i].id.toString(), 'parent' : dat[i].parent.toString() }) };
1827
+ this.settings.core.error.call(this, this._data.core.last_error);
1828
+ continue;
1829
+ }
1830
+
1831
+ m[dat[i].parent.toString()].children.push(dat[i].id.toString());
1832
+ // populate parent.children_d
1833
+ p.children_d.push(dat[i].id.toString());
1834
+ }
1835
+ // 3) normalize && populate parents and children_d with recursion
1836
+ for(i = 0, j = p.children.length; i < j; i++) {
1837
+ tmp = parse_flat(m[p.children[i]], par, p.parents.concat());
1838
+ dpc.push(tmp);
1839
+ if(m[tmp].children_d.length) {
1840
+ dpc = dpc.concat(m[tmp].children_d);
1841
+ }
1842
+ }
1843
+ for(i = 0, j = p.parents.length; i < j; i++) {
1844
+ m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1845
+ }
1846
+ // ?) three_state selection - p.state.selected && t - (if three_state foreach(dat => ch) -> foreach(parents) if(parent.selected) child.selected = true;
1847
+ rslt = {
1848
+ 'cnt' : t_cnt,
1849
+ 'mod' : m,
1850
+ 'sel' : sel,
1851
+ 'par' : par,
1852
+ 'dpc' : dpc,
1853
+ 'add' : add
1854
+ };
1855
+ }
1856
+ else {
1857
+ for(i = 0, j = dat.length; i < j; i++) {
1858
+ tmp = parse_nest(dat[i], par, p.parents.concat());
1859
+ if(tmp) {
1860
+ chd.push(tmp);
1861
+ dpc.push(tmp);
1862
+ if(m[tmp].children_d.length) {
1863
+ dpc = dpc.concat(m[tmp].children_d);
1864
+ }
1865
+ }
1866
+ }
1867
+ p.children = chd;
1868
+ p.children_d = dpc;
1869
+ for(i = 0, j = p.parents.length; i < j; i++) {
1870
+ m[p.parents[i]].children_d = m[p.parents[i]].children_d.concat(dpc);
1871
+ }
1872
+ rslt = {
1873
+ 'cnt' : t_cnt,
1874
+ 'mod' : m,
1875
+ 'sel' : sel,
1876
+ 'par' : par,
1877
+ 'dpc' : dpc,
1878
+ 'add' : add
1879
+ };
1880
+ }
1881
+ if(typeof window === 'undefined' || typeof window.document === 'undefined') {
1882
+ postMessage(rslt);
1883
+ }
1884
+ else {
1885
+ return rslt;
1886
+ }
1887
+ },
1888
+ rslt = function (rslt, worker) {
1889
+ if(this.element === null) { return; }
1890
+ this._cnt = rslt.cnt;
1891
+ var i, m = this._model.data;
1892
+ for (i in m) {
1893
+ if (m.hasOwnProperty(i) && m[i].state && m[i].state.loading && rslt.mod[i]) {
1894
+ rslt.mod[i].state.loading = true;
1895
+ }
1896
+ }
1897
+ this._model.data = rslt.mod; // breaks the reference in load_node - careful
1898
+
1899
+ if(worker) {
1900
+ var j, a = rslt.add, r = rslt.sel, s = this._data.core.selected.slice();
1901
+ m = this._model.data;
1902
+ // if selection was changed while calculating in worker
1903
+ if(r.length !== s.length || $.vakata.array_unique(r.concat(s)).length !== r.length) {
1904
+ // deselect nodes that are no longer selected
1905
+ for(i = 0, j = r.length; i < j; i++) {
1906
+ if($.inArray(r[i], a) === -1 && $.inArray(r[i], s) === -1) {
1907
+ m[r[i]].state.selected = false;
1908
+ }
1909
+ }
1910
+ // select nodes that were selected in the mean time
1911
+ for(i = 0, j = s.length; i < j; i++) {
1912
+ if($.inArray(s[i], r) === -1) {
1913
+ m[s[i]].state.selected = true;
1914
+ }
1915
+ }
1916
+ }
1917
+ }
1918
+ if(rslt.add.length) {
1919
+ this._data.core.selected = this._data.core.selected.concat(rslt.add);
1920
+ }
1921
+
1922
+ this.trigger('model', { "nodes" : rslt.dpc, 'parent' : rslt.par });
1923
+
1924
+ if(rslt.par !== $.jstree.root) {
1925
+ this._node_changed(rslt.par);
1926
+ this.redraw();
1927
+ }
1928
+ else {
1929
+ // this.get_container_ul().children('.jstree-initial-node').remove();
1930
+ this.redraw(true);
1931
+ }
1932
+ if(rslt.add.length) {
1933
+ this.trigger('changed', { 'action' : 'model', 'selected' : this._data.core.selected });
1934
+ }
1935
+ cb.call(this, true);
1936
+ };
1937
+ if(this.settings.core.worker && window.Blob && window.URL && window.Worker) {
1938
+ try {
1939
+ if(this._wrk === null) {
1940
+ this._wrk = window.URL.createObjectURL(
1941
+ new window.Blob(
1942
+ ['self.onmessage = ' + func.toString()],
1943
+ {type:"text/javascript"}
1944
+ )
1945
+ );
1946
+ }
1947
+ if(!this._data.core.working || force_processing) {
1948
+ this._data.core.working = true;
1949
+ w = new window.Worker(this._wrk);
1950
+ w.onmessage = $.proxy(function (e) {
1951
+ rslt.call(this, e.data, true);
1952
+ try { w.terminate(); w = null; } catch(ignore) { }
1953
+ if(this._data.core.worker_queue.length) {
1954
+ this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1955
+ }
1956
+ else {
1957
+ this._data.core.working = false;
1958
+ }
1959
+ }, this);
1960
+ if(!args.par) {
1961
+ if(this._data.core.worker_queue.length) {
1962
+ this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1963
+ }
1964
+ else {
1965
+ this._data.core.working = false;
1966
+ }
1967
+ }
1968
+ else {
1969
+ w.postMessage(args);
1970
+ }
1971
+ }
1972
+ else {
1973
+ this._data.core.worker_queue.push([dom, data, cb, true]);
1974
+ }
1975
+ }
1976
+ catch(e) {
1977
+ rslt.call(this, func(args), false);
1978
+ if(this._data.core.worker_queue.length) {
1979
+ this._append_json_data.apply(this, this._data.core.worker_queue.shift());
1980
+ }
1981
+ else {
1982
+ this._data.core.working = false;
1983
+ }
1984
+ }
1985
+ }
1986
+ else {
1987
+ rslt.call(this, func(args), false);
1988
+ }
1989
+ },
1990
+ /**
1991
+ * parses a node from a jQuery object and appends them to the in memory tree model. Used internally.
1992
+ * @private
1993
+ * @name _parse_model_from_html(d [, p, ps])
1994
+ * @param {jQuery} d the jQuery object to parse
1995
+ * @param {String} p the parent ID
1996
+ * @param {Array} ps list of all parents
1997
+ * @return {String} the ID of the object added to the model
1998
+ */
1999
+ _parse_model_from_html : function (d, p, ps) {
2000
+ if(!ps) { ps = []; }
2001
+ else { ps = [].concat(ps); }
2002
+ if(p) { ps.unshift(p); }
2003
+ var c, e, m = this._model.data,
2004
+ data = {
2005
+ id : false,
2006
+ text : false,
2007
+ icon : true,
2008
+ parent : p,
2009
+ parents : ps,
2010
+ children : [],
2011
+ children_d : [],
2012
+ data : null,
2013
+ state : { },
2014
+ li_attr : { id : false },
2015
+ a_attr : { href : '#' },
2016
+ original : false
2017
+ }, i, tmp, tid;
2018
+ for(i in this._model.default_state) {
2019
+ if(this._model.default_state.hasOwnProperty(i)) {
2020
+ data.state[i] = this._model.default_state[i];
2021
+ }
2022
+ }
2023
+ tmp = $.vakata.attributes(d, true);
2024
+ $.each(tmp, function (i, v) {
2025
+ v = $.trim(v);
2026
+ if(!v.length) { return true; }
2027
+ data.li_attr[i] = v;
2028
+ if(i === 'id') {
2029
+ data.id = v.toString();
2030
+ }
2031
+ });
2032
+ tmp = d.children('a').first();
2033
+ if(tmp.length) {
2034
+ tmp = $.vakata.attributes(tmp, true);
2035
+ $.each(tmp, function (i, v) {
2036
+ v = $.trim(v);
2037
+ if(v.length) {
2038
+ data.a_attr[i] = v;
2039
+ }
2040
+ });
2041
+ }
2042
+ tmp = d.children("a").first().length ? d.children("a").first().clone() : d.clone();
2043
+ tmp.children("ins, i, ul").remove();
2044
+ tmp = tmp.html();
2045
+ tmp = $('<div />').html(tmp);
2046
+ data.text = this.settings.core.force_text ? tmp.text() : tmp.html();
2047
+ tmp = d.data();
2048
+ data.data = tmp ? $.extend(true, {}, tmp) : null;
2049
+ data.state.opened = d.hasClass('jstree-open');
2050
+ data.state.selected = d.children('a').hasClass('jstree-clicked');
2051
+ data.state.disabled = d.children('a').hasClass('jstree-disabled');
2052
+ if(data.data && data.data.jstree) {
2053
+ for(i in data.data.jstree) {
2054
+ if(data.data.jstree.hasOwnProperty(i)) {
2055
+ data.state[i] = data.data.jstree[i];
2056
+ }
2057
+ }
2058
+ }
2059
+ tmp = d.children("a").children(".jstree-themeicon");
2060
+ if(tmp.length) {
2061
+ data.icon = tmp.hasClass('jstree-themeicon-hidden') ? false : tmp.attr('rel');
2062
+ }
2063
+ if(data.state.icon !== undefined) {
2064
+ data.icon = data.state.icon;
2065
+ }
2066
+ if(data.icon === undefined || data.icon === null || data.icon === "") {
2067
+ data.icon = true;
2068
+ }
2069
+ tmp = d.children("ul").children("li");
2070
+ do {
2071
+ tid = 'j' + this._id + '_' + (++this._cnt);
2072
+ } while(m[tid]);
2073
+ data.id = data.li_attr.id ? data.li_attr.id.toString() : tid;
2074
+ if(tmp.length) {
2075
+ tmp.each($.proxy(function (i, v) {
2076
+ c = this._parse_model_from_html($(v), data.id, ps);
2077
+ e = this._model.data[c];
2078
+ data.children.push(c);
2079
+ if(e.children_d.length) {
2080
+ data.children_d = data.children_d.concat(e.children_d);
2081
+ }
2082
+ }, this));
2083
+ data.children_d = data.children_d.concat(data.children);
2084
+ }
2085
+ else {
2086
+ if(d.hasClass('jstree-closed')) {
2087
+ data.state.loaded = false;
2088
+ }
2089
+ }
2090
+ if(data.li_attr['class']) {
2091
+ data.li_attr['class'] = data.li_attr['class'].replace('jstree-closed','').replace('jstree-open','');
2092
+ }
2093
+ if(data.a_attr['class']) {
2094
+ data.a_attr['class'] = data.a_attr['class'].replace('jstree-clicked','').replace('jstree-disabled','');
2095
+ }
2096
+ m[data.id] = data;
2097
+ if(data.state.selected) {
2098
+ this._data.core.selected.push(data.id);
2099
+ }
2100
+ return data.id;
2101
+ },
2102
+ /**
2103
+ * parses a node from a JSON object (used when dealing with flat data, which has no nesting of children, but has id and parent properties) and appends it to the in memory tree model. Used internally.
2104
+ * @private
2105
+ * @name _parse_model_from_flat_json(d [, p, ps])
2106
+ * @param {Object} d the JSON object to parse
2107
+ * @param {String} p the parent ID
2108
+ * @param {Array} ps list of all parents
2109
+ * @return {String} the ID of the object added to the model
2110
+ */
2111
+ _parse_model_from_flat_json : function (d, p, ps) {
2112
+ if(!ps) { ps = []; }
2113
+ else { ps = ps.concat(); }
2114
+ if(p) { ps.unshift(p); }
2115
+ var tid = d.id.toString(),
2116
+ m = this._model.data,
2117
+ df = this._model.default_state,
2118
+ i, j, c, e,
2119
+ tmp = {
2120
+ id : tid,
2121
+ text : d.text || '',
2122
+ icon : d.icon !== undefined ? d.icon : true,
2123
+ parent : p,
2124
+ parents : ps,
2125
+ children : d.children || [],
2126
+ children_d : d.children_d || [],
2127
+ data : d.data,
2128
+ state : { },
2129
+ li_attr : { id : false },
2130
+ a_attr : { href : '#' },
2131
+ original : false
2132
+ };
2133
+ for(i in df) {
2134
+ if(df.hasOwnProperty(i)) {
2135
+ tmp.state[i] = df[i];
2136
+ }
2137
+ }
2138
+ if(d && d.data && d.data.jstree && d.data.jstree.icon) {
2139
+ tmp.icon = d.data.jstree.icon;
2140
+ }
2141
+ if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
2142
+ tmp.icon = true;
2143
+ }
2144
+ if(d && d.data) {
2145
+ tmp.data = d.data;
2146
+ if(d.data.jstree) {
2147
+ for(i in d.data.jstree) {
2148
+ if(d.data.jstree.hasOwnProperty(i)) {
2149
+ tmp.state[i] = d.data.jstree[i];
2150
+ }
2151
+ }
2152
+ }
2153
+ }
2154
+ if(d && typeof d.state === 'object') {
2155
+ for (i in d.state) {
2156
+ if(d.state.hasOwnProperty(i)) {
2157
+ tmp.state[i] = d.state[i];
2158
+ }
2159
+ }
2160
+ }
2161
+ if(d && typeof d.li_attr === 'object') {
2162
+ for (i in d.li_attr) {
2163
+ if(d.li_attr.hasOwnProperty(i)) {
2164
+ tmp.li_attr[i] = d.li_attr[i];
2165
+ }
2166
+ }
2167
+ }
2168
+ if(!tmp.li_attr.id) {
2169
+ tmp.li_attr.id = tid;
2170
+ }
2171
+ if(d && typeof d.a_attr === 'object') {
2172
+ for (i in d.a_attr) {
2173
+ if(d.a_attr.hasOwnProperty(i)) {
2174
+ tmp.a_attr[i] = d.a_attr[i];
2175
+ }
2176
+ }
2177
+ }
2178
+ if(d && d.children && d.children === true) {
2179
+ tmp.state.loaded = false;
2180
+ tmp.children = [];
2181
+ tmp.children_d = [];
2182
+ }
2183
+ m[tmp.id] = tmp;
2184
+ for(i = 0, j = tmp.children.length; i < j; i++) {
2185
+ c = this._parse_model_from_flat_json(m[tmp.children[i]], tmp.id, ps);
2186
+ e = m[c];
2187
+ tmp.children_d.push(c);
2188
+ if(e.children_d.length) {
2189
+ tmp.children_d = tmp.children_d.concat(e.children_d);
2190
+ }
2191
+ }
2192
+ delete d.data;
2193
+ delete d.children;
2194
+ m[tmp.id].original = d;
2195
+ if(tmp.state.selected) {
2196
+ this._data.core.selected.push(tmp.id);
2197
+ }
2198
+ return tmp.id;
2199
+ },
2200
+ /**
2201
+ * parses a node from a JSON object and appends it to the in memory tree model. Used internally.
2202
+ * @private
2203
+ * @name _parse_model_from_json(d [, p, ps])
2204
+ * @param {Object} d the JSON object to parse
2205
+ * @param {String} p the parent ID
2206
+ * @param {Array} ps list of all parents
2207
+ * @return {String} the ID of the object added to the model
2208
+ */
2209
+ _parse_model_from_json : function (d, p, ps) {
2210
+ if(!ps) { ps = []; }
2211
+ else { ps = ps.concat(); }
2212
+ if(p) { ps.unshift(p); }
2213
+ var tid = false, i, j, c, e, m = this._model.data, df = this._model.default_state, tmp;
2214
+ do {
2215
+ tid = 'j' + this._id + '_' + (++this._cnt);
2216
+ } while(m[tid]);
2217
+
2218
+ tmp = {
2219
+ id : false,
2220
+ text : typeof d === 'string' ? d : '',
2221
+ icon : typeof d === 'object' && d.icon !== undefined ? d.icon : true,
2222
+ parent : p,
2223
+ parents : ps,
2224
+ children : [],
2225
+ children_d : [],
2226
+ data : null,
2227
+ state : { },
2228
+ li_attr : { id : false },
2229
+ a_attr : { href : '#' },
2230
+ original : false
2231
+ };
2232
+ for(i in df) {
2233
+ if(df.hasOwnProperty(i)) {
2234
+ tmp.state[i] = df[i];
2235
+ }
2236
+ }
2237
+ if(d && d.id) { tmp.id = d.id.toString(); }
2238
+ if(d && d.text) { tmp.text = d.text; }
2239
+ if(d && d.data && d.data.jstree && d.data.jstree.icon) {
2240
+ tmp.icon = d.data.jstree.icon;
2241
+ }
2242
+ if(tmp.icon === undefined || tmp.icon === null || tmp.icon === "") {
2243
+ tmp.icon = true;
2244
+ }
2245
+ if(d && d.data) {
2246
+ tmp.data = d.data;
2247
+ if(d.data.jstree) {
2248
+ for(i in d.data.jstree) {
2249
+ if(d.data.jstree.hasOwnProperty(i)) {
2250
+ tmp.state[i] = d.data.jstree[i];
2251
+ }
2252
+ }
2253
+ }
2254
+ }
2255
+ if(d && typeof d.state === 'object') {
2256
+ for (i in d.state) {
2257
+ if(d.state.hasOwnProperty(i)) {
2258
+ tmp.state[i] = d.state[i];
2259
+ }
2260
+ }
2261
+ }
2262
+ if(d && typeof d.li_attr === 'object') {
2263
+ for (i in d.li_attr) {
2264
+ if(d.li_attr.hasOwnProperty(i)) {
2265
+ tmp.li_attr[i] = d.li_attr[i];
2266
+ }
2267
+ }
2268
+ }
2269
+ if(tmp.li_attr.id && !tmp.id) {
2270
+ tmp.id = tmp.li_attr.id.toString();
2271
+ }
2272
+ if(!tmp.id) {
2273
+ tmp.id = tid;
2274
+ }
2275
+ if(!tmp.li_attr.id) {
2276
+ tmp.li_attr.id = tmp.id;
2277
+ }
2278
+ if(d && typeof d.a_attr === 'object') {
2279
+ for (i in d.a_attr) {
2280
+ if(d.a_attr.hasOwnProperty(i)) {
2281
+ tmp.a_attr[i] = d.a_attr[i];
2282
+ }
2283
+ }
2284
+ }
2285
+ if(d && d.children && d.children.length) {
2286
+ for(i = 0, j = d.children.length; i < j; i++) {
2287
+ c = this._parse_model_from_json(d.children[i], tmp.id, ps);
2288
+ e = m[c];
2289
+ tmp.children.push(c);
2290
+ if(e.children_d.length) {
2291
+ tmp.children_d = tmp.children_d.concat(e.children_d);
2292
+ }
2293
+ }
2294
+ tmp.children_d = tmp.children_d.concat(tmp.children);
2295
+ }
2296
+ if(d && d.children && d.children === true) {
2297
+ tmp.state.loaded = false;
2298
+ tmp.children = [];
2299
+ tmp.children_d = [];
2300
+ }
2301
+ delete d.data;
2302
+ delete d.children;
2303
+ tmp.original = d;
2304
+ m[tmp.id] = tmp;
2305
+ if(tmp.state.selected) {
2306
+ this._data.core.selected.push(tmp.id);
2307
+ }
2308
+ return tmp.id;
2309
+ },
2310
+ /**
2311
+ * redraws all nodes that need to be redrawn. Used internally.
2312
+ * @private
2313
+ * @name _redraw()
2314
+ * @trigger redraw.jstree
2315
+ */
2316
+ _redraw : function () {
2317
+ var nodes = this._model.force_full_redraw ? this._model.data[$.jstree.root].children.concat([]) : this._model.changed.concat([]),
2318
+ f = document.createElement('UL'), tmp, i, j, fe = this._data.core.focused;
2319
+ for(i = 0, j = nodes.length; i < j; i++) {
2320
+ tmp = this.redraw_node(nodes[i], true, this._model.force_full_redraw);
2321
+ if(tmp && this._model.force_full_redraw) {
2322
+ f.appendChild(tmp);
2323
+ }
2324
+ }
2325
+ if(this._model.force_full_redraw) {
2326
+ f.className = this.get_container_ul()[0].className;
2327
+ f.setAttribute('role','group');
2328
+ this.element.empty().append(f);
2329
+ //this.get_container_ul()[0].appendChild(f);
2330
+ }
2331
+ if(fe !== null && this.settings.core.restore_focus) {
2332
+ tmp = this.get_node(fe, true);
2333
+ if(tmp && tmp.length && tmp.children('.jstree-anchor')[0] !== document.activeElement) {
2334
+ tmp.children('.jstree-anchor').focus();
2335
+ }
2336
+ else {
2337
+ this._data.core.focused = null;
2338
+ }
2339
+ }
2340
+ this._model.force_full_redraw = false;
2341
+ this._model.changed = [];
2342
+ /**
2343
+ * triggered after nodes are redrawn
2344
+ * @event
2345
+ * @name redraw.jstree
2346
+ * @param {array} nodes the redrawn nodes
2347
+ */
2348
+ this.trigger('redraw', { "nodes" : nodes });
2349
+ },
2350
+ /**
2351
+ * redraws all nodes that need to be redrawn or optionally - the whole tree
2352
+ * @name redraw([full])
2353
+ * @param {Boolean} full if set to `true` all nodes are redrawn.
2354
+ */
2355
+ redraw : function (full) {
2356
+ if(full) {
2357
+ this._model.force_full_redraw = true;
2358
+ }
2359
+ //if(this._model.redraw_timeout) {
2360
+ // clearTimeout(this._model.redraw_timeout);
2361
+ //}
2362
+ //this._model.redraw_timeout = setTimeout($.proxy(this._redraw, this),0);
2363
+ this._redraw();
2364
+ },
2365
+ /**
2366
+ * redraws a single node's children. Used internally.
2367
+ * @private
2368
+ * @name draw_children(node)
2369
+ * @param {mixed} node the node whose children will be redrawn
2370
+ */
2371
+ draw_children : function (node) {
2372
+ var obj = this.get_node(node),
2373
+ i = false,
2374
+ j = false,
2375
+ k = false,
2376
+ d = document;
2377
+ if(!obj) { return false; }
2378
+ if(obj.id === $.jstree.root) { return this.redraw(true); }
2379
+ node = this.get_node(node, true);
2380
+ if(!node || !node.length) { return false; } // TODO: quick toggle
2381
+
2382
+ node.children('.jstree-children').remove();
2383
+ node = node[0];
2384
+ if(obj.children.length && obj.state.loaded) {
2385
+ k = d.createElement('UL');
2386
+ k.setAttribute('role', 'group');
2387
+ k.className = 'jstree-children';
2388
+ for(i = 0, j = obj.children.length; i < j; i++) {
2389
+ k.appendChild(this.redraw_node(obj.children[i], true, true));
2390
+ }
2391
+ node.appendChild(k);
2392
+ }
2393
+ },
2394
+ /**
2395
+ * redraws a single node. Used internally.
2396
+ * @private
2397
+ * @name redraw_node(node, deep, is_callback, force_render)
2398
+ * @param {mixed} node the node to redraw
2399
+ * @param {Boolean} deep should child nodes be redrawn too
2400
+ * @param {Boolean} is_callback is this a recursion call
2401
+ * @param {Boolean} force_render should children of closed parents be drawn anyway
2402
+ */
2403
+ redraw_node : function (node, deep, is_callback, force_render) {
2404
+ var obj = this.get_node(node),
2405
+ par = false,
2406
+ ind = false,
2407
+ old = false,
2408
+ i = false,
2409
+ j = false,
2410
+ k = false,
2411
+ c = '',
2412
+ d = document,
2413
+ m = this._model.data,
2414
+ f = false,
2415
+ s = false,
2416
+ tmp = null,
2417
+ t = 0,
2418
+ l = 0,
2419
+ has_children = false,
2420
+ last_sibling = false;
2421
+ if(!obj) { return false; }
2422
+ if(obj.id === $.jstree.root) { return this.redraw(true); }
2423
+ deep = deep || obj.children.length === 0;
2424
+ node = !document.querySelector ? document.getElementById(obj.id) : this.element[0].querySelector('#' + ("0123456789".indexOf(obj.id[0]) !== -1 ? '\\3' + obj.id[0] + ' ' + obj.id.substr(1).replace($.jstree.idregex,'\\$&') : obj.id.replace($.jstree.idregex,'\\$&')) ); //, this.element);
2425
+ if(!node) {
2426
+ deep = true;
2427
+ //node = d.createElement('LI');
2428
+ if(!is_callback) {
2429
+ par = obj.parent !== $.jstree.root ? $('#' + obj.parent.replace($.jstree.idregex,'\\$&'), this.element)[0] : null;
2430
+ if(par !== null && (!par || !m[obj.parent].state.opened)) {
2431
+ return false;
2432
+ }
2433
+ ind = $.inArray(obj.id, par === null ? m[$.jstree.root].children : m[obj.parent].children);
2434
+ }
2435
+ }
2436
+ else {
2437
+ node = $(node);
2438
+ if(!is_callback) {
2439
+ par = node.parent().parent()[0];
2440
+ if(par === this.element[0]) {
2441
+ par = null;
2442
+ }
2443
+ ind = node.index();
2444
+ }
2445
+ // m[obj.id].data = node.data(); // use only node's data, no need to touch jquery storage
2446
+ if(!deep && obj.children.length && !node.children('.jstree-children').length) {
2447
+ deep = true;
2448
+ }
2449
+ if(!deep) {
2450
+ old = node.children('.jstree-children')[0];
2451
+ }
2452
+ f = node.children('.jstree-anchor')[0] === document.activeElement;
2453
+ node.remove();
2454
+ //node = d.createElement('LI');
2455
+ //node = node[0];
2456
+ }
2457
+ node = this._data.core.node.cloneNode(true);
2458
+ // node is DOM, deep is boolean
2459
+
2460
+ c = 'jstree-node ';
2461
+ for(i in obj.li_attr) {
2462
+ if(obj.li_attr.hasOwnProperty(i)) {
2463
+ if(i === 'id') { continue; }
2464
+ if(i !== 'class') {
2465
+ node.setAttribute(i, obj.li_attr[i]);
2466
+ }
2467
+ else {
2468
+ c += obj.li_attr[i];
2469
+ }
2470
+ }
2471
+ }
2472
+ if(!obj.a_attr.id) {
2473
+ obj.a_attr.id = obj.id + '_anchor';
2474
+ }
2475
+ node.setAttribute('aria-selected', !!obj.state.selected);
2476
+ node.setAttribute('aria-level', obj.parents.length);
2477
+ node.setAttribute('aria-labelledby', obj.a_attr.id);
2478
+ if(obj.state.disabled) {
2479
+ node.setAttribute('aria-disabled', true);
2480
+ }
2481
+
2482
+ for(i = 0, j = obj.children.length; i < j; i++) {
2483
+ if(!m[obj.children[i]].state.hidden) {
2484
+ has_children = true;
2485
+ break;
2486
+ }
2487
+ }
2488
+ if(obj.parent !== null && m[obj.parent] && !obj.state.hidden) {
2489
+ i = $.inArray(obj.id, m[obj.parent].children);
2490
+ last_sibling = obj.id;
2491
+ if(i !== -1) {
2492
+ i++;
2493
+ for(j = m[obj.parent].children.length; i < j; i++) {
2494
+ if(!m[m[obj.parent].children[i]].state.hidden) {
2495
+ last_sibling = m[obj.parent].children[i];
2496
+ }
2497
+ if(last_sibling !== obj.id) {
2498
+ break;
2499
+ }
2500
+ }
2501
+ }
2502
+ }
2503
+
2504
+ if(obj.state.hidden) {
2505
+ c += ' jstree-hidden';
2506
+ }
2507
+ if (obj.state.loading) {
2508
+ c += ' jstree-loading';
2509
+ }
2510
+ if(obj.state.loaded && !has_children) {
2511
+ c += ' jstree-leaf';
2512
+ }
2513
+ else {
2514
+ c += obj.state.opened && obj.state.loaded ? ' jstree-open' : ' jstree-closed';
2515
+ node.setAttribute('aria-expanded', (obj.state.opened && obj.state.loaded) );
2516
+ }
2517
+ if(last_sibling === obj.id) {
2518
+ c += ' jstree-last';
2519
+ }
2520
+ node.id = obj.id;
2521
+ node.className = c;
2522
+ c = ( obj.state.selected ? ' jstree-clicked' : '') + ( obj.state.disabled ? ' jstree-disabled' : '');
2523
+ for(j in obj.a_attr) {
2524
+ if(obj.a_attr.hasOwnProperty(j)) {
2525
+ if(j === 'href' && obj.a_attr[j] === '#') { continue; }
2526
+ if(j !== 'class') {
2527
+ node.childNodes[1].setAttribute(j, obj.a_attr[j]);
2528
+ }
2529
+ else {
2530
+ c += ' ' + obj.a_attr[j];
2531
+ }
2532
+ }
2533
+ }
2534
+ if(c.length) {
2535
+ node.childNodes[1].className = 'jstree-anchor ' + c;
2536
+ }
2537
+ if((obj.icon && obj.icon !== true) || obj.icon === false) {
2538
+ if(obj.icon === false) {
2539
+ node.childNodes[1].childNodes[0].className += ' jstree-themeicon-hidden';
2540
+ }
2541
+ else if(obj.icon.indexOf('/') === -1 && obj.icon.indexOf('.') === -1) {
2542
+ node.childNodes[1].childNodes[0].className += ' ' + obj.icon + ' jstree-themeicon-custom';
2543
+ }
2544
+ else {
2545
+ node.childNodes[1].childNodes[0].style.backgroundImage = 'url("'+obj.icon+'")';
2546
+ node.childNodes[1].childNodes[0].style.backgroundPosition = 'center center';
2547
+ node.childNodes[1].childNodes[0].style.backgroundSize = 'auto';
2548
+ node.childNodes[1].childNodes[0].className += ' jstree-themeicon-custom';
2549
+ }
2550
+ }
2551
+
2552
+ if(this.settings.core.force_text) {
2553
+ node.childNodes[1].appendChild(d.createTextNode(obj.text));
2554
+ }
2555
+ else {
2556
+ node.childNodes[1].innerHTML += obj.text;
2557
+ }
2558
+
2559
+
2560
+ if(deep && obj.children.length && (obj.state.opened || force_render) && obj.state.loaded) {
2561
+ k = d.createElement('UL');
2562
+ k.setAttribute('role', 'group');
2563
+ k.className = 'jstree-children';
2564
+ for(i = 0, j = obj.children.length; i < j; i++) {
2565
+ k.appendChild(this.redraw_node(obj.children[i], deep, true));
2566
+ }
2567
+ node.appendChild(k);
2568
+ }
2569
+ if(old) {
2570
+ node.appendChild(old);
2571
+ }
2572
+ if(!is_callback) {
2573
+ // append back using par / ind
2574
+ if(!par) {
2575
+ par = this.element[0];
2576
+ }
2577
+ for(i = 0, j = par.childNodes.length; i < j; i++) {
2578
+ if(par.childNodes[i] && par.childNodes[i].className && par.childNodes[i].className.indexOf('jstree-children') !== -1) {
2579
+ tmp = par.childNodes[i];
2580
+ break;
2581
+ }
2582
+ }
2583
+ if(!tmp) {
2584
+ tmp = d.createElement('UL');
2585
+ tmp.setAttribute('role', 'group');
2586
+ tmp.className = 'jstree-children';
2587
+ par.appendChild(tmp);
2588
+ }
2589
+ par = tmp;
2590
+
2591
+ if(ind < par.childNodes.length) {
2592
+ par.insertBefore(node, par.childNodes[ind]);
2593
+ }
2594
+ else {
2595
+ par.appendChild(node);
2596
+ }
2597
+ if(f) {
2598
+ t = this.element[0].scrollTop;
2599
+ l = this.element[0].scrollLeft;
2600
+ node.childNodes[1].focus();
2601
+ this.element[0].scrollTop = t;
2602
+ this.element[0].scrollLeft = l;
2603
+ }
2604
+ }
2605
+ if(obj.state.opened && !obj.state.loaded) {
2606
+ obj.state.opened = false;
2607
+ setTimeout($.proxy(function () {
2608
+ this.open_node(obj.id, false, 0);
2609
+ }, this), 0);
2610
+ }
2611
+ return node;
2612
+ },
2613
+ /**
2614
+ * opens a node, revealing its children. If the node is not loaded it will be loaded and opened once ready.
2615
+ * @name open_node(obj [, callback, animation])
2616
+ * @param {mixed} obj the node to open
2617
+ * @param {Function} callback a function to execute once the node is opened
2618
+ * @param {Number} animation the animation duration in milliseconds when opening the node (overrides the `core.animation` setting). Use `false` for no animation.
2619
+ * @trigger open_node.jstree, after_open.jstree, before_open.jstree
2620
+ */
2621
+ open_node : function (obj, callback, animation) {
2622
+ var t1, t2, d, t;
2623
+ if($.isArray(obj)) {
2624
+ obj = obj.slice();
2625
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2626
+ this.open_node(obj[t1], callback, animation);
2627
+ }
2628
+ return true;
2629
+ }
2630
+ obj = this.get_node(obj);
2631
+ if(!obj || obj.id === $.jstree.root) {
2632
+ return false;
2633
+ }
2634
+ animation = animation === undefined ? this.settings.core.animation : animation;
2635
+ if(!this.is_closed(obj)) {
2636
+ if(callback) {
2637
+ callback.call(this, obj, false);
2638
+ }
2639
+ return false;
2640
+ }
2641
+ if(!this.is_loaded(obj)) {
2642
+ if(this.is_loading(obj)) {
2643
+ return setTimeout($.proxy(function () {
2644
+ this.open_node(obj, callback, animation);
2645
+ }, this), 500);
2646
+ }
2647
+ this.load_node(obj, function (o, ok) {
2648
+ return ok ? this.open_node(o, callback, animation) : (callback ? callback.call(this, o, false) : false);
2649
+ });
2650
+ }
2651
+ else {
2652
+ d = this.get_node(obj, true);
2653
+ t = this;
2654
+ if(d.length) {
2655
+ if(animation && d.children(".jstree-children").length) {
2656
+ d.children(".jstree-children").stop(true, true);
2657
+ }
2658
+ if(obj.children.length && !this._firstChild(d.children('.jstree-children')[0])) {
2659
+ this.draw_children(obj);
2660
+ //d = this.get_node(obj, true);
2661
+ }
2662
+ if(!animation) {
2663
+ this.trigger('before_open', { "node" : obj });
2664
+ d[0].className = d[0].className.replace('jstree-closed', 'jstree-open');
2665
+ d[0].setAttribute("aria-expanded", true);
2666
+ }
2667
+ else {
2668
+ this.trigger('before_open', { "node" : obj });
2669
+ d
2670
+ .children(".jstree-children").css("display","none").end()
2671
+ .removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded", true)
2672
+ .children(".jstree-children").stop(true, true)
2673
+ .slideDown(animation, function () {
2674
+ this.style.display = "";
2675
+ if (t.element) {
2676
+ t.trigger("after_open", { "node" : obj });
2677
+ }
2678
+ });
2679
+ }
2680
+ }
2681
+ obj.state.opened = true;
2682
+ if(callback) {
2683
+ callback.call(this, obj, true);
2684
+ }
2685
+ if(!d.length) {
2686
+ /**
2687
+ * triggered when a node is about to be opened (if the node is supposed to be in the DOM, it will be, but it won't be visible yet)
2688
+ * @event
2689
+ * @name before_open.jstree
2690
+ * @param {Object} node the opened node
2691
+ */
2692
+ this.trigger('before_open', { "node" : obj });
2693
+ }
2694
+ /**
2695
+ * triggered when a node is opened (if there is an animation it will not be completed yet)
2696
+ * @event
2697
+ * @name open_node.jstree
2698
+ * @param {Object} node the opened node
2699
+ */
2700
+ this.trigger('open_node', { "node" : obj });
2701
+ if(!animation || !d.length) {
2702
+ /**
2703
+ * triggered when a node is opened and the animation is complete
2704
+ * @event
2705
+ * @name after_open.jstree
2706
+ * @param {Object} node the opened node
2707
+ */
2708
+ this.trigger("after_open", { "node" : obj });
2709
+ }
2710
+ return true;
2711
+ }
2712
+ },
2713
+ /**
2714
+ * opens every parent of a node (node should be loaded)
2715
+ * @name _open_to(obj)
2716
+ * @param {mixed} obj the node to reveal
2717
+ * @private
2718
+ */
2719
+ _open_to : function (obj) {
2720
+ obj = this.get_node(obj);
2721
+ if(!obj || obj.id === $.jstree.root) {
2722
+ return false;
2723
+ }
2724
+ var i, j, p = obj.parents;
2725
+ for(i = 0, j = p.length; i < j; i+=1) {
2726
+ if(i !== $.jstree.root) {
2727
+ this.open_node(p[i], false, 0);
2728
+ }
2729
+ }
2730
+ return $('#' + obj.id.replace($.jstree.idregex,'\\$&'), this.element);
2731
+ },
2732
+ /**
2733
+ * closes a node, hiding its children
2734
+ * @name close_node(obj [, animation])
2735
+ * @param {mixed} obj the node to close
2736
+ * @param {Number} animation the animation duration in milliseconds when closing the node (overrides the `core.animation` setting). Use `false` for no animation.
2737
+ * @trigger close_node.jstree, after_close.jstree
2738
+ */
2739
+ close_node : function (obj, animation) {
2740
+ var t1, t2, t, d;
2741
+ if($.isArray(obj)) {
2742
+ obj = obj.slice();
2743
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2744
+ this.close_node(obj[t1], animation);
2745
+ }
2746
+ return true;
2747
+ }
2748
+ obj = this.get_node(obj);
2749
+ if(!obj || obj.id === $.jstree.root) {
2750
+ return false;
2751
+ }
2752
+ if(this.is_closed(obj)) {
2753
+ return false;
2754
+ }
2755
+ animation = animation === undefined ? this.settings.core.animation : animation;
2756
+ t = this;
2757
+ d = this.get_node(obj, true);
2758
+
2759
+ obj.state.opened = false;
2760
+ /**
2761
+ * triggered when a node is closed (if there is an animation it will not be complete yet)
2762
+ * @event
2763
+ * @name close_node.jstree
2764
+ * @param {Object} node the closed node
2765
+ */
2766
+ this.trigger('close_node',{ "node" : obj });
2767
+ if(!d.length) {
2768
+ /**
2769
+ * triggered when a node is closed and the animation is complete
2770
+ * @event
2771
+ * @name after_close.jstree
2772
+ * @param {Object} node the closed node
2773
+ */
2774
+ this.trigger("after_close", { "node" : obj });
2775
+ }
2776
+ else {
2777
+ if(!animation) {
2778
+ d[0].className = d[0].className.replace('jstree-open', 'jstree-closed');
2779
+ d.attr("aria-expanded", false).children('.jstree-children').remove();
2780
+ this.trigger("after_close", { "node" : obj });
2781
+ }
2782
+ else {
2783
+ d
2784
+ .children(".jstree-children").attr("style","display:block !important").end()
2785
+ .removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded", false)
2786
+ .children(".jstree-children").stop(true, true).slideUp(animation, function () {
2787
+ this.style.display = "";
2788
+ d.children('.jstree-children').remove();
2789
+ if (t.element) {
2790
+ t.trigger("after_close", { "node" : obj });
2791
+ }
2792
+ });
2793
+ }
2794
+ }
2795
+ },
2796
+ /**
2797
+ * toggles a node - closing it if it is open, opening it if it is closed
2798
+ * @name toggle_node(obj)
2799
+ * @param {mixed} obj the node to toggle
2800
+ */
2801
+ toggle_node : function (obj) {
2802
+ var t1, t2;
2803
+ if($.isArray(obj)) {
2804
+ obj = obj.slice();
2805
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2806
+ this.toggle_node(obj[t1]);
2807
+ }
2808
+ return true;
2809
+ }
2810
+ if(this.is_closed(obj)) {
2811
+ return this.open_node(obj);
2812
+ }
2813
+ if(this.is_open(obj)) {
2814
+ return this.close_node(obj);
2815
+ }
2816
+ },
2817
+ /**
2818
+ * opens all nodes within a node (or the tree), revealing their children. If the node is not loaded it will be loaded and opened once ready.
2819
+ * @name open_all([obj, animation, original_obj])
2820
+ * @param {mixed} obj the node to open recursively, omit to open all nodes in the tree
2821
+ * @param {Number} animation the animation duration in milliseconds when opening the nodes, the default is no animation
2822
+ * @param {jQuery} reference to the node that started the process (internal use)
2823
+ * @trigger open_all.jstree
2824
+ */
2825
+ open_all : function (obj, animation, original_obj) {
2826
+ if(!obj) { obj = $.jstree.root; }
2827
+ obj = this.get_node(obj);
2828
+ if(!obj) { return false; }
2829
+ var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true), i, j, _this;
2830
+ if(!dom.length) {
2831
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
2832
+ if(this.is_closed(this._model.data[obj.children_d[i]])) {
2833
+ this._model.data[obj.children_d[i]].state.opened = true;
2834
+ }
2835
+ }
2836
+ return this.trigger('open_all', { "node" : obj });
2837
+ }
2838
+ original_obj = original_obj || dom;
2839
+ _this = this;
2840
+ dom = this.is_closed(obj) ? dom.find('.jstree-closed').addBack() : dom.find('.jstree-closed');
2841
+ dom.each(function () {
2842
+ _this.open_node(
2843
+ this,
2844
+ function(node, status) { if(status && this.is_parent(node)) { this.open_all(node, animation, original_obj); } },
2845
+ animation || 0
2846
+ );
2847
+ });
2848
+ if(original_obj.find('.jstree-closed').length === 0) {
2849
+ /**
2850
+ * triggered when an `open_all` call completes
2851
+ * @event
2852
+ * @name open_all.jstree
2853
+ * @param {Object} node the opened node
2854
+ */
2855
+ this.trigger('open_all', { "node" : this.get_node(original_obj) });
2856
+ }
2857
+ },
2858
+ /**
2859
+ * closes all nodes within a node (or the tree), revealing their children
2860
+ * @name close_all([obj, animation])
2861
+ * @param {mixed} obj the node to close recursively, omit to close all nodes in the tree
2862
+ * @param {Number} animation the animation duration in milliseconds when closing the nodes, the default is no animation
2863
+ * @trigger close_all.jstree
2864
+ */
2865
+ close_all : function (obj, animation) {
2866
+ if(!obj) { obj = $.jstree.root; }
2867
+ obj = this.get_node(obj);
2868
+ if(!obj) { return false; }
2869
+ var dom = obj.id === $.jstree.root ? this.get_container_ul() : this.get_node(obj, true),
2870
+ _this = this, i, j;
2871
+ if(dom.length) {
2872
+ dom = this.is_open(obj) ? dom.find('.jstree-open').addBack() : dom.find('.jstree-open');
2873
+ $(dom.get().reverse()).each(function () { _this.close_node(this, animation || 0); });
2874
+ }
2875
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
2876
+ this._model.data[obj.children_d[i]].state.opened = false;
2877
+ }
2878
+ /**
2879
+ * triggered when an `close_all` call completes
2880
+ * @event
2881
+ * @name close_all.jstree
2882
+ * @param {Object} node the closed node
2883
+ */
2884
+ this.trigger('close_all', { "node" : obj });
2885
+ },
2886
+ /**
2887
+ * checks if a node is disabled (not selectable)
2888
+ * @name is_disabled(obj)
2889
+ * @param {mixed} obj
2890
+ * @return {Boolean}
2891
+ */
2892
+ is_disabled : function (obj) {
2893
+ obj = this.get_node(obj);
2894
+ return obj && obj.state && obj.state.disabled;
2895
+ },
2896
+ /**
2897
+ * enables a node - so that it can be selected
2898
+ * @name enable_node(obj)
2899
+ * @param {mixed} obj the node to enable
2900
+ * @trigger enable_node.jstree
2901
+ */
2902
+ enable_node : function (obj) {
2903
+ var t1, t2;
2904
+ if($.isArray(obj)) {
2905
+ obj = obj.slice();
2906
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2907
+ this.enable_node(obj[t1]);
2908
+ }
2909
+ return true;
2910
+ }
2911
+ obj = this.get_node(obj);
2912
+ if(!obj || obj.id === $.jstree.root) {
2913
+ return false;
2914
+ }
2915
+ obj.state.disabled = false;
2916
+ this.get_node(obj,true).children('.jstree-anchor').removeClass('jstree-disabled').attr('aria-disabled', false);
2917
+ /**
2918
+ * triggered when an node is enabled
2919
+ * @event
2920
+ * @name enable_node.jstree
2921
+ * @param {Object} node the enabled node
2922
+ */
2923
+ this.trigger('enable_node', { 'node' : obj });
2924
+ },
2925
+ /**
2926
+ * disables a node - so that it can not be selected
2927
+ * @name disable_node(obj)
2928
+ * @param {mixed} obj the node to disable
2929
+ * @trigger disable_node.jstree
2930
+ */
2931
+ disable_node : function (obj) {
2932
+ var t1, t2;
2933
+ if($.isArray(obj)) {
2934
+ obj = obj.slice();
2935
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2936
+ this.disable_node(obj[t1]);
2937
+ }
2938
+ return true;
2939
+ }
2940
+ obj = this.get_node(obj);
2941
+ if(!obj || obj.id === $.jstree.root) {
2942
+ return false;
2943
+ }
2944
+ obj.state.disabled = true;
2945
+ this.get_node(obj,true).children('.jstree-anchor').addClass('jstree-disabled').attr('aria-disabled', true);
2946
+ /**
2947
+ * triggered when an node is disabled
2948
+ * @event
2949
+ * @name disable_node.jstree
2950
+ * @param {Object} node the disabled node
2951
+ */
2952
+ this.trigger('disable_node', { 'node' : obj });
2953
+ },
2954
+ /**
2955
+ * determines if a node is hidden
2956
+ * @name is_hidden(obj)
2957
+ * @param {mixed} obj the node
2958
+ */
2959
+ is_hidden : function (obj) {
2960
+ obj = this.get_node(obj);
2961
+ return obj.state.hidden === true;
2962
+ },
2963
+ /**
2964
+ * hides a node - it is still in the structure but will not be visible
2965
+ * @name hide_node(obj)
2966
+ * @param {mixed} obj the node to hide
2967
+ * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
2968
+ * @trigger hide_node.jstree
2969
+ */
2970
+ hide_node : function (obj, skip_redraw) {
2971
+ var t1, t2;
2972
+ if($.isArray(obj)) {
2973
+ obj = obj.slice();
2974
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
2975
+ this.hide_node(obj[t1], true);
2976
+ }
2977
+ if (!skip_redraw) {
2978
+ this.redraw();
2979
+ }
2980
+ return true;
2981
+ }
2982
+ obj = this.get_node(obj);
2983
+ if(!obj || obj.id === $.jstree.root) {
2984
+ return false;
2985
+ }
2986
+ if(!obj.state.hidden) {
2987
+ obj.state.hidden = true;
2988
+ this._node_changed(obj.parent);
2989
+ if(!skip_redraw) {
2990
+ this.redraw();
2991
+ }
2992
+ /**
2993
+ * triggered when an node is hidden
2994
+ * @event
2995
+ * @name hide_node.jstree
2996
+ * @param {Object} node the hidden node
2997
+ */
2998
+ this.trigger('hide_node', { 'node' : obj });
2999
+ }
3000
+ },
3001
+ /**
3002
+ * shows a node
3003
+ * @name show_node(obj)
3004
+ * @param {mixed} obj the node to show
3005
+ * @param {Boolean} skip_redraw internal parameter controlling if redraw is called
3006
+ * @trigger show_node.jstree
3007
+ */
3008
+ show_node : function (obj, skip_redraw) {
3009
+ var t1, t2;
3010
+ if($.isArray(obj)) {
3011
+ obj = obj.slice();
3012
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3013
+ this.show_node(obj[t1], true);
3014
+ }
3015
+ if (!skip_redraw) {
3016
+ this.redraw();
3017
+ }
3018
+ return true;
3019
+ }
3020
+ obj = this.get_node(obj);
3021
+ if(!obj || obj.id === $.jstree.root) {
3022
+ return false;
3023
+ }
3024
+ if(obj.state.hidden) {
3025
+ obj.state.hidden = false;
3026
+ this._node_changed(obj.parent);
3027
+ if(!skip_redraw) {
3028
+ this.redraw();
3029
+ }
3030
+ /**
3031
+ * triggered when an node is shown
3032
+ * @event
3033
+ * @name show_node.jstree
3034
+ * @param {Object} node the shown node
3035
+ */
3036
+ this.trigger('show_node', { 'node' : obj });
3037
+ }
3038
+ },
3039
+ /**
3040
+ * hides all nodes
3041
+ * @name hide_all()
3042
+ * @trigger hide_all.jstree
3043
+ */
3044
+ hide_all : function (skip_redraw) {
3045
+ var i, m = this._model.data, ids = [];
3046
+ for(i in m) {
3047
+ if(m.hasOwnProperty(i) && i !== $.jstree.root && !m[i].state.hidden) {
3048
+ m[i].state.hidden = true;
3049
+ ids.push(i);
3050
+ }
3051
+ }
3052
+ this._model.force_full_redraw = true;
3053
+ if(!skip_redraw) {
3054
+ this.redraw();
3055
+ }
3056
+ /**
3057
+ * triggered when all nodes are hidden
3058
+ * @event
3059
+ * @name hide_all.jstree
3060
+ * @param {Array} nodes the IDs of all hidden nodes
3061
+ */
3062
+ this.trigger('hide_all', { 'nodes' : ids });
3063
+ return ids;
3064
+ },
3065
+ /**
3066
+ * shows all nodes
3067
+ * @name show_all()
3068
+ * @trigger show_all.jstree
3069
+ */
3070
+ show_all : function (skip_redraw) {
3071
+ var i, m = this._model.data, ids = [];
3072
+ for(i in m) {
3073
+ if(m.hasOwnProperty(i) && i !== $.jstree.root && m[i].state.hidden) {
3074
+ m[i].state.hidden = false;
3075
+ ids.push(i);
3076
+ }
3077
+ }
3078
+ this._model.force_full_redraw = true;
3079
+ if(!skip_redraw) {
3080
+ this.redraw();
3081
+ }
3082
+ /**
3083
+ * triggered when all nodes are shown
3084
+ * @event
3085
+ * @name show_all.jstree
3086
+ * @param {Array} nodes the IDs of all shown nodes
3087
+ */
3088
+ this.trigger('show_all', { 'nodes' : ids });
3089
+ return ids;
3090
+ },
3091
+ /**
3092
+ * called when a node is selected by the user. Used internally.
3093
+ * @private
3094
+ * @name activate_node(obj, e)
3095
+ * @param {mixed} obj the node
3096
+ * @param {Object} e the related event
3097
+ * @trigger activate_node.jstree, changed.jstree
3098
+ */
3099
+ activate_node : function (obj, e) {
3100
+ if(this.is_disabled(obj)) {
3101
+ return false;
3102
+ }
3103
+ if(!e || typeof e !== 'object') {
3104
+ e = {};
3105
+ }
3106
+
3107
+ // ensure last_clicked is still in the DOM, make it fresh (maybe it was moved?) and make sure it is still selected, if not - make last_clicked the last selected node
3108
+ this._data.core.last_clicked = this._data.core.last_clicked && this._data.core.last_clicked.id !== undefined ? this.get_node(this._data.core.last_clicked.id) : null;
3109
+ if(this._data.core.last_clicked && !this._data.core.last_clicked.state.selected) { this._data.core.last_clicked = null; }
3110
+ if(!this._data.core.last_clicked && this._data.core.selected.length) { this._data.core.last_clicked = this.get_node(this._data.core.selected[this._data.core.selected.length - 1]); }
3111
+
3112
+ if(!this.settings.core.multiple || (!e.metaKey && !e.ctrlKey && !e.shiftKey) || (e.shiftKey && (!this._data.core.last_clicked || !this.get_parent(obj) || this.get_parent(obj) !== this._data.core.last_clicked.parent ) )) {
3113
+ if(!this.settings.core.multiple && (e.metaKey || e.ctrlKey || e.shiftKey) && this.is_selected(obj)) {
3114
+ this.deselect_node(obj, false, e);
3115
+ }
3116
+ else {
3117
+ this.deselect_all(true);
3118
+ this.select_node(obj, false, false, e);
3119
+ this._data.core.last_clicked = this.get_node(obj);
3120
+ }
3121
+ }
3122
+ else {
3123
+ if(e.shiftKey) {
3124
+ var o = this.get_node(obj).id,
3125
+ l = this._data.core.last_clicked.id,
3126
+ p = this.get_node(this._data.core.last_clicked.parent).children,
3127
+ c = false,
3128
+ i, j;
3129
+ for(i = 0, j = p.length; i < j; i += 1) {
3130
+ // separate IFs work whem o and l are the same
3131
+ if(p[i] === o) {
3132
+ c = !c;
3133
+ }
3134
+ if(p[i] === l) {
3135
+ c = !c;
3136
+ }
3137
+ if(!this.is_disabled(p[i]) && (c || p[i] === o || p[i] === l)) {
3138
+ if (!this.is_hidden(p[i])) {
3139
+ this.select_node(p[i], true, false, e);
3140
+ }
3141
+ }
3142
+ else {
3143
+ this.deselect_node(p[i], true, e);
3144
+ }
3145
+ }
3146
+ this.trigger('changed', { 'action' : 'select_node', 'node' : this.get_node(obj), 'selected' : this._data.core.selected, 'event' : e });
3147
+ }
3148
+ else {
3149
+ if(!this.is_selected(obj)) {
3150
+ this.select_node(obj, false, false, e);
3151
+ }
3152
+ else {
3153
+ this.deselect_node(obj, false, e);
3154
+ }
3155
+ }
3156
+ }
3157
+ /**
3158
+ * triggered when an node is clicked or intercated with by the user
3159
+ * @event
3160
+ * @name activate_node.jstree
3161
+ * @param {Object} node
3162
+ * @param {Object} event the ooriginal event (if any) which triggered the call (may be an empty object)
3163
+ */
3164
+ this.trigger('activate_node', { 'node' : this.get_node(obj), 'event' : e });
3165
+ },
3166
+ /**
3167
+ * applies the hover state on a node, called when a node is hovered by the user. Used internally.
3168
+ * @private
3169
+ * @name hover_node(obj)
3170
+ * @param {mixed} obj
3171
+ * @trigger hover_node.jstree
3172
+ */
3173
+ hover_node : function (obj) {
3174
+ obj = this.get_node(obj, true);
3175
+ if(!obj || !obj.length || obj.children('.jstree-hovered').length) {
3176
+ return false;
3177
+ }
3178
+ var o = this.element.find('.jstree-hovered'), t = this.element;
3179
+ if(o && o.length) { this.dehover_node(o); }
3180
+
3181
+ obj.children('.jstree-anchor').addClass('jstree-hovered');
3182
+ /**
3183
+ * triggered when an node is hovered
3184
+ * @event
3185
+ * @name hover_node.jstree
3186
+ * @param {Object} node
3187
+ */
3188
+ this.trigger('hover_node', { 'node' : this.get_node(obj) });
3189
+ setTimeout(function () { t.attr('aria-activedescendant', obj[0].id); }, 0);
3190
+ },
3191
+ /**
3192
+ * removes the hover state from a nodecalled when a node is no longer hovered by the user. Used internally.
3193
+ * @private
3194
+ * @name dehover_node(obj)
3195
+ * @param {mixed} obj
3196
+ * @trigger dehover_node.jstree
3197
+ */
3198
+ dehover_node : function (obj) {
3199
+ obj = this.get_node(obj, true);
3200
+ if(!obj || !obj.length || !obj.children('.jstree-hovered').length) {
3201
+ return false;
3202
+ }
3203
+ obj.children('.jstree-anchor').removeClass('jstree-hovered');
3204
+ /**
3205
+ * triggered when an node is no longer hovered
3206
+ * @event
3207
+ * @name dehover_node.jstree
3208
+ * @param {Object} node
3209
+ */
3210
+ this.trigger('dehover_node', { 'node' : this.get_node(obj) });
3211
+ },
3212
+ /**
3213
+ * select a node
3214
+ * @name select_node(obj [, supress_event, prevent_open])
3215
+ * @param {mixed} obj an array can be used to select multiple nodes
3216
+ * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3217
+ * @param {Boolean} prevent_open if set to `true` parents of the selected node won't be opened
3218
+ * @trigger select_node.jstree, changed.jstree
3219
+ */
3220
+ select_node : function (obj, supress_event, prevent_open, e) {
3221
+ var dom, t1, t2, th;
3222
+ if($.isArray(obj)) {
3223
+ obj = obj.slice();
3224
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3225
+ this.select_node(obj[t1], supress_event, prevent_open, e);
3226
+ }
3227
+ return true;
3228
+ }
3229
+ obj = this.get_node(obj);
3230
+ if(!obj || obj.id === $.jstree.root) {
3231
+ return false;
3232
+ }
3233
+ dom = this.get_node(obj, true);
3234
+ if(!obj.state.selected) {
3235
+ obj.state.selected = true;
3236
+ this._data.core.selected.push(obj.id);
3237
+ if(!prevent_open) {
3238
+ dom = this._open_to(obj);
3239
+ }
3240
+ if(dom && dom.length) {
3241
+ dom.attr('aria-selected', true).children('.jstree-anchor').addClass('jstree-clicked');
3242
+ }
3243
+ /**
3244
+ * triggered when an node is selected
3245
+ * @event
3246
+ * @name select_node.jstree
3247
+ * @param {Object} node
3248
+ * @param {Array} selected the current selection
3249
+ * @param {Object} event the event (if any) that triggered this select_node
3250
+ */
3251
+ this.trigger('select_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3252
+ if(!supress_event) {
3253
+ /**
3254
+ * triggered when selection changes
3255
+ * @event
3256
+ * @name changed.jstree
3257
+ * @param {Object} node
3258
+ * @param {Object} action the action that caused the selection to change
3259
+ * @param {Array} selected the current selection
3260
+ * @param {Object} event the event (if any) that triggered this changed event
3261
+ */
3262
+ this.trigger('changed', { 'action' : 'select_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3263
+ }
3264
+ }
3265
+ },
3266
+ /**
3267
+ * deselect a node
3268
+ * @name deselect_node(obj [, supress_event])
3269
+ * @param {mixed} obj an array can be used to deselect multiple nodes
3270
+ * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3271
+ * @trigger deselect_node.jstree, changed.jstree
3272
+ */
3273
+ deselect_node : function (obj, supress_event, e) {
3274
+ var t1, t2, dom;
3275
+ if($.isArray(obj)) {
3276
+ obj = obj.slice();
3277
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3278
+ this.deselect_node(obj[t1], supress_event, e);
3279
+ }
3280
+ return true;
3281
+ }
3282
+ obj = this.get_node(obj);
3283
+ if(!obj || obj.id === $.jstree.root) {
3284
+ return false;
3285
+ }
3286
+ dom = this.get_node(obj, true);
3287
+ if(obj.state.selected) {
3288
+ obj.state.selected = false;
3289
+ this._data.core.selected = $.vakata.array_remove_item(this._data.core.selected, obj.id);
3290
+ if(dom.length) {
3291
+ dom.attr('aria-selected', false).children('.jstree-anchor').removeClass('jstree-clicked');
3292
+ }
3293
+ /**
3294
+ * triggered when an node is deselected
3295
+ * @event
3296
+ * @name deselect_node.jstree
3297
+ * @param {Object} node
3298
+ * @param {Array} selected the current selection
3299
+ * @param {Object} event the event (if any) that triggered this deselect_node
3300
+ */
3301
+ this.trigger('deselect_node', { 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3302
+ if(!supress_event) {
3303
+ this.trigger('changed', { 'action' : 'deselect_node', 'node' : obj, 'selected' : this._data.core.selected, 'event' : e });
3304
+ }
3305
+ }
3306
+ },
3307
+ /**
3308
+ * select all nodes in the tree
3309
+ * @name select_all([supress_event])
3310
+ * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3311
+ * @trigger select_all.jstree, changed.jstree
3312
+ */
3313
+ select_all : function (supress_event) {
3314
+ var tmp = this._data.core.selected.concat([]), i, j;
3315
+ this._data.core.selected = this._model.data[$.jstree.root].children_d.concat();
3316
+ for(i = 0, j = this._data.core.selected.length; i < j; i++) {
3317
+ if(this._model.data[this._data.core.selected[i]]) {
3318
+ this._model.data[this._data.core.selected[i]].state.selected = true;
3319
+ }
3320
+ }
3321
+ this.redraw(true);
3322
+ /**
3323
+ * triggered when all nodes are selected
3324
+ * @event
3325
+ * @name select_all.jstree
3326
+ * @param {Array} selected the current selection
3327
+ */
3328
+ this.trigger('select_all', { 'selected' : this._data.core.selected });
3329
+ if(!supress_event) {
3330
+ this.trigger('changed', { 'action' : 'select_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
3331
+ }
3332
+ },
3333
+ /**
3334
+ * deselect all selected nodes
3335
+ * @name deselect_all([supress_event])
3336
+ * @param {Boolean} supress_event if set to `true` the `changed.jstree` event won't be triggered
3337
+ * @trigger deselect_all.jstree, changed.jstree
3338
+ */
3339
+ deselect_all : function (supress_event) {
3340
+ var tmp = this._data.core.selected.concat([]), i, j;
3341
+ for(i = 0, j = this._data.core.selected.length; i < j; i++) {
3342
+ if(this._model.data[this._data.core.selected[i]]) {
3343
+ this._model.data[this._data.core.selected[i]].state.selected = false;
3344
+ }
3345
+ }
3346
+ this._data.core.selected = [];
3347
+ this.element.find('.jstree-clicked').removeClass('jstree-clicked').parent().attr('aria-selected', false);
3348
+ /**
3349
+ * triggered when all nodes are deselected
3350
+ * @event
3351
+ * @name deselect_all.jstree
3352
+ * @param {Object} node the previous selection
3353
+ * @param {Array} selected the current selection
3354
+ */
3355
+ this.trigger('deselect_all', { 'selected' : this._data.core.selected, 'node' : tmp });
3356
+ if(!supress_event) {
3357
+ this.trigger('changed', { 'action' : 'deselect_all', 'selected' : this._data.core.selected, 'old_selection' : tmp });
3358
+ }
3359
+ },
3360
+ /**
3361
+ * checks if a node is selected
3362
+ * @name is_selected(obj)
3363
+ * @param {mixed} obj
3364
+ * @return {Boolean}
3365
+ */
3366
+ is_selected : function (obj) {
3367
+ obj = this.get_node(obj);
3368
+ if(!obj || obj.id === $.jstree.root) {
3369
+ return false;
3370
+ }
3371
+ return obj.state.selected;
3372
+ },
3373
+ /**
3374
+ * get an array of all selected nodes
3375
+ * @name get_selected([full])
3376
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3377
+ * @return {Array}
3378
+ */
3379
+ get_selected : function (full) {
3380
+ return full ? $.map(this._data.core.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.core.selected.slice();
3381
+ },
3382
+ /**
3383
+ * get an array of all top level selected nodes (ignoring children of selected nodes)
3384
+ * @name get_top_selected([full])
3385
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3386
+ * @return {Array}
3387
+ */
3388
+ get_top_selected : function (full) {
3389
+ var tmp = this.get_selected(true),
3390
+ obj = {}, i, j, k, l;
3391
+ for(i = 0, j = tmp.length; i < j; i++) {
3392
+ obj[tmp[i].id] = tmp[i];
3393
+ }
3394
+ for(i = 0, j = tmp.length; i < j; i++) {
3395
+ for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
3396
+ if(obj[tmp[i].children_d[k]]) {
3397
+ delete obj[tmp[i].children_d[k]];
3398
+ }
3399
+ }
3400
+ }
3401
+ tmp = [];
3402
+ for(i in obj) {
3403
+ if(obj.hasOwnProperty(i)) {
3404
+ tmp.push(i);
3405
+ }
3406
+ }
3407
+ return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
3408
+ },
3409
+ /**
3410
+ * get an array of all bottom level selected nodes (ignoring selected parents)
3411
+ * @name get_bottom_selected([full])
3412
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
3413
+ * @return {Array}
3414
+ */
3415
+ get_bottom_selected : function (full) {
3416
+ var tmp = this.get_selected(true),
3417
+ obj = [], i, j;
3418
+ for(i = 0, j = tmp.length; i < j; i++) {
3419
+ if(!tmp[i].children.length) {
3420
+ obj.push(tmp[i].id);
3421
+ }
3422
+ }
3423
+ return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
3424
+ },
3425
+ /**
3426
+ * gets the current state of the tree so that it can be restored later with `set_state(state)`. Used internally.
3427
+ * @name get_state()
3428
+ * @private
3429
+ * @return {Object}
3430
+ */
3431
+ get_state : function () {
3432
+ var state = {
3433
+ 'core' : {
3434
+ 'open' : [],
3435
+ 'loaded' : [],
3436
+ 'scroll' : {
3437
+ 'left' : this.element.scrollLeft(),
3438
+ 'top' : this.element.scrollTop()
3439
+ },
3440
+ /*!
3441
+ 'themes' : {
3442
+ 'name' : this.get_theme(),
3443
+ 'icons' : this._data.core.themes.icons,
3444
+ 'dots' : this._data.core.themes.dots
3445
+ },
3446
+ */
3447
+ 'selected' : []
3448
+ }
3449
+ }, i;
3450
+ for(i in this._model.data) {
3451
+ if(this._model.data.hasOwnProperty(i)) {
3452
+ if(i !== $.jstree.root) {
3453
+ if(this._model.data[i].state.loaded && this.settings.core.loaded_state) {
3454
+ state.core.loaded.push(i);
3455
+ }
3456
+ if(this._model.data[i].state.opened) {
3457
+ state.core.open.push(i);
3458
+ }
3459
+ if(this._model.data[i].state.selected) {
3460
+ state.core.selected.push(i);
3461
+ }
3462
+ }
3463
+ }
3464
+ }
3465
+ return state;
3466
+ },
3467
+ /**
3468
+ * sets the state of the tree. Used internally.
3469
+ * @name set_state(state [, callback])
3470
+ * @private
3471
+ * @param {Object} state the state to restore. Keep in mind this object is passed by reference and jstree will modify it.
3472
+ * @param {Function} callback an optional function to execute once the state is restored.
3473
+ * @trigger set_state.jstree
3474
+ */
3475
+ set_state : function (state, callback) {
3476
+ if(state) {
3477
+ if(state.core && state.core.selected && state.core.initial_selection === undefined) {
3478
+ state.core.initial_selection = this._data.core.selected.concat([]).sort().join(',');
3479
+ }
3480
+ if(state.core) {
3481
+ var res, n, t, _this, i;
3482
+ if(state.core.loaded) {
3483
+ if(!this.settings.core.loaded_state || !$.isArray(state.core.loaded) || !state.core.loaded.length) {
3484
+ delete state.core.loaded;
3485
+ this.set_state(state, callback);
3486
+ }
3487
+ else {
3488
+ this._load_nodes(state.core.loaded, function (nodes) {
3489
+ delete state.core.loaded;
3490
+ this.set_state(state, callback);
3491
+ });
3492
+ }
3493
+ return false;
3494
+ }
3495
+ if(state.core.open) {
3496
+ if(!$.isArray(state.core.open) || !state.core.open.length) {
3497
+ delete state.core.open;
3498
+ this.set_state(state, callback);
3499
+ }
3500
+ else {
3501
+ this._load_nodes(state.core.open, function (nodes) {
3502
+ this.open_node(nodes, false, 0);
3503
+ delete state.core.open;
3504
+ this.set_state(state, callback);
3505
+ });
3506
+ }
3507
+ return false;
3508
+ }
3509
+ if(state.core.scroll) {
3510
+ if(state.core.scroll && state.core.scroll.left !== undefined) {
3511
+ this.element.scrollLeft(state.core.scroll.left);
3512
+ }
3513
+ if(state.core.scroll && state.core.scroll.top !== undefined) {
3514
+ this.element.scrollTop(state.core.scroll.top);
3515
+ }
3516
+ delete state.core.scroll;
3517
+ this.set_state(state, callback);
3518
+ return false;
3519
+ }
3520
+ if(state.core.selected) {
3521
+ _this = this;
3522
+ if (state.core.initial_selection === undefined ||
3523
+ state.core.initial_selection === this._data.core.selected.concat([]).sort().join(',')
3524
+ ) {
3525
+ this.deselect_all();
3526
+ $.each(state.core.selected, function (i, v) {
3527
+ _this.select_node(v, false, true);
3528
+ });
3529
+ }
3530
+ delete state.core.initial_selection;
3531
+ delete state.core.selected;
3532
+ this.set_state(state, callback);
3533
+ return false;
3534
+ }
3535
+ for(i in state) {
3536
+ if(state.hasOwnProperty(i) && i !== "core" && $.inArray(i, this.settings.plugins) === -1) {
3537
+ delete state[i];
3538
+ }
3539
+ }
3540
+ if($.isEmptyObject(state.core)) {
3541
+ delete state.core;
3542
+ this.set_state(state, callback);
3543
+ return false;
3544
+ }
3545
+ }
3546
+ if($.isEmptyObject(state)) {
3547
+ state = null;
3548
+ if(callback) { callback.call(this); }
3549
+ /**
3550
+ * triggered when a `set_state` call completes
3551
+ * @event
3552
+ * @name set_state.jstree
3553
+ */
3554
+ this.trigger('set_state');
3555
+ return false;
3556
+ }
3557
+ return true;
3558
+ }
3559
+ return false;
3560
+ },
3561
+ /**
3562
+ * refreshes the tree - all nodes are reloaded with calls to `load_node`.
3563
+ * @name refresh()
3564
+ * @param {Boolean} skip_loading an option to skip showing the loading indicator
3565
+ * @param {Mixed} forget_state if set to `true` state will not be reapplied, if set to a function (receiving the current state as argument) the result of that function will be used as state
3566
+ * @trigger refresh.jstree
3567
+ */
3568
+ refresh : function (skip_loading, forget_state) {
3569
+ this._data.core.state = forget_state === true ? {} : this.get_state();
3570
+ if(forget_state && $.isFunction(forget_state)) { this._data.core.state = forget_state.call(this, this._data.core.state); }
3571
+ this._cnt = 0;
3572
+ this._model.data = {};
3573
+ this._model.data[$.jstree.root] = {
3574
+ id : $.jstree.root,
3575
+ parent : null,
3576
+ parents : [],
3577
+ children : [],
3578
+ children_d : [],
3579
+ state : { loaded : false }
3580
+ };
3581
+ this._data.core.selected = [];
3582
+ this._data.core.last_clicked = null;
3583
+ this._data.core.focused = null;
3584
+
3585
+ var c = this.get_container_ul()[0].className;
3586
+ if(!skip_loading) {
3587
+ this.element.html("<"+"ul class='"+c+"' role='group'><"+"li class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='treeitem' id='j"+this._id+"_loading'><i class='jstree-icon jstree-ocl'></i><"+"a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>" + this.get_string("Loading ...") + "</a></li></ul>");
3588
+ this.element.attr('aria-activedescendant','j'+this._id+'_loading');
3589
+ }
3590
+ this.load_node($.jstree.root, function (o, s) {
3591
+ if(s) {
3592
+ this.get_container_ul()[0].className = c;
3593
+ if(this._firstChild(this.get_container_ul()[0])) {
3594
+ this.element.attr('aria-activedescendant',this._firstChild(this.get_container_ul()[0]).id);
3595
+ }
3596
+ this.set_state($.extend(true, {}, this._data.core.state), function () {
3597
+ /**
3598
+ * triggered when a `refresh` call completes
3599
+ * @event
3600
+ * @name refresh.jstree
3601
+ */
3602
+ this.trigger('refresh');
3603
+ });
3604
+ }
3605
+ this._data.core.state = null;
3606
+ });
3607
+ },
3608
+ /**
3609
+ * refreshes a node in the tree (reload its children) all opened nodes inside that node are reloaded with calls to `load_node`.
3610
+ * @name refresh_node(obj)
3611
+ * @param {mixed} obj the node
3612
+ * @trigger refresh_node.jstree
3613
+ */
3614
+ refresh_node : function (obj) {
3615
+ obj = this.get_node(obj);
3616
+ if(!obj || obj.id === $.jstree.root) { return false; }
3617
+ var opened = [], to_load = [], s = this._data.core.selected.concat([]);
3618
+ to_load.push(obj.id);
3619
+ if(obj.state.opened === true) { opened.push(obj.id); }
3620
+ this.get_node(obj, true).find('.jstree-open').each(function() { to_load.push(this.id); opened.push(this.id); });
3621
+ this._load_nodes(to_load, $.proxy(function (nodes) {
3622
+ this.open_node(opened, false, 0);
3623
+ this.select_node(s);
3624
+ /**
3625
+ * triggered when a node is refreshed
3626
+ * @event
3627
+ * @name refresh_node.jstree
3628
+ * @param {Object} node - the refreshed node
3629
+ * @param {Array} nodes - an array of the IDs of the nodes that were reloaded
3630
+ */
3631
+ this.trigger('refresh_node', { 'node' : obj, 'nodes' : nodes });
3632
+ }, this), false, true);
3633
+ },
3634
+ /**
3635
+ * set (change) the ID of a node
3636
+ * @name set_id(obj, id)
3637
+ * @param {mixed} obj the node
3638
+ * @param {String} id the new ID
3639
+ * @return {Boolean}
3640
+ * @trigger set_id.jstree
3641
+ */
3642
+ set_id : function (obj, id) {
3643
+ obj = this.get_node(obj);
3644
+ if(!obj || obj.id === $.jstree.root) { return false; }
3645
+ var i, j, m = this._model.data, old = obj.id;
3646
+ id = id.toString();
3647
+ // update parents (replace current ID with new one in children and children_d)
3648
+ m[obj.parent].children[$.inArray(obj.id, m[obj.parent].children)] = id;
3649
+ for(i = 0, j = obj.parents.length; i < j; i++) {
3650
+ m[obj.parents[i]].children_d[$.inArray(obj.id, m[obj.parents[i]].children_d)] = id;
3651
+ }
3652
+ // update children (replace current ID with new one in parent and parents)
3653
+ for(i = 0, j = obj.children.length; i < j; i++) {
3654
+ m[obj.children[i]].parent = id;
3655
+ }
3656
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
3657
+ m[obj.children_d[i]].parents[$.inArray(obj.id, m[obj.children_d[i]].parents)] = id;
3658
+ }
3659
+ i = $.inArray(obj.id, this._data.core.selected);
3660
+ if(i !== -1) { this._data.core.selected[i] = id; }
3661
+ // update model and obj itself (obj.id, this._model.data[KEY])
3662
+ i = this.get_node(obj.id, true);
3663
+ if(i) {
3664
+ i.attr('id', id); //.children('.jstree-anchor').attr('id', id + '_anchor').end().attr('aria-labelledby', id + '_anchor');
3665
+ if(this.element.attr('aria-activedescendant') === obj.id) {
3666
+ this.element.attr('aria-activedescendant', id);
3667
+ }
3668
+ }
3669
+ delete m[obj.id];
3670
+ obj.id = id;
3671
+ obj.li_attr.id = id;
3672
+ m[id] = obj;
3673
+ /**
3674
+ * triggered when a node id value is changed
3675
+ * @event
3676
+ * @name set_id.jstree
3677
+ * @param {Object} node
3678
+ * @param {String} old the old id
3679
+ */
3680
+ this.trigger('set_id',{ "node" : obj, "new" : obj.id, "old" : old });
3681
+ return true;
3682
+ },
3683
+ /**
3684
+ * get the text value of a node
3685
+ * @name get_text(obj)
3686
+ * @param {mixed} obj the node
3687
+ * @return {String}
3688
+ */
3689
+ get_text : function (obj) {
3690
+ obj = this.get_node(obj);
3691
+ return (!obj || obj.id === $.jstree.root) ? false : obj.text;
3692
+ },
3693
+ /**
3694
+ * set the text value of a node. Used internally, please use `rename_node(obj, val)`.
3695
+ * @private
3696
+ * @name set_text(obj, val)
3697
+ * @param {mixed} obj the node, you can pass an array to set the text on multiple nodes
3698
+ * @param {String} val the new text value
3699
+ * @return {Boolean}
3700
+ * @trigger set_text.jstree
3701
+ */
3702
+ set_text : function (obj, val) {
3703
+ var t1, t2;
3704
+ if($.isArray(obj)) {
3705
+ obj = obj.slice();
3706
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3707
+ this.set_text(obj[t1], val);
3708
+ }
3709
+ return true;
3710
+ }
3711
+ obj = this.get_node(obj);
3712
+ if(!obj || obj.id === $.jstree.root) { return false; }
3713
+ obj.text = val;
3714
+ if(this.get_node(obj, true).length) {
3715
+ this.redraw_node(obj.id);
3716
+ }
3717
+ /**
3718
+ * triggered when a node text value is changed
3719
+ * @event
3720
+ * @name set_text.jstree
3721
+ * @param {Object} obj
3722
+ * @param {String} text the new value
3723
+ */
3724
+ this.trigger('set_text',{ "obj" : obj, "text" : val });
3725
+ return true;
3726
+ },
3727
+ /**
3728
+ * gets a JSON representation of a node (or the whole tree)
3729
+ * @name get_json([obj, options])
3730
+ * @param {mixed} obj
3731
+ * @param {Object} options
3732
+ * @param {Boolean} options.no_state do not return state information
3733
+ * @param {Boolean} options.no_id do not return ID
3734
+ * @param {Boolean} options.no_children do not include children
3735
+ * @param {Boolean} options.no_data do not include node data
3736
+ * @param {Boolean} options.no_li_attr do not include LI attributes
3737
+ * @param {Boolean} options.no_a_attr do not include A attributes
3738
+ * @param {Boolean} options.flat return flat JSON instead of nested
3739
+ * @return {Object}
3740
+ */
3741
+ get_json : function (obj, options, flat) {
3742
+ obj = this.get_node(obj || $.jstree.root);
3743
+ if(!obj) { return false; }
3744
+ if(options && options.flat && !flat) { flat = []; }
3745
+ var tmp = {
3746
+ 'id' : obj.id,
3747
+ 'text' : obj.text,
3748
+ 'icon' : this.get_icon(obj),
3749
+ 'li_attr' : $.extend(true, {}, obj.li_attr),
3750
+ 'a_attr' : $.extend(true, {}, obj.a_attr),
3751
+ 'state' : {},
3752
+ 'data' : options && options.no_data ? false : $.extend(true, $.isArray(obj.data)?[]:{}, obj.data)
3753
+ //( this.get_node(obj, true).length ? this.get_node(obj, true).data() : obj.data ),
3754
+ }, i, j;
3755
+ if(options && options.flat) {
3756
+ tmp.parent = obj.parent;
3757
+ }
3758
+ else {
3759
+ tmp.children = [];
3760
+ }
3761
+ if(!options || !options.no_state) {
3762
+ for(i in obj.state) {
3763
+ if(obj.state.hasOwnProperty(i)) {
3764
+ tmp.state[i] = obj.state[i];
3765
+ }
3766
+ }
3767
+ } else {
3768
+ delete tmp.state;
3769
+ }
3770
+ if(options && options.no_li_attr) {
3771
+ delete tmp.li_attr;
3772
+ }
3773
+ if(options && options.no_a_attr) {
3774
+ delete tmp.a_attr;
3775
+ }
3776
+ if(options && options.no_id) {
3777
+ delete tmp.id;
3778
+ if(tmp.li_attr && tmp.li_attr.id) {
3779
+ delete tmp.li_attr.id;
3780
+ }
3781
+ if(tmp.a_attr && tmp.a_attr.id) {
3782
+ delete tmp.a_attr.id;
3783
+ }
3784
+ }
3785
+ if(options && options.flat && obj.id !== $.jstree.root) {
3786
+ flat.push(tmp);
3787
+ }
3788
+ if(!options || !options.no_children) {
3789
+ for(i = 0, j = obj.children.length; i < j; i++) {
3790
+ if(options && options.flat) {
3791
+ this.get_json(obj.children[i], options, flat);
3792
+ }
3793
+ else {
3794
+ tmp.children.push(this.get_json(obj.children[i], options));
3795
+ }
3796
+ }
3797
+ }
3798
+ return options && options.flat ? flat : (obj.id === $.jstree.root ? tmp.children : tmp);
3799
+ },
3800
+ /**
3801
+ * create a new node (do not confuse with load_node)
3802
+ * @name create_node([par, node, pos, callback, is_loaded])
3803
+ * @param {mixed} par the parent node (to create a root node use either "#" (string) or `null`)
3804
+ * @param {mixed} node the data for the new node (a valid JSON object, or a simple string with the name)
3805
+ * @param {mixed} pos the index at which to insert the node, "first" and "last" are also supported, default is "last"
3806
+ * @param {Function} callback a function to be called once the node is created
3807
+ * @param {Boolean} is_loaded internal argument indicating if the parent node was succesfully loaded
3808
+ * @return {String} the ID of the newly create node
3809
+ * @trigger model.jstree, create_node.jstree
3810
+ */
3811
+ create_node : function (par, node, pos, callback, is_loaded) {
3812
+ if(par === null) { par = $.jstree.root; }
3813
+ par = this.get_node(par);
3814
+ if(!par) { return false; }
3815
+ pos = pos === undefined ? "last" : pos;
3816
+ if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
3817
+ return this.load_node(par, function () { this.create_node(par, node, pos, callback, true); });
3818
+ }
3819
+ if(!node) { node = { "text" : this.get_string('New node') }; }
3820
+ if(typeof node === "string") {
3821
+ node = { "text" : node };
3822
+ } else {
3823
+ node = $.extend(true, {}, node);
3824
+ }
3825
+ if(node.text === undefined) { node.text = this.get_string('New node'); }
3826
+ var tmp, dpc, i, j;
3827
+
3828
+ if(par.id === $.jstree.root) {
3829
+ if(pos === "before") { pos = "first"; }
3830
+ if(pos === "after") { pos = "last"; }
3831
+ }
3832
+ switch(pos) {
3833
+ case "before":
3834
+ tmp = this.get_node(par.parent);
3835
+ pos = $.inArray(par.id, tmp.children);
3836
+ par = tmp;
3837
+ break;
3838
+ case "after" :
3839
+ tmp = this.get_node(par.parent);
3840
+ pos = $.inArray(par.id, tmp.children) + 1;
3841
+ par = tmp;
3842
+ break;
3843
+ case "inside":
3844
+ case "first":
3845
+ pos = 0;
3846
+ break;
3847
+ case "last":
3848
+ pos = par.children.length;
3849
+ break;
3850
+ default:
3851
+ if(!pos) { pos = 0; }
3852
+ break;
3853
+ }
3854
+ if(pos > par.children.length) { pos = par.children.length; }
3855
+ if(!node.id) { node.id = true; }
3856
+ if(!this.check("create_node", node, par, pos)) {
3857
+ this.settings.core.error.call(this, this._data.core.last_error);
3858
+ return false;
3859
+ }
3860
+ if(node.id === true) { delete node.id; }
3861
+ node = this._parse_model_from_json(node, par.id, par.parents.concat());
3862
+ if(!node) { return false; }
3863
+ tmp = this.get_node(node);
3864
+ dpc = [];
3865
+ dpc.push(node);
3866
+ dpc = dpc.concat(tmp.children_d);
3867
+ this.trigger('model', { "nodes" : dpc, "parent" : par.id });
3868
+
3869
+ par.children_d = par.children_d.concat(dpc);
3870
+ for(i = 0, j = par.parents.length; i < j; i++) {
3871
+ this._model.data[par.parents[i]].children_d = this._model.data[par.parents[i]].children_d.concat(dpc);
3872
+ }
3873
+ node = tmp;
3874
+ tmp = [];
3875
+ for(i = 0, j = par.children.length; i < j; i++) {
3876
+ tmp[i >= pos ? i+1 : i] = par.children[i];
3877
+ }
3878
+ tmp[pos] = node.id;
3879
+ par.children = tmp;
3880
+
3881
+ this.redraw_node(par, true);
3882
+ /**
3883
+ * triggered when a node is created
3884
+ * @event
3885
+ * @name create_node.jstree
3886
+ * @param {Object} node
3887
+ * @param {String} parent the parent's ID
3888
+ * @param {Number} position the position of the new node among the parent's children
3889
+ */
3890
+ this.trigger('create_node', { "node" : this.get_node(node), "parent" : par.id, "position" : pos });
3891
+ if(callback) { callback.call(this, this.get_node(node)); }
3892
+ return node.id;
3893
+ },
3894
+ /**
3895
+ * set the text value of a node
3896
+ * @name rename_node(obj, val)
3897
+ * @param {mixed} obj the node, you can pass an array to rename multiple nodes to the same name
3898
+ * @param {String} val the new text value
3899
+ * @return {Boolean}
3900
+ * @trigger rename_node.jstree
3901
+ */
3902
+ rename_node : function (obj, val) {
3903
+ var t1, t2, old;
3904
+ if($.isArray(obj)) {
3905
+ obj = obj.slice();
3906
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3907
+ this.rename_node(obj[t1], val);
3908
+ }
3909
+ return true;
3910
+ }
3911
+ obj = this.get_node(obj);
3912
+ if(!obj || obj.id === $.jstree.root) { return false; }
3913
+ old = obj.text;
3914
+ if(!this.check("rename_node", obj, this.get_parent(obj), val)) {
3915
+ this.settings.core.error.call(this, this._data.core.last_error);
3916
+ return false;
3917
+ }
3918
+ this.set_text(obj, val); // .apply(this, Array.prototype.slice.call(arguments))
3919
+ /**
3920
+ * triggered when a node is renamed
3921
+ * @event
3922
+ * @name rename_node.jstree
3923
+ * @param {Object} node
3924
+ * @param {String} text the new value
3925
+ * @param {String} old the old value
3926
+ */
3927
+ this.trigger('rename_node', { "node" : obj, "text" : val, "old" : old });
3928
+ return true;
3929
+ },
3930
+ /**
3931
+ * remove a node
3932
+ * @name delete_node(obj)
3933
+ * @param {mixed} obj the node, you can pass an array to delete multiple nodes
3934
+ * @return {Boolean}
3935
+ * @trigger delete_node.jstree, changed.jstree
3936
+ */
3937
+ delete_node : function (obj) {
3938
+ var t1, t2, par, pos, tmp, i, j, k, l, c, top, lft;
3939
+ if($.isArray(obj)) {
3940
+ obj = obj.slice();
3941
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
3942
+ this.delete_node(obj[t1]);
3943
+ }
3944
+ return true;
3945
+ }
3946
+ obj = this.get_node(obj);
3947
+ if(!obj || obj.id === $.jstree.root) { return false; }
3948
+ par = this.get_node(obj.parent);
3949
+ pos = $.inArray(obj.id, par.children);
3950
+ c = false;
3951
+ if(!this.check("delete_node", obj, par, pos)) {
3952
+ this.settings.core.error.call(this, this._data.core.last_error);
3953
+ return false;
3954
+ }
3955
+ if(pos !== -1) {
3956
+ par.children = $.vakata.array_remove(par.children, pos);
3957
+ }
3958
+ tmp = obj.children_d.concat([]);
3959
+ tmp.push(obj.id);
3960
+ for(i = 0, j = obj.parents.length; i < j; i++) {
3961
+ this._model.data[obj.parents[i]].children_d = $.vakata.array_filter(this._model.data[obj.parents[i]].children_d, function (v) {
3962
+ return $.inArray(v, tmp) === -1;
3963
+ });
3964
+ }
3965
+ for(k = 0, l = tmp.length; k < l; k++) {
3966
+ if(this._model.data[tmp[k]].state.selected) {
3967
+ c = true;
3968
+ break;
3969
+ }
3970
+ }
3971
+ if (c) {
3972
+ this._data.core.selected = $.vakata.array_filter(this._data.core.selected, function (v) {
3973
+ return $.inArray(v, tmp) === -1;
3974
+ });
3975
+ }
3976
+ /**
3977
+ * triggered when a node is deleted
3978
+ * @event
3979
+ * @name delete_node.jstree
3980
+ * @param {Object} node
3981
+ * @param {String} parent the parent's ID
3982
+ */
3983
+ this.trigger('delete_node', { "node" : obj, "parent" : par.id });
3984
+ if(c) {
3985
+ this.trigger('changed', { 'action' : 'delete_node', 'node' : obj, 'selected' : this._data.core.selected, 'parent' : par.id });
3986
+ }
3987
+ for(k = 0, l = tmp.length; k < l; k++) {
3988
+ delete this._model.data[tmp[k]];
3989
+ }
3990
+ if($.inArray(this._data.core.focused, tmp) !== -1) {
3991
+ this._data.core.focused = null;
3992
+ top = this.element[0].scrollTop;
3993
+ lft = this.element[0].scrollLeft;
3994
+ if(par.id === $.jstree.root) {
3995
+ if (this._model.data[$.jstree.root].children[0]) {
3996
+ this.get_node(this._model.data[$.jstree.root].children[0], true).children('.jstree-anchor').focus();
3997
+ }
3998
+ }
3999
+ else {
4000
+ this.get_node(par, true).children('.jstree-anchor').focus();
4001
+ }
4002
+ this.element[0].scrollTop = top;
4003
+ this.element[0].scrollLeft = lft;
4004
+ }
4005
+ this.redraw_node(par, true);
4006
+ return true;
4007
+ },
4008
+ /**
4009
+ * check if an operation is premitted on the tree. Used internally.
4010
+ * @private
4011
+ * @name check(chk, obj, par, pos)
4012
+ * @param {String} chk the operation to check, can be "create_node", "rename_node", "delete_node", "copy_node" or "move_node"
4013
+ * @param {mixed} obj the node
4014
+ * @param {mixed} par the parent
4015
+ * @param {mixed} pos the position to insert at, or if "rename_node" - the new name
4016
+ * @param {mixed} more some various additional information, for example if a "move_node" operations is triggered by DND this will be the hovered node
4017
+ * @return {Boolean}
4018
+ */
4019
+ check : function (chk, obj, par, pos, more) {
4020
+ obj = obj && obj.id ? obj : this.get_node(obj);
4021
+ par = par && par.id ? par : this.get_node(par);
4022
+ var tmp = chk.match(/^move_node|copy_node|create_node$/i) ? par : obj,
4023
+ chc = this.settings.core.check_callback;
4024
+ if(chk === "move_node" || chk === "copy_node") {
4025
+ if((!more || !more.is_multi) && (obj.id === par.id || (chk === "move_node" && $.inArray(obj.id, par.children) === pos) || $.inArray(par.id, obj.children_d) !== -1)) {
4026
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_01', 'reason' : 'Moving parent inside child', 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
4027
+ return false;
4028
+ }
4029
+ }
4030
+ if(tmp && tmp.data) { tmp = tmp.data; }
4031
+ if(tmp && tmp.functions && (tmp.functions[chk] === false || tmp.functions[chk] === true)) {
4032
+ if(tmp.functions[chk] === false) {
4033
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_02', 'reason' : 'Node data prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
4034
+ }
4035
+ return tmp.functions[chk];
4036
+ }
4037
+ if(chc === false || ($.isFunction(chc) && chc.call(this, chk, obj, par, pos, more) === false) || (chc && chc[chk] === false)) {
4038
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'core', 'id' : 'core_03', 'reason' : 'User config for core.check_callback prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
4039
+ return false;
4040
+ }
4041
+ return true;
4042
+ },
4043
+ /**
4044
+ * get the last error
4045
+ * @name last_error()
4046
+ * @return {Object}
4047
+ */
4048
+ last_error : function () {
4049
+ return this._data.core.last_error;
4050
+ },
4051
+ /**
4052
+ * move a node to a new parent
4053
+ * @name move_node(obj, par [, pos, callback, is_loaded])
4054
+ * @param {mixed} obj the node to move, pass an array to move multiple nodes
4055
+ * @param {mixed} par the new parent
4056
+ * @param {mixed} pos the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer `0`
4057
+ * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
4058
+ * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
4059
+ * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
4060
+ * @param {Boolean} instance internal parameter indicating if the node comes from another instance
4061
+ * @trigger move_node.jstree
4062
+ */
4063
+ move_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
4064
+ var t1, t2, old_par, old_pos, new_par, old_ins, is_multi, dpc, tmp, i, j, k, l, p;
4065
+
4066
+ par = this.get_node(par);
4067
+ pos = pos === undefined ? 0 : pos;
4068
+ if(!par) { return false; }
4069
+ if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
4070
+ return this.load_node(par, function () { this.move_node(obj, par, pos, callback, true, false, origin); });
4071
+ }
4072
+
4073
+ if($.isArray(obj)) {
4074
+ if(obj.length === 1) {
4075
+ obj = obj[0];
4076
+ }
4077
+ else {
4078
+ //obj = obj.slice();
4079
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4080
+ if((tmp = this.move_node(obj[t1], par, pos, callback, is_loaded, false, origin))) {
4081
+ par = tmp;
4082
+ pos = "after";
4083
+ }
4084
+ }
4085
+ this.redraw();
4086
+ return true;
4087
+ }
4088
+ }
4089
+ obj = obj && obj.id ? obj : this.get_node(obj);
4090
+
4091
+ if(!obj || obj.id === $.jstree.root) { return false; }
4092
+
4093
+ old_par = (obj.parent || $.jstree.root).toString();
4094
+ new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
4095
+ old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
4096
+ is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
4097
+ 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;
4098
+ if(old_ins && old_ins._id) {
4099
+ obj = old_ins._model.data[obj.id];
4100
+ }
4101
+
4102
+ if(is_multi) {
4103
+ if((tmp = this.copy_node(obj, par, pos, callback, is_loaded, false, origin))) {
4104
+ if(old_ins) { old_ins.delete_node(obj); }
4105
+ return tmp;
4106
+ }
4107
+ return false;
4108
+ }
4109
+ //var m = this._model.data;
4110
+ if(par.id === $.jstree.root) {
4111
+ if(pos === "before") { pos = "first"; }
4112
+ if(pos === "after") { pos = "last"; }
4113
+ }
4114
+ switch(pos) {
4115
+ case "before":
4116
+ pos = $.inArray(par.id, new_par.children);
4117
+ break;
4118
+ case "after" :
4119
+ pos = $.inArray(par.id, new_par.children) + 1;
4120
+ break;
4121
+ case "inside":
4122
+ case "first":
4123
+ pos = 0;
4124
+ break;
4125
+ case "last":
4126
+ pos = new_par.children.length;
4127
+ break;
4128
+ default:
4129
+ if(!pos) { pos = 0; }
4130
+ break;
4131
+ }
4132
+ if(pos > new_par.children.length) { pos = new_par.children.length; }
4133
+ if(!this.check("move_node", obj, new_par, pos, { 'core' : true, 'origin' : origin, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id) })) {
4134
+ this.settings.core.error.call(this, this._data.core.last_error);
4135
+ return false;
4136
+ }
4137
+ if(obj.parent === new_par.id) {
4138
+ dpc = new_par.children.concat();
4139
+ tmp = $.inArray(obj.id, dpc);
4140
+ if(tmp !== -1) {
4141
+ dpc = $.vakata.array_remove(dpc, tmp);
4142
+ if(pos > tmp) { pos--; }
4143
+ }
4144
+ tmp = [];
4145
+ for(i = 0, j = dpc.length; i < j; i++) {
4146
+ tmp[i >= pos ? i+1 : i] = dpc[i];
4147
+ }
4148
+ tmp[pos] = obj.id;
4149
+ new_par.children = tmp;
4150
+ this._node_changed(new_par.id);
4151
+ this.redraw(new_par.id === $.jstree.root);
4152
+ }
4153
+ else {
4154
+ // clean old parent and up
4155
+ tmp = obj.children_d.concat();
4156
+ tmp.push(obj.id);
4157
+ for(i = 0, j = obj.parents.length; i < j; i++) {
4158
+ dpc = [];
4159
+ p = old_ins._model.data[obj.parents[i]].children_d;
4160
+ for(k = 0, l = p.length; k < l; k++) {
4161
+ if($.inArray(p[k], tmp) === -1) {
4162
+ dpc.push(p[k]);
4163
+ }
4164
+ }
4165
+ old_ins._model.data[obj.parents[i]].children_d = dpc;
4166
+ }
4167
+ old_ins._model.data[old_par].children = $.vakata.array_remove_item(old_ins._model.data[old_par].children, obj.id);
4168
+
4169
+ // insert into new parent and up
4170
+ for(i = 0, j = new_par.parents.length; i < j; i++) {
4171
+ this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(tmp);
4172
+ }
4173
+ dpc = [];
4174
+ for(i = 0, j = new_par.children.length; i < j; i++) {
4175
+ dpc[i >= pos ? i+1 : i] = new_par.children[i];
4176
+ }
4177
+ dpc[pos] = obj.id;
4178
+ new_par.children = dpc;
4179
+ new_par.children_d.push(obj.id);
4180
+ new_par.children_d = new_par.children_d.concat(obj.children_d);
4181
+
4182
+ // update object
4183
+ obj.parent = new_par.id;
4184
+ tmp = new_par.parents.concat();
4185
+ tmp.unshift(new_par.id);
4186
+ p = obj.parents.length;
4187
+ obj.parents = tmp;
4188
+
4189
+ // update object children
4190
+ tmp = tmp.concat();
4191
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
4192
+ this._model.data[obj.children_d[i]].parents = this._model.data[obj.children_d[i]].parents.slice(0,p*-1);
4193
+ Array.prototype.push.apply(this._model.data[obj.children_d[i]].parents, tmp);
4194
+ }
4195
+
4196
+ if(old_par === $.jstree.root || new_par.id === $.jstree.root) {
4197
+ this._model.force_full_redraw = true;
4198
+ }
4199
+ if(!this._model.force_full_redraw) {
4200
+ this._node_changed(old_par);
4201
+ this._node_changed(new_par.id);
4202
+ }
4203
+ if(!skip_redraw) {
4204
+ this.redraw();
4205
+ }
4206
+ }
4207
+ if(callback) { callback.call(this, obj, new_par, pos); }
4208
+ /**
4209
+ * triggered when a node is moved
4210
+ * @event
4211
+ * @name move_node.jstree
4212
+ * @param {Object} node
4213
+ * @param {String} parent the parent's ID
4214
+ * @param {Number} position the position of the node among the parent's children
4215
+ * @param {String} old_parent the old parent of the node
4216
+ * @param {Number} old_position the old position of the node
4217
+ * @param {Boolean} is_multi do the node and new parent belong to different instances
4218
+ * @param {jsTree} old_instance the instance the node came from
4219
+ * @param {jsTree} new_instance the instance of the new parent
4220
+ */
4221
+ this.trigger('move_node', { "node" : obj, "parent" : new_par.id, "position" : pos, "old_parent" : old_par, "old_position" : old_pos, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id), 'old_instance' : old_ins, 'new_instance' : this });
4222
+ return obj.id;
4223
+ },
4224
+ /**
4225
+ * copy a node to a new parent
4226
+ * @name copy_node(obj, par [, pos, callback, is_loaded])
4227
+ * @param {mixed} obj the node to copy, pass an array to copy multiple nodes
4228
+ * @param {mixed} par the new parent
4229
+ * @param {mixed} pos the position to insert at (besides integer values, "first" and "last" are supported, as well as "before" and "after"), defaults to integer `0`
4230
+ * @param {function} callback a function to call once the move is completed, receives 3 arguments - the node, the new parent and the position
4231
+ * @param {Boolean} is_loaded internal parameter indicating if the parent node has been loaded
4232
+ * @param {Boolean} skip_redraw internal parameter indicating if the tree should be redrawn
4233
+ * @param {Boolean} instance internal parameter indicating if the node comes from another instance
4234
+ * @trigger model.jstree copy_node.jstree
4235
+ */
4236
+ copy_node : function (obj, par, pos, callback, is_loaded, skip_redraw, origin) {
4237
+ var t1, t2, dpc, tmp, i, j, node, old_par, new_par, old_ins, is_multi;
4238
+
4239
+ par = this.get_node(par);
4240
+ pos = pos === undefined ? 0 : pos;
4241
+ if(!par) { return false; }
4242
+ if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
4243
+ return this.load_node(par, function () { this.copy_node(obj, par, pos, callback, true, false, origin); });
4244
+ }
4245
+
4246
+ if($.isArray(obj)) {
4247
+ if(obj.length === 1) {
4248
+ obj = obj[0];
4249
+ }
4250
+ else {
4251
+ //obj = obj.slice();
4252
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4253
+ if((tmp = this.copy_node(obj[t1], par, pos, callback, is_loaded, true, origin))) {
4254
+ par = tmp;
4255
+ pos = "after";
4256
+ }
4257
+ }
4258
+ this.redraw();
4259
+ return true;
4260
+ }
4261
+ }
4262
+ obj = obj && obj.id ? obj : this.get_node(obj);
4263
+ if(!obj || obj.id === $.jstree.root) { return false; }
4264
+
4265
+ old_par = (obj.parent || $.jstree.root).toString();
4266
+ new_par = (!pos.toString().match(/^(before|after)$/) || par.id === $.jstree.root) ? par : this.get_node(par.parent);
4267
+ old_ins = origin ? origin : (this._model.data[obj.id] ? this : $.jstree.reference(obj.id));
4268
+ is_multi = !old_ins || !old_ins._id || (this._id !== old_ins._id);
4269
+
4270
+ if(old_ins && old_ins._id) {
4271
+ obj = old_ins._model.data[obj.id];
4272
+ }
4273
+
4274
+ if(par.id === $.jstree.root) {
4275
+ if(pos === "before") { pos = "first"; }
4276
+ if(pos === "after") { pos = "last"; }
4277
+ }
4278
+ switch(pos) {
4279
+ case "before":
4280
+ pos = $.inArray(par.id, new_par.children);
4281
+ break;
4282
+ case "after" :
4283
+ pos = $.inArray(par.id, new_par.children) + 1;
4284
+ break;
4285
+ case "inside":
4286
+ case "first":
4287
+ pos = 0;
4288
+ break;
4289
+ case "last":
4290
+ pos = new_par.children.length;
4291
+ break;
4292
+ default:
4293
+ if(!pos) { pos = 0; }
4294
+ break;
4295
+ }
4296
+ if(pos > new_par.children.length) { pos = new_par.children.length; }
4297
+ if(!this.check("copy_node", obj, new_par, pos, { 'core' : true, 'origin' : origin, 'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id) })) {
4298
+ this.settings.core.error.call(this, this._data.core.last_error);
4299
+ return false;
4300
+ }
4301
+ node = old_ins ? old_ins.get_json(obj, { no_id : true, no_data : true, no_state : true }) : obj;
4302
+ if(!node) { return false; }
4303
+ if(node.id === true) { delete node.id; }
4304
+ node = this._parse_model_from_json(node, new_par.id, new_par.parents.concat());
4305
+ if(!node) { return false; }
4306
+ tmp = this.get_node(node);
4307
+ if(obj && obj.state && obj.state.loaded === false) { tmp.state.loaded = false; }
4308
+ dpc = [];
4309
+ dpc.push(node);
4310
+ dpc = dpc.concat(tmp.children_d);
4311
+ this.trigger('model', { "nodes" : dpc, "parent" : new_par.id });
4312
+
4313
+ // insert into new parent and up
4314
+ for(i = 0, j = new_par.parents.length; i < j; i++) {
4315
+ this._model.data[new_par.parents[i]].children_d = this._model.data[new_par.parents[i]].children_d.concat(dpc);
4316
+ }
4317
+ dpc = [];
4318
+ for(i = 0, j = new_par.children.length; i < j; i++) {
4319
+ dpc[i >= pos ? i+1 : i] = new_par.children[i];
4320
+ }
4321
+ dpc[pos] = tmp.id;
4322
+ new_par.children = dpc;
4323
+ new_par.children_d.push(tmp.id);
4324
+ new_par.children_d = new_par.children_d.concat(tmp.children_d);
4325
+
4326
+ if(new_par.id === $.jstree.root) {
4327
+ this._model.force_full_redraw = true;
4328
+ }
4329
+ if(!this._model.force_full_redraw) {
4330
+ this._node_changed(new_par.id);
4331
+ }
4332
+ if(!skip_redraw) {
4333
+ this.redraw(new_par.id === $.jstree.root);
4334
+ }
4335
+ if(callback) { callback.call(this, tmp, new_par, pos); }
4336
+ /**
4337
+ * triggered when a node is copied
4338
+ * @event
4339
+ * @name copy_node.jstree
4340
+ * @param {Object} node the copied node
4341
+ * @param {Object} original the original node
4342
+ * @param {String} parent the parent's ID
4343
+ * @param {Number} position the position of the node among the parent's children
4344
+ * @param {String} old_parent the old parent of the node
4345
+ * @param {Number} old_position the position of the original node
4346
+ * @param {Boolean} is_multi do the node and new parent belong to different instances
4347
+ * @param {jsTree} old_instance the instance the node came from
4348
+ * @param {jsTree} new_instance the instance of the new parent
4349
+ */
4350
+ this.trigger('copy_node', { "node" : tmp, "original" : obj, "parent" : new_par.id, "position" : pos, "old_parent" : old_par, "old_position" : 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,'is_multi' : (old_ins && old_ins._id && old_ins._id !== this._id), 'is_foreign' : (!old_ins || !old_ins._id), 'old_instance' : old_ins, 'new_instance' : this });
4351
+ return tmp.id;
4352
+ },
4353
+ /**
4354
+ * cut a node (a later call to `paste(obj)` would move the node)
4355
+ * @name cut(obj)
4356
+ * @param {mixed} obj multiple objects can be passed using an array
4357
+ * @trigger cut.jstree
4358
+ */
4359
+ cut : function (obj) {
4360
+ if(!obj) { obj = this._data.core.selected.concat(); }
4361
+ if(!$.isArray(obj)) { obj = [obj]; }
4362
+ if(!obj.length) { return false; }
4363
+ var tmp = [], o, t1, t2;
4364
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4365
+ o = this.get_node(obj[t1]);
4366
+ if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
4367
+ }
4368
+ if(!tmp.length) { return false; }
4369
+ ccp_node = tmp;
4370
+ ccp_inst = this;
4371
+ ccp_mode = 'move_node';
4372
+ /**
4373
+ * triggered when nodes are added to the buffer for moving
4374
+ * @event
4375
+ * @name cut.jstree
4376
+ * @param {Array} node
4377
+ */
4378
+ this.trigger('cut', { "node" : obj });
4379
+ },
4380
+ /**
4381
+ * copy a node (a later call to `paste(obj)` would copy the node)
4382
+ * @name copy(obj)
4383
+ * @param {mixed} obj multiple objects can be passed using an array
4384
+ * @trigger copy.jstree
4385
+ */
4386
+ copy : function (obj) {
4387
+ if(!obj) { obj = this._data.core.selected.concat(); }
4388
+ if(!$.isArray(obj)) { obj = [obj]; }
4389
+ if(!obj.length) { return false; }
4390
+ var tmp = [], o, t1, t2;
4391
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4392
+ o = this.get_node(obj[t1]);
4393
+ if(o && o.id && o.id !== $.jstree.root) { tmp.push(o); }
4394
+ }
4395
+ if(!tmp.length) { return false; }
4396
+ ccp_node = tmp;
4397
+ ccp_inst = this;
4398
+ ccp_mode = 'copy_node';
4399
+ /**
4400
+ * triggered when nodes are added to the buffer for copying
4401
+ * @event
4402
+ * @name copy.jstree
4403
+ * @param {Array} node
4404
+ */
4405
+ this.trigger('copy', { "node" : obj });
4406
+ },
4407
+ /**
4408
+ * get the current buffer (any nodes that are waiting for a paste operation)
4409
+ * @name get_buffer()
4410
+ * @return {Object} an object consisting of `mode` ("copy_node" or "move_node"), `node` (an array of objects) and `inst` (the instance)
4411
+ */
4412
+ get_buffer : function () {
4413
+ return { 'mode' : ccp_mode, 'node' : ccp_node, 'inst' : ccp_inst };
4414
+ },
4415
+ /**
4416
+ * check if there is something in the buffer to paste
4417
+ * @name can_paste()
4418
+ * @return {Boolean}
4419
+ */
4420
+ can_paste : function () {
4421
+ return ccp_mode !== false && ccp_node !== false; // && ccp_inst._model.data[ccp_node];
4422
+ },
4423
+ /**
4424
+ * copy or move the previously cut or copied nodes to a new parent
4425
+ * @name paste(obj [, pos])
4426
+ * @param {mixed} obj the new parent
4427
+ * @param {mixed} pos the position to insert at (besides integer, "first" and "last" are supported), defaults to integer `0`
4428
+ * @trigger paste.jstree
4429
+ */
4430
+ paste : function (obj, pos) {
4431
+ obj = this.get_node(obj);
4432
+ if(!obj || !ccp_mode || !ccp_mode.match(/^(copy_node|move_node)$/) || !ccp_node) { return false; }
4433
+ if(this[ccp_mode](ccp_node, obj, pos, false, false, false, ccp_inst)) {
4434
+ /**
4435
+ * triggered when paste is invoked
4436
+ * @event
4437
+ * @name paste.jstree
4438
+ * @param {String} parent the ID of the receiving node
4439
+ * @param {Array} node the nodes in the buffer
4440
+ * @param {String} mode the performed operation - "copy_node" or "move_node"
4441
+ */
4442
+ this.trigger('paste', { "parent" : obj.id, "node" : ccp_node, "mode" : ccp_mode });
4443
+ }
4444
+ ccp_node = false;
4445
+ ccp_mode = false;
4446
+ ccp_inst = false;
4447
+ },
4448
+ /**
4449
+ * clear the buffer of previously copied or cut nodes
4450
+ * @name clear_buffer()
4451
+ * @trigger clear_buffer.jstree
4452
+ */
4453
+ clear_buffer : function () {
4454
+ ccp_node = false;
4455
+ ccp_mode = false;
4456
+ ccp_inst = false;
4457
+ /**
4458
+ * triggered when the copy / cut buffer is cleared
4459
+ * @event
4460
+ * @name clear_buffer.jstree
4461
+ */
4462
+ this.trigger('clear_buffer');
4463
+ },
4464
+ /**
4465
+ * put a node in edit mode (input field to rename the node)
4466
+ * @name edit(obj [, default_text, callback])
4467
+ * @param {mixed} obj
4468
+ * @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)
4469
+ * @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, a status parameter (true if the rename is successful, false otherwise) and a boolean indicating if the user cancelled the edit. You can access the node's title using .text
4470
+ */
4471
+ edit : function (obj, default_text, callback) {
4472
+ var rtl, w, a, s, t, h1, h2, fn, tmp, cancel = false;
4473
+ obj = this.get_node(obj);
4474
+ if(!obj) { return false; }
4475
+ if(!this.check("edit", obj, this.get_parent(obj))) {
4476
+ this.settings.core.error.call(this, this._data.core.last_error);
4477
+ return false;
4478
+ }
4479
+ tmp = obj;
4480
+ default_text = typeof default_text === 'string' ? default_text : obj.text;
4481
+ this.set_text(obj, "");
4482
+ obj = this._open_to(obj);
4483
+ tmp.text = default_text;
4484
+
4485
+ rtl = this._data.core.rtl;
4486
+ w = this.element.width();
4487
+ this._data.core.focused = tmp.id;
4488
+ a = obj.children('.jstree-anchor').focus();
4489
+ s = $('<span>');
4490
+ /*!
4491
+ oi = obj.children("i:visible"),
4492
+ ai = a.children("i:visible"),
4493
+ w1 = oi.width() * oi.length,
4494
+ w2 = ai.width() * ai.length,
4495
+ */
4496
+ t = default_text;
4497
+ h1 = $("<"+"div />", { css : { "position" : "absolute", "top" : "-200px", "left" : (rtl ? "0px" : "-1000px"), "visibility" : "hidden" } }).appendTo(document.body);
4498
+ h2 = $("<"+"input />", {
4499
+ "value" : t,
4500
+ "class" : "jstree-rename-input",
4501
+ // "size" : t.length,
4502
+ "css" : {
4503
+ "padding" : "0",
4504
+ "border" : "1px solid silver",
4505
+ "box-sizing" : "border-box",
4506
+ "display" : "inline-block",
4507
+ "height" : (this._data.core.li_height) + "px",
4508
+ "lineHeight" : (this._data.core.li_height) + "px",
4509
+ "width" : "150px" // will be set a bit further down
4510
+ },
4511
+ "blur" : $.proxy(function (e) {
4512
+ e.stopImmediatePropagation();
4513
+ e.preventDefault();
4514
+ var i = s.children(".jstree-rename-input"),
4515
+ v = i.val(),
4516
+ f = this.settings.core.force_text,
4517
+ nv;
4518
+ if(v === "") { v = t; }
4519
+ h1.remove();
4520
+ s.replaceWith(a);
4521
+ s.remove();
4522
+ t = f ? t : $('<div></div>').append($.parseHTML(t)).html();
4523
+ obj = this.get_node(obj);
4524
+ this.set_text(obj, t);
4525
+ nv = !!this.rename_node(obj, f ? $('<div></div>').text(v).text() : $('<div></div>').append($.parseHTML(v)).html());
4526
+ if(!nv) {
4527
+ this.set_text(obj, t); // move this up? and fix #483
4528
+ }
4529
+ this._data.core.focused = tmp.id;
4530
+ setTimeout($.proxy(function () {
4531
+ var node = this.get_node(tmp.id, true);
4532
+ if(node.length) {
4533
+ this._data.core.focused = tmp.id;
4534
+ node.children('.jstree-anchor').focus();
4535
+ }
4536
+ }, this), 0);
4537
+ if(callback) {
4538
+ callback.call(this, tmp, nv, cancel);
4539
+ }
4540
+ h2 = null;
4541
+ }, this),
4542
+ "keydown" : function (e) {
4543
+ var key = e.which;
4544
+ if(key === 27) {
4545
+ cancel = true;
4546
+ this.value = t;
4547
+ }
4548
+ if(key === 27 || key === 13 || key === 37 || key === 38 || key === 39 || key === 40 || key === 32) {
4549
+ e.stopImmediatePropagation();
4550
+ }
4551
+ if(key === 27 || key === 13) {
4552
+ e.preventDefault();
4553
+ this.blur();
4554
+ }
4555
+ },
4556
+ "click" : function (e) { e.stopImmediatePropagation(); },
4557
+ "mousedown" : function (e) { e.stopImmediatePropagation(); },
4558
+ "keyup" : function (e) {
4559
+ h2.width(Math.min(h1.text("pW" + this.value).width(),w));
4560
+ },
4561
+ "keypress" : function(e) {
4562
+ if(e.which === 13) { return false; }
4563
+ }
4564
+ });
4565
+ fn = {
4566
+ fontFamily : a.css('fontFamily') || '',
4567
+ fontSize : a.css('fontSize') || '',
4568
+ fontWeight : a.css('fontWeight') || '',
4569
+ fontStyle : a.css('fontStyle') || '',
4570
+ fontStretch : a.css('fontStretch') || '',
4571
+ fontVariant : a.css('fontVariant') || '',
4572
+ letterSpacing : a.css('letterSpacing') || '',
4573
+ wordSpacing : a.css('wordSpacing') || ''
4574
+ };
4575
+ s.attr('class', a.attr('class')).append(a.contents().clone()).append(h2);
4576
+ a.replaceWith(s);
4577
+ h1.css(fn);
4578
+ h2.css(fn).width(Math.min(h1.text("pW" + h2[0].value).width(),w))[0].select();
4579
+ $(document).one('mousedown.jstree touchstart.jstree dnd_start.vakata', function (e) {
4580
+ if (h2 && e.target !== h2) {
4581
+ $(h2).blur();
4582
+ }
4583
+ });
4584
+ },
4585
+
4586
+
4587
+ /**
4588
+ * changes the theme
4589
+ * @name set_theme(theme_name [, theme_url])
4590
+ * @param {String} theme_name the name of the new theme to apply
4591
+ * @param {mixed} theme_url the location of the CSS file for this theme. Omit or set to `false` if you manually included the file. Set to `true` to autoload from the `core.themes.dir` directory.
4592
+ * @trigger set_theme.jstree
4593
+ */
4594
+ set_theme : function (theme_name, theme_url) {
4595
+ if(!theme_name) { return false; }
4596
+ if(theme_url === true) {
4597
+ var dir = this.settings.core.themes.dir;
4598
+ if(!dir) { dir = $.jstree.path + '/themes'; }
4599
+ theme_url = dir + '/' + theme_name + '/style.css';
4600
+ }
4601
+ if(theme_url && $.inArray(theme_url, themes_loaded) === -1) {
4602
+ $('head').append('<'+'link rel="stylesheet" href="' + theme_url + '" type="text/css" />');
4603
+ themes_loaded.push(theme_url);
4604
+ }
4605
+ if(this._data.core.themes.name) {
4606
+ this.element.removeClass('jstree-' + this._data.core.themes.name);
4607
+ }
4608
+ this._data.core.themes.name = theme_name;
4609
+ this.element.addClass('jstree-' + theme_name);
4610
+ this.element[this.settings.core.themes.responsive ? 'addClass' : 'removeClass' ]('jstree-' + theme_name + '-responsive');
4611
+ /**
4612
+ * triggered when a theme is set
4613
+ * @event
4614
+ * @name set_theme.jstree
4615
+ * @param {String} theme the new theme
4616
+ */
4617
+ this.trigger('set_theme', { 'theme' : theme_name });
4618
+ },
4619
+ /**
4620
+ * gets the name of the currently applied theme name
4621
+ * @name get_theme()
4622
+ * @return {String}
4623
+ */
4624
+ get_theme : function () { return this._data.core.themes.name; },
4625
+ /**
4626
+ * changes the theme variant (if the theme has variants)
4627
+ * @name set_theme_variant(variant_name)
4628
+ * @param {String|Boolean} variant_name the variant to apply (if `false` is used the current variant is removed)
4629
+ */
4630
+ set_theme_variant : function (variant_name) {
4631
+ if(this._data.core.themes.variant) {
4632
+ this.element.removeClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
4633
+ }
4634
+ this._data.core.themes.variant = variant_name;
4635
+ if(variant_name) {
4636
+ this.element.addClass('jstree-' + this._data.core.themes.name + '-' + this._data.core.themes.variant);
4637
+ }
4638
+ },
4639
+ /**
4640
+ * gets the name of the currently applied theme variant
4641
+ * @name get_theme()
4642
+ * @return {String}
4643
+ */
4644
+ get_theme_variant : function () { return this._data.core.themes.variant; },
4645
+ /**
4646
+ * shows a striped background on the container (if the theme supports it)
4647
+ * @name show_stripes()
4648
+ */
4649
+ show_stripes : function () {
4650
+ this._data.core.themes.stripes = true;
4651
+ this.get_container_ul().addClass("jstree-striped");
4652
+ /**
4653
+ * triggered when stripes are shown
4654
+ * @event
4655
+ * @name show_stripes.jstree
4656
+ */
4657
+ this.trigger('show_stripes');
4658
+ },
4659
+ /**
4660
+ * hides the striped background on the container
4661
+ * @name hide_stripes()
4662
+ */
4663
+ hide_stripes : function () {
4664
+ this._data.core.themes.stripes = false;
4665
+ this.get_container_ul().removeClass("jstree-striped");
4666
+ /**
4667
+ * triggered when stripes are hidden
4668
+ * @event
4669
+ * @name hide_stripes.jstree
4670
+ */
4671
+ this.trigger('hide_stripes');
4672
+ },
4673
+ /**
4674
+ * toggles the striped background on the container
4675
+ * @name toggle_stripes()
4676
+ */
4677
+ toggle_stripes : function () { if(this._data.core.themes.stripes) { this.hide_stripes(); } else { this.show_stripes(); } },
4678
+ /**
4679
+ * shows the connecting dots (if the theme supports it)
4680
+ * @name show_dots()
4681
+ */
4682
+ show_dots : function () {
4683
+ this._data.core.themes.dots = true;
4684
+ this.get_container_ul().removeClass("jstree-no-dots");
4685
+ /**
4686
+ * triggered when dots are shown
4687
+ * @event
4688
+ * @name show_dots.jstree
4689
+ */
4690
+ this.trigger('show_dots');
4691
+ },
4692
+ /**
4693
+ * hides the connecting dots
4694
+ * @name hide_dots()
4695
+ */
4696
+ hide_dots : function () {
4697
+ this._data.core.themes.dots = false;
4698
+ this.get_container_ul().addClass("jstree-no-dots");
4699
+ /**
4700
+ * triggered when dots are hidden
4701
+ * @event
4702
+ * @name hide_dots.jstree
4703
+ */
4704
+ this.trigger('hide_dots');
4705
+ },
4706
+ /**
4707
+ * toggles the connecting dots
4708
+ * @name toggle_dots()
4709
+ */
4710
+ toggle_dots : function () { if(this._data.core.themes.dots) { this.hide_dots(); } else { this.show_dots(); } },
4711
+ /**
4712
+ * show the node icons
4713
+ * @name show_icons()
4714
+ */
4715
+ show_icons : function () {
4716
+ this._data.core.themes.icons = true;
4717
+ this.get_container_ul().removeClass("jstree-no-icons");
4718
+ /**
4719
+ * triggered when icons are shown
4720
+ * @event
4721
+ * @name show_icons.jstree
4722
+ */
4723
+ this.trigger('show_icons');
4724
+ },
4725
+ /**
4726
+ * hide the node icons
4727
+ * @name hide_icons()
4728
+ */
4729
+ hide_icons : function () {
4730
+ this._data.core.themes.icons = false;
4731
+ this.get_container_ul().addClass("jstree-no-icons");
4732
+ /**
4733
+ * triggered when icons are hidden
4734
+ * @event
4735
+ * @name hide_icons.jstree
4736
+ */
4737
+ this.trigger('hide_icons');
4738
+ },
4739
+ /**
4740
+ * toggle the node icons
4741
+ * @name toggle_icons()
4742
+ */
4743
+ toggle_icons : function () { if(this._data.core.themes.icons) { this.hide_icons(); } else { this.show_icons(); } },
4744
+ /**
4745
+ * show the node ellipsis
4746
+ * @name show_icons()
4747
+ */
4748
+ show_ellipsis : function () {
4749
+ this._data.core.themes.ellipsis = true;
4750
+ this.get_container_ul().addClass("jstree-ellipsis");
4751
+ /**
4752
+ * triggered when ellisis is shown
4753
+ * @event
4754
+ * @name show_ellipsis.jstree
4755
+ */
4756
+ this.trigger('show_ellipsis');
4757
+ },
4758
+ /**
4759
+ * hide the node ellipsis
4760
+ * @name hide_ellipsis()
4761
+ */
4762
+ hide_ellipsis : function () {
4763
+ this._data.core.themes.ellipsis = false;
4764
+ this.get_container_ul().removeClass("jstree-ellipsis");
4765
+ /**
4766
+ * triggered when ellisis is hidden
4767
+ * @event
4768
+ * @name hide_ellipsis.jstree
4769
+ */
4770
+ this.trigger('hide_ellipsis');
4771
+ },
4772
+ /**
4773
+ * toggle the node ellipsis
4774
+ * @name toggle_icons()
4775
+ */
4776
+ toggle_ellipsis : function () { if(this._data.core.themes.ellipsis) { this.hide_ellipsis(); } else { this.show_ellipsis(); } },
4777
+ /**
4778
+ * set the node icon for a node
4779
+ * @name set_icon(obj, icon)
4780
+ * @param {mixed} obj
4781
+ * @param {String} icon the new icon - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
4782
+ */
4783
+ set_icon : function (obj, icon) {
4784
+ var t1, t2, dom, old;
4785
+ if($.isArray(obj)) {
4786
+ obj = obj.slice();
4787
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4788
+ this.set_icon(obj[t1], icon);
4789
+ }
4790
+ return true;
4791
+ }
4792
+ obj = this.get_node(obj);
4793
+ if(!obj || obj.id === $.jstree.root) { return false; }
4794
+ old = obj.icon;
4795
+ obj.icon = icon === true || icon === null || icon === undefined || icon === '' ? true : icon;
4796
+ dom = this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon");
4797
+ if(icon === false) {
4798
+ dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
4799
+ this.hide_icon(obj);
4800
+ }
4801
+ else if(icon === true || icon === null || icon === undefined || icon === '') {
4802
+ dom.removeClass('jstree-themeicon-custom ' + old).css("background","").removeAttr("rel");
4803
+ if(old === false) { this.show_icon(obj); }
4804
+ }
4805
+ else if(icon.indexOf("/") === -1 && icon.indexOf(".") === -1) {
4806
+ dom.removeClass(old).css("background","");
4807
+ dom.addClass(icon + ' jstree-themeicon-custom').attr("rel",icon);
4808
+ if(old === false) { this.show_icon(obj); }
4809
+ }
4810
+ else {
4811
+ dom.removeClass(old).css("background","");
4812
+ dom.addClass('jstree-themeicon-custom').css("background", "url('" + icon + "') center center no-repeat").attr("rel",icon);
4813
+ if(old === false) { this.show_icon(obj); }
4814
+ }
4815
+ return true;
4816
+ },
4817
+ /**
4818
+ * get the node icon for a node
4819
+ * @name get_icon(obj)
4820
+ * @param {mixed} obj
4821
+ * @return {String}
4822
+ */
4823
+ get_icon : function (obj) {
4824
+ obj = this.get_node(obj);
4825
+ return (!obj || obj.id === $.jstree.root) ? false : obj.icon;
4826
+ },
4827
+ /**
4828
+ * hide the icon on an individual node
4829
+ * @name hide_icon(obj)
4830
+ * @param {mixed} obj
4831
+ */
4832
+ hide_icon : function (obj) {
4833
+ var t1, t2;
4834
+ if($.isArray(obj)) {
4835
+ obj = obj.slice();
4836
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4837
+ this.hide_icon(obj[t1]);
4838
+ }
4839
+ return true;
4840
+ }
4841
+ obj = this.get_node(obj);
4842
+ if(!obj || obj === $.jstree.root) { return false; }
4843
+ obj.icon = false;
4844
+ this.get_node(obj, true).children(".jstree-anchor").children(".jstree-themeicon").addClass('jstree-themeicon-hidden');
4845
+ return true;
4846
+ },
4847
+ /**
4848
+ * show the icon on an individual node
4849
+ * @name show_icon(obj)
4850
+ * @param {mixed} obj
4851
+ */
4852
+ show_icon : function (obj) {
4853
+ var t1, t2, dom;
4854
+ if($.isArray(obj)) {
4855
+ obj = obj.slice();
4856
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
4857
+ this.show_icon(obj[t1]);
4858
+ }
4859
+ return true;
4860
+ }
4861
+ obj = this.get_node(obj);
4862
+ if(!obj || obj === $.jstree.root) { return false; }
4863
+ dom = this.get_node(obj, true);
4864
+ obj.icon = dom.length ? dom.children(".jstree-anchor").children(".jstree-themeicon").attr('rel') : true;
4865
+ if(!obj.icon) { obj.icon = true; }
4866
+ dom.children(".jstree-anchor").children(".jstree-themeicon").removeClass('jstree-themeicon-hidden');
4867
+ return true;
4868
+ }
4869
+ };
4870
+
4871
+ // helpers
4872
+ $.vakata = {};
4873
+ // collect attributes
4874
+ $.vakata.attributes = function(node, with_values) {
4875
+ node = $(node)[0];
4876
+ var attr = with_values ? {} : [];
4877
+ if(node && node.attributes) {
4878
+ $.each(node.attributes, function (i, v) {
4879
+ if($.inArray(v.name.toLowerCase(),['style','contenteditable','hasfocus','tabindex']) !== -1) { return; }
4880
+ if(v.value !== null && $.trim(v.value) !== '') {
4881
+ if(with_values) { attr[v.name] = v.value; }
4882
+ else { attr.push(v.name); }
4883
+ }
4884
+ });
4885
+ }
4886
+ return attr;
4887
+ };
4888
+ $.vakata.array_unique = function(array) {
4889
+ var a = [], i, j, l, o = {};
4890
+ for(i = 0, l = array.length; i < l; i++) {
4891
+ if(o[array[i]] === undefined) {
4892
+ a.push(array[i]);
4893
+ o[array[i]] = true;
4894
+ }
4895
+ }
4896
+ return a;
4897
+ };
4898
+ // remove item from array
4899
+ $.vakata.array_remove = function(array, from) {
4900
+ array.splice(from, 1);
4901
+ return array;
4902
+ //var rest = array.slice((to || from) + 1 || array.length);
4903
+ //array.length = from < 0 ? array.length + from : from;
4904
+ //array.push.apply(array, rest);
4905
+ //return array;
4906
+ };
4907
+ // remove item from array
4908
+ $.vakata.array_remove_item = function(array, item) {
4909
+ var tmp = $.inArray(item, array);
4910
+ return tmp !== -1 ? $.vakata.array_remove(array, tmp) : array;
4911
+ };
4912
+ $.vakata.array_filter = function(c,a,b,d,e) {
4913
+ if (c.filter) {
4914
+ return c.filter(a, b);
4915
+ }
4916
+ d=[];
4917
+ for (e in c) {
4918
+ if (~~e+''===e+'' && e>=0 && a.call(b,c[e],+e,c)) {
4919
+ d.push(c[e]);
4920
+ }
4921
+ }
4922
+ return d;
4923
+ };
4924
+
4925
+
4926
+ /**
4927
+ * ### Changed plugin
4928
+ *
4929
+ * This plugin adds more information to the `changed.jstree` event. The new data is contained in the `changed` event data property, and contains a lists of `selected` and `deselected` nodes.
4930
+ */
4931
+
4932
+ $.jstree.plugins.changed = function (options, parent) {
4933
+ var last = [];
4934
+ this.trigger = function (ev, data) {
4935
+ var i, j;
4936
+ if(!data) {
4937
+ data = {};
4938
+ }
4939
+ if(ev.replace('.jstree','') === 'changed') {
4940
+ data.changed = { selected : [], deselected : [] };
4941
+ var tmp = {};
4942
+ for(i = 0, j = last.length; i < j; i++) {
4943
+ tmp[last[i]] = 1;
4944
+ }
4945
+ for(i = 0, j = data.selected.length; i < j; i++) {
4946
+ if(!tmp[data.selected[i]]) {
4947
+ data.changed.selected.push(data.selected[i]);
4948
+ }
4949
+ else {
4950
+ tmp[data.selected[i]] = 2;
4951
+ }
4952
+ }
4953
+ for(i = 0, j = last.length; i < j; i++) {
4954
+ if(tmp[last[i]] === 1) {
4955
+ data.changed.deselected.push(last[i]);
4956
+ }
4957
+ }
4958
+ last = data.selected.slice();
4959
+ }
4960
+ /**
4961
+ * triggered when selection changes (the "changed" plugin enhances the original event with more data)
4962
+ * @event
4963
+ * @name changed.jstree
4964
+ * @param {Object} node
4965
+ * @param {Object} action the action that caused the selection to change
4966
+ * @param {Array} selected the current selection
4967
+ * @param {Object} changed an object containing two properties `selected` and `deselected` - both arrays of node IDs, which were selected or deselected since the last changed event
4968
+ * @param {Object} event the event (if any) that triggered this changed event
4969
+ * @plugin changed
4970
+ */
4971
+ parent.trigger.call(this, ev, data);
4972
+ };
4973
+ this.refresh = function (skip_loading, forget_state) {
4974
+ last = [];
4975
+ return parent.refresh.apply(this, arguments);
4976
+ };
4977
+ };
4978
+
4979
+ /**
4980
+ * ### Checkbox plugin
4981
+ *
4982
+ * This plugin renders checkbox icons in front of each node, making multiple selection much easier.
4983
+ * It also supports tri-state behavior, meaning that if a node has a few of its children checked it will be rendered as undetermined, and state will be propagated up.
4984
+ */
4985
+
4986
+ var _i = document.createElement('I');
4987
+ _i.className = 'jstree-icon jstree-checkbox';
4988
+ _i.setAttribute('role', 'presentation');
4989
+ /**
4990
+ * stores all defaults for the checkbox plugin
4991
+ * @name $.jstree.defaults.checkbox
4992
+ * @plugin checkbox
4993
+ */
4994
+ $.jstree.defaults.checkbox = {
4995
+ /**
4996
+ * a boolean indicating if checkboxes should be visible (can be changed at a later time using `show_checkboxes()` and `hide_checkboxes`). Defaults to `true`.
4997
+ * @name $.jstree.defaults.checkbox.visible
4998
+ * @plugin checkbox
4999
+ */
5000
+ visible : true,
5001
+ /**
5002
+ * a boolean indicating if checkboxes should cascade down and have an undetermined state. Defaults to `true`.
5003
+ * @name $.jstree.defaults.checkbox.three_state
5004
+ * @plugin checkbox
5005
+ */
5006
+ three_state : true,
5007
+ /**
5008
+ * a boolean indicating if clicking anywhere on the node should act as clicking on the checkbox. Defaults to `true`.
5009
+ * @name $.jstree.defaults.checkbox.whole_node
5010
+ * @plugin checkbox
5011
+ */
5012
+ whole_node : true,
5013
+ /**
5014
+ * a boolean indicating if the selected style of a node should be kept, or removed. Defaults to `true`.
5015
+ * @name $.jstree.defaults.checkbox.keep_selected_style
5016
+ * @plugin checkbox
5017
+ */
5018
+ keep_selected_style : true,
5019
+ /**
5020
+ * This setting controls how cascading and undetermined nodes are applied.
5021
+ * If 'up' is in the string - cascading up is enabled, if 'down' is in the string - cascading down is enabled, if 'undetermined' is in the string - undetermined nodes will be used.
5022
+ * If `three_state` is set to `true` this setting is automatically set to 'up+down+undetermined'. Defaults to ''.
5023
+ * @name $.jstree.defaults.checkbox.cascade
5024
+ * @plugin checkbox
5025
+ */
5026
+ cascade : '',
5027
+ /**
5028
+ * This setting controls if checkbox are bound to the general tree selection or to an internal array maintained by the checkbox plugin. Defaults to `true`, only set to `false` if you know exactly what you are doing.
5029
+ * @name $.jstree.defaults.checkbox.tie_selection
5030
+ * @plugin checkbox
5031
+ */
5032
+ tie_selection : true,
5033
+
5034
+ /**
5035
+ * This setting controls if cascading down affects disabled checkboxes
5036
+ * @name $.jstree.defaults.checkbox.cascade_to_disabled
5037
+ * @plugin checkbox
5038
+ */
5039
+ cascade_to_disabled : true,
5040
+
5041
+ /**
5042
+ * This setting controls if cascading down affects hidden checkboxes
5043
+ * @name $.jstree.defaults.checkbox.cascade_to_hidden
5044
+ * @plugin checkbox
5045
+ */
5046
+ cascade_to_hidden : true
5047
+ };
5048
+ $.jstree.plugins.checkbox = function (options, parent) {
5049
+ this.bind = function () {
5050
+ parent.bind.call(this);
5051
+ this._data.checkbox.uto = false;
5052
+ this._data.checkbox.selected = [];
5053
+ if(this.settings.checkbox.three_state) {
5054
+ this.settings.checkbox.cascade = 'up+down+undetermined';
5055
+ }
5056
+ this.element
5057
+ .on("init.jstree", $.proxy(function () {
5058
+ this._data.checkbox.visible = this.settings.checkbox.visible;
5059
+ if(!this.settings.checkbox.keep_selected_style) {
5060
+ this.element.addClass('jstree-checkbox-no-clicked');
5061
+ }
5062
+ if(this.settings.checkbox.tie_selection) {
5063
+ this.element.addClass('jstree-checkbox-selection');
5064
+ }
5065
+ }, this))
5066
+ .on("loading.jstree", $.proxy(function () {
5067
+ this[ this._data.checkbox.visible ? 'show_checkboxes' : 'hide_checkboxes' ]();
5068
+ }, this));
5069
+ if(this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
5070
+ this.element
5071
+ .on('changed.jstree uncheck_node.jstree check_node.jstree uncheck_all.jstree check_all.jstree move_node.jstree copy_node.jstree redraw.jstree open_node.jstree', $.proxy(function () {
5072
+ // only if undetermined is in setting
5073
+ if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
5074
+ this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
5075
+ }, this));
5076
+ }
5077
+ if(!this.settings.checkbox.tie_selection) {
5078
+ this.element
5079
+ .on('model.jstree', $.proxy(function (e, data) {
5080
+ var m = this._model.data,
5081
+ p = m[data.parent],
5082
+ dpc = data.nodes,
5083
+ i, j;
5084
+ for(i = 0, j = dpc.length; i < j; i++) {
5085
+ m[dpc[i]].state.checked = m[dpc[i]].state.checked || (m[dpc[i]].original && m[dpc[i]].original.state && m[dpc[i]].original.state.checked);
5086
+ if(m[dpc[i]].state.checked) {
5087
+ this._data.checkbox.selected.push(dpc[i]);
5088
+ }
5089
+ }
5090
+ }, this));
5091
+ }
5092
+ if(this.settings.checkbox.cascade.indexOf('up') !== -1 || this.settings.checkbox.cascade.indexOf('down') !== -1) {
5093
+ this.element
5094
+ .on('model.jstree', $.proxy(function (e, data) {
5095
+ var m = this._model.data,
5096
+ p = m[data.parent],
5097
+ dpc = data.nodes,
5098
+ chd = [],
5099
+ c, i, j, k, l, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection;
5100
+
5101
+ if(s.indexOf('down') !== -1) {
5102
+ // apply down
5103
+ if(p.state[ t ? 'selected' : 'checked' ]) {
5104
+ for(i = 0, j = dpc.length; i < j; i++) {
5105
+ m[dpc[i]].state[ t ? 'selected' : 'checked' ] = true;
5106
+ }
5107
+
5108
+ this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(dpc);
5109
+ }
5110
+ else {
5111
+ for(i = 0, j = dpc.length; i < j; i++) {
5112
+ if(m[dpc[i]].state[ t ? 'selected' : 'checked' ]) {
5113
+ for(k = 0, l = m[dpc[i]].children_d.length; k < l; k++) {
5114
+ m[m[dpc[i]].children_d[k]].state[ t ? 'selected' : 'checked' ] = true;
5115
+ }
5116
+ this._data[ t ? 'core' : 'checkbox' ].selected = this._data[ t ? 'core' : 'checkbox' ].selected.concat(m[dpc[i]].children_d);
5117
+ }
5118
+ }
5119
+ }
5120
+ }
5121
+
5122
+ if(s.indexOf('up') !== -1) {
5123
+ // apply up
5124
+ for(i = 0, j = p.children_d.length; i < j; i++) {
5125
+ if(!m[p.children_d[i]].children.length) {
5126
+ chd.push(m[p.children_d[i]].parent);
5127
+ }
5128
+ }
5129
+ chd = $.vakata.array_unique(chd);
5130
+ for(k = 0, l = chd.length; k < l; k++) {
5131
+ p = m[chd[k]];
5132
+ while(p && p.id !== $.jstree.root) {
5133
+ c = 0;
5134
+ for(i = 0, j = p.children.length; i < j; i++) {
5135
+ c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
5136
+ }
5137
+ if(c === j) {
5138
+ p.state[ t ? 'selected' : 'checked' ] = true;
5139
+ this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5140
+ tmp = this.get_node(p, true);
5141
+ if(tmp && tmp.length) {
5142
+ tmp.attr('aria-selected', true).children('.jstree-anchor').addClass( t ? 'jstree-clicked' : 'jstree-checked');
5143
+ }
5144
+ }
5145
+ else {
5146
+ break;
5147
+ }
5148
+ p = this.get_node(p.parent);
5149
+ }
5150
+ }
5151
+ }
5152
+
5153
+ this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected);
5154
+ }, this))
5155
+ .on(this.settings.checkbox.tie_selection ? 'select_node.jstree' : 'check_node.jstree', $.proxy(function (e, data) {
5156
+ var self = this,
5157
+ obj = data.node,
5158
+ m = this._model.data,
5159
+ par = this.get_node(obj.parent),
5160
+ i, j, c, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
5161
+ sel = {}, cur = this._data[ t ? 'core' : 'checkbox' ].selected;
5162
+
5163
+ for (i = 0, j = cur.length; i < j; i++) {
5164
+ sel[cur[i]] = true;
5165
+ }
5166
+
5167
+ // apply down
5168
+ if(s.indexOf('down') !== -1) {
5169
+ //this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_unique(this._data[ t ? 'core' : 'checkbox' ].selected.concat(obj.children_d));
5170
+ var selectedIds = this._cascade_new_checked_state(obj.id, true);
5171
+ var temp = obj.children_d.concat(obj.id);
5172
+ for (i = 0, j = temp.length; i < j; i++) {
5173
+ if (selectedIds.indexOf(temp[i]) > -1) {
5174
+ sel[temp[i]] = true;
5175
+ }
5176
+ else {
5177
+ delete sel[temp[i]];
5178
+ }
5179
+ }
5180
+ }
5181
+
5182
+ // apply up
5183
+ if(s.indexOf('up') !== -1) {
5184
+ while(par && par.id !== $.jstree.root) {
5185
+ c = 0;
5186
+ for(i = 0, j = par.children.length; i < j; i++) {
5187
+ c += m[par.children[i]].state[ t ? 'selected' : 'checked' ];
5188
+ }
5189
+ if(c === j) {
5190
+ par.state[ t ? 'selected' : 'checked' ] = true;
5191
+ sel[par.id] = true;
5192
+ //this._data[ t ? 'core' : 'checkbox' ].selected.push(par.id);
5193
+ tmp = this.get_node(par, true);
5194
+ if(tmp && tmp.length) {
5195
+ tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5196
+ }
5197
+ }
5198
+ else {
5199
+ break;
5200
+ }
5201
+ par = this.get_node(par.parent);
5202
+ }
5203
+ }
5204
+
5205
+ cur = [];
5206
+ for (i in sel) {
5207
+ if (sel.hasOwnProperty(i)) {
5208
+ cur.push(i);
5209
+ }
5210
+ }
5211
+ this._data[ t ? 'core' : 'checkbox' ].selected = cur;
5212
+ }, this))
5213
+ .on(this.settings.checkbox.tie_selection ? 'deselect_all.jstree' : 'uncheck_all.jstree', $.proxy(function (e, data) {
5214
+ var obj = this.get_node($.jstree.root),
5215
+ m = this._model.data,
5216
+ i, j, tmp;
5217
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
5218
+ tmp = m[obj.children_d[i]];
5219
+ if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
5220
+ tmp.original.state.undetermined = false;
5221
+ }
5222
+ }
5223
+ }, this))
5224
+ .on(this.settings.checkbox.tie_selection ? 'deselect_node.jstree' : 'uncheck_node.jstree', $.proxy(function (e, data) {
5225
+ var self = this,
5226
+ obj = data.node,
5227
+ dom = this.get_node(obj, true),
5228
+ i, j, tmp, s = this.settings.checkbox.cascade, t = this.settings.checkbox.tie_selection,
5229
+ cur = this._data[ t ? 'core' : 'checkbox' ].selected, sel = {},
5230
+ stillSelectedIds = [],
5231
+ allIds = obj.children_d.concat(obj.id);
5232
+
5233
+ // apply down
5234
+ if(s.indexOf('down') !== -1) {
5235
+ var selectedIds = this._cascade_new_checked_state(obj.id, false);
5236
+
5237
+ cur = cur.filter(function(id) {
5238
+ return allIds.indexOf(id) === -1 || selectedIds.indexOf(id) > -1;
5239
+ });
5240
+ }
5241
+
5242
+ // only apply up if cascade up is enabled and if this node is not selected
5243
+ // (if all child nodes are disabled and cascade_to_disabled === false then this node will till be selected).
5244
+ if(s.indexOf('up') !== -1 && cur.indexOf(obj.id) === -1) {
5245
+ for(i = 0, j = obj.parents.length; i < j; i++) {
5246
+ tmp = this._model.data[obj.parents[i]];
5247
+ tmp.state[ t ? 'selected' : 'checked' ] = false;
5248
+ if(tmp && tmp.original && tmp.original.state && tmp.original.state.undetermined) {
5249
+ tmp.original.state.undetermined = false;
5250
+ }
5251
+ tmp = this.get_node(obj.parents[i], true);
5252
+ if(tmp && tmp.length) {
5253
+ tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5254
+ }
5255
+ }
5256
+
5257
+ cur = cur.filter(function(id) {
5258
+ return obj.parents.indexOf(id) === -1;
5259
+ });
5260
+ }
5261
+
5262
+ this._data[ t ? 'core' : 'checkbox' ].selected = cur;
5263
+ }, this));
5264
+ }
5265
+ if(this.settings.checkbox.cascade.indexOf('up') !== -1) {
5266
+ this.element
5267
+ .on('delete_node.jstree', $.proxy(function (e, data) {
5268
+ // apply up (whole handler)
5269
+ var p = this.get_node(data.parent),
5270
+ m = this._model.data,
5271
+ i, j, c, tmp, t = this.settings.checkbox.tie_selection;
5272
+ while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
5273
+ c = 0;
5274
+ for(i = 0, j = p.children.length; i < j; i++) {
5275
+ c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
5276
+ }
5277
+ if(j > 0 && c === j) {
5278
+ p.state[ t ? 'selected' : 'checked' ] = true;
5279
+ this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5280
+ tmp = this.get_node(p, true);
5281
+ if(tmp && tmp.length) {
5282
+ tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5283
+ }
5284
+ }
5285
+ else {
5286
+ break;
5287
+ }
5288
+ p = this.get_node(p.parent);
5289
+ }
5290
+ }, this))
5291
+ .on('move_node.jstree', $.proxy(function (e, data) {
5292
+ // apply up (whole handler)
5293
+ var is_multi = data.is_multi,
5294
+ old_par = data.old_parent,
5295
+ new_par = this.get_node(data.parent),
5296
+ m = this._model.data,
5297
+ p, c, i, j, tmp, t = this.settings.checkbox.tie_selection;
5298
+ if(!is_multi) {
5299
+ p = this.get_node(old_par);
5300
+ while(p && p.id !== $.jstree.root && !p.state[ t ? 'selected' : 'checked' ]) {
5301
+ c = 0;
5302
+ for(i = 0, j = p.children.length; i < j; i++) {
5303
+ c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
5304
+ }
5305
+ if(j > 0 && c === j) {
5306
+ p.state[ t ? 'selected' : 'checked' ] = true;
5307
+ this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5308
+ tmp = this.get_node(p, true);
5309
+ if(tmp && tmp.length) {
5310
+ tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5311
+ }
5312
+ }
5313
+ else {
5314
+ break;
5315
+ }
5316
+ p = this.get_node(p.parent);
5317
+ }
5318
+ }
5319
+ p = new_par;
5320
+ while(p && p.id !== $.jstree.root) {
5321
+ c = 0;
5322
+ for(i = 0, j = p.children.length; i < j; i++) {
5323
+ c += m[p.children[i]].state[ t ? 'selected' : 'checked' ];
5324
+ }
5325
+ if(c === j) {
5326
+ if(!p.state[ t ? 'selected' : 'checked' ]) {
5327
+ p.state[ t ? 'selected' : 'checked' ] = true;
5328
+ this._data[ t ? 'core' : 'checkbox' ].selected.push(p.id);
5329
+ tmp = this.get_node(p, true);
5330
+ if(tmp && tmp.length) {
5331
+ tmp.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5332
+ }
5333
+ }
5334
+ }
5335
+ else {
5336
+ if(p.state[ t ? 'selected' : 'checked' ]) {
5337
+ p.state[ t ? 'selected' : 'checked' ] = false;
5338
+ this._data[ t ? 'core' : 'checkbox' ].selected = $.vakata.array_remove_item(this._data[ t ? 'core' : 'checkbox' ].selected, p.id);
5339
+ tmp = this.get_node(p, true);
5340
+ if(tmp && tmp.length) {
5341
+ tmp.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5342
+ }
5343
+ }
5344
+ else {
5345
+ break;
5346
+ }
5347
+ }
5348
+ p = this.get_node(p.parent);
5349
+ }
5350
+ }, this));
5351
+ }
5352
+ };
5353
+ /**
5354
+ * get an array of all nodes whose state is "undetermined"
5355
+ * @name get_undetermined([full])
5356
+ * @param {boolean} full: if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
5357
+ * @return {Array}
5358
+ * @plugin checkbox
5359
+ */
5360
+ this.get_undetermined = function (full) {
5361
+ if (this.settings.checkbox.cascade.indexOf('undetermined') === -1) {
5362
+ return [];
5363
+ }
5364
+ 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, r = [];
5365
+ for(i = 0, j = s.length; i < j; i++) {
5366
+ if(m[s[i]] && m[s[i]].parents) {
5367
+ for(k = 0, l = m[s[i]].parents.length; k < l; k++) {
5368
+ if(o[m[s[i]].parents[k]] !== undefined) {
5369
+ break;
5370
+ }
5371
+ if(m[s[i]].parents[k] !== $.jstree.root) {
5372
+ o[m[s[i]].parents[k]] = true;
5373
+ p.push(m[s[i]].parents[k]);
5374
+ }
5375
+ }
5376
+ }
5377
+ }
5378
+ // attempt for server side undetermined state
5379
+ this.element.find('.jstree-closed').not(':has(.jstree-children)')
5380
+ .each(function () {
5381
+ var tmp = tt.get_node(this), tmp2;
5382
+
5383
+ if(!tmp) { return; }
5384
+
5385
+ if(!tmp.state.loaded) {
5386
+ if(tmp.original && tmp.original.state && tmp.original.state.undetermined && tmp.original.state.undetermined === true) {
5387
+ if(o[tmp.id] === undefined && tmp.id !== $.jstree.root) {
5388
+ o[tmp.id] = true;
5389
+ p.push(tmp.id);
5390
+ }
5391
+ for(k = 0, l = tmp.parents.length; k < l; k++) {
5392
+ if(o[tmp.parents[k]] === undefined && tmp.parents[k] !== $.jstree.root) {
5393
+ o[tmp.parents[k]] = true;
5394
+ p.push(tmp.parents[k]);
5395
+ }
5396
+ }
5397
+ }
5398
+ }
5399
+ else {
5400
+ for(i = 0, j = tmp.children_d.length; i < j; i++) {
5401
+ tmp2 = m[tmp.children_d[i]];
5402
+ if(!tmp2.state.loaded && tmp2.original && tmp2.original.state && tmp2.original.state.undetermined && tmp2.original.state.undetermined === true) {
5403
+ if(o[tmp2.id] === undefined && tmp2.id !== $.jstree.root) {
5404
+ o[tmp2.id] = true;
5405
+ p.push(tmp2.id);
5406
+ }
5407
+ for(k = 0, l = tmp2.parents.length; k < l; k++) {
5408
+ if(o[tmp2.parents[k]] === undefined && tmp2.parents[k] !== $.jstree.root) {
5409
+ o[tmp2.parents[k]] = true;
5410
+ p.push(tmp2.parents[k]);
5411
+ }
5412
+ }
5413
+ }
5414
+ }
5415
+ }
5416
+ });
5417
+ for (i = 0, j = p.length; i < j; i++) {
5418
+ if(!m[p[i]].state[ t ? 'selected' : 'checked' ]) {
5419
+ r.push(full ? m[p[i]] : p[i]);
5420
+ }
5421
+ }
5422
+ return r;
5423
+ };
5424
+ /**
5425
+ * set the undetermined state where and if necessary. Used internally.
5426
+ * @private
5427
+ * @name _undetermined()
5428
+ * @plugin checkbox
5429
+ */
5430
+ this._undetermined = function () {
5431
+ if(this.element === null) { return; }
5432
+ var p = this.get_undetermined(false), i, j, s;
5433
+
5434
+ this.element.find('.jstree-undetermined').removeClass('jstree-undetermined');
5435
+ for (i = 0, j = p.length; i < j; i++) {
5436
+ s = this.get_node(p[i], true);
5437
+ if(s && s.length) {
5438
+ s.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-undetermined');
5439
+ }
5440
+ }
5441
+ };
5442
+ this.redraw_node = function(obj, deep, is_callback, force_render) {
5443
+ obj = parent.redraw_node.apply(this, arguments);
5444
+ if(obj) {
5445
+ var i, j, tmp = null, icon = null;
5446
+ for(i = 0, j = obj.childNodes.length; i < j; i++) {
5447
+ if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
5448
+ tmp = obj.childNodes[i];
5449
+ break;
5450
+ }
5451
+ }
5452
+ if(tmp) {
5453
+ if(!this.settings.checkbox.tie_selection && this._model.data[obj.id].state.checked) { tmp.className += ' jstree-checked'; }
5454
+ icon = _i.cloneNode(false);
5455
+ if(this._model.data[obj.id].state.checkbox_disabled) { icon.className += ' jstree-checkbox-disabled'; }
5456
+ tmp.insertBefore(icon, tmp.childNodes[0]);
5457
+ }
5458
+ }
5459
+ if(!is_callback && this.settings.checkbox.cascade.indexOf('undetermined') !== -1) {
5460
+ if(this._data.checkbox.uto) { clearTimeout(this._data.checkbox.uto); }
5461
+ this._data.checkbox.uto = setTimeout($.proxy(this._undetermined, this), 50);
5462
+ }
5463
+ return obj;
5464
+ };
5465
+ /**
5466
+ * show the node checkbox icons
5467
+ * @name show_checkboxes()
5468
+ * @plugin checkbox
5469
+ */
5470
+ this.show_checkboxes = function () { this._data.core.themes.checkboxes = true; this.get_container_ul().removeClass("jstree-no-checkboxes"); };
5471
+ /**
5472
+ * hide the node checkbox icons
5473
+ * @name hide_checkboxes()
5474
+ * @plugin checkbox
5475
+ */
5476
+ this.hide_checkboxes = function () { this._data.core.themes.checkboxes = false; this.get_container_ul().addClass("jstree-no-checkboxes"); };
5477
+ /**
5478
+ * toggle the node icons
5479
+ * @name toggle_checkboxes()
5480
+ * @plugin checkbox
5481
+ */
5482
+ this.toggle_checkboxes = function () { if(this._data.core.themes.checkboxes) { this.hide_checkboxes(); } else { this.show_checkboxes(); } };
5483
+ /**
5484
+ * checks if a node is in an undetermined state
5485
+ * @name is_undetermined(obj)
5486
+ * @param {mixed} obj
5487
+ * @return {Boolean}
5488
+ */
5489
+ this.is_undetermined = function (obj) {
5490
+ obj = this.get_node(obj);
5491
+ var s = this.settings.checkbox.cascade, i, j, t = this.settings.checkbox.tie_selection, d = this._data[ t ? 'core' : 'checkbox' ].selected, m = this._model.data;
5492
+ if(!obj || obj.state[ t ? 'selected' : 'checked' ] === true || s.indexOf('undetermined') === -1 || (s.indexOf('down') === -1 && s.indexOf('up') === -1)) {
5493
+ return false;
5494
+ }
5495
+ if(!obj.state.loaded && obj.original.state.undetermined === true) {
5496
+ return true;
5497
+ }
5498
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
5499
+ if($.inArray(obj.children_d[i], d) !== -1 || (!m[obj.children_d[i]].state.loaded && m[obj.children_d[i]].original.state.undetermined)) {
5500
+ return true;
5501
+ }
5502
+ }
5503
+ return false;
5504
+ };
5505
+ /**
5506
+ * disable a node's checkbox
5507
+ * @name disable_checkbox(obj)
5508
+ * @param {mixed} obj an array can be used too
5509
+ * @trigger disable_checkbox.jstree
5510
+ * @plugin checkbox
5511
+ */
5512
+ this.disable_checkbox = function (obj) {
5513
+ var t1, t2, dom;
5514
+ if($.isArray(obj)) {
5515
+ obj = obj.slice();
5516
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5517
+ this.disable_checkbox(obj[t1]);
5518
+ }
5519
+ return true;
5520
+ }
5521
+ obj = this.get_node(obj);
5522
+ if(!obj || obj.id === $.jstree.root) {
5523
+ return false;
5524
+ }
5525
+ dom = this.get_node(obj, true);
5526
+ if(!obj.state.checkbox_disabled) {
5527
+ obj.state.checkbox_disabled = true;
5528
+ if(dom && dom.length) {
5529
+ dom.children('.jstree-anchor').children('.jstree-checkbox').addClass('jstree-checkbox-disabled');
5530
+ }
5531
+ /**
5532
+ * triggered when an node's checkbox is disabled
5533
+ * @event
5534
+ * @name disable_checkbox.jstree
5535
+ * @param {Object} node
5536
+ * @plugin checkbox
5537
+ */
5538
+ this.trigger('disable_checkbox', { 'node' : obj });
5539
+ }
5540
+ };
5541
+ /**
5542
+ * enable a node's checkbox
5543
+ * @name disable_checkbox(obj)
5544
+ * @param {mixed} obj an array can be used too
5545
+ * @trigger enable_checkbox.jstree
5546
+ * @plugin checkbox
5547
+ */
5548
+ this.enable_checkbox = function (obj) {
5549
+ var t1, t2, dom;
5550
+ if($.isArray(obj)) {
5551
+ obj = obj.slice();
5552
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5553
+ this.enable_checkbox(obj[t1]);
5554
+ }
5555
+ return true;
5556
+ }
5557
+ obj = this.get_node(obj);
5558
+ if(!obj || obj.id === $.jstree.root) {
5559
+ return false;
5560
+ }
5561
+ dom = this.get_node(obj, true);
5562
+ if(obj.state.checkbox_disabled) {
5563
+ obj.state.checkbox_disabled = false;
5564
+ if(dom && dom.length) {
5565
+ dom.children('.jstree-anchor').children('.jstree-checkbox').removeClass('jstree-checkbox-disabled');
5566
+ }
5567
+ /**
5568
+ * triggered when an node's checkbox is enabled
5569
+ * @event
5570
+ * @name enable_checkbox.jstree
5571
+ * @param {Object} node
5572
+ * @plugin checkbox
5573
+ */
5574
+ this.trigger('enable_checkbox', { 'node' : obj });
5575
+ }
5576
+ };
5577
+
5578
+ this.activate_node = function (obj, e) {
5579
+ if($(e.target).hasClass('jstree-checkbox-disabled')) {
5580
+ return false;
5581
+ }
5582
+ if(this.settings.checkbox.tie_selection && (this.settings.checkbox.whole_node || $(e.target).hasClass('jstree-checkbox'))) {
5583
+ e.ctrlKey = true;
5584
+ }
5585
+ if(this.settings.checkbox.tie_selection || (!this.settings.checkbox.whole_node && !$(e.target).hasClass('jstree-checkbox'))) {
5586
+ return parent.activate_node.call(this, obj, e);
5587
+ }
5588
+ if(this.is_disabled(obj)) {
5589
+ return false;
5590
+ }
5591
+ if(this.is_checked(obj)) {
5592
+ this.uncheck_node(obj, e);
5593
+ }
5594
+ else {
5595
+ this.check_node(obj, e);
5596
+ }
5597
+ this.trigger('activate_node', { 'node' : this.get_node(obj) });
5598
+ };
5599
+
5600
+ /**
5601
+ * Cascades checked state to a node and all its descendants. This function does NOT affect hidden and disabled nodes (or their descendants).
5602
+ * However if these unaffected nodes are already selected their ids will be included in the returned array.
5603
+ * @private
5604
+ * @param {string} id the node ID
5605
+ * @param {bool} checkedState should the nodes be checked or not
5606
+ * @returns {Array} Array of all node id's (in this tree branch) that are checked.
5607
+ */
5608
+ this._cascade_new_checked_state = function (id, checkedState) {
5609
+ var self = this;
5610
+ var t = this.settings.checkbox.tie_selection;
5611
+ var node = this._model.data[id];
5612
+ var selectedNodeIds = [];
5613
+ var selectedChildrenIds = [], i, j, selectedChildIds;
5614
+
5615
+ if (
5616
+ (this.settings.checkbox.cascade_to_disabled || !node.state.disabled) &&
5617
+ (this.settings.checkbox.cascade_to_hidden || !node.state.hidden)
5618
+ ) {
5619
+ //First try and check/uncheck the children
5620
+ if (node.children) {
5621
+ for (i = 0, j = node.children.length; i < j; i++) {
5622
+ var childId = node.children[i];
5623
+ selectedChildIds = self._cascade_new_checked_state(childId, checkedState);
5624
+ selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
5625
+ if (selectedChildIds.indexOf(childId) > -1) {
5626
+ selectedChildrenIds.push(childId);
5627
+ }
5628
+ }
5629
+ }
5630
+
5631
+ var dom = self.get_node(node, true);
5632
+
5633
+ //A node's state is undetermined if some but not all of it's children are checked/selected .
5634
+ var undetermined = selectedChildrenIds.length > 0 && selectedChildrenIds.length < node.children.length;
5635
+
5636
+ if(node.original && node.original.state && node.original.state.undetermined) {
5637
+ node.original.state.undetermined = undetermined;
5638
+ }
5639
+
5640
+ //If a node is undetermined then remove selected class
5641
+ if (undetermined) {
5642
+ node.state[ t ? 'selected' : 'checked' ] = false;
5643
+ dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5644
+ }
5645
+ //Otherwise, if the checkedState === true (i.e. the node is being checked now) and all of the node's children are checked (if it has any children),
5646
+ //check the node and style it correctly.
5647
+ else if (checkedState && selectedChildrenIds.length === node.children.length) {
5648
+ node.state[ t ? 'selected' : 'checked' ] = checkedState;
5649
+ selectedNodeIds.push(node.id);
5650
+
5651
+ dom.attr('aria-selected', true).children('.jstree-anchor').addClass(t ? 'jstree-clicked' : 'jstree-checked');
5652
+ }
5653
+ else {
5654
+ node.state[ t ? 'selected' : 'checked' ] = false;
5655
+ dom.attr('aria-selected', false).children('.jstree-anchor').removeClass(t ? 'jstree-clicked' : 'jstree-checked');
5656
+ }
5657
+ }
5658
+ else {
5659
+ selectedChildIds = this.get_checked_descendants(id);
5660
+
5661
+ if (node.state[ t ? 'selected' : 'checked' ]) {
5662
+ selectedChildIds.push(node.id);
5663
+ }
5664
+
5665
+ selectedNodeIds = selectedNodeIds.concat(selectedChildIds);
5666
+ }
5667
+
5668
+ return selectedNodeIds;
5669
+ };
5670
+
5671
+ /**
5672
+ * Gets ids of nodes selected in branch (of tree) specified by id (does not include the node specified by id)
5673
+ * @name get_checked_descendants(obj)
5674
+ * @param {string} id the node ID
5675
+ * @return {Array} array of IDs
5676
+ * @plugin checkbox
5677
+ */
5678
+ this.get_checked_descendants = function (id) {
5679
+ var self = this;
5680
+ var t = self.settings.checkbox.tie_selection;
5681
+ var node = self._model.data[id];
5682
+
5683
+ return node.children_d.filter(function(_id) {
5684
+ return self._model.data[_id].state[ t ? 'selected' : 'checked' ];
5685
+ });
5686
+ };
5687
+
5688
+ /**
5689
+ * check a node (only if tie_selection in checkbox settings is false, otherwise select_node will be called internally)
5690
+ * @name check_node(obj)
5691
+ * @param {mixed} obj an array can be used to check multiple nodes
5692
+ * @trigger check_node.jstree
5693
+ * @plugin checkbox
5694
+ */
5695
+ this.check_node = function (obj, e) {
5696
+ if(this.settings.checkbox.tie_selection) { return this.select_node(obj, false, true, e); }
5697
+ var dom, t1, t2, th;
5698
+ if($.isArray(obj)) {
5699
+ obj = obj.slice();
5700
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5701
+ this.check_node(obj[t1], e);
5702
+ }
5703
+ return true;
5704
+ }
5705
+ obj = this.get_node(obj);
5706
+ if(!obj || obj.id === $.jstree.root) {
5707
+ return false;
5708
+ }
5709
+ dom = this.get_node(obj, true);
5710
+ if(!obj.state.checked) {
5711
+ obj.state.checked = true;
5712
+ this._data.checkbox.selected.push(obj.id);
5713
+ if(dom && dom.length) {
5714
+ dom.children('.jstree-anchor').addClass('jstree-checked');
5715
+ }
5716
+ /**
5717
+ * triggered when an node is checked (only if tie_selection in checkbox settings is false)
5718
+ * @event
5719
+ * @name check_node.jstree
5720
+ * @param {Object} node
5721
+ * @param {Array} selected the current selection
5722
+ * @param {Object} event the event (if any) that triggered this check_node
5723
+ * @plugin checkbox
5724
+ */
5725
+ this.trigger('check_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
5726
+ }
5727
+ };
5728
+ /**
5729
+ * uncheck a node (only if tie_selection in checkbox settings is false, otherwise deselect_node will be called internally)
5730
+ * @name uncheck_node(obj)
5731
+ * @param {mixed} obj an array can be used to uncheck multiple nodes
5732
+ * @trigger uncheck_node.jstree
5733
+ * @plugin checkbox
5734
+ */
5735
+ this.uncheck_node = function (obj, e) {
5736
+ if(this.settings.checkbox.tie_selection) { return this.deselect_node(obj, false, e); }
5737
+ var t1, t2, dom;
5738
+ if($.isArray(obj)) {
5739
+ obj = obj.slice();
5740
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
5741
+ this.uncheck_node(obj[t1], e);
5742
+ }
5743
+ return true;
5744
+ }
5745
+ obj = this.get_node(obj);
5746
+ if(!obj || obj.id === $.jstree.root) {
5747
+ return false;
5748
+ }
5749
+ dom = this.get_node(obj, true);
5750
+ if(obj.state.checked) {
5751
+ obj.state.checked = false;
5752
+ this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, obj.id);
5753
+ if(dom.length) {
5754
+ dom.children('.jstree-anchor').removeClass('jstree-checked');
5755
+ }
5756
+ /**
5757
+ * triggered when an node is unchecked (only if tie_selection in checkbox settings is false)
5758
+ * @event
5759
+ * @name uncheck_node.jstree
5760
+ * @param {Object} node
5761
+ * @param {Array} selected the current selection
5762
+ * @param {Object} event the event (if any) that triggered this uncheck_node
5763
+ * @plugin checkbox
5764
+ */
5765
+ this.trigger('uncheck_node', { 'node' : obj, 'selected' : this._data.checkbox.selected, 'event' : e });
5766
+ }
5767
+ };
5768
+
5769
+ /**
5770
+ * checks all nodes in the tree (only if tie_selection in checkbox settings is false, otherwise select_all will be called internally)
5771
+ * @name check_all()
5772
+ * @trigger check_all.jstree, changed.jstree
5773
+ * @plugin checkbox
5774
+ */
5775
+ this.check_all = function () {
5776
+ if(this.settings.checkbox.tie_selection) { return this.select_all(); }
5777
+ var tmp = this._data.checkbox.selected.concat([]), i, j;
5778
+ this._data.checkbox.selected = this._model.data[$.jstree.root].children_d.concat();
5779
+ for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
5780
+ if(this._model.data[this._data.checkbox.selected[i]]) {
5781
+ this._model.data[this._data.checkbox.selected[i]].state.checked = true;
5782
+ }
5783
+ }
5784
+ this.redraw(true);
5785
+ /**
5786
+ * triggered when all nodes are checked (only if tie_selection in checkbox settings is false)
5787
+ * @event
5788
+ * @name check_all.jstree
5789
+ * @param {Array} selected the current selection
5790
+ * @plugin checkbox
5791
+ */
5792
+ this.trigger('check_all', { 'selected' : this._data.checkbox.selected });
5793
+ };
5794
+ /**
5795
+ * uncheck all checked nodes (only if tie_selection in checkbox settings is false, otherwise deselect_all will be called internally)
5796
+ * @name uncheck_all()
5797
+ * @trigger uncheck_all.jstree
5798
+ * @plugin checkbox
5799
+ */
5800
+ this.uncheck_all = function () {
5801
+ if(this.settings.checkbox.tie_selection) { return this.deselect_all(); }
5802
+ var tmp = this._data.checkbox.selected.concat([]), i, j;
5803
+ for(i = 0, j = this._data.checkbox.selected.length; i < j; i++) {
5804
+ if(this._model.data[this._data.checkbox.selected[i]]) {
5805
+ this._model.data[this._data.checkbox.selected[i]].state.checked = false;
5806
+ }
5807
+ }
5808
+ this._data.checkbox.selected = [];
5809
+ this.element.find('.jstree-checked').removeClass('jstree-checked');
5810
+ /**
5811
+ * triggered when all nodes are unchecked (only if tie_selection in checkbox settings is false)
5812
+ * @event
5813
+ * @name uncheck_all.jstree
5814
+ * @param {Object} node the previous selection
5815
+ * @param {Array} selected the current selection
5816
+ * @plugin checkbox
5817
+ */
5818
+ this.trigger('uncheck_all', { 'selected' : this._data.checkbox.selected, 'node' : tmp });
5819
+ };
5820
+ /**
5821
+ * checks if a node is checked (if tie_selection is on in the settings this function will return the same as is_selected)
5822
+ * @name is_checked(obj)
5823
+ * @param {mixed} obj
5824
+ * @return {Boolean}
5825
+ * @plugin checkbox
5826
+ */
5827
+ this.is_checked = function (obj) {
5828
+ if(this.settings.checkbox.tie_selection) { return this.is_selected(obj); }
5829
+ obj = this.get_node(obj);
5830
+ if(!obj || obj.id === $.jstree.root) { return false; }
5831
+ return obj.state.checked;
5832
+ };
5833
+ /**
5834
+ * get an array of all checked nodes (if tie_selection is on in the settings this function will return the same as get_selected)
5835
+ * @name get_checked([full])
5836
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
5837
+ * @return {Array}
5838
+ * @plugin checkbox
5839
+ */
5840
+ this.get_checked = function (full) {
5841
+ if(this.settings.checkbox.tie_selection) { return this.get_selected(full); }
5842
+ return full ? $.map(this._data.checkbox.selected, $.proxy(function (i) { return this.get_node(i); }, this)) : this._data.checkbox.selected;
5843
+ };
5844
+ /**
5845
+ * get an array of all top level checked nodes (ignoring children of checked nodes) (if tie_selection is on in the settings this function will return the same as get_top_selected)
5846
+ * @name get_top_checked([full])
5847
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
5848
+ * @return {Array}
5849
+ * @plugin checkbox
5850
+ */
5851
+ this.get_top_checked = function (full) {
5852
+ if(this.settings.checkbox.tie_selection) { return this.get_top_selected(full); }
5853
+ var tmp = this.get_checked(true),
5854
+ obj = {}, i, j, k, l;
5855
+ for(i = 0, j = tmp.length; i < j; i++) {
5856
+ obj[tmp[i].id] = tmp[i];
5857
+ }
5858
+ for(i = 0, j = tmp.length; i < j; i++) {
5859
+ for(k = 0, l = tmp[i].children_d.length; k < l; k++) {
5860
+ if(obj[tmp[i].children_d[k]]) {
5861
+ delete obj[tmp[i].children_d[k]];
5862
+ }
5863
+ }
5864
+ }
5865
+ tmp = [];
5866
+ for(i in obj) {
5867
+ if(obj.hasOwnProperty(i)) {
5868
+ tmp.push(i);
5869
+ }
5870
+ }
5871
+ return full ? $.map(tmp, $.proxy(function (i) { return this.get_node(i); }, this)) : tmp;
5872
+ };
5873
+ /**
5874
+ * get an array of all bottom level checked nodes (ignoring selected parents) (if tie_selection is on in the settings this function will return the same as get_bottom_selected)
5875
+ * @name get_bottom_checked([full])
5876
+ * @param {mixed} full if set to `true` the returned array will consist of the full node objects, otherwise - only IDs will be returned
5877
+ * @return {Array}
5878
+ * @plugin checkbox
5879
+ */
5880
+ this.get_bottom_checked = function (full) {
5881
+ if(this.settings.checkbox.tie_selection) { return this.get_bottom_selected(full); }
5882
+ var tmp = this.get_checked(true),
5883
+ obj = [], i, j;
5884
+ for(i = 0, j = tmp.length; i < j; i++) {
5885
+ if(!tmp[i].children.length) {
5886
+ obj.push(tmp[i].id);
5887
+ }
5888
+ }
5889
+ return full ? $.map(obj, $.proxy(function (i) { return this.get_node(i); }, this)) : obj;
5890
+ };
5891
+ this.load_node = function (obj, callback) {
5892
+ var k, l, i, j, c, tmp;
5893
+ if(!$.isArray(obj) && !this.settings.checkbox.tie_selection) {
5894
+ tmp = this.get_node(obj);
5895
+ if(tmp && tmp.state.loaded) {
5896
+ for(k = 0, l = tmp.children_d.length; k < l; k++) {
5897
+ if(this._model.data[tmp.children_d[k]].state.checked) {
5898
+ c = true;
5899
+ this._data.checkbox.selected = $.vakata.array_remove_item(this._data.checkbox.selected, tmp.children_d[k]);
5900
+ }
5901
+ }
5902
+ }
5903
+ }
5904
+ return parent.load_node.apply(this, arguments);
5905
+ };
5906
+ this.get_state = function () {
5907
+ var state = parent.get_state.apply(this, arguments);
5908
+ if(this.settings.checkbox.tie_selection) { return state; }
5909
+ state.checkbox = this._data.checkbox.selected.slice();
5910
+ return state;
5911
+ };
5912
+ this.set_state = function (state, callback) {
5913
+ var res = parent.set_state.apply(this, arguments);
5914
+ if(res && state.checkbox) {
5915
+ if(!this.settings.checkbox.tie_selection) {
5916
+ this.uncheck_all();
5917
+ var _this = this;
5918
+ $.each(state.checkbox, function (i, v) {
5919
+ _this.check_node(v);
5920
+ });
5921
+ }
5922
+ delete state.checkbox;
5923
+ this.set_state(state, callback);
5924
+ return false;
5925
+ }
5926
+ return res;
5927
+ };
5928
+ this.refresh = function (skip_loading, forget_state) {
5929
+ if(this.settings.checkbox.tie_selection) {
5930
+ this._data.checkbox.selected = [];
5931
+ }
5932
+ return parent.refresh.apply(this, arguments);
5933
+ };
5934
+ };
5935
+
5936
+ // include the checkbox plugin by default
5937
+ // $.jstree.defaults.plugins.push("checkbox");
5938
+
5939
+
5940
+ /**
5941
+ * ### Conditionalselect plugin
5942
+ *
5943
+ * This plugin allows defining a callback to allow or deny node selection by user input (activate node method).
5944
+ */
5945
+
5946
+ /**
5947
+ * a callback (function) which is invoked in the instance's scope and receives two arguments - the node and the event that triggered the `activate_node` call. Returning false prevents working with the node, returning true allows invoking activate_node. Defaults to returning `true`.
5948
+ * @name $.jstree.defaults.checkbox.visible
5949
+ * @plugin checkbox
5950
+ */
5951
+ $.jstree.defaults.conditionalselect = function () { return true; };
5952
+ $.jstree.plugins.conditionalselect = function (options, parent) {
5953
+ // own function
5954
+ this.activate_node = function (obj, e) {
5955
+ if(this.settings.conditionalselect.call(this, this.get_node(obj), e)) {
5956
+ return parent.activate_node.call(this, obj, e);
5957
+ }
5958
+ };
5959
+ };
5960
+
5961
+
5962
+ /**
5963
+ * ### Contextmenu plugin
5964
+ *
5965
+ * Shows a context menu when a node is right-clicked.
5966
+ */
5967
+
5968
+ /**
5969
+ * stores all defaults for the contextmenu plugin
5970
+ * @name $.jstree.defaults.contextmenu
5971
+ * @plugin contextmenu
5972
+ */
5973
+ $.jstree.defaults.contextmenu = {
5974
+ /**
5975
+ * a boolean indicating if the node should be selected when the context menu is invoked on it. Defaults to `true`.
5976
+ * @name $.jstree.defaults.contextmenu.select_node
5977
+ * @plugin contextmenu
5978
+ */
5979
+ select_node : true,
5980
+ /**
5981
+ * a boolean indicating if the menu should be shown aligned with the node. Defaults to `true`, otherwise the mouse coordinates are used.
5982
+ * @name $.jstree.defaults.contextmenu.show_at_node
5983
+ * @plugin contextmenu
5984
+ */
5985
+ show_at_node : true,
5986
+ /**
5987
+ * an object of actions, or a function that accepts a node and a callback function and calls the callback function with an object of actions available for that node (you can also return the items too).
5988
+ *
5989
+ * Each action consists of a key (a unique name) and a value which is an object with the following properties (only label and action are required). Once a menu item is activated the `action` function will be invoked with an object containing the following keys: item - the contextmenu item definition as seen below, reference - the DOM node that was used (the tree node), element - the contextmenu DOM element, position - an object with x/y properties indicating the position of the menu.
5990
+ *
5991
+ * * `separator_before` - a boolean indicating if there should be a separator before this item
5992
+ * * `separator_after` - a boolean indicating if there should be a separator after this item
5993
+ * * `_disabled` - a boolean indicating if this action should be disabled
5994
+ * * `label` - a string - the name of the action (could be a function returning a string)
5995
+ * * `title` - a string - an optional tooltip for the item
5996
+ * * `action` - a function to be executed if this item is chosen, the function will receive
5997
+ * * `icon` - a string, can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class
5998
+ * * `shortcut` - keyCode which will trigger the action if the menu is open (for example `113` for rename, which equals F2)
5999
+ * * `shortcut_label` - shortcut label (like for example `F2` for rename)
6000
+ * * `submenu` - an object with the same structure as $.jstree.defaults.contextmenu.items which can be used to create a submenu - each key will be rendered as a separate option in a submenu that will appear once the current item is hovered
6001
+ *
6002
+ * @name $.jstree.defaults.contextmenu.items
6003
+ * @plugin contextmenu
6004
+ */
6005
+ items : function (o, cb) { // Could be an object directly
6006
+ return {
6007
+ "create" : {
6008
+ "separator_before" : false,
6009
+ "separator_after" : true,
6010
+ "_disabled" : false, //(this.check("create_node", data.reference, {}, "last")),
6011
+ "label" : "Create",
6012
+ "action" : function (data) {
6013
+ var inst = $.jstree.reference(data.reference),
6014
+ obj = inst.get_node(data.reference);
6015
+ inst.create_node(obj, {}, "last", function (new_node) {
6016
+ try {
6017
+ inst.edit(new_node);
6018
+ } catch (ex) {
6019
+ setTimeout(function () { inst.edit(new_node); },0);
6020
+ }
6021
+ });
6022
+ }
6023
+ },
6024
+ "rename" : {
6025
+ "separator_before" : false,
6026
+ "separator_after" : false,
6027
+ "_disabled" : false, //(this.check("rename_node", data.reference, this.get_parent(data.reference), "")),
6028
+ "label" : "Rename",
6029
+ /*!
6030
+ "shortcut" : 113,
6031
+ "shortcut_label" : 'F2',
6032
+ "icon" : "glyphicon glyphicon-leaf",
6033
+ */
6034
+ "action" : function (data) {
6035
+ var inst = $.jstree.reference(data.reference),
6036
+ obj = inst.get_node(data.reference);
6037
+ inst.edit(obj);
6038
+ }
6039
+ },
6040
+ "remove" : {
6041
+ "separator_before" : false,
6042
+ "icon" : false,
6043
+ "separator_after" : false,
6044
+ "_disabled" : false, //(this.check("delete_node", data.reference, this.get_parent(data.reference), "")),
6045
+ "label" : "Delete",
6046
+ "action" : function (data) {
6047
+ var inst = $.jstree.reference(data.reference),
6048
+ obj = inst.get_node(data.reference);
6049
+ if(inst.is_selected(obj)) {
6050
+ inst.delete_node(inst.get_selected());
6051
+ }
6052
+ else {
6053
+ inst.delete_node(obj);
6054
+ }
6055
+ }
6056
+ },
6057
+ "ccp" : {
6058
+ "separator_before" : true,
6059
+ "icon" : false,
6060
+ "separator_after" : false,
6061
+ "label" : "Edit",
6062
+ "action" : false,
6063
+ "submenu" : {
6064
+ "cut" : {
6065
+ "separator_before" : false,
6066
+ "separator_after" : false,
6067
+ "label" : "Cut",
6068
+ "action" : function (data) {
6069
+ var inst = $.jstree.reference(data.reference),
6070
+ obj = inst.get_node(data.reference);
6071
+ if(inst.is_selected(obj)) {
6072
+ inst.cut(inst.get_top_selected());
6073
+ }
6074
+ else {
6075
+ inst.cut(obj);
6076
+ }
6077
+ }
6078
+ },
6079
+ "copy" : {
6080
+ "separator_before" : false,
6081
+ "icon" : false,
6082
+ "separator_after" : false,
6083
+ "label" : "Copy",
6084
+ "action" : function (data) {
6085
+ var inst = $.jstree.reference(data.reference),
6086
+ obj = inst.get_node(data.reference);
6087
+ if(inst.is_selected(obj)) {
6088
+ inst.copy(inst.get_top_selected());
6089
+ }
6090
+ else {
6091
+ inst.copy(obj);
6092
+ }
6093
+ }
6094
+ },
6095
+ "paste" : {
6096
+ "separator_before" : false,
6097
+ "icon" : false,
6098
+ "_disabled" : function (data) {
6099
+ return !$.jstree.reference(data.reference).can_paste();
6100
+ },
6101
+ "separator_after" : false,
6102
+ "label" : "Paste",
6103
+ "action" : function (data) {
6104
+ var inst = $.jstree.reference(data.reference),
6105
+ obj = inst.get_node(data.reference);
6106
+ inst.paste(obj);
6107
+ }
6108
+ }
6109
+ }
6110
+ }
6111
+ };
6112
+ }
6113
+ };
6114
+
6115
+ $.jstree.plugins.contextmenu = function (options, parent) {
6116
+ this.bind = function () {
6117
+ parent.bind.call(this);
6118
+
6119
+ var last_ts = 0, cto = null, ex, ey;
6120
+ this.element
6121
+ .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
6122
+ this.get_container_ul().addClass('jstree-contextmenu');
6123
+ }, this))
6124
+ .on("contextmenu.jstree", ".jstree-anchor", $.proxy(function (e, data) {
6125
+ if (e.target.tagName.toLowerCase() === 'input') {
6126
+ return;
6127
+ }
6128
+ e.preventDefault();
6129
+ last_ts = e.ctrlKey ? +new Date() : 0;
6130
+ if(data || cto) {
6131
+ last_ts = (+new Date()) + 10000;
6132
+ }
6133
+ if(cto) {
6134
+ clearTimeout(cto);
6135
+ }
6136
+ if(!this.is_loading(e.currentTarget)) {
6137
+ this.show_contextmenu(e.currentTarget, e.pageX, e.pageY, e);
6138
+ }
6139
+ }, this))
6140
+ .on("click.jstree", ".jstree-anchor", $.proxy(function (e) {
6141
+ if(this._data.contextmenu.visible && (!last_ts || (+new Date()) - last_ts > 250)) { // work around safari & macOS ctrl+click
6142
+ $.vakata.context.hide();
6143
+ }
6144
+ last_ts = 0;
6145
+ }, this))
6146
+ .on("touchstart.jstree", ".jstree-anchor", function (e) {
6147
+ if(!e.originalEvent || !e.originalEvent.changedTouches || !e.originalEvent.changedTouches[0]) {
6148
+ return;
6149
+ }
6150
+ ex = e.originalEvent.changedTouches[0].clientX;
6151
+ ey = e.originalEvent.changedTouches[0].clientY;
6152
+ cto = setTimeout(function () {
6153
+ $(e.currentTarget).trigger('contextmenu', true);
6154
+ }, 750);
6155
+ })
6156
+ .on('touchmove.vakata.jstree', function (e) {
6157
+ if(cto && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0] && (Math.abs(ex - e.originalEvent.changedTouches[0].clientX) > 10 || Math.abs(ey - e.originalEvent.changedTouches[0].clientY) > 10)) {
6158
+ clearTimeout(cto);
6159
+ $.vakata.context.hide();
6160
+ }
6161
+ })
6162
+ .on('touchend.vakata.jstree', function (e) {
6163
+ if(cto) {
6164
+ clearTimeout(cto);
6165
+ }
6166
+ });
6167
+
6168
+ /*!
6169
+ if(!('oncontextmenu' in document.body) && ('ontouchstart' in document.body)) {
6170
+ var el = null, tm = null;
6171
+ this.element
6172
+ .on("touchstart", ".jstree-anchor", function (e) {
6173
+ el = e.currentTarget;
6174
+ tm = +new Date();
6175
+ $(document).one("touchend", function (e) {
6176
+ e.target = document.elementFromPoint(e.originalEvent.targetTouches[0].pageX - window.pageXOffset, e.originalEvent.targetTouches[0].pageY - window.pageYOffset);
6177
+ e.currentTarget = e.target;
6178
+ tm = ((+(new Date())) - tm);
6179
+ if(e.target === el && tm > 600 && tm < 1000) {
6180
+ e.preventDefault();
6181
+ $(el).trigger('contextmenu', e);
6182
+ }
6183
+ el = null;
6184
+ tm = null;
6185
+ });
6186
+ });
6187
+ }
6188
+ */
6189
+ $(document).on("context_hide.vakata.jstree", $.proxy(function (e, data) {
6190
+ this._data.contextmenu.visible = false;
6191
+ $(data.reference).removeClass('jstree-context');
6192
+ }, this));
6193
+ };
6194
+ this.teardown = function () {
6195
+ if(this._data.contextmenu.visible) {
6196
+ $.vakata.context.hide();
6197
+ }
6198
+ parent.teardown.call(this);
6199
+ };
6200
+
6201
+ /**
6202
+ * prepare and show the context menu for a node
6203
+ * @name show_contextmenu(obj [, x, y])
6204
+ * @param {mixed} obj the node
6205
+ * @param {Number} x the x-coordinate relative to the document to show the menu at
6206
+ * @param {Number} y the y-coordinate relative to the document to show the menu at
6207
+ * @param {Object} e the event if available that triggered the contextmenu
6208
+ * @plugin contextmenu
6209
+ * @trigger show_contextmenu.jstree
6210
+ */
6211
+ this.show_contextmenu = function (obj, x, y, e) {
6212
+ obj = this.get_node(obj);
6213
+ if(!obj || obj.id === $.jstree.root) { return false; }
6214
+ var s = this.settings.contextmenu,
6215
+ d = this.get_node(obj, true),
6216
+ a = d.children(".jstree-anchor"),
6217
+ o = false,
6218
+ i = false;
6219
+ if(s.show_at_node || x === undefined || y === undefined) {
6220
+ o = a.offset();
6221
+ x = o.left;
6222
+ y = o.top + this._data.core.li_height;
6223
+ }
6224
+ if(this.settings.contextmenu.select_node && !this.is_selected(obj)) {
6225
+ this.activate_node(obj, e);
6226
+ }
6227
+
6228
+ i = s.items;
6229
+ if($.isFunction(i)) {
6230
+ i = i.call(this, obj, $.proxy(function (i) {
6231
+ this._show_contextmenu(obj, x, y, i);
6232
+ }, this));
6233
+ }
6234
+ if($.isPlainObject(i)) {
6235
+ this._show_contextmenu(obj, x, y, i);
6236
+ }
6237
+ };
6238
+ /**
6239
+ * show the prepared context menu for a node
6240
+ * @name _show_contextmenu(obj, x, y, i)
6241
+ * @param {mixed} obj the node
6242
+ * @param {Number} x the x-coordinate relative to the document to show the menu at
6243
+ * @param {Number} y the y-coordinate relative to the document to show the menu at
6244
+ * @param {Number} i the object of items to show
6245
+ * @plugin contextmenu
6246
+ * @trigger show_contextmenu.jstree
6247
+ * @private
6248
+ */
6249
+ this._show_contextmenu = function (obj, x, y, i) {
6250
+ var d = this.get_node(obj, true),
6251
+ a = d.children(".jstree-anchor");
6252
+ $(document).one("context_show.vakata.jstree", $.proxy(function (e, data) {
6253
+ var cls = 'jstree-contextmenu jstree-' + this.get_theme() + '-contextmenu';
6254
+ $(data.element).addClass(cls);
6255
+ a.addClass('jstree-context');
6256
+ }, this));
6257
+ this._data.contextmenu.visible = true;
6258
+ $.vakata.context.show(a, { 'x' : x, 'y' : y }, i);
6259
+ /**
6260
+ * triggered when the contextmenu is shown for a node
6261
+ * @event
6262
+ * @name show_contextmenu.jstree
6263
+ * @param {Object} node the node
6264
+ * @param {Number} x the x-coordinate of the menu relative to the document
6265
+ * @param {Number} y the y-coordinate of the menu relative to the document
6266
+ * @plugin contextmenu
6267
+ */
6268
+ this.trigger('show_contextmenu', { "node" : obj, "x" : x, "y" : y });
6269
+ };
6270
+ };
6271
+
6272
+ // contextmenu helper
6273
+ (function ($) {
6274
+ var right_to_left = false,
6275
+ vakata_context = {
6276
+ element : false,
6277
+ reference : false,
6278
+ position_x : 0,
6279
+ position_y : 0,
6280
+ items : [],
6281
+ html : "",
6282
+ is_visible : false
6283
+ };
6284
+
6285
+ $.vakata.context = {
6286
+ settings : {
6287
+ hide_onmouseleave : 0,
6288
+ icons : true
6289
+ },
6290
+ _trigger : function (event_name) {
6291
+ $(document).triggerHandler("context_" + event_name + ".vakata", {
6292
+ "reference" : vakata_context.reference,
6293
+ "element" : vakata_context.element,
6294
+ "position" : {
6295
+ "x" : vakata_context.position_x,
6296
+ "y" : vakata_context.position_y
6297
+ }
6298
+ });
6299
+ },
6300
+ _execute : function (i) {
6301
+ i = vakata_context.items[i];
6302
+ return i && (!i._disabled || ($.isFunction(i._disabled) && !i._disabled({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }))) && i.action ? i.action.call(null, {
6303
+ "item" : i,
6304
+ "reference" : vakata_context.reference,
6305
+ "element" : vakata_context.element,
6306
+ "position" : {
6307
+ "x" : vakata_context.position_x,
6308
+ "y" : vakata_context.position_y
6309
+ }
6310
+ }) : false;
6311
+ },
6312
+ _parse : function (o, is_callback) {
6313
+ if(!o) { return false; }
6314
+ if(!is_callback) {
6315
+ vakata_context.html = "";
6316
+ vakata_context.items = [];
6317
+ }
6318
+ var str = "",
6319
+ sep = false,
6320
+ tmp;
6321
+
6322
+ if(is_callback) { str += "<"+"ul>"; }
6323
+ $.each(o, function (i, val) {
6324
+ if(!val) { return true; }
6325
+ vakata_context.items.push(val);
6326
+ if(!sep && val.separator_before) {
6327
+ str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
6328
+ }
6329
+ sep = false;
6330
+ str += "<"+"li class='" + (val._class || "") + (val._disabled === true || ($.isFunction(val._disabled) && val._disabled({ "item" : val, "reference" : vakata_context.reference, "element" : vakata_context.element })) ? " vakata-contextmenu-disabled " : "") + "' "+(val.shortcut?" data-shortcut='"+val.shortcut+"' ":'')+">";
6331
+ str += "<"+"a href='#' rel='" + (vakata_context.items.length - 1) + "' " + (val.title ? "title='" + val.title + "'" : "") + ">";
6332
+ if($.vakata.context.settings.icons) {
6333
+ str += "<"+"i ";
6334
+ if(val.icon) {
6335
+ if(val.icon.indexOf("/") !== -1 || val.icon.indexOf(".") !== -1) { str += " style='background:url(\"" + val.icon + "\") center center no-repeat' "; }
6336
+ else { str += " class='" + val.icon + "' "; }
6337
+ }
6338
+ str += "><"+"/i><"+"span class='vakata-contextmenu-sep'>&#160;<"+"/span>";
6339
+ }
6340
+ str += ($.isFunction(val.label) ? val.label({ "item" : i, "reference" : vakata_context.reference, "element" : vakata_context.element }) : val.label) + (val.shortcut?' <span class="vakata-contextmenu-shortcut vakata-contextmenu-shortcut-'+val.shortcut+'">'+ (val.shortcut_label || '') +'</span>':'') + "<"+"/a>";
6341
+ if(val.submenu) {
6342
+ tmp = $.vakata.context._parse(val.submenu, true);
6343
+ if(tmp) { str += tmp; }
6344
+ }
6345
+ str += "<"+"/li>";
6346
+ if(val.separator_after) {
6347
+ str += "<"+"li class='vakata-context-separator'><"+"a href='#' " + ($.vakata.context.settings.icons ? '' : 'style="margin-left:0px;"') + ">&#160;<"+"/a><"+"/li>";
6348
+ sep = true;
6349
+ }
6350
+ });
6351
+ str = str.replace(/<li class\='vakata-context-separator'\><\/li\>$/,"");
6352
+ if(is_callback) { str += "</ul>"; }
6353
+ /**
6354
+ * triggered on the document when the contextmenu is parsed (HTML is built)
6355
+ * @event
6356
+ * @plugin contextmenu
6357
+ * @name context_parse.vakata
6358
+ * @param {jQuery} reference the element that was right clicked
6359
+ * @param {jQuery} element the DOM element of the menu itself
6360
+ * @param {Object} position the x & y coordinates of the menu
6361
+ */
6362
+ if(!is_callback) { vakata_context.html = str; $.vakata.context._trigger("parse"); }
6363
+ return str.length > 10 ? str : false;
6364
+ },
6365
+ _show_submenu : function (o) {
6366
+ o = $(o);
6367
+ if(!o.length || !o.children("ul").length) { return; }
6368
+ var e = o.children("ul"),
6369
+ xl = o.offset().left,
6370
+ x = xl + o.outerWidth(),
6371
+ y = o.offset().top,
6372
+ w = e.width(),
6373
+ h = e.height(),
6374
+ dw = $(window).width() + $(window).scrollLeft(),
6375
+ dh = $(window).height() + $(window).scrollTop();
6376
+ // може да се спести е една проверка - дали няма някой от класовете вече нагоре
6377
+ if(right_to_left) {
6378
+ o[x - (w + 10 + o.outerWidth()) < 0 ? "addClass" : "removeClass"]("vakata-context-left");
6379
+ }
6380
+ else {
6381
+ o[x + w > dw && xl > dw - x ? "addClass" : "removeClass"]("vakata-context-right");
6382
+ }
6383
+ if(y + h + 10 > dh) {
6384
+ e.css("bottom","-1px");
6385
+ }
6386
+
6387
+ //if does not fit - stick it to the side
6388
+ if (o.hasClass('vakata-context-right')) {
6389
+ if (xl < w) {
6390
+ e.css("margin-right", xl - w);
6391
+ }
6392
+ } else {
6393
+ if (dw - x < w) {
6394
+ e.css("margin-left", dw - x - w);
6395
+ }
6396
+ }
6397
+
6398
+ e.show();
6399
+ },
6400
+ show : function (reference, position, data) {
6401
+ var o, e, x, y, w, h, dw, dh, cond = true;
6402
+ if(vakata_context.element && vakata_context.element.length) {
6403
+ vakata_context.element.width('');
6404
+ }
6405
+ switch(cond) {
6406
+ case (!position && !reference):
6407
+ return false;
6408
+ case (!!position && !!reference):
6409
+ vakata_context.reference = reference;
6410
+ vakata_context.position_x = position.x;
6411
+ vakata_context.position_y = position.y;
6412
+ break;
6413
+ case (!position && !!reference):
6414
+ vakata_context.reference = reference;
6415
+ o = reference.offset();
6416
+ vakata_context.position_x = o.left + reference.outerHeight();
6417
+ vakata_context.position_y = o.top;
6418
+ break;
6419
+ case (!!position && !reference):
6420
+ vakata_context.position_x = position.x;
6421
+ vakata_context.position_y = position.y;
6422
+ break;
6423
+ }
6424
+ if(!!reference && !data && $(reference).data('vakata_contextmenu')) {
6425
+ data = $(reference).data('vakata_contextmenu');
6426
+ }
6427
+ if($.vakata.context._parse(data)) {
6428
+ vakata_context.element.html(vakata_context.html);
6429
+ }
6430
+ if(vakata_context.items.length) {
6431
+ vakata_context.element.appendTo(document.body);
6432
+ e = vakata_context.element;
6433
+ x = vakata_context.position_x;
6434
+ y = vakata_context.position_y;
6435
+ w = e.width();
6436
+ h = e.height();
6437
+ dw = $(window).width() + $(window).scrollLeft();
6438
+ dh = $(window).height() + $(window).scrollTop();
6439
+ if(right_to_left) {
6440
+ x -= (e.outerWidth() - $(reference).outerWidth());
6441
+ if(x < $(window).scrollLeft() + 20) {
6442
+ x = $(window).scrollLeft() + 20;
6443
+ }
6444
+ }
6445
+ if(x + w + 20 > dw) {
6446
+ x = dw - (w + 20);
6447
+ }
6448
+ if(y + h + 20 > dh) {
6449
+ y = dh - (h + 20);
6450
+ }
6451
+
6452
+ vakata_context.element
6453
+ .css({ "left" : x, "top" : y })
6454
+ .show()
6455
+ .find('a').first().focus().parent().addClass("vakata-context-hover");
6456
+ vakata_context.is_visible = true;
6457
+ /**
6458
+ * triggered on the document when the contextmenu is shown
6459
+ * @event
6460
+ * @plugin contextmenu
6461
+ * @name context_show.vakata
6462
+ * @param {jQuery} reference the element that was right clicked
6463
+ * @param {jQuery} element the DOM element of the menu itself
6464
+ * @param {Object} position the x & y coordinates of the menu
6465
+ */
6466
+ $.vakata.context._trigger("show");
6467
+ }
6468
+ },
6469
+ hide : function () {
6470
+ if(vakata_context.is_visible) {
6471
+ vakata_context.element.hide().find("ul").hide().end().find(':focus').blur().end().detach();
6472
+ vakata_context.is_visible = false;
6473
+ /**
6474
+ * triggered on the document when the contextmenu is hidden
6475
+ * @event
6476
+ * @plugin contextmenu
6477
+ * @name context_hide.vakata
6478
+ * @param {jQuery} reference the element that was right clicked
6479
+ * @param {jQuery} element the DOM element of the menu itself
6480
+ * @param {Object} position the x & y coordinates of the menu
6481
+ */
6482
+ $.vakata.context._trigger("hide");
6483
+ }
6484
+ }
6485
+ };
6486
+ $(function () {
6487
+ right_to_left = $(document.body).css("direction") === "rtl";
6488
+ var to = false;
6489
+
6490
+ vakata_context.element = $("<ul class='vakata-context'></ul>");
6491
+ vakata_context.element
6492
+ .on("mouseenter", "li", function (e) {
6493
+ e.stopImmediatePropagation();
6494
+
6495
+ if($.contains(this, e.relatedTarget)) {
6496
+ // премахнато заради delegate mouseleave по-долу
6497
+ // $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
6498
+ return;
6499
+ }
6500
+
6501
+ if(to) { clearTimeout(to); }
6502
+ vakata_context.element.find(".vakata-context-hover").removeClass("vakata-context-hover").end();
6503
+
6504
+ $(this)
6505
+ .siblings().find("ul").hide().end().end()
6506
+ .parentsUntil(".vakata-context", "li").addBack().addClass("vakata-context-hover");
6507
+ $.vakata.context._show_submenu(this);
6508
+ })
6509
+ // тестово - дали не натоварва?
6510
+ .on("mouseleave", "li", function (e) {
6511
+ if($.contains(this, e.relatedTarget)) { return; }
6512
+ $(this).find(".vakata-context-hover").addBack().removeClass("vakata-context-hover");
6513
+ })
6514
+ .on("mouseleave", function (e) {
6515
+ $(this).find(".vakata-context-hover").removeClass("vakata-context-hover");
6516
+ if($.vakata.context.settings.hide_onmouseleave) {
6517
+ to = setTimeout(
6518
+ (function (t) {
6519
+ return function () { $.vakata.context.hide(); };
6520
+ }(this)), $.vakata.context.settings.hide_onmouseleave);
6521
+ }
6522
+ })
6523
+ .on("click", "a", function (e) {
6524
+ e.preventDefault();
6525
+ //})
6526
+ //.on("mouseup", "a", function (e) {
6527
+ if(!$(this).blur().parent().hasClass("vakata-context-disabled") && $.vakata.context._execute($(this).attr("rel")) !== false) {
6528
+ $.vakata.context.hide();
6529
+ }
6530
+ })
6531
+ .on('keydown', 'a', function (e) {
6532
+ var o = null;
6533
+ switch(e.which) {
6534
+ case 13:
6535
+ case 32:
6536
+ e.type = "click";
6537
+ e.preventDefault();
6538
+ $(e.currentTarget).trigger(e);
6539
+ break;
6540
+ case 37:
6541
+ if(vakata_context.is_visible) {
6542
+ vakata_context.element.find(".vakata-context-hover").last().closest("li").first().find("ul").hide().find(".vakata-context-hover").removeClass("vakata-context-hover").end().end().children('a').focus();
6543
+ e.stopImmediatePropagation();
6544
+ e.preventDefault();
6545
+ }
6546
+ break;
6547
+ case 38:
6548
+ if(vakata_context.is_visible) {
6549
+ o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first();
6550
+ if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last(); }
6551
+ o.addClass("vakata-context-hover").children('a').focus();
6552
+ e.stopImmediatePropagation();
6553
+ e.preventDefault();
6554
+ }
6555
+ break;
6556
+ case 39:
6557
+ if(vakata_context.is_visible) {
6558
+ vakata_context.element.find(".vakata-context-hover").last().children("ul").show().children("li:not(.vakata-context-separator)").removeClass("vakata-context-hover").first().addClass("vakata-context-hover").children('a').focus();
6559
+ e.stopImmediatePropagation();
6560
+ e.preventDefault();
6561
+ }
6562
+ break;
6563
+ case 40:
6564
+ if(vakata_context.is_visible) {
6565
+ o = vakata_context.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").nextAll("li:not(.vakata-context-separator)").first();
6566
+ if(!o.length) { o = vakata_context.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").first(); }
6567
+ o.addClass("vakata-context-hover").children('a').focus();
6568
+ e.stopImmediatePropagation();
6569
+ e.preventDefault();
6570
+ }
6571
+ break;
6572
+ case 27:
6573
+ $.vakata.context.hide();
6574
+ e.preventDefault();
6575
+ break;
6576
+ default:
6577
+ //console.log(e.which);
6578
+ break;
6579
+ }
6580
+ })
6581
+ .on('keydown', function (e) {
6582
+ e.preventDefault();
6583
+ var a = vakata_context.element.find('.vakata-contextmenu-shortcut-' + e.which).parent();
6584
+ if(a.parent().not('.vakata-context-disabled')) {
6585
+ a.click();
6586
+ }
6587
+ });
6588
+
6589
+ $(document)
6590
+ .on("mousedown.vakata.jstree", function (e) {
6591
+ if(vakata_context.is_visible && vakata_context.element[0] !== e.target && !$.contains(vakata_context.element[0], e.target)) {
6592
+ $.vakata.context.hide();
6593
+ }
6594
+ })
6595
+ .on("context_show.vakata.jstree", function (e, data) {
6596
+ vakata_context.element.find("li:has(ul)").children("a").addClass("vakata-context-parent");
6597
+ if(right_to_left) {
6598
+ vakata_context.element.addClass("vakata-context-rtl").css("direction", "rtl");
6599
+ }
6600
+ // also apply a RTL class?
6601
+ vakata_context.element.find("ul").hide().end();
6602
+ });
6603
+ });
6604
+ }($));
6605
+ // $.jstree.defaults.plugins.push("contextmenu");
6606
+
6607
+
6608
+ /**
6609
+ * ### Drag'n'drop plugin
6610
+ *
6611
+ * Enables dragging and dropping of nodes in the tree, resulting in a move or copy operations.
6612
+ */
6613
+
6614
+ /**
6615
+ * stores all defaults for the drag'n'drop plugin
6616
+ * @name $.jstree.defaults.dnd
6617
+ * @plugin dnd
6618
+ */
6619
+ $.jstree.defaults.dnd = {
6620
+ /**
6621
+ * a boolean indicating if a copy should be possible while dragging (by pressint the meta key or Ctrl). Defaults to `true`.
6622
+ * @name $.jstree.defaults.dnd.copy
6623
+ * @plugin dnd
6624
+ */
6625
+ copy : true,
6626
+ /**
6627
+ * a number indicating how long a node should remain hovered while dragging to be opened. Defaults to `500`.
6628
+ * @name $.jstree.defaults.dnd.open_timeout
6629
+ * @plugin dnd
6630
+ */
6631
+ open_timeout : 500,
6632
+ /**
6633
+ * a function invoked each time a node is about to be dragged, invoked in the tree's scope and receives the nodes about to be dragged as an argument (array) and the event that started the drag - return `false` to prevent dragging
6634
+ * @name $.jstree.defaults.dnd.is_draggable
6635
+ * @plugin dnd
6636
+ */
6637
+ is_draggable : true,
6638
+ /**
6639
+ * a boolean indicating if checks should constantly be made while the user is dragging the node (as opposed to checking only on drop), default is `true`
6640
+ * @name $.jstree.defaults.dnd.check_while_dragging
6641
+ * @plugin dnd
6642
+ */
6643
+ check_while_dragging : true,
6644
+ /**
6645
+ * a boolean indicating if nodes from this tree should only be copied with dnd (as opposed to moved), default is `false`
6646
+ * @name $.jstree.defaults.dnd.always_copy
6647
+ * @plugin dnd
6648
+ */
6649
+ always_copy : false,
6650
+ /**
6651
+ * when dropping a node "inside", this setting indicates the position the node should go to - it can be an integer or a string: "first" (same as 0) or "last", default is `0`
6652
+ * @name $.jstree.defaults.dnd.inside_pos
6653
+ * @plugin dnd
6654
+ */
6655
+ inside_pos : 0,
6656
+ /**
6657
+ * when starting the drag on a node that is selected this setting controls if all selected nodes are dragged or only the single node, default is `true`, which means all selected nodes are dragged when the drag is started on a selected node
6658
+ * @name $.jstree.defaults.dnd.drag_selection
6659
+ * @plugin dnd
6660
+ */
6661
+ drag_selection : true,
6662
+ /**
6663
+ * controls whether dnd works on touch devices. If left as boolean true dnd will work the same as in desktop browsers, which in some cases may impair scrolling. If set to boolean false dnd will not work on touch devices. There is a special third option - string "selected" which means only selected nodes can be dragged on touch devices.
6664
+ * @name $.jstree.defaults.dnd.touch
6665
+ * @plugin dnd
6666
+ */
6667
+ touch : true,
6668
+ /**
6669
+ * controls whether items can be dropped anywhere on the node, not just on the anchor, by default only the node anchor is a valid drop target. Works best with the wholerow plugin. If enabled on mobile depending on the interface it might be hard for the user to cancel the drop, since the whole tree container will be a valid drop target.
6670
+ * @name $.jstree.defaults.dnd.large_drop_target
6671
+ * @plugin dnd
6672
+ */
6673
+ large_drop_target : false,
6674
+ /**
6675
+ * controls whether a drag can be initiated from any part of the node and not just the text/icon part, works best with the wholerow plugin. Keep in mind it can cause problems with tree scrolling on mobile depending on the interface - in that case set the touch option to "selected".
6676
+ * @name $.jstree.defaults.dnd.large_drag_target
6677
+ * @plugin dnd
6678
+ */
6679
+ large_drag_target : false,
6680
+ /**
6681
+ * controls whether use HTML5 dnd api instead of classical. That will allow better integration of dnd events with other HTML5 controls.
6682
+ * @reference http://caniuse.com/#feat=dragndrop
6683
+ * @name $.jstree.defaults.dnd.use_html5
6684
+ * @plugin dnd
6685
+ */
6686
+ use_html5: false
6687
+ };
6688
+ var drg, elm;
6689
+ // TODO: now check works by checking for each node individually, how about max_children, unique, etc?
6690
+ $.jstree.plugins.dnd = function (options, parent) {
6691
+ this.init = function (el, options) {
6692
+ parent.init.call(this, el, options);
6693
+ this.settings.dnd.use_html5 = this.settings.dnd.use_html5 && ('draggable' in document.createElement('span'));
6694
+ };
6695
+ this.bind = function () {
6696
+ parent.bind.call(this);
6697
+
6698
+ this.element
6699
+ .on(this.settings.dnd.use_html5 ? 'dragstart.jstree' : 'mousedown.jstree touchstart.jstree', this.settings.dnd.large_drag_target ? '.jstree-node' : '.jstree-anchor', $.proxy(function (e) {
6700
+ if(this.settings.dnd.large_drag_target && $(e.target).closest('.jstree-node')[0] !== e.currentTarget) {
6701
+ return true;
6702
+ }
6703
+ if(e.type === "touchstart" && (!this.settings.dnd.touch || (this.settings.dnd.touch === 'selected' && !$(e.currentTarget).closest('.jstree-node').children('.jstree-anchor').hasClass('jstree-clicked')))) {
6704
+ return true;
6705
+ }
6706
+ var obj = this.get_node(e.target),
6707
+ mlt = this.is_selected(obj) && this.settings.dnd.drag_selection ? this.get_top_selected().length : 1,
6708
+ txt = (mlt > 1 ? mlt + ' ' + this.get_string('nodes') : this.get_text(e.currentTarget));
6709
+ if(this.settings.core.force_text) {
6710
+ txt = $.vakata.html.escape(txt);
6711
+ }
6712
+ if(obj && obj.id && obj.id !== $.jstree.root && (e.which === 1 || e.type === "touchstart" || e.type === "dragstart") &&
6713
+ (this.settings.dnd.is_draggable === true || ($.isFunction(this.settings.dnd.is_draggable) && this.settings.dnd.is_draggable.call(this, (mlt > 1 ? this.get_top_selected(true) : [obj]), e)))
6714
+ ) {
6715
+ drg = { 'jstree' : true, 'origin' : this, 'obj' : this.get_node(obj,true), 'nodes' : mlt > 1 ? this.get_top_selected() : [obj.id] };
6716
+ elm = e.currentTarget;
6717
+ if (this.settings.dnd.use_html5) {
6718
+ $.vakata.dnd._trigger('start', e, { 'helper': $(), 'element': elm, 'data': drg });
6719
+ } else {
6720
+ this.element.trigger('mousedown.jstree');
6721
+ return $.vakata.dnd.start(e, drg, '<div id="jstree-dnd" class="jstree-' + this.get_theme() + ' jstree-' + this.get_theme() + '-' + this.get_theme_variant() + ' ' + ( this.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ) + '"><i class="jstree-icon jstree-er"></i>' + txt + '<ins class="jstree-copy" style="display:none;">+</ins></div>');
6722
+ }
6723
+ }
6724
+ }, this));
6725
+ if (this.settings.dnd.use_html5) {
6726
+ this.element
6727
+ .on('dragover.jstree', function (e) {
6728
+ e.preventDefault();
6729
+ $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
6730
+ return false;
6731
+ })
6732
+ //.on('dragenter.jstree', this.settings.dnd.large_drop_target ? '.jstree-node' : '.jstree-anchor', $.proxy(function (e) {
6733
+ // e.preventDefault();
6734
+ // $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
6735
+ // return false;
6736
+ // }, this))
6737
+ .on('drop.jstree', $.proxy(function (e) {
6738
+ e.preventDefault();
6739
+ $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
6740
+ return false;
6741
+ }, this));
6742
+ }
6743
+ };
6744
+ this.redraw_node = function(obj, deep, callback, force_render) {
6745
+ obj = parent.redraw_node.apply(this, arguments);
6746
+ if (obj && this.settings.dnd.use_html5) {
6747
+ if (this.settings.dnd.large_drag_target) {
6748
+ obj.setAttribute('draggable', true);
6749
+ } else {
6750
+ var i, j, tmp = null;
6751
+ for(i = 0, j = obj.childNodes.length; i < j; i++) {
6752
+ if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
6753
+ tmp = obj.childNodes[i];
6754
+ break;
6755
+ }
6756
+ }
6757
+ if(tmp) {
6758
+ tmp.setAttribute('draggable', true);
6759
+ }
6760
+ }
6761
+ }
6762
+ return obj;
6763
+ };
6764
+ };
6765
+
6766
+ $(function() {
6767
+ // bind only once for all instances
6768
+ var lastmv = false,
6769
+ laster = false,
6770
+ lastev = false,
6771
+ opento = false,
6772
+ marker = $('<div id="jstree-marker">&#160;</div>').hide(); //.appendTo('body');
6773
+
6774
+ $(document)
6775
+ .on('dragover.vakata.jstree', function (e) {
6776
+ if (elm) {
6777
+ $.vakata.dnd._trigger('move', e, { 'helper': $(), 'element': elm, 'data': drg });
6778
+ }
6779
+ })
6780
+ .on('drop.vakata.jstree', function (e) {
6781
+ if (elm) {
6782
+ $.vakata.dnd._trigger('stop', e, { 'helper': $(), 'element': elm, 'data': drg });
6783
+ elm = null;
6784
+ drg = null;
6785
+ }
6786
+ })
6787
+ .on('dnd_start.vakata.jstree', function (e, data) {
6788
+ lastmv = false;
6789
+ lastev = false;
6790
+ if(!data || !data.data || !data.data.jstree) { return; }
6791
+ marker.appendTo(document.body); //.show();
6792
+ })
6793
+ .on('dnd_move.vakata.jstree', function (e, data) {
6794
+ var isDifferentNode = data.event.target !== lastev.target;
6795
+ if(opento) {
6796
+ if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
6797
+ clearTimeout(opento);
6798
+ }
6799
+ }
6800
+ if(!data || !data.data || !data.data.jstree) { return; }
6801
+
6802
+ // if we are hovering the marker image do nothing (can happen on "inside" drags)
6803
+ if(data.event.target.id && data.event.target.id === 'jstree-marker') {
6804
+ return;
6805
+ }
6806
+ lastev = data.event;
6807
+
6808
+ var ins = $.jstree.reference(data.event.target),
6809
+ ref = false,
6810
+ off = false,
6811
+ rel = false,
6812
+ tmp, l, t, h, p, i, o, ok, t1, t2, op, ps, pr, ip, tm, is_copy, pn;
6813
+ // if we are over an instance
6814
+ if(ins && ins._data && ins._data.dnd) {
6815
+ marker.attr('class', 'jstree-' + ins.get_theme() + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ));
6816
+ is_copy = data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)));
6817
+ data.helper
6818
+ .children().attr('class', 'jstree-' + ins.get_theme() + ' jstree-' + ins.get_theme() + '-' + ins.get_theme_variant() + ' ' + ( ins.settings.core.themes.responsive ? ' jstree-dnd-responsive' : '' ))
6819
+ .find('.jstree-copy').first()[ is_copy ? 'show' : 'hide' ]();
6820
+
6821
+ // if are hovering the container itself add a new root node
6822
+ //console.log(data.event);
6823
+ if( (data.event.target === ins.element[0] || data.event.target === ins.get_container_ul()[0]) && ins.get_container_ul().children().length === 0) {
6824
+ ok = true;
6825
+ for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
6826
+ ok = ok && ins.check( (data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey)) ) ? "copy_node" : "move_node"), (data.data.origin && data.data.origin !== ins ? data.data.origin.get_node(data.data.nodes[t1]) : data.data.nodes[t1]), $.jstree.root, 'last', { 'dnd' : true, 'ref' : ins.get_node($.jstree.root), 'pos' : 'i', 'origin' : data.data.origin, 'is_multi' : (data.data.origin && data.data.origin !== ins), 'is_foreign' : (!data.data.origin) });
6827
+ if(!ok) { break; }
6828
+ }
6829
+ if(ok) {
6830
+ lastmv = { 'ins' : ins, 'par' : $.jstree.root, 'pos' : 'last' };
6831
+ marker.hide();
6832
+ data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
6833
+ if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
6834
+ data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
6835
+ }
6836
+ return;
6837
+ }
6838
+ }
6839
+ else {
6840
+ // if we are hovering a tree node
6841
+ ref = ins.settings.dnd.large_drop_target ? $(data.event.target).closest('.jstree-node').children('.jstree-anchor') : $(data.event.target).closest('.jstree-anchor');
6842
+ if(ref && ref.length && ref.parent().is('.jstree-closed, .jstree-open, .jstree-leaf')) {
6843
+ off = ref.offset();
6844
+ rel = (data.event.pageY !== undefined ? data.event.pageY : data.event.originalEvent.pageY) - off.top;
6845
+ h = ref.outerHeight();
6846
+ if(rel < h / 3) {
6847
+ o = ['b', 'i', 'a'];
6848
+ }
6849
+ else if(rel > h - h / 3) {
6850
+ o = ['a', 'i', 'b'];
6851
+ }
6852
+ else {
6853
+ o = rel > h / 2 ? ['i', 'a', 'b'] : ['i', 'b', 'a'];
6854
+ }
6855
+ $.each(o, function (j, v) {
6856
+ switch(v) {
6857
+ case 'b':
6858
+ l = off.left - 6;
6859
+ t = off.top;
6860
+ p = ins.get_parent(ref);
6861
+ i = ref.parent().index();
6862
+ break;
6863
+ case 'i':
6864
+ ip = ins.settings.dnd.inside_pos;
6865
+ tm = ins.get_node(ref.parent());
6866
+ l = off.left - 2;
6867
+ t = off.top + h / 2 + 1;
6868
+ p = tm.id;
6869
+ i = ip === 'first' ? 0 : (ip === 'last' ? tm.children.length : Math.min(ip, tm.children.length));
6870
+ break;
6871
+ case 'a':
6872
+ l = off.left - 6;
6873
+ t = off.top + h;
6874
+ p = ins.get_parent(ref);
6875
+ i = ref.parent().index() + 1;
6876
+ break;
6877
+ }
6878
+ ok = true;
6879
+ for(t1 = 0, t2 = data.data.nodes.length; t1 < t2; t1++) {
6880
+ op = data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey))) ? "copy_node" : "move_node";
6881
+ ps = i;
6882
+ if(op === "move_node" && v === 'a' && (data.data.origin && data.data.origin === ins) && p === ins.get_parent(data.data.nodes[t1])) {
6883
+ pr = ins.get_node(p);
6884
+ if(ps > $.inArray(data.data.nodes[t1], pr.children)) {
6885
+ ps -= 1;
6886
+ }
6887
+ }
6888
+ ok = ok && ( (ins && ins.settings && ins.settings.dnd && ins.settings.dnd.check_while_dragging === false) || ins.check(op, (data.data.origin && data.data.origin !== ins ? data.data.origin.get_node(data.data.nodes[t1]) : data.data.nodes[t1]), p, ps, { 'dnd' : true, 'ref' : ins.get_node(ref.parent()), 'pos' : v, 'origin' : data.data.origin, 'is_multi' : (data.data.origin && data.data.origin !== ins), 'is_foreign' : (!data.data.origin) }) );
6889
+ if(!ok) {
6890
+ if(ins && ins.last_error) { laster = ins.last_error(); }
6891
+ break;
6892
+ }
6893
+ }
6894
+ if(v === 'i' && ref.parent().is('.jstree-closed') && ins.settings.dnd.open_timeout) {
6895
+ if (!data.event || data.event.type !== 'dragover' || isDifferentNode) {
6896
+ if (opento) { clearTimeout(opento); }
6897
+ opento = setTimeout((function (x, z) { return function () { x.open_node(z); }; }(ins, ref)), ins.settings.dnd.open_timeout);
6898
+ }
6899
+ }
6900
+ if(ok) {
6901
+ pn = ins.get_node(p, true);
6902
+ if (!pn.hasClass('.jstree-dnd-parent')) {
6903
+ $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
6904
+ pn.addClass('jstree-dnd-parent');
6905
+ }
6906
+ lastmv = { 'ins' : ins, 'par' : p, 'pos' : v === 'i' && ip === 'last' && i === 0 && !ins.is_loaded(tm) ? 'last' : i };
6907
+ marker.css({ 'left' : l + 'px', 'top' : t + 'px' }).show();
6908
+ data.helper.find('.jstree-icon').first().removeClass('jstree-er').addClass('jstree-ok');
6909
+ if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
6910
+ data.event.originalEvent.dataTransfer.dropEffect = is_copy ? 'copy' : 'move';
6911
+ }
6912
+ laster = {};
6913
+ o = true;
6914
+ return false;
6915
+ }
6916
+ });
6917
+ if(o === true) { return; }
6918
+ }
6919
+ }
6920
+ }
6921
+ $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
6922
+ lastmv = false;
6923
+ data.helper.find('.jstree-icon').removeClass('jstree-ok').addClass('jstree-er');
6924
+ if (data.event.originalEvent && data.event.originalEvent.dataTransfer) {
6925
+ //data.event.originalEvent.dataTransfer.dropEffect = 'none';
6926
+ }
6927
+ marker.hide();
6928
+ })
6929
+ .on('dnd_scroll.vakata.jstree', function (e, data) {
6930
+ if(!data || !data.data || !data.data.jstree) { return; }
6931
+ marker.hide();
6932
+ lastmv = false;
6933
+ lastev = false;
6934
+ data.helper.find('.jstree-icon').first().removeClass('jstree-ok').addClass('jstree-er');
6935
+ })
6936
+ .on('dnd_stop.vakata.jstree', function (e, data) {
6937
+ $('.jstree-dnd-parent').removeClass('jstree-dnd-parent');
6938
+ if(opento) { clearTimeout(opento); }
6939
+ if(!data || !data.data || !data.data.jstree) { return; }
6940
+ marker.hide().detach();
6941
+ var i, j, nodes = [];
6942
+ if(lastmv) {
6943
+ for(i = 0, j = data.data.nodes.length; i < j; i++) {
6944
+ nodes[i] = data.data.origin ? data.data.origin.get_node(data.data.nodes[i]) : data.data.nodes[i];
6945
+ }
6946
+ lastmv.ins[ data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (data.event.metaKey || data.event.ctrlKey))) ? 'copy_node' : 'move_node' ](nodes, lastmv.par, lastmv.pos, false, false, false, data.data.origin);
6947
+ }
6948
+ else {
6949
+ i = $(data.event.target).closest('.jstree');
6950
+ if(i.length && laster && laster.error && laster.error === 'check') {
6951
+ i = i.jstree(true);
6952
+ if(i) {
6953
+ i.settings.core.error.call(this, laster);
6954
+ }
6955
+ }
6956
+ }
6957
+ lastev = false;
6958
+ lastmv = false;
6959
+ })
6960
+ .on('keyup.jstree keydown.jstree', function (e, data) {
6961
+ data = $.vakata.dnd._get();
6962
+ if(data && data.data && data.data.jstree) {
6963
+ if (e.type === "keyup" && e.which === 27) {
6964
+ if (opento) { clearTimeout(opento); }
6965
+ lastmv = false;
6966
+ laster = false;
6967
+ lastev = false;
6968
+ opento = false;
6969
+ marker.hide().detach();
6970
+ $.vakata.dnd._clean();
6971
+ } else {
6972
+ data.helper.find('.jstree-copy').first()[ data.data.origin && (data.data.origin.settings.dnd.always_copy || (data.data.origin.settings.dnd.copy && (e.metaKey || e.ctrlKey))) ? 'show' : 'hide' ]();
6973
+ if(lastev) {
6974
+ lastev.metaKey = e.metaKey;
6975
+ lastev.ctrlKey = e.ctrlKey;
6976
+ $.vakata.dnd._trigger('move', lastev);
6977
+ }
6978
+ }
6979
+ }
6980
+ });
6981
+ });
6982
+
6983
+ // helpers
6984
+ (function ($) {
6985
+ $.vakata.html = {
6986
+ div : $('<div />'),
6987
+ escape : function (str) {
6988
+ return $.vakata.html.div.text(str).html();
6989
+ },
6990
+ strip : function (str) {
6991
+ return $.vakata.html.div.empty().append($.parseHTML(str)).text();
6992
+ }
6993
+ };
6994
+ // private variable
6995
+ var vakata_dnd = {
6996
+ element : false,
6997
+ target : false,
6998
+ is_down : false,
6999
+ is_drag : false,
7000
+ helper : false,
7001
+ helper_w: 0,
7002
+ data : false,
7003
+ init_x : 0,
7004
+ init_y : 0,
7005
+ scroll_l: 0,
7006
+ scroll_t: 0,
7007
+ scroll_e: false,
7008
+ scroll_i: false,
7009
+ is_touch: false
7010
+ };
7011
+ $.vakata.dnd = {
7012
+ settings : {
7013
+ scroll_speed : 10,
7014
+ scroll_proximity : 20,
7015
+ helper_left : 5,
7016
+ helper_top : 10,
7017
+ threshold : 5,
7018
+ threshold_touch : 10
7019
+ },
7020
+ _trigger : function (event_name, e, data) {
7021
+ if (data === undefined) {
7022
+ data = $.vakata.dnd._get();
7023
+ }
7024
+ data.event = e;
7025
+ $(document).triggerHandler("dnd_" + event_name + ".vakata", data);
7026
+ },
7027
+ _get : function () {
7028
+ return {
7029
+ "data" : vakata_dnd.data,
7030
+ "element" : vakata_dnd.element,
7031
+ "helper" : vakata_dnd.helper
7032
+ };
7033
+ },
7034
+ _clean : function () {
7035
+ if(vakata_dnd.helper) { vakata_dnd.helper.remove(); }
7036
+ if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
7037
+ vakata_dnd = {
7038
+ element : false,
7039
+ target : false,
7040
+ is_down : false,
7041
+ is_drag : false,
7042
+ helper : false,
7043
+ helper_w: 0,
7044
+ data : false,
7045
+ init_x : 0,
7046
+ init_y : 0,
7047
+ scroll_l: 0,
7048
+ scroll_t: 0,
7049
+ scroll_e: false,
7050
+ scroll_i: false,
7051
+ is_touch: false
7052
+ };
7053
+ $(document).off("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
7054
+ $(document).off("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
7055
+ },
7056
+ _scroll : function (init_only) {
7057
+ if(!vakata_dnd.scroll_e || (!vakata_dnd.scroll_l && !vakata_dnd.scroll_t)) {
7058
+ if(vakata_dnd.scroll_i) { clearInterval(vakata_dnd.scroll_i); vakata_dnd.scroll_i = false; }
7059
+ return false;
7060
+ }
7061
+ if(!vakata_dnd.scroll_i) {
7062
+ vakata_dnd.scroll_i = setInterval($.vakata.dnd._scroll, 100);
7063
+ return false;
7064
+ }
7065
+ if(init_only === true) { return false; }
7066
+
7067
+ var i = vakata_dnd.scroll_e.scrollTop(),
7068
+ j = vakata_dnd.scroll_e.scrollLeft();
7069
+ vakata_dnd.scroll_e.scrollTop(i + vakata_dnd.scroll_t * $.vakata.dnd.settings.scroll_speed);
7070
+ vakata_dnd.scroll_e.scrollLeft(j + vakata_dnd.scroll_l * $.vakata.dnd.settings.scroll_speed);
7071
+ if(i !== vakata_dnd.scroll_e.scrollTop() || j !== vakata_dnd.scroll_e.scrollLeft()) {
7072
+ /**
7073
+ * triggered on the document when a drag causes an element to scroll
7074
+ * @event
7075
+ * @plugin dnd
7076
+ * @name dnd_scroll.vakata
7077
+ * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
7078
+ * @param {DOM} element the DOM element being dragged
7079
+ * @param {jQuery} helper the helper shown next to the mouse
7080
+ * @param {jQuery} event the element that is scrolling
7081
+ */
7082
+ $.vakata.dnd._trigger("scroll", vakata_dnd.scroll_e);
7083
+ }
7084
+ },
7085
+ start : function (e, data, html) {
7086
+ if(e.type === "touchstart" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
7087
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
7088
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
7089
+ e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
7090
+ }
7091
+ if(vakata_dnd.is_drag) { $.vakata.dnd.stop({}); }
7092
+ try {
7093
+ e.currentTarget.unselectable = "on";
7094
+ e.currentTarget.onselectstart = function() { return false; };
7095
+ if(e.currentTarget.style) {
7096
+ e.currentTarget.style.touchAction = "none";
7097
+ e.currentTarget.style.msTouchAction = "none";
7098
+ e.currentTarget.style.MozUserSelect = "none";
7099
+ }
7100
+ } catch(ignore) { }
7101
+ vakata_dnd.init_x = e.pageX;
7102
+ vakata_dnd.init_y = e.pageY;
7103
+ vakata_dnd.data = data;
7104
+ vakata_dnd.is_down = true;
7105
+ vakata_dnd.element = e.currentTarget;
7106
+ vakata_dnd.target = e.target;
7107
+ vakata_dnd.is_touch = e.type === "touchstart";
7108
+ if(html !== false) {
7109
+ vakata_dnd.helper = $("<div id='vakata-dnd'></div>").html(html).css({
7110
+ "display" : "block",
7111
+ "margin" : "0",
7112
+ "padding" : "0",
7113
+ "position" : "absolute",
7114
+ "top" : "-2000px",
7115
+ "lineHeight" : "16px",
7116
+ "zIndex" : "10000"
7117
+ });
7118
+ }
7119
+ $(document).on("mousemove.vakata.jstree touchmove.vakata.jstree", $.vakata.dnd.drag);
7120
+ $(document).on("mouseup.vakata.jstree touchend.vakata.jstree", $.vakata.dnd.stop);
7121
+ return false;
7122
+ },
7123
+ drag : function (e) {
7124
+ if(e.type === "touchmove" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
7125
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
7126
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
7127
+ e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
7128
+ }
7129
+ if(!vakata_dnd.is_down) { return; }
7130
+ if(!vakata_dnd.is_drag) {
7131
+ if(
7132
+ Math.abs(e.pageX - vakata_dnd.init_x) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold) ||
7133
+ Math.abs(e.pageY - vakata_dnd.init_y) > (vakata_dnd.is_touch ? $.vakata.dnd.settings.threshold_touch : $.vakata.dnd.settings.threshold)
7134
+ ) {
7135
+ if(vakata_dnd.helper) {
7136
+ vakata_dnd.helper.appendTo(document.body);
7137
+ vakata_dnd.helper_w = vakata_dnd.helper.outerWidth();
7138
+ }
7139
+ vakata_dnd.is_drag = true;
7140
+ $(vakata_dnd.target).one('click.vakata', false);
7141
+ /**
7142
+ * triggered on the document when a drag starts
7143
+ * @event
7144
+ * @plugin dnd
7145
+ * @name dnd_start.vakata
7146
+ * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
7147
+ * @param {DOM} element the DOM element being dragged
7148
+ * @param {jQuery} helper the helper shown next to the mouse
7149
+ * @param {Object} event the event that caused the start (probably mousemove)
7150
+ */
7151
+ $.vakata.dnd._trigger("start", e);
7152
+ }
7153
+ else { return; }
7154
+ }
7155
+
7156
+ var d = false, w = false,
7157
+ dh = false, wh = false,
7158
+ dw = false, ww = false,
7159
+ dt = false, dl = false,
7160
+ ht = false, hl = false;
7161
+
7162
+ vakata_dnd.scroll_t = 0;
7163
+ vakata_dnd.scroll_l = 0;
7164
+ vakata_dnd.scroll_e = false;
7165
+ $($(e.target).parentsUntil("body").addBack().get().reverse())
7166
+ .filter(function () {
7167
+ return (/^auto|scroll$/).test($(this).css("overflow")) &&
7168
+ (this.scrollHeight > this.offsetHeight || this.scrollWidth > this.offsetWidth);
7169
+ })
7170
+ .each(function () {
7171
+ var t = $(this), o = t.offset();
7172
+ if(this.scrollHeight > this.offsetHeight) {
7173
+ if(o.top + t.height() - e.pageY < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
7174
+ if(e.pageY - o.top < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
7175
+ }
7176
+ if(this.scrollWidth > this.offsetWidth) {
7177
+ if(o.left + t.width() - e.pageX < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
7178
+ if(e.pageX - o.left < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
7179
+ }
7180
+ if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
7181
+ vakata_dnd.scroll_e = $(this);
7182
+ return false;
7183
+ }
7184
+ });
7185
+
7186
+ if(!vakata_dnd.scroll_e) {
7187
+ d = $(document); w = $(window);
7188
+ dh = d.height(); wh = w.height();
7189
+ dw = d.width(); ww = w.width();
7190
+ dt = d.scrollTop(); dl = d.scrollLeft();
7191
+ if(dh > wh && e.pageY - dt < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = -1; }
7192
+ if(dh > wh && wh - (e.pageY - dt) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_t = 1; }
7193
+ if(dw > ww && e.pageX - dl < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = -1; }
7194
+ if(dw > ww && ww - (e.pageX - dl) < $.vakata.dnd.settings.scroll_proximity) { vakata_dnd.scroll_l = 1; }
7195
+ if(vakata_dnd.scroll_t || vakata_dnd.scroll_l) {
7196
+ vakata_dnd.scroll_e = d;
7197
+ }
7198
+ }
7199
+ if(vakata_dnd.scroll_e) { $.vakata.dnd._scroll(true); }
7200
+
7201
+ if(vakata_dnd.helper) {
7202
+ ht = parseInt(e.pageY + $.vakata.dnd.settings.helper_top, 10);
7203
+ hl = parseInt(e.pageX + $.vakata.dnd.settings.helper_left, 10);
7204
+ if(dh && ht + 25 > dh) { ht = dh - 50; }
7205
+ if(dw && hl + vakata_dnd.helper_w > dw) { hl = dw - (vakata_dnd.helper_w + 2); }
7206
+ vakata_dnd.helper.css({
7207
+ left : hl + "px",
7208
+ top : ht + "px"
7209
+ });
7210
+ }
7211
+ /**
7212
+ * triggered on the document when a drag is in progress
7213
+ * @event
7214
+ * @plugin dnd
7215
+ * @name dnd_move.vakata
7216
+ * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
7217
+ * @param {DOM} element the DOM element being dragged
7218
+ * @param {jQuery} helper the helper shown next to the mouse
7219
+ * @param {Object} event the event that caused this to trigger (most likely mousemove)
7220
+ */
7221
+ $.vakata.dnd._trigger("move", e);
7222
+ return false;
7223
+ },
7224
+ stop : function (e) {
7225
+ if(e.type === "touchend" && e.originalEvent && e.originalEvent.changedTouches && e.originalEvent.changedTouches[0]) {
7226
+ e.pageX = e.originalEvent.changedTouches[0].pageX;
7227
+ e.pageY = e.originalEvent.changedTouches[0].pageY;
7228
+ e.target = document.elementFromPoint(e.originalEvent.changedTouches[0].pageX - window.pageXOffset, e.originalEvent.changedTouches[0].pageY - window.pageYOffset);
7229
+ }
7230
+ if(vakata_dnd.is_drag) {
7231
+ /**
7232
+ * triggered on the document when a drag stops (the dragged element is dropped)
7233
+ * @event
7234
+ * @plugin dnd
7235
+ * @name dnd_stop.vakata
7236
+ * @param {Mixed} data any data supplied with the call to $.vakata.dnd.start
7237
+ * @param {DOM} element the DOM element being dragged
7238
+ * @param {jQuery} helper the helper shown next to the mouse
7239
+ * @param {Object} event the event that caused the stop
7240
+ */
7241
+ if (e.target !== vakata_dnd.target) {
7242
+ $(vakata_dnd.target).off('click.vakata');
7243
+ }
7244
+ $.vakata.dnd._trigger("stop", e);
7245
+ }
7246
+ else {
7247
+ if(e.type === "touchend" && e.target === vakata_dnd.target) {
7248
+ var to = setTimeout(function () { $(e.target).click(); }, 100);
7249
+ $(e.target).one('click', function() { if(to) { clearTimeout(to); } });
7250
+ }
7251
+ }
7252
+ $.vakata.dnd._clean();
7253
+ return false;
7254
+ }
7255
+ };
7256
+ }($));
7257
+
7258
+ // include the dnd plugin by default
7259
+ // $.jstree.defaults.plugins.push("dnd");
7260
+
7261
+
7262
+ /**
7263
+ * ### Massload plugin
7264
+ *
7265
+ * Adds massload functionality to jsTree, so that multiple nodes can be loaded in a single request (only useful with lazy loading).
7266
+ */
7267
+
7268
+ /**
7269
+ * massload configuration
7270
+ *
7271
+ * It is possible to set this to a standard jQuery-like AJAX config.
7272
+ * In addition to the standard jQuery ajax options here you can supply functions for `data` and `url`, the functions will be run in the current instance's scope and a param will be passed indicating which node IDs need to be loaded, the return value of those functions will be used.
7273
+ *
7274
+ * You can also set this to a function, that function will receive the node IDs being loaded as argument and a second param which is a function (callback) which should be called with the result.
7275
+ *
7276
+ * Both the AJAX and the function approach rely on the same return value - an object where the keys are the node IDs, and the value is the children of that node as an array.
7277
+ *
7278
+ * {
7279
+ * "id1" : [{ "text" : "Child of ID1", "id" : "c1" }, { "text" : "Another child of ID1", "id" : "c2" }],
7280
+ * "id2" : [{ "text" : "Child of ID2", "id" : "c3" }]
7281
+ * }
7282
+ *
7283
+ * @name $.jstree.defaults.massload
7284
+ * @plugin massload
7285
+ */
7286
+ $.jstree.defaults.massload = null;
7287
+ $.jstree.plugins.massload = function (options, parent) {
7288
+ this.init = function (el, options) {
7289
+ this._data.massload = {};
7290
+ parent.init.call(this, el, options);
7291
+ };
7292
+ this._load_nodes = function (nodes, callback, is_callback, force_reload) {
7293
+ var s = this.settings.massload,
7294
+ nodesString = JSON.stringify(nodes),
7295
+ toLoad = [],
7296
+ m = this._model.data,
7297
+ i, j, dom;
7298
+ if (!is_callback) {
7299
+ for(i = 0, j = nodes.length; i < j; i++) {
7300
+ if(!m[nodes[i]] || ( (!m[nodes[i]].state.loaded && !m[nodes[i]].state.failed) || force_reload) ) {
7301
+ toLoad.push(nodes[i]);
7302
+ dom = this.get_node(nodes[i], true);
7303
+ if (dom && dom.length) {
7304
+ dom.addClass("jstree-loading").attr('aria-busy',true);
7305
+ }
7306
+ }
7307
+ }
7308
+ this._data.massload = {};
7309
+ if (toLoad.length) {
7310
+ if($.isFunction(s)) {
7311
+ return s.call(this, toLoad, $.proxy(function (data) {
7312
+ var i, j;
7313
+ if(data) {
7314
+ for(i in data) {
7315
+ if(data.hasOwnProperty(i)) {
7316
+ this._data.massload[i] = data[i];
7317
+ }
7318
+ }
7319
+ }
7320
+ for(i = 0, j = nodes.length; i < j; i++) {
7321
+ dom = this.get_node(nodes[i], true);
7322
+ if (dom && dom.length) {
7323
+ dom.removeClass("jstree-loading").attr('aria-busy',false);
7324
+ }
7325
+ }
7326
+ parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7327
+ }, this));
7328
+ }
7329
+ if(typeof s === 'object' && s && s.url) {
7330
+ s = $.extend(true, {}, s);
7331
+ if($.isFunction(s.url)) {
7332
+ s.url = s.url.call(this, toLoad);
7333
+ }
7334
+ if($.isFunction(s.data)) {
7335
+ s.data = s.data.call(this, toLoad);
7336
+ }
7337
+ return $.ajax(s)
7338
+ .done($.proxy(function (data,t,x) {
7339
+ var i, j;
7340
+ if(data) {
7341
+ for(i in data) {
7342
+ if(data.hasOwnProperty(i)) {
7343
+ this._data.massload[i] = data[i];
7344
+ }
7345
+ }
7346
+ }
7347
+ for(i = 0, j = nodes.length; i < j; i++) {
7348
+ dom = this.get_node(nodes[i], true);
7349
+ if (dom && dom.length) {
7350
+ dom.removeClass("jstree-loading").attr('aria-busy',false);
7351
+ }
7352
+ }
7353
+ parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7354
+ }, this))
7355
+ .fail($.proxy(function (f) {
7356
+ parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7357
+ }, this));
7358
+ }
7359
+ }
7360
+ }
7361
+ return parent._load_nodes.call(this, nodes, callback, is_callback, force_reload);
7362
+ };
7363
+ this._load_node = function (obj, callback) {
7364
+ var data = this._data.massload[obj.id],
7365
+ rslt = null, dom;
7366
+ if(data) {
7367
+ rslt = this[typeof data === 'string' ? '_append_html_data' : '_append_json_data'](
7368
+ obj,
7369
+ typeof data === 'string' ? $($.parseHTML(data)).filter(function () { return this.nodeType !== 3; }) : data,
7370
+ function (status) { callback.call(this, status); }
7371
+ );
7372
+ dom = this.get_node(obj.id, true);
7373
+ if (dom && dom.length) {
7374
+ dom.removeClass("jstree-loading").attr('aria-busy',false);
7375
+ }
7376
+ delete this._data.massload[obj.id];
7377
+ return rslt;
7378
+ }
7379
+ return parent._load_node.call(this, obj, callback);
7380
+ };
7381
+ };
7382
+
7383
+ /**
7384
+ * ### Search plugin
7385
+ *
7386
+ * Adds search functionality to jsTree.
7387
+ */
7388
+
7389
+ /**
7390
+ * stores all defaults for the search plugin
7391
+ * @name $.jstree.defaults.search
7392
+ * @plugin search
7393
+ */
7394
+ $.jstree.defaults.search = {
7395
+ /**
7396
+ * a jQuery-like AJAX config, which jstree uses if a server should be queried for results.
7397
+ *
7398
+ * A `str` (which is the search string) parameter will be added with the request, an optional `inside` parameter will be added if the search is limited to a node id. The expected result is a JSON array with nodes that need to be opened so that matching nodes will be revealed.
7399
+ * Leave this setting as `false` to not query the server. You can also set this to a function, which will be invoked in the instance's scope and receive 3 parameters - the search string, the callback to call with the array of nodes to load, and the optional node ID to limit the search to
7400
+ * @name $.jstree.defaults.search.ajax
7401
+ * @plugin search
7402
+ */
7403
+ ajax : false,
7404
+ /**
7405
+ * Indicates if the search should be fuzzy or not (should `chnd3` match `child node 3`). Default is `false`.
7406
+ * @name $.jstree.defaults.search.fuzzy
7407
+ * @plugin search
7408
+ */
7409
+ fuzzy : false,
7410
+ /**
7411
+ * Indicates if the search should be case sensitive. Default is `false`.
7412
+ * @name $.jstree.defaults.search.case_sensitive
7413
+ * @plugin search
7414
+ */
7415
+ case_sensitive : false,
7416
+ /**
7417
+ * Indicates if the tree should be filtered (by default) to show only matching nodes (keep in mind this can be a heavy on large trees in old browsers).
7418
+ * This setting can be changed at runtime when calling the search method. Default is `false`.
7419
+ * @name $.jstree.defaults.search.show_only_matches
7420
+ * @plugin search
7421
+ */
7422
+ show_only_matches : false,
7423
+ /**
7424
+ * Indicates if the children of matched element are shown (when show_only_matches is true)
7425
+ * This setting can be changed at runtime when calling the search method. Default is `false`.
7426
+ * @name $.jstree.defaults.search.show_only_matches_children
7427
+ * @plugin search
7428
+ */
7429
+ show_only_matches_children : false,
7430
+ /**
7431
+ * 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`.
7432
+ * @name $.jstree.defaults.search.close_opened_onclear
7433
+ * @plugin search
7434
+ */
7435
+ close_opened_onclear : true,
7436
+ /**
7437
+ * Indicates if only leaf nodes should be included in search results. Default is `false`.
7438
+ * @name $.jstree.defaults.search.search_leaves_only
7439
+ * @plugin search
7440
+ */
7441
+ search_leaves_only : false,
7442
+ /**
7443
+ * If set to a function it wil be called in the instance's scope with two arguments - search string and node (where node will be every node in the structure, so use with caution).
7444
+ * If the function returns a truthy value the node will be considered a match (it might not be displayed if search_only_leaves is set to true and the node is not a leaf). Default is `false`.
7445
+ * @name $.jstree.defaults.search.search_callback
7446
+ * @plugin search
7447
+ */
7448
+ search_callback : false
7449
+ };
7450
+
7451
+ $.jstree.plugins.search = function (options, parent) {
7452
+ this.bind = function () {
7453
+ parent.bind.call(this);
7454
+
7455
+ this._data.search.str = "";
7456
+ this._data.search.dom = $();
7457
+ this._data.search.res = [];
7458
+ this._data.search.opn = [];
7459
+ this._data.search.som = false;
7460
+ this._data.search.smc = false;
7461
+ this._data.search.hdn = [];
7462
+
7463
+ this.element
7464
+ .on("search.jstree", $.proxy(function (e, data) {
7465
+ if(this._data.search.som && data.res.length) {
7466
+ var m = this._model.data, i, j, p = [], k, l;
7467
+ for(i = 0, j = data.res.length; i < j; i++) {
7468
+ if(m[data.res[i]] && !m[data.res[i]].state.hidden) {
7469
+ p.push(data.res[i]);
7470
+ p = p.concat(m[data.res[i]].parents);
7471
+ if(this._data.search.smc) {
7472
+ for (k = 0, l = m[data.res[i]].children_d.length; k < l; k++) {
7473
+ if (m[m[data.res[i]].children_d[k]] && !m[m[data.res[i]].children_d[k]].state.hidden) {
7474
+ p.push(m[data.res[i]].children_d[k]);
7475
+ }
7476
+ }
7477
+ }
7478
+ }
7479
+ }
7480
+ p = $.vakata.array_remove_item($.vakata.array_unique(p), $.jstree.root);
7481
+ this._data.search.hdn = this.hide_all(true);
7482
+ this.show_node(p, true);
7483
+ this.redraw(true);
7484
+ }
7485
+ }, this))
7486
+ .on("clear_search.jstree", $.proxy(function (e, data) {
7487
+ if(this._data.search.som && data.res.length) {
7488
+ this.show_node(this._data.search.hdn, true);
7489
+ this.redraw(true);
7490
+ }
7491
+ }, this));
7492
+ };
7493
+ /**
7494
+ * used to search the tree nodes for a given string
7495
+ * @name search(str [, skip_async])
7496
+ * @param {String} str the search string
7497
+ * @param {Boolean} skip_async if set to true server will not be queried even if configured
7498
+ * @param {Boolean} show_only_matches if set to true only matching nodes will be shown (keep in mind this can be very slow on large trees or old browsers)
7499
+ * @param {mixed} inside an optional node to whose children to limit the search
7500
+ * @param {Boolean} append if set to true the results of this search are appended to the previous search
7501
+ * @plugin search
7502
+ * @trigger search.jstree
7503
+ */
7504
+ this.search = function (str, skip_async, show_only_matches, inside, append, show_only_matches_children) {
7505
+ if(str === false || $.trim(str.toString()) === "") {
7506
+ return this.clear_search();
7507
+ }
7508
+ inside = this.get_node(inside);
7509
+ inside = inside && inside.id ? inside.id : null;
7510
+ str = str.toString();
7511
+ var s = this.settings.search,
7512
+ a = s.ajax ? s.ajax : false,
7513
+ m = this._model.data,
7514
+ f = null,
7515
+ r = [],
7516
+ p = [], i, j;
7517
+ if(this._data.search.res.length && !append) {
7518
+ this.clear_search();
7519
+ }
7520
+ if(show_only_matches === undefined) {
7521
+ show_only_matches = s.show_only_matches;
7522
+ }
7523
+ if(show_only_matches_children === undefined) {
7524
+ show_only_matches_children = s.show_only_matches_children;
7525
+ }
7526
+ if(!skip_async && a !== false) {
7527
+ if($.isFunction(a)) {
7528
+ return a.call(this, str, $.proxy(function (d) {
7529
+ if(d && d.d) { d = d.d; }
7530
+ this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
7531
+ this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
7532
+ });
7533
+ }, this), inside);
7534
+ }
7535
+ else {
7536
+ a = $.extend({}, a);
7537
+ if(!a.data) { a.data = {}; }
7538
+ a.data.str = str;
7539
+ if(inside) {
7540
+ a.data.inside = inside;
7541
+ }
7542
+ if (this._data.search.lastRequest) {
7543
+ this._data.search.lastRequest.abort();
7544
+ }
7545
+ this._data.search.lastRequest = $.ajax(a)
7546
+ .fail($.proxy(function () {
7547
+ this._data.core.last_error = { 'error' : 'ajax', 'plugin' : 'search', 'id' : 'search_01', 'reason' : 'Could not load search parents', 'data' : JSON.stringify(a) };
7548
+ this.settings.core.error.call(this, this._data.core.last_error);
7549
+ }, this))
7550
+ .done($.proxy(function (d) {
7551
+ if(d && d.d) { d = d.d; }
7552
+ this._load_nodes(!$.isArray(d) ? [] : $.vakata.array_unique(d), function () {
7553
+ this.search(str, true, show_only_matches, inside, append, show_only_matches_children);
7554
+ });
7555
+ }, this));
7556
+ return this._data.search.lastRequest;
7557
+ }
7558
+ }
7559
+ if(!append) {
7560
+ this._data.search.str = str;
7561
+ this._data.search.dom = $();
7562
+ this._data.search.res = [];
7563
+ this._data.search.opn = [];
7564
+ this._data.search.som = show_only_matches;
7565
+ this._data.search.smc = show_only_matches_children;
7566
+ }
7567
+
7568
+ f = new $.vakata.search(str, true, { caseSensitive : s.case_sensitive, fuzzy : s.fuzzy });
7569
+ $.each(m[inside ? inside : $.jstree.root].children_d, function (ii, i) {
7570
+ var v = m[i];
7571
+ if(v.text && !v.state.hidden && (!s.search_leaves_only || (v.state.loaded && v.children.length === 0)) && ( (s.search_callback && s.search_callback.call(this, str, v)) || (!s.search_callback && f.search(v.text).isMatch) ) ) {
7572
+ r.push(i);
7573
+ p = p.concat(v.parents);
7574
+ }
7575
+ });
7576
+ if(r.length) {
7577
+ p = $.vakata.array_unique(p);
7578
+ for(i = 0, j = p.length; i < j; i++) {
7579
+ if(p[i] !== $.jstree.root && m[p[i]] && this.open_node(p[i], null, 0) === true) {
7580
+ this._data.search.opn.push(p[i]);
7581
+ }
7582
+ }
7583
+ if(!append) {
7584
+ this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(r, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #')));
7585
+ this._data.search.res = r;
7586
+ }
7587
+ else {
7588
+ this._data.search.dom = this._data.search.dom.add($(this.element[0].querySelectorAll('#' + $.map(r, function (v) { return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&'); }).join(', #'))));
7589
+ this._data.search.res = $.vakata.array_unique(this._data.search.res.concat(r));
7590
+ }
7591
+ this._data.search.dom.children(".jstree-anchor").addClass('jstree-search');
7592
+ }
7593
+ /**
7594
+ * triggered after search is complete
7595
+ * @event
7596
+ * @name search.jstree
7597
+ * @param {jQuery} nodes a jQuery collection of matching nodes
7598
+ * @param {String} str the search string
7599
+ * @param {Array} res a collection of objects represeing the matching nodes
7600
+ * @plugin search
7601
+ */
7602
+ this.trigger('search', { nodes : this._data.search.dom, str : str, res : this._data.search.res, show_only_matches : show_only_matches });
7603
+ };
7604
+ /**
7605
+ * used to clear the last search (removes classes and shows all nodes if filtering is on)
7606
+ * @name clear_search()
7607
+ * @plugin search
7608
+ * @trigger clear_search.jstree
7609
+ */
7610
+ this.clear_search = function () {
7611
+ if(this.settings.search.close_opened_onclear) {
7612
+ this.close_node(this._data.search.opn, 0);
7613
+ }
7614
+ /**
7615
+ * triggered after search is complete
7616
+ * @event
7617
+ * @name clear_search.jstree
7618
+ * @param {jQuery} nodes a jQuery collection of matching nodes (the result from the last search)
7619
+ * @param {String} str the search string (the last search string)
7620
+ * @param {Array} res a collection of objects represeing the matching nodes (the result from the last search)
7621
+ * @plugin search
7622
+ */
7623
+ this.trigger('clear_search', { 'nodes' : this._data.search.dom, str : this._data.search.str, res : this._data.search.res });
7624
+ if(this._data.search.res.length) {
7625
+ this._data.search.dom = $(this.element[0].querySelectorAll('#' + $.map(this._data.search.res, function (v) {
7626
+ return "0123456789".indexOf(v[0]) !== -1 ? '\\3' + v[0] + ' ' + v.substr(1).replace($.jstree.idregex,'\\$&') : v.replace($.jstree.idregex,'\\$&');
7627
+ }).join(', #')));
7628
+ this._data.search.dom.children(".jstree-anchor").removeClass("jstree-search");
7629
+ }
7630
+ this._data.search.str = "";
7631
+ this._data.search.res = [];
7632
+ this._data.search.opn = [];
7633
+ this._data.search.dom = $();
7634
+ };
7635
+
7636
+ this.redraw_node = function(obj, deep, callback, force_render) {
7637
+ obj = parent.redraw_node.apply(this, arguments);
7638
+ if(obj) {
7639
+ if($.inArray(obj.id, this._data.search.res) !== -1) {
7640
+ var i, j, tmp = null;
7641
+ for(i = 0, j = obj.childNodes.length; i < j; i++) {
7642
+ if(obj.childNodes[i] && obj.childNodes[i].className && obj.childNodes[i].className.indexOf("jstree-anchor") !== -1) {
7643
+ tmp = obj.childNodes[i];
7644
+ break;
7645
+ }
7646
+ }
7647
+ if(tmp) {
7648
+ tmp.className += ' jstree-search';
7649
+ }
7650
+ }
7651
+ }
7652
+ return obj;
7653
+ };
7654
+ };
7655
+
7656
+ // helpers
7657
+ (function ($) {
7658
+ // from http://kiro.me/projects/fuse.html
7659
+ $.vakata.search = function(pattern, txt, options) {
7660
+ options = options || {};
7661
+ options = $.extend({}, $.vakata.search.defaults, options);
7662
+ if(options.fuzzy !== false) {
7663
+ options.fuzzy = true;
7664
+ }
7665
+ pattern = options.caseSensitive ? pattern : pattern.toLowerCase();
7666
+ var MATCH_LOCATION = options.location,
7667
+ MATCH_DISTANCE = options.distance,
7668
+ MATCH_THRESHOLD = options.threshold,
7669
+ patternLen = pattern.length,
7670
+ matchmask, pattern_alphabet, match_bitapScore, search;
7671
+ if(patternLen > 32) {
7672
+ options.fuzzy = false;
7673
+ }
7674
+ if(options.fuzzy) {
7675
+ matchmask = 1 << (patternLen - 1);
7676
+ pattern_alphabet = (function () {
7677
+ var mask = {},
7678
+ i = 0;
7679
+ for (i = 0; i < patternLen; i++) {
7680
+ mask[pattern.charAt(i)] = 0;
7681
+ }
7682
+ for (i = 0; i < patternLen; i++) {
7683
+ mask[pattern.charAt(i)] |= 1 << (patternLen - i - 1);
7684
+ }
7685
+ return mask;
7686
+ }());
7687
+ match_bitapScore = function (e, x) {
7688
+ var accuracy = e / patternLen,
7689
+ proximity = Math.abs(MATCH_LOCATION - x);
7690
+ if(!MATCH_DISTANCE) {
7691
+ return proximity ? 1.0 : accuracy;
7692
+ }
7693
+ return accuracy + (proximity / MATCH_DISTANCE);
7694
+ };
7695
+ }
7696
+ search = function (text) {
7697
+ text = options.caseSensitive ? text : text.toLowerCase();
7698
+ if(pattern === text || text.indexOf(pattern) !== -1) {
7699
+ return {
7700
+ isMatch: true,
7701
+ score: 0
7702
+ };
7703
+ }
7704
+ if(!options.fuzzy) {
7705
+ return {
7706
+ isMatch: false,
7707
+ score: 1
7708
+ };
7709
+ }
7710
+ var i, j,
7711
+ textLen = text.length,
7712
+ scoreThreshold = MATCH_THRESHOLD,
7713
+ bestLoc = text.indexOf(pattern, MATCH_LOCATION),
7714
+ binMin, binMid,
7715
+ binMax = patternLen + textLen,
7716
+ lastRd, start, finish, rd, charMatch,
7717
+ score = 1,
7718
+ locations = [];
7719
+ if (bestLoc !== -1) {
7720
+ scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
7721
+ bestLoc = text.lastIndexOf(pattern, MATCH_LOCATION + patternLen);
7722
+ if (bestLoc !== -1) {
7723
+ scoreThreshold = Math.min(match_bitapScore(0, bestLoc), scoreThreshold);
7724
+ }
7725
+ }
7726
+ bestLoc = -1;
7727
+ for (i = 0; i < patternLen; i++) {
7728
+ binMin = 0;
7729
+ binMid = binMax;
7730
+ while (binMin < binMid) {
7731
+ if (match_bitapScore(i, MATCH_LOCATION + binMid) <= scoreThreshold) {
7732
+ binMin = binMid;
7733
+ } else {
7734
+ binMax = binMid;
7735
+ }
7736
+ binMid = Math.floor((binMax - binMin) / 2 + binMin);
7737
+ }
7738
+ binMax = binMid;
7739
+ start = Math.max(1, MATCH_LOCATION - binMid + 1);
7740
+ finish = Math.min(MATCH_LOCATION + binMid, textLen) + patternLen;
7741
+ rd = new Array(finish + 2);
7742
+ rd[finish + 1] = (1 << i) - 1;
7743
+ for (j = finish; j >= start; j--) {
7744
+ charMatch = pattern_alphabet[text.charAt(j - 1)];
7745
+ if (i === 0) {
7746
+ rd[j] = ((rd[j + 1] << 1) | 1) & charMatch;
7747
+ } else {
7748
+ rd[j] = ((rd[j + 1] << 1) | 1) & charMatch | (((lastRd[j + 1] | lastRd[j]) << 1) | 1) | lastRd[j + 1];
7749
+ }
7750
+ if (rd[j] & matchmask) {
7751
+ score = match_bitapScore(i, j - 1);
7752
+ if (score <= scoreThreshold) {
7753
+ scoreThreshold = score;
7754
+ bestLoc = j - 1;
7755
+ locations.push(bestLoc);
7756
+ if (bestLoc > MATCH_LOCATION) {
7757
+ start = Math.max(1, 2 * MATCH_LOCATION - bestLoc);
7758
+ } else {
7759
+ break;
7760
+ }
7761
+ }
7762
+ }
7763
+ }
7764
+ if (match_bitapScore(i + 1, MATCH_LOCATION) > scoreThreshold) {
7765
+ break;
7766
+ }
7767
+ lastRd = rd;
7768
+ }
7769
+ return {
7770
+ isMatch: bestLoc >= 0,
7771
+ score: score
7772
+ };
7773
+ };
7774
+ return txt === true ? { 'search' : search } : search(txt);
7775
+ };
7776
+ $.vakata.search.defaults = {
7777
+ location : 0,
7778
+ distance : 100,
7779
+ threshold : 0.6,
7780
+ fuzzy : false,
7781
+ caseSensitive : false
7782
+ };
7783
+ }($));
7784
+
7785
+ // include the search plugin by default
7786
+ // $.jstree.defaults.plugins.push("search");
7787
+
7788
+
7789
+ /**
7790
+ * ### Sort plugin
7791
+ *
7792
+ * Automatically sorts all siblings in the tree according to a sorting function.
7793
+ */
7794
+
7795
+ /**
7796
+ * the settings function used to sort the nodes.
7797
+ * It is executed in the tree's context, accepts two nodes as arguments and should return `1` or `-1`.
7798
+ * @name $.jstree.defaults.sort
7799
+ * @plugin sort
7800
+ */
7801
+ $.jstree.defaults.sort = function (a, b) {
7802
+ //return this.get_type(a) === this.get_type(b) ? (this.get_text(a) > this.get_text(b) ? 1 : -1) : this.get_type(a) >= this.get_type(b);
7803
+ return this.get_text(a) > this.get_text(b) ? 1 : -1;
7804
+ };
7805
+ $.jstree.plugins.sort = function (options, parent) {
7806
+ this.bind = function () {
7807
+ parent.bind.call(this);
7808
+ this.element
7809
+ .on("model.jstree", $.proxy(function (e, data) {
7810
+ this.sort(data.parent, true);
7811
+ }, this))
7812
+ .on("rename_node.jstree create_node.jstree", $.proxy(function (e, data) {
7813
+ this.sort(data.parent || data.node.parent, false);
7814
+ this.redraw_node(data.parent || data.node.parent, true);
7815
+ }, this))
7816
+ .on("move_node.jstree copy_node.jstree", $.proxy(function (e, data) {
7817
+ this.sort(data.parent, false);
7818
+ this.redraw_node(data.parent, true);
7819
+ }, this));
7820
+ };
7821
+ /**
7822
+ * used to sort a node's children
7823
+ * @private
7824
+ * @name sort(obj [, deep])
7825
+ * @param {mixed} obj the node
7826
+ * @param {Boolean} deep if set to `true` nodes are sorted recursively.
7827
+ * @plugin sort
7828
+ * @trigger search.jstree
7829
+ */
7830
+ this.sort = function (obj, deep) {
7831
+ var i, j;
7832
+ obj = this.get_node(obj);
7833
+ if(obj && obj.children && obj.children.length) {
7834
+ obj.children.sort($.proxy(this.settings.sort, this));
7835
+ if(deep) {
7836
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
7837
+ this.sort(obj.children_d[i], false);
7838
+ }
7839
+ }
7840
+ }
7841
+ };
7842
+ };
7843
+
7844
+ // include the sort plugin by default
7845
+ // $.jstree.defaults.plugins.push("sort");
7846
+
7847
+ /**
7848
+ * ### State plugin
7849
+ *
7850
+ * Saves the state of the tree (selected nodes, opened nodes) on the user's computer using available options (localStorage, cookies, etc)
7851
+ */
7852
+
7853
+ var to = false;
7854
+ /**
7855
+ * stores all defaults for the state plugin
7856
+ * @name $.jstree.defaults.state
7857
+ * @plugin state
7858
+ */
7859
+ $.jstree.defaults.state = {
7860
+ /**
7861
+ * A string for the key to use when saving the current tree (change if using multiple trees in your project). Defaults to `jstree`.
7862
+ * @name $.jstree.defaults.state.key
7863
+ * @plugin state
7864
+ */
7865
+ key : 'jstree',
7866
+ /**
7867
+ * A space separated list of events that trigger a state save. Defaults to `changed.jstree open_node.jstree close_node.jstree`.
7868
+ * @name $.jstree.defaults.state.events
7869
+ * @plugin state
7870
+ */
7871
+ events : 'changed.jstree open_node.jstree close_node.jstree check_node.jstree uncheck_node.jstree',
7872
+ /**
7873
+ * Time in milliseconds after which the state will expire. Defaults to 'false' meaning - no expire.
7874
+ * @name $.jstree.defaults.state.ttl
7875
+ * @plugin state
7876
+ */
7877
+ ttl : false,
7878
+ /**
7879
+ * A function that will be executed prior to restoring state with one argument - the state object. Can be used to clear unwanted parts of the state.
7880
+ * @name $.jstree.defaults.state.filter
7881
+ * @plugin state
7882
+ */
7883
+ filter : false,
7884
+ /**
7885
+ * Should loaded nodes be restored (setting this to true means that it is possible that the whole tree will be loaded for some users - use with caution). Defaults to `false`
7886
+ * @name $.jstree.defaults.state.preserve_loaded
7887
+ * @plugin state
7888
+ */
7889
+ preserve_loaded : false
7890
+ };
7891
+ $.jstree.plugins.state = function (options, parent) {
7892
+ this.bind = function () {
7893
+ parent.bind.call(this);
7894
+ var bind = $.proxy(function () {
7895
+ this.element.on(this.settings.state.events, $.proxy(function () {
7896
+ if(to) { clearTimeout(to); }
7897
+ to = setTimeout($.proxy(function () { this.save_state(); }, this), 100);
7898
+ }, this));
7899
+ /**
7900
+ * triggered when the state plugin is finished restoring the state (and immediately after ready if there is no state to restore).
7901
+ * @event
7902
+ * @name state_ready.jstree
7903
+ * @plugin state
7904
+ */
7905
+ this.trigger('state_ready');
7906
+ }, this);
7907
+ this.element
7908
+ .on("ready.jstree", $.proxy(function (e, data) {
7909
+ this.element.one("restore_state.jstree", bind);
7910
+ if(!this.restore_state()) { bind(); }
7911
+ }, this));
7912
+ };
7913
+ /**
7914
+ * save the state
7915
+ * @name save_state()
7916
+ * @plugin state
7917
+ */
7918
+ this.save_state = function () {
7919
+ var tm = this.get_state();
7920
+ if (!this.settings.state.preserve_loaded) {
7921
+ delete tm.core.loaded;
7922
+ }
7923
+ var st = { 'state' : tm, 'ttl' : this.settings.state.ttl, 'sec' : +(new Date()) };
7924
+ $.vakata.storage.set(this.settings.state.key, JSON.stringify(st));
7925
+ };
7926
+ /**
7927
+ * restore the state from the user's computer
7928
+ * @name restore_state()
7929
+ * @plugin state
7930
+ */
7931
+ this.restore_state = function () {
7932
+ var k = $.vakata.storage.get(this.settings.state.key);
7933
+ if(!!k) { try { k = JSON.parse(k); } catch(ex) { return false; } }
7934
+ if(!!k && k.ttl && k.sec && +(new Date()) - k.sec > k.ttl) { return false; }
7935
+ if(!!k && k.state) { k = k.state; }
7936
+ if(!!k && $.isFunction(this.settings.state.filter)) { k = this.settings.state.filter.call(this, k); }
7937
+ if(!!k) {
7938
+ if (!this.settings.state.preserve_loaded) {
7939
+ delete k.core.loaded;
7940
+ }
7941
+ this.element.one("set_state.jstree", function (e, data) { data.instance.trigger('restore_state', { 'state' : $.extend(true, {}, k) }); });
7942
+ this.set_state(k);
7943
+ return true;
7944
+ }
7945
+ return false;
7946
+ };
7947
+ /**
7948
+ * clear the state on the user's computer
7949
+ * @name clear_state()
7950
+ * @plugin state
7951
+ */
7952
+ this.clear_state = function () {
7953
+ return $.vakata.storage.del(this.settings.state.key);
7954
+ };
7955
+ };
7956
+
7957
+ (function ($, undefined) {
7958
+ $.vakata.storage = {
7959
+ // simply specifying the functions in FF throws an error
7960
+ set : function (key, val) { return window.localStorage.setItem(key, val); },
7961
+ get : function (key) { return window.localStorage.getItem(key); },
7962
+ del : function (key) { return window.localStorage.removeItem(key); }
7963
+ };
7964
+ }($));
7965
+
7966
+ // include the state plugin by default
7967
+ // $.jstree.defaults.plugins.push("state");
7968
+
7969
+ /**
7970
+ * ### Types plugin
7971
+ *
7972
+ * Makes it possible to add predefined types for groups of nodes, which make it possible to easily control nesting rules and icon for each group.
7973
+ */
7974
+
7975
+ /**
7976
+ * An object storing all types as key value pairs, where the key is the type name and the value is an object that could contain following keys (all optional).
7977
+ *
7978
+ * * `max_children` the maximum number of immediate children this node type can have. Do not specify or set to `-1` for unlimited.
7979
+ * * `max_depth` the maximum number of nesting this node type can have. A value of `1` would mean that the node can have children, but no grandchildren. Do not specify or set to `-1` for unlimited.
7980
+ * * `valid_children` an array of node type strings, that nodes of this type can have as children. Do not specify or set to `-1` for no limits.
7981
+ * * `icon` a string - can be a path to an icon or a className, if using an image that is in the current directory use a `./` prefix, otherwise it will be detected as a class. Omit to use the default icon from your theme.
7982
+ * * `li_attr` an object of values which will be used to add HTML attributes on the resulting LI DOM node (merged with the node's own data)
7983
+ * * `a_attr` an object of values which will be used to add HTML attributes on the resulting A DOM node (merged with the node's own data)
7984
+ *
7985
+ * There are two predefined types:
7986
+ *
7987
+ * * `#` represents the root of the tree, for example `max_children` would control the maximum number of root nodes.
7988
+ * * `default` represents the default node - any settings here will be applied to all nodes that do not have a type specified.
7989
+ *
7990
+ * @name $.jstree.defaults.types
7991
+ * @plugin types
7992
+ */
7993
+ $.jstree.defaults.types = {
7994
+ 'default' : {}
7995
+ };
7996
+ $.jstree.defaults.types[$.jstree.root] = {};
7997
+
7998
+ $.jstree.plugins.types = function (options, parent) {
7999
+ this.init = function (el, options) {
8000
+ var i, j;
8001
+ if(options && options.types && options.types['default']) {
8002
+ for(i in options.types) {
8003
+ if(i !== "default" && i !== $.jstree.root && options.types.hasOwnProperty(i)) {
8004
+ for(j in options.types['default']) {
8005
+ if(options.types['default'].hasOwnProperty(j) && options.types[i][j] === undefined) {
8006
+ options.types[i][j] = options.types['default'][j];
8007
+ }
8008
+ }
8009
+ }
8010
+ }
8011
+ }
8012
+ parent.init.call(this, el, options);
8013
+ this._model.data[$.jstree.root].type = $.jstree.root;
8014
+ };
8015
+ this.refresh = function (skip_loading, forget_state) {
8016
+ parent.refresh.call(this, skip_loading, forget_state);
8017
+ this._model.data[$.jstree.root].type = $.jstree.root;
8018
+ };
8019
+ this.bind = function () {
8020
+ this.element
8021
+ .on('model.jstree', $.proxy(function (e, data) {
8022
+ var m = this._model.data,
8023
+ dpc = data.nodes,
8024
+ t = this.settings.types,
8025
+ i, j, c = 'default', k;
8026
+ for(i = 0, j = dpc.length; i < j; i++) {
8027
+ c = 'default';
8028
+ if(m[dpc[i]].original && m[dpc[i]].original.type && t[m[dpc[i]].original.type]) {
8029
+ c = m[dpc[i]].original.type;
8030
+ }
8031
+ if(m[dpc[i]].data && m[dpc[i]].data.jstree && m[dpc[i]].data.jstree.type && t[m[dpc[i]].data.jstree.type]) {
8032
+ c = m[dpc[i]].data.jstree.type;
8033
+ }
8034
+ m[dpc[i]].type = c;
8035
+ if(m[dpc[i]].icon === true && t[c].icon !== undefined) {
8036
+ m[dpc[i]].icon = t[c].icon;
8037
+ }
8038
+ if(t[c].li_attr !== undefined && typeof t[c].li_attr === 'object') {
8039
+ for (k in t[c].li_attr) {
8040
+ if (t[c].li_attr.hasOwnProperty(k)) {
8041
+ if (k === 'id') {
8042
+ continue;
8043
+ }
8044
+ else if (m[dpc[i]].li_attr[k] === undefined) {
8045
+ m[dpc[i]].li_attr[k] = t[c].li_attr[k];
8046
+ }
8047
+ else if (k === 'class') {
8048
+ m[dpc[i]].li_attr['class'] = t[c].li_attr['class'] + ' ' + m[dpc[i]].li_attr['class'];
8049
+ }
8050
+ }
8051
+ }
8052
+ }
8053
+ if(t[c].a_attr !== undefined && typeof t[c].a_attr === 'object') {
8054
+ for (k in t[c].a_attr) {
8055
+ if (t[c].a_attr.hasOwnProperty(k)) {
8056
+ if (k === 'id') {
8057
+ continue;
8058
+ }
8059
+ else if (m[dpc[i]].a_attr[k] === undefined) {
8060
+ m[dpc[i]].a_attr[k] = t[c].a_attr[k];
8061
+ }
8062
+ else if (k === 'href' && m[dpc[i]].a_attr[k] === '#') {
8063
+ m[dpc[i]].a_attr['href'] = t[c].a_attr['href'];
8064
+ }
8065
+ else if (k === 'class') {
8066
+ m[dpc[i]].a_attr['class'] = t[c].a_attr['class'] + ' ' + m[dpc[i]].a_attr['class'];
8067
+ }
8068
+ }
8069
+ }
8070
+ }
8071
+ }
8072
+ m[$.jstree.root].type = $.jstree.root;
8073
+ }, this));
8074
+ parent.bind.call(this);
8075
+ };
8076
+ this.get_json = function (obj, options, flat) {
8077
+ var i, j,
8078
+ m = this._model.data,
8079
+ opt = options ? $.extend(true, {}, options, {no_id:false}) : {},
8080
+ tmp = parent.get_json.call(this, obj, opt, flat);
8081
+ if(tmp === false) { return false; }
8082
+ if($.isArray(tmp)) {
8083
+ for(i = 0, j = tmp.length; i < j; i++) {
8084
+ tmp[i].type = tmp[i].id && m[tmp[i].id] && m[tmp[i].id].type ? m[tmp[i].id].type : "default";
8085
+ if(options && options.no_id) {
8086
+ delete tmp[i].id;
8087
+ if(tmp[i].li_attr && tmp[i].li_attr.id) {
8088
+ delete tmp[i].li_attr.id;
8089
+ }
8090
+ if(tmp[i].a_attr && tmp[i].a_attr.id) {
8091
+ delete tmp[i].a_attr.id;
8092
+ }
8093
+ }
8094
+ }
8095
+ }
8096
+ else {
8097
+ tmp.type = tmp.id && m[tmp.id] && m[tmp.id].type ? m[tmp.id].type : "default";
8098
+ if(options && options.no_id) {
8099
+ tmp = this._delete_ids(tmp);
8100
+ }
8101
+ }
8102
+ return tmp;
8103
+ };
8104
+ this._delete_ids = function (tmp) {
8105
+ if($.isArray(tmp)) {
8106
+ for(var i = 0, j = tmp.length; i < j; i++) {
8107
+ tmp[i] = this._delete_ids(tmp[i]);
8108
+ }
8109
+ return tmp;
8110
+ }
8111
+ delete tmp.id;
8112
+ if(tmp.li_attr && tmp.li_attr.id) {
8113
+ delete tmp.li_attr.id;
8114
+ }
8115
+ if(tmp.a_attr && tmp.a_attr.id) {
8116
+ delete tmp.a_attr.id;
8117
+ }
8118
+ if(tmp.children && $.isArray(tmp.children)) {
8119
+ tmp.children = this._delete_ids(tmp.children);
8120
+ }
8121
+ return tmp;
8122
+ };
8123
+ this.check = function (chk, obj, par, pos, more) {
8124
+ if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
8125
+ obj = obj && obj.id ? obj : this.get_node(obj);
8126
+ par = par && par.id ? par : this.get_node(par);
8127
+ var m = obj && obj.id ? (more && more.origin ? more.origin : $.jstree.reference(obj.id)) : null, tmp, d, i, j;
8128
+ m = m && m._model && m._model.data ? m._model.data : null;
8129
+ switch(chk) {
8130
+ case "create_node":
8131
+ case "move_node":
8132
+ case "copy_node":
8133
+ if(chk !== 'move_node' || $.inArray(obj.id, par.children) === -1) {
8134
+ tmp = this.get_rules(par);
8135
+ if(tmp.max_children !== undefined && tmp.max_children !== -1 && tmp.max_children === par.children.length) {
8136
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_01', 'reason' : 'max_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8137
+ return false;
8138
+ }
8139
+ if(tmp.valid_children !== undefined && tmp.valid_children !== -1 && $.inArray((obj.type || 'default'), tmp.valid_children) === -1) {
8140
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_02', 'reason' : 'valid_children prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8141
+ return false;
8142
+ }
8143
+ if(m && obj.children_d && obj.parents) {
8144
+ d = 0;
8145
+ for(i = 0, j = obj.children_d.length; i < j; i++) {
8146
+ d = Math.max(d, m[obj.children_d[i]].parents.length);
8147
+ }
8148
+ d = d - obj.parents.length + 1;
8149
+ }
8150
+ if(d <= 0 || d === undefined) { d = 1; }
8151
+ do {
8152
+ if(tmp.max_depth !== undefined && tmp.max_depth !== -1 && tmp.max_depth < d) {
8153
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'types', 'id' : 'types_03', 'reason' : 'max_depth prevents function: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8154
+ return false;
8155
+ }
8156
+ par = this.get_node(par.parent);
8157
+ tmp = this.get_rules(par);
8158
+ d++;
8159
+ } while(par);
8160
+ }
8161
+ break;
8162
+ }
8163
+ return true;
8164
+ };
8165
+ /**
8166
+ * used to retrieve the type settings object for a node
8167
+ * @name get_rules(obj)
8168
+ * @param {mixed} obj the node to find the rules for
8169
+ * @return {Object}
8170
+ * @plugin types
8171
+ */
8172
+ this.get_rules = function (obj) {
8173
+ obj = this.get_node(obj);
8174
+ if(!obj) { return false; }
8175
+ var tmp = this.get_type(obj, true);
8176
+ if(tmp.max_depth === undefined) { tmp.max_depth = -1; }
8177
+ if(tmp.max_children === undefined) { tmp.max_children = -1; }
8178
+ if(tmp.valid_children === undefined) { tmp.valid_children = -1; }
8179
+ return tmp;
8180
+ };
8181
+ /**
8182
+ * used to retrieve the type string or settings object for a node
8183
+ * @name get_type(obj [, rules])
8184
+ * @param {mixed} obj the node to find the rules for
8185
+ * @param {Boolean} rules if set to `true` instead of a string the settings object will be returned
8186
+ * @return {String|Object}
8187
+ * @plugin types
8188
+ */
8189
+ this.get_type = function (obj, rules) {
8190
+ obj = this.get_node(obj);
8191
+ return (!obj) ? false : ( rules ? $.extend({ 'type' : obj.type }, this.settings.types[obj.type]) : obj.type);
8192
+ };
8193
+ /**
8194
+ * used to change a node's type
8195
+ * @name set_type(obj, type)
8196
+ * @param {mixed} obj the node to change
8197
+ * @param {String} type the new type
8198
+ * @plugin types
8199
+ */
8200
+ this.set_type = function (obj, type) {
8201
+ var m = this._model.data, t, t1, t2, old_type, old_icon, k, d, a;
8202
+ if($.isArray(obj)) {
8203
+ obj = obj.slice();
8204
+ for(t1 = 0, t2 = obj.length; t1 < t2; t1++) {
8205
+ this.set_type(obj[t1], type);
8206
+ }
8207
+ return true;
8208
+ }
8209
+ t = this.settings.types;
8210
+ obj = this.get_node(obj);
8211
+ if(!t[type] || !obj) { return false; }
8212
+ d = this.get_node(obj, true);
8213
+ if (d && d.length) {
8214
+ a = d.children('.jstree-anchor');
8215
+ }
8216
+ old_type = obj.type;
8217
+ old_icon = this.get_icon(obj);
8218
+ obj.type = type;
8219
+ if(old_icon === true || !t[old_type] || (t[old_type].icon !== undefined && old_icon === t[old_type].icon)) {
8220
+ this.set_icon(obj, t[type].icon !== undefined ? t[type].icon : true);
8221
+ }
8222
+
8223
+ // remove old type props
8224
+ if(t[old_type] && t[old_type].li_attr !== undefined && typeof t[old_type].li_attr === 'object') {
8225
+ for (k in t[old_type].li_attr) {
8226
+ if (t[old_type].li_attr.hasOwnProperty(k)) {
8227
+ if (k === 'id') {
8228
+ continue;
8229
+ }
8230
+ else if (k === 'class') {
8231
+ m[obj.id].li_attr['class'] = (m[obj.id].li_attr['class'] || '').replace(t[old_type].li_attr[k], '');
8232
+ if (d) { d.removeClass(t[old_type].li_attr[k]); }
8233
+ }
8234
+ else if (m[obj.id].li_attr[k] === t[old_type].li_attr[k]) {
8235
+ m[obj.id].li_attr[k] = null;
8236
+ if (d) { d.removeAttr(k); }
8237
+ }
8238
+ }
8239
+ }
8240
+ }
8241
+ if(t[old_type] && t[old_type].a_attr !== undefined && typeof t[old_type].a_attr === 'object') {
8242
+ for (k in t[old_type].a_attr) {
8243
+ if (t[old_type].a_attr.hasOwnProperty(k)) {
8244
+ if (k === 'id') {
8245
+ continue;
8246
+ }
8247
+ else if (k === 'class') {
8248
+ m[obj.id].a_attr['class'] = (m[obj.id].a_attr['class'] || '').replace(t[old_type].a_attr[k], '');
8249
+ if (a) { a.removeClass(t[old_type].a_attr[k]); }
8250
+ }
8251
+ else if (m[obj.id].a_attr[k] === t[old_type].a_attr[k]) {
8252
+ if (k === 'href') {
8253
+ m[obj.id].a_attr[k] = '#';
8254
+ if (a) { a.attr('href', '#'); }
8255
+ }
8256
+ else {
8257
+ delete m[obj.id].a_attr[k];
8258
+ if (a) { a.removeAttr(k); }
8259
+ }
8260
+ }
8261
+ }
8262
+ }
8263
+ }
8264
+
8265
+ // add new props
8266
+ if(t[type].li_attr !== undefined && typeof t[type].li_attr === 'object') {
8267
+ for (k in t[type].li_attr) {
8268
+ if (t[type].li_attr.hasOwnProperty(k)) {
8269
+ if (k === 'id') {
8270
+ continue;
8271
+ }
8272
+ else if (m[obj.id].li_attr[k] === undefined) {
8273
+ m[obj.id].li_attr[k] = t[type].li_attr[k];
8274
+ if (d) {
8275
+ if (k === 'class') {
8276
+ d.addClass(t[type].li_attr[k]);
8277
+ }
8278
+ else {
8279
+ d.attr(k, t[type].li_attr[k]);
8280
+ }
8281
+ }
8282
+ }
8283
+ else if (k === 'class') {
8284
+ m[obj.id].li_attr['class'] = t[type].li_attr[k] + ' ' + m[obj.id].li_attr['class'];
8285
+ if (d) { d.addClass(t[type].li_attr[k]); }
8286
+ }
8287
+ }
8288
+ }
8289
+ }
8290
+ if(t[type].a_attr !== undefined && typeof t[type].a_attr === 'object') {
8291
+ for (k in t[type].a_attr) {
8292
+ if (t[type].a_attr.hasOwnProperty(k)) {
8293
+ if (k === 'id') {
8294
+ continue;
8295
+ }
8296
+ else if (m[obj.id].a_attr[k] === undefined) {
8297
+ m[obj.id].a_attr[k] = t[type].a_attr[k];
8298
+ if (a) {
8299
+ if (k === 'class') {
8300
+ a.addClass(t[type].a_attr[k]);
8301
+ }
8302
+ else {
8303
+ a.attr(k, t[type].a_attr[k]);
8304
+ }
8305
+ }
8306
+ }
8307
+ else if (k === 'href' && m[obj.id].a_attr[k] === '#') {
8308
+ m[obj.id].a_attr['href'] = t[type].a_attr['href'];
8309
+ if (a) { a.attr('href', t[type].a_attr['href']); }
8310
+ }
8311
+ else if (k === 'class') {
8312
+ m[obj.id].a_attr['class'] = t[type].a_attr['class'] + ' ' + m[obj.id].a_attr['class'];
8313
+ if (a) { a.addClass(t[type].a_attr[k]); }
8314
+ }
8315
+ }
8316
+ }
8317
+ }
8318
+
8319
+ return true;
8320
+ };
8321
+ };
8322
+ // include the types plugin by default
8323
+ // $.jstree.defaults.plugins.push("types");
8324
+
8325
+
8326
+ /**
8327
+ * ### Unique plugin
8328
+ *
8329
+ * Enforces that no nodes with the same name can coexist as siblings.
8330
+ */
8331
+
8332
+ /**
8333
+ * stores all defaults for the unique plugin
8334
+ * @name $.jstree.defaults.unique
8335
+ * @plugin unique
8336
+ */
8337
+ $.jstree.defaults.unique = {
8338
+ /**
8339
+ * Indicates if the comparison should be case sensitive. Default is `false`.
8340
+ * @name $.jstree.defaults.unique.case_sensitive
8341
+ * @plugin unique
8342
+ */
8343
+ case_sensitive : false,
8344
+ /**
8345
+ * Indicates if white space should be trimmed before the comparison. Default is `false`.
8346
+ * @name $.jstree.defaults.unique.trim_whitespace
8347
+ * @plugin unique
8348
+ */
8349
+ trim_whitespace : false,
8350
+ /**
8351
+ * A callback executed in the instance's scope when a new node is created and the name is already taken, the two arguments are the conflicting name and the counter. The default will produce results like `New node (2)`.
8352
+ * @name $.jstree.defaults.unique.duplicate
8353
+ * @plugin unique
8354
+ */
8355
+ duplicate : function (name, counter) {
8356
+ return name + ' (' + counter + ')';
8357
+ }
8358
+ };
8359
+
8360
+ $.jstree.plugins.unique = function (options, parent) {
8361
+ this.check = function (chk, obj, par, pos, more) {
8362
+ if(parent.check.call(this, chk, obj, par, pos, more) === false) { return false; }
8363
+ obj = obj && obj.id ? obj : this.get_node(obj);
8364
+ par = par && par.id ? par : this.get_node(par);
8365
+ if(!par || !par.children) { return true; }
8366
+ var n = chk === "rename_node" ? pos : obj.text,
8367
+ c = [],
8368
+ s = this.settings.unique.case_sensitive,
8369
+ w = this.settings.unique.trim_whitespace,
8370
+ m = this._model.data, i, j, t;
8371
+ for(i = 0, j = par.children.length; i < j; i++) {
8372
+ t = m[par.children[i]].text;
8373
+ if (!s) {
8374
+ t = t.toLowerCase();
8375
+ }
8376
+ if (w) {
8377
+ t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8378
+ }
8379
+ c.push(t);
8380
+ }
8381
+ if(!s) { n = n.toLowerCase(); }
8382
+ if (w) { n = n.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, ''); }
8383
+ switch(chk) {
8384
+ case "delete_node":
8385
+ return true;
8386
+ case "rename_node":
8387
+ t = obj.text || '';
8388
+ if (!s) {
8389
+ t = t.toLowerCase();
8390
+ }
8391
+ if (w) {
8392
+ t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8393
+ }
8394
+ i = ($.inArray(n, c) === -1 || (obj.text && t === n));
8395
+ if(!i) {
8396
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_01', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8397
+ }
8398
+ return i;
8399
+ case "create_node":
8400
+ i = ($.inArray(n, c) === -1);
8401
+ if(!i) {
8402
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_04', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8403
+ }
8404
+ return i;
8405
+ case "copy_node":
8406
+ i = ($.inArray(n, c) === -1);
8407
+ if(!i) {
8408
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_02', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8409
+ }
8410
+ return i;
8411
+ case "move_node":
8412
+ i = ( (obj.parent === par.id && (!more || !more.is_multi)) || $.inArray(n, c) === -1);
8413
+ if(!i) {
8414
+ this._data.core.last_error = { 'error' : 'check', 'plugin' : 'unique', 'id' : 'unique_03', 'reason' : 'Child with name ' + n + ' already exists. Preventing: ' + chk, 'data' : JSON.stringify({ 'chk' : chk, 'pos' : pos, 'obj' : obj && obj.id ? obj.id : false, 'par' : par && par.id ? par.id : false }) };
8415
+ }
8416
+ return i;
8417
+ }
8418
+ return true;
8419
+ };
8420
+ this.create_node = function (par, node, pos, callback, is_loaded) {
8421
+ if(!node || node.text === undefined) {
8422
+ if(par === null) {
8423
+ par = $.jstree.root;
8424
+ }
8425
+ par = this.get_node(par);
8426
+ if(!par) {
8427
+ return parent.create_node.call(this, par, node, pos, callback, is_loaded);
8428
+ }
8429
+ pos = pos === undefined ? "last" : pos;
8430
+ if(!pos.toString().match(/^(before|after)$/) && !is_loaded && !this.is_loaded(par)) {
8431
+ return parent.create_node.call(this, par, node, pos, callback, is_loaded);
8432
+ }
8433
+ if(!node) { node = {}; }
8434
+ var tmp, n, dpc, i, j, m = this._model.data, s = this.settings.unique.case_sensitive, w = this.settings.unique.trim_whitespace, cb = this.settings.unique.duplicate, t;
8435
+ n = tmp = this.get_string('New node');
8436
+ dpc = [];
8437
+ for(i = 0, j = par.children.length; i < j; i++) {
8438
+ t = m[par.children[i]].text;
8439
+ if (!s) {
8440
+ t = t.toLowerCase();
8441
+ }
8442
+ if (w) {
8443
+ t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8444
+ }
8445
+ dpc.push(t);
8446
+ }
8447
+ i = 1;
8448
+ t = n;
8449
+ if (!s) {
8450
+ t = t.toLowerCase();
8451
+ }
8452
+ if (w) {
8453
+ t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8454
+ }
8455
+ while($.inArray(t, dpc) !== -1) {
8456
+ n = cb.call(this, tmp, (++i)).toString();
8457
+ t = n;
8458
+ if (!s) {
8459
+ t = t.toLowerCase();
8460
+ }
8461
+ if (w) {
8462
+ t = t.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
8463
+ }
8464
+ }
8465
+ node.text = n;
8466
+ }
8467
+ return parent.create_node.call(this, par, node, pos, callback, is_loaded);
8468
+ };
8469
+ };
8470
+
8471
+ // include the unique plugin by default
8472
+ // $.jstree.defaults.plugins.push("unique");
8473
+
8474
+
8475
+ /**
8476
+ * ### Wholerow plugin
8477
+ *
8478
+ * Makes each node appear block level. Making selection easier. May cause slow down for large trees in old browsers.
8479
+ */
8480
+
8481
+ var div = document.createElement('DIV');
8482
+ div.setAttribute('unselectable','on');
8483
+ div.setAttribute('role','presentation');
8484
+ div.className = 'jstree-wholerow';
8485
+ div.innerHTML = '&#160;';
8486
+ $.jstree.plugins.wholerow = function (options, parent) {
8487
+ this.bind = function () {
8488
+ parent.bind.call(this);
8489
+
8490
+ this.element
8491
+ .on('ready.jstree set_state.jstree', $.proxy(function () {
8492
+ this.hide_dots();
8493
+ }, this))
8494
+ .on("init.jstree loading.jstree ready.jstree", $.proxy(function () {
8495
+ //div.style.height = this._data.core.li_height + 'px';
8496
+ this.get_container_ul().addClass('jstree-wholerow-ul');
8497
+ }, this))
8498
+ .on("deselect_all.jstree", $.proxy(function (e, data) {
8499
+ this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
8500
+ }, this))
8501
+ .on("changed.jstree", $.proxy(function (e, data) {
8502
+ this.element.find('.jstree-wholerow-clicked').removeClass('jstree-wholerow-clicked');
8503
+ var tmp = false, i, j;
8504
+ for(i = 0, j = data.selected.length; i < j; i++) {
8505
+ tmp = this.get_node(data.selected[i], true);
8506
+ if(tmp && tmp.length) {
8507
+ tmp.children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
8508
+ }
8509
+ }
8510
+ }, this))
8511
+ .on("open_node.jstree", $.proxy(function (e, data) {
8512
+ this.get_node(data.node, true).find('.jstree-clicked').parent().children('.jstree-wholerow').addClass('jstree-wholerow-clicked');
8513
+ }, this))
8514
+ .on("hover_node.jstree dehover_node.jstree", $.proxy(function (e, data) {
8515
+ if(e.type === "hover_node" && this.is_disabled(data.node)) { return; }
8516
+ this.get_node(data.node, true).children('.jstree-wholerow')[e.type === "hover_node"?"addClass":"removeClass"]('jstree-wholerow-hovered');
8517
+ }, this))
8518
+ .on("contextmenu.jstree", ".jstree-wholerow", $.proxy(function (e) {
8519
+ if (this._data.contextmenu) {
8520
+ e.preventDefault();
8521
+ var tmp = $.Event('contextmenu', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey, pageX : e.pageX, pageY : e.pageY });
8522
+ $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp);
8523
+ }
8524
+ }, this))
8525
+ /*!
8526
+ .on("mousedown.jstree touchstart.jstree", ".jstree-wholerow", function (e) {
8527
+ if(e.target === e.currentTarget) {
8528
+ var a = $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor");
8529
+ e.target = a[0];
8530
+ a.trigger(e);
8531
+ }
8532
+ })
8533
+ */
8534
+ .on("click.jstree", ".jstree-wholerow", function (e) {
8535
+ e.stopImmediatePropagation();
8536
+ var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8537
+ $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8538
+ })
8539
+ .on("dblclick.jstree", ".jstree-wholerow", function (e) {
8540
+ e.stopImmediatePropagation();
8541
+ var tmp = $.Event('dblclick', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8542
+ $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8543
+ })
8544
+ .on("click.jstree", ".jstree-leaf > .jstree-ocl", $.proxy(function (e) {
8545
+ e.stopImmediatePropagation();
8546
+ var tmp = $.Event('click', { metaKey : e.metaKey, ctrlKey : e.ctrlKey, altKey : e.altKey, shiftKey : e.shiftKey });
8547
+ $(e.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(tmp).focus();
8548
+ }, this))
8549
+ .on("mouseover.jstree", ".jstree-wholerow, .jstree-icon", $.proxy(function (e) {
8550
+ e.stopImmediatePropagation();
8551
+ if(!this.is_disabled(e.currentTarget)) {
8552
+ this.hover_node(e.currentTarget);
8553
+ }
8554
+ return false;
8555
+ }, this))
8556
+ .on("mouseleave.jstree", ".jstree-node", $.proxy(function (e) {
8557
+ this.dehover_node(e.currentTarget);
8558
+ }, this));
8559
+ };
8560
+ this.teardown = function () {
8561
+ if(this.settings.wholerow) {
8562
+ this.element.find(".jstree-wholerow").remove();
8563
+ }
8564
+ parent.teardown.call(this);
8565
+ };
8566
+ this.redraw_node = function(obj, deep, callback, force_render) {
8567
+ obj = parent.redraw_node.apply(this, arguments);
8568
+ if(obj) {
8569
+ var tmp = div.cloneNode(true);
8570
+ //tmp.style.height = this._data.core.li_height + 'px';
8571
+ if($.inArray(obj.id, this._data.core.selected) !== -1) { tmp.className += ' jstree-wholerow-clicked'; }
8572
+ if(this._data.core.focused && this._data.core.focused === obj.id) { tmp.className += ' jstree-wholerow-hovered'; }
8573
+ obj.insertBefore(tmp, obj.childNodes[0]);
8574
+ }
8575
+ return obj;
8576
+ };
8577
+ };
8578
+ // include the wholerow plugin by default
8579
+ // $.jstree.defaults.plugins.push("wholerow");
8580
+ if(window.customElements && Object && Object.create) {
8581
+ var proto = Object.create(HTMLElement.prototype);
8582
+ proto.createdCallback = function () {
8583
+ var c = { core : {}, plugins : [] }, i;
8584
+ for(i in $.jstree.plugins) {
8585
+ if($.jstree.plugins.hasOwnProperty(i) && this.attributes[i]) {
8586
+ c.plugins.push(i);
8587
+ if(this.getAttribute(i) && JSON.parse(this.getAttribute(i))) {
8588
+ c[i] = JSON.parse(this.getAttribute(i));
8589
+ }
8590
+ }
8591
+ }
8592
+ for(i in $.jstree.defaults.core) {
8593
+ if($.jstree.defaults.core.hasOwnProperty(i) && this.attributes[i]) {
8594
+ c.core[i] = JSON.parse(this.getAttribute(i)) || this.getAttribute(i);
8595
+ }
8596
+ }
8597
+ $(this).jstree(c);
8598
+ };
8599
+ // proto.attributeChangedCallback = function (name, previous, value) { };
8600
+ try {
8601
+ window.customElements.define("vakata-jstree", function() {}, { prototype: proto });
8602
+ } catch (ignore) { }
8603
+ }
8604
+
8605
  }));
assets/jstree/jstree.min.js CHANGED
@@ -1,6 +1,6 @@
1
- /*! jsTree - v3.3.5 - 2018-01-02 - (MIT) */
2
- !function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):"undefined"!=typeof module&&module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a,b){"use strict";if(!a.jstree){var c=0,d=!1,e=!1,f=!1,g=[],h=a("script:last").attr("src"),i=window.document;a.jstree={version:"3.3.5",defaults:{plugins:[]},plugins:{},path:h&&-1!==h.indexOf("/")?h.replace(/\/[^\/]+$/,""):"",idregex:/[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,root:"#"},a.jstree.create=function(b,d){var e=new a.jstree.core(++c),f=d;return d=a.extend(!0,{},a.jstree.defaults,d),f&&f.plugins&&(d.plugins=f.plugins),a.each(d.plugins,function(a,b){"core"!==a&&(e=e.plugin(b,d[b]))}),a(b).data("jstree",e),e.init(b,d),e},a.jstree.destroy=function(){a(".jstree:jstree").jstree("destroy"),a(i).off(".jstree")},a.jstree.core=function(a){this._id=a,this._cnt=0,this._wrk=null,this._data={core:{themes:{name:!1,dots:!1,icons:!1,ellipsis:!1},selected:[],last_error:{},working:!1,worker_queue:[],focused:null}}},a.jstree.reference=function(b){var c=null,d=null;if(!b||!b.id||b.tagName&&b.nodeType||(b=b.id),!d||!d.length)try{d=a(b)}catch(e){}if(!d||!d.length)try{d=a("#"+b.replace(a.jstree.idregex,"\\$&"))}catch(e){}return d&&d.length&&(d=d.closest(".jstree")).length&&(d=d.data("jstree"))?c=d:a(".jstree").each(function(){var d=a(this).data("jstree");return d&&d._model.data[b]?(c=d,!1):void 0}),c},a.fn.jstree=function(c){var d="string"==typeof c,e=Array.prototype.slice.call(arguments,1),f=null;return c!==!0||this.length?(this.each(function(){var g=a.jstree.reference(this),h=d&&g?g[c]:null;return f=d&&h?h.apply(g,e):null,g||d||c!==b&&!a.isPlainObject(c)||a.jstree.create(this,c),(g&&!d||c===!0)&&(f=g||!1),null!==f&&f!==b?!1:void 0}),null!==f&&f!==b?f:this):!1},a.expr.pseudos.jstree=a.expr.createPseudo(function(c){return function(c){return a(c).hasClass("jstree")&&a(c).data("jstree")!==b}}),a.jstree.defaults.core={data:!1,strings:!1,check_callback:!1,error:a.noop,animation:200,multiple:!0,themes:{name:!1,url:!1,dir:!1,dots:!0,icons:!0,ellipsis:!1,stripes:!1,variant:!1,responsive:!1},expand_selected_onload:!0,worker:!0,force_text:!1,dblclick_toggle:!0,loaded_state:!1,restore_focus:!0,keyboard:{"ctrl-space":function(b){b.type="click",a(b.currentTarget).trigger(b)},enter:function(b){b.type="click",a(b.currentTarget).trigger(b)},left:function(b){if(b.preventDefault(),this.is_open(b.currentTarget))this.close_node(b.currentTarget);else{var c=this.get_parent(b.currentTarget);c&&c.id!==a.jstree.root&&this.get_node(c,!0).children(".jstree-anchor").focus()}},up:function(a){a.preventDefault();var b=this.get_prev_dom(a.currentTarget);b&&b.length&&b.children(".jstree-anchor").focus()},right:function(b){if(b.preventDefault(),this.is_closed(b.currentTarget))this.open_node(b.currentTarget,function(a){this.get_node(a,!0).children(".jstree-anchor").focus()});else if(this.is_open(b.currentTarget)){var c=this.get_node(b.currentTarget,!0).children(".jstree-children")[0];c&&a(this._firstChild(c)).children(".jstree-anchor").focus()}},down:function(a){a.preventDefault();var b=this.get_next_dom(a.currentTarget);b&&b.length&&b.children(".jstree-anchor").focus()},"*":function(a){this.open_all()},home:function(b){b.preventDefault();var c=this._firstChild(this.get_container_ul()[0]);c&&a(c).children(".jstree-anchor").filter(":visible").focus()},end:function(a){a.preventDefault(),this.element.find(".jstree-anchor").filter(":visible").last().focus()},f2:function(a){a.preventDefault(),this.edit(a.currentTarget)}}},a.jstree.core.prototype={plugin:function(b,c){var d=a.jstree.plugins[b];return d?(this._data[b]={},d.prototype=this,new d(c,this)):this},init:function(b,c){this._model={data:{},changed:[],force_full_redraw:!1,redraw_timeout:!1,default_state:{loaded:!0,opened:!1,selected:!1,disabled:!1}},this._model.data[a.jstree.root]={id:a.jstree.root,parent:null,parents:[],children:[],children_d:[],state:{loaded:!1}},this.element=a(b).addClass("jstree jstree-"+this._id),this.settings=c,this._data.core.ready=!1,this._data.core.loaded=!1,this._data.core.rtl="rtl"===this.element.css("direction"),this.element[this._data.core.rtl?"addClass":"removeClass"]("jstree-rtl"),this.element.attr("role","tree"),this.settings.core.multiple&&this.element.attr("aria-multiselectable",!0),this.element.attr("tabindex")||this.element.attr("tabindex","0"),this.bind(),this.trigger("init"),this._data.core.original_container_html=this.element.find(" > ul > li").clone(!0),this._data.core.original_container_html.find("li").addBack().contents().filter(function(){return 3===this.nodeType&&(!this.nodeValue||/^\s+$/.test(this.nodeValue))}).remove(),this.element.html("<ul class='jstree-container-ul jstree-children' role='group'><li id='j"+this._id+"_loading' class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='tree-item'><i class='jstree-icon jstree-ocl'></i><a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>"+this.get_string("Loading ...")+"</a></li></ul>"),this.element.attr("aria-activedescendant","j"+this._id+"_loading"),this._data.core.li_height=this.get_container_ul().children("li").first().outerHeight()||24,this._data.core.node=this._create_prototype_node(),this.trigger("loading"),this.load_node(a.jstree.root)},destroy:function(a){if(this.trigger("destroy"),this._wrk)try{window.URL.revokeObjectURL(this._wrk),this._wrk=null}catch(b){}a||this.element.empty(),this.teardown()},_create_prototype_node:function(){var a=i.createElement("LI"),b,c;return a.setAttribute("role","treeitem"),b=i.createElement("I"),b.className="jstree-icon jstree-ocl",b.setAttribute("role","presentation"),a.appendChild(b),b=i.createElement("A"),b.className="jstree-anchor",b.setAttribute("href","#"),b.setAttribute("tabindex","-1"),c=i.createElement("I"),c.className="jstree-icon jstree-themeicon",c.setAttribute("role","presentation"),b.appendChild(c),a.appendChild(b),b=c=null,a},_kbevent_to_func:function(a){var b={8:"Backspace",9:"Tab",13:"Return",19:"Pause",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"Print",45:"Insert",46:"Delete",96:"Numpad0",97:"Numpad1",98:"Numpad2",99:"Numpad3",100:"Numpad4",101:"Numpad5",102:"Numpad6",103:"Numpad7",104:"Numpad8",105:"Numpad9","-13":"NumpadEnter",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"Numlock",145:"Scrolllock",16:"Shift",17:"Ctrl",18:"Alt",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",107:"+",109:"-",110:".",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",111:"/",106:"*",173:"-"},c=[];a.ctrlKey&&c.push("ctrl"),a.altKey&&c.push("alt"),a.shiftKey&&c.push("shift"),c.push(b[a.which]||a.which),c=c.sort().join("-").toLowerCase();var d=this.settings.core.keyboard,e,f;for(e in d)if(d.hasOwnProperty(e)&&(f=e,"-"!==f&&"+"!==f&&(f=f.replace("--","-MINUS").replace("+-","-MINUS").replace("++","-PLUS").replace("-+","-PLUS"),f=f.split(/-|\+/).sort().join("-").replace("MINUS","-").replace("PLUS","+").toLowerCase()),f===c))return d[e];return null},teardown:function(){this.unbind(),this.element.removeClass("jstree").removeData("jstree").find("[class^='jstree']").addBack().attr("class",function(){return this.className.replace(/jstree[^ ]*|$/gi,"")}),this.element=null},bind:function(){var b="",c=null,d=0;this.element.on("dblclick.jstree",function(a){if(a.target.tagName&&"input"===a.target.tagName.toLowerCase())return!0;if(i.selection&&i.selection.empty)i.selection.empty();else if(window.getSelection){var b=window.getSelection();try{b.removeAllRanges(),b.collapse()}catch(c){}}}).on("mousedown.jstree",a.proxy(function(a){a.target===this.element[0]&&(a.preventDefault(),d=+new Date)},this)).on("mousedown.jstree",".jstree-ocl",function(a){a.preventDefault()}).on("click.jstree",".jstree-ocl",a.proxy(function(a){this.toggle_node(a.target)},this)).on("dblclick.jstree",".jstree-anchor",a.proxy(function(a){return a.target.tagName&&"input"===a.target.tagName.toLowerCase()?!0:void(this.settings.core.dblclick_toggle&&this.toggle_node(a.target))},this)).on("click.jstree",".jstree-anchor",a.proxy(function(b){b.preventDefault(),b.currentTarget!==i.activeElement&&a(b.currentTarget).focus(),this.activate_node(b.currentTarget,b)},this)).on("keydown.jstree",".jstree-anchor",a.proxy(function(a){if(a.target.tagName&&"input"===a.target.tagName.toLowerCase())return!0;this._data.core.rtl&&(37===a.which?a.which=39:39===a.which&&(a.which=37));var b=this._kbevent_to_func(a);if(b){var c=b.call(this,a);if(c===!1||c===!0)return c}},this)).on("load_node.jstree",a.proxy(function(b,c){c.status&&(c.node.id!==a.jstree.root||this._data.core.loaded||(this._data.core.loaded=!0,this._firstChild(this.get_container_ul()[0])&&this.element.attr("aria-activedescendant",this._firstChild(this.get_container_ul()[0]).id),this.trigger("loaded")),this._data.core.ready||setTimeout(a.proxy(function(){if(this.element&&!this.get_container_ul().find(".jstree-loading").length){if(this._data.core.ready=!0,this._data.core.selected.length){if(this.settings.core.expand_selected_onload){var b=[],c,d;for(c=0,d=this._data.core.selected.length;d>c;c++)b=b.concat(this._model.data[this._data.core.selected[c]].parents);for(b=a.vakata.array_unique(b),c=0,d=b.length;d>c;c++)this.open_node(b[c],!1,0)}this.trigger("changed",{action:"ready",selected:this._data.core.selected})}this.trigger("ready")}},this),0))},this)).on("keypress.jstree",a.proxy(function(d){if(d.target.tagName&&"input"===d.target.tagName.toLowerCase())return!0;c&&clearTimeout(c),c=setTimeout(function(){b=""},500);var e=String.fromCharCode(d.which).toLowerCase(),f=this.element.find(".jstree-anchor").filter(":visible"),g=f.index(i.activeElement)||0,h=!1;if(b+=e,b.length>1){if(f.slice(g).each(a.proxy(function(c,d){return 0===a(d).text().toLowerCase().indexOf(b)?(a(d).focus(),h=!0,!1):void 0},this)),h)return;if(f.slice(0,g).each(a.proxy(function(c,d){return 0===a(d).text().toLowerCase().indexOf(b)?(a(d).focus(),h=!0,!1):void 0},this)),h)return}if(new RegExp("^"+e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")+"+$").test(b)){if(f.slice(g+1).each(a.proxy(function(b,c){return a(c).text().toLowerCase().charAt(0)===e?(a(c).focus(),h=!0,!1):void 0},this)),h)return;if(f.slice(0,g+1).each(a.proxy(function(b,c){return a(c).text().toLowerCase().charAt(0)===e?(a(c).focus(),h=!0,!1):void 0},this)),h)return}},this)).on("init.jstree",a.proxy(function(){var a=this.settings.core.themes;this._data.core.themes.dots=a.dots,this._data.core.themes.stripes=a.stripes,this._data.core.themes.icons=a.icons,this._data.core.themes.ellipsis=a.ellipsis,this.set_theme(a.name||"default",a.url),this.set_theme_variant(a.variant)},this)).on("loading.jstree",a.proxy(function(){this[this._data.core.themes.dots?"show_dots":"hide_dots"](),this[this._data.core.themes.icons?"show_icons":"hide_icons"](),this[this._data.core.themes.stripes?"show_stripes":"hide_stripes"](),this[this._data.core.themes.ellipsis?"show_ellipsis":"hide_ellipsis"]()},this)).on("blur.jstree",".jstree-anchor",a.proxy(function(b){this._data.core.focused=null,a(b.currentTarget).filter(".jstree-hovered").mouseleave(),this.element.attr("tabindex","0")},this)).on("focus.jstree",".jstree-anchor",a.proxy(function(b){var c=this.get_node(b.currentTarget);c&&c.id&&(this._data.core.focused=c.id),this.element.find(".jstree-hovered").not(b.currentTarget).mouseleave(),a(b.currentTarget).mouseenter(),this.element.attr("tabindex","-1")},this)).on("focus.jstree",a.proxy(function(){if(+new Date-d>500&&!this._data.core.focused&&this.settings.core.restore_focus){d=0;var a=this.get_node(this.element.attr("aria-activedescendant"),!0);a&&a.find("> .jstree-anchor").focus()}},this)).on("mouseenter.jstree",".jstree-anchor",a.proxy(function(a){this.hover_node(a.currentTarget)},this)).on("mouseleave.jstree",".jstree-anchor",a.proxy(function(a){this.dehover_node(a.currentTarget)},this))},unbind:function(){this.element.off(".jstree"),a(i).off(".jstree-"+this._id)},trigger:function(a,b){b||(b={}),b.instance=this,this.element.triggerHandler(a.replace(".jstree","")+".jstree",b)},get_container:function(){return this.element},get_container_ul:function(){return this.element.children(".jstree-children").first()},get_string:function(b){var c=this.settings.core.strings;return a.isFunction(c)?c.call(this,b):c&&c[b]?c[b]:b},_firstChild:function(a){a=a?a.firstChild:null;while(null!==a&&1!==a.nodeType)a=a.nextSibling;return a},_nextSibling:function(a){a=a?a.nextSibling:null;while(null!==a&&1!==a.nodeType)a=a.nextSibling;return a},_previousSibling:function(a){a=a?a.previousSibling:null;while(null!==a&&1!==a.nodeType)a=a.previousSibling;return a},get_node:function(b,c){b&&b.id&&(b=b.id);var d;try{if(this._model.data[b])b=this._model.data[b];else if("string"==typeof b&&this._model.data[b.replace(/^#/,"")])b=this._model.data[b.replace(/^#/,"")];else if("string"==typeof b&&(d=a("#"+b.replace(a.jstree.idregex,"\\$&"),this.element)).length&&this._model.data[d.closest(".jstree-node").attr("id")])b=this._model.data[d.closest(".jstree-node").attr("id")];else if((d=a(b,this.element)).length&&this._model.data[d.closest(".jstree-node").attr("id")])b=this._model.data[d.closest(".jstree-node").attr("id")];else{if(!(d=a(b,this.element)).length||!d.hasClass("jstree"))return!1;b=this._model.data[a.jstree.root]}return c&&(b=b.id===a.jstree.root?this.element:a("#"+b.id.replace(a.jstree.idregex,"\\$&"),this.element)),b}catch(e){return!1}},get_path:function(b,c,d){if(b=b.parents?b:this.get_node(b),!b||b.id===a.jstree.root||!b.parents)return!1;var e,f,g=[];for(g.push(d?b.id:b.text),e=0,f=b.parents.length;f>e;e++)g.push(d?b.parents[e]:this.get_text(b.parents[e]));return g=g.reverse().slice(1),c?g.join(c):g},get_next_dom:function(b,c){var d;if(b=this.get_node(b,!0),b[0]===this.element[0]){d=this._firstChild(this.get_container_ul()[0]);while(d&&0===d.offsetHeight)d=this._nextSibling(d);return d?a(d):!1}if(!b||!b.length)return!1;if(c){d=b[0];do d=this._nextSibling(d);while(d&&0===d.offsetHeight);return d?a(d):!1}if(b.hasClass("jstree-open")){d=this._firstChild(b.children(".jstree-children")[0]);while(d&&0===d.offsetHeight)d=this._nextSibling(d);if(null!==d)return a(d)}d=b[0];do d=this._nextSibling(d);while(d&&0===d.offsetHeight);return null!==d?a(d):b.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first()},get_prev_dom:function(b,c){var d;if(b=this.get_node(b,!0),b[0]===this.element[0]){d=this.get_container_ul()[0].lastChild;while(d&&0===d.offsetHeight)d=this._previousSibling(d);return d?a(d):!1}if(!b||!b.length)return!1;if(c){d=b[0];do d=this._previousSibling(d);while(d&&0===d.offsetHeight);return d?a(d):!1}d=b[0];do d=this._previousSibling(d);while(d&&0===d.offsetHeight);if(null!==d){b=a(d);while(b.hasClass("jstree-open"))b=b.children(".jstree-children").first().children(".jstree-node:visible:last");return b}return d=b[0].parentNode.parentNode,d&&d.className&&-1!==d.className.indexOf("jstree-node")?a(d):!1},get_parent:function(b){return b=this.get_node(b),b&&b.id!==a.jstree.root?b.parent:!1},get_children_dom:function(a){return a=this.get_node(a,!0),a[0]===this.element[0]?this.get_container_ul().children(".jstree-node"):a&&a.length?a.children(".jstree-children").children(".jstree-node"):!1},is_parent:function(a){return a=this.get_node(a),a&&(a.state.loaded===!1||a.children.length>0)},is_loaded:function(a){return a=this.get_node(a),a&&a.state.loaded},is_loading:function(a){return a=this.get_node(a),a&&a.state&&a.state.loading},is_open:function(a){return a=this.get_node(a),a&&a.state.opened},is_closed:function(a){return a=this.get_node(a),a&&this.is_parent(a)&&!a.state.opened},is_leaf:function(a){return!this.is_parent(a)},load_node:function(b,c){var d,e,f,g,h;if(a.isArray(b))return this._load_nodes(b.slice(),c),!0;if(b=this.get_node(b),!b)return c&&c.call(this,b,!1),!1;if(b.state.loaded){for(b.state.loaded=!1,f=0,g=b.parents.length;g>f;f++)this._model.data[b.parents[f]].children_d=a.vakata.array_filter(this._model.data[b.parents[f]].children_d,function(c){return-1===a.inArray(c,b.children_d)});for(d=0,e=b.children_d.length;e>d;d++)this._model.data[b.children_d[d]].state.selected&&(h=!0),delete this._model.data[b.children_d[d]];h&&(this._data.core.selected=a.vakata.array_filter(this._data.core.selected,function(c){return-1===a.inArray(c,b.children_d)})),b.children=[],b.children_d=[],h&&this.trigger("changed",{action:"load_node",node:b,selected:this._data.core.selected})}return b.state.failed=!1,b.state.loading=!0,this.get_node(b,!0).addClass("jstree-loading").attr("aria-busy",!0),this._load_node(b,a.proxy(function(a){b=this._model.data[b.id],b.state.loading=!1,b.state.loaded=a,b.state.failed=!b.state.loaded;var d=this.get_node(b,!0),e=0,f=0,g=this._model.data,h=!1;for(e=0,f=b.children.length;f>e;e++)if(g[b.children[e]]&&!g[b.children[e]].state.hidden){h=!0;break}b.state.loaded&&d&&d.length&&(d.removeClass("jstree-closed jstree-open jstree-leaf"),h?"#"!==b.id&&d.addClass(b.state.opened?"jstree-open":"jstree-closed"):d.addClass("jstree-leaf")),d.removeClass("jstree-loading").attr("aria-busy",!1),this.trigger("load_node",{node:b,status:a}),c&&c.call(this,b,a)},this)),!0},_load_nodes:function(a,b,c,d){var e=!0,f=function(){this._load_nodes(a,b,!0)},g=this._model.data,h,i,j=[];for(h=0,i=a.length;i>h;h++)g[a[h]]&&(!g[a[h]].state.loaded&&!g[a[h]].state.failed||!c&&d)&&(this.is_loading(a[h])||this.load_node(a[h],f),e=!1);if(e){for(h=0,i=a.length;i>h;h++)g[a[h]]&&g[a[h]].state.loaded&&j.push(a[h]);b&&!b.done&&(b.call(this,j),b.done=!0)}},load_all:function(b,c){if(b||(b=a.jstree.root),b=this.get_node(b),!b)return!1;var d=[],e=this._model.data,f=e[b.id].children_d,g,h;for(b.state&&!b.state.loaded&&d.push(b.id),g=0,h=f.length;h>g;g++)e[f[g]]&&e[f[g]].state&&!e[f[g]].state.loaded&&d.push(f[g]);d.length?this._load_nodes(d,function(){this.load_all(b,c)}):(c&&c.call(this,b),this.trigger("load_all",{node:b}))},_load_node:function(b,c){var d=this.settings.core.data,e,f=function g(){return 3!==this.nodeType&&8!==this.nodeType};return d?a.isFunction(d)?d.call(this,b,a.proxy(function(d){d===!1?c.call(this,!1):this["string"==typeof d?"_append_html_data":"_append_json_data"](b,"string"==typeof d?a(a.parseHTML(d)).filter(f):d,function(a){c.call(this,a)})},this)):"object"==typeof d?d.url?(d=a.extend(!0,{},d),a.isFunction(d.url)&&(d.url=d.url.call(this,b)),a.isFunction(d.data)&&(d.data=d.data.call(this,b)),a.ajax(d).done(a.proxy(function(d,e,g){var h=g.getResponseHeader("Content-Type");return h&&-1!==h.indexOf("json")||"object"==typeof d?this._append_json_data(b,d,function(a){c.call(this,a)}):h&&-1!==h.indexOf("html")||"string"==typeof d?this._append_html_data(b,a(a.parseHTML(d)).filter(f),function(a){c.call(this,a)}):(this._data.core.last_error={error:"ajax",plugin:"core",id:"core_04",reason:"Could not load node",data:JSON.stringify({id:b.id,xhr:g})},this.settings.core.error.call(this,this._data.core.last_error),c.call(this,!1))},this)).fail(a.proxy(function(a){this._data.core.last_error={error:"ajax",plugin:"core",id:"core_04",reason:"Could not load node",data:JSON.stringify({id:b.id,xhr:a})},c.call(this,!1),this.settings.core.error.call(this,this._data.core.last_error)},this))):(e=a.isArray(d)?a.extend(!0,[],d):a.isPlainObject(d)?a.extend(!0,{},d):d,b.id===a.jstree.root?this._append_json_data(b,e,function(a){c.call(this,a)}):(this._data.core.last_error={error:"nodata",plugin:"core",id:"core_05",reason:"Could not load node",data:JSON.stringify({id:b.id})},this.settings.core.error.call(this,this._data.core.last_error),c.call(this,!1))):"string"==typeof d?b.id===a.jstree.root?this._append_html_data(b,a(a.parseHTML(d)).filter(f),function(a){c.call(this,a)}):(this._data.core.last_error={error:"nodata",plugin:"core",id:"core_06",reason:"Could not load node",data:JSON.stringify({id:b.id})},this.settings.core.error.call(this,this._data.core.last_error),c.call(this,!1)):c.call(this,!1):b.id===a.jstree.root?this._append_html_data(b,this._data.core.original_container_html.clone(!0),function(a){c.call(this,a)}):c.call(this,!1)},_node_changed:function(b){b=this.get_node(b),b&&-1===a.inArray(b.id,this._model.changed)&&this._model.changed.push(b.id)},_append_html_data:function(b,c,d){b=this.get_node(b),b.children=[],b.children_d=[];var e=c.is("ul")?c.children():c,f=b.id,g=[],h=[],i=this._model.data,j=i[f],k=this._data.core.selected.length,l,m,n;for(e.each(a.proxy(function(b,c){l=this._parse_model_from_html(a(c),f,j.parents.concat()),l&&(g.push(l),h.push(l),i[l].children_d.length&&(h=h.concat(i[l].children_d)))},this)),j.children=g,j.children_d=h,m=0,n=j.parents.length;n>m;m++)i[j.parents[m]].children_d=i[j.parents[m]].children_d.concat(h);this.trigger("model",{nodes:h,parent:f}),f!==a.jstree.root?(this._node_changed(f),this.redraw()):(this.get_container_ul().children(".jstree-initial-node").remove(),this.redraw(!0)),this._data.core.selected.length!==k&&this.trigger("changed",{action:"model",selected:this._data.core.selected}),d.call(this,!0)},_append_json_data:function(b,c,d,e){if(null!==this.element){b=this.get_node(b),b.children=[],b.children_d=[],c.d&&(c=c.d,"string"==typeof c&&(c=JSON.parse(c))),a.isArray(c)||(c=[c]);var f=null,g={df:this._model.default_state,dat:c,par:b.id,m:this._model.data,t_id:this._id,t_cnt:this._cnt,sel:this._data.core.selected},h=function(a,b){a.data&&(a=a.data);var c=a.dat,d=a.par,e=[],f=[],g=[],h=a.df,i=a.t_id,j=a.t_cnt,k=a.m,l=k[d],m=a.sel,n,o,p,q,r=function(a,c,d){d=d?d.concat():[],c&&d.unshift(c);var e=a.id.toString(),f,i,j,l,m={id:e,text:a.text||"",icon:a.icon!==b?a.icon:!0,parent:c,parents:d,children:a.children||[],children_d:a.children_d||[],data:a.data,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1};for(f in h)h.hasOwnProperty(f)&&(m.state[f]=h[f]);if(a&&a.data&&a.data.jstree&&a.data.jstree.icon&&(m.icon=a.data.jstree.icon),(m.icon===b||null===m.icon||""===m.icon)&&(m.icon=!0),a&&a.data&&(m.data=a.data,a.data.jstree))for(f in a.data.jstree)a.data.jstree.hasOwnProperty(f)&&(m.state[f]=a.data.jstree[f]);if(a&&"object"==typeof a.state)for(f in a.state)a.state.hasOwnProperty(f)&&(m.state[f]=a.state[f]);if(a&&"object"==typeof a.li_attr)for(f in a.li_attr)a.li_attr.hasOwnProperty(f)&&(m.li_attr[f]=a.li_attr[f]);if(m.li_attr.id||(m.li_attr.id=e),a&&"object"==typeof a.a_attr)for(f in a.a_attr)a.a_attr.hasOwnProperty(f)&&(m.a_attr[f]=a.a_attr[f]);for(a&&a.children&&a.children===!0&&(m.state.loaded=!1,m.children=[],m.children_d=[]),k[m.id]=m,f=0,i=m.children.length;i>f;f++)j=r(k[m.children[f]],m.id,d),l=k[j],m.children_d.push(j),l.children_d.length&&(m.children_d=m.children_d.concat(l.children_d));return delete a.data,delete a.children,k[m.id].original=a,m.state.selected&&g.push(m.id),m.id},s=function(a,c,d){d=d?d.concat():[],c&&d.unshift(c);var e=!1,f,l,m,n,o;do e="j"+i+"_"+ ++j;while(k[e]);o={id:!1,text:"string"==typeof a?a:"",icon:"object"==typeof a&&a.icon!==b?a.icon:!0,parent:c,parents:d,children:[],children_d:[],data:null,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1};for(f in h)h.hasOwnProperty(f)&&(o.state[f]=h[f]);if(a&&a.id&&(o.id=a.id.toString()),a&&a.text&&(o.text=a.text),a&&a.data&&a.data.jstree&&a.data.jstree.icon&&(o.icon=a.data.jstree.icon),(o.icon===b||null===o.icon||""===o.icon)&&(o.icon=!0),a&&a.data&&(o.data=a.data,a.data.jstree))for(f in a.data.jstree)a.data.jstree.hasOwnProperty(f)&&(o.state[f]=a.data.jstree[f]);if(a&&"object"==typeof a.state)for(f in a.state)a.state.hasOwnProperty(f)&&(o.state[f]=a.state[f]);if(a&&"object"==typeof a.li_attr)for(f in a.li_attr)a.li_attr.hasOwnProperty(f)&&(o.li_attr[f]=a.li_attr[f]);if(o.li_attr.id&&!o.id&&(o.id=o.li_attr.id.toString()),o.id||(o.id=e),o.li_attr.id||(o.li_attr.id=o.id),a&&"object"==typeof a.a_attr)for(f in a.a_attr)a.a_attr.hasOwnProperty(f)&&(o.a_attr[f]=a.a_attr[f]);if(a&&a.children&&a.children.length){for(f=0,l=a.children.length;l>f;f++)m=s(a.children[f],o.id,d),n=k[m],o.children.push(m),n.children_d.length&&(o.children_d=o.children_d.concat(n.children_d));o.children_d=o.children_d.concat(o.children)}return a&&a.children&&a.children===!0&&(o.state.loaded=!1,o.children=[],o.children_d=[]),delete a.data,delete a.children,o.original=a,k[o.id]=o,o.state.selected&&g.push(o.id),o.id};if(c.length&&c[0].id!==b&&c[0].parent!==b){for(o=0,p=c.length;p>o;o++)c[o].children||(c[o].children=[]),c[o].state||(c[o].state={}),k[c[o].id.toString()]=c[o];for(o=0,p=c.length;p>o;o++)k[c[o].parent.toString()]?(k[c[o].parent.toString()].children.push(c[o].id.toString()),l.children_d.push(c[o].id.toString())):(this._data.core.last_error={error:"parse",plugin:"core",id:"core_07",reason:"Node with invalid parent",data:JSON.stringify({id:c[o].id.toString(),parent:c[o].parent.toString()})},this.settings.core.error.call(this,this._data.core.last_error));for(o=0,p=l.children.length;p>o;o++)n=r(k[l.children[o]],d,l.parents.concat()),f.push(n),k[n].children_d.length&&(f=f.concat(k[n].children_d));for(o=0,p=l.parents.length;p>o;o++)k[l.parents[o]].children_d=k[l.parents[o]].children_d.concat(f);q={cnt:j,mod:k,sel:m,par:d,dpc:f,add:g}}else{for(o=0,p=c.length;p>o;o++)n=s(c[o],d,l.parents.concat()),n&&(e.push(n),f.push(n),k[n].children_d.length&&(f=f.concat(k[n].children_d)));for(l.children=e,l.children_d=f,o=0,p=l.parents.length;p>o;o++)k[l.parents[o]].children_d=k[l.parents[o]].children_d.concat(f);q={cnt:j,mod:k,sel:m,par:d,dpc:f,add:g}}return"undefined"!=typeof window&&"undefined"!=typeof window.document?q:void postMessage(q)},i=function(b,c){if(null!==this.element){this._cnt=b.cnt;var e,f=this._model.data;for(e in f)f.hasOwnProperty(e)&&f[e].state&&f[e].state.loading&&b.mod[e]&&(b.mod[e].state.loading=!0);if(this._model.data=b.mod,c){var g,h=b.add,i=b.sel,j=this._data.core.selected.slice();if(f=this._model.data,i.length!==j.length||a.vakata.array_unique(i.concat(j)).length!==i.length){for(e=0,g=i.length;g>e;e++)-1===a.inArray(i[e],h)&&-1===a.inArray(i[e],j)&&(f[i[e]].state.selected=!1);for(e=0,g=j.length;g>e;e++)-1===a.inArray(j[e],i)&&(f[j[e]].state.selected=!0)}}b.add.length&&(this._data.core.selected=this._data.core.selected.concat(b.add)),this.trigger("model",{nodes:b.dpc,parent:b.par}),b.par!==a.jstree.root?(this._node_changed(b.par),this.redraw()):this.redraw(!0),b.add.length&&this.trigger("changed",{action:"model",selected:this._data.core.selected}),d.call(this,!0)}};if(this.settings.core.worker&&window.Blob&&window.URL&&window.Worker)try{null===this._wrk&&(this._wrk=window.URL.createObjectURL(new window.Blob(["self.onmessage = "+h.toString()],{type:"text/javascript"}))),!this._data.core.working||e?(this._data.core.working=!0,f=new window.Worker(this._wrk),f.onmessage=a.proxy(function(a){i.call(this,a.data,!0);try{f.terminate(),f=null}catch(b){}this._data.core.worker_queue.length?this._append_json_data.apply(this,this._data.core.worker_queue.shift()):this._data.core.working=!1},this),g.par?f.postMessage(g):this._data.core.worker_queue.length?this._append_json_data.apply(this,this._data.core.worker_queue.shift()):this._data.core.working=!1):this._data.core.worker_queue.push([b,c,d,!0])}catch(j){i.call(this,h(g),!1),this._data.core.worker_queue.length?this._append_json_data.apply(this,this._data.core.worker_queue.shift()):this._data.core.working=!1}else i.call(this,h(g),!1)}},_parse_model_from_html:function(c,d,e){e=e?[].concat(e):[],d&&e.unshift(d);var f,g,h=this._model.data,i={id:!1,text:!1,icon:!0,parent:d,parents:e,children:[],children_d:[],data:null,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1},j,k,l;for(j in this._model.default_state)this._model.default_state.hasOwnProperty(j)&&(i.state[j]=this._model.default_state[j]);if(k=a.vakata.attributes(c,!0),a.each(k,function(b,c){return c=a.trim(c),c.length?(i.li_attr[b]=c,void("id"===b&&(i.id=c.toString()))):!0}),k=c.children("a").first(),k.length&&(k=a.vakata.attributes(k,!0),a.each(k,function(b,c){c=a.trim(c),c.length&&(i.a_attr[b]=c)})),k=c.children("a").first().length?c.children("a").first().clone():c.clone(),k.children("ins, i, ul").remove(),k=k.html(),k=a("<div />").html(k),i.text=this.settings.core.force_text?k.text():k.html(),k=c.data(),i.data=k?a.extend(!0,{},k):null,i.state.opened=c.hasClass("jstree-open"),i.state.selected=c.children("a").hasClass("jstree-clicked"),i.state.disabled=c.children("a").hasClass("jstree-disabled"),i.data&&i.data.jstree)for(j in i.data.jstree)i.data.jstree.hasOwnProperty(j)&&(i.state[j]=i.data.jstree[j]);k=c.children("a").children(".jstree-themeicon"),k.length&&(i.icon=k.hasClass("jstree-themeicon-hidden")?!1:k.attr("rel")),i.state.icon!==b&&(i.icon=i.state.icon),(i.icon===b||null===i.icon||""===i.icon)&&(i.icon=!0),k=c.children("ul").children("li");do l="j"+this._id+"_"+ ++this._cnt;while(h[l]);return i.id=i.li_attr.id?i.li_attr.id.toString():l,k.length?(k.each(a.proxy(function(b,c){f=this._parse_model_from_html(a(c),i.id,e),g=this._model.data[f],i.children.push(f),g.children_d.length&&(i.children_d=i.children_d.concat(g.children_d))},this)),i.children_d=i.children_d.concat(i.children)):c.hasClass("jstree-closed")&&(i.state.loaded=!1),i.li_attr["class"]&&(i.li_attr["class"]=i.li_attr["class"].replace("jstree-closed","").replace("jstree-open","")),i.a_attr["class"]&&(i.a_attr["class"]=i.a_attr["class"].replace("jstree-clicked","").replace("jstree-disabled","")),h[i.id]=i,i.state.selected&&this._data.core.selected.push(i.id),i.id},_parse_model_from_flat_json:function(a,c,d){d=d?d.concat():[],c&&d.unshift(c);var e=a.id.toString(),f=this._model.data,g=this._model.default_state,h,i,j,k,l={id:e,text:a.text||"",icon:a.icon!==b?a.icon:!0,parent:c,parents:d,children:a.children||[],children_d:a.children_d||[],data:a.data,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1};for(h in g)g.hasOwnProperty(h)&&(l.state[h]=g[h]);if(a&&a.data&&a.data.jstree&&a.data.jstree.icon&&(l.icon=a.data.jstree.icon),(l.icon===b||null===l.icon||""===l.icon)&&(l.icon=!0),a&&a.data&&(l.data=a.data,a.data.jstree))for(h in a.data.jstree)a.data.jstree.hasOwnProperty(h)&&(l.state[h]=a.data.jstree[h]);if(a&&"object"==typeof a.state)for(h in a.state)a.state.hasOwnProperty(h)&&(l.state[h]=a.state[h]);if(a&&"object"==typeof a.li_attr)for(h in a.li_attr)a.li_attr.hasOwnProperty(h)&&(l.li_attr[h]=a.li_attr[h]);if(l.li_attr.id||(l.li_attr.id=e),a&&"object"==typeof a.a_attr)for(h in a.a_attr)a.a_attr.hasOwnProperty(h)&&(l.a_attr[h]=a.a_attr[h]);for(a&&a.children&&a.children===!0&&(l.state.loaded=!1,l.children=[],l.children_d=[]),f[l.id]=l,h=0,i=l.children.length;i>h;h++)j=this._parse_model_from_flat_json(f[l.children[h]],l.id,d),k=f[j],l.children_d.push(j),k.children_d.length&&(l.children_d=l.children_d.concat(k.children_d));return delete a.data,delete a.children,f[l.id].original=a,l.state.selected&&this._data.core.selected.push(l.id),l.id},_parse_model_from_json:function(a,c,d){d=d?d.concat():[],c&&d.unshift(c);var e=!1,f,g,h,i,j=this._model.data,k=this._model.default_state,l;do e="j"+this._id+"_"+ ++this._cnt;while(j[e]);l={id:!1,text:"string"==typeof a?a:"",icon:"object"==typeof a&&a.icon!==b?a.icon:!0,parent:c,parents:d,children:[],children_d:[],data:null,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1};for(f in k)k.hasOwnProperty(f)&&(l.state[f]=k[f]);if(a&&a.id&&(l.id=a.id.toString()),a&&a.text&&(l.text=a.text),a&&a.data&&a.data.jstree&&a.data.jstree.icon&&(l.icon=a.data.jstree.icon),(l.icon===b||null===l.icon||""===l.icon)&&(l.icon=!0),a&&a.data&&(l.data=a.data,a.data.jstree))for(f in a.data.jstree)a.data.jstree.hasOwnProperty(f)&&(l.state[f]=a.data.jstree[f]);if(a&&"object"==typeof a.state)for(f in a.state)a.state.hasOwnProperty(f)&&(l.state[f]=a.state[f]);if(a&&"object"==typeof a.li_attr)for(f in a.li_attr)a.li_attr.hasOwnProperty(f)&&(l.li_attr[f]=a.li_attr[f]);if(l.li_attr.id&&!l.id&&(l.id=l.li_attr.id.toString()),l.id||(l.id=e),l.li_attr.id||(l.li_attr.id=l.id),
3
- a&&"object"==typeof a.a_attr)for(f in a.a_attr)a.a_attr.hasOwnProperty(f)&&(l.a_attr[f]=a.a_attr[f]);if(a&&a.children&&a.children.length){for(f=0,g=a.children.length;g>f;f++)h=this._parse_model_from_json(a.children[f],l.id,d),i=j[h],l.children.push(h),i.children_d.length&&(l.children_d=l.children_d.concat(i.children_d));l.children_d=l.children_d.concat(l.children)}return a&&a.children&&a.children===!0&&(l.state.loaded=!1,l.children=[],l.children_d=[]),delete a.data,delete a.children,l.original=a,j[l.id]=l,l.state.selected&&this._data.core.selected.push(l.id),l.id},_redraw:function(){var b=this._model.force_full_redraw?this._model.data[a.jstree.root].children.concat([]):this._model.changed.concat([]),c=i.createElement("UL"),d,e,f,g=this._data.core.focused;for(e=0,f=b.length;f>e;e++)d=this.redraw_node(b[e],!0,this._model.force_full_redraw),d&&this._model.force_full_redraw&&c.appendChild(d);this._model.force_full_redraw&&(c.className=this.get_container_ul()[0].className,c.setAttribute("role","group"),this.element.empty().append(c)),null!==g&&(d=this.get_node(g,!0),d&&d.length&&d.children(".jstree-anchor")[0]!==i.activeElement?d.children(".jstree-anchor").focus():this._data.core.focused=null),this._model.force_full_redraw=!1,this._model.changed=[],this.trigger("redraw",{nodes:b})},redraw:function(a){a&&(this._model.force_full_redraw=!0),this._redraw()},draw_children:function(b){var c=this.get_node(b),d=!1,e=!1,f=!1,g=i;if(!c)return!1;if(c.id===a.jstree.root)return this.redraw(!0);if(b=this.get_node(b,!0),!b||!b.length)return!1;if(b.children(".jstree-children").remove(),b=b[0],c.children.length&&c.state.loaded){for(f=g.createElement("UL"),f.setAttribute("role","group"),f.className="jstree-children",d=0,e=c.children.length;e>d;d++)f.appendChild(this.redraw_node(c.children[d],!0,!0));b.appendChild(f)}},redraw_node:function(b,c,d,e){var f=this.get_node(b),g=!1,h=!1,j=!1,k=!1,l=!1,m=!1,n="",o=i,p=this._model.data,q=!1,r=!1,s=null,t=0,u=0,v=!1,w=!1;if(!f)return!1;if(f.id===a.jstree.root)return this.redraw(!0);if(c=c||0===f.children.length,b=i.querySelector?this.element[0].querySelector("#"+(-1!=="0123456789".indexOf(f.id[0])?"\\3"+f.id[0]+" "+f.id.substr(1).replace(a.jstree.idregex,"\\$&"):f.id.replace(a.jstree.idregex,"\\$&"))):i.getElementById(f.id))b=a(b),d||(g=b.parent().parent()[0],g===this.element[0]&&(g=null),h=b.index()),c||!f.children.length||b.children(".jstree-children").length||(c=!0),c||(j=b.children(".jstree-children")[0]),q=b.children(".jstree-anchor")[0]===i.activeElement,b.remove();else if(c=!0,!d){if(g=f.parent!==a.jstree.root?a("#"+f.parent.replace(a.jstree.idregex,"\\$&"),this.element)[0]:null,!(null===g||g&&p[f.parent].state.opened))return!1;h=a.inArray(f.id,null===g?p[a.jstree.root].children:p[f.parent].children)}b=this._data.core.node.cloneNode(!0),n="jstree-node ";for(k in f.li_attr)if(f.li_attr.hasOwnProperty(k)){if("id"===k)continue;"class"!==k?b.setAttribute(k,f.li_attr[k]):n+=f.li_attr[k]}for(f.a_attr.id||(f.a_attr.id=f.id+"_anchor"),b.setAttribute("aria-selected",!!f.state.selected),b.setAttribute("aria-level",f.parents.length),b.setAttribute("aria-labelledby",f.a_attr.id),f.state.disabled&&b.setAttribute("aria-disabled",!0),k=0,l=f.children.length;l>k;k++)if(!p[f.children[k]].state.hidden){v=!0;break}if(null!==f.parent&&p[f.parent]&&!f.state.hidden&&(k=a.inArray(f.id,p[f.parent].children),w=f.id,-1!==k))for(k++,l=p[f.parent].children.length;l>k;k++)if(p[p[f.parent].children[k]].state.hidden||(w=p[f.parent].children[k]),w!==f.id)break;f.state.hidden&&(n+=" jstree-hidden"),f.state.loading&&(n+=" jstree-loading"),f.state.loaded&&!v?n+=" jstree-leaf":(n+=f.state.opened&&f.state.loaded?" jstree-open":" jstree-closed",b.setAttribute("aria-expanded",f.state.opened&&f.state.loaded)),w===f.id&&(n+=" jstree-last"),b.id=f.id,b.className=n,n=(f.state.selected?" jstree-clicked":"")+(f.state.disabled?" jstree-disabled":"");for(l in f.a_attr)if(f.a_attr.hasOwnProperty(l)){if("href"===l&&"#"===f.a_attr[l])continue;"class"!==l?b.childNodes[1].setAttribute(l,f.a_attr[l]):n+=" "+f.a_attr[l]}if(n.length&&(b.childNodes[1].className="jstree-anchor "+n),(f.icon&&f.icon!==!0||f.icon===!1)&&(f.icon===!1?b.childNodes[1].childNodes[0].className+=" jstree-themeicon-hidden":-1===f.icon.indexOf("/")&&-1===f.icon.indexOf(".")?b.childNodes[1].childNodes[0].className+=" "+f.icon+" jstree-themeicon-custom":(b.childNodes[1].childNodes[0].style.backgroundImage='url("'+f.icon+'")',b.childNodes[1].childNodes[0].style.backgroundPosition="center center",b.childNodes[1].childNodes[0].style.backgroundSize="auto",b.childNodes[1].childNodes[0].className+=" jstree-themeicon-custom")),this.settings.core.force_text?b.childNodes[1].appendChild(o.createTextNode(f.text)):b.childNodes[1].innerHTML+=f.text,c&&f.children.length&&(f.state.opened||e)&&f.state.loaded){for(m=o.createElement("UL"),m.setAttribute("role","group"),m.className="jstree-children",k=0,l=f.children.length;l>k;k++)m.appendChild(this.redraw_node(f.children[k],c,!0));b.appendChild(m)}if(j&&b.appendChild(j),!d){for(g||(g=this.element[0]),k=0,l=g.childNodes.length;l>k;k++)if(g.childNodes[k]&&g.childNodes[k].className&&-1!==g.childNodes[k].className.indexOf("jstree-children")){s=g.childNodes[k];break}s||(s=o.createElement("UL"),s.setAttribute("role","group"),s.className="jstree-children",g.appendChild(s)),g=s,h<g.childNodes.length?g.insertBefore(b,g.childNodes[h]):g.appendChild(b),q&&(t=this.element[0].scrollTop,u=this.element[0].scrollLeft,b.childNodes[1].focus(),this.element[0].scrollTop=t,this.element[0].scrollLeft=u)}return f.state.opened&&!f.state.loaded&&(f.state.opened=!1,setTimeout(a.proxy(function(){this.open_node(f.id,!1,0)},this),0)),b},open_node:function(c,d,e){var f,g,h,i;if(a.isArray(c)){for(c=c.slice(),f=0,g=c.length;g>f;f++)this.open_node(c[f],d,e);return!0}return c=this.get_node(c),c&&c.id!==a.jstree.root?(e=e===b?this.settings.core.animation:e,this.is_closed(c)?this.is_loaded(c)?(h=this.get_node(c,!0),i=this,h.length&&(e&&h.children(".jstree-children").length&&h.children(".jstree-children").stop(!0,!0),c.children.length&&!this._firstChild(h.children(".jstree-children")[0])&&this.draw_children(c),e?(this.trigger("before_open",{node:c}),h.children(".jstree-children").css("display","none").end().removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded",!0).children(".jstree-children").stop(!0,!0).slideDown(e,function(){this.style.display="",i.element&&i.trigger("after_open",{node:c})})):(this.trigger("before_open",{node:c}),h[0].className=h[0].className.replace("jstree-closed","jstree-open"),h[0].setAttribute("aria-expanded",!0))),c.state.opened=!0,d&&d.call(this,c,!0),h.length||this.trigger("before_open",{node:c}),this.trigger("open_node",{node:c}),e&&h.length||this.trigger("after_open",{node:c}),!0):this.is_loading(c)?setTimeout(a.proxy(function(){this.open_node(c,d,e)},this),500):void this.load_node(c,function(a,b){return b?this.open_node(a,d,e):d?d.call(this,a,!1):!1}):(d&&d.call(this,c,!1),!1)):!1},_open_to:function(b){if(b=this.get_node(b),!b||b.id===a.jstree.root)return!1;var c,d,e=b.parents;for(c=0,d=e.length;d>c;c+=1)c!==a.jstree.root&&this.open_node(e[c],!1,0);return a("#"+b.id.replace(a.jstree.idregex,"\\$&"),this.element)},close_node:function(c,d){var e,f,g,h;if(a.isArray(c)){for(c=c.slice(),e=0,f=c.length;f>e;e++)this.close_node(c[e],d);return!0}return c=this.get_node(c),c&&c.id!==a.jstree.root?this.is_closed(c)?!1:(d=d===b?this.settings.core.animation:d,g=this,h=this.get_node(c,!0),c.state.opened=!1,this.trigger("close_node",{node:c}),void(h.length?d?h.children(".jstree-children").attr("style","display:block !important").end().removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded",!1).children(".jstree-children").stop(!0,!0).slideUp(d,function(){this.style.display="",h.children(".jstree-children").remove(),g.element&&g.trigger("after_close",{node:c})}):(h[0].className=h[0].className.replace("jstree-open","jstree-closed"),h.attr("aria-expanded",!1).children(".jstree-children").remove(),this.trigger("after_close",{node:c})):this.trigger("after_close",{node:c}))):!1},toggle_node:function(b){var c,d;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.toggle_node(b[c]);return!0}return this.is_closed(b)?this.open_node(b):this.is_open(b)?this.close_node(b):void 0},open_all:function(b,c,d){if(b||(b=a.jstree.root),b=this.get_node(b),!b)return!1;var e=b.id===a.jstree.root?this.get_container_ul():this.get_node(b,!0),f,g,h;if(!e.length){for(f=0,g=b.children_d.length;g>f;f++)this.is_closed(this._model.data[b.children_d[f]])&&(this._model.data[b.children_d[f]].state.opened=!0);return this.trigger("open_all",{node:b})}d=d||e,h=this,e=this.is_closed(b)?e.find(".jstree-closed").addBack():e.find(".jstree-closed"),e.each(function(){h.open_node(this,function(a,b){b&&this.is_parent(a)&&this.open_all(a,c,d)},c||0)}),0===d.find(".jstree-closed").length&&this.trigger("open_all",{node:this.get_node(d)})},close_all:function(b,c){if(b||(b=a.jstree.root),b=this.get_node(b),!b)return!1;var d=b.id===a.jstree.root?this.get_container_ul():this.get_node(b,!0),e=this,f,g;for(d.length&&(d=this.is_open(b)?d.find(".jstree-open").addBack():d.find(".jstree-open"),a(d.get().reverse()).each(function(){e.close_node(this,c||0)})),f=0,g=b.children_d.length;g>f;f++)this._model.data[b.children_d[f]].state.opened=!1;this.trigger("close_all",{node:b})},is_disabled:function(a){return a=this.get_node(a),a&&a.state&&a.state.disabled},enable_node:function(b){var c,d;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.enable_node(b[c]);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(b.state.disabled=!1,this.get_node(b,!0).children(".jstree-anchor").removeClass("jstree-disabled").attr("aria-disabled",!1),void this.trigger("enable_node",{node:b})):!1},disable_node:function(b){var c,d;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.disable_node(b[c]);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(b.state.disabled=!0,this.get_node(b,!0).children(".jstree-anchor").addClass("jstree-disabled").attr("aria-disabled",!0),void this.trigger("disable_node",{node:b})):!1},is_hidden:function(a){return a=this.get_node(a),a.state.hidden===!0},hide_node:function(b,c){var d,e;if(a.isArray(b)){for(b=b.slice(),d=0,e=b.length;e>d;d++)this.hide_node(b[d],!0);return c||this.redraw(),!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?void(b.state.hidden||(b.state.hidden=!0,this._node_changed(b.parent),c||this.redraw(),this.trigger("hide_node",{node:b}))):!1},show_node:function(b,c){var d,e;if(a.isArray(b)){for(b=b.slice(),d=0,e=b.length;e>d;d++)this.show_node(b[d],!0);return c||this.redraw(),!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?void(b.state.hidden&&(b.state.hidden=!1,this._node_changed(b.parent),c||this.redraw(),this.trigger("show_node",{node:b}))):!1},hide_all:function(b){var c,d=this._model.data,e=[];for(c in d)d.hasOwnProperty(c)&&c!==a.jstree.root&&!d[c].state.hidden&&(d[c].state.hidden=!0,e.push(c));return this._model.force_full_redraw=!0,b||this.redraw(),this.trigger("hide_all",{nodes:e}),e},show_all:function(b){var c,d=this._model.data,e=[];for(c in d)d.hasOwnProperty(c)&&c!==a.jstree.root&&d[c].state.hidden&&(d[c].state.hidden=!1,e.push(c));return this._model.force_full_redraw=!0,b||this.redraw(),this.trigger("show_all",{nodes:e}),e},activate_node:function(a,c){if(this.is_disabled(a))return!1;if(c&&"object"==typeof c||(c={}),this._data.core.last_clicked=this._data.core.last_clicked&&this._data.core.last_clicked.id!==b?this.get_node(this._data.core.last_clicked.id):null,this._data.core.last_clicked&&!this._data.core.last_clicked.state.selected&&(this._data.core.last_clicked=null),!this._data.core.last_clicked&&this._data.core.selected.length&&(this._data.core.last_clicked=this.get_node(this._data.core.selected[this._data.core.selected.length-1])),this.settings.core.multiple&&(c.metaKey||c.ctrlKey||c.shiftKey)&&(!c.shiftKey||this._data.core.last_clicked&&this.get_parent(a)&&this.get_parent(a)===this._data.core.last_clicked.parent))if(c.shiftKey){var d=this.get_node(a).id,e=this._data.core.last_clicked.id,f=this.get_node(this._data.core.last_clicked.parent).children,g=!1,h,i;for(h=0,i=f.length;i>h;h+=1)f[h]===d&&(g=!g),f[h]===e&&(g=!g),this.is_disabled(f[h])||!g&&f[h]!==d&&f[h]!==e?this.deselect_node(f[h],!0,c):this.is_hidden(f[h])||this.select_node(f[h],!0,!1,c);this.trigger("changed",{action:"select_node",node:this.get_node(a),selected:this._data.core.selected,event:c})}else this.is_selected(a)?this.deselect_node(a,!1,c):this.select_node(a,!1,!1,c);else!this.settings.core.multiple&&(c.metaKey||c.ctrlKey||c.shiftKey)&&this.is_selected(a)?this.deselect_node(a,!1,c):(this.deselect_all(!0),this.select_node(a,!1,!1,c),this._data.core.last_clicked=this.get_node(a));this.trigger("activate_node",{node:this.get_node(a),event:c})},hover_node:function(a){if(a=this.get_node(a,!0),!a||!a.length||a.children(".jstree-hovered").length)return!1;var b=this.element.find(".jstree-hovered"),c=this.element;b&&b.length&&this.dehover_node(b),a.children(".jstree-anchor").addClass("jstree-hovered"),this.trigger("hover_node",{node:this.get_node(a)}),setTimeout(function(){c.attr("aria-activedescendant",a[0].id)},0)},dehover_node:function(a){return a=this.get_node(a,!0),a&&a.length&&a.children(".jstree-hovered").length?(a.children(".jstree-anchor").removeClass("jstree-hovered"),void this.trigger("dehover_node",{node:this.get_node(a)})):!1},select_node:function(b,c,d,e){var f,g,h,i;if(a.isArray(b)){for(b=b.slice(),g=0,h=b.length;h>g;g++)this.select_node(b[g],c,d,e);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(f=this.get_node(b,!0),void(b.state.selected||(b.state.selected=!0,this._data.core.selected.push(b.id),d||(f=this._open_to(b)),f&&f.length&&f.attr("aria-selected",!0).children(".jstree-anchor").addClass("jstree-clicked"),this.trigger("select_node",{node:b,selected:this._data.core.selected,event:e}),c||this.trigger("changed",{action:"select_node",node:b,selected:this._data.core.selected,event:e})))):!1},deselect_node:function(b,c,d){var e,f,g;if(a.isArray(b)){for(b=b.slice(),e=0,f=b.length;f>e;e++)this.deselect_node(b[e],c,d);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(g=this.get_node(b,!0),void(b.state.selected&&(b.state.selected=!1,this._data.core.selected=a.vakata.array_remove_item(this._data.core.selected,b.id),g.length&&g.attr("aria-selected",!1).children(".jstree-anchor").removeClass("jstree-clicked"),this.trigger("deselect_node",{node:b,selected:this._data.core.selected,event:d}),c||this.trigger("changed",{action:"deselect_node",node:b,selected:this._data.core.selected,event:d})))):!1},select_all:function(b){var c=this._data.core.selected.concat([]),d,e;for(this._data.core.selected=this._model.data[a.jstree.root].children_d.concat(),d=0,e=this._data.core.selected.length;e>d;d++)this._model.data[this._data.core.selected[d]]&&(this._model.data[this._data.core.selected[d]].state.selected=!0);this.redraw(!0),this.trigger("select_all",{selected:this._data.core.selected}),b||this.trigger("changed",{action:"select_all",selected:this._data.core.selected,old_selection:c})},deselect_all:function(a){var b=this._data.core.selected.concat([]),c,d;for(c=0,d=this._data.core.selected.length;d>c;c++)this._model.data[this._data.core.selected[c]]&&(this._model.data[this._data.core.selected[c]].state.selected=!1);this._data.core.selected=[],this.element.find(".jstree-clicked").removeClass("jstree-clicked").parent().attr("aria-selected",!1),this.trigger("deselect_all",{selected:this._data.core.selected,node:b}),a||this.trigger("changed",{action:"deselect_all",selected:this._data.core.selected,old_selection:b})},is_selected:function(b){return b=this.get_node(b),b&&b.id!==a.jstree.root?b.state.selected:!1},get_selected:function(b){return b?a.map(this._data.core.selected,a.proxy(function(a){return this.get_node(a)},this)):this._data.core.selected.slice()},get_top_selected:function(b){var c=this.get_selected(!0),d={},e,f,g,h;for(e=0,f=c.length;f>e;e++)d[c[e].id]=c[e];for(e=0,f=c.length;f>e;e++)for(g=0,h=c[e].children_d.length;h>g;g++)d[c[e].children_d[g]]&&delete d[c[e].children_d[g]];c=[];for(e in d)d.hasOwnProperty(e)&&c.push(e);return b?a.map(c,a.proxy(function(a){return this.get_node(a)},this)):c},get_bottom_selected:function(b){var c=this.get_selected(!0),d=[],e,f;for(e=0,f=c.length;f>e;e++)c[e].children.length||d.push(c[e].id);return b?a.map(d,a.proxy(function(a){return this.get_node(a)},this)):d},get_state:function(){var b={core:{open:[],loaded:[],scroll:{left:this.element.scrollLeft(),top:this.element.scrollTop()},selected:[]}},c;for(c in this._model.data)this._model.data.hasOwnProperty(c)&&c!==a.jstree.root&&(this._model.data[c].state.loaded&&this.settings.core.loaded_state&&b.core.loaded.push(c),this._model.data[c].state.opened&&b.core.open.push(c),this._model.data[c].state.selected&&b.core.selected.push(c));return b},set_state:function(c,d){if(c){if(c.core&&c.core.selected&&c.core.initial_selection===b&&(c.core.initial_selection=this._data.core.selected.concat([]).sort().join(",")),c.core){var e,f,g,h,i;if(c.core.loaded)return this.settings.core.loaded_state&&a.isArray(c.core.loaded)&&c.core.loaded.length?this._load_nodes(c.core.loaded,function(a){delete c.core.loaded,this.set_state(c,d)}):(delete c.core.loaded,this.set_state(c,d)),!1;if(c.core.open)return a.isArray(c.core.open)&&c.core.open.length?this._load_nodes(c.core.open,function(a){this.open_node(a,!1,0),delete c.core.open,this.set_state(c,d)}):(delete c.core.open,this.set_state(c,d)),!1;if(c.core.scroll)return c.core.scroll&&c.core.scroll.left!==b&&this.element.scrollLeft(c.core.scroll.left),c.core.scroll&&c.core.scroll.top!==b&&this.element.scrollTop(c.core.scroll.top),delete c.core.scroll,this.set_state(c,d),!1;if(c.core.selected)return h=this,(c.core.initial_selection===b||c.core.initial_selection===this._data.core.selected.concat([]).sort().join(","))&&(this.deselect_all(),a.each(c.core.selected,function(a,b){h.select_node(b,!1,!0)})),delete c.core.initial_selection,delete c.core.selected,this.set_state(c,d),!1;for(i in c)c.hasOwnProperty(i)&&"core"!==i&&-1===a.inArray(i,this.settings.plugins)&&delete c[i];if(a.isEmptyObject(c.core))return delete c.core,this.set_state(c,d),!1}return a.isEmptyObject(c)?(c=null,d&&d.call(this),this.trigger("set_state"),!1):!0}return!1},refresh:function(b,c){this._data.core.state=c===!0?{}:this.get_state(),c&&a.isFunction(c)&&(this._data.core.state=c.call(this,this._data.core.state)),this._cnt=0,this._model.data={},this._model.data[a.jstree.root]={id:a.jstree.root,parent:null,parents:[],children:[],children_d:[],state:{loaded:!1}},this._data.core.selected=[],this._data.core.last_clicked=null,this._data.core.focused=null;var d=this.get_container_ul()[0].className;b||(this.element.html("<ul class='"+d+"' role='group'><li class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='treeitem' id='j"+this._id+"_loading'><i class='jstree-icon jstree-ocl'></i><a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>"+this.get_string("Loading ...")+"</a></li></ul>"),this.element.attr("aria-activedescendant","j"+this._id+"_loading")),this.load_node(a.jstree.root,function(b,c){c&&(this.get_container_ul()[0].className=d,this._firstChild(this.get_container_ul()[0])&&this.element.attr("aria-activedescendant",this._firstChild(this.get_container_ul()[0]).id),this.set_state(a.extend(!0,{},this._data.core.state),function(){this.trigger("refresh")})),this._data.core.state=null})},refresh_node:function(b){if(b=this.get_node(b),!b||b.id===a.jstree.root)return!1;var c=[],d=[],e=this._data.core.selected.concat([]);d.push(b.id),b.state.opened===!0&&c.push(b.id),this.get_node(b,!0).find(".jstree-open").each(function(){d.push(this.id),c.push(this.id)}),this._load_nodes(d,a.proxy(function(a){this.open_node(c,!1,0),this.select_node(e),this.trigger("refresh_node",{node:b,nodes:a})},this),!1,!0)},set_id:function(b,c){if(b=this.get_node(b),!b||b.id===a.jstree.root)return!1;var d,e,f=this._model.data,g=b.id;for(c=c.toString(),f[b.parent].children[a.inArray(b.id,f[b.parent].children)]=c,d=0,e=b.parents.length;e>d;d++)f[b.parents[d]].children_d[a.inArray(b.id,f[b.parents[d]].children_d)]=c;for(d=0,e=b.children.length;e>d;d++)f[b.children[d]].parent=c;for(d=0,e=b.children_d.length;e>d;d++)f[b.children_d[d]].parents[a.inArray(b.id,f[b.children_d[d]].parents)]=c;return d=a.inArray(b.id,this._data.core.selected),-1!==d&&(this._data.core.selected[d]=c),d=this.get_node(b.id,!0),d&&(d.attr("id",c),this.element.attr("aria-activedescendant")===b.id&&this.element.attr("aria-activedescendant",c)),delete f[b.id],b.id=c,b.li_attr.id=c,f[c]=b,this.trigger("set_id",{node:b,"new":b.id,old:g}),!0},get_text:function(b){return b=this.get_node(b),b&&b.id!==a.jstree.root?b.text:!1},set_text:function(b,c){var d,e;if(a.isArray(b)){for(b=b.slice(),d=0,e=b.length;e>d;d++)this.set_text(b[d],c);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(b.text=c,this.get_node(b,!0).length&&this.redraw_node(b.id),this.trigger("set_text",{obj:b,text:c}),!0):!1},get_json:function(b,c,d){if(b=this.get_node(b||a.jstree.root),!b)return!1;c&&c.flat&&!d&&(d=[]);var e={id:b.id,text:b.text,icon:this.get_icon(b),li_attr:a.extend(!0,{},b.li_attr),a_attr:a.extend(!0,{},b.a_attr),state:{},data:c&&c.no_data?!1:a.extend(!0,a.isArray(b.data)?[]:{},b.data)},f,g;if(c&&c.flat?e.parent=b.parent:e.children=[],c&&c.no_state)delete e.state;else for(f in b.state)b.state.hasOwnProperty(f)&&(e.state[f]=b.state[f]);if(c&&c.no_li_attr&&delete e.li_attr,c&&c.no_a_attr&&delete e.a_attr,c&&c.no_id&&(delete e.id,e.li_attr&&e.li_attr.id&&delete e.li_attr.id,e.a_attr&&e.a_attr.id&&delete e.a_attr.id),c&&c.flat&&b.id!==a.jstree.root&&d.push(e),!c||!c.no_children)for(f=0,g=b.children.length;g>f;f++)c&&c.flat?this.get_json(b.children[f],c,d):e.children.push(this.get_json(b.children[f],c));return c&&c.flat?d:b.id===a.jstree.root?e.children:e},create_node:function(c,d,e,f,g){if(null===c&&(c=a.jstree.root),c=this.get_node(c),!c)return!1;if(e=e===b?"last":e,!e.toString().match(/^(before|after)$/)&&!g&&!this.is_loaded(c))return this.load_node(c,function(){this.create_node(c,d,e,f,!0)});d||(d={text:this.get_string("New node")}),d="string"==typeof d?{text:d}:a.extend(!0,{},d),d.text===b&&(d.text=this.get_string("New node"));var h,i,j,k;switch(c.id===a.jstree.root&&("before"===e&&(e="first"),"after"===e&&(e="last")),e){case"before":h=this.get_node(c.parent),e=a.inArray(c.id,h.children),c=h;break;case"after":h=this.get_node(c.parent),e=a.inArray(c.id,h.children)+1,c=h;break;case"inside":case"first":e=0;break;case"last":e=c.children.length;break;default:e||(e=0)}if(e>c.children.length&&(e=c.children.length),d.id||(d.id=!0),!this.check("create_node",d,c,e))return this.settings.core.error.call(this,this._data.core.last_error),!1;if(d.id===!0&&delete d.id,d=this._parse_model_from_json(d,c.id,c.parents.concat()),!d)return!1;for(h=this.get_node(d),i=[],i.push(d),i=i.concat(h.children_d),this.trigger("model",{nodes:i,parent:c.id}),c.children_d=c.children_d.concat(i),j=0,k=c.parents.length;k>j;j++)this._model.data[c.parents[j]].children_d=this._model.data[c.parents[j]].children_d.concat(i);for(d=h,h=[],j=0,k=c.children.length;k>j;j++)h[j>=e?j+1:j]=c.children[j];return h[e]=d.id,c.children=h,this.redraw_node(c,!0),this.trigger("create_node",{node:this.get_node(d),parent:c.id,position:e}),f&&f.call(this,this.get_node(d)),d.id},rename_node:function(b,c){var d,e,f;if(a.isArray(b)){for(b=b.slice(),d=0,e=b.length;e>d;d++)this.rename_node(b[d],c);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(f=b.text,this.check("rename_node",b,this.get_parent(b),c)?(this.set_text(b,c),this.trigger("rename_node",{node:b,text:c,old:f}),!0):(this.settings.core.error.call(this,this._data.core.last_error),!1)):!1},delete_node:function(b){var c,d,e,f,g,h,i,j,k,l,m,n;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.delete_node(b[c]);return!0}if(b=this.get_node(b),!b||b.id===a.jstree.root)return!1;if(e=this.get_node(b.parent),f=a.inArray(b.id,e.children),l=!1,!this.check("delete_node",b,e,f))return this.settings.core.error.call(this,this._data.core.last_error),!1;for(-1!==f&&(e.children=a.vakata.array_remove(e.children,f)),g=b.children_d.concat([]),g.push(b.id),h=0,i=b.parents.length;i>h;h++)this._model.data[b.parents[h]].children_d=a.vakata.array_filter(this._model.data[b.parents[h]].children_d,function(b){return-1===a.inArray(b,g)});for(j=0,k=g.length;k>j;j++)if(this._model.data[g[j]].state.selected){l=!0;break}for(l&&(this._data.core.selected=a.vakata.array_filter(this._data.core.selected,function(b){return-1===a.inArray(b,g)})),this.trigger("delete_node",{node:b,parent:e.id}),l&&this.trigger("changed",{action:"delete_node",node:b,selected:this._data.core.selected,parent:e.id}),j=0,k=g.length;k>j;j++)delete this._model.data[g[j]];return-1!==a.inArray(this._data.core.focused,g)&&(this._data.core.focused=null,m=this.element[0].scrollTop,n=this.element[0].scrollLeft,e.id===a.jstree.root?this._model.data[a.jstree.root].children[0]&&this.get_node(this._model.data[a.jstree.root].children[0],!0).children(".jstree-anchor").focus():this.get_node(e,!0).children(".jstree-anchor").focus(),this.element[0].scrollTop=m,this.element[0].scrollLeft=n),this.redraw_node(e,!0),!0},check:function(b,c,d,e,f){c=c&&c.id?c:this.get_node(c),d=d&&d.id?d:this.get_node(d);var g=b.match(/^move_node|copy_node|create_node$/i)?d:c,h=this.settings.core.check_callback;return"move_node"!==b&&"copy_node"!==b||f&&f.is_multi||c.id!==d.id&&("move_node"!==b||a.inArray(c.id,d.children)!==e)&&-1===a.inArray(d.id,c.children_d)?(g&&g.data&&(g=g.data),g&&g.functions&&(g.functions[b]===!1||g.functions[b]===!0)?(g.functions[b]===!1&&(this._data.core.last_error={error:"check",plugin:"core",id:"core_02",reason:"Node data prevents function: "+b,data:JSON.stringify({chk:b,pos:e,obj:c&&c.id?c.id:!1,par:d&&d.id?d.id:!1})}),g.functions[b]):h===!1||a.isFunction(h)&&h.call(this,b,c,d,e,f)===!1||h&&h[b]===!1?(this._data.core.last_error={error:"check",plugin:"core",id:"core_03",reason:"User config for core.check_callback prevents function: "+b,data:JSON.stringify({chk:b,pos:e,obj:c&&c.id?c.id:!1,par:d&&d.id?d.id:!1})},!1):!0):(this._data.core.last_error={error:"check",plugin:"core",id:"core_01",reason:"Moving parent inside child",data:JSON.stringify({chk:b,pos:e,obj:c&&c.id?c.id:!1,par:d&&d.id?d.id:!1})},!1)},last_error:function(){return this._data.core.last_error},move_node:function(c,d,e,f,g,h,i){var j,k,l,m,n,o,p,q,r,s,t,u,v,w;if(d=this.get_node(d),e=e===b?0:e,!d)return!1;if(!e.toString().match(/^(before|after)$/)&&!g&&!this.is_loaded(d))return this.load_node(d,function(){this.move_node(c,d,e,f,!0,!1,i)});if(a.isArray(c)){if(1!==c.length){for(j=0,k=c.length;k>j;j++)(r=this.move_node(c[j],d,e,f,g,!1,i))&&(d=r,e="after");return this.redraw(),!0}c=c[0]}if(c=c&&c.id?c:this.get_node(c),!c||c.id===a.jstree.root)return!1;if(l=(c.parent||a.jstree.root).toString(),n=e.toString().match(/^(before|after)$/)&&d.id!==a.jstree.root?this.get_node(d.parent):d,o=i?i:this._model.data[c.id]?this:a.jstree.reference(c.id),p=!o||!o._id||this._id!==o._id,m=o&&o._id&&l&&o._model.data[l]&&o._model.data[l].children?a.inArray(c.id,o._model.data[l].children):-1,o&&o._id&&(c=o._model.data[c.id]),p)return(r=this.copy_node(c,d,e,f,g,!1,i))?(o&&o.delete_node(c),r):!1;switch(d.id===a.jstree.root&&("before"===e&&(e="first"),"after"===e&&(e="last")),e){case"before":e=a.inArray(d.id,n.children);break;case"after":e=a.inArray(d.id,n.children)+1;break;case"inside":case"first":e=0;break;case"last":e=n.children.length;break;default:e||(e=0)}if(e>n.children.length&&(e=n.children.length),!this.check("move_node",c,n,e,{core:!0,origin:i,is_multi:o&&o._id&&o._id!==this._id,is_foreign:!o||!o._id}))return this.settings.core.error.call(this,this._data.core.last_error),!1;if(c.parent===n.id){for(q=n.children.concat(),r=a.inArray(c.id,q),-1!==r&&(q=a.vakata.array_remove(q,r),e>r&&e--),r=[],s=0,t=q.length;t>s;s++)r[s>=e?s+1:s]=q[s];r[e]=c.id,n.children=r,this._node_changed(n.id),this.redraw(n.id===a.jstree.root)}else{for(r=c.children_d.concat(),r.push(c.id),s=0,t=c.parents.length;t>s;s++){for(q=[],w=o._model.data[c.parents[s]].children_d,u=0,v=w.length;v>u;u++)-1===a.inArray(w[u],r)&&q.push(w[u]);o._model.data[c.parents[s]].children_d=q}for(o._model.data[l].children=a.vakata.array_remove_item(o._model.data[l].children,c.id),s=0,t=n.parents.length;t>s;s++)this._model.data[n.parents[s]].children_d=this._model.data[n.parents[s]].children_d.concat(r);for(q=[],s=0,t=n.children.length;t>s;s++)q[s>=e?s+1:s]=n.children[s];for(q[e]=c.id,n.children=q,n.children_d.push(c.id),n.children_d=n.children_d.concat(c.children_d),c.parent=n.id,r=n.parents.concat(),r.unshift(n.id),w=c.parents.length,c.parents=r,r=r.concat(),s=0,t=c.children_d.length;t>s;s++)this._model.data[c.children_d[s]].parents=this._model.data[c.children_d[s]].parents.slice(0,-1*w),Array.prototype.push.apply(this._model.data[c.children_d[s]].parents,r);(l===a.jstree.root||n.id===a.jstree.root)&&(this._model.force_full_redraw=!0),this._model.force_full_redraw||(this._node_changed(l),this._node_changed(n.id)),h||this.redraw()}return f&&f.call(this,c,n,e),this.trigger("move_node",{node:c,parent:n.id,position:e,old_parent:l,old_position:m,is_multi:o&&o._id&&o._id!==this._id,is_foreign:!o||!o._id,old_instance:o,new_instance:this}),c.id},copy_node:function(c,d,e,f,g,h,i){var j,k,l,m,n,o,p,q,r,s,t;if(d=this.get_node(d),e=e===b?0:e,!d)return!1;if(!e.toString().match(/^(before|after)$/)&&!g&&!this.is_loaded(d))return this.load_node(d,function(){this.copy_node(c,d,e,f,!0,!1,i)});if(a.isArray(c)){if(1!==c.length){for(j=0,k=c.length;k>j;j++)(m=this.copy_node(c[j],d,e,f,g,!0,i))&&(d=m,e="after");return this.redraw(),!0}c=c[0]}if(c=c&&c.id?c:this.get_node(c),!c||c.id===a.jstree.root)return!1;switch(q=(c.parent||a.jstree.root).toString(),r=e.toString().match(/^(before|after)$/)&&d.id!==a.jstree.root?this.get_node(d.parent):d,s=i?i:this._model.data[c.id]?this:a.jstree.reference(c.id),t=!s||!s._id||this._id!==s._id,s&&s._id&&(c=s._model.data[c.id]),d.id===a.jstree.root&&("before"===e&&(e="first"),"after"===e&&(e="last")),e){case"before":e=a.inArray(d.id,r.children);break;case"after":e=a.inArray(d.id,r.children)+1;break;case"inside":case"first":e=0;break;case"last":e=r.children.length;break;default:e||(e=0)}if(e>r.children.length&&(e=r.children.length),!this.check("copy_node",c,r,e,{core:!0,origin:i,is_multi:s&&s._id&&s._id!==this._id,is_foreign:!s||!s._id}))return this.settings.core.error.call(this,this._data.core.last_error),!1;if(p=s?s.get_json(c,{no_id:!0,no_data:!0,no_state:!0}):c,!p)return!1;if(p.id===!0&&delete p.id,p=this._parse_model_from_json(p,r.id,r.parents.concat()),!p)return!1;for(m=this.get_node(p),c&&c.state&&c.state.loaded===!1&&(m.state.loaded=!1),l=[],l.push(p),l=l.concat(m.children_d),this.trigger("model",{nodes:l,parent:r.id}),n=0,o=r.parents.length;o>n;n++)this._model.data[r.parents[n]].children_d=this._model.data[r.parents[n]].children_d.concat(l);for(l=[],n=0,o=r.children.length;o>n;n++)l[n>=e?n+1:n]=r.children[n];return l[e]=m.id,r.children=l,r.children_d.push(m.id),r.children_d=r.children_d.concat(m.children_d),r.id===a.jstree.root&&(this._model.force_full_redraw=!0),this._model.force_full_redraw||this._node_changed(r.id),h||this.redraw(r.id===a.jstree.root),f&&f.call(this,m,r,e),this.trigger("copy_node",{node:m,original:c,parent:r.id,position:e,old_parent:q,old_position:s&&s._id&&q&&s._model.data[q]&&s._model.data[q].children?a.inArray(c.id,s._model.data[q].children):-1,is_multi:s&&s._id&&s._id!==this._id,is_foreign:!s||!s._id,old_instance:s,new_instance:this}),m.id},cut:function(b){if(b||(b=this._data.core.selected.concat()),a.isArray(b)||(b=[b]),!b.length)return!1;var c=[],g,h,i;for(h=0,i=b.length;i>h;h++)g=this.get_node(b[h]),g&&g.id&&g.id!==a.jstree.root&&c.push(g);return c.length?(d=c,f=this,e="move_node",void this.trigger("cut",{
4
- node:b})):!1},copy:function(b){if(b||(b=this._data.core.selected.concat()),a.isArray(b)||(b=[b]),!b.length)return!1;var c=[],g,h,i;for(h=0,i=b.length;i>h;h++)g=this.get_node(b[h]),g&&g.id&&g.id!==a.jstree.root&&c.push(g);return c.length?(d=c,f=this,e="copy_node",void this.trigger("copy",{node:b})):!1},get_buffer:function(){return{mode:e,node:d,inst:f}},can_paste:function(){return e!==!1&&d!==!1},paste:function(a,b){return a=this.get_node(a),a&&e&&e.match(/^(copy_node|move_node)$/)&&d?(this[e](d,a,b,!1,!1,!1,f)&&this.trigger("paste",{parent:a.id,node:d,mode:e}),d=!1,e=!1,void(f=!1)):!1},clear_buffer:function(){d=!1,e=!1,f=!1,this.trigger("clear_buffer")},edit:function(b,c,d){var e,f,g,h,j,k,l,m,n,o=!1;return(b=this.get_node(b))?this.check("edit",b,this.get_parent(b))?(n=b,c="string"==typeof c?c:b.text,this.set_text(b,""),b=this._open_to(b),n.text=c,e=this._data.core.rtl,f=this.element.width(),this._data.core.focused=n.id,g=b.children(".jstree-anchor").focus(),h=a("<span>"),j=c,k=a("<div />",{css:{position:"absolute",top:"-200px",left:e?"0px":"-1000px",visibility:"hidden"}}).appendTo("body"),l=a("<input />",{value:j,"class":"jstree-rename-input",css:{padding:"0",border:"1px solid silver","box-sizing":"border-box",display:"inline-block",height:this._data.core.li_height+"px",lineHeight:this._data.core.li_height+"px",width:"150px"},blur:a.proxy(function(c){c.stopImmediatePropagation(),c.preventDefault();var e=h.children(".jstree-rename-input"),f=e.val(),i=this.settings.core.force_text,m;""===f&&(f=j),k.remove(),h.replaceWith(g),h.remove(),j=i?j:a("<div></div>").append(a.parseHTML(j)).html(),this.set_text(b,j),m=!!this.rename_node(b,i?a("<div></div>").text(f).text():a("<div></div>").append(a.parseHTML(f)).html()),m||this.set_text(b,j),this._data.core.focused=n.id,setTimeout(a.proxy(function(){var a=this.get_node(n.id,!0);a.length&&(this._data.core.focused=n.id,a.children(".jstree-anchor").focus())},this),0),d&&d.call(this,n,m,o),l=null},this),keydown:function(a){var b=a.which;27===b&&(o=!0,this.value=j),(27===b||13===b||37===b||38===b||39===b||40===b||32===b)&&a.stopImmediatePropagation(),(27===b||13===b)&&(a.preventDefault(),this.blur())},click:function(a){a.stopImmediatePropagation()},mousedown:function(a){a.stopImmediatePropagation()},keyup:function(a){l.width(Math.min(k.text("pW"+this.value).width(),f))},keypress:function(a){return 13===a.which?!1:void 0}}),m={fontFamily:g.css("fontFamily")||"",fontSize:g.css("fontSize")||"",fontWeight:g.css("fontWeight")||"",fontStyle:g.css("fontStyle")||"",fontStretch:g.css("fontStretch")||"",fontVariant:g.css("fontVariant")||"",letterSpacing:g.css("letterSpacing")||"",wordSpacing:g.css("wordSpacing")||""},h.attr("class",g.attr("class")).append(g.contents().clone()).append(l),g.replaceWith(h),k.css(m),l.css(m).width(Math.min(k.text("pW"+l[0].value).width(),f))[0].select(),void a(i).one("mousedown.jstree touchstart.jstree dnd_start.vakata",function(b){l&&b.target!==l&&a(l).blur()})):(this.settings.core.error.call(this,this._data.core.last_error),!1):!1},set_theme:function(b,c){if(!b)return!1;if(c===!0){var d=this.settings.core.themes.dir;d||(d=a.jstree.path+"/themes"),c=d+"/"+b+"/style.css"}c&&-1===a.inArray(c,g)&&(a("head").append('<link rel="stylesheet" href="'+c+'" type="text/css" />'),g.push(c)),this._data.core.themes.name&&this.element.removeClass("jstree-"+this._data.core.themes.name),this._data.core.themes.name=b,this.element.addClass("jstree-"+b),this.element[this.settings.core.themes.responsive?"addClass":"removeClass"]("jstree-"+b+"-responsive"),this.trigger("set_theme",{theme:b})},get_theme:function(){return this._data.core.themes.name},set_theme_variant:function(a){this._data.core.themes.variant&&this.element.removeClass("jstree-"+this._data.core.themes.name+"-"+this._data.core.themes.variant),this._data.core.themes.variant=a,a&&this.element.addClass("jstree-"+this._data.core.themes.name+"-"+this._data.core.themes.variant)},get_theme_variant:function(){return this._data.core.themes.variant},show_stripes:function(){this._data.core.themes.stripes=!0,this.get_container_ul().addClass("jstree-striped"),this.trigger("show_stripes")},hide_stripes:function(){this._data.core.themes.stripes=!1,this.get_container_ul().removeClass("jstree-striped"),this.trigger("hide_stripes")},toggle_stripes:function(){this._data.core.themes.stripes?this.hide_stripes():this.show_stripes()},show_dots:function(){this._data.core.themes.dots=!0,this.get_container_ul().removeClass("jstree-no-dots"),this.trigger("show_dots")},hide_dots:function(){this._data.core.themes.dots=!1,this.get_container_ul().addClass("jstree-no-dots"),this.trigger("hide_dots")},toggle_dots:function(){this._data.core.themes.dots?this.hide_dots():this.show_dots()},show_icons:function(){this._data.core.themes.icons=!0,this.get_container_ul().removeClass("jstree-no-icons"),this.trigger("show_icons")},hide_icons:function(){this._data.core.themes.icons=!1,this.get_container_ul().addClass("jstree-no-icons"),this.trigger("hide_icons")},toggle_icons:function(){this._data.core.themes.icons?this.hide_icons():this.show_icons()},show_ellipsis:function(){this._data.core.themes.ellipsis=!0,this.get_container_ul().addClass("jstree-ellipsis"),this.trigger("show_ellipsis")},hide_ellipsis:function(){this._data.core.themes.ellipsis=!1,this.get_container_ul().removeClass("jstree-ellipsis"),this.trigger("hide_ellipsis")},toggle_ellipsis:function(){this._data.core.themes.ellipsis?this.hide_ellipsis():this.show_ellipsis()},set_icon:function(c,d){var e,f,g,h;if(a.isArray(c)){for(c=c.slice(),e=0,f=c.length;f>e;e++)this.set_icon(c[e],d);return!0}return c=this.get_node(c),c&&c.id!==a.jstree.root?(h=c.icon,c.icon=d===!0||null===d||d===b||""===d?!0:d,g=this.get_node(c,!0).children(".jstree-anchor").children(".jstree-themeicon"),d===!1?(g.removeClass("jstree-themeicon-custom "+h).css("background","").removeAttr("rel"),this.hide_icon(c)):d===!0||null===d||d===b||""===d?(g.removeClass("jstree-themeicon-custom "+h).css("background","").removeAttr("rel"),h===!1&&this.show_icon(c)):-1===d.indexOf("/")&&-1===d.indexOf(".")?(g.removeClass(h).css("background",""),g.addClass(d+" jstree-themeicon-custom").attr("rel",d),h===!1&&this.show_icon(c)):(g.removeClass(h).css("background",""),g.addClass("jstree-themeicon-custom").css("background","url('"+d+"') center center no-repeat").attr("rel",d),h===!1&&this.show_icon(c)),!0):!1},get_icon:function(b){return b=this.get_node(b),b&&b.id!==a.jstree.root?b.icon:!1},hide_icon:function(b){var c,d;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.hide_icon(b[c]);return!0}return b=this.get_node(b),b&&b!==a.jstree.root?(b.icon=!1,this.get_node(b,!0).children(".jstree-anchor").children(".jstree-themeicon").addClass("jstree-themeicon-hidden"),!0):!1},show_icon:function(b){var c,d,e;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.show_icon(b[c]);return!0}return b=this.get_node(b),b&&b!==a.jstree.root?(e=this.get_node(b,!0),b.icon=e.length?e.children(".jstree-anchor").children(".jstree-themeicon").attr("rel"):!0,b.icon||(b.icon=!0),e.children(".jstree-anchor").children(".jstree-themeicon").removeClass("jstree-themeicon-hidden"),!0):!1}},a.vakata={},a.vakata.attributes=function(b,c){b=a(b)[0];var d=c?{}:[];return b&&b.attributes&&a.each(b.attributes,function(b,e){-1===a.inArray(e.name.toLowerCase(),["style","contenteditable","hasfocus","tabindex"])&&null!==e.value&&""!==a.trim(e.value)&&(c?d[e.name]=e.value:d.push(e.name))}),d},a.vakata.array_unique=function(a){var c=[],d,e,f,g={};for(d=0,f=a.length;f>d;d++)g[a[d]]===b&&(c.push(a[d]),g[a[d]]=!0);return c},a.vakata.array_remove=function(a,b){return a.splice(b,1),a},a.vakata.array_remove_item=function(b,c){var d=a.inArray(c,b);return-1!==d?a.vakata.array_remove(b,d):b},a.vakata.array_filter=function(a,b,c,d,e){if(a.filter)return a.filter(b,c);d=[];for(e in a)~~e+""==e+""&&e>=0&&b.call(c,a[e],+e,a)&&d.push(a[e]);return d},a.jstree.plugins.changed=function(a,b){var c=[];this.trigger=function(a,d){var e,f;if(d||(d={}),"changed"===a.replace(".jstree","")){d.changed={selected:[],deselected:[]};var g={};for(e=0,f=c.length;f>e;e++)g[c[e]]=1;for(e=0,f=d.selected.length;f>e;e++)g[d.selected[e]]?g[d.selected[e]]=2:d.changed.selected.push(d.selected[e]);for(e=0,f=c.length;f>e;e++)1===g[c[e]]&&d.changed.deselected.push(c[e]);c=d.selected.slice()}b.trigger.call(this,a,d)},this.refresh=function(a,d){return c=[],b.refresh.apply(this,arguments)}};var j=i.createElement("I");j.className="jstree-icon jstree-checkbox",j.setAttribute("role","presentation"),a.jstree.defaults.checkbox={visible:!0,three_state:!0,whole_node:!0,keep_selected_style:!0,cascade:"",tie_selection:!0,cascade_to_disabled:!0,cascade_to_hidden:!0},a.jstree.plugins.checkbox=function(c,d){this.bind=function(){d.bind.call(this),this._data.checkbox.uto=!1,this._data.checkbox.selected=[],this.settings.checkbox.three_state&&(this.settings.checkbox.cascade="up+down+undetermined"),this.element.on("init.jstree",a.proxy(function(){this._data.checkbox.visible=this.settings.checkbox.visible,this.settings.checkbox.keep_selected_style||this.element.addClass("jstree-checkbox-no-clicked"),this.settings.checkbox.tie_selection&&this.element.addClass("jstree-checkbox-selection")},this)).on("loading.jstree",a.proxy(function(){this[this._data.checkbox.visible?"show_checkboxes":"hide_checkboxes"]()},this)),-1!==this.settings.checkbox.cascade.indexOf("undetermined")&&this.element.on("changed.jstree uncheck_node.jstree check_node.jstree uncheck_all.jstree check_all.jstree move_node.jstree copy_node.jstree redraw.jstree open_node.jstree",a.proxy(function(){this._data.checkbox.uto&&clearTimeout(this._data.checkbox.uto),this._data.checkbox.uto=setTimeout(a.proxy(this._undetermined,this),50)},this)),this.settings.checkbox.tie_selection||this.element.on("model.jstree",a.proxy(function(a,b){var c=this._model.data,d=c[b.parent],e=b.nodes,f,g;for(f=0,g=e.length;g>f;f++)c[e[f]].state.checked=c[e[f]].state.checked||c[e[f]].original&&c[e[f]].original.state&&c[e[f]].original.state.checked,c[e[f]].state.checked&&this._data.checkbox.selected.push(e[f])},this)),(-1!==this.settings.checkbox.cascade.indexOf("up")||-1!==this.settings.checkbox.cascade.indexOf("down"))&&this.element.on("model.jstree",a.proxy(function(b,c){var d=this._model.data,e=d[c.parent],f=c.nodes,g=[],h,i,j,k,l,m,n=this.settings.checkbox.cascade,o=this.settings.checkbox.tie_selection;if(-1!==n.indexOf("down"))if(e.state[o?"selected":"checked"]){for(i=0,j=f.length;j>i;i++)d[f[i]].state[o?"selected":"checked"]=!0;this._data[o?"core":"checkbox"].selected=this._data[o?"core":"checkbox"].selected.concat(f)}else for(i=0,j=f.length;j>i;i++)if(d[f[i]].state[o?"selected":"checked"]){for(k=0,l=d[f[i]].children_d.length;l>k;k++)d[d[f[i]].children_d[k]].state[o?"selected":"checked"]=!0;this._data[o?"core":"checkbox"].selected=this._data[o?"core":"checkbox"].selected.concat(d[f[i]].children_d)}if(-1!==n.indexOf("up")){for(i=0,j=e.children_d.length;j>i;i++)d[e.children_d[i]].children.length||g.push(d[e.children_d[i]].parent);for(g=a.vakata.array_unique(g),k=0,l=g.length;l>k;k++){e=d[g[k]];while(e&&e.id!==a.jstree.root){for(h=0,i=0,j=e.children.length;j>i;i++)h+=d[e.children[i]].state[o?"selected":"checked"];if(h!==j)break;e.state[o?"selected":"checked"]=!0,this._data[o?"core":"checkbox"].selected.push(e.id),m=this.get_node(e,!0),m&&m.length&&m.attr("aria-selected",!0).children(".jstree-anchor").addClass(o?"jstree-clicked":"jstree-checked"),e=this.get_node(e.parent)}}}this._data[o?"core":"checkbox"].selected=a.vakata.array_unique(this._data[o?"core":"checkbox"].selected)},this)).on(this.settings.checkbox.tie_selection?"select_node.jstree":"check_node.jstree",a.proxy(function(b,c){var d=this,e=c.node,f=this._model.data,g=this.get_node(e.parent),h,i,j,k,l=this.settings.checkbox.cascade,m=this.settings.checkbox.tie_selection,n={},o=this._data[m?"core":"checkbox"].selected;for(h=0,i=o.length;i>h;h++)n[o[h]]=!0;if(-1!==l.indexOf("down")){var p=this._cascade_new_checked_state(e.id,!0),q=e.children_d.concat(e.id);for(h=0,i=q.length;i>h;h++)p.indexOf(q[h])>-1?n[q[h]]=!0:delete n[q[h]]}if(-1!==l.indexOf("up"))while(g&&g.id!==a.jstree.root){for(j=0,h=0,i=g.children.length;i>h;h++)j+=f[g.children[h]].state[m?"selected":"checked"];if(j!==i)break;g.state[m?"selected":"checked"]=!0,n[g.id]=!0,k=this.get_node(g,!0),k&&k.length&&k.attr("aria-selected",!0).children(".jstree-anchor").addClass(m?"jstree-clicked":"jstree-checked"),g=this.get_node(g.parent)}o=[];for(h in n)n.hasOwnProperty(h)&&o.push(h);this._data[m?"core":"checkbox"].selected=o},this)).on(this.settings.checkbox.tie_selection?"deselect_all.jstree":"uncheck_all.jstree",a.proxy(function(b,c){var d=this.get_node(a.jstree.root),e=this._model.data,f,g,h;for(f=0,g=d.children_d.length;g>f;f++)h=e[d.children_d[f]],h&&h.original&&h.original.state&&h.original.state.undetermined&&(h.original.state.undetermined=!1)},this)).on(this.settings.checkbox.tie_selection?"deselect_node.jstree":"uncheck_node.jstree",a.proxy(function(a,b){var c=this,d=b.node,e=this.get_node(d,!0),f,g,h,i=this.settings.checkbox.cascade,j=this.settings.checkbox.tie_selection,k=this._data[j?"core":"checkbox"].selected,l={},m=[],n=d.children_d.concat(d.id);if(-1!==i.indexOf("down")){var o=this._cascade_new_checked_state(d.id,!1);k=k.filter(function(a){return-1===n.indexOf(a)||o.indexOf(a)>-1})}if(-1!==i.indexOf("up")&&-1===k.indexOf(d.id)){for(f=0,g=d.parents.length;g>f;f++)h=this._model.data[d.parents[f]],h.state[j?"selected":"checked"]=!1,h&&h.original&&h.original.state&&h.original.state.undetermined&&(h.original.state.undetermined=!1),h=this.get_node(d.parents[f],!0),h&&h.length&&h.attr("aria-selected",!1).children(".jstree-anchor").removeClass(j?"jstree-clicked":"jstree-checked");k=k.filter(function(a){return-1===d.parents.indexOf(a)})}this._data[j?"core":"checkbox"].selected=k},this)),-1!==this.settings.checkbox.cascade.indexOf("up")&&this.element.on("delete_node.jstree",a.proxy(function(b,c){var d=this.get_node(c.parent),e=this._model.data,f,g,h,i,j=this.settings.checkbox.tie_selection;while(d&&d.id!==a.jstree.root&&!d.state[j?"selected":"checked"]){for(h=0,f=0,g=d.children.length;g>f;f++)h+=e[d.children[f]].state[j?"selected":"checked"];if(!(g>0&&h===g))break;d.state[j?"selected":"checked"]=!0,this._data[j?"core":"checkbox"].selected.push(d.id),i=this.get_node(d,!0),i&&i.length&&i.attr("aria-selected",!0).children(".jstree-anchor").addClass(j?"jstree-clicked":"jstree-checked"),d=this.get_node(d.parent)}},this)).on("move_node.jstree",a.proxy(function(b,c){var d=c.is_multi,e=c.old_parent,f=this.get_node(c.parent),g=this._model.data,h,i,j,k,l,m=this.settings.checkbox.tie_selection;if(!d){h=this.get_node(e);while(h&&h.id!==a.jstree.root&&!h.state[m?"selected":"checked"]){for(i=0,j=0,k=h.children.length;k>j;j++)i+=g[h.children[j]].state[m?"selected":"checked"];if(!(k>0&&i===k))break;h.state[m?"selected":"checked"]=!0,this._data[m?"core":"checkbox"].selected.push(h.id),l=this.get_node(h,!0),l&&l.length&&l.attr("aria-selected",!0).children(".jstree-anchor").addClass(m?"jstree-clicked":"jstree-checked"),h=this.get_node(h.parent)}}h=f;while(h&&h.id!==a.jstree.root){for(i=0,j=0,k=h.children.length;k>j;j++)i+=g[h.children[j]].state[m?"selected":"checked"];if(i===k)h.state[m?"selected":"checked"]||(h.state[m?"selected":"checked"]=!0,this._data[m?"core":"checkbox"].selected.push(h.id),l=this.get_node(h,!0),l&&l.length&&l.attr("aria-selected",!0).children(".jstree-anchor").addClass(m?"jstree-clicked":"jstree-checked"));else{if(!h.state[m?"selected":"checked"])break;h.state[m?"selected":"checked"]=!1,this._data[m?"core":"checkbox"].selected=a.vakata.array_remove_item(this._data[m?"core":"checkbox"].selected,h.id),l=this.get_node(h,!0),l&&l.length&&l.attr("aria-selected",!1).children(".jstree-anchor").removeClass(m?"jstree-clicked":"jstree-checked")}h=this.get_node(h.parent)}},this))},this.get_undetermined=function(c){if(-1===this.settings.checkbox.cascade.indexOf("undetermined"))return[];var d,e,f,g,h={},i=this._model.data,j=this.settings.checkbox.tie_selection,k=this._data[j?"core":"checkbox"].selected,l=[],m=this,n=[];for(d=0,e=k.length;e>d;d++)if(i[k[d]]&&i[k[d]].parents)for(f=0,g=i[k[d]].parents.length;g>f;f++){if(h[i[k[d]].parents[f]]!==b)break;i[k[d]].parents[f]!==a.jstree.root&&(h[i[k[d]].parents[f]]=!0,l.push(i[k[d]].parents[f]))}for(this.element.find(".jstree-closed").not(":has(.jstree-children)").each(function(){var c=m.get_node(this),j;if(c)if(c.state.loaded){for(d=0,e=c.children_d.length;e>d;d++)if(j=i[c.children_d[d]],!j.state.loaded&&j.original&&j.original.state&&j.original.state.undetermined&&j.original.state.undetermined===!0)for(h[j.id]===b&&j.id!==a.jstree.root&&(h[j.id]=!0,l.push(j.id)),f=0,g=j.parents.length;g>f;f++)h[j.parents[f]]===b&&j.parents[f]!==a.jstree.root&&(h[j.parents[f]]=!0,l.push(j.parents[f]))}else if(c.original&&c.original.state&&c.original.state.undetermined&&c.original.state.undetermined===!0)for(h[c.id]===b&&c.id!==a.jstree.root&&(h[c.id]=!0,l.push(c.id)),f=0,g=c.parents.length;g>f;f++)h[c.parents[f]]===b&&c.parents[f]!==a.jstree.root&&(h[c.parents[f]]=!0,l.push(c.parents[f]))}),d=0,e=l.length;e>d;d++)i[l[d]].state[j?"selected":"checked"]||n.push(c?i[l[d]]:l[d]);return n},this._undetermined=function(){if(null!==this.element){var a=this.get_undetermined(!1),b,c,d;for(this.element.find(".jstree-undetermined").removeClass("jstree-undetermined"),b=0,c=a.length;c>b;b++)d=this.get_node(a[b],!0),d&&d.length&&d.children(".jstree-anchor").children(".jstree-checkbox").addClass("jstree-undetermined")}},this.redraw_node=function(b,c,e,f){if(b=d.redraw_node.apply(this,arguments)){var g,h,i=null,k=null;for(g=0,h=b.childNodes.length;h>g;g++)if(b.childNodes[g]&&b.childNodes[g].className&&-1!==b.childNodes[g].className.indexOf("jstree-anchor")){i=b.childNodes[g];break}i&&(!this.settings.checkbox.tie_selection&&this._model.data[b.id].state.checked&&(i.className+=" jstree-checked"),k=j.cloneNode(!1),this._model.data[b.id].state.checkbox_disabled&&(k.className+=" jstree-checkbox-disabled"),i.insertBefore(k,i.childNodes[0]))}return e||-1===this.settings.checkbox.cascade.indexOf("undetermined")||(this._data.checkbox.uto&&clearTimeout(this._data.checkbox.uto),this._data.checkbox.uto=setTimeout(a.proxy(this._undetermined,this),50)),b},this.show_checkboxes=function(){this._data.core.themes.checkboxes=!0,this.get_container_ul().removeClass("jstree-no-checkboxes")},this.hide_checkboxes=function(){this._data.core.themes.checkboxes=!1,this.get_container_ul().addClass("jstree-no-checkboxes")},this.toggle_checkboxes=function(){this._data.core.themes.checkboxes?this.hide_checkboxes():this.show_checkboxes()},this.is_undetermined=function(b){b=this.get_node(b);var c=this.settings.checkbox.cascade,d,e,f=this.settings.checkbox.tie_selection,g=this._data[f?"core":"checkbox"].selected,h=this._model.data;if(!b||b.state[f?"selected":"checked"]===!0||-1===c.indexOf("undetermined")||-1===c.indexOf("down")&&-1===c.indexOf("up"))return!1;if(!b.state.loaded&&b.original.state.undetermined===!0)return!0;for(d=0,e=b.children_d.length;e>d;d++)if(-1!==a.inArray(b.children_d[d],g)||!h[b.children_d[d]].state.loaded&&h[b.children_d[d]].original.state.undetermined)return!0;return!1},this.disable_checkbox=function(b){var c,d,e;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.disable_checkbox(b[c]);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(e=this.get_node(b,!0),void(b.state.checkbox_disabled||(b.state.checkbox_disabled=!0,e&&e.length&&e.children(".jstree-anchor").children(".jstree-checkbox").addClass("jstree-checkbox-disabled"),this.trigger("disable_checkbox",{node:b})))):!1},this.enable_checkbox=function(b){var c,d,e;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.enable_checkbox(b[c]);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(e=this.get_node(b,!0),void(b.state.checkbox_disabled&&(b.state.checkbox_disabled=!1,e&&e.length&&e.children(".jstree-anchor").children(".jstree-checkbox").removeClass("jstree-checkbox-disabled"),this.trigger("enable_checkbox",{node:b})))):!1},this.activate_node=function(b,c){return a(c.target).hasClass("jstree-checkbox-disabled")?!1:(this.settings.checkbox.tie_selection&&(this.settings.checkbox.whole_node||a(c.target).hasClass("jstree-checkbox"))&&(c.ctrlKey=!0),this.settings.checkbox.tie_selection||!this.settings.checkbox.whole_node&&!a(c.target).hasClass("jstree-checkbox")?d.activate_node.call(this,b,c):this.is_disabled(b)?!1:(this.is_checked(b)?this.uncheck_node(b,c):this.check_node(b,c),void this.trigger("activate_node",{node:this.get_node(b)})))},this._cascade_new_checked_state=function(a,b){var c=this,d=this.settings.checkbox.tie_selection,e=this._model.data[a],f=[],g=[],h,i,j;if(!this.settings.checkbox.cascade_to_disabled&&e.state.disabled||!this.settings.checkbox.cascade_to_hidden&&e.state.hidden)j=this.get_checked_descendants(a),e.state[d?"selected":"checked"]&&j.push(e.id),f=f.concat(j);else{if(e.children)for(h=0,i=e.children.length;i>h;h++){var k=e.children[h];j=c._cascade_new_checked_state(k,b),f=f.concat(j),j.indexOf(k)>-1&&g.push(k)}var l=c.get_node(e,!0),m=g.length>0&&g.length<e.children.length;e.original&&e.original.state&&e.original.state.undetermined&&(e.original.state.undetermined=m),m?(e.state[d?"selected":"checked"]=!1,l.attr("aria-selected",!1).children(".jstree-anchor").removeClass(d?"jstree-clicked":"jstree-checked")):b&&g.length===e.children.length?(e.state[d?"selected":"checked"]=b,f.push(e.id),l.attr("aria-selected",!0).children(".jstree-anchor").addClass(d?"jstree-clicked":"jstree-checked")):(e.state[d?"selected":"checked"]=!1,l.attr("aria-selected",!1).children(".jstree-anchor").removeClass(d?"jstree-clicked":"jstree-checked"))}return f},this.get_checked_descendants=function(a){var b=this,c=b.settings.checkbox.tie_selection,d=b._model.data[a];return d.children_d.filter(function(a){return b._model.data[a].state[c?"selected":"checked"]})},this.check_node=function(b,c){if(this.settings.checkbox.tie_selection)return this.select_node(b,!1,!0,c);var d,e,f,g;if(a.isArray(b)){for(b=b.slice(),e=0,f=b.length;f>e;e++)this.check_node(b[e],c);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(d=this.get_node(b,!0),void(b.state.checked||(b.state.checked=!0,this._data.checkbox.selected.push(b.id),d&&d.length&&d.children(".jstree-anchor").addClass("jstree-checked"),this.trigger("check_node",{node:b,selected:this._data.checkbox.selected,event:c})))):!1},this.uncheck_node=function(b,c){if(this.settings.checkbox.tie_selection)return this.deselect_node(b,!1,c);var d,e,f;if(a.isArray(b)){for(b=b.slice(),d=0,e=b.length;e>d;d++)this.uncheck_node(b[d],c);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(f=this.get_node(b,!0),void(b.state.checked&&(b.state.checked=!1,this._data.checkbox.selected=a.vakata.array_remove_item(this._data.checkbox.selected,b.id),f.length&&f.children(".jstree-anchor").removeClass("jstree-checked"),this.trigger("uncheck_node",{node:b,selected:this._data.checkbox.selected,event:c})))):!1},this.check_all=function(){if(this.settings.checkbox.tie_selection)return this.select_all();var b=this._data.checkbox.selected.concat([]),c,d;for(this._data.checkbox.selected=this._model.data[a.jstree.root].children_d.concat(),c=0,d=this._data.checkbox.selected.length;d>c;c++)this._model.data[this._data.checkbox.selected[c]]&&(this._model.data[this._data.checkbox.selected[c]].state.checked=!0);this.redraw(!0),this.trigger("check_all",{selected:this._data.checkbox.selected})},this.uncheck_all=function(){if(this.settings.checkbox.tie_selection)return this.deselect_all();var a=this._data.checkbox.selected.concat([]),b,c;for(b=0,c=this._data.checkbox.selected.length;c>b;b++)this._model.data[this._data.checkbox.selected[b]]&&(this._model.data[this._data.checkbox.selected[b]].state.checked=!1);this._data.checkbox.selected=[],this.element.find(".jstree-checked").removeClass("jstree-checked"),this.trigger("uncheck_all",{selected:this._data.checkbox.selected,node:a})},this.is_checked=function(b){return this.settings.checkbox.tie_selection?this.is_selected(b):(b=this.get_node(b),b&&b.id!==a.jstree.root?b.state.checked:!1)},this.get_checked=function(b){return this.settings.checkbox.tie_selection?this.get_selected(b):b?a.map(this._data.checkbox.selected,a.proxy(function(a){return this.get_node(a)},this)):this._data.checkbox.selected},this.get_top_checked=function(b){if(this.settings.checkbox.tie_selection)return this.get_top_selected(b);var c=this.get_checked(!0),d={},e,f,g,h;for(e=0,f=c.length;f>e;e++)d[c[e].id]=c[e];for(e=0,f=c.length;f>e;e++)for(g=0,h=c[e].children_d.length;h>g;g++)d[c[e].children_d[g]]&&delete d[c[e].children_d[g]];c=[];for(e in d)d.hasOwnProperty(e)&&c.push(e);return b?a.map(c,a.proxy(function(a){return this.get_node(a)},this)):c},this.get_bottom_checked=function(b){if(this.settings.checkbox.tie_selection)return this.get_bottom_selected(b);var c=this.get_checked(!0),d=[],e,f;for(e=0,f=c.length;f>e;e++)c[e].children.length||d.push(c[e].id);return b?a.map(d,a.proxy(function(a){return this.get_node(a)},this)):d},this.load_node=function(b,c){var e,f,g,h,i,j;if(!a.isArray(b)&&!this.settings.checkbox.tie_selection&&(j=this.get_node(b),j&&j.state.loaded))for(e=0,f=j.children_d.length;f>e;e++)this._model.data[j.children_d[e]].state.checked&&(i=!0,this._data.checkbox.selected=a.vakata.array_remove_item(this._data.checkbox.selected,j.children_d[e]));return d.load_node.apply(this,arguments)},this.get_state=function(){var a=d.get_state.apply(this,arguments);return this.settings.checkbox.tie_selection?a:(a.checkbox=this._data.checkbox.selected.slice(),a)},this.set_state=function(b,c){var e=d.set_state.apply(this,arguments);if(e&&b.checkbox){if(!this.settings.checkbox.tie_selection){this.uncheck_all();var f=this;a.each(b.checkbox,function(a,b){f.check_node(b)})}return delete b.checkbox,this.set_state(b,c),!1}return e},this.refresh=function(a,b){return this.settings.checkbox.tie_selection||(this._data.checkbox.selected=[]),d.refresh.apply(this,arguments)}},a.jstree.defaults.conditionalselect=function(){return!0},a.jstree.plugins.conditionalselect=function(a,b){this.activate_node=function(a,c){return this.settings.conditionalselect.call(this,this.get_node(a),c)?b.activate_node.call(this,a,c):void 0}},a.jstree.defaults.contextmenu={select_node:!0,show_at_node:!0,items:function(b,c){return{create:{separator_before:!1,separator_after:!0,_disabled:!1,label:"Create",action:function(b){var c=a.jstree.reference(b.reference),d=c.get_node(b.reference);c.create_node(d,{},"last",function(a){try{c.edit(a)}catch(b){setTimeout(function(){c.edit(a)},0)}})}},rename:{separator_before:!1,separator_after:!1,_disabled:!1,label:"Rename",action:function(b){var c=a.jstree.reference(b.reference),d=c.get_node(b.reference);c.edit(d)}},remove:{separator_before:!1,icon:!1,separator_after:!1,_disabled:!1,label:"Delete",action:function(b){var c=a.jstree.reference(b.reference),d=c.get_node(b.reference);c.is_selected(d)?c.delete_node(c.get_selected()):c.delete_node(d)}},ccp:{separator_before:!0,icon:!1,separator_after:!1,label:"Edit",action:!1,submenu:{cut:{separator_before:!1,separator_after:!1,label:"Cut",action:function(b){var c=a.jstree.reference(b.reference),d=c.get_node(b.reference);c.is_selected(d)?c.cut(c.get_top_selected()):c.cut(d)}},copy:{separator_before:!1,icon:!1,separator_after:!1,label:"Copy",action:function(b){var c=a.jstree.reference(b.reference),d=c.get_node(b.reference);c.is_selected(d)?c.copy(c.get_top_selected()):c.copy(d)}},paste:{separator_before:!1,icon:!1,_disabled:function(b){return!a.jstree.reference(b.reference).can_paste()},separator_after:!1,label:"Paste",action:function(b){var c=a.jstree.reference(b.reference),d=c.get_node(b.reference);c.paste(d)}}}}}}},a.jstree.plugins.contextmenu=function(c,d){this.bind=function(){d.bind.call(this);var b=0,c=null,e,f;this.element.on("init.jstree loading.jstree ready.jstree",a.proxy(function(){this.get_container_ul().addClass("jstree-contextmenu")},this)).on("contextmenu.jstree",".jstree-anchor",a.proxy(function(a,d){"input"!==a.target.tagName.toLowerCase()&&(a.preventDefault(),b=a.ctrlKey?+new Date:0,(d||c)&&(b=+new Date+1e4),c&&clearTimeout(c),this.is_loading(a.currentTarget)||this.show_contextmenu(a.currentTarget,a.pageX,a.pageY,a))},this)).on("click.jstree",".jstree-anchor",a.proxy(function(c){this._data.contextmenu.visible&&(!b||+new Date-b>250)&&a.vakata.context.hide(),b=0},this)).on("touchstart.jstree",".jstree-anchor",function(b){b.originalEvent&&b.originalEvent.changedTouches&&b.originalEvent.changedTouches[0]&&(e=b.originalEvent.changedTouches[0].clientX,f=b.originalEvent.changedTouches[0].clientY,c=setTimeout(function(){a(b.currentTarget).trigger("contextmenu",!0)},750))}).on("touchmove.vakata.jstree",function(b){c&&b.originalEvent&&b.originalEvent.changedTouches&&b.originalEvent.changedTouches[0]&&(Math.abs(e-b.originalEvent.changedTouches[0].clientX)>10||Math.abs(f-b.originalEvent.changedTouches[0].clientY)>10)&&(clearTimeout(c),a.vakata.context.hide())}).on("touchend.vakata.jstree",function(a){c&&clearTimeout(c)}),a(i).on("context_hide.vakata.jstree",a.proxy(function(b,c){this._data.contextmenu.visible=!1,a(c.reference).removeClass("jstree-context")},this))},this.teardown=function(){this._data.contextmenu.visible&&a.vakata.context.hide(),d.teardown.call(this)},this.show_contextmenu=function(c,d,e,f){if(c=this.get_node(c),!c||c.id===a.jstree.root)return!1;var g=this.settings.contextmenu,h=this.get_node(c,!0),i=h.children(".jstree-anchor"),j=!1,k=!1;(g.show_at_node||d===b||e===b)&&(j=i.offset(),d=j.left,e=j.top+this._data.core.li_height),this.settings.contextmenu.select_node&&!this.is_selected(c)&&this.activate_node(c,f),k=g.items,a.isFunction(k)&&(k=k.call(this,c,a.proxy(function(a){this._show_contextmenu(c,d,e,a)},this))),a.isPlainObject(k)&&this._show_contextmenu(c,d,e,k)},this._show_contextmenu=function(b,c,d,e){var f=this.get_node(b,!0),g=f.children(".jstree-anchor");a(i).one("context_show.vakata.jstree",a.proxy(function(b,c){var d="jstree-contextmenu jstree-"+this.get_theme()+"-contextmenu";a(c.element).addClass(d),g.addClass("jstree-context")},this)),this._data.contextmenu.visible=!0,a.vakata.context.show(g,{x:c,y:d},e),this.trigger("show_contextmenu",{node:b,x:c,y:d})}},function(a){var b=!1,c={element:!1,reference:!1,position_x:0,position_y:0,items:[],html:"",is_visible:!1};a.vakata.context={settings:{hide_onmouseleave:0,icons:!0},_trigger:function(b){a(i).triggerHandler("context_"+b+".vakata",{reference:c.reference,element:c.element,position:{x:c.position_x,y:c.position_y}})},_execute:function(b){return b=c.items[b],b&&(!b._disabled||a.isFunction(b._disabled)&&!b._disabled({item:b,reference:c.reference,element:c.element}))&&b.action?b.action.call(null,{item:b,reference:c.reference,element:c.element,position:{x:c.position_x,y:c.position_y}}):!1},_parse:function(b,d){if(!b)return!1;d||(c.html="",c.items=[]);var e="",f=!1,g;return d&&(e+="<ul>"),a.each(b,function(b,d){return d?(c.items.push(d),!f&&d.separator_before&&(e+="<li class='vakata-context-separator'><a href='#' "+(a.vakata.context.settings.icons?"":'style="margin-left:0px;"')+">&#160;</a></li>"),f=!1,e+="<li class='"+(d._class||"")+(d._disabled===!0||a.isFunction(d._disabled)&&d._disabled({item:d,reference:c.reference,element:c.element})?" vakata-contextmenu-disabled ":"")+"' "+(d.shortcut?" data-shortcut='"+d.shortcut+"' ":"")+">",e+="<a href='#' rel='"+(c.items.length-1)+"' "+(d.title?"title='"+d.title+"'":"")+">",a.vakata.context.settings.icons&&(e+="<i ",d.icon&&(e+=-1!==d.icon.indexOf("/")||-1!==d.icon.indexOf(".")?" style='background:url(\""+d.icon+"\") center center no-repeat' ":" class='"+d.icon+"' "),e+="></i><span class='vakata-contextmenu-sep'>&#160;</span>"),e+=(a.isFunction(d.label)?d.label({item:b,reference:c.reference,element:c.element}):d.label)+(d.shortcut?' <span class="vakata-contextmenu-shortcut vakata-contextmenu-shortcut-'+d.shortcut+'">'+(d.shortcut_label||"")+"</span>":"")+"</a>",
5
- d.submenu&&(g=a.vakata.context._parse(d.submenu,!0),g&&(e+=g)),e+="</li>",void(d.separator_after&&(e+="<li class='vakata-context-separator'><a href='#' "+(a.vakata.context.settings.icons?"":'style="margin-left:0px;"')+">&#160;</a></li>",f=!0))):!0}),e=e.replace(/<li class\='vakata-context-separator'\><\/li\>$/,""),d&&(e+="</ul>"),d||(c.html=e,a.vakata.context._trigger("parse")),e.length>10?e:!1},_show_submenu:function(c){if(c=a(c),c.length&&c.children("ul").length){var d=c.children("ul"),e=c.offset().left,f=e+c.outerWidth(),g=c.offset().top,h=d.width(),i=d.height(),j=a(window).width()+a(window).scrollLeft(),k=a(window).height()+a(window).scrollTop();b?c[f-(h+10+c.outerWidth())<0?"addClass":"removeClass"]("vakata-context-left"):c[f+h>j&&e>j-f?"addClass":"removeClass"]("vakata-context-right"),g+i+10>k&&d.css("bottom","-1px"),c.hasClass("vakata-context-right")?h>e&&d.css("margin-right",e-h):h>j-f&&d.css("margin-left",j-f-h),d.show()}},show:function(d,e,f){var g,h,i,j,k,l,m,n,o=!0;switch(c.element&&c.element.length&&c.element.width(""),o){case!e&&!d:return!1;case!!e&&!!d:c.reference=d,c.position_x=e.x,c.position_y=e.y;break;case!e&&!!d:c.reference=d,g=d.offset(),c.position_x=g.left+d.outerHeight(),c.position_y=g.top;break;case!!e&&!d:c.position_x=e.x,c.position_y=e.y}d&&!f&&a(d).data("vakata_contextmenu")&&(f=a(d).data("vakata_contextmenu")),a.vakata.context._parse(f)&&c.element.html(c.html),c.items.length&&(c.element.appendTo("body"),h=c.element,i=c.position_x,j=c.position_y,k=h.width(),l=h.height(),m=a(window).width()+a(window).scrollLeft(),n=a(window).height()+a(window).scrollTop(),b&&(i-=h.outerWidth()-a(d).outerWidth(),i<a(window).scrollLeft()+20&&(i=a(window).scrollLeft()+20)),i+k+20>m&&(i=m-(k+20)),j+l+20>n&&(j=n-(l+20)),c.element.css({left:i,top:j}).show().find("a").first().focus().parent().addClass("vakata-context-hover"),c.is_visible=!0,a.vakata.context._trigger("show"))},hide:function(){c.is_visible&&(c.element.hide().find("ul").hide().end().find(":focus").blur().end().detach(),c.is_visible=!1,a.vakata.context._trigger("hide"))}},a(function(){b="rtl"===a("body").css("direction");var d=!1;c.element=a("<ul class='vakata-context'></ul>"),c.element.on("mouseenter","li",function(b){b.stopImmediatePropagation(),a.contains(this,b.relatedTarget)||(d&&clearTimeout(d),c.element.find(".vakata-context-hover").removeClass("vakata-context-hover").end(),a(this).siblings().find("ul").hide().end().end().parentsUntil(".vakata-context","li").addBack().addClass("vakata-context-hover"),a.vakata.context._show_submenu(this))}).on("mouseleave","li",function(b){a.contains(this,b.relatedTarget)||a(this).find(".vakata-context-hover").addBack().removeClass("vakata-context-hover")}).on("mouseleave",function(b){a(this).find(".vakata-context-hover").removeClass("vakata-context-hover"),a.vakata.context.settings.hide_onmouseleave&&(d=setTimeout(function(b){return function(){a.vakata.context.hide()}}(this),a.vakata.context.settings.hide_onmouseleave))}).on("click","a",function(b){b.preventDefault(),a(this).blur().parent().hasClass("vakata-context-disabled")||a.vakata.context._execute(a(this).attr("rel"))===!1||a.vakata.context.hide()}).on("keydown","a",function(b){var d=null;switch(b.which){case 13:case 32:b.type="click",b.preventDefault(),a(b.currentTarget).trigger(b);break;case 37:c.is_visible&&(c.element.find(".vakata-context-hover").last().closest("li").first().find("ul").hide().find(".vakata-context-hover").removeClass("vakata-context-hover").end().end().children("a").focus(),b.stopImmediatePropagation(),b.preventDefault());break;case 38:c.is_visible&&(d=c.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").prevAll("li:not(.vakata-context-separator)").first(),d.length||(d=c.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").last()),d.addClass("vakata-context-hover").children("a").focus(),b.stopImmediatePropagation(),b.preventDefault());break;case 39:c.is_visible&&(c.element.find(".vakata-context-hover").last().children("ul").show().children("li:not(.vakata-context-separator)").removeClass("vakata-context-hover").first().addClass("vakata-context-hover").children("a").focus(),b.stopImmediatePropagation(),b.preventDefault());break;case 40:c.is_visible&&(d=c.element.find("ul:visible").addBack().last().children(".vakata-context-hover").removeClass("vakata-context-hover").nextAll("li:not(.vakata-context-separator)").first(),d.length||(d=c.element.find("ul:visible").addBack().last().children("li:not(.vakata-context-separator)").first()),d.addClass("vakata-context-hover").children("a").focus(),b.stopImmediatePropagation(),b.preventDefault());break;case 27:a.vakata.context.hide(),b.preventDefault()}}).on("keydown",function(a){a.preventDefault();var b=c.element.find(".vakata-contextmenu-shortcut-"+a.which).parent();b.parent().not(".vakata-context-disabled")&&b.click()}),a(i).on("mousedown.vakata.jstree",function(b){c.is_visible&&c.element[0]!==b.target&&!a.contains(c.element[0],b.target)&&a.vakata.context.hide()}).on("context_show.vakata.jstree",function(a,d){c.element.find("li:has(ul)").children("a").addClass("vakata-context-parent"),b&&c.element.addClass("vakata-context-rtl").css("direction","rtl"),c.element.find("ul").hide().end()})})}(a),a.jstree.defaults.dnd={copy:!0,open_timeout:500,is_draggable:!0,check_while_dragging:!0,always_copy:!1,inside_pos:0,drag_selection:!0,touch:!0,large_drop_target:!1,large_drag_target:!1,use_html5:!1};var k,l;a.jstree.plugins.dnd=function(b,c){this.init=function(a,b){c.init.call(this,a,b),this.settings.dnd.use_html5=this.settings.dnd.use_html5&&"draggable"in i.createElement("span")},this.bind=function(){c.bind.call(this),this.element.on(this.settings.dnd.use_html5?"dragstart.jstree":"mousedown.jstree touchstart.jstree",this.settings.dnd.large_drag_target?".jstree-node":".jstree-anchor",a.proxy(function(b){if(this.settings.dnd.large_drag_target&&a(b.target).closest(".jstree-node")[0]!==b.currentTarget)return!0;if("touchstart"===b.type&&(!this.settings.dnd.touch||"selected"===this.settings.dnd.touch&&!a(b.currentTarget).closest(".jstree-node").children(".jstree-anchor").hasClass("jstree-clicked")))return!0;var c=this.get_node(b.target),d=this.is_selected(c)&&this.settings.dnd.drag_selection?this.get_top_selected().length:1,e=d>1?d+" "+this.get_string("nodes"):this.get_text(b.currentTarget);if(this.settings.core.force_text&&(e=a.vakata.html.escape(e)),c&&c.id&&c.id!==a.jstree.root&&(1===b.which||"touchstart"===b.type||"dragstart"===b.type)&&(this.settings.dnd.is_draggable===!0||a.isFunction(this.settings.dnd.is_draggable)&&this.settings.dnd.is_draggable.call(this,d>1?this.get_top_selected(!0):[c],b))){if(k={jstree:!0,origin:this,obj:this.get_node(c,!0),nodes:d>1?this.get_top_selected():[c.id]},l=b.currentTarget,!this.settings.dnd.use_html5)return this.element.trigger("mousedown.jstree"),a.vakata.dnd.start(b,k,'<div id="jstree-dnd" class="jstree-'+this.get_theme()+" jstree-"+this.get_theme()+"-"+this.get_theme_variant()+" "+(this.settings.core.themes.responsive?" jstree-dnd-responsive":"")+'"><i class="jstree-icon jstree-er"></i>'+e+'<ins class="jstree-copy" style="display:none;">+</ins></div>');a.vakata.dnd._trigger("start",b,{helper:a(),element:l,data:k})}},this)),this.settings.dnd.use_html5&&this.element.on("dragover.jstree",function(b){return b.preventDefault(),a.vakata.dnd._trigger("move",b,{helper:a(),element:l,data:k}),!1}).on("drop.jstree",a.proxy(function(b){return b.preventDefault(),a.vakata.dnd._trigger("stop",b,{helper:a(),element:l,data:k}),!1},this))},this.redraw_node=function(a,b,d,e){if(a=c.redraw_node.apply(this,arguments),a&&this.settings.dnd.use_html5)if(this.settings.dnd.large_drag_target)a.setAttribute("draggable",!0);else{var f,g,h=null;for(f=0,g=a.childNodes.length;g>f;f++)if(a.childNodes[f]&&a.childNodes[f].className&&-1!==a.childNodes[f].className.indexOf("jstree-anchor")){h=a.childNodes[f];break}h&&h.setAttribute("draggable",!0)}return a}},a(function(){var c=!1,d=!1,e=!1,f=!1,g=a('<div id="jstree-marker">&#160;</div>').hide();a(i).on("dnd_start.vakata.jstree",function(a,b){c=!1,e=!1,b&&b.data&&b.data.jstree&&g.appendTo("body")}).on("dnd_move.vakata.jstree",function(h,i){var j=i.event.target!==e.target;if(f&&(!i.event||"dragover"!==i.event.type||j)&&clearTimeout(f),i&&i.data&&i.data.jstree&&(!i.event.target.id||"jstree-marker"!==i.event.target.id)){e=i.event;var k=a.jstree.reference(i.event.target),l=!1,m=!1,n=!1,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E;if(k&&k._data&&k._data.dnd)if(g.attr("class","jstree-"+k.get_theme()+(k.settings.core.themes.responsive?" jstree-dnd-responsive":"")),D=i.data.origin&&(i.data.origin.settings.dnd.always_copy||i.data.origin.settings.dnd.copy&&(i.event.metaKey||i.event.ctrlKey)),i.helper.children().attr("class","jstree-"+k.get_theme()+" jstree-"+k.get_theme()+"-"+k.get_theme_variant()+" "+(k.settings.core.themes.responsive?" jstree-dnd-responsive":"")).find(".jstree-copy").first()[D?"show":"hide"](),i.event.target!==k.element[0]&&i.event.target!==k.get_container_ul()[0]||0!==k.get_container_ul().children().length){if(l=k.settings.dnd.large_drop_target?a(i.event.target).closest(".jstree-node").children(".jstree-anchor"):a(i.event.target).closest(".jstree-anchor"),l&&l.length&&l.parent().is(".jstree-closed, .jstree-open, .jstree-leaf")&&(m=l.offset(),n=(i.event.pageY!==b?i.event.pageY:i.event.originalEvent.pageY)-m.top,r=l.outerHeight(),u=r/3>n?["b","i","a"]:n>r-r/3?["a","i","b"]:n>r/2?["i","a","b"]:["i","b","a"],a.each(u,function(b,e){switch(e){case"b":p=m.left-6,q=m.top,s=k.get_parent(l),t=l.parent().index();break;case"i":B=k.settings.dnd.inside_pos,C=k.get_node(l.parent()),p=m.left-2,q=m.top+r/2+1,s=C.id,t="first"===B?0:"last"===B?C.children.length:Math.min(B,C.children.length);break;case"a":p=m.left-6,q=m.top+r,s=k.get_parent(l),t=l.parent().index()+1}for(v=!0,w=0,x=i.data.nodes.length;x>w;w++)if(y=i.data.origin&&(i.data.origin.settings.dnd.always_copy||i.data.origin.settings.dnd.copy&&(i.event.metaKey||i.event.ctrlKey))?"copy_node":"move_node",z=t,"move_node"===y&&"a"===e&&i.data.origin&&i.data.origin===k&&s===k.get_parent(i.data.nodes[w])&&(A=k.get_node(s),z>a.inArray(i.data.nodes[w],A.children)&&(z-=1)),v=v&&(k&&k.settings&&k.settings.dnd&&k.settings.dnd.check_while_dragging===!1||k.check(y,i.data.origin&&i.data.origin!==k?i.data.origin.get_node(i.data.nodes[w]):i.data.nodes[w],s,z,{dnd:!0,ref:k.get_node(l.parent()),pos:e,origin:i.data.origin,is_multi:i.data.origin&&i.data.origin!==k,is_foreign:!i.data.origin})),!v){k&&k.last_error&&(d=k.last_error());break}return"i"===e&&l.parent().is(".jstree-closed")&&k.settings.dnd.open_timeout&&(!i.event||"dragover"!==i.event.type||j)&&(f&&clearTimeout(f),f=setTimeout(function(a,b){return function(){a.open_node(b)}}(k,l),k.settings.dnd.open_timeout)),v?(E=k.get_node(s,!0),E.hasClass(".jstree-dnd-parent")||(a(".jstree-dnd-parent").removeClass("jstree-dnd-parent"),E.addClass("jstree-dnd-parent")),c={ins:k,par:s,pos:"i"!==e||"last"!==B||0!==t||k.is_loaded(C)?t:"last"},g.css({left:p+"px",top:q+"px"}).show(),i.helper.find(".jstree-icon").first().removeClass("jstree-er").addClass("jstree-ok"),i.event.originalEvent&&i.event.originalEvent.dataTransfer&&(i.event.originalEvent.dataTransfer.dropEffect=D?"copy":"move"),d={},u=!0,!1):void 0}),u===!0))return}else{for(v=!0,w=0,x=i.data.nodes.length;x>w;w++)if(v=v&&k.check(i.data.origin&&(i.data.origin.settings.dnd.always_copy||i.data.origin.settings.dnd.copy&&(i.event.metaKey||i.event.ctrlKey))?"copy_node":"move_node",i.data.origin&&i.data.origin!==k?i.data.origin.get_node(i.data.nodes[w]):i.data.nodes[w],a.jstree.root,"last",{dnd:!0,ref:k.get_node(a.jstree.root),pos:"i",origin:i.data.origin,is_multi:i.data.origin&&i.data.origin!==k,is_foreign:!i.data.origin}),!v)break;if(v)return c={ins:k,par:a.jstree.root,pos:"last"},g.hide(),i.helper.find(".jstree-icon").first().removeClass("jstree-er").addClass("jstree-ok"),void(i.event.originalEvent&&i.event.originalEvent.dataTransfer&&(i.event.originalEvent.dataTransfer.dropEffect=D?"copy":"move"))}a(".jstree-dnd-parent").removeClass("jstree-dnd-parent"),c=!1,i.helper.find(".jstree-icon").removeClass("jstree-ok").addClass("jstree-er"),i.event.originalEvent&&i.event.originalEvent.dataTransfer&&(i.event.originalEvent.dataTransfer.dropEffect="none"),g.hide()}}).on("dnd_scroll.vakata.jstree",function(a,b){b&&b.data&&b.data.jstree&&(g.hide(),c=!1,e=!1,b.helper.find(".jstree-icon").first().removeClass("jstree-ok").addClass("jstree-er"))}).on("dnd_stop.vakata.jstree",function(b,h){if(a(".jstree-dnd-parent").removeClass("jstree-dnd-parent"),f&&clearTimeout(f),h&&h.data&&h.data.jstree){g.hide().detach();var i,j,k=[];if(c){for(i=0,j=h.data.nodes.length;j>i;i++)k[i]=h.data.origin?h.data.origin.get_node(h.data.nodes[i]):h.data.nodes[i];c.ins[h.data.origin&&(h.data.origin.settings.dnd.always_copy||h.data.origin.settings.dnd.copy&&(h.event.metaKey||h.event.ctrlKey))?"copy_node":"move_node"](k,c.par,c.pos,!1,!1,!1,h.data.origin)}else i=a(h.event.target).closest(".jstree"),i.length&&d&&d.error&&"check"===d.error&&(i=i.jstree(!0),i&&i.settings.core.error.call(this,d));e=!1,c=!1}}).on("keyup.jstree keydown.jstree",function(b,h){h=a.vakata.dnd._get(),h&&h.data&&h.data.jstree&&("keyup"===b.type&&27===b.which?(f&&clearTimeout(f),c=!1,d=!1,e=!1,f=!1,g.hide().detach(),a.vakata.dnd._clean()):(h.helper.find(".jstree-copy").first()[h.data.origin&&(h.data.origin.settings.dnd.always_copy||h.data.origin.settings.dnd.copy&&(b.metaKey||b.ctrlKey))?"show":"hide"](),e&&(e.metaKey=b.metaKey,e.ctrlKey=b.ctrlKey,a.vakata.dnd._trigger("move",e))))})}),function(a){a.vakata.html={div:a("<div />"),escape:function(b){return a.vakata.html.div.text(b).html()},strip:function(b){return a.vakata.html.div.empty().append(a.parseHTML(b)).text()}};var c={element:!1,target:!1,is_down:!1,is_drag:!1,helper:!1,helper_w:0,data:!1,init_x:0,init_y:0,scroll_l:0,scroll_t:0,scroll_e:!1,scroll_i:!1,is_touch:!1};a.vakata.dnd={settings:{scroll_speed:10,scroll_proximity:20,helper_left:5,helper_top:10,threshold:5,threshold_touch:10},_trigger:function(c,d,e){e===b&&(e=a.vakata.dnd._get()),e.event=d,a(i).triggerHandler("dnd_"+c+".vakata",e)},_get:function(){return{data:c.data,element:c.element,helper:c.helper}},_clean:function(){c.helper&&c.helper.remove(),c.scroll_i&&(clearInterval(c.scroll_i),c.scroll_i=!1),c={element:!1,target:!1,is_down:!1,is_drag:!1,helper:!1,helper_w:0,data:!1,init_x:0,init_y:0,scroll_l:0,scroll_t:0,scroll_e:!1,scroll_i:!1,is_touch:!1},a(i).off("mousemove.vakata.jstree touchmove.vakata.jstree",a.vakata.dnd.drag),a(i).off("mouseup.vakata.jstree touchend.vakata.jstree",a.vakata.dnd.stop)},_scroll:function(b){if(!c.scroll_e||!c.scroll_l&&!c.scroll_t)return c.scroll_i&&(clearInterval(c.scroll_i),c.scroll_i=!1),!1;if(!c.scroll_i)return c.scroll_i=setInterval(a.vakata.dnd._scroll,100),!1;if(b===!0)return!1;var d=c.scroll_e.scrollTop(),e=c.scroll_e.scrollLeft();c.scroll_e.scrollTop(d+c.scroll_t*a.vakata.dnd.settings.scroll_speed),c.scroll_e.scrollLeft(e+c.scroll_l*a.vakata.dnd.settings.scroll_speed),(d!==c.scroll_e.scrollTop()||e!==c.scroll_e.scrollLeft())&&a.vakata.dnd._trigger("scroll",c.scroll_e)},start:function(b,d,e){"touchstart"===b.type&&b.originalEvent&&b.originalEvent.changedTouches&&b.originalEvent.changedTouches[0]&&(b.pageX=b.originalEvent.changedTouches[0].pageX,b.pageY=b.originalEvent.changedTouches[0].pageY,b.target=i.elementFromPoint(b.originalEvent.changedTouches[0].pageX-window.pageXOffset,b.originalEvent.changedTouches[0].pageY-window.pageYOffset)),c.is_drag&&a.vakata.dnd.stop({});try{b.currentTarget.unselectable="on",b.currentTarget.onselectstart=function(){return!1},b.currentTarget.style&&(b.currentTarget.style.touchAction="none",b.currentTarget.style.msTouchAction="none",b.currentTarget.style.MozUserSelect="none")}catch(f){}return c.init_x=b.pageX,c.init_y=b.pageY,c.data=d,c.is_down=!0,c.element=b.currentTarget,c.target=b.target,c.is_touch="touchstart"===b.type,e!==!1&&(c.helper=a("<div id='vakata-dnd'></div>").html(e).css({display:"block",margin:"0",padding:"0",position:"absolute",top:"-2000px",lineHeight:"16px",zIndex:"10000"})),a(i).on("mousemove.vakata.jstree touchmove.vakata.jstree",a.vakata.dnd.drag),a(i).on("mouseup.vakata.jstree touchend.vakata.jstree",a.vakata.dnd.stop),!1},drag:function(b){if("touchmove"===b.type&&b.originalEvent&&b.originalEvent.changedTouches&&b.originalEvent.changedTouches[0]&&(b.pageX=b.originalEvent.changedTouches[0].pageX,b.pageY=b.originalEvent.changedTouches[0].pageY,b.target=i.elementFromPoint(b.originalEvent.changedTouches[0].pageX-window.pageXOffset,b.originalEvent.changedTouches[0].pageY-window.pageYOffset)),c.is_down){if(!c.is_drag){if(!(Math.abs(b.pageX-c.init_x)>(c.is_touch?a.vakata.dnd.settings.threshold_touch:a.vakata.dnd.settings.threshold)||Math.abs(b.pageY-c.init_y)>(c.is_touch?a.vakata.dnd.settings.threshold_touch:a.vakata.dnd.settings.threshold)))return;c.helper&&(c.helper.appendTo("body"),c.helper_w=c.helper.outerWidth()),c.is_drag=!0,a(c.target).one("click.vakata",!1),a.vakata.dnd._trigger("start",b)}var d=!1,e=!1,f=!1,g=!1,h=!1,j=!1,k=!1,l=!1,m=!1,n=!1;return c.scroll_t=0,c.scroll_l=0,c.scroll_e=!1,a(a(b.target).parentsUntil("body").addBack().get().reverse()).filter(function(){return/^auto|scroll$/.test(a(this).css("overflow"))&&(this.scrollHeight>this.offsetHeight||this.scrollWidth>this.offsetWidth)}).each(function(){var d=a(this),e=d.offset();return this.scrollHeight>this.offsetHeight&&(e.top+d.height()-b.pageY<a.vakata.dnd.settings.scroll_proximity&&(c.scroll_t=1),b.pageY-e.top<a.vakata.dnd.settings.scroll_proximity&&(c.scroll_t=-1)),this.scrollWidth>this.offsetWidth&&(e.left+d.width()-b.pageX<a.vakata.dnd.settings.scroll_proximity&&(c.scroll_l=1),b.pageX-e.left<a.vakata.dnd.settings.scroll_proximity&&(c.scroll_l=-1)),c.scroll_t||c.scroll_l?(c.scroll_e=a(this),!1):void 0}),c.scroll_e||(d=a(i),e=a(window),f=d.height(),g=e.height(),h=d.width(),j=e.width(),k=d.scrollTop(),l=d.scrollLeft(),f>g&&b.pageY-k<a.vakata.dnd.settings.scroll_proximity&&(c.scroll_t=-1),f>g&&g-(b.pageY-k)<a.vakata.dnd.settings.scroll_proximity&&(c.scroll_t=1),h>j&&b.pageX-l<a.vakata.dnd.settings.scroll_proximity&&(c.scroll_l=-1),h>j&&j-(b.pageX-l)<a.vakata.dnd.settings.scroll_proximity&&(c.scroll_l=1),(c.scroll_t||c.scroll_l)&&(c.scroll_e=d)),c.scroll_e&&a.vakata.dnd._scroll(!0),c.helper&&(m=parseInt(b.pageY+a.vakata.dnd.settings.helper_top,10),n=parseInt(b.pageX+a.vakata.dnd.settings.helper_left,10),f&&m+25>f&&(m=f-50),h&&n+c.helper_w>h&&(n=h-(c.helper_w+2)),c.helper.css({left:n+"px",top:m+"px"})),a.vakata.dnd._trigger("move",b),!1}},stop:function(b){if("touchend"===b.type&&b.originalEvent&&b.originalEvent.changedTouches&&b.originalEvent.changedTouches[0]&&(b.pageX=b.originalEvent.changedTouches[0].pageX,b.pageY=b.originalEvent.changedTouches[0].pageY,b.target=i.elementFromPoint(b.originalEvent.changedTouches[0].pageX-window.pageXOffset,b.originalEvent.changedTouches[0].pageY-window.pageYOffset)),c.is_drag)b.target!==c.target&&a(c.target).off("click.vakata"),a.vakata.dnd._trigger("stop",b);else if("touchend"===b.type&&b.target===c.target){var d=setTimeout(function(){a(b.target).click()},100);a(b.target).one("click",function(){d&&clearTimeout(d)})}return a.vakata.dnd._clean(),!1}}}(a),a.jstree.defaults.massload=null,a.jstree.plugins.massload=function(b,c){this.init=function(a,b){this._data.massload={},c.init.call(this,a,b)},this._load_nodes=function(b,d,e,f){var g=this.settings.massload,h=JSON.stringify(b),i=[],j=this._model.data,k,l,m;if(!e){for(k=0,l=b.length;l>k;k++)(!j[b[k]]||!j[b[k]].state.loaded&&!j[b[k]].state.failed||f)&&(i.push(b[k]),m=this.get_node(b[k],!0),m&&m.length&&m.addClass("jstree-loading").attr("aria-busy",!0));if(this._data.massload={},i.length){if(a.isFunction(g))return g.call(this,i,a.proxy(function(a){var g,h;if(a)for(g in a)a.hasOwnProperty(g)&&(this._data.massload[g]=a[g]);for(g=0,h=b.length;h>g;g++)m=this.get_node(b[g],!0),m&&m.length&&m.removeClass("jstree-loading").attr("aria-busy",!1);c._load_nodes.call(this,b,d,e,f)},this));if("object"==typeof g&&g&&g.url)return g=a.extend(!0,{},g),a.isFunction(g.url)&&(g.url=g.url.call(this,i)),a.isFunction(g.data)&&(g.data=g.data.call(this,i)),a.ajax(g).done(a.proxy(function(a,g,h){var i,j;if(a)for(i in a)a.hasOwnProperty(i)&&(this._data.massload[i]=a[i]);for(i=0,j=b.length;j>i;i++)m=this.get_node(b[i],!0),m&&m.length&&m.removeClass("jstree-loading").attr("aria-busy",!1);c._load_nodes.call(this,b,d,e,f)},this)).fail(a.proxy(function(a){c._load_nodes.call(this,b,d,e,f)},this))}}return c._load_nodes.call(this,b,d,e,f)},this._load_node=function(b,d){var e=this._data.massload[b.id],f=null,g;return e?(f=this["string"==typeof e?"_append_html_data":"_append_json_data"](b,"string"==typeof e?a(a.parseHTML(e)).filter(function(){return 3!==this.nodeType}):e,function(a){d.call(this,a)}),g=this.get_node(b.id,!0),g&&g.length&&g.removeClass("jstree-loading").attr("aria-busy",!1),delete this._data.massload[b.id],f):c._load_node.call(this,b,d)}},a.jstree.defaults.search={ajax:!1,fuzzy:!1,case_sensitive:!1,show_only_matches:!1,show_only_matches_children:!1,close_opened_onclear:!0,search_leaves_only:!1,search_callback:!1},a.jstree.plugins.search=function(c,d){this.bind=function(){d.bind.call(this),this._data.search.str="",this._data.search.dom=a(),this._data.search.res=[],this._data.search.opn=[],this._data.search.som=!1,this._data.search.smc=!1,this._data.search.hdn=[],this.element.on("search.jstree",a.proxy(function(b,c){if(this._data.search.som&&c.res.length){var d=this._model.data,e,f,g=[],h,i;for(e=0,f=c.res.length;f>e;e++)if(d[c.res[e]]&&!d[c.res[e]].state.hidden&&(g.push(c.res[e]),g=g.concat(d[c.res[e]].parents),this._data.search.smc))for(h=0,i=d[c.res[e]].children_d.length;i>h;h++)d[d[c.res[e]].children_d[h]]&&!d[d[c.res[e]].children_d[h]].state.hidden&&g.push(d[c.res[e]].children_d[h]);g=a.vakata.array_remove_item(a.vakata.array_unique(g),a.jstree.root),this._data.search.hdn=this.hide_all(!0),this.show_node(g,!0),this.redraw(!0)}},this)).on("clear_search.jstree",a.proxy(function(a,b){this._data.search.som&&b.res.length&&(this.show_node(this._data.search.hdn,!0),this.redraw(!0))},this))},this.search=function(c,d,e,f,g,h){if(c===!1||""===a.trim(c.toString()))return this.clear_search();f=this.get_node(f),f=f&&f.id?f.id:null,c=c.toString();var i=this.settings.search,j=i.ajax?i.ajax:!1,k=this._model.data,l=null,m=[],n=[],o,p;if(this._data.search.res.length&&!g&&this.clear_search(),e===b&&(e=i.show_only_matches),h===b&&(h=i.show_only_matches_children),!d&&j!==!1)return a.isFunction(j)?j.call(this,c,a.proxy(function(b){b&&b.d&&(b=b.d),this._load_nodes(a.isArray(b)?a.vakata.array_unique(b):[],function(){this.search(c,!0,e,f,g,h)})},this),f):(j=a.extend({},j),j.data||(j.data={}),j.data.str=c,f&&(j.data.inside=f),this._data.search.lastRequest&&this._data.search.lastRequest.abort(),this._data.search.lastRequest=a.ajax(j).fail(a.proxy(function(){this._data.core.last_error={error:"ajax",plugin:"search",id:"search_01",reason:"Could not load search parents",data:JSON.stringify(j)},this.settings.core.error.call(this,this._data.core.last_error)},this)).done(a.proxy(function(b){b&&b.d&&(b=b.d),this._load_nodes(a.isArray(b)?a.vakata.array_unique(b):[],function(){this.search(c,!0,e,f,g,h)})},this)),this._data.search.lastRequest);if(g||(this._data.search.str=c,this._data.search.dom=a(),this._data.search.res=[],this._data.search.opn=[],this._data.search.som=e,this._data.search.smc=h),l=new a.vakata.search(c,!0,{caseSensitive:i.case_sensitive,fuzzy:i.fuzzy}),a.each(k[f?f:a.jstree.root].children_d,function(a,b){var d=k[b];d.text&&!d.state.hidden&&(!i.search_leaves_only||d.state.loaded&&0===d.children.length)&&(i.search_callback&&i.search_callback.call(this,c,d)||!i.search_callback&&l.search(d.text).isMatch)&&(m.push(b),n=n.concat(d.parents))}),m.length){for(n=a.vakata.array_unique(n),o=0,p=n.length;p>o;o++)n[o]!==a.jstree.root&&k[n[o]]&&this.open_node(n[o],null,0)===!0&&this._data.search.opn.push(n[o]);g?(this._data.search.dom=this._data.search.dom.add(a(this.element[0].querySelectorAll("#"+a.map(m,function(b){return-1!=="0123456789".indexOf(b[0])?"\\3"+b[0]+" "+b.substr(1).replace(a.jstree.idregex,"\\$&"):b.replace(a.jstree.idregex,"\\$&")}).join(", #")))),this._data.search.res=a.vakata.array_unique(this._data.search.res.concat(m))):(this._data.search.dom=a(this.element[0].querySelectorAll("#"+a.map(m,function(b){return-1!=="0123456789".indexOf(b[0])?"\\3"+b[0]+" "+b.substr(1).replace(a.jstree.idregex,"\\$&"):b.replace(a.jstree.idregex,"\\$&")}).join(", #"))),this._data.search.res=m),this._data.search.dom.children(".jstree-anchor").addClass("jstree-search")}this.trigger("search",{nodes:this._data.search.dom,str:c,res:this._data.search.res,show_only_matches:e})},this.clear_search=function(){this.settings.search.close_opened_onclear&&this.close_node(this._data.search.opn,0),this.trigger("clear_search",{nodes:this._data.search.dom,str:this._data.search.str,res:this._data.search.res}),this._data.search.res.length&&(this._data.search.dom=a(this.element[0].querySelectorAll("#"+a.map(this._data.search.res,function(b){return-1!=="0123456789".indexOf(b[0])?"\\3"+b[0]+" "+b.substr(1).replace(a.jstree.idregex,"\\$&"):b.replace(a.jstree.idregex,"\\$&")}).join(", #"))),this._data.search.dom.children(".jstree-anchor").removeClass("jstree-search")),this._data.search.str="",this._data.search.res=[],this._data.search.opn=[],this._data.search.dom=a()},this.redraw_node=function(b,c,e,f){if(b=d.redraw_node.apply(this,arguments),b&&-1!==a.inArray(b.id,this._data.search.res)){var g,h,i=null;for(g=0,h=b.childNodes.length;h>g;g++)if(b.childNodes[g]&&b.childNodes[g].className&&-1!==b.childNodes[g].className.indexOf("jstree-anchor")){i=b.childNodes[g];break}i&&(i.className+=" jstree-search")}return b}},function(a){a.vakata.search=function(b,c,d){d=d||{},d=a.extend({},a.vakata.search.defaults,d),d.fuzzy!==!1&&(d.fuzzy=!0),b=d.caseSensitive?b:b.toLowerCase();var e=d.location,f=d.distance,g=d.threshold,h=b.length,i,j,k,l;return h>32&&(d.fuzzy=!1),d.fuzzy&&(i=1<<h-1,j=function(){var a={},c=0;for(c=0;h>c;c++)a[b.charAt(c)]=0;for(c=0;h>c;c++)a[b.charAt(c)]|=1<<h-c-1;return a}(),k=function(a,b){var c=a/h,d=Math.abs(e-b);return f?c+d/f:d?1:c}),l=function(a){if(a=d.caseSensitive?a:a.toLowerCase(),b===a||-1!==a.indexOf(b))return{isMatch:!0,score:0};if(!d.fuzzy)return{isMatch:!1,score:1};var c,f,l=a.length,m=g,n=a.indexOf(b,e),o,p,q=h+l,r,s,t,u,v,w=1,x=[];for(-1!==n&&(m=Math.min(k(0,n),m),n=a.lastIndexOf(b,e+h),-1!==n&&(m=Math.min(k(0,n),m))),n=-1,c=0;h>c;c++){o=0,p=q;while(p>o)k(c,e+p)<=m?o=p:q=p,p=Math.floor((q-o)/2+o);for(q=p,s=Math.max(1,e-p+1),t=Math.min(e+p,l)+h,u=new Array(t+2),u[t+1]=(1<<c)-1,f=t;f>=s;f--)if(v=j[a.charAt(f-1)],0===c?u[f]=(u[f+1]<<1|1)&v:u[f]=(u[f+1]<<1|1)&v|((r[f+1]|r[f])<<1|1)|r[f+1],u[f]&i&&(w=k(c,f-1),m>=w)){if(m=w,n=f-1,x.push(n),!(n>e))break;s=Math.max(1,2*e-n)}if(k(c+1,e)>m)break;r=u}return{isMatch:n>=0,score:w}},c===!0?{search:l}:l(c)},a.vakata.search.defaults={location:0,distance:100,threshold:.6,fuzzy:!1,caseSensitive:!1}}(a),a.jstree.defaults.sort=function(a,b){return this.get_text(a)>this.get_text(b)?1:-1},a.jstree.plugins.sort=function(b,c){this.bind=function(){c.bind.call(this),this.element.on("model.jstree",a.proxy(function(a,b){this.sort(b.parent,!0)},this)).on("rename_node.jstree create_node.jstree",a.proxy(function(a,b){this.sort(b.parent||b.node.parent,!1),this.redraw_node(b.parent||b.node.parent,!0)},this)).on("move_node.jstree copy_node.jstree",a.proxy(function(a,b){this.sort(b.parent,!1),this.redraw_node(b.parent,!0)},this))},this.sort=function(b,c){var d,e;if(b=this.get_node(b),b&&b.children&&b.children.length&&(b.children.sort(a.proxy(this.settings.sort,this)),c))for(d=0,e=b.children_d.length;e>d;d++)this.sort(b.children_d[d],!1)}};var m=!1;a.jstree.defaults.state={key:"jstree",events:"changed.jstree open_node.jstree close_node.jstree check_node.jstree uncheck_node.jstree",ttl:!1,filter:!1,preserve_loaded:!1},a.jstree.plugins.state=function(b,c){this.bind=function(){c.bind.call(this);var b=a.proxy(function(){this.element.on(this.settings.state.events,a.proxy(function(){m&&clearTimeout(m),m=setTimeout(a.proxy(function(){this.save_state()},this),100)},this)),this.trigger("state_ready")},this);this.element.on("ready.jstree",a.proxy(function(a,c){this.element.one("restore_state.jstree",b),this.restore_state()||b()},this))},this.save_state=function(){var b=this.get_state();this.settings.state.preserve_loaded||delete b.core.loaded;var c={state:b,ttl:this.settings.state.ttl,sec:+new Date};a.vakata.storage.set(this.settings.state.key,JSON.stringify(c))},this.restore_state=function(){var b=a.vakata.storage.get(this.settings.state.key);if(b)try{b=JSON.parse(b)}catch(c){return!1}return b&&b.ttl&&b.sec&&+new Date-b.sec>b.ttl?!1:(b&&b.state&&(b=b.state),b&&a.isFunction(this.settings.state.filter)&&(b=this.settings.state.filter.call(this,b)),b?(this.settings.state.preserve_loaded||delete b.core.loaded,this.element.one("set_state.jstree",function(c,d){d.instance.trigger("restore_state",{state:a.extend(!0,{},b)})}),this.set_state(b),!0):!1)},this.clear_state=function(){return a.vakata.storage.del(this.settings.state.key)}},function(a,b){a.vakata.storage={set:function(a,b){return window.localStorage.setItem(a,b)},get:function(a){return window.localStorage.getItem(a)},del:function(a){return window.localStorage.removeItem(a)}}}(a),a.jstree.defaults.types={"default":{}},a.jstree.defaults.types[a.jstree.root]={},a.jstree.plugins.types=function(c,d){this.init=function(c,e){var f,g;if(e&&e.types&&e.types["default"])for(f in e.types)if("default"!==f&&f!==a.jstree.root&&e.types.hasOwnProperty(f))for(g in e.types["default"])e.types["default"].hasOwnProperty(g)&&e.types[f][g]===b&&(e.types[f][g]=e.types["default"][g]);d.init.call(this,c,e),this._model.data[a.jstree.root].type=a.jstree.root},this.refresh=function(b,c){d.refresh.call(this,b,c),this._model.data[a.jstree.root].type=a.jstree.root},this.bind=function(){this.element.on("model.jstree",a.proxy(function(c,d){var e=this._model.data,f=d.nodes,g=this.settings.types,h,i,j="default",k;for(h=0,i=f.length;i>h;h++){if(j="default",e[f[h]].original&&e[f[h]].original.type&&g[e[f[h]].original.type]&&(j=e[f[h]].original.type),e[f[h]].data&&e[f[h]].data.jstree&&e[f[h]].data.jstree.type&&g[e[f[h]].data.jstree.type]&&(j=e[f[h]].data.jstree.type),e[f[h]].type=j,e[f[h]].icon===!0&&g[j].icon!==b&&(e[f[h]].icon=g[j].icon),g[j].li_attr!==b&&"object"==typeof g[j].li_attr)for(k in g[j].li_attr)if(g[j].li_attr.hasOwnProperty(k)){if("id"===k)continue;e[f[h]].li_attr[k]===b?e[f[h]].li_attr[k]=g[j].li_attr[k]:"class"===k&&(e[f[h]].li_attr["class"]=g[j].li_attr["class"]+" "+e[f[h]].li_attr["class"])}if(g[j].a_attr!==b&&"object"==typeof g[j].a_attr)for(k in g[j].a_attr)if(g[j].a_attr.hasOwnProperty(k)){if("id"===k)continue;e[f[h]].a_attr[k]===b?e[f[h]].a_attr[k]=g[j].a_attr[k]:"href"===k&&"#"===e[f[h]].a_attr[k]?e[f[h]].a_attr.href=g[j].a_attr.href:"class"===k&&(e[f[h]].a_attr["class"]=g[j].a_attr["class"]+" "+e[f[h]].a_attr["class"])}}e[a.jstree.root].type=a.jstree.root},this)),d.bind.call(this)},this.get_json=function(b,c,e){var f,g,h=this._model.data,i=c?a.extend(!0,{},c,{no_id:!1}):{},j=d.get_json.call(this,b,i,e);if(j===!1)return!1;if(a.isArray(j))for(f=0,g=j.length;g>f;f++)j[f].type=j[f].id&&h[j[f].id]&&h[j[f].id].type?h[j[f].id].type:"default",c&&c.no_id&&(delete j[f].id,j[f].li_attr&&j[f].li_attr.id&&delete j[f].li_attr.id,j[f].a_attr&&j[f].a_attr.id&&delete j[f].a_attr.id);else j.type=j.id&&h[j.id]&&h[j.id].type?h[j.id].type:"default",c&&c.no_id&&(j=this._delete_ids(j));return j},this._delete_ids=function(b){if(a.isArray(b)){for(var c=0,d=b.length;d>c;c++)b[c]=this._delete_ids(b[c]);return b}return delete b.id,b.li_attr&&b.li_attr.id&&delete b.li_attr.id,b.a_attr&&b.a_attr.id&&delete b.a_attr.id,b.children&&a.isArray(b.children)&&(b.children=this._delete_ids(b.children)),
6
- b},this.check=function(c,e,f,g,h){if(d.check.call(this,c,e,f,g,h)===!1)return!1;e=e&&e.id?e:this.get_node(e),f=f&&f.id?f:this.get_node(f);var i=e&&e.id?h&&h.origin?h.origin:a.jstree.reference(e.id):null,j,k,l,m;switch(i=i&&i._model&&i._model.data?i._model.data:null,c){case"create_node":case"move_node":case"copy_node":if("move_node"!==c||-1===a.inArray(e.id,f.children)){if(j=this.get_rules(f),j.max_children!==b&&-1!==j.max_children&&j.max_children===f.children.length)return this._data.core.last_error={error:"check",plugin:"types",id:"types_01",reason:"max_children prevents function: "+c,data:JSON.stringify({chk:c,pos:g,obj:e&&e.id?e.id:!1,par:f&&f.id?f.id:!1})},!1;if(j.valid_children!==b&&-1!==j.valid_children&&-1===a.inArray(e.type||"default",j.valid_children))return this._data.core.last_error={error:"check",plugin:"types",id:"types_02",reason:"valid_children prevents function: "+c,data:JSON.stringify({chk:c,pos:g,obj:e&&e.id?e.id:!1,par:f&&f.id?f.id:!1})},!1;if(i&&e.children_d&&e.parents){for(k=0,l=0,m=e.children_d.length;m>l;l++)k=Math.max(k,i[e.children_d[l]].parents.length);k=k-e.parents.length+1}(0>=k||k===b)&&(k=1);do{if(j.max_depth!==b&&-1!==j.max_depth&&j.max_depth<k)return this._data.core.last_error={error:"check",plugin:"types",id:"types_03",reason:"max_depth prevents function: "+c,data:JSON.stringify({chk:c,pos:g,obj:e&&e.id?e.id:!1,par:f&&f.id?f.id:!1})},!1;f=this.get_node(f.parent),j=this.get_rules(f),k++}while(f)}}return!0},this.get_rules=function(a){if(a=this.get_node(a),!a)return!1;var c=this.get_type(a,!0);return c.max_depth===b&&(c.max_depth=-1),c.max_children===b&&(c.max_children=-1),c.valid_children===b&&(c.valid_children=-1),c},this.get_type=function(b,c){return b=this.get_node(b),b?c?a.extend({type:b.type},this.settings.types[b.type]):b.type:!1},this.set_type=function(c,d){var e=this._model.data,f,g,h,i,j,k,l,m;if(a.isArray(c)){for(c=c.slice(),g=0,h=c.length;h>g;g++)this.set_type(c[g],d);return!0}if(f=this.settings.types,c=this.get_node(c),!f[d]||!c)return!1;if(l=this.get_node(c,!0),l&&l.length&&(m=l.children(".jstree-anchor")),i=c.type,j=this.get_icon(c),c.type=d,(j===!0||!f[i]||f[i].icon!==b&&j===f[i].icon)&&this.set_icon(c,f[d].icon!==b?f[d].icon:!0),f[i]&&f[i].li_attr!==b&&"object"==typeof f[i].li_attr)for(k in f[i].li_attr)if(f[i].li_attr.hasOwnProperty(k)){if("id"===k)continue;"class"===k?(e[c.id].li_attr["class"]=(e[c.id].li_attr["class"]||"").replace(f[i].li_attr[k],""),l&&l.removeClass(f[i].li_attr[k])):e[c.id].li_attr[k]===f[i].li_attr[k]&&(e[c.id].li_attr[k]=null,l&&l.removeAttr(k))}if(f[i]&&f[i].a_attr!==b&&"object"==typeof f[i].a_attr)for(k in f[i].a_attr)if(f[i].a_attr.hasOwnProperty(k)){if("id"===k)continue;"class"===k?(e[c.id].a_attr["class"]=(e[c.id].a_attr["class"]||"").replace(f[i].a_attr[k],""),m&&m.removeClass(f[i].a_attr[k])):e[c.id].a_attr[k]===f[i].a_attr[k]&&("href"===k?(e[c.id].a_attr[k]="#",m&&m.attr("href","#")):(delete e[c.id].a_attr[k],m&&m.removeAttr(k)))}if(f[d].li_attr!==b&&"object"==typeof f[d].li_attr)for(k in f[d].li_attr)if(f[d].li_attr.hasOwnProperty(k)){if("id"===k)continue;e[c.id].li_attr[k]===b?(e[c.id].li_attr[k]=f[d].li_attr[k],l&&("class"===k?l.addClass(f[d].li_attr[k]):l.attr(k,f[d].li_attr[k]))):"class"===k&&(e[c.id].li_attr["class"]=f[d].li_attr[k]+" "+e[c.id].li_attr["class"],l&&l.addClass(f[d].li_attr[k]))}if(f[d].a_attr!==b&&"object"==typeof f[d].a_attr)for(k in f[d].a_attr)if(f[d].a_attr.hasOwnProperty(k)){if("id"===k)continue;e[c.id].a_attr[k]===b?(e[c.id].a_attr[k]=f[d].a_attr[k],m&&("class"===k?m.addClass(f[d].a_attr[k]):m.attr(k,f[d].a_attr[k]))):"href"===k&&"#"===e[c.id].a_attr[k]?(e[c.id].a_attr.href=f[d].a_attr.href,m&&m.attr("href",f[d].a_attr.href)):"class"===k&&(e[c.id].a_attr["class"]=f[d].a_attr["class"]+" "+e[c.id].a_attr["class"],m&&m.addClass(f[d].a_attr[k]))}return!0}},a.jstree.defaults.unique={case_sensitive:!1,trim_whitespace:!1,duplicate:function(a,b){return a+" ("+b+")"}},a.jstree.plugins.unique=function(c,d){this.check=function(b,c,e,f,g){if(d.check.call(this,b,c,e,f,g)===!1)return!1;if(c=c&&c.id?c:this.get_node(c),e=e&&e.id?e:this.get_node(e),!e||!e.children)return!0;var h="rename_node"===b?f:c.text,i=[],j=this.settings.unique.case_sensitive,k=this.settings.unique.trim_whitespace,l=this._model.data,m,n,o;for(m=0,n=e.children.length;n>m;m++)o=l[e.children[m]].text,j||(o=o.toLowerCase()),k&&(o=o.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")),i.push(o);switch(j||(h=h.toLowerCase()),k&&(h=h.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")),b){case"delete_node":return!0;case"rename_node":return o=c.text||"",j||(o=o.toLowerCase()),k&&(o=o.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")),m=-1===a.inArray(h,i)||c.text&&o===h,m||(this._data.core.last_error={error:"check",plugin:"unique",id:"unique_01",reason:"Child with name "+h+" already exists. Preventing: "+b,data:JSON.stringify({chk:b,pos:f,obj:c&&c.id?c.id:!1,par:e&&e.id?e.id:!1})}),m;case"create_node":return m=-1===a.inArray(h,i),m||(this._data.core.last_error={error:"check",plugin:"unique",id:"unique_04",reason:"Child with name "+h+" already exists. Preventing: "+b,data:JSON.stringify({chk:b,pos:f,obj:c&&c.id?c.id:!1,par:e&&e.id?e.id:!1})}),m;case"copy_node":return m=-1===a.inArray(h,i),m||(this._data.core.last_error={error:"check",plugin:"unique",id:"unique_02",reason:"Child with name "+h+" already exists. Preventing: "+b,data:JSON.stringify({chk:b,pos:f,obj:c&&c.id?c.id:!1,par:e&&e.id?e.id:!1})}),m;case"move_node":return m=c.parent===e.id&&(!g||!g.is_multi)||-1===a.inArray(h,i),m||(this._data.core.last_error={error:"check",plugin:"unique",id:"unique_03",reason:"Child with name "+h+" already exists. Preventing: "+b,data:JSON.stringify({chk:b,pos:f,obj:c&&c.id?c.id:!1,par:e&&e.id?e.id:!1})}),m}return!0},this.create_node=function(c,e,f,g,h){if(!e||e.text===b){if(null===c&&(c=a.jstree.root),c=this.get_node(c),!c)return d.create_node.call(this,c,e,f,g,h);if(f=f===b?"last":f,!f.toString().match(/^(before|after)$/)&&!h&&!this.is_loaded(c))return d.create_node.call(this,c,e,f,g,h);e||(e={});var i,j,k,l,m,n=this._model.data,o=this.settings.unique.case_sensitive,p=this.settings.unique.trim_whitespace,q=this.settings.unique.duplicate,r;for(j=i=this.get_string("New node"),k=[],l=0,m=c.children.length;m>l;l++)r=n[c.children[l]].text,o||(r=r.toLowerCase()),p&&(r=r.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,"")),k.push(r);l=1,r=j,o||(r=r.toLowerCase()),p&&(r=r.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""));while(-1!==a.inArray(r,k))j=q.call(this,i,++l).toString(),r=j,o||(r=r.toLowerCase()),p&&(r=r.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,""));e.text=j}return d.create_node.call(this,c,e,f,g,h)}};var n=i.createElement("DIV");if(n.setAttribute("unselectable","on"),n.setAttribute("role","presentation"),n.className="jstree-wholerow",n.innerHTML="&#160;",a.jstree.plugins.wholerow=function(b,c){this.bind=function(){c.bind.call(this),this.element.on("ready.jstree set_state.jstree",a.proxy(function(){this.hide_dots()},this)).on("init.jstree loading.jstree ready.jstree",a.proxy(function(){this.get_container_ul().addClass("jstree-wholerow-ul")},this)).on("deselect_all.jstree",a.proxy(function(a,b){this.element.find(".jstree-wholerow-clicked").removeClass("jstree-wholerow-clicked")},this)).on("changed.jstree",a.proxy(function(a,b){this.element.find(".jstree-wholerow-clicked").removeClass("jstree-wholerow-clicked");var c=!1,d,e;for(d=0,e=b.selected.length;e>d;d++)c=this.get_node(b.selected[d],!0),c&&c.length&&c.children(".jstree-wholerow").addClass("jstree-wholerow-clicked")},this)).on("open_node.jstree",a.proxy(function(a,b){this.get_node(b.node,!0).find(".jstree-clicked").parent().children(".jstree-wholerow").addClass("jstree-wholerow-clicked")},this)).on("hover_node.jstree dehover_node.jstree",a.proxy(function(a,b){"hover_node"===a.type&&this.is_disabled(b.node)||this.get_node(b.node,!0).children(".jstree-wholerow")["hover_node"===a.type?"addClass":"removeClass"]("jstree-wholerow-hovered")},this)).on("contextmenu.jstree",".jstree-wholerow",a.proxy(function(b){if(this._data.contextmenu){b.preventDefault();var c=a.Event("contextmenu",{metaKey:b.metaKey,ctrlKey:b.ctrlKey,altKey:b.altKey,shiftKey:b.shiftKey,pageX:b.pageX,pageY:b.pageY});a(b.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(c)}},this)).on("click.jstree",".jstree-wholerow",function(b){b.stopImmediatePropagation();var c=a.Event("click",{metaKey:b.metaKey,ctrlKey:b.ctrlKey,altKey:b.altKey,shiftKey:b.shiftKey});a(b.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(c).focus()}).on("dblclick.jstree",".jstree-wholerow",function(b){b.stopImmediatePropagation();var c=a.Event("dblclick",{metaKey:b.metaKey,ctrlKey:b.ctrlKey,altKey:b.altKey,shiftKey:b.shiftKey});a(b.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(c).focus()}).on("click.jstree",".jstree-leaf > .jstree-ocl",a.proxy(function(b){b.stopImmediatePropagation();var c=a.Event("click",{metaKey:b.metaKey,ctrlKey:b.ctrlKey,altKey:b.altKey,shiftKey:b.shiftKey});a(b.currentTarget).closest(".jstree-node").children(".jstree-anchor").first().trigger(c).focus()},this)).on("mouseover.jstree",".jstree-wholerow, .jstree-icon",a.proxy(function(a){return a.stopImmediatePropagation(),this.is_disabled(a.currentTarget)||this.hover_node(a.currentTarget),!1},this)).on("mouseleave.jstree",".jstree-node",a.proxy(function(a){this.dehover_node(a.currentTarget)},this))},this.teardown=function(){this.settings.wholerow&&this.element.find(".jstree-wholerow").remove(),c.teardown.call(this)},this.redraw_node=function(b,d,e,f){if(b=c.redraw_node.apply(this,arguments)){var g=n.cloneNode(!0);-1!==a.inArray(b.id,this._data.core.selected)&&(g.className+=" jstree-wholerow-clicked"),this._data.core.focused&&this._data.core.focused===b.id&&(g.className+=" jstree-wholerow-hovered"),b.insertBefore(g,b.childNodes[0])}return b}},i.registerElement&&Object&&Object.create){var o=Object.create(HTMLElement.prototype);o.createdCallback=function(){var b={core:{},plugins:[]},c;for(c in a.jstree.plugins)a.jstree.plugins.hasOwnProperty(c)&&this.attributes[c]&&(b.plugins.push(c),this.getAttribute(c)&&JSON.parse(this.getAttribute(c))&&(b[c]=JSON.parse(this.getAttribute(c))));for(c in a.jstree.defaults.core)a.jstree.defaults.core.hasOwnProperty(c)&&this.attributes[c]&&(b.core[c]=JSON.parse(this.getAttribute(c))||this.getAttribute(c));a(this).jstree(b)};try{i.registerElement("vakata-jstree",{prototype:o})}catch(p){}}}});
1
+ /*! jsTree - v3.3.7 - 2018-11-06 - (MIT) */
2
+ !function(a){"use strict";"function"==typeof define&&define.amd?define(["jquery"],a):"undefined"!=typeof module&&module.exports?module.exports=a(require("jquery")):a(jQuery)}(function(a,b){"use strict";if(!a.jstree){var c=0,d=!1,e=!1,f=!1,g=[],h=a("script:last").attr("src"),i=window.document;a.jstree={version:"3.3.7",defaults:{plugins:[]},plugins:{},path:h&&-1!==h.indexOf("/")?h.replace(/\/[^\/]+$/,""):"",idregex:/[\\:&!^|()\[\]<>@*'+~#";.,=\- \/${}%?`]/g,root:"#"},a.jstree.create=function(b,d){var e=new a.jstree.core(++c),f=d;return d=a.extend(!0,{},a.jstree.defaults,d),f&&f.plugins&&(d.plugins=f.plugins),a.each(d.plugins,function(a,b){"core"!==a&&(e=e.plugin(b,d[b]))}),a(b).data("jstree",e),e.init(b,d),e},a.jstree.destroy=function(){a(".jstree:jstree").jstree("destroy"),a(i).off(".jstree")},a.jstree.core=function(a){this._id=a,this._cnt=0,this._wrk=null,this._data={core:{themes:{name:!1,dots:!1,icons:!1,ellipsis:!1},selected:[],last_error:{},working:!1,worker_queue:[],focused:null}}},a.jstree.reference=function(b){var c=null,d=null;if(!b||!b.id||b.tagName&&b.nodeType||(b=b.id),!d||!d.length)try{d=a(b)}catch(e){}if(!d||!d.length)try{d=a("#"+b.replace(a.jstree.idregex,"\\$&"))}catch(e){}return d&&d.length&&(d=d.closest(".jstree")).length&&(d=d.data("jstree"))?c=d:a(".jstree").each(function(){var d=a(this).data("jstree");return d&&d._model.data[b]?(c=d,!1):void 0}),c},a.fn.jstree=function(c){var d="string"==typeof c,e=Array.prototype.slice.call(arguments,1),f=null;return c!==!0||this.length?(this.each(function(){var g=a.jstree.reference(this),h=d&&g?g[c]:null;return f=d&&h?h.apply(g,e):null,g||d||c!==b&&!a.isPlainObject(c)||a.jstree.create(this,c),(g&&!d||c===!0)&&(f=g||!1),null!==f&&f!==b?!1:void 0}),null!==f&&f!==b?f:this):!1},a.expr.pseudos.jstree=a.expr.createPseudo(function(c){return function(c){return a(c).hasClass("jstree")&&a(c).data("jstree")!==b}}),a.jstree.defaults.core={data:!1,strings:!1,check_callback:!1,error:a.noop,animation:200,multiple:!0,themes:{name:!1,url:!1,dir:!1,dots:!0,icons:!0,ellipsis:!1,stripes:!1,variant:!1,responsive:!1},expand_selected_onload:!0,worker:!0,force_text:!1,dblclick_toggle:!0,loaded_state:!1,restore_focus:!0,keyboard:{"ctrl-space":function(b){b.type="click",a(b.currentTarget).trigger(b)},enter:function(b){b.type="click",a(b.currentTarget).trigger(b)},left:function(b){if(b.preventDefault(),this.is_open(b.currentTarget))this.close_node(b.currentTarget);else{var c=this.get_parent(b.currentTarget);c&&c.id!==a.jstree.root&&this.get_node(c,!0).children(".jstree-anchor").focus()}},up:function(a){a.preventDefault();var b=this.get_prev_dom(a.currentTarget);b&&b.length&&b.children(".jstree-anchor").focus()},right:function(b){if(b.preventDefault(),this.is_closed(b.currentTarget))this.open_node(b.currentTarget,function(a){this.get_node(a,!0).children(".jstree-anchor").focus()});else if(this.is_open(b.currentTarget)){var c=this.get_node(b.currentTarget,!0).children(".jstree-children")[0];c&&a(this._firstChild(c)).children(".jstree-anchor").focus()}},down:function(a){a.preventDefault();var b=this.get_next_dom(a.currentTarget);b&&b.length&&b.children(".jstree-anchor").focus()},"*":function(a){this.open_all()},home:function(b){b.preventDefault();var c=this._firstChild(this.get_container_ul()[0]);c&&a(c).children(".jstree-anchor").filter(":visible").focus()},end:function(a){a.preventDefault(),this.element.find(".jstree-anchor").filter(":visible").last().focus()},f2:function(a){a.preventDefault(),this.edit(a.currentTarget)}}},a.jstree.core.prototype={plugin:function(b,c){var d=a.jstree.plugins[b];return d?(this._data[b]={},d.prototype=this,new d(c,this)):this},init:function(b,c){this._model={data:{},changed:[],force_full_redraw:!1,redraw_timeout:!1,default_state:{loaded:!0,opened:!1,selected:!1,disabled:!1}},this._model.data[a.jstree.root]={id:a.jstree.root,parent:null,parents:[],children:[],children_d:[],state:{loaded:!1}},this.element=a(b).addClass("jstree jstree-"+this._id),this.settings=c,this._data.core.ready=!1,this._data.core.loaded=!1,this._data.core.rtl="rtl"===this.element.css("direction"),this.element[this._data.core.rtl?"addClass":"removeClass"]("jstree-rtl"),this.element.attr("role","tree"),this.settings.core.multiple&&this.element.attr("aria-multiselectable",!0),this.element.attr("tabindex")||this.element.attr("tabindex","0"),this.bind(),this.trigger("init"),this._data.core.original_container_html=this.element.find(" > ul > li").clone(!0),this._data.core.original_container_html.find("li").addBack().contents().filter(function(){return 3===this.nodeType&&(!this.nodeValue||/^\s+$/.test(this.nodeValue))}).remove(),this.element.html("<ul class='jstree-container-ul jstree-children' role='group'><li id='j"+this._id+"_loading' class='jstree-initial-node jstree-loading jstree-leaf jstree-last' role='tree-item'><i class='jstree-icon jstree-ocl'></i><a class='jstree-anchor' href='#'><i class='jstree-icon jstree-themeicon-hidden'></i>"+this.get_string("Loading ...")+"</a></li></ul>"),this.element.attr("aria-activedescendant","j"+this._id+"_loading"),this._data.core.li_height=this.get_container_ul().children("li").first().outerHeight()||24,this._data.core.node=this._create_prototype_node(),this.trigger("loading"),this.load_node(a.jstree.root)},destroy:function(a){if(this.trigger("destroy"),this._wrk)try{window.URL.revokeObjectURL(this._wrk),this._wrk=null}catch(b){}a||this.element.empty(),this.teardown()},_create_prototype_node:function(){var a=i.createElement("LI"),b,c;return a.setAttribute("role","treeitem"),b=i.createElement("I"),b.className="jstree-icon jstree-ocl",b.setAttribute("role","presentation"),a.appendChild(b),b=i.createElement("A"),b.className="jstree-anchor",b.setAttribute("href","#"),b.setAttribute("tabindex","-1"),c=i.createElement("I"),c.className="jstree-icon jstree-themeicon",c.setAttribute("role","presentation"),b.appendChild(c),a.appendChild(b),b=c=null,a},_kbevent_to_func:function(a){var b={8:"Backspace",9:"Tab",13:"Return",19:"Pause",27:"Esc",32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"Print",45:"Insert",46:"Delete",96:"Numpad0",97:"Numpad1",98:"Numpad2",99:"Numpad3",100:"Numpad4",101:"Numpad5",102:"Numpad6",103:"Numpad7",104:"Numpad8",105:"Numpad9","-13":"NumpadEnter",112:"F1",113:"F2",114:"F3",115:"F4",116:"F5",117:"F6",118:"F7",119:"F8",120:"F9",121:"F10",122:"F11",123:"F12",144:"Numlock",145:"Scrolllock",16:"Shift",17:"Ctrl",18:"Alt",48:"0",49:"1",50:"2",51:"3",52:"4",53:"5",54:"6",55:"7",56:"8",57:"9",59:";",61:"=",65:"a",66:"b",67:"c",68:"d",69:"e",70:"f",71:"g",72:"h",73:"i",74:"j",75:"k",76:"l",77:"m",78:"n",79:"o",80:"p",81:"q",82:"r",83:"s",84:"t",85:"u",86:"v",87:"w",88:"x",89:"y",90:"z",107:"+",109:"-",110:".",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",111:"/",106:"*",173:"-"},c=[];a.ctrlKey&&c.push("ctrl"),a.altKey&&c.push("alt"),a.shiftKey&&c.push("shift"),c.push(b[a.which]||a.which),c=c.sort().join("-").toLowerCase();var d=this.settings.core.keyboard,e,f;for(e in d)if(d.hasOwnProperty(e)&&(f=e,"-"!==f&&"+"!==f&&(f=f.replace("--","-MINUS").replace("+-","-MINUS").replace("++","-PLUS").replace("-+","-PLUS"),f=f.split(/-|\+/).sort().join("-").replace("MINUS","-").replace("PLUS","+").toLowerCase()),f===c))return d[e];return null},teardown:function(){this.unbind(),this.element.removeClass("jstree").removeData("jstree").find("[class^='jstree']").addBack().attr("class",function(){return this.className.replace(/jstree[^ ]*|$/gi,"")}),this.element=null},bind:function(){var b="",c=null,d=0;this.element.on("dblclick.jstree",function(a){if(a.target.tagName&&"input"===a.target.tagName.toLowerCase())return!0;if(i.selection&&i.selection.empty)i.selection.empty();else if(window.getSelection){var b=window.getSelection();try{b.removeAllRanges(),b.collapse()}catch(c){}}}).on("mousedown.jstree",a.proxy(function(a){a.target===this.element[0]&&(a.preventDefault(),d=+new Date)},this)).on("mousedown.jstree",".jstree-ocl",function(a){a.preventDefault()}).on("click.jstree",".jstree-ocl",a.proxy(function(a){this.toggle_node(a.target)},this)).on("dblclick.jstree",".jstree-anchor",a.proxy(function(a){return a.target.tagName&&"input"===a.target.tagName.toLowerCase()?!0:void(this.settings.core.dblclick_toggle&&this.toggle_node(a.target))},this)).on("click.jstree",".jstree-anchor",a.proxy(function(b){b.preventDefault(),b.currentTarget!==i.activeElement&&a(b.currentTarget).focus(),this.activate_node(b.currentTarget,b)},this)).on("keydown.jstree",".jstree-anchor",a.proxy(function(a){if(a.target.tagName&&"input"===a.target.tagName.toLowerCase())return!0;this._data.core.rtl&&(37===a.which?a.which=39:39===a.which&&(a.which=37));var b=this._kbevent_to_func(a);if(b){var c=b.call(this,a);if(c===!1||c===!0)return c}},this)).on("load_node.jstree",a.proxy(function(b,c){c.status&&(c.node.id!==a.jstree.root||this._data.core.loaded||(this._data.core.loaded=!0,this._firstChild(this.get_container_ul()[0])&&this.element.attr("aria-activedescendant",this._firstChild(this.get_container_ul()[0]).id),this.trigger("loaded")),this._data.core.ready||setTimeout(a.proxy(function(){if(this.element&&!this.get_container_ul().find(".jstree-loading").length){if(this._data.core.ready=!0,this._data.core.selected.length){if(this.settings.core.expand_selected_onload){var b=[],c,d;for(c=0,d=this._data.core.selected.length;d>c;c++)b=b.concat(this._model.data[this._data.core.selected[c]].parents);for(b=a.vakata.array_unique(b),c=0,d=b.length;d>c;c++)this.open_node(b[c],!1,0)}this.trigger("changed",{action:"ready",selected:this._data.core.selected})}this.trigger("ready")}},this),0))},this)).on("keypress.jstree",a.proxy(function(d){if(d.target.tagName&&"input"===d.target.tagName.toLowerCase())return!0;c&&clearTimeout(c),c=setTimeout(function(){b=""},500);var e=String.fromCharCode(d.which).toLowerCase(),f=this.element.find(".jstree-anchor").filter(":visible"),g=f.index(i.activeElement)||0,h=!1;if(b+=e,b.length>1){if(f.slice(g).each(a.proxy(function(c,d){return 0===a(d).text().toLowerCase().indexOf(b)?(a(d).focus(),h=!0,!1):void 0},this)),h)return;if(f.slice(0,g).each(a.proxy(function(c,d){return 0===a(d).text().toLowerCase().indexOf(b)?(a(d).focus(),h=!0,!1):void 0},this)),h)return}if(new RegExp("^"+e.replace(/[-\/\\^$*+?.()|[\]{}]/g,"\\$&")+"+$").test(b)){if(f.slice(g+1).each(a.proxy(function(b,c){return a(c).text().toLowerCase().charAt(0)===e?(a(c).focus(),h=!0,!1):void 0},this)),h)return;if(f.slice(0,g+1).each(a.proxy(function(b,c){return a(c).text().toLowerCase().charAt(0)===e?(a(c).focus(),h=!0,!1):void 0},this)),h)return}},this)).on("init.jstree",a.proxy(function(){var a=this.settings.core.themes;this._data.core.themes.dots=a.dots,this._data.core.themes.stripes=a.stripes,this._data.core.themes.icons=a.icons,this._data.core.themes.ellipsis=a.ellipsis,this.set_theme(a.name||"default",a.url),this.set_theme_variant(a.variant)},this)).on("loading.jstree",a.proxy(function(){this[this._data.core.themes.dots?"show_dots":"hide_dots"](),this[this._data.core.themes.icons?"show_icons":"hide_icons"](),this[this._data.core.themes.stripes?"show_stripes":"hide_stripes"](),this[this._data.core.themes.ellipsis?"show_ellipsis":"hide_ellipsis"]()},this)).on("blur.jstree",".jstree-anchor",a.proxy(function(b){this._data.core.focused=null,a(b.currentTarget).filter(".jstree-hovered").mouseleave(),this.element.attr("tabindex","0")},this)).on("focus.jstree",".jstree-anchor",a.proxy(function(b){var c=this.get_node(b.currentTarget);c&&c.id&&(this._data.core.focused=c.id),this.element.find(".jstree-hovered").not(b.currentTarget).mouseleave(),a(b.currentTarget).mouseenter(),this.element.attr("tabindex","-1")},this)).on("focus.jstree",a.proxy(function(){if(+new Date-d>500&&!this._data.core.focused&&this.settings.core.restore_focus){d=0;var a=this.get_node(this.element.attr("aria-activedescendant"),!0);a&&a.find("> .jstree-anchor").focus()}},this)).on("mouseenter.jstree",".jstree-anchor",a.proxy(function(a){this.hover_node(a.currentTarget)},this)).on("mouseleave.jstree",".jstree-anchor",a.proxy(function(a){this.dehover_node(a.currentTarget)},this))},unbind:function(){this.element.off(".jstree"),a(i).off(".jstree-"+this._id)},trigger:function(a,b){b||(b={}),b.instance=this,this.element.triggerHandler(a.replace(".jstree","")+".jstree",b)},get_container:function(){return this.element},get_container_ul:function(){return this.element.children(".jstree-children").first()},get_string:function(b){var c=this.settings.core.strings;return a.isFunction(c)?c.call(this,b):c&&c[b]?c[b]:b},_firstChild:function(a){a=a?a.firstChild:null;while(null!==a&&1!==a.nodeType)a=a.nextSibling;return a},_nextSibling:function(a){a=a?a.nextSibling:null;while(null!==a&&1!==a.nodeType)a=a.nextSibling;return a},_previousSibling:function(a){a=a?a.previousSibling:null;while(null!==a&&1!==a.nodeType)a=a.previousSibling;return a},get_node:function(b,c){b&&b.id&&(b=b.id),b instanceof jQuery&&b.length&&b[0].id&&(b=b[0].id);var d;try{if(this._model.data[b])b=this._model.data[b];else if("string"==typeof b&&this._model.data[b.replace(/^#/,"")])b=this._model.data[b.replace(/^#/,"")];else if("string"==typeof b&&(d=a("#"+b.replace(a.jstree.idregex,"\\$&"),this.element)).length&&this._model.data[d.closest(".jstree-node").attr("id")])b=this._model.data[d.closest(".jstree-node").attr("id")];else if((d=this.element.find(b)).length&&this._model.data[d.closest(".jstree-node").attr("id")])b=this._model.data[d.closest(".jstree-node").attr("id")];else{if(!(d=this.element.find(b)).length||!d.hasClass("jstree"))return!1;b=this._model.data[a.jstree.root]}return c&&(b=b.id===a.jstree.root?this.element:a("#"+b.id.replace(a.jstree.idregex,"\\$&"),this.element)),b}catch(e){return!1}},get_path:function(b,c,d){if(b=b.parents?b:this.get_node(b),!b||b.id===a.jstree.root||!b.parents)return!1;var e,f,g=[];for(g.push(d?b.id:b.text),e=0,f=b.parents.length;f>e;e++)g.push(d?b.parents[e]:this.get_text(b.parents[e]));return g=g.reverse().slice(1),c?g.join(c):g},get_next_dom:function(b,c){var d;if(b=this.get_node(b,!0),b[0]===this.element[0]){d=this._firstChild(this.get_container_ul()[0]);while(d&&0===d.offsetHeight)d=this._nextSibling(d);return d?a(d):!1}if(!b||!b.length)return!1;if(c){d=b[0];do d=this._nextSibling(d);while(d&&0===d.offsetHeight);return d?a(d):!1}if(b.hasClass("jstree-open")){d=this._firstChild(b.children(".jstree-children")[0]);while(d&&0===d.offsetHeight)d=this._nextSibling(d);if(null!==d)return a(d)}d=b[0];do d=this._nextSibling(d);while(d&&0===d.offsetHeight);return null!==d?a(d):b.parentsUntil(".jstree",".jstree-node").nextAll(".jstree-node:visible").first()},get_prev_dom:function(b,c){var d;if(b=this.get_node(b,!0),b[0]===this.element[0]){d=this.get_container_ul()[0].lastChild;while(d&&0===d.offsetHeight)d=this._previousSibling(d);return d?a(d):!1}if(!b||!b.length)return!1;if(c){d=b[0];do d=this._previousSibling(d);while(d&&0===d.offsetHeight);return d?a(d):!1}d=b[0];do d=this._previousSibling(d);while(d&&0===d.offsetHeight);if(null!==d){b=a(d);while(b.hasClass("jstree-open"))b=b.children(".jstree-children").first().children(".jstree-node:visible:last");return b}return d=b[0].parentNode.parentNode,d&&d.className&&-1!==d.className.indexOf("jstree-node")?a(d):!1},get_parent:function(b){return b=this.get_node(b),b&&b.id!==a.jstree.root?b.parent:!1},get_children_dom:function(a){return a=this.get_node(a,!0),a[0]===this.element[0]?this.get_container_ul().children(".jstree-node"):a&&a.length?a.children(".jstree-children").children(".jstree-node"):!1},is_parent:function(a){return a=this.get_node(a),a&&(a.state.loaded===!1||a.children.length>0)},is_loaded:function(a){return a=this.get_node(a),a&&a.state.loaded},is_loading:function(a){return a=this.get_node(a),a&&a.state&&a.state.loading},is_open:function(a){return a=this.get_node(a),a&&a.state.opened},is_closed:function(a){return a=this.get_node(a),a&&this.is_parent(a)&&!a.state.opened},is_leaf:function(a){return!this.is_parent(a)},load_node:function(b,c){var d,e,f,g,h;if(a.isArray(b))return this._load_nodes(b.slice(),c),!0;if(b=this.get_node(b),!b)return c&&c.call(this,b,!1),!1;if(b.state.loaded){for(b.state.loaded=!1,f=0,g=b.parents.length;g>f;f++)this._model.data[b.parents[f]].children_d=a.vakata.array_filter(this._model.data[b.parents[f]].children_d,function(c){return-1===a.inArray(c,b.children_d)});for(d=0,e=b.children_d.length;e>d;d++)this._model.data[b.children_d[d]].state.selected&&(h=!0),delete this._model.data[b.children_d[d]];h&&(this._data.core.selected=a.vakata.array_filter(this._data.core.selected,function(c){return-1===a.inArray(c,b.children_d)})),b.children=[],b.children_d=[],h&&this.trigger("changed",{action:"load_node",node:b,selected:this._data.core.selected})}return b.state.failed=!1,b.state.loading=!0,this.get_node(b,!0).addClass("jstree-loading").attr("aria-busy",!0),this._load_node(b,a.proxy(function(a){b=this._model.data[b.id],b.state.loading=!1,b.state.loaded=a,b.state.failed=!b.state.loaded;var d=this.get_node(b,!0),e=0,f=0,g=this._model.data,h=!1;for(e=0,f=b.children.length;f>e;e++)if(g[b.children[e]]&&!g[b.children[e]].state.hidden){h=!0;break}b.state.loaded&&d&&d.length&&(d.removeClass("jstree-closed jstree-open jstree-leaf"),h?"#"!==b.id&&d.addClass(b.state.opened?"jstree-open":"jstree-closed"):d.addClass("jstree-leaf")),d.removeClass("jstree-loading").attr("aria-busy",!1),this.trigger("load_node",{node:b,status:a}),c&&c.call(this,b,a)},this)),!0},_load_nodes:function(a,b,c,d){var e=!0,f=function(){this._load_nodes(a,b,!0)},g=this._model.data,h,i,j=[];for(h=0,i=a.length;i>h;h++)g[a[h]]&&(!g[a[h]].state.loaded&&!g[a[h]].state.failed||!c&&d)&&(this.is_loading(a[h])||this.load_node(a[h],f),e=!1);if(e){for(h=0,i=a.length;i>h;h++)g[a[h]]&&g[a[h]].state.loaded&&j.push(a[h]);b&&!b.done&&(b.call(this,j),b.done=!0)}},load_all:function(b,c){if(b||(b=a.jstree.root),b=this.get_node(b),!b)return!1;var d=[],e=this._model.data,f=e[b.id].children_d,g,h;for(b.state&&!b.state.loaded&&d.push(b.id),g=0,h=f.length;h>g;g++)e[f[g]]&&e[f[g]].state&&!e[f[g]].state.loaded&&d.push(f[g]);d.length?this._load_nodes(d,function(){this.load_all(b,c)}):(c&&c.call(this,b),this.trigger("load_all",{node:b}))},_load_node:function(b,c){var d=this.settings.core.data,e,f=function g(){return 3!==this.nodeType&&8!==this.nodeType};return d?a.isFunction(d)?d.call(this,b,a.proxy(function(d){d===!1?c.call(this,!1):this["string"==typeof d?"_append_html_data":"_append_json_data"](b,"string"==typeof d?a(a.parseHTML(d)).filter(f):d,function(a){c.call(this,a)})},this)):"object"==typeof d?d.url?(d=a.extend(!0,{},d),a.isFunction(d.url)&&(d.url=d.url.call(this,b)),a.isFunction(d.data)&&(d.data=d.data.call(this,b)),a.ajax(d).done(a.proxy(function(d,e,g){var h=g.getResponseHeader("Content-Type");return h&&-1!==h.indexOf("json")||"object"==typeof d?this._append_json_data(b,d,function(a){c.call(this,a)}):h&&-1!==h.indexOf("html")||"string"==typeof d?this._append_html_data(b,a(a.parseHTML(d)).filter(f),function(a){c.call(this,a)}):(this._data.core.last_error={error:"ajax",plugin:"core",id:"core_04",reason:"Could not load node",data:JSON.stringify({id:b.id,xhr:g})},this.settings.core.error.call(this,this._data.core.last_error),c.call(this,!1))},this)).fail(a.proxy(function(a){this._data.core.last_error={error:"ajax",plugin:"core",id:"core_04",reason:"Could not load node",data:JSON.stringify({id:b.id,xhr:a})},c.call(this,!1),this.settings.core.error.call(this,this._data.core.last_error)},this))):(e=a.isArray(d)?a.extend(!0,[],d):a.isPlainObject(d)?a.extend(!0,{},d):d,b.id===a.jstree.root?this._append_json_data(b,e,function(a){c.call(this,a)}):(this._data.core.last_error={error:"nodata",plugin:"core",id:"core_05",reason:"Could not load node",data:JSON.stringify({id:b.id})},this.settings.core.error.call(this,this._data.core.last_error),c.call(this,!1))):"string"==typeof d?b.id===a.jstree.root?this._append_html_data(b,a(a.parseHTML(d)).filter(f),function(a){c.call(this,a)}):(this._data.core.last_error={error:"nodata",plugin:"core",id:"core_06",reason:"Could not load node",data:JSON.stringify({id:b.id})},this.settings.core.error.call(this,this._data.core.last_error),c.call(this,!1)):c.call(this,!1):b.id===a.jstree.root?this._append_html_data(b,this._data.core.original_container_html.clone(!0),function(a){c.call(this,a)}):c.call(this,!1)},_node_changed:function(b){b=this.get_node(b),b&&-1===a.inArray(b.id,this._model.changed)&&this._model.changed.push(b.id)},_append_html_data:function(b,c,d){b=this.get_node(b),b.children=[],b.children_d=[];var e=c.is("ul")?c.children():c,f=b.id,g=[],h=[],i=this._model.data,j=i[f],k=this._data.core.selected.length,l,m,n;for(e.each(a.proxy(function(b,c){l=this._parse_model_from_html(a(c),f,j.parents.concat()),l&&(g.push(l),h.push(l),i[l].children_d.length&&(h=h.concat(i[l].children_d)))},this)),j.children=g,j.children_d=h,m=0,n=j.parents.length;n>m;m++)i[j.parents[m]].children_d=i[j.parents[m]].children_d.concat(h);this.trigger("model",{nodes:h,parent:f}),f!==a.jstree.root?(this._node_changed(f),this.redraw()):(this.get_container_ul().children(".jstree-initial-node").remove(),this.redraw(!0)),this._data.core.selected.length!==k&&this.trigger("changed",{action:"model",selected:this._data.core.selected}),d.call(this,!0)},_append_json_data:function(b,c,d,e){if(null!==this.element){b=this.get_node(b),b.children=[],b.children_d=[],c.d&&(c=c.d,"string"==typeof c&&(c=JSON.parse(c))),a.isArray(c)||(c=[c]);var f=null,g={df:this._model.default_state,dat:c,par:b.id,m:this._model.data,t_id:this._id,t_cnt:this._cnt,sel:this._data.core.selected},h=function(a,b){a.data&&(a=a.data);var c=a.dat,d=a.par,e=[],f=[],g=[],h=a.df,i=a.t_id,j=a.t_cnt,k=a.m,l=k[d],m=a.sel,n,o,p,q,r=function(a,c,d){d=d?d.concat():[],c&&d.unshift(c);var e=a.id.toString(),f,i,j,l,m={id:e,text:a.text||"",icon:a.icon!==b?a.icon:!0,parent:c,parents:d,children:a.children||[],children_d:a.children_d||[],data:a.data,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1};for(f in h)h.hasOwnProperty(f)&&(m.state[f]=h[f]);if(a&&a.data&&a.data.jstree&&a.data.jstree.icon&&(m.icon=a.data.jstree.icon),(m.icon===b||null===m.icon||""===m.icon)&&(m.icon=!0),a&&a.data&&(m.data=a.data,a.data.jstree))for(f in a.data.jstree)a.data.jstree.hasOwnProperty(f)&&(m.state[f]=a.data.jstree[f]);if(a&&"object"==typeof a.state)for(f in a.state)a.state.hasOwnProperty(f)&&(m.state[f]=a.state[f]);if(a&&"object"==typeof a.li_attr)for(f in a.li_attr)a.li_attr.hasOwnProperty(f)&&(m.li_attr[f]=a.li_attr[f]);if(m.li_attr.id||(m.li_attr.id=e),a&&"object"==typeof a.a_attr)for(f in a.a_attr)a.a_attr.hasOwnProperty(f)&&(m.a_attr[f]=a.a_attr[f]);for(a&&a.children&&a.children===!0&&(m.state.loaded=!1,m.children=[],m.children_d=[]),k[m.id]=m,f=0,i=m.children.length;i>f;f++)j=r(k[m.children[f]],m.id,d),l=k[j],m.children_d.push(j),l.children_d.length&&(m.children_d=m.children_d.concat(l.children_d));return delete a.data,delete a.children,k[m.id].original=a,m.state.selected&&g.push(m.id),m.id},s=function(a,c,d){d=d?d.concat():[],c&&d.unshift(c);var e=!1,f,l,m,n,o;do e="j"+i+"_"+ ++j;while(k[e]);o={id:!1,text:"string"==typeof a?a:"",icon:"object"==typeof a&&a.icon!==b?a.icon:!0,parent:c,parents:d,children:[],children_d:[],data:null,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1};for(f in h)h.hasOwnProperty(f)&&(o.state[f]=h[f]);if(a&&a.id&&(o.id=a.id.toString()),a&&a.text&&(o.text=a.text),a&&a.data&&a.data.jstree&&a.data.jstree.icon&&(o.icon=a.data.jstree.icon),(o.icon===b||null===o.icon||""===o.icon)&&(o.icon=!0),a&&a.data&&(o.data=a.data,a.data.jstree))for(f in a.data.jstree)a.data.jstree.hasOwnProperty(f)&&(o.state[f]=a.data.jstree[f]);if(a&&"object"==typeof a.state)for(f in a.state)a.state.hasOwnProperty(f)&&(o.state[f]=a.state[f]);if(a&&"object"==typeof a.li_attr)for(f in a.li_attr)a.li_attr.hasOwnProperty(f)&&(o.li_attr[f]=a.li_attr[f]);if(o.li_attr.id&&!o.id&&(o.id=o.li_attr.id.toString()),o.id||(o.id=e),o.li_attr.id||(o.li_attr.id=o.id),a&&"object"==typeof a.a_attr)for(f in a.a_attr)a.a_attr.hasOwnProperty(f)&&(o.a_attr[f]=a.a_attr[f]);if(a&&a.children&&a.children.length){for(f=0,l=a.children.length;l>f;f++)m=s(a.children[f],o.id,d),n=k[m],o.children.push(m),n.children_d.length&&(o.children_d=o.children_d.concat(n.children_d));o.children_d=o.children_d.concat(o.children)}return a&&a.children&&a.children===!0&&(o.state.loaded=!1,o.children=[],o.children_d=[]),delete a.data,delete a.children,o.original=a,k[o.id]=o,o.state.selected&&g.push(o.id),o.id};if(c.length&&c[0].id!==b&&c[0].parent!==b){for(o=0,p=c.length;p>o;o++)c[o].children||(c[o].children=[]),c[o].state||(c[o].state={}),k[c[o].id.toString()]=c[o];for(o=0,p=c.length;p>o;o++)k[c[o].parent.toString()]?(k[c[o].parent.toString()].children.push(c[o].id.toString()),l.children_d.push(c[o].id.toString())):(this._data.core.last_error={error:"parse",plugin:"core",id:"core_07",reason:"Node with invalid parent",data:JSON.stringify({id:c[o].id.toString(),parent:c[o].parent.toString()})},this.settings.core.error.call(this,this._data.core.last_error));for(o=0,p=l.children.length;p>o;o++)n=r(k[l.children[o]],d,l.parents.concat()),f.push(n),k[n].children_d.length&&(f=f.concat(k[n].children_d));for(o=0,p=l.parents.length;p>o;o++)k[l.parents[o]].children_d=k[l.parents[o]].children_d.concat(f);q={cnt:j,mod:k,sel:m,par:d,dpc:f,add:g}}else{for(o=0,p=c.length;p>o;o++)n=s(c[o],d,l.parents.concat()),n&&(e.push(n),f.push(n),k[n].children_d.length&&(f=f.concat(k[n].children_d)));for(l.children=e,l.children_d=f,o=0,p=l.parents.length;p>o;o++)k[l.parents[o]].children_d=k[l.parents[o]].children_d.concat(f);q={cnt:j,mod:k,sel:m,par:d,dpc:f,add:g}}return"undefined"!=typeof window&&"undefined"!=typeof window.document?q:void postMessage(q)},i=function(b,c){if(null!==this.element){this._cnt=b.cnt;var e,f=this._model.data;for(e in f)f.hasOwnProperty(e)&&f[e].state&&f[e].state.loading&&b.mod[e]&&(b.mod[e].state.loading=!0);if(this._model.data=b.mod,c){var g,h=b.add,i=b.sel,j=this._data.core.selected.slice();if(f=this._model.data,i.length!==j.length||a.vakata.array_unique(i.concat(j)).length!==i.length){for(e=0,g=i.length;g>e;e++)-1===a.inArray(i[e],h)&&-1===a.inArray(i[e],j)&&(f[i[e]].state.selected=!1);for(e=0,g=j.length;g>e;e++)-1===a.inArray(j[e],i)&&(f[j[e]].state.selected=!0)}}b.add.length&&(this._data.core.selected=this._data.core.selected.concat(b.add)),this.trigger("model",{nodes:b.dpc,parent:b.par}),b.par!==a.jstree.root?(this._node_changed(b.par),this.redraw()):this.redraw(!0),b.add.length&&this.trigger("changed",{action:"model",selected:this._data.core.selected}),d.call(this,!0)}};if(this.settings.core.worker&&window.Blob&&window.URL&&window.Worker)try{null===this._wrk&&(this._wrk=window.URL.createObjectURL(new window.Blob(["self.onmessage = "+h.toString()],{type:"text/javascript"}))),!this._data.core.working||e?(this._data.core.working=!0,f=new window.Worker(this._wrk),f.onmessage=a.proxy(function(a){i.call(this,a.data,!0);try{f.terminate(),f=null}catch(b){}this._data.core.worker_queue.length?this._append_json_data.apply(this,this._data.core.worker_queue.shift()):this._data.core.working=!1},this),g.par?f.postMessage(g):this._data.core.worker_queue.length?this._append_json_data.apply(this,this._data.core.worker_queue.shift()):this._data.core.working=!1):this._data.core.worker_queue.push([b,c,d,!0])}catch(j){i.call(this,h(g),!1),this._data.core.worker_queue.length?this._append_json_data.apply(this,this._data.core.worker_queue.shift()):this._data.core.working=!1}else i.call(this,h(g),!1)}},_parse_model_from_html:function(c,d,e){e=e?[].concat(e):[],d&&e.unshift(d);var f,g,h=this._model.data,i={id:!1,text:!1,icon:!0,parent:d,parents:e,children:[],children_d:[],data:null,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1},j,k,l;for(j in this._model.default_state)this._model.default_state.hasOwnProperty(j)&&(i.state[j]=this._model.default_state[j]);if(k=a.vakata.attributes(c,!0),a.each(k,function(b,c){return c=a.trim(c),c.length?(i.li_attr[b]=c,void("id"===b&&(i.id=c.toString()))):!0}),k=c.children("a").first(),k.length&&(k=a.vakata.attributes(k,!0),a.each(k,function(b,c){c=a.trim(c),c.length&&(i.a_attr[b]=c)})),k=c.children("a").first().length?c.children("a").first().clone():c.clone(),k.children("ins, i, ul").remove(),k=k.html(),k=a("<div />").html(k),i.text=this.settings.core.force_text?k.text():k.html(),k=c.data(),i.data=k?a.extend(!0,{},k):null,i.state.opened=c.hasClass("jstree-open"),i.state.selected=c.children("a").hasClass("jstree-clicked"),i.state.disabled=c.children("a").hasClass("jstree-disabled"),i.data&&i.data.jstree)for(j in i.data.jstree)i.data.jstree.hasOwnProperty(j)&&(i.state[j]=i.data.jstree[j]);k=c.children("a").children(".jstree-themeicon"),k.length&&(i.icon=k.hasClass("jstree-themeicon-hidden")?!1:k.attr("rel")),i.state.icon!==b&&(i.icon=i.state.icon),(i.icon===b||null===i.icon||""===i.icon)&&(i.icon=!0),k=c.children("ul").children("li");do l="j"+this._id+"_"+ ++this._cnt;while(h[l]);return i.id=i.li_attr.id?i.li_attr.id.toString():l,k.length?(k.each(a.proxy(function(b,c){f=this._parse_model_from_html(a(c),i.id,e),g=this._model.data[f],i.children.push(f),g.children_d.length&&(i.children_d=i.children_d.concat(g.children_d))},this)),i.children_d=i.children_d.concat(i.children)):c.hasClass("jstree-closed")&&(i.state.loaded=!1),i.li_attr["class"]&&(i.li_attr["class"]=i.li_attr["class"].replace("jstree-closed","").replace("jstree-open","")),i.a_attr["class"]&&(i.a_attr["class"]=i.a_attr["class"].replace("jstree-clicked","").replace("jstree-disabled","")),h[i.id]=i,i.state.selected&&this._data.core.selected.push(i.id),i.id},_parse_model_from_flat_json:function(a,c,d){d=d?d.concat():[],c&&d.unshift(c);var e=a.id.toString(),f=this._model.data,g=this._model.default_state,h,i,j,k,l={id:e,text:a.text||"",icon:a.icon!==b?a.icon:!0,parent:c,parents:d,children:a.children||[],children_d:a.children_d||[],data:a.data,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1};for(h in g)g.hasOwnProperty(h)&&(l.state[h]=g[h]);if(a&&a.data&&a.data.jstree&&a.data.jstree.icon&&(l.icon=a.data.jstree.icon),(l.icon===b||null===l.icon||""===l.icon)&&(l.icon=!0),a&&a.data&&(l.data=a.data,a.data.jstree))for(h in a.data.jstree)a.data.jstree.hasOwnProperty(h)&&(l.state[h]=a.data.jstree[h]);if(a&&"object"==typeof a.state)for(h in a.state)a.state.hasOwnProperty(h)&&(l.state[h]=a.state[h]);if(a&&"object"==typeof a.li_attr)for(h in a.li_attr)a.li_attr.hasOwnProperty(h)&&(l.li_attr[h]=a.li_attr[h]);if(l.li_attr.id||(l.li_attr.id=e),a&&"object"==typeof a.a_attr)for(h in a.a_attr)a.a_attr.hasOwnProperty(h)&&(l.a_attr[h]=a.a_attr[h]);for(a&&a.children&&a.children===!0&&(l.state.loaded=!1,l.children=[],l.children_d=[]),f[l.id]=l,h=0,i=l.children.length;i>h;h++)j=this._parse_model_from_flat_json(f[l.children[h]],l.id,d),k=f[j],l.children_d.push(j),k.children_d.length&&(l.children_d=l.children_d.concat(k.children_d));return delete a.data,delete a.children,f[l.id].original=a,l.state.selected&&this._data.core.selected.push(l.id),l.id},_parse_model_from_json:function(a,c,d){d=d?d.concat():[],c&&d.unshift(c);var e=!1,f,g,h,i,j=this._model.data,k=this._model.default_state,l;do e="j"+this._id+"_"+ ++this._cnt;while(j[e]);l={id:!1,text:"string"==typeof a?a:"",icon:"object"==typeof a&&a.icon!==b?a.icon:!0,parent:c,parents:d,children:[],children_d:[],data:null,state:{},li_attr:{id:!1},a_attr:{href:"#"},original:!1};for(f in k)k.hasOwnProperty(f)&&(l.state[f]=k[f]);if(a&&a.id&&(l.id=a.id.toString()),a&&a.text&&(l.text=a.text),a&&a.data&&a.data.jstree&&a.data.jstree.icon&&(l.icon=a.data.jstree.icon),(l.icon===b||null===l.icon||""===l.icon)&&(l.icon=!0),a&&a.data&&(l.data=a.data,a.data.jstree))for(f in a.data.jstree)a.data.jstree.hasOwnProperty(f)&&(l.state[f]=a.data.jstree[f]);if(a&&"object"==typeof a.state)for(f in a.state)a.state.hasOwnProperty(f)&&(l.state[f]=a.state[f]);if(a&&"object"==typeof a.li_attr)for(f in a.li_attr)a.li_attr.hasOwnProperty(f)&&(l.li_attr[f]=a.li_attr[f]);if(l.li_attr.id&&!l.id&&(l.id=l.li_attr.id.toString()),
3
+ l.id||(l.id=e),l.li_attr.id||(l.li_attr.id=l.id),a&&"object"==typeof a.a_attr)for(f in a.a_attr)a.a_attr.hasOwnProperty(f)&&(l.a_attr[f]=a.a_attr[f]);if(a&&a.children&&a.children.length){for(f=0,g=a.children.length;g>f;f++)h=this._parse_model_from_json(a.children[f],l.id,d),i=j[h],l.children.push(h),i.children_d.length&&(l.children_d=l.children_d.concat(i.children_d));l.children_d=l.children_d.concat(l.children)}return a&&a.children&&a.children===!0&&(l.state.loaded=!1,l.children=[],l.children_d=[]),delete a.data,delete a.children,l.original=a,j[l.id]=l,l.state.selected&&this._data.core.selected.push(l.id),l.id},_redraw:function(){var b=this._model.force_full_redraw?this._model.data[a.jstree.root].children.concat([]):this._model.changed.concat([]),c=i.createElement("UL"),d,e,f,g=this._data.core.focused;for(e=0,f=b.length;f>e;e++)d=this.redraw_node(b[e],!0,this._model.force_full_redraw),d&&this._model.force_full_redraw&&c.appendChild(d);this._model.force_full_redraw&&(c.className=this.get_container_ul()[0].className,c.setAttribute("role","group"),this.element.empty().append(c)),null!==g&&this.settings.core.restore_focus&&(d=this.get_node(g,!0),d&&d.length&&d.children(".jstree-anchor")[0]!==i.activeElement?d.children(".jstree-anchor").focus():this._data.core.focused=null),this._model.force_full_redraw=!1,this._model.changed=[],this.trigger("redraw",{nodes:b})},redraw:function(a){a&&(this._model.force_full_redraw=!0),this._redraw()},draw_children:function(b){var c=this.get_node(b),d=!1,e=!1,f=!1,g=i;if(!c)return!1;if(c.id===a.jstree.root)return this.redraw(!0);if(b=this.get_node(b,!0),!b||!b.length)return!1;if(b.children(".jstree-children").remove(),b=b[0],c.children.length&&c.state.loaded){for(f=g.createElement("UL"),f.setAttribute("role","group"),f.className="jstree-children",d=0,e=c.children.length;e>d;d++)f.appendChild(this.redraw_node(c.children[d],!0,!0));b.appendChild(f)}},redraw_node:function(b,c,d,e){var f=this.get_node(b),g=!1,h=!1,j=!1,k=!1,l=!1,m=!1,n="",o=i,p=this._model.data,q=!1,r=!1,s=null,t=0,u=0,v=!1,w=!1;if(!f)return!1;if(f.id===a.jstree.root)return this.redraw(!0);if(c=c||0===f.children.length,b=i.querySelector?this.element[0].querySelector("#"+(-1!=="0123456789".indexOf(f.id[0])?"\\3"+f.id[0]+" "+f.id.substr(1).replace(a.jstree.idregex,"\\$&"):f.id.replace(a.jstree.idregex,"\\$&"))):i.getElementById(f.id))b=a(b),d||(g=b.parent().parent()[0],g===this.element[0]&&(g=null),h=b.index()),c||!f.children.length||b.children(".jstree-children").length||(c=!0),c||(j=b.children(".jstree-children")[0]),q=b.children(".jstree-anchor")[0]===i.activeElement,b.remove();else if(c=!0,!d){if(g=f.parent!==a.jstree.root?a("#"+f.parent.replace(a.jstree.idregex,"\\$&"),this.element)[0]:null,!(null===g||g&&p[f.parent].state.opened))return!1;h=a.inArray(f.id,null===g?p[a.jstree.root].children:p[f.parent].children)}b=this._data.core.node.cloneNode(!0),n="jstree-node ";for(k in f.li_attr)if(f.li_attr.hasOwnProperty(k)){if("id"===k)continue;"class"!==k?b.setAttribute(k,f.li_attr[k]):n+=f.li_attr[k]}for(f.a_attr.id||(f.a_attr.id=f.id+"_anchor"),b.setAttribute("aria-selected",!!f.state.selected),b.setAttribute("aria-level",f.parents.length),b.setAttribute("aria-labelledby",f.a_attr.id),f.state.disabled&&b.setAttribute("aria-disabled",!0),k=0,l=f.children.length;l>k;k++)if(!p[f.children[k]].state.hidden){v=!0;break}if(null!==f.parent&&p[f.parent]&&!f.state.hidden&&(k=a.inArray(f.id,p[f.parent].children),w=f.id,-1!==k))for(k++,l=p[f.parent].children.length;l>k;k++)if(p[p[f.parent].children[k]].state.hidden||(w=p[f.parent].children[k]),w!==f.id)break;f.state.hidden&&(n+=" jstree-hidden"),f.state.loading&&(n+=" jstree-loading"),f.state.loaded&&!v?n+=" jstree-leaf":(n+=f.state.opened&&f.state.loaded?" jstree-open":" jstree-closed",b.setAttribute("aria-expanded",f.state.opened&&f.state.loaded)),w===f.id&&(n+=" jstree-last"),b.id=f.id,b.className=n,n=(f.state.selected?" jstree-clicked":"")+(f.state.disabled?" jstree-disabled":"");for(l in f.a_attr)if(f.a_attr.hasOwnProperty(l)){if("href"===l&&"#"===f.a_attr[l])continue;"class"!==l?b.childNodes[1].setAttribute(l,f.a_attr[l]):n+=" "+f.a_attr[l]}if(n.length&&(b.childNodes[1].className="jstree-anchor "+n),(f.icon&&f.icon!==!0||f.icon===!1)&&(f.icon===!1?b.childNodes[1].childNodes[0].className+=" jstree-themeicon-hidden":-1===f.icon.indexOf("/")&&-1===f.icon.indexOf(".")?b.childNodes[1].childNodes[0].className+=" "+f.icon+" jstree-themeicon-custom":(b.childNodes[1].childNodes[0].style.backgroundImage='url("'+f.icon+'")',b.childNodes[1].childNodes[0].style.backgroundPosition="center center",b.childNodes[1].childNodes[0].style.backgroundSize="auto",b.childNodes[1].childNodes[0].className+=" jstree-themeicon-custom")),this.settings.core.force_text?b.childNodes[1].appendChild(o.createTextNode(f.text)):b.childNodes[1].innerHTML+=f.text,c&&f.children.length&&(f.state.opened||e)&&f.state.loaded){for(m=o.createElement("UL"),m.setAttribute("role","group"),m.className="jstree-children",k=0,l=f.children.length;l>k;k++)m.appendChild(this.redraw_node(f.children[k],c,!0));b.appendChild(m)}if(j&&b.appendChild(j),!d){for(g||(g=this.element[0]),k=0,l=g.childNodes.length;l>k;k++)if(g.childNodes[k]&&g.childNodes[k].className&&-1!==g.childNodes[k].className.indexOf("jstree-children")){s=g.childNodes[k];break}s||(s=o.createElement("UL"),s.setAttribute("role","group"),s.className="jstree-children",g.appendChild(s)),g=s,h<g.childNodes.length?g.insertBefore(b,g.childNodes[h]):g.appendChild(b),q&&(t=this.element[0].scrollTop,u=this.element[0].scrollLeft,b.childNodes[1].focus(),this.element[0].scrollTop=t,this.element[0].scrollLeft=u)}return f.state.opened&&!f.state.loaded&&(f.state.opened=!1,setTimeout(a.proxy(function(){this.open_node(f.id,!1,0)},this),0)),b},open_node:function(c,d,e){var f,g,h,i;if(a.isArray(c)){for(c=c.slice(),f=0,g=c.length;g>f;f++)this.open_node(c[f],d,e);return!0}return c=this.get_node(c),c&&c.id!==a.jstree.root?(e=e===b?this.settings.core.animation:e,this.is_closed(c)?this.is_loaded(c)?(h=this.get_node(c,!0),i=this,h.length&&(e&&h.children(".jstree-children").length&&h.children(".jstree-children").stop(!0,!0),c.children.length&&!this._firstChild(h.children(".jstree-children")[0])&&this.draw_children(c),e?(this.trigger("before_open",{node:c}),h.children(".jstree-children").css("display","none").end().removeClass("jstree-closed").addClass("jstree-open").attr("aria-expanded",!0).children(".jstree-children").stop(!0,!0).slideDown(e,function(){this.style.display="",i.element&&i.trigger("after_open",{node:c})})):(this.trigger("before_open",{node:c}),h[0].className=h[0].className.replace("jstree-closed","jstree-open"),h[0].setAttribute("aria-expanded",!0))),c.state.opened=!0,d&&d.call(this,c,!0),h.length||this.trigger("before_open",{node:c}),this.trigger("open_node",{node:c}),e&&h.length||this.trigger("after_open",{node:c}),!0):this.is_loading(c)?setTimeout(a.proxy(function(){this.open_node(c,d,e)},this),500):void this.load_node(c,function(a,b){return b?this.open_node(a,d,e):d?d.call(this,a,!1):!1}):(d&&d.call(this,c,!1),!1)):!1},_open_to:function(b){if(b=this.get_node(b),!b||b.id===a.jstree.root)return!1;var c,d,e=b.parents;for(c=0,d=e.length;d>c;c+=1)c!==a.jstree.root&&this.open_node(e[c],!1,0);return a("#"+b.id.replace(a.jstree.idregex,"\\$&"),this.element)},close_node:function(c,d){var e,f,g,h;if(a.isArray(c)){for(c=c.slice(),e=0,f=c.length;f>e;e++)this.close_node(c[e],d);return!0}return c=this.get_node(c),c&&c.id!==a.jstree.root?this.is_closed(c)?!1:(d=d===b?this.settings.core.animation:d,g=this,h=this.get_node(c,!0),c.state.opened=!1,this.trigger("close_node",{node:c}),void(h.length?d?h.children(".jstree-children").attr("style","display:block !important").end().removeClass("jstree-open").addClass("jstree-closed").attr("aria-expanded",!1).children(".jstree-children").stop(!0,!0).slideUp(d,function(){this.style.display="",h.children(".jstree-children").remove(),g.element&&g.trigger("after_close",{node:c})}):(h[0].className=h[0].className.replace("jstree-open","jstree-closed"),h.attr("aria-expanded",!1).children(".jstree-children").remove(),this.trigger("after_close",{node:c})):this.trigger("after_close",{node:c}))):!1},toggle_node:function(b){var c,d;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.toggle_node(b[c]);return!0}return this.is_closed(b)?this.open_node(b):this.is_open(b)?this.close_node(b):void 0},open_all:function(b,c,d){if(b||(b=a.jstree.root),b=this.get_node(b),!b)return!1;var e=b.id===a.jstree.root?this.get_container_ul():this.get_node(b,!0),f,g,h;if(!e.length){for(f=0,g=b.children_d.length;g>f;f++)this.is_closed(this._model.data[b.children_d[f]])&&(this._model.data[b.children_d[f]].state.opened=!0);return this.trigger("open_all",{node:b})}d=d||e,h=this,e=this.is_closed(b)?e.find(".jstree-closed").addBack():e.find(".jstree-closed"),e.each(function(){h.open_node(this,function(a,b){b&&this.is_parent(a)&&this.open_all(a,c,d)},c||0)}),0===d.find(".jstree-closed").length&&this.trigger("open_all",{node:this.get_node(d)})},close_all:function(b,c){if(b||(b=a.jstree.root),b=this.get_node(b),!b)return!1;var d=b.id===a.jstree.root?this.get_container_ul():this.get_node(b,!0),e=this,f,g;for(d.length&&(d=this.is_open(b)?d.find(".jstree-open").addBack():d.find(".jstree-open"),a(d.get().reverse()).each(function(){e.close_node(this,c||0)})),f=0,g=b.children_d.length;g>f;f++)this._model.data[b.children_d[f]].state.opened=!1;this.trigger("close_all",{node:b})},is_disabled:function(a){return a=this.get_node(a),a&&a.state&&a.state.disabled},enable_node:function(b){var c,d;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.enable_node(b[c]);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(b.state.disabled=!1,this.get_node(b,!0).children(".jstree-anchor").removeClass("jstree-disabled").attr("aria-disabled",!1),void this.trigger("enable_node",{node:b})):!1},disable_node:function(b){var c,d;if(a.isArray(b)){for(b=b.slice(),c=0,d=b.length;d>c;c++)this.disable_node(b[c]);return!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?(b.state.disabled=!0,this.get_node(b,!0).children(".jstree-anchor").addClass("jstree-disabled").attr("aria-disabled",!0),void this.trigger("disable_node",{node:b})):!1},is_hidden:function(a){return a=this.get_node(a),a.state.hidden===!0},hide_node:function(b,c){var d,e;if(a.isArray(b)){for(b=b.slice(),d=0,e=b.length;e>d;d++)this.hide_node(b[d],!0);return c||this.redraw(),!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?void(b.state.hidden||(b.state.hidden=!0,this._node_changed(b.parent),c||this.redraw(),this.trigger("hide_node",{node:b}))):!1},show_node:function(b,c){var d,e;if(a.isArray(b)){for(b=b.slice(),d=0,e=b.length;e>d;d++)this.show_node(b[d],!0);return c||this.redraw(),!0}return b=this.get_node(b),b&&b.id!==a.jstree.root?void(b.state.hidden&&(b.state.hidden=!1,this._node_changed(b.parent),c||this.redraw(),this.trigger("show_node",{node:b}))):!1},hide_all:function(b){var c,d=this._model.data,e=[];for(c in d)d.hasOwnProperty(c)&&c!==a.jstree.root&&!d[c].state.hidden&&(d[c].state.hidden=!0,e.push(c));return this._model.force_full_redraw=!0,b||this.redraw(),this.trigger("hide_all",{nodes:e}),e},show_all:function(b){var c,d=this._model.data,e=[];for(c in d)d.hasOwnProperty(c)&&c!==a.jstree.root&&d[c].state.hidden&&(d[c].state.hidden=!1,e.push(c));return this._model.force_full_redraw=!0,b||this.redraw(),this.trigger("show_all",{nodes:e}),e},activate_node:function(a,c){if(this.is_disabled(a))return!1;if(c&&"object"==typeof c||(c={}),this._data.core.last_clicked=this._data.core.last_clicked&&this._data.core.last_clicked.id!==b?this.get_node(this._data.core.last_clicked.id):null,this._data.core.last_clicked&&!this._data.core.last_clicked.state.selected&&(this._data.core.last_clicked=null),!this._data.core.last_clicked&&this._data.core.selected.length&&(this._data.core.last_clicked=this.get_node(this._data.core.selected[this._data.core.selected.length-1])),this.settings.core.multiple&&(c.metaKey||c.ctrlKey||c.shiftKey)&&(!c.shiftKey||this._data.core.last_clicked&&this.get_parent(a)&&this.get_parent(a)===this._data.core.last_clicked.parent))if(c.shiftKey){var d=this.get_node(a).id,e=this._data.core.last_clicked.id,f=this.get_node(this._data.core.last_clicked.parent).children,g=!1,h,i;for(h=0,i=f.length;i>h;h+=1)f[h]===d&&(g=!g),f[h]===e&&(g=!g),this.is_disabled(f[h])||!g&&f[h]!==d&&f[h]!==e?this.deselect_node(f[h],!0,c):this.is_hidden(f[h])||this.select_node(f[h],!0,!1,c);this.trigger("changed",{action:"select_node",node:this.get_node(a),selected:this._data.core.selected,event:c})}else this.is_selected(a)?this.deselect_node(a,!1,c):this.select_node(a,!1,!1,c);else!this.settings.core.multiple&&(c.metaKey||c.ctrlKey||c.shiftKey)&&this.is_selected(a)?this.deselect_node(a,!1,c):(this.deselect_all(!0),this.select_node(a,!1,!1,c),this._data.core.last_clicked=this.get_node(a));this.trigger("activate_node",{node:this.get_node(a),event:c})},hover_node:function(a){if(a=this.get_node(a,!0),!a||!a.length||a.children(".jstree-hovered").leng