├── .gitignore
├── LICENSE.txt
├── README.md
├── app.js
├── logs
└── .gitignore
├── package.json
├── public
└── node-zk
│ ├── jquery.tree.js
│ ├── lib
│ ├── jquery.cookie.js
│ ├── jquery.hotkeys.js
│ ├── jquery.js
│ ├── jquery.metadata.js
│ └── sarissa.js
│ ├── plugins
│ ├── _jquery.tree.rtl.js
│ ├── jquery.tree.checkbox.js
│ ├── jquery.tree.contextmenu.js
│ ├── jquery.tree.cookie.js
│ ├── jquery.tree.hotkeys.js
│ ├── jquery.tree.metadata.js
│ ├── jquery.tree.themeroller.js
│ ├── jquery.tree.xml_flat.js
│ └── jquery.tree.xml_nested.js
│ ├── stylesheets
│ └── style.css
│ └── themes
│ ├── apple
│ ├── bg.jpg
│ ├── dot_for_ie.gif
│ ├── icons.png
│ ├── style.css
│ └── throbber.gif
│ ├── checkbox
│ ├── dot_for_ie.gif
│ ├── icons.png
│ ├── style.css
│ └── throbber.gif
│ ├── classic
│ ├── dot_for_ie.gif
│ ├── icons.png
│ ├── style.css
│ └── throbber.gif
│ ├── default
│ ├── dot_for_ie.gif
│ ├── icons.png
│ ├── style.css
│ └── throbber.gif
│ └── themeroller
│ ├── dot_for_ie.gif
│ ├── icons.png
│ ├── style.css
│ └── throbber.gif
├── start.sh
├── test
└── app.test.js
├── user.json
├── views
├── create.ejs
├── data.ejs
├── index.ejs
├── layout.ejs
└── tree.ejs
└── zk.js
/.gitignore:
--------------------------------------------------------------------------------
1 | logs/
2 | node_modules/
3 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 |
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [yyyy] [name of copyright owner]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## node-zk-browser
2 |
3 | A zookeeper web administrator in node.js. It's based on [express.js](http://expressjs.com/) and [node-zookeeper](https://github.com/yfinkelstein/node-zookeeper).It will display zookeeper's data as a lazy loading tree,and display every path's stat info and data;and you can create,edit or delete path if you logon.
4 |
5 | ## Requirement
6 |
7 | You must install node.js 0.8.x from https://github.com/joyent/node/tags and [npm](https://github.com/isaacs/npm).
8 |
9 | ## Configure
10 | First,you must install dependencies with npm
11 |
12 | npm install -d
13 |
14 | Then edit app.js to configure your zk hosts
15 |
16 | var zkclient = new ZkClient("localhost:2181");
17 |
18 | Or you can pass it by enviroment variable:
19 |
20 | export ZK_HOST="localhost:2181"
21 |
22 | in `start.sh`.
23 |
24 | And edit user.json to configure your administrator account:
25 |
26 | { "name" : "password"}
27 |
28 | ## Run
29 | Type command to start app
30 |
31 | ./start.sh
32 |
33 | You can visit node-zk now at
34 |
35 | http://localhost:3000
36 |
37 | # License
38 | Apache License Version 2.0
39 |
40 | See LICENSE.txt file in the top level folder.
41 |
42 | # Author
43 | Dennis Zhuang(killme2008@gmail.com)
44 |
--------------------------------------------------------------------------------
/app.js:
--------------------------------------------------------------------------------
1 | /**
2 | /*
3 | * Licensed to the Apache Software Foundation (ASF) under one
4 | * or more contributor license agreements. See the NOTICE file
5 | * distributed with this work for additional information
6 | * regarding copyright ownership. The ASF licenses this file
7 | * to you under the Apache License, Version 2.0 (the
8 | * "License"); you may not use this file except in compliance
9 | * with the License. You may obtain a copy of the License at
10 | *
11 | * http://www.apache.org/licenses/LICENSE-2.0
12 | *
13 | * Unless required by applicable law or agreed to in writing,
14 | * software distributed under the License is distributed on an
15 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16 | * KIND, either express or implied. See the License for the
17 | * specific language governing permissions and limitations
18 | * under the License.
19 | *
20 | * node-zk-browser
21 | * author :dennis (killme2008@gmail.com)
22 | *
23 | */
24 |
25 | var express = require('express');
26 | require('express-namespace');
27 | var path=require('path');
28 | var fs=require('fs');
29 | var util=require('util');
30 | var ZkClient=require('./zk.js').ZkClient;
31 |
32 | var port = process.env.ZK_BROWSER_PORT || 3000;
33 | var host = process.env.ZK_HOST || 'localhost:2181';
34 | var zkclient = new ZkClient(host);
35 | var users = JSON.parse(fs.readFileSync(path.join(__dirname,'user.json'), 'utf8'));
36 | var app = express();
37 |
38 | process.on('uncaughtException', function (err) {
39 | console.error('Caught exception: ' + err);
40 | });
41 |
42 |
43 | // Configuration
44 | app.configure(function(){
45 | app.set('views', __dirname + '/views');
46 | app.set('view engine', 'ejs');
47 | app.use(express.cookieParser());
48 | app.use(express.session({ secret: "node zk browser" }));
49 | app.use(express.bodyParser());
50 | app.use(express.methodOverride());
51 | app.use(app.router);
52 | app.use(express.static(__dirname + '/public'));
53 | });
54 |
55 | app.configure('development', function(){
56 | app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
57 | });
58 |
59 | app.configure('production', function(){
60 | app.use(express.errorHandler());
61 | });
62 |
63 | // Routes
64 |
65 | app.get('/', function(req, res){
66 | res.redirect("/node-zk");
67 | });
68 |
69 | app.namespace("/node-zk",function(){
70 |
71 | //index
72 | app.get('/', function(req, res){
73 | res.render('index', { });
74 | });
75 |
76 | //display tree
77 | app.get('/tree', function(req, res){
78 | var path=req.query.path || "/";
79 | res.render('tree', {layout:false,'path':path, 'host':host});
80 | });
81 |
82 | //login
83 | app.post("/login",function(req,res){
84 | var user=req.body.user;
85 | if(users[user.name]==user.password){
86 | req.session.user=user.name
87 | req.session.cookie.maxAge=5*60*1000;
88 | }
89 | res.redirect(req.header('Referer'));
90 | });
91 |
92 | //delete
93 | app.post("/delete",function(req,res){
94 | if(req.session.user){
95 | var path=req.body.path;
96 | var version=Number(req.body.version);
97 | zkclient.zk.a_delete_(path,version,function(rc,err){
98 | if(rc!=0)
99 | res.send(err);
100 | else
101 | res.send("Delete ok");
102 | });
103 | }else{
104 | res.send("Please logon");
105 | }
106 | });
107 |
108 | //create view
109 | app.get("/create",function(req,res){
110 | res.render("create",{layout:false,user: req.session.user});
111 | });
112 |
113 | //create
114 | app.post("/create",function(req,res){
115 | if(req.session.user){
116 | var path=req.body.path;
117 | var data=req.body.data;
118 | var flag=Number(req.body.flag);
119 | zkclient.zk.a_create(path,data,flag,function(rc,err,path){
120 | if(rc!=0)
121 | res.send(err);
122 | else
123 | res.send("Create ok");
124 | });
125 | }else{
126 | res.send("Please logon");
127 | }
128 | });
129 |
130 | //edit
131 | app.post("/edit",function(req,res){
132 | if(req.session.user){
133 | var path=req.body.path;
134 | var new_data=req.body.new_data;
135 | var version=Number(req.body.version);
136 | zkclient.zk.a_set(path,new_data,version,function(rc,err,stat){
137 | if(rc!=0){
138 | res.send(err);
139 | }else
140 | res.send("set ok");
141 | });
142 | }else{
143 | res.send("Please logon");
144 | }
145 | });
146 |
147 | //query data
148 | app.get("/get",function(req,res){
149 | var path=req.query.path || "/";
150 | zkclient.zk.a_get(path,null,function(rc,err,stat,data){
151 | if(rc!=0){
152 | res.send(err);
153 | }else{
154 | res.render("data",{ layout: false, 'stat':stat,'data':data,'path':path,'user': req.session.user});
155 | }
156 | });
157 | });
158 |
159 | //query children
160 | app.get('/children',function(req,res){
161 | var parenPath=req.query.path || '/';
162 | zkclient.zk.a_get_children(parenPath,null,function(rc,error,children){
163 | res.header("Content-Type","application/json");
164 | var result=[];
165 | if(rc==0){
166 | children.forEach(function(child){
167 | realPath=path.join(parenPath,child);
168 | result.unshift({
169 | attributes:{"path":realPath,"rel":"chv"},
170 | data:{
171 | title : child,icon:"ou.png", attributes: { "href" : ("/node-zk/get?path="+realPath) }
172 | },
173 | state:"closed"
174 | });
175 | });
176 | }
177 | res.send(result);
178 | });
179 | });
180 | });
181 |
182 | app.listen(port);
183 | console.log("Express server listening on port %d", port);
184 |
--------------------------------------------------------------------------------
/logs/.gitignore:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/logs/.gitignore
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "node-zk-browser",
3 | "version": "0.0.2",
4 | "dependencies": {
5 | "ejs": ">= 0.7.2",
6 | "express": "3.x",
7 | "zookeeper":"*",
8 | "express-namespace":">=0.1.1"
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/public/node-zk/jquery.tree.js:
--------------------------------------------------------------------------------
1 | /*
2 | * jsTree 0.9.9a
3 | * http://jstree.com/
4 | *
5 | * Copyright (c) 2009 Ivan Bozhanov (vakata.com)
6 | *
7 | * Dual licensed under the MIT and GPL licenses:
8 | * http://www.opensource.org/licenses/mit-license.php
9 | * http://www.gnu.org/licenses/gpl.html
10 | *
11 | * Date: 2009-10-06
12 | *
13 | */
14 |
15 | (function($) {
16 | // jQuery plugin
17 | $.tree = {
18 | datastores : { },
19 | plugins : { },
20 | defaults : {
21 | data : {
22 | async : false, // Are async requests used to load open_branch contents
23 | type : "html", // One of included datastores
24 | opts : { method: "GET", url: false } // Options passed to datastore
25 | },
26 | selected : false, // FALSE or STRING or ARRAY
27 | opened : [], // ARRAY OF INITIALLY OPENED NODES
28 | languages : [], // ARRAY of string values (which will be used as CSS classes - so they must be valid)
29 | ui : {
30 | dots : true, // BOOL - dots or no dots
31 | animation : 0, // INT - duration of open/close animations in miliseconds
32 | scroll_spd : 4,
33 | theme_path : false, // Path to the theme CSS file - if set to false and theme_name is not false - will lookup jstree-path-here/themes/theme-name-here/style.css
34 | theme_name : "default",// if set to false no theme will be loaded
35 | selected_parent_close : "select_parent", // false, "deselect", "select_parent"
36 | selected_delete : "select_previous" // false, "select_previous"
37 | },
38 | types : {
39 | "default" : {
40 | clickable : true, // can be function
41 | renameable : true, // can be function
42 | deletable : true, // can be function
43 | creatable : true, // can be function
44 | draggable : true, // can be function
45 | max_children : -1, // -1 - not set, 0 - no children, 1 - one child, etc // can be function
46 | max_depth : -1, // -1 - not set, 0 - no children, 1 - one level of children, etc // can be function
47 | valid_children : "all", // all, none, array of values // can be function
48 | icon : {
49 | image : false,
50 | position : false
51 | }
52 | }
53 | },
54 | rules : {
55 | multiple : false, // FALSE | CTRL | ON - multiple selection off/ with or without holding Ctrl
56 | multitree : "none", // all, none, array of tree IDs to accept from
57 | type_attr : "rel", // STRING attribute name (where is the type stored as string)
58 | createat : "bottom", // STRING (top or bottom) new nodes get inserted at top or bottom
59 | drag_copy : "ctrl", // FALSE | CTRL | ON - drag to copy off/ with or without holding Ctrl
60 | drag_button : "left", // left, right or both
61 | use_max_children : true,
62 | use_max_depth : true,
63 |
64 | max_children: -1,
65 | max_depth : -1,
66 | valid_children : "all"
67 | },
68 | lang : {
69 | new_node : "New folder",
70 | loading : "Loading ..."
71 | },
72 | callback : {
73 | beforechange: function(NODE,TREE_OBJ) { return true },
74 | beforeopen : function(NODE,TREE_OBJ) { return true },
75 | beforeclose : function(NODE,TREE_OBJ) { return true },
76 | beforemove : function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
77 | beforecreate: function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true },
78 | beforerename: function(NODE,LANG,TREE_OBJ) { return true },
79 | beforedelete: function(NODE,TREE_OBJ) { return true },
80 | beforedata : function(NODE,TREE_OBJ) { return { id : $(NODE).attr("id") || 0 } }, // PARAMETERS PASSED TO SERVER
81 | ondata : function(DATA,TREE_OBJ) { return DATA; }, // modify data before parsing it
82 | onparse : function(STR,TREE_OBJ) { return STR; }, // modify string before visualizing it
83 | onhover : function(NODE,TREE_OBJ) { }, // node hovered
84 | onselect : function(NODE,TREE_OBJ) { }, // node selected
85 | ondeselect : function(NODE,TREE_OBJ) { }, // node deselected
86 | onchange : function(NODE,TREE_OBJ) { }, // focus changed
87 | onrename : function(NODE,TREE_OBJ,RB) { }, // node renamed
88 | onmove : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // move completed
89 | oncopy : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // copy completed
90 | oncreate : function(NODE,REF_NODE,TYPE,TREE_OBJ,RB) { }, // node created
91 | ondelete : function(NODE,TREE_OBJ,RB) { }, // node deleted
92 | onopen : function(NODE,TREE_OBJ) { }, // node opened
93 | onopen_all : function(TREE_OBJ) { }, // all nodes opened
94 | onclose_all : function(TREE_OBJ) { }, // all nodes closed
95 | onclose : function(NODE,TREE_OBJ) { }, // node closed
96 | error : function(TEXT,TREE_OBJ) { }, // error occured
97 | ondblclk : function(NODE,TREE_OBJ) { TREE_OBJ.toggle_branch.call(TREE_OBJ, NODE); TREE_OBJ.select_branch.call(TREE_OBJ, NODE); },
98 | onrgtclk : function(NODE,TREE_OBJ,EV) { }, // right click - to prevent use: EV.preventDefault(); EV.stopPropagation(); return false
99 | onload : function(TREE_OBJ) { },
100 | oninit : function(TREE_OBJ) { },
101 | onfocus : function(TREE_OBJ) { },
102 | ondestroy : function(TREE_OBJ) { },
103 | onsearch : function(NODES, TREE_OBJ) { NODES.addClass("search"); },
104 | ondrop : function(NODE,REF_NODE,TYPE,TREE_OBJ) { },
105 | check : function(RULE,NODE,VALUE,TREE_OBJ) { return VALUE; },
106 | check_move : function(NODE,REF_NODE,TYPE,TREE_OBJ) { return true; }
107 | },
108 | plugins : { }
109 | },
110 |
111 | create : function () { return new tree_component(); },
112 | focused : function () { return tree_component.inst[tree_component.focused]; },
113 | reference : function (obj) {
114 | var o = $(obj);
115 | if(!o.size()) o = $("#" + obj);
116 | if(!o.size()) return null;
117 | o = (o.is(".tree")) ? o.attr("id") : o.parents(".tree:eq(0)").attr("id");
118 | return tree_component.inst[o] || null;
119 | },
120 | rollback : function (data) {
121 | for(var i in data) {
122 | if(!data.hasOwnProperty(i)) continue;
123 | var tmp = tree_component.inst[i];
124 | var lock = !tmp.locked;
125 |
126 | // if not locked - lock the tree
127 | if(lock) tmp.lock(true);
128 | // Cancel ongoing rename
129 | tmp.inp = false;
130 | tmp.container.html(data[i].html).find(".dragged").removeClass("dragged").end().find(".hover").removeClass("hover");
131 |
132 | if(data[i].selected) {
133 | tmp.selected = $("#" + data[i].selected);
134 | tmp.selected_arr = [];
135 | tmp.container
136 | .find("a.clicked").each( function () {
137 | tmp.selected_arr.push(tmp.get_node(this));
138 | });
139 | }
140 | // if this function set the lock - unlock
141 | if(lock) tmp.lock(false);
142 |
143 | delete lock;
144 | delete tmp;
145 | }
146 | },
147 | drop_mode : function (opts) {
148 | opts = $.extend(opts, { show : false, type : "default", str : "Foreign node" });
149 | tree_component.drag_drop.foreign = true;
150 | tree_component.drag_drop.isdown = true;
151 | tree_component.drag_drop.moving = true;
152 | tree_component.drag_drop.appended = false;
153 | tree_component.drag_drop.f_type = opts.type;
154 | tree_component.drag_drop.f_data = opts;
155 |
156 |
157 | if(!opts.show) {
158 | tree_component.drag_drop.drag_help = false;
159 | tree_component.drag_drop.drag_node = false;
160 | }
161 | else {
162 | tree_component.drag_drop.drag_help = $("
");
163 | tree_component.drag_drop.drag_node = tree_component.drag_drop.drag_help.find("li:eq(0)");
164 | }
165 | if($.tree.drag_start !== false) $.tree.drag_start.call(null, false);
166 | },
167 | drag_start : false,
168 | drag : false,
169 | drag_end : false
170 | };
171 | $.fn.tree = function (opts) {
172 | return this.each(function() {
173 | var conf = $.extend({},opts);
174 | if(tree_component.inst && tree_component.inst[$(this).attr('id')]) tree_component.inst[$(this).attr('id')].destroy();
175 | if(conf !== false) new tree_component().init(this, conf);
176 | });
177 | };
178 |
179 | // core
180 | function tree_component () {
181 | return {
182 | cntr : ++tree_component.cntr,
183 | settings : $.extend({},$.tree.defaults),
184 |
185 | init : function(elem, conf) {
186 | var _this = this;
187 | this.container = $(elem);
188 | if(this.container.size == 0) return false;
189 | tree_component.inst[this.cntr] = this;
190 | if(!this.container.attr("id")) this.container.attr("id","jstree_" + this.cntr);
191 | tree_component.inst[this.container.attr("id")] = tree_component.inst[this.cntr];
192 | tree_component.focused = this.cntr;
193 | this.settings = $.extend(true, {}, this.settings, conf);
194 |
195 | // DEAL WITH LANGUAGE VERSIONS
196 | if(this.settings.languages && this.settings.languages.length) {
197 | this.current_lang = this.settings.languages[0];
198 | var st = false;
199 | var id = "#" + this.container.attr("id");
200 | for(var ln = 0; ln < this.settings.languages.length; ln++) {
201 | st = tree_component.add_css(id + " ." + this.settings.languages[ln]);
202 | if(st !== false) st.style.display = (this.settings.languages[ln] == this.current_lang) ? "" : "none";
203 | }
204 | }
205 | else this.current_lang = false;
206 | // THEMES
207 | this.container.addClass("tree");
208 | if(this.settings.ui.theme_name !== false) {
209 | if(this.settings.ui.theme_path === false) {
210 | $("script").each(function () {
211 | if(this.src.toString().match(/jquery\.tree.*?js$/)) { _this.settings.ui.theme_path = this.src.toString().replace(/jquery\.tree.*?js$/, "") + "themes/" + _this.settings.ui.theme_name + "/style.css"; return false; }
212 | });
213 | }
214 | if(this.settings.ui.theme_path != "" && $.inArray(this.settings.ui.theme_path, tree_component.themes) == -1) {
215 | tree_component.add_sheet({ url : this.settings.ui.theme_path });
216 | tree_component.themes.push(this.settings.ui.theme_path);
217 | }
218 | this.container.addClass("tree-" + this.settings.ui.theme_name);
219 | }
220 | // TYPE ICONS
221 | var type_icons = "";
222 | for(var t in this.settings.types) {
223 | if(!this.settings.types.hasOwnProperty(t)) continue;
224 | if(!this.settings.types[t].icon) continue;
225 | if( this.settings.types[t].icon.image || this.settings.types[t].icon.position) {
226 | if(t == "default") type_icons += "#" + this.container.attr("id") + " li > a ins { ";
227 | else type_icons += "#" + this.container.attr("id") + " li[rel=" + t + "] > a ins { ";
228 | if(this.settings.types[t].icon.image) type_icons += " background-image:url(" + this.settings.types[t].icon.image + "); ";
229 | if(this.settings.types[t].icon.position) type_icons += " background-position:" + this.settings.types[t].icon.position + "; ";
230 | type_icons += "} ";
231 | }
232 | }
233 | if(type_icons != "") tree_component.add_sheet({ str : type_icons });
234 |
235 | if(this.settings.rules.multiple) this.selected_arr = [];
236 | this.offset = false;
237 | this.hovered = false;
238 | this.locked = false;
239 |
240 | if(tree_component.drag_drop.marker === false) tree_component.drag_drop.marker = $("").attr({ id : "jstree-marker" }).hide().appendTo("body");
241 | this.callback("oninit", [this]);
242 | this.refresh();
243 | this.attach_events();
244 | this.focus();
245 | },
246 | refresh : function (obj) {
247 | if(this.locked) return this.error("LOCKED");
248 | var _this = this;
249 | if(obj && !this.settings.data.async) obj = false;
250 | this.is_partial_refresh = obj ? true : false;
251 |
252 | // SAVE OPENED
253 | this.opened = Array();
254 | if(this.settings.opened != false) {
255 | $.each(this.settings.opened, function (i, item) {
256 | if(this.replace(/^#/,"").length > 0) { _this.opened.push("#" + this.replace(/^#/,"")); }
257 | });
258 | this.settings.opened = false;
259 | }
260 | else {
261 | this.container.find("li.open").each(function (i) { if(this.id) { _this.opened.push("#" + this.id); } });
262 | }
263 |
264 | // SAVE SELECTED
265 | if(this.selected) {
266 | this.settings.selected = Array();
267 | if(obj) {
268 | $(obj).find("li:has(a.clicked)").each(function () {
269 | if(this.id) _this.settings.selected.push("#" + this.id);
270 | });
271 | }
272 | else {
273 | if(this.selected_arr) {
274 | $.each(this.selected_arr, function () {
275 | if(this.attr("id")) _this.settings.selected.push("#" + this.attr("id"));
276 | });
277 | }
278 | else {
279 | if(this.selected.attr("id")) this.settings.selected.push("#" + this.selected.attr("id"));
280 | }
281 | }
282 | }
283 | else if(this.settings.selected !== false) {
284 | var tmp = Array();
285 | if((typeof this.settings.selected).toLowerCase() == "object") {
286 | $.each(this.settings.selected, function () {
287 | if(this.replace(/^#/,"").length > 0) tmp.push("#" + this.replace(/^#/,""));
288 | });
289 | }
290 | else {
291 | if(this.settings.selected.replace(/^#/,"").length > 0) tmp.push("#" + this.settings.selected.replace(/^#/,""));
292 | }
293 | this.settings.selected = tmp;
294 | }
295 |
296 | if(obj && this.settings.data.async) {
297 | this.opened = Array();
298 | obj = this.get_node(obj);
299 | obj.find("li.open").each(function (i) { _this.opened.push("#" + this.id); });
300 | if(obj.hasClass("open")) obj.removeClass("open").addClass("closed");
301 | if(obj.hasClass("leaf")) obj.removeClass("leaf");
302 | obj.children("ul:eq(0)").html("");
303 | return this.open_branch(obj, true, function () { _this.reselect.apply(_this); });
304 | }
305 |
306 | var _this = this;
307 | var _datastore = new $.tree.datastores[this.settings.data.type]();
308 | if(this.container.children("ul").size() == 0) {
309 | this.container.html("
");
310 | }
311 | _datastore.load(this.callback("beforedata",[false,this]),this,this.settings.data.opts,function(data) {
312 | data = _this.callback("ondata",[data, _this]);
313 | _datastore.parse(data,_this,_this.settings.data.opts,function(str) {
314 | str = _this.callback("onparse", [str, _this]);
315 | _this.container.empty().append($("
").html(str));
316 | _this.container.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
317 | _this.container.find("li").not(".open").not(".closed").addClass("leaf");
318 | _this.reselect();
319 | });
320 | });
321 | },
322 | reselect : function (is_callback) {
323 | var _this = this;
324 |
325 | if(!is_callback) this.cl_count = 0;
326 | else this.cl_count --;
327 | // REOPEN BRANCHES
328 | if(this.opened && this.opened.length) {
329 | var opn = false;
330 | for(var j = 0; this.opened && j < this.opened.length; j++) {
331 | if(this.settings.data.async) {
332 | var tmp = this.get_node(this.opened[j]);
333 | if(tmp.size() && tmp.hasClass("closed") > 0) {
334 | opn = true;
335 | var tmp = this.opened[j].toString().replace('/','\\/');
336 | delete this.opened[j];
337 | this.open_branch(tmp, true, function () { _this.reselect.apply(_this, [true]); } );
338 | this.cl_count ++;
339 | }
340 | }
341 | else this.open_branch(this.opened[j], true);
342 | }
343 | if(this.settings.data.async && opn) return;
344 | if(this.cl_count > 0) return;
345 | delete this.opened;
346 | }
347 | if(this.cl_count > 0) return;
348 |
349 | // DOTS and RIGHT TO LEFT
350 | this.container.css("direction","ltr").children("ul:eq(0)").addClass("ltr");
351 | if(this.settings.ui.dots == false) this.container.children("ul:eq(0)").addClass("no_dots");
352 |
353 | // REPOSITION SCROLL
354 | if(this.scrtop) {
355 | this.container.scrollTop(_this.scrtop);
356 | delete this.scrtop;
357 | }
358 | // RESELECT PREVIOUSLY SELECTED
359 | if(this.settings.selected !== false) {
360 | $.each(this.settings.selected, function (i) {
361 | if(_this.is_partial_refresh) _this.select_branch($(_this.settings.selected[i].toString().replace('/','\\/'), _this.container), (_this.settings.rules.multiple !== false) );
362 | else _this.select_branch($(_this.settings.selected[i].toString().replace('/','\\/'), _this.container), (_this.settings.rules.multiple !== false && i > 0) );
363 | });
364 | this.settings.selected = false;
365 | }
366 | this.callback("onload", [_this]);
367 | },
368 |
369 | get : function (obj, format, opts) {
370 | if(!format) format = this.settings.data.type;
371 | if(!opts) opts = this.settings.data.opts;
372 | return new $.tree.datastores[format]().get(obj, this, opts);
373 | },
374 |
375 | attach_events : function () {
376 | var _this = this;
377 |
378 | this.container
379 | .bind("mousedown.jstree", function (event) {
380 | if(tree_component.drag_drop.isdown) {
381 | tree_component.drag_drop.move_type = false;
382 | event.preventDefault();
383 | event.stopPropagation();
384 | event.stopImmediatePropagation();
385 | return false;
386 | }
387 | })
388 | .bind("mouseup.jstree", function (event) {
389 | setTimeout( function() { _this.focus.apply(_this); }, 5);
390 | })
391 | .bind("click.jstree", function (event) {
392 | //event.stopPropagation();
393 | return true;
394 | });
395 | $("li", this.container.get(0))
396 | .live("click", function(event) { // WHEN CLICK IS ON THE ARROW
397 | if(event.target.tagName != "LI") return true;
398 | _this.off_height();
399 | if(event.pageY - $(event.target).offset().top > _this.li_height) return true;
400 | _this.toggle_branch.apply(_this, [event.target]);
401 | event.stopPropagation();
402 | return false;
403 | });
404 | $("a", this.container.get(0))
405 | .live("click", function (event) { // WHEN CLICK IS ON THE TEXT OR ICON
406 | if(event.which && event.which == 3) return true;
407 | if(_this.locked) {
408 | event.preventDefault();
409 | event.target.blur();
410 | return _this.error("LOCKED");
411 | }
412 | _this.select_branch.apply(_this, [event.target, event.ctrlKey || _this.settings.rules.multiple == "on"]);
413 | if(_this.inp) { _this.inp.blur(); }
414 | event.preventDefault();
415 | event.target.blur();
416 | return false;
417 | })
418 | .live("dblclick", function (event) { // WHEN DOUBLECLICK ON TEXT OR ICON
419 | if(_this.locked) {
420 | event.preventDefault();
421 | event.stopPropagation();
422 | event.target.blur();
423 | return _this.error("LOCKED");
424 | }
425 | _this.callback("ondblclk", [_this.get_node(event.target).get(0), _this]);
426 | event.preventDefault();
427 | event.stopPropagation();
428 | event.target.blur();
429 | })
430 | .live("contextmenu", function (event) {
431 | if(_this.locked) {
432 | event.target.blur();
433 | return _this.error("LOCKED");
434 | }
435 | return _this.callback("onrgtclk", [_this.get_node(event.target).get(0), _this, event]);
436 | })
437 | .live("mouseover", function (event) {
438 | if(_this.locked) {
439 | event.preventDefault();
440 | event.stopPropagation();
441 | return _this.error("LOCKED");
442 | }
443 | if(_this.hovered !== false && (event.target.tagName == "A" || event.target.tagName == "INS")) {
444 | _this.hovered.children("a").removeClass("hover");
445 | _this.hovered = false;
446 | }
447 | _this.callback("onhover",[_this.get_node(event.target).get(0), _this]);
448 | })
449 | .live("mousedown", function (event) {
450 | if(_this.settings.rules.drag_button == "left" && event.which && event.which != 1) return true;
451 | if(_this.settings.rules.drag_button == "right" && event.which && event.which != 3) return true;
452 | _this.focus.apply(_this);
453 | if(_this.locked) return _this.error("LOCKED");
454 | // SELECT LIST ITEM NODE
455 | var obj = _this.get_node(event.target);
456 | // IF ITEM IS DRAGGABLE
457 | if(_this.settings.rules.multiple != false && _this.selected_arr.length > 1 && obj.children("a:eq(0)").hasClass("clicked")) {
458 | var counter = 0;
459 | for(var i in _this.selected_arr) {
460 | if(!_this.selected_arr.hasOwnProperty(i)) continue;
461 | if(_this.check("draggable", _this.selected_arr[i])) {
462 | _this.selected_arr[i].addClass("dragged");
463 | tree_component.drag_drop.origin_tree = _this;
464 | counter ++;
465 | }
466 | }
467 | if(counter > 0) {
468 | if(_this.check("draggable", obj)) tree_component.drag_drop.drag_node = obj;
469 | else tree_component.drag_drop.drag_node = _this.container.find("li.dragged:eq(0)");
470 | tree_component.drag_drop.isdown = true;
471 | tree_component.drag_drop.drag_help = $("
").append("");
472 | var tmp = tree_component.drag_drop.drag_node.clone();
473 | if(_this.settings.languages.length > 0) tmp.find("a").not("." + _this.current_lang).hide();
474 | tree_component.drag_drop.drag_help.children("ul:eq(0)").append(tmp);
475 | tree_component.drag_drop.drag_help.find("li:eq(0)").removeClass("last").addClass("last").children("a").html(" Multiple selection").end().children("ul").remove();
476 |
477 | tree_component.drag_drop.dragged = _this.container.find("li.dragged");
478 | }
479 | }
480 | else {
481 | if(_this.check("draggable", obj)) {
482 | tree_component.drag_drop.drag_node = obj;
483 | tree_component.drag_drop.drag_help = $("
").append("");
484 | var tmp = obj.clone();
485 | if(_this.settings.languages.length > 0) tmp.find("a").not("." + _this.current_lang).hide();
486 | tree_component.drag_drop.drag_help.children("ul:eq(0)").append(tmp);
487 | tree_component.drag_drop.drag_help.find("li:eq(0)").removeClass("last").addClass("last");
488 | tree_component.drag_drop.isdown = true;
489 | tree_component.drag_drop.foreign = false;
490 | tree_component.drag_drop.origin_tree = _this;
491 | obj.addClass("dragged");
492 |
493 | tree_component.drag_drop.dragged = _this.container.find("li.dragged");
494 | }
495 | }
496 | tree_component.drag_drop.init_x = event.pageX;
497 | tree_component.drag_drop.init_y = event.pageY;
498 | obj.blur();
499 | event.preventDefault();
500 | event.stopPropagation();
501 | return false;
502 | });
503 | },
504 | focus : function () {
505 | if(this.locked) return false;
506 | if(tree_component.focused != this.cntr) {
507 | tree_component.focused = this.cntr;
508 | this.callback("onfocus",[this]);
509 | }
510 | },
511 |
512 | off_height : function () {
513 | if(this.offset === false) {
514 | this.container.css({ position : "relative" });
515 | this.offset = this.container.offset();
516 | var tmp = 0;
517 | tmp = parseInt($.curCSS(this.container.get(0), "paddingTop", true),10);
518 | if(tmp) this.offset.top += tmp;
519 | tmp = parseInt($.curCSS(this.container.get(0), "borderTopWidth", true),10);
520 | if(tmp) this.offset.top += tmp;
521 | this.container.css({ position : "" });
522 | }
523 | if(!this.li_height) {
524 | var tmp = this.container.find("ul li.closed, ul li.leaf").eq(0);
525 | this.li_height = tmp.height();
526 | if(tmp.children("ul:eq(0)").size()) this.li_height -= tmp.children("ul:eq(0)").height();
527 | if(!this.li_height) this.li_height = 18;
528 | }
529 | },
530 | scroll_check : function (x,y) {
531 | var _this = this;
532 | var cnt = _this.container;
533 | var off = _this.container.offset();
534 |
535 | var st = cnt.scrollTop();
536 | var sl = cnt.scrollLeft();
537 | // DETECT HORIZONTAL SCROLL
538 | var h_cor = (cnt.get(0).scrollWidth > cnt.width()) ? 40 : 20;
539 |
540 | if(y - off.top < 20) cnt.scrollTop(Math.max( (st - _this.settings.ui.scroll_spd) ,0)); // NEAR TOP
541 | if(cnt.height() - (y - off.top) < h_cor) cnt.scrollTop(st + _this.settings.ui.scroll_spd); // NEAR BOTTOM
542 | if(x - off.left < 20) cnt.scrollLeft(Math.max( (sl - _this.settings.ui.scroll_spd),0)); // NEAR LEFT
543 | if(cnt.width() - (x - off.left) < 40) cnt.scrollLeft(sl + _this.settings.ui.scroll_spd); // NEAR RIGHT
544 |
545 | if(cnt.scrollLeft() != sl || cnt.scrollTop() != st) {
546 | tree_component.drag_drop.move_type = false;
547 | tree_component.drag_drop.ref_node = false;
548 | tree_component.drag_drop.marker.hide();
549 | }
550 | tree_component.drag_drop.scroll_time = setTimeout( function() { _this.scroll_check(x,y); }, 50);
551 | },
552 | scroll_into_view : function (obj) {
553 | obj = obj ? this.get_node(obj) : this.selected;
554 | if(!obj) return false;
555 | var off_t = obj.offset().top;
556 | var beg_t = this.container.offset().top;
557 | var end_t = beg_t + this.container.height();
558 | var h_cor = (this.container.get(0).scrollWidth > this.container.width()) ? 40 : 20;
559 | if(off_t + 5 < beg_t) this.container.scrollTop(this.container.scrollTop() - (beg_t - off_t + 5) );
560 | if(off_t + h_cor > end_t) this.container.scrollTop(this.container.scrollTop() + (off_t + h_cor - end_t) );
561 | },
562 |
563 | get_node : function (obj) {
564 | return $(obj).closest("li");
565 | },
566 | get_type : function (obj) {
567 | obj = !obj ? this.selected : this.get_node(obj);
568 | if(!obj) return;
569 | var tmp = obj.attr(this.settings.rules.type_attr);
570 | return tmp || "default";
571 | },
572 | set_type : function (str, obj) {
573 | obj = !obj ? this.selected : this.get_node(obj);
574 | if(!obj || !str) return;
575 | obj.attr(this.settings.rules.type_attr, str);
576 | },
577 | get_text : function (obj, lang) {
578 | obj = this.get_node(obj);
579 | if(!obj || obj.size() == 0) return "";
580 | if(this.settings.languages && this.settings.languages.length) {
581 | lang = lang ? lang : this.current_lang;
582 | obj = obj.children("a." + lang);
583 | }
584 | else obj = obj.children("a:visible");
585 | var val = "";
586 | obj.contents().each(function () {
587 | if(this.nodeType == 3) { val = this.data; return false; }
588 | });
589 | return val;
590 | },
591 |
592 | check : function (rule, obj) {
593 | if(this.locked) return false;
594 | var v = false;
595 | // if root node
596 | if(obj === -1) { if(typeof this.settings.rules[rule] != "undefined") v = this.settings.rules[rule]; }
597 | else {
598 | obj = !obj ? this.selected : this.get_node(obj);
599 | if(!obj) return;
600 | var t = this.get_type(obj);
601 | if(typeof this.settings.types[t] != "undefined" && typeof this.settings.types[t][rule] != "undefined") v = this.settings.types[t][rule];
602 | else if(typeof this.settings.types["default"] != "undefined" && typeof this.settings.types["default"][rule] != "undefined") v = this.settings.types["default"][rule];
603 | }
604 | if(typeof v == "function") v = v.call(null, obj, this);
605 | v = this.callback("check", [rule, obj, v, this]);
606 | return v;
607 | },
608 | check_move : function (nod, ref_node, how) {
609 | if(this.locked) return false;
610 | if($(ref_node).closest("li.dragged").size()) return false;
611 |
612 | var tree1 = nod.parents(".tree:eq(0)").get(0);
613 | var tree2 = ref_node.parents(".tree:eq(0)").get(0);
614 | // if different trees
615 | if(tree1 && tree1 != tree2) {
616 | var m = $.tree.reference(tree2.id).settings.rules.multitree;
617 | if(m == "none" || ($.isArray(m) && $.inArray(tree1.id, m) == -1)) return false;
618 | }
619 |
620 | var p = (how != "inside") ? this.parent(ref_node) : this.get_node(ref_node);
621 | nod = this.get_node(nod);
622 | if(p == false) return false;
623 | var r = {
624 | max_depth : this.settings.rules.use_max_depth ? this.check("max_depth", p) : -1,
625 | max_children : this.settings.rules.use_max_children ? this.check("max_children", p) : -1,
626 | valid_children : this.check("valid_children", p)
627 | };
628 | var nod_type = (typeof nod == "string") ? nod : this.get_type(nod);
629 | if(typeof r.valid_children != "undefined" && (r.valid_children == "none" || (typeof r.valid_children == "object" && $.inArray(nod_type, $.makeArray(r.valid_children)) == -1))) return false;
630 |
631 | if(this.settings.rules.use_max_children) {
632 | if(typeof r.max_children != "undefined" && r.max_children != -1) {
633 | if(r.max_children == 0) return false;
634 | var c_count = 1;
635 | if(tree_component.drag_drop.moving == true && tree_component.drag_drop.foreign == false) {
636 | c_count = tree_component.drag_drop.dragged.size();
637 | c_count = c_count - p.find('> ul > li.dragged').size();
638 | }
639 | if(r.max_children < p.find('> ul > li').size() + c_count) return false;
640 | }
641 | }
642 |
643 | if(this.settings.rules.use_max_depth) {
644 | if(typeof r.max_depth != "undefined" && r.max_depth === 0) return this.error("MOVE: MAX-DEPTH REACHED");
645 | // check for max_depth up the chain
646 | var mx = (r.max_depth > 0) ? r.max_depth : false;
647 | var i = 0;
648 | var t = p;
649 | while(t !== -1) {
650 | t = this.parent(t);
651 | i ++;
652 | var m = this.check("max_depth",t);
653 | if(m >= 0) {
654 | mx = (mx === false) ? (m - i) : Math.min(mx, m - i);
655 | }
656 | if(mx !== false && mx <= 0) return this.error("MOVE: MAX-DEPTH REACHED");
657 | }
658 | if(mx !== false && mx <= 0) return this.error("MOVE: MAX-DEPTH REACHED");
659 | if(mx !== false) {
660 | var incr = 1;
661 | if(typeof nod != "string") {
662 | var t = nod;
663 | // possible async problem - when nodes are not all loaded down the chain
664 | while(t.size() > 0) {
665 | if(mx - incr < 0) return this.error("MOVE: MAX-DEPTH REACHED");
666 | t = t.children("ul").children("li");
667 | incr ++;
668 | }
669 | }
670 | }
671 | }
672 | if(this.callback("check_move", [nod, ref_node, how, this]) == false) return false;
673 | return true;
674 | },
675 |
676 | hover_branch : function (obj) {
677 | if(this.locked) return this.error("LOCKED");
678 | var _this = this;
679 | var obj = _this.get_node(obj);
680 | if(!obj.size()) return this.error("HOVER: NOT A VALID NODE");
681 | if(!_this.check("clickable", obj)) return this.error("SELECT: NODE NOT SELECTABLE");
682 | if(this.hovered) this.hovered.children("A").removeClass("hover");
683 | this.hovered = obj;
684 | this.hovered.children("a").addClass("hover");
685 | this.scroll_into_view(this.hovered);
686 | },
687 | select_branch : function (obj, multiple) {
688 | if(this.locked) return this.error("LOCKED");
689 | if(!obj && this.hovered !== false) obj = this.hovered;
690 | var _this = this;
691 | obj = _this.get_node(obj);
692 | if(!obj.size()) return this.error("SELECT: NOT A VALID NODE");
693 | obj.children("a").removeClass("hover");
694 | // CHECK AGAINST RULES FOR SELECTABLE NODES
695 | if(!_this.check("clickable", obj)) return this.error("SELECT: NODE NOT SELECTABLE");
696 | if(_this.callback("beforechange",[obj.get(0),_this]) === false) return this.error("SELECT: STOPPED BY USER");
697 | // IF multiple AND obj IS ALREADY SELECTED - DESELECT IT
698 | if(this.settings.rules.multiple != false && multiple && obj.children("a.clicked").size() > 0) {
699 | return this.deselect_branch(obj);
700 | }
701 | if(this.settings.rules.multiple != false && multiple) {
702 | this.selected_arr.push(obj);
703 | }
704 | if(this.settings.rules.multiple != false && !multiple) {
705 | for(var i in this.selected_arr) {
706 | if(!this.selected_arr.hasOwnProperty(i)) continue;
707 | this.selected_arr[i].children("A").removeClass("clicked");
708 | this.callback("ondeselect", [this.selected_arr[i].get(0), _this]);
709 | }
710 | this.selected_arr = [];
711 | this.selected_arr.push(obj);
712 | if(this.selected && this.selected.children("A").hasClass("clicked")) {
713 | this.selected.children("A").removeClass("clicked");
714 | this.callback("ondeselect", [this.selected.get(0), _this]);
715 | }
716 | }
717 | if(!this.settings.rules.multiple) {
718 | if(this.selected) {
719 | this.selected.children("A").removeClass("clicked");
720 | this.callback("ondeselect", [this.selected.get(0), _this]);
721 | }
722 | }
723 | // SAVE NEWLY SELECTED
724 | this.selected = obj;
725 | if(this.hovered !== false) {
726 | this.hovered.children("A").removeClass("hover");
727 | this.hovered = obj;
728 | }
729 |
730 | // FOCUS NEW NODE AND OPEN ALL PARENT NODES IF CLOSED
731 | this.selected.children("a").addClass("clicked").end().parents("li.closed").each( function () { _this.open_branch(this, true); });
732 |
733 | // SCROLL SELECTED NODE INTO VIEW
734 | this.scroll_into_view(this.selected);
735 |
736 | this.callback("onselect", [this.selected.get(0), _this]);
737 | this.callback("onchange", [this.selected.get(0), _this]);
738 | },
739 | deselect_branch : function (obj) {
740 | if(this.locked) return this.error("LOCKED");
741 | var _this = this;
742 | var obj = this.get_node(obj);
743 | if(obj.children("a.clicked").size() == 0) return this.error("DESELECT: NODE NOT SELECTED");
744 |
745 | obj.children("a").removeClass("clicked");
746 | this.callback("ondeselect", [obj.get(0), _this]);
747 | if(this.settings.rules.multiple != false && this.selected_arr.length > 1) {
748 | this.selected_arr = [];
749 | this.container.find("a.clicked").filter(":first-child").parent().each(function () {
750 | _this.selected_arr.push($(this));
751 | });
752 | if(obj.get(0) == this.selected.get(0)) {
753 | this.selected = this.selected_arr[0];
754 | }
755 | }
756 | else {
757 | if(this.settings.rules.multiple != false) this.selected_arr = [];
758 | this.selected = false;
759 | }
760 | this.callback("onchange", [obj.get(0), _this]);
761 | },
762 | toggle_branch : function (obj) {
763 | if(this.locked) return this.error("LOCKED");
764 | var obj = this.get_node(obj);
765 | if(obj.hasClass("closed")) return this.open_branch(obj);
766 | if(obj.hasClass("open")) return this.close_branch(obj);
767 | },
768 | open_branch : function (obj, disable_animation, callback) {
769 | var _this = this;
770 |
771 | if(this.locked) return this.error("LOCKED");
772 | var obj = this.get_node(obj);
773 | if(!obj.size()) return this.error("OPEN: NO SUCH NODE");
774 | if(obj.hasClass("leaf")) return this.error("OPEN: OPENING LEAF NODE");
775 | if(this.settings.data.async && obj.find("li").size() == 0) {
776 |
777 | if(this.callback("beforeopen",[obj.get(0),this]) === false) return this.error("OPEN: STOPPED BY USER");
778 |
779 | obj.children("ul:eq(0)").remove().end().append("");
780 | obj.removeClass("closed").addClass("open");
781 |
782 | var _datastore = new $.tree.datastores[this.settings.data.type]();
783 | _datastore.load(this.callback("beforedata",[obj,this]),this,this.settings.data.opts,function(data){
784 | data = _this.callback("ondata", [data, _this]);
785 | if(!data || data.length == 0) {
786 | obj.removeClass("closed").removeClass("open").addClass("leaf").children("ul").remove();
787 | if(callback) callback.call();
788 | return;
789 | }
790 | _datastore.parse(data,_this,_this.settings.data.opts,function(str){
791 | str = _this.callback("onparse", [str, _this]);
792 | // if(obj.children('ul:eq(0)').children('li').size() > 1) obj.children("ul").find('.loaading').parent().replaceWith(str); else
793 | obj.children("ul:eq(0)").replaceWith($("").html(str));
794 | obj.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
795 | obj.find("li").not(".open").not(".closed").addClass("leaf");
796 | _this.open_branch.apply(_this, [obj]);
797 | if(callback) callback.call();
798 | });
799 | });
800 | return true;
801 | }
802 | else {
803 | if(!this.settings.data.async) {
804 | if(this.callback("beforeopen",[obj.get(0),this]) === false) return this.error("OPEN: STOPPED BY USER");
805 | }
806 | if(parseInt(this.settings.ui.animation) > 0 && !disable_animation ) {
807 | obj.children("ul:eq(0)").css("display","none");
808 | obj.removeClass("closed").addClass("open");
809 | obj.children("ul:eq(0)").slideDown(parseInt(this.settings.ui.animation), function() {
810 | $(this).css("display","");
811 | if(callback) callback.call();
812 | });
813 | } else {
814 | obj.removeClass("closed").addClass("open");
815 | if(callback) callback.call();
816 | }
817 | this.callback("onopen", [obj.get(0), this]);
818 | return true;
819 | }
820 | },
821 | close_branch : function (obj, disable_animation) {
822 | if(this.locked) return this.error("LOCKED");
823 | var _this = this;
824 | var obj = this.get_node(obj);
825 | if(!obj.size()) return this.error("CLOSE: NO SUCH NODE");
826 | if(_this.callback("beforeclose",[obj.get(0),_this]) === false) return this.error("CLOSE: STOPPED BY USER");
827 | if(parseInt(this.settings.ui.animation) > 0 && !disable_animation && obj.children("ul:eq(0)").size() == 1) {
828 | obj.children("ul:eq(0)").slideUp(parseInt(this.settings.ui.animation), function() {
829 | if(obj.hasClass("open")) obj.removeClass("open").addClass("closed");
830 | $(this).css("display","");
831 | });
832 | }
833 | else {
834 | if(obj.hasClass("open")) obj.removeClass("open").addClass("closed");
835 | }
836 | if(this.selected && this.settings.ui.selected_parent_close !== false && obj.children("ul:eq(0)").find("a.clicked").size() > 0) {
837 | obj.find("li:has(a.clicked)").each(function() {
838 | _this.deselect_branch(this);
839 | });
840 | if(this.settings.ui.selected_parent_close == "select_parent" && obj.children("a.clicked").size() == 0) this.select_branch(obj, (this.settings.rules.multiple != false && this.selected_arr.length > 0) );
841 | }
842 | this.callback("onclose", [obj.get(0), this]);
843 | },
844 | open_all : function (obj, callback) {
845 | if(this.locked) return this.error("LOCKED");
846 | var _this = this;
847 | obj = obj ? this.get_node(obj) : this.container;
848 |
849 | var s = obj.find("li.closed").size();
850 | if(!callback) this.cl_count = 0;
851 | else this.cl_count --;
852 | if(s > 0) {
853 | this.cl_count += s;
854 | // maybe add .andSelf()
855 | obj.find("li.closed").each( function () { var __this = this; _this.open_branch.apply(_this, [this, true, function() { _this.open_all.apply(_this, [__this, true]); } ]); });
856 | }
857 | else if(this.cl_count == 0) this.callback("onopen_all",[this]);
858 | },
859 | close_all : function (obj) {
860 | if(this.locked) return this.error("LOCKED");
861 | var _this = this;
862 | obj = obj ? this.get_node(obj) : this.container;
863 | // maybe add .andSelf()
864 | obj.find("li.open").each( function () { _this.close_branch(this, true); });
865 | this.callback("onclose_all",[this]);
866 | },
867 |
868 | set_lang : function (i) {
869 | if(!$.isArray(this.settings.languages) || this.settings.languages.length == 0) return false;
870 | if(this.locked) return this.error("LOCKED");
871 | if(!$.inArray(i,this.settings.languages) && typeof this.settings.languages[i] != "undefined") i = this.settings.languages[i];
872 | if(typeof i == "undefined") return false;
873 | if(i == this.current_lang) return true;
874 | var st = false;
875 | var id = "#" + this.container.attr("id");
876 | st = tree_component.get_css(id + " ." + this.current_lang);
877 | if(st !== false) st.style.display = "none";
878 | st = tree_component.get_css(id + " ." + i);
879 | if(st !== false) st.style.display = "";
880 | this.current_lang = i;
881 | return true;
882 | },
883 | get_lang : function () {
884 | if(!$.isArray(this.settings.languages) || this.settings.languages.length == 0) return false;
885 | return this.current_lang;
886 | },
887 |
888 | create : function (obj, ref_node, position) {
889 | if(this.locked) return this.error("LOCKED");
890 |
891 | var root = false;
892 | if(ref_node == -1) { root = true; ref_node = this.container; }
893 | else ref_node = ref_node ? this.get_node(ref_node) : this.selected;
894 |
895 | if(!root && (!ref_node || !ref_node.size())) return this.error("CREATE: NO NODE SELECTED");
896 |
897 | var pos = position;
898 |
899 | var tmp = ref_node; // for type calculation
900 | if(position == "before") {
901 | position = ref_node.parent().children().index(ref_node);
902 | ref_node = ref_node.parents("li:eq(0)");
903 | }
904 | if(position == "after") {
905 | position = ref_node.parent().children().index(ref_node) + 1;
906 | ref_node = ref_node.parents("li:eq(0)");
907 | }
908 | if(!root && ref_node.size() == 0) { root = true; ref_node = this.container; }
909 |
910 | if(!root) {
911 | if(!this.check("creatable", ref_node)) return this.error("CREATE: CANNOT CREATE IN NODE");
912 | if(ref_node.hasClass("closed")) {
913 | if(this.settings.data.async && ref_node.children("ul").size() == 0) {
914 | var _this = this;
915 | return this.open_branch(ref_node, true, function () { _this.create.apply(_this, [obj, ref_node, position]); } );
916 | }
917 | else this.open_branch(ref_node, true);
918 | }
919 | }
920 |
921 | // creating new object to pass to parseJSON
922 | var torename = false;
923 | if(!obj) obj = {};
924 | else obj = $.extend(true, {}, obj);
925 | if(!obj.attributes) obj.attributes = {};
926 | if(!obj.attributes[this.settings.rules.type_attr]) obj.attributes[this.settings.rules.type_attr] = this.get_type(tmp) || "default";
927 | if(this.settings.languages.length) {
928 | if(!obj.data) { obj.data = {}; torename = true; }
929 | for(var i = 0; i < this.settings.languages.length; i++) {
930 | if(!obj.data[this.settings.languages[i]]) obj.data[this.settings.languages[i]] = ((typeof this.settings.lang.new_node).toLowerCase() != "string" && this.settings.lang.new_node[i]) ? this.settings.lang.new_node[i] : this.settings.lang.new_node;
931 | }
932 | }
933 | else {
934 | if(!obj.data) { obj.data = this.settings.lang.new_node; torename = true; }
935 | }
936 |
937 | obj = this.callback("ondata",[obj, this]);
938 | var obj_s = $.tree.datastores.json().parse(obj,this);
939 | obj_s = this.callback("onparse", [obj_s, this]);
940 | var $li = $(obj_s);
941 |
942 | if($li.children("ul").size()) {
943 | if(!$li.is(".open")) $li.addClass("closed");
944 | }
945 | else $li.addClass("leaf");
946 | $li.find("li:last-child").addClass("last").end().find("li:has(ul)").not(".open").addClass("closed");
947 | $li.find("li").not(".open").not(".closed").addClass("leaf");
948 |
949 | var r = {
950 | max_depth : this.settings.rules.use_max_depth ? this.check("max_depth", (root ? -1 : ref_node) ) : -1,
951 | max_children : this.settings.rules.use_max_children ? this.check("max_children", (root ? -1 : ref_node) ) : -1,
952 | valid_children : this.check("valid_children", (root ? -1 : ref_node) )
953 | };
954 | var nod_type = this.get_type($li);
955 | if(typeof r.valid_children != "undefined" && (r.valid_children == "none" || ($.isArray(r.valid_children) && $.inArray(nod_type, r.valid_children) == -1))) return this.error("CREATE: NODE NOT A VALID CHILD");
956 |
957 | if(this.settings.rules.use_max_children) {
958 | if(typeof r.max_children != "undefined" && r.max_children != -1 && r.max_children >= this.children(ref_node).size()) return this.error("CREATE: MAX_CHILDREN REACHED");
959 | }
960 |
961 | if(this.settings.rules.use_max_depth) {
962 | if(typeof r.max_depth != "undefined" && r.max_depth === 0) return this.error("CREATE: MAX-DEPTH REACHED");
963 | // check for max_depth up the chain
964 | var mx = (r.max_depth > 0) ? r.max_depth : false;
965 | var i = 0;
966 | var t = ref_node;
967 |
968 | while(t !== -1 && !root) {
969 | t = this.parent(t);
970 | i ++;
971 | var m = this.check("max_depth",t);
972 | if(m >= 0) {
973 | mx = (mx === false) ? (m - i) : Math.min(mx, m - i);
974 | }
975 | if(mx !== false && mx <= 0) return this.error("CREATE: MAX-DEPTH REACHED");
976 | }
977 | if(mx !== false && mx <= 0) return this.error("CREATE: MAX-DEPTH REACHED");
978 | if(mx !== false) {
979 | var incr = 1;
980 | var t = $li;
981 | while(t.size() > 0) {
982 | if(mx - incr < 0) return this.error("CREATE: MAX-DEPTH REACHED");
983 | t = t.children("ul").children("li");
984 | incr ++;
985 | }
986 | }
987 | }
988 |
989 | if((typeof position).toLowerCase() == "undefined" || position == "inside")
990 | position = (this.settings.rules.createat == "top") ? 0 : ref_node.children("ul:eq(0)").children("li").size();
991 | if(ref_node.children("ul").size() == 0 || (root == true && ref_node.children("ul").children("li").size() == 0) ) {
992 | if(!root) var a = this.moved($li,ref_node.children("a:eq(0)"),"inside", true);
993 | else var a = this.moved($li,this.container.children("ul:eq(0)"),"inside", true);
994 | }
995 | else if(pos == "before" && ref_node.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
996 | var a = this.moved($li,ref_node.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before", true);
997 | else if(pos == "after" && ref_node.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").size())
998 | var a = this.moved($li,ref_node.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").children("a:eq(0)"),"after", true);
999 | else if(ref_node.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1000 | var a = this.moved($li,ref_node.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before", true);
1001 | else
1002 | var a = this.moved($li,ref_node.children("ul:eq(0)").children("li:last").children("a:eq(0)"),"after",true);
1003 |
1004 | if(a === false) return this.error("CREATE: ABORTED");
1005 |
1006 | if(torename) {
1007 | this.select_branch($li.children("a:eq(0)"));
1008 | this.rename();
1009 | }
1010 | return $li;
1011 | },
1012 | rename : function (obj, new_name) {
1013 | if(this.locked) return this.error("LOCKED");
1014 | obj = obj ? this.get_node(obj) : this.selected;
1015 | var _this = this;
1016 | if(!obj || !obj.size()) return this.error("RENAME: NO NODE SELECTED");
1017 | if(!this.check("renameable", obj)) return this.error("RENAME: NODE NOT RENAMABLE");
1018 | if(!this.callback("beforerename",[obj.get(0), _this.current_lang, _this])) return this.error("RENAME: STOPPED BY USER");
1019 |
1020 | obj.parents("li.closed").each(function () { _this.open_branch(this) });
1021 | if(this.current_lang) obj = obj.find("a." + this.current_lang);
1022 | else obj = obj.find("a:first");
1023 |
1024 | // Rollback
1025 | var rb = {};
1026 | rb[this.container.attr("id")] = this.get_rollback();
1027 |
1028 | var icn = obj.children("ins").clone();
1029 | if((typeof new_name).toLowerCase() == "string") {
1030 | obj.text(new_name).prepend(icn);
1031 | _this.callback("onrename", [_this.get_node(obj).get(0), _this, rb]);
1032 | }
1033 | else {
1034 | var last_value = "";
1035 | obj.contents().each(function () {
1036 | if(this.nodeType == 3) { last_value = this.data; return false; }
1037 | });
1038 | _this.inp = $(" ");
1039 | _this.inp
1040 | .val(last_value.replace(/&/g,"&").replace(/>/g,">").replace(/</g,"<"))
1041 | .bind("mousedown", function (event) { event.stopPropagation(); })
1042 | .bind("mouseup", function (event) { event.stopPropagation(); })
1043 | .bind("click", function (event) { event.stopPropagation(); })
1044 | .bind("keyup", function (event) {
1045 | var key = event.keyCode || event.which;
1046 | if(key == 27) { this.value = last_value; this.blur(); return }
1047 | if(key == 13) { this.blur(); return; }
1048 | });
1049 | _this.inp.blur(function(event) {
1050 | if(this.value == "") this.value = last_value;
1051 | obj.text(this.value).prepend(icn);
1052 | obj.get(0).style.display = "";
1053 | obj.prevAll("span").remove();
1054 | _this.inp = false;
1055 | _this.callback("onrename", [_this.get_node(obj).get(0), _this, rb]);
1056 | });
1057 |
1058 | var spn = $(" ").addClass(obj.attr("class")).append(icn).append(_this.inp);
1059 | obj.get(0).style.display = "none";
1060 | obj.parent().prepend(spn);
1061 | _this.inp.get(0).focus();
1062 | _this.inp.get(0).select();
1063 | }
1064 | },
1065 | remove : function(obj) {
1066 | if(this.locked) return this.error("LOCKED");
1067 | var _this = this;
1068 |
1069 | // Rollback
1070 | var rb = {};
1071 | rb[this.container.attr("id")] = this.get_rollback();
1072 |
1073 | if(obj && (!this.selected || this.get_node(obj).get(0) != this.selected.get(0) )) {
1074 | obj = this.get_node(obj);
1075 | if(obj.size()) {
1076 | if(!this.check("deletable", obj)) return this.error("DELETE: NODE NOT DELETABLE");
1077 | if(!this.callback("beforedelete",[obj.get(0), _this])) return this.error("DELETE: STOPPED BY USER");
1078 | $parent = obj.parent();
1079 | if(obj.find("a.clicked").size()) {
1080 | var reset_selected = false;
1081 | _this.selected_arr = [];
1082 | this.container.find("a.clicked").filter(":first-child").parent().each(function () {
1083 | if(!reset_selected && this == _this.selected.get(0)) reset_selected = true;
1084 | if($(this).parents().index(obj) != -1) return true;
1085 | _this.selected_arr.push($(this));
1086 | });
1087 | if(reset_selected) this.selected = this.selected_arr[0] || false;
1088 | }
1089 | obj = obj.remove();
1090 | $parent.children("li:last").addClass("last");
1091 | if($parent.children("li").size() == 0) {
1092 | $li = $parent.parents("li:eq(0)");
1093 | $li.removeClass("open").removeClass("closed").addClass("leaf").children("ul").remove();
1094 | }
1095 | this.callback("ondelete", [obj.get(0), this, rb]);
1096 | }
1097 | }
1098 | else if(this.selected) {
1099 | if(!this.check("deletable", this.selected)) return this.error("DELETE: NODE NOT DELETABLE");
1100 | if(!this.callback("beforedelete",[this.selected.get(0), _this])) return this.error("DELETE: STOPPED BY USER");
1101 | $parent = this.selected.parent();
1102 | var obj = this.selected;
1103 | if(this.settings.rules.multiple == false || this.selected_arr.length == 1) {
1104 | var stop = true;
1105 | var tmp = this.settings.ui.selected_delete == "select_previous" ? this.prev(this.selected) : false;
1106 | }
1107 | obj = obj.remove();
1108 | $parent.children("li:last").addClass("last");
1109 | if($parent.children("li").size() == 0) {
1110 | $li = $parent.parents("li:eq(0)");
1111 | $li.removeClass("open").removeClass("closed").addClass("leaf").children("ul").remove();
1112 | }
1113 | if(!stop && this.settings.rules.multiple != false) {
1114 | var _this = this;
1115 | this.selected_arr = [];
1116 | this.container.find("a.clicked").filter(":first-child").parent().each(function () {
1117 | _this.selected_arr.push($(this));
1118 | });
1119 | if(this.selected_arr.length > 0) {
1120 | this.selected = this.selected_arr[0];
1121 | this.remove();
1122 | }
1123 | }
1124 | if(stop && tmp) this.select_branch(tmp);
1125 | this.callback("ondelete", [obj.get(0), this, rb]);
1126 | }
1127 | else return this.error("DELETE: NO NODE SELECTED");
1128 | },
1129 |
1130 | next : function (obj, strict) {
1131 | obj = this.get_node(obj);
1132 | if(!obj.size()) return false;
1133 | if(strict) return (obj.nextAll("li").size() > 0) ? obj.nextAll("li:eq(0)") : false;
1134 |
1135 | if(obj.hasClass("open")) return obj.find("li:eq(0)");
1136 | else if(obj.nextAll("li").size() > 0) return obj.nextAll("li:eq(0)");
1137 | else return obj.parents("li").next("li").eq(0);
1138 | },
1139 | prev : function(obj, strict) {
1140 | obj = this.get_node(obj);
1141 | if(!obj.size()) return false;
1142 | if(strict) return (obj.prevAll("li").size() > 0) ? obj.prevAll("li:eq(0)") : false;
1143 |
1144 | if(obj.prev("li").size()) {
1145 | var obj = obj.prev("li").eq(0);
1146 | while(obj.hasClass("open")) obj = obj.children("ul:eq(0)").children("li:last");
1147 | return obj;
1148 | }
1149 | else return obj.parents("li:eq(0)").size() ? obj.parents("li:eq(0)") : false;
1150 | },
1151 | parent : function(obj) {
1152 | obj = this.get_node(obj);
1153 | if(!obj.size()) return false;
1154 | return obj.parents("li:eq(0)").size() ? obj.parents("li:eq(0)") : -1;
1155 | },
1156 | children : function(obj) {
1157 | if(obj === -1) return this.container.children("ul:eq(0)").children("li");
1158 |
1159 | obj = this.get_node(obj);
1160 | if(!obj.size()) return false;
1161 | return obj.children("ul:eq(0)").children("li");
1162 | },
1163 |
1164 | toggle_dots : function () {
1165 | if(this.settings.ui.dots) {
1166 | this.settings.ui.dots = false;
1167 | this.container.children("ul:eq(0)").addClass("no_dots");
1168 | }
1169 | else {
1170 | this.settings.ui.dots = true;
1171 | this.container.children("ul:eq(0)").removeClass("no_dots");
1172 | }
1173 | },
1174 |
1175 | callback : function (cb, args) {
1176 | var p = false;
1177 | var r = null;
1178 | for(var i in this.settings.plugins) {
1179 | if(typeof $.tree.plugins[i] != "object") continue;
1180 | p = $.tree.plugins[i];
1181 | if(p.callbacks && typeof p.callbacks[cb] == "function") r = p.callbacks[cb].apply(this, args);
1182 | if(typeof r !== "undefined" && r !== null) {
1183 | if(cb == "ondata" || cb == "onparse") args[0] = r; // keep the chain if data or parse
1184 | else return r;
1185 | }
1186 | }
1187 | p = this.settings.callback[cb];
1188 | if(typeof p == "function") return p.apply(null, args);
1189 | },
1190 | get_rollback : function () {
1191 | var rb = {};
1192 | rb.html = this.container.html();
1193 | rb.selected = this.selected ? this.selected.attr("id") : false;
1194 | return rb;
1195 | },
1196 | moved : function (what, where, how, is_new, is_copy, rb) {
1197 | var what = $(what);
1198 | var $parent = $(what).parents("ul:eq(0)");
1199 | var $where = $(where);
1200 | if($where.is("ins")) $where = $where.parent();
1201 |
1202 | // Rollback
1203 | if(!rb) {
1204 | var rb = {};
1205 | rb[this.container.attr("id")] = this.get_rollback();
1206 | if(!is_new) {
1207 | var tmp = what.size() > 1 ? what.eq(0).parents(".tree:eq(0)") : what.parents(".tree:eq(0)");
1208 | if(tmp.get(0) != this.container.get(0)) {
1209 | tmp = tree_component.inst[tmp.attr("id")];
1210 | rb[tmp.container.attr("id")] = tmp.get_rollback();
1211 | }
1212 | delete tmp;
1213 | }
1214 | }
1215 |
1216 | if(how == "inside" && this.settings.data.async) {
1217 | var _this = this;
1218 | if(this.get_node($where).hasClass("closed")) {
1219 | return this.open_branch(this.get_node($where), true, function () { _this.moved.apply(_this, [what, where, how, is_new, is_copy, rb]); });
1220 | }
1221 | if(this.get_node($where).find("> ul > li > a.loading").size() == 1) {
1222 | setTimeout(function () { _this.moved.apply(_this, [what, where, how, is_new, is_copy]); }, 200);
1223 | return;
1224 | }
1225 | }
1226 |
1227 |
1228 | // IF MULTIPLE
1229 | if(what.size() > 1) {
1230 | var _this = this;
1231 | var tmp = this.moved(what.eq(0), where, how, false, is_copy, rb);
1232 | what.each(function (i) {
1233 | if(i == 0) return;
1234 | if(tmp) { // if tmp is false - the previous move was a no-go
1235 | tmp = _this.moved(this, tmp.children("a:eq(0)"), "after", false, is_copy, rb);
1236 | }
1237 | });
1238 | return what;
1239 | }
1240 |
1241 | if(is_copy) {
1242 | _what = what.clone();
1243 | _what.each(function (i) {
1244 | this.id = this.id + "_copy";
1245 | $(this).find("li").each(function () {
1246 | this.id = this.id + "_copy";
1247 | });
1248 | $(this).removeClass("dragged").find("a.clicked").removeClass("clicked").end().find("li.dragged").removeClass("dragged");
1249 | });
1250 | }
1251 | else _what = what;
1252 | if(is_new) {
1253 | if(!this.callback("beforecreate", [this.get_node(what).get(0), this.get_node(where).get(0),how,this])) return false;
1254 | }
1255 | else {
1256 | if(!this.callback("beforemove", [this.get_node(what).get(0), this.get_node(where).get(0),how,this])) return false;
1257 | }
1258 |
1259 | if(!is_new) {
1260 | var tmp = what.parents(".tree:eq(0)");
1261 | // if different trees
1262 | if(tmp.get(0) != this.container.get(0)) {
1263 | tmp = tree_component.inst[tmp.attr("id")];
1264 |
1265 | // if there are languages - otherwise - no cleanup needed
1266 | if(tmp.settings.languages.length) {
1267 | var res = [];
1268 | // if new tree has no languages - use current visible
1269 | if(this.settings.languages.length == 0) res.push("." + tmp.current_lang);
1270 | else {
1271 | for(var i in this.settings.languages) {
1272 | if(!this.settings.languages.hasOwnProperty(i)) continue;
1273 | for(var j in tmp.settings.languages) {
1274 | if(!tmp.settings.languages.hasOwnProperty(j)) continue;
1275 | if(this.settings.languages[i] == tmp.settings.languages[j]) res.push("." + this.settings.languages[i]);
1276 | }
1277 | }
1278 | }
1279 | if(res.length == 0) return this.error("MOVE: NO COMMON LANGUAGES");
1280 | _what.find("a").not(res.join(",")).remove();
1281 | }
1282 | _what.find("a.clicked").removeClass("clicked");
1283 | }
1284 | }
1285 | what = _what;
1286 |
1287 | // ADD NODE TO NEW PLACE
1288 | switch(how) {
1289 | case "before":
1290 | $where.parents("ul:eq(0)").children("li.last").removeClass("last");
1291 | $where.parent().before(what.removeClass("last"));
1292 | $where.parents("ul:eq(0)").children("li:last").addClass("last");
1293 | break;
1294 | case "after":
1295 | $where.parents("ul:eq(0)").children("li.last").removeClass("last");
1296 | $where.parent().after(what.removeClass("last"));
1297 | $where.parents("ul:eq(0)").children("li:last").addClass("last");
1298 | break;
1299 | case "inside":
1300 | if($where.parent().children("ul:first").size()) {
1301 | if(this.settings.rules.createat == "top") {
1302 | $where.parent().children("ul:first").prepend(what.removeClass("last")).children("li:last").addClass("last");
1303 |
1304 | // restored this section
1305 | var tmp_node = $where.parent().children("ul:first").children("li:first");
1306 | if(tmp_node.size()) {
1307 | how = "before";
1308 | where = tmp_node;
1309 | }
1310 | }
1311 | else {
1312 | // restored this section
1313 | var tmp_node = $where.parent().children("ul:first").children(".last");
1314 | if(tmp_node.size()) {
1315 | how = "after";
1316 | where = tmp_node;
1317 | }
1318 |
1319 | $where.parent().children("ul:first").children(".last").removeClass("last").end().append(what.removeClass("last")).children("li:last").addClass("last");
1320 | }
1321 | }
1322 | else {
1323 | what.addClass("last");
1324 | $where.parent().removeClass("leaf").append("");
1325 | if(!$where.parent().hasClass("open")) $where.parent().addClass("closed");
1326 | $where.parent().children("ul:first").prepend(what);
1327 | }
1328 | if($where.parent().hasClass("closed")) { this.open_branch($where); }
1329 | break;
1330 | default:
1331 | break;
1332 | }
1333 | // CLEANUP OLD PARENT
1334 | if($parent.find("li").size() == 0) {
1335 | var $li = $parent.parent();
1336 | $li.removeClass("open").removeClass("closed").addClass("leaf");
1337 | if(!$li.is(".tree")) $li.children("ul").remove();
1338 | $li.parents("ul:eq(0)").children("li.last").removeClass("last").end().children("li:last").addClass("last");
1339 | }
1340 | else {
1341 | $parent.children("li.last").removeClass("last");
1342 | $parent.children("li:last").addClass("last");
1343 | }
1344 |
1345 | // NO LONGER CORRECT WITH position PARAM - if(is_new && how != "inside") where = this.get_node(where).parents("li:eq(0)");
1346 | if(is_copy) this.callback("oncopy", [this.get_node(what).get(0), this.get_node(where).get(0), how, this, rb]);
1347 | else if(is_new) this.callback("oncreate", [this.get_node(what).get(0), ($where.is("ul") ? -1 : this.get_node(where).get(0) ), how, this, rb]);
1348 | else this.callback("onmove", [this.get_node(what).get(0), this.get_node(where).get(0), how, this, rb]);
1349 | return what;
1350 | },
1351 | error : function (code) {
1352 | this.callback("error",[code,this]);
1353 | return false;
1354 | },
1355 | lock : function (state) {
1356 | this.locked = state;
1357 | if(this.locked) this.container.children("ul:eq(0)").addClass("locked");
1358 | else this.container.children("ul:eq(0)").removeClass("locked");
1359 | },
1360 | cut : function (obj) {
1361 | if(this.locked) return this.error("LOCKED");
1362 | obj = obj ? this.get_node(obj) : this.container.find("a.clicked").filter(":first-child").parent();
1363 | if(!obj || !obj.size()) return this.error("CUT: NO NODE SELECTED");
1364 | tree_component.cut_copy.copy_nodes = false;
1365 | tree_component.cut_copy.cut_nodes = obj;
1366 | },
1367 | copy : function (obj) {
1368 | if(this.locked) return this.error("LOCKED");
1369 | obj = obj ? this.get_node(obj) : this.container.find("a.clicked").filter(":first-child").parent();
1370 | if(!obj || !obj.size()) return this.error("COPY: NO NODE SELECTED");
1371 | tree_component.cut_copy.copy_nodes = obj;
1372 | tree_component.cut_copy.cut_nodes = false;
1373 | },
1374 | paste : function (obj, position) {
1375 | if(this.locked) return this.error("LOCKED");
1376 |
1377 | var root = false;
1378 | if(obj == -1) { root = true; obj = this.container; }
1379 | else obj = obj ? this.get_node(obj) : this.selected;
1380 |
1381 | if(!root && (!obj || !obj.size())) return this.error("PASTE: NO NODE SELECTED");
1382 | if(!tree_component.cut_copy.copy_nodes && !tree_component.cut_copy.cut_nodes) return this.error("PASTE: NOTHING TO DO");
1383 |
1384 | var _this = this;
1385 |
1386 | var pos = position;
1387 |
1388 | if(position == "before") {
1389 | position = obj.parent().children().index(obj);
1390 | obj = obj.parents("li:eq(0)");
1391 | }
1392 | else if(position == "after") {
1393 | position = obj.parent().children().index(obj) + 1;
1394 | obj = obj.parents("li:eq(0)");
1395 | }
1396 | else if((typeof position).toLowerCase() == "undefined" || position == "inside") {
1397 | position = (this.settings.rules.createat == "top") ? 0 : obj.children("ul:eq(0)").children("li").size();
1398 | }
1399 | if(!root && obj.size() == 0) { root = true; obj = this.container; }
1400 |
1401 | if(tree_component.cut_copy.copy_nodes && tree_component.cut_copy.copy_nodes.size()) {
1402 | var ok = true;
1403 | if(!root && !this.check_move(tree_component.cut_copy.copy_nodes, obj.children("a:eq(0)"), "inside")) return false;
1404 |
1405 | if(obj.children("ul").size() == 0 || (root == true && obj.children("ul").children("li").size() == 0) ) {
1406 | if(!root) var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("a:eq(0)"),"inside", false, true);
1407 | else var a = this.moved(tree_component.cut_copy.copy_nodes,this.container.children("ul:eq(0)"),"inside", false, true);
1408 | }
1409 | else if(pos == "before" && obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1410 | var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before", false, true);
1411 | else if(pos == "after" && obj.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").size())
1412 | var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").children("a:eq(0)"),"after", false, true);
1413 | else if(obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1414 | var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before", false, true);
1415 | else
1416 | var a = this.moved(tree_component.cut_copy.copy_nodes,obj.children("ul:eq(0)").children("li:last").children("a:eq(0)"),"after", false, true);
1417 | tree_component.cut_copy.copy_nodes = false;
1418 | }
1419 | if(tree_component.cut_copy.cut_nodes && tree_component.cut_copy.cut_nodes.size()) {
1420 | var ok = true;
1421 | obj.parents().andSelf().each(function () {
1422 | if(tree_component.cut_copy.cut_nodes.index(this) != -1) {
1423 | ok = false;
1424 | return false;
1425 | }
1426 | });
1427 | if(!ok) return this.error("Invalid paste");
1428 | if(!root && !this.check_move(tree_component.cut_copy.cut_nodes, obj.children("a:eq(0)"), "inside")) return false;
1429 |
1430 | if(obj.children("ul").size() == 0 || (root == true && obj.children("ul").children("li").size() == 0) ) {
1431 | if(!root) var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("a:eq(0)"),"inside");
1432 | else var a = this.moved(tree_component.cut_copy.cut_nodes,this.container.children("ul:eq(0)"),"inside");
1433 | }
1434 | else if(pos == "before" && obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1435 | var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before");
1436 | else if(pos == "after" && obj.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").size())
1437 | var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position) + ")").children("a:eq(0)"),"after");
1438 | else if(obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").size())
1439 | var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("ul:eq(0)").children("li:nth-child(" + (position + 1) + ")").children("a:eq(0)"),"before");
1440 | else
1441 | var a = this.moved(tree_component.cut_copy.cut_nodes,obj.children("ul:eq(0)").children("li:last").children("a:eq(0)"),"after");
1442 | tree_component.cut_copy.cut_nodes = false;
1443 | }
1444 | },
1445 | search : function(str, func) {
1446 | var _this = this;
1447 | if(!str || (this.srch && str != this.srch) ) {
1448 | this.srch = "";
1449 | this.srch_opn = false;
1450 | this.container.find("a.search").removeClass("search");
1451 | }
1452 | this.srch = str;
1453 | if(!str) return;
1454 |
1455 | if(!func) func = "contains";
1456 | if(this.settings.data.async) {
1457 | if(!this.srch_opn) {
1458 | var dd = $.extend( { "search" : str } , this.callback("beforedata", [false, this] ) );
1459 | $.ajax({
1460 | type : this.settings.data.opts.method,
1461 | url : this.settings.data.opts.url,
1462 | data : dd,
1463 | dataType : "text",
1464 | success : function (data) {
1465 | _this.srch_opn = $.unique(data.split(","));
1466 | _this.search.apply(_this,[str, func]);
1467 | }
1468 | });
1469 | }
1470 | else if(this.srch_opn.length) {
1471 | if(this.srch_opn && this.srch_opn.length) {
1472 | var opn = false;
1473 | for(var j = 0; j < this.srch_opn.length; j++) {
1474 | if(this.get_node("#" + this.srch_opn[j]).size() > 0) {
1475 | opn = true;
1476 | var tmp = "#" + this.srch_opn[j];
1477 | delete this.srch_opn[j];
1478 | this.open_branch(tmp, true, function () { _this.search.apply(_this,[str, func]); } );
1479 | }
1480 | }
1481 | if(!opn) {
1482 | this.srch_opn = [];
1483 | _this.search.apply(_this,[str, func]);
1484 | }
1485 | }
1486 | }
1487 | else {
1488 | this.srch_opn = false;
1489 | var selector = "a";
1490 | // IF LANGUAGE VERSIONS
1491 | if(this.settings.languages.length) selector += "." + this.current_lang;
1492 | this.callback("onsearch", [this.container.find(selector + ":" + func + "('" + str + "')"), this]);
1493 | }
1494 | }
1495 | else {
1496 | var selector = "a";
1497 | // IF LANGUAGE VERSIONS
1498 | if(this.settings.languages.length) selector += "." + this.current_lang;
1499 | var nn = this.container.find(selector + ":" + func + "('" + str + "')");
1500 | nn.parents("li.closed").each( function () { _this.open_branch(this, true); });
1501 | this.callback("onsearch", [nn, this]);
1502 | }
1503 | },
1504 | add_sheet : tree_component.add_sheet,
1505 |
1506 | destroy : function() {
1507 | this.callback("ondestroy", [this]);
1508 |
1509 | this.container.unbind(".jstree");
1510 | $("#" + this.container.attr("id")).die("click.jstree").die("dblclick.jstree").die("mouseover.jstree").die("mouseout.jstree").die("mousedown.jstree");
1511 | this.container.removeClass("tree ui-widget ui-widget-content tree-default tree-" + this.settings.ui.theme_name).children("ul").removeClass("no_dots ltr locked").find("li").removeClass("leaf").removeClass("open").removeClass("closed").removeClass("last").children("a").removeClass("clicked hover search");
1512 |
1513 | if(this.cntr == tree_component.focused) {
1514 | for(var i in tree_component.inst) {
1515 | if(i != this.cntr && i != this.container.attr("id")) {
1516 | tree_component.inst[i].focus();
1517 | break;
1518 | }
1519 | }
1520 | }
1521 |
1522 | tree_component.inst[this.cntr] = false;
1523 | tree_component.inst[this.container.attr("id")] = false;
1524 | delete tree_component.inst[this.cntr];
1525 | delete tree_component.inst[this.container.attr("id")];
1526 | tree_component.cntr --;
1527 | }
1528 | }
1529 | };
1530 |
1531 | // instance manager
1532 | tree_component.cntr = 0;
1533 | tree_component.inst = {};
1534 |
1535 | // themes
1536 | tree_component.themes = [];
1537 |
1538 | // drag'n'drop stuff
1539 | tree_component.drag_drop = {
1540 | isdown : false, // Is there a drag
1541 | drag_node : false, // The actual node
1542 | drag_help : false, // The helper
1543 | dragged : false,
1544 |
1545 | init_x : false,
1546 | init_y : false,
1547 | moving : false,
1548 |
1549 | origin_tree : false,
1550 | marker : false,
1551 |
1552 | move_type : false, // before, after or inside
1553 | ref_node : false, // reference node
1554 | appended : false, // is helper appended
1555 |
1556 | foreign : false, // Is the dragged node a foreign one
1557 | droppable : [], // Array of classes that can be dropped onto the tree
1558 |
1559 | open_time : false, // Timeout for opening nodes
1560 | scroll_time : false // Timeout for scrolling
1561 | };
1562 | tree_component.mouseup = function(event) {
1563 | var tmp = tree_component.drag_drop;
1564 | if(tmp.open_time) clearTimeout(tmp.open_time);
1565 | if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
1566 |
1567 | if(tmp.moving && $.tree.drag_end !== false) $.tree.drag_end.call(null, event, tmp);
1568 |
1569 | if(tmp.foreign === false && tmp.drag_node && tmp.drag_node.size()) {
1570 | tmp.drag_help.remove();
1571 | if(tmp.move_type) {
1572 | var tree1 = tree_component.inst[tmp.ref_node.parents(".tree:eq(0)").attr("id")];
1573 | if(tree1) tree1.moved(tmp.dragged, tmp.ref_node, tmp.move_type, false, (tmp.origin_tree.settings.rules.drag_copy == "on" || (tmp.origin_tree.settings.rules.drag_copy == "ctrl" && event.ctrlKey) ) );
1574 | }
1575 | tmp.move_type = false;
1576 | tmp.ref_node = false;
1577 | }
1578 | if(tmp.foreign !== false) {
1579 | if(tmp.drag_help) tmp.drag_help.remove();
1580 | if(tmp.move_type) {
1581 | var tree1 = tree_component.inst[tmp.ref_node.parents(".tree:eq(0)").attr("id")];
1582 | if(tree1) tree1.callback("ondrop",[tmp.f_data, tree1.get_node(tmp.ref_node).get(0), tmp.move_type, tree1]);
1583 | }
1584 | tmp.foreign = false;
1585 | tmp.move_type = false;
1586 | tmp.ref_node = false;
1587 | }
1588 | // RESET EVERYTHING
1589 | if(tree_component.drag_drop.marker) tree_component.drag_drop.marker.hide();
1590 | if(tmp.dragged && tmp.dragged.size()) tmp.dragged.removeClass("dragged");
1591 | tmp.dragged = false;
1592 | tmp.drag_help = false;
1593 | tmp.drag_node = false;
1594 | tmp.f_type = false;
1595 | tmp.f_data = false;
1596 | tmp.init_x = false;
1597 | tmp.init_y = false;
1598 | tmp.moving = false;
1599 | tmp.appended = false;
1600 | tmp.origin_tree = false;
1601 | if(tmp.isdown) {
1602 | tmp.isdown = false;
1603 | event.preventDefault();
1604 | event.stopPropagation();
1605 | return false;
1606 | }
1607 | };
1608 | tree_component.mousemove = function(event) {
1609 | var tmp = tree_component.drag_drop;
1610 | var is_start = false;
1611 |
1612 | if(tmp.isdown) {
1613 | if(!tmp.moving && Math.abs(tmp.init_x - event.pageX) < 5 && Math.abs(tmp.init_y - event.pageY) < 5) {
1614 | event.preventDefault();
1615 | event.stopPropagation();
1616 | return false;
1617 | }
1618 | else {
1619 | if(!tmp.moving) {
1620 | tree_component.drag_drop.moving = true;
1621 | is_start = true;
1622 | }
1623 | }
1624 |
1625 | if(tmp.open_time) clearTimeout(tmp.open_time);
1626 |
1627 | if(tmp.drag_help !== false) {
1628 | if(!tmp.appended) {
1629 | if(tmp.foreign !== false) tmp.origin_tree = $.tree.focused();
1630 | $("body").append(tmp.drag_help);
1631 | tmp.w = tmp.drag_help.width();
1632 | tmp.appended = true;
1633 | }
1634 | tmp.drag_help.css({ "left" : (event.pageX + 5 ), "top" : (event.pageY + 15) });
1635 | }
1636 |
1637 | if(is_start && $.tree.drag_start !== false) $.tree.drag_start.call(null, event, tmp);
1638 | if($.tree.drag !== false) $.tree.drag.call(null, event, tmp);
1639 |
1640 | if(event.target.tagName == "DIV" && event.target.id == "jstree-marker") return false;
1641 |
1642 | var et = $(event.target);
1643 | if(et.is("ins")) et = et.parent();
1644 | var cnt = et.is(".tree") ? et : et.parents(".tree:eq(0)");
1645 |
1646 | // if not moving over a tree
1647 | if(cnt.size() == 0 || !tree_component.inst[cnt.attr("id")]) {
1648 | if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
1649 | if(tmp.drag_help !== false) tmp.drag_help.find("li:eq(0) ins").addClass("forbidden");
1650 | tmp.move_type = false;
1651 | tmp.ref_node = false;
1652 | tree_component.drag_drop.marker.hide();
1653 | return false;
1654 | }
1655 |
1656 | var tree2 = tree_component.inst[cnt.attr("id")];
1657 | tree2.off_height();
1658 |
1659 | if(tmp.scroll_time) clearTimeout(tmp.scroll_time);
1660 | tmp.scroll_time = setTimeout( function() { tree2.scroll_check(event.pageX,event.pageY); }, 50);
1661 |
1662 | var mov = false;
1663 | var st = cnt.scrollTop();
1664 |
1665 | if(event.target.tagName == "A" || event.target.tagName == "INS") {
1666 | // just in case if hover is over the draggable
1667 | if(et.is("#jstree-dragged")) return false;
1668 | if(tree2.get_node(event.target).hasClass("closed")) {
1669 | tmp.open_time = setTimeout( function () { tree2.open_branch(et); }, 500);
1670 | }
1671 |
1672 | var et_off = et.offset();
1673 | var goTo = {
1674 | x : (et_off.left - 1),
1675 | y : (event.pageY - et_off.top)
1676 | };
1677 |
1678 | var arr = [];
1679 | if(goTo.y < tree2.li_height/3 + 1 ) arr = ["before","inside","after"];
1680 | else if(goTo.y > tree2.li_height*2/3 - 1 ) arr = ["after","inside","before"];
1681 | else {
1682 | if(goTo.y < tree2.li_height/2) arr = ["inside","before","after"];
1683 | else arr = ["inside","after","before"];
1684 | }
1685 | var ok = false;
1686 | var nn = (tmp.foreign == false) ? tmp.origin_tree.container.find("li.dragged") : tmp.f_type;
1687 | $.each(arr, function(i, val) {
1688 | if(tree2.check_move(nn, et, val)) {
1689 | mov = val;
1690 | ok = true;
1691 | return false;
1692 | }
1693 | });
1694 | if(ok) {
1695 | switch(mov) {
1696 | case "before":
1697 | goTo.y = et_off.top - 2;
1698 | tree_component.drag_drop.marker.attr("class","marker");
1699 | break;
1700 | case "after":
1701 | goTo.y = et_off.top - 2 + tree2.li_height;
1702 | tree_component.drag_drop.marker.attr("class","marker");
1703 | break;
1704 | case "inside":
1705 | goTo.x -= 2;
1706 | goTo.y = et_off.top - 2 + tree2.li_height/2;
1707 | tree_component.drag_drop.marker.attr("class","marker_plus");
1708 | break;
1709 | }
1710 | tmp.move_type = mov;
1711 | tmp.ref_node = $(event.target);
1712 | if(tmp.drag_help !== false) tmp.drag_help.find(".forbidden").removeClass("forbidden");
1713 | tree_component.drag_drop.marker.css({ "left" : goTo.x , "top" : goTo.y }).show();
1714 | }
1715 | }
1716 |
1717 | if( (et.is(".tree") || et.is("ul") ) && et.find("li:eq(0)").size() == 0) {
1718 | var et_off = et.offset();
1719 | tmp.move_type = "inside";
1720 | tmp.ref_node = cnt.children("ul:eq(0)");
1721 | if(tmp.drag_help !== false) tmp.drag_help.find(".forbidden").removeClass("forbidden");
1722 | tree_component.drag_drop.marker.attr("class","marker_plus");
1723 | tree_component.drag_drop.marker.css({ "left" : (et_off.left + 10) , "top" : et_off.top + 15 }).show();
1724 | }
1725 | else if( (event.target.tagName != "A" && event.target.tagName != "INS") || !ok) {
1726 | if(tmp.drag_help !== false) tmp.drag_help.find("li:eq(0) ins").addClass("forbidden");
1727 | tmp.move_type = false;
1728 | tmp.ref_node = false;
1729 | tree_component.drag_drop.marker.hide();
1730 | }
1731 | event.preventDefault();
1732 | event.stopPropagation();
1733 | return false;
1734 | }
1735 | return true;
1736 | };
1737 | $(function () {
1738 | $(document).bind("mousemove.jstree", tree_component.mousemove);
1739 | $(document).bind("mouseup.jstree", tree_component.mouseup);
1740 | });
1741 |
1742 | // cut, copy, paste stuff
1743 | tree_component.cut_copy = {
1744 | copy_nodes : false,
1745 | cut_nodes : false
1746 | };
1747 |
1748 | // css stuff
1749 | tree_component.css = false;
1750 | tree_component.get_css = function(rule_name, delete_flag) {
1751 | rule_name = rule_name.toLowerCase();
1752 | var css_rules = tree_component.css.cssRules || tree_component.css.rules;
1753 | var j = 0;
1754 | do {
1755 | if(css_rules.length && j > css_rules.length + 5) return false;
1756 | if(css_rules[j].selectorText && css_rules[j].selectorText.toLowerCase() == rule_name) {
1757 | if(delete_flag == true) {
1758 | if(tree_component.css.removeRule) document.styleSheets[i].removeRule(j);
1759 | if(tree_component.css.deleteRule) document.styleSheets[i].deleteRule(j);
1760 | return true;
1761 | }
1762 | else return css_rules[j];
1763 | }
1764 | }
1765 | while (css_rules[++j]);
1766 | return false;
1767 | };
1768 | tree_component.add_css = function(rule_name) {
1769 | if(tree_component.get_css(rule_name)) return false;
1770 | (tree_component.css.insertRule) ? tree_component.css.insertRule(rule_name + ' { }', 0) : tree_component.css.addRule(rule_name, null, 0);
1771 | return tree_component.get_css(rule_name);
1772 | };
1773 | tree_component.remove_css = function(rule_name) {
1774 | return tree_component.get_css(rule_name, true);
1775 | };
1776 | tree_component.add_sheet = function(opts) {
1777 | if(opts.str) {
1778 | var tmp = document.createElement("style");
1779 | tmp.setAttribute('type',"text/css");
1780 | if(tmp.styleSheet) {
1781 | document.getElementsByTagName("head")[0].appendChild(tmp);
1782 | tmp.styleSheet.cssText = opts.str;
1783 | }
1784 | else {
1785 | tmp.appendChild(document.createTextNode(opts.str));
1786 | document.getElementsByTagName("head")[0].appendChild(tmp);
1787 | }
1788 | return tmp.sheet || tmp.styleSheet;
1789 | }
1790 | if(opts.url) {
1791 | if(document.createStyleSheet) {
1792 | try { document.createStyleSheet(opts.url); } catch (e) { };
1793 | }
1794 | else {
1795 | var newSS = document.createElement('link');
1796 | newSS.rel = 'stylesheet';
1797 | newSS.type = 'text/css';
1798 | newSS.media = "all";
1799 | newSS.href = opts.url;
1800 | // var styles = "@import url(' " + url + " ');";
1801 | // newSS.href ='data:text/css,'+escape(styles);
1802 | document.getElementsByTagName("head")[0].appendChild(newSS);
1803 | return newSS.styleSheet;
1804 | }
1805 | }
1806 | };
1807 | $(function () {
1808 | var u = navigator.userAgent.toLowerCase();
1809 | var v = (u.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [0,'0'])[1];
1810 |
1811 | var css = '/* TREE LAYOUT */ .tree ul { margin:0 0 0 5px; padding:0 0 0 0; list-style-type:none; } .tree li { display:block; min-height:18px; line-height:18px; padding:0 0 0 15px; margin:0 0 0 0; /* Background fix */ clear:both; } .tree li ul { display:none; } .tree li a, .tree li span { display:inline-block;line-height:16px;height:16px;color:black;white-space:nowrap;text-decoration:none;padding:1px 4px 1px 4px;margin:0; } .tree li a:focus { outline: none; } .tree li a input, .tree li span input { margin:0;padding:0 0;display:inline-block;height:12px !important;border:1px solid white;background:white;font-size:10px;font-family:Verdana; } .tree li a input:not([class="xxx"]), .tree li span input:not([class="xxx"]) { padding:1px 0; } /* FOR DOTS */ .tree .ltr li.last { float:left; } .tree > ul li.last { overflow:visible; } /* OPEN OR CLOSE */ .tree li.open ul { display:block; } .tree li.closed ul { display:none !important; } /* FOR DRAGGING */ #jstree-dragged { position:absolute; top:-10px; left:-10px; margin:0; padding:0; } #jstree-dragged ul ul ul { display:none; } #jstree-marker { padding:0; margin:0; line-height:5px; font-size:1px; overflow:hidden; height:5px; position:absolute; left:-45px; top:-30px; z-index:1000; background-color:transparent; background-repeat:no-repeat; display:none; } #jstree-marker.marker { width:45px; background-position:-32px top; } #jstree-marker.marker_plus { width:5px; background-position:right top; } /* BACKGROUND DOTS */ .tree li li { overflow:hidden; } .tree > .ltr > li { display:table; } /* ICONS */ .tree ul ins { display:inline-block; text-decoration:none; width:16px; height:16px; } .tree .ltr ins { margin:0 4px 0 0px; } ';
1812 | if($.browser.msie) {
1813 | if($.browser.version == 6) css += '.tree li { height:18px; zoom:1; } .tree li li { overflow:visible; } .tree .ltr li.last { margin-top: expression( (this.previousSibling && /open/.test(this.previousSibling.className) ) ? "-2px" : "0"); } .marker { width:45px; background-position:-32px top; } .marker_plus { width:5px; background-position:right top; }';
1814 | if($.browser.version == 7) css += '.tree li li { overflow:visible; } .tree .ltr li.last { margin-top: expression( (this.previousSibling && /open/.test(this.previousSibling.className) ) ? "-2px" : "0"); }';
1815 | }
1816 | if($.browser.opera) css += '.tree > ul > li.last:after { content:"."; display: block; height:1px; clear:both; visibility:hidden; }';
1817 | if($.browser.mozilla && $.browser.version.indexOf("1.8") == 0) css += '.tree .ltr li a { display:inline; float:left; } .tree li ul { clear:both; }';
1818 | tree_component.css = tree_component.add_sheet({ str : css });
1819 | });
1820 | })(jQuery);
1821 |
1822 | // Datastores
1823 | // HTML and JSON are included here by default
1824 | (function ($) {
1825 | $.extend($.tree.datastores, {
1826 | "html" : function () {
1827 | return {
1828 | get : function(obj, tree, opts) {
1829 | return obj && $(obj).size() ? $('').append(tree.get_node(obj).clone()).html() : tree.container.children("ul:eq(0)").html();
1830 | },
1831 | parse : function(data, tree, opts, callback) {
1832 | if(callback) callback.call(null, data);
1833 | return data;
1834 | },
1835 | load : function(data, tree, opts, callback) {
1836 | if(opts.url) {
1837 | $.ajax({
1838 | 'type' : opts.method,
1839 | 'url' : opts.url,
1840 | 'data' : data,
1841 | 'dataType' : "html",
1842 | 'success' : function (d, textStatus) {
1843 | callback.call(null, d);
1844 | },
1845 | 'error' : function (xhttp, textStatus, errorThrown) {
1846 | callback.call(null, false);
1847 | tree.error(errorThrown + " " + textStatus);
1848 | }
1849 | });
1850 | }
1851 | else {
1852 | callback.call(null, opts.static || tree.container.children("ul:eq(0)").html());
1853 | }
1854 | }
1855 | };
1856 | },
1857 | "json" : function () {
1858 | return {
1859 | get : function(obj, tree, opts) {
1860 | var _this = this;
1861 | if(!obj || $(obj).size() == 0) obj = tree.container.children("ul").children("li");
1862 | else obj = $(obj);
1863 |
1864 | if(!opts) opts = {};
1865 | if(!opts.outer_attrib) opts.outer_attrib = [ "id", "rel", "class" ];
1866 | if(!opts.inner_attrib) opts.inner_attrib = [ ];
1867 |
1868 | if(obj.size() > 1) {
1869 | var arr = [];
1870 | obj.each(function () {
1871 | arr.push(_this.get(this, tree, opts));
1872 | });
1873 | return arr;
1874 | }
1875 | if(obj.size() == 0) return [];
1876 |
1877 | var json = { attributes : {}, data : {} };
1878 | if(obj.hasClass("open")) json.data.state = "open";
1879 | if(obj.hasClass("closed")) json.data.state = "closed";
1880 |
1881 | for(var i in opts.outer_attrib) {
1882 | if(!opts.outer_attrib.hasOwnProperty(i)) continue;
1883 | var val = (opts.outer_attrib[i] == "class") ? obj.attr(opts.outer_attrib[i]).replace(/(^| )last( |$)/ig," ").replace(/(^| )(leaf|closed|open)( |$)/ig," ") : obj.attr(opts.outer_attrib[i]);
1884 | if(typeof val != "undefined" && val.toString().replace(" ","").length > 0) json.attributes[opts.outer_attrib[i]] = val;
1885 | delete val;
1886 | }
1887 |
1888 | if(tree.settings.languages.length) {
1889 | for(var i in tree.settings.languages) {
1890 | if(!tree.settings.languages.hasOwnProperty(i)) continue;
1891 | var a = obj.children("a." + tree.settings.languages[i]);
1892 | if(opts.force || opts.inner_attrib.length || a.children("ins").get(0).style.backgroundImage.toString().length || a.children("ins").get(0).className.length) {
1893 | json.data[tree.settings.languages[i]] = {};
1894 | json.data[tree.settings.languages[i]].title = tree.get_text(obj,tree.settings.languages[i]);
1895 | if(a.children("ins").get(0).style.className.length) {
1896 | json.data[tree.settings.languages[i]].icon = a.children("ins").get(0).style.className;
1897 | }
1898 | if(a.children("ins").get(0).style.backgroundImage.length) {
1899 | json.data[tree.settings.languages[i]].icon = a.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","");
1900 | }
1901 | if(opts.inner_attrib.length) {
1902 | json.data[tree.settings.languages[i]].attributes = {};
1903 | for(var j in opts.inner_attrib) {
1904 | if(!opts.inner_attrib.hasOwnProperty(j)) continue;
1905 | var val = a.attr(opts.inner_attrib[j]);
1906 | if(typeof val != "undefined" && val.toString().replace(" ","").length > 0) json.data[tree.settings.languages[i]].attributes[opts.inner_attrib[j]] = val;
1907 | delete val;
1908 | }
1909 | }
1910 | }
1911 | else {
1912 | json.data[tree.settings.languages[i]] = tree.get_text(obj,tree.settings.languages[i]);
1913 | }
1914 | }
1915 | }
1916 | else {
1917 | var a = obj.children("a");
1918 | json.data.title = tree.get_text(obj);
1919 |
1920 | if(a.children("ins").size() && a.children("ins").get(0).className.length) {
1921 | json.data.icon = a.children("ins").get(0).className;
1922 | }
1923 | if(a.children("ins").size() && a.children("ins").get(0).style.backgroundImage.length) {
1924 | json.data.icon = a.children("ins").get(0).style.backgroundImage.replace("url(","").replace(")","");
1925 | }
1926 |
1927 | if(opts.inner_attrib.length) {
1928 | json.data.attributes = {};
1929 | for(var j in opts.inner_attrib) {
1930 | if(!opts.inner_attrib.hasOwnProperty(j)) continue;
1931 | var val = a.attr(opts.inner_attrib[j]);
1932 | if(typeof val != "undefined" && val.toString().replace(" ","").length > 0) json.data.attributes[opts.inner_attrib[j]] = val;
1933 | delete val;
1934 | }
1935 | }
1936 | }
1937 |
1938 | if(obj.children("ul").size() > 0) {
1939 | json.children = [];
1940 | obj.children("ul").children("li").each(function () {
1941 | json.children.push(_this.get(this, tree, opts));
1942 | });
1943 | }
1944 | return json;
1945 | },
1946 | parse : function(data, tree, opts, callback) {
1947 | if(Object.prototype.toString.apply(data) === "[object Array]") {
1948 | var str = '';
1949 | for(var i = 0; i < data.length; i ++) {
1950 | if(typeof data[i] == "function") continue;
1951 | str += this.parse(data[i], tree, opts);
1952 | }
1953 | if(callback) callback.call(null, str);
1954 | return str;
1955 | }
1956 |
1957 | if(!data || !data.data) {
1958 | if(callback) callback.call(null, false);
1959 | return "";
1960 | }
1961 |
1962 | var str = '';
1963 | str += "
";
1979 |
1980 | if(tree.settings.languages.length) {
1981 | for(var i = 0; i < tree.settings.languages.length; i++) {
1982 | var attr = {};
1983 | attr["href"] = "";
1984 | attr["style"] = "";
1985 | attr["class"] = tree.settings.languages[i];
1986 | if(data.data[tree.settings.languages[i]] && (typeof data.data[tree.settings.languages[i]].attributes).toLowerCase() != "undefined") {
1987 | for(var j in data.data[tree.settings.languages[i]].attributes) {
1988 | if(!data.data[tree.settings.languages[i]].attributes.hasOwnProperty(j)) continue;
1989 | if(j == "style" || j == "class") attr[j] += " " + data.data[tree.settings.languages[i]].attributes[j];
1990 | else attr[j] = data.data[tree.settings.languages[i]].attributes[j];
1991 | }
1992 | }
1993 | str += "";
1999 | if(data.data[tree.settings.languages[i]] && data.data[tree.settings.languages[i]].icon) {
2000 | str += " ";
2001 | }
2002 | else str += " ";
2003 | str += ( (typeof data.data[tree.settings.languages[i]].title).toLowerCase() != "undefined" ? data.data[tree.settings.languages[i]].title : data.data[tree.settings.languages[i]] ) + " ";
2004 | }
2005 | }
2006 | else {
2007 | var attr = {};
2008 | attr["href"] = "";
2009 | attr["style"] = "";
2010 | attr["class"] = "";
2011 | if((typeof data.data.attributes).toLowerCase() != "undefined") {
2012 | for(var i in data.data.attributes) {
2013 | if(!data.data.attributes.hasOwnProperty(i)) continue;
2014 | if(i == "style" || i == "class") attr[i] += " " + data.data.attributes[i];
2015 | else attr[i] = data.data.attributes[i];
2016 | }
2017 | }
2018 | str += "";
2024 | if(data.data.icon) {
2025 | str += " ";
2026 | }
2027 | else str += " ";
2028 | str += ( (typeof data.data.title).toLowerCase() != "undefined" ? data.data.title : data.data ) + " ";
2029 | }
2030 | if(data.children && data.children.length) {
2031 | str += '';
2032 | for(var i = 0; i < data.children.length; i++) {
2033 | str += this.parse(data.children[i], tree, opts);
2034 | }
2035 | str += ' ';
2036 | }
2037 | str += " ";
2038 | if(callback) callback.call(null, str);
2039 | return str;
2040 | },
2041 | load : function(data, tree, opts, callback) {
2042 | if(opts.static) {
2043 | callback.call(null, opts.static);
2044 | }
2045 | else {
2046 | $.ajax({
2047 | 'type' : opts.method,
2048 | 'url' : opts.url,
2049 | 'data' : data,
2050 | 'dataType' : "json",
2051 | 'success' : function (d, textStatus) {
2052 | callback.call(null, d);
2053 | },
2054 | 'error' : function (xhttp, textStatus, errorThrown) {
2055 | callback.call(null, false);
2056 | tree.error(errorThrown + " " + textStatus);
2057 | }
2058 | });
2059 | }
2060 | }
2061 | }
2062 | }
2063 | });
2064 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/lib/jquery.cookie.js:
--------------------------------------------------------------------------------
1 | /**
2 | * Cookie plugin
3 | *
4 | * Copyright (c) 2006 Klaus Hartl (stilbuero.de)
5 | * Dual licensed under the MIT and GPL licenses:
6 | * http://www.opensource.org/licenses/mit-license.php
7 | * http://www.gnu.org/licenses/gpl.html
8 | *
9 | */
10 |
11 | /**
12 | * Create a cookie with the given name and value and other optional parameters.
13 | *
14 | * @example $.cookie('the_cookie', 'the_value');
15 | * @desc Set the value of a cookie.
16 | * @example $.cookie('the_cookie', 'the_value', { expires: 7, path: '/', domain: 'jquery.com', secure: true });
17 | * @desc Create a cookie with all available options.
18 | * @example $.cookie('the_cookie', 'the_value');
19 | * @desc Create a session cookie.
20 | * @example $.cookie('the_cookie', null);
21 | * @desc Delete a cookie by passing null as value. Keep in mind that you have to use the same path and domain
22 | * used when the cookie was set.
23 | *
24 | * @param String name The name of the cookie.
25 | * @param String value The value of the cookie.
26 | * @param Object options An object literal containing key/value pairs to provide optional cookie attributes.
27 | * @option Number|Date expires Either an integer specifying the expiration date from now on in days or a Date object.
28 | * If a negative value is specified (e.g. a date in the past), the cookie will be deleted.
29 | * If set to null or omitted, the cookie will be a session cookie and will not be retained
30 | * when the the browser exits.
31 | * @option String path The value of the path atribute of the cookie (default: path of page that created the cookie).
32 | * @option String domain The value of the domain attribute of the cookie (default: domain of page that created the cookie).
33 | * @option Boolean secure If true, the secure attribute of the cookie will be set and the cookie transmission will
34 | * require a secure protocol (like HTTPS).
35 | * @type undefined
36 | *
37 | * @name $.cookie
38 | * @cat Plugins/Cookie
39 | * @author Klaus Hartl/klaus.hartl@stilbuero.de
40 | */
41 |
42 | /**
43 | * Get the value of a cookie with the given name.
44 | *
45 | * @example $.cookie('the_cookie');
46 | * @desc Get the value of a cookie.
47 | *
48 | * @param String name The name of the cookie.
49 | * @return The value of the cookie.
50 | * @type String
51 | *
52 | * @name $.cookie
53 | * @cat Plugins/Cookie
54 | * @author Klaus Hartl/klaus.hartl@stilbuero.de
55 | */
56 | jQuery.cookie = function(name, value, options) {
57 | if (typeof value != 'undefined') { // name and value given, set cookie
58 | options = options || {};
59 | if (value === null) {
60 | value = '';
61 | options.expires = -1;
62 | }
63 | var expires = '';
64 | if (options.expires && (typeof options.expires == 'number' || options.expires.toUTCString)) {
65 | var date;
66 | if (typeof options.expires == 'number') {
67 | date = new Date();
68 | date.setTime(date.getTime() + (options.expires * 24 * 60 * 60 * 1000));
69 | } else {
70 | date = options.expires;
71 | }
72 | expires = '; expires=' + date.toUTCString(); // use expires attribute, max-age is not supported by IE
73 | }
74 | // CAUTION: Needed to parenthesize options.path and options.domain
75 | // in the following expressions, otherwise they evaluate to undefined
76 | // in the packed version for some reason...
77 | var path = options.path ? '; path=' + (options.path) : '';
78 | var domain = options.domain ? '; domain=' + (options.domain) : '';
79 | var secure = options.secure ? '; secure' : '';
80 | document.cookie = [name, '=', encodeURIComponent(value), expires, path, domain, secure].join('');
81 | } else { // only name given, get cookie
82 | var cookieValue = null;
83 | if (document.cookie && document.cookie != '') {
84 | var cookies = document.cookie.split(';');
85 | for (var i = 0; i < cookies.length; i++) {
86 | var cookie = jQuery.trim(cookies[i]);
87 | // Does this cookie string begin with the name we want?
88 | if (cookie.substring(0, name.length + 1) == (name + '=')) {
89 | cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
90 | break;
91 | }
92 | }
93 | }
94 | return cookieValue;
95 | }
96 | };
--------------------------------------------------------------------------------
/public/node-zk/lib/jquery.hotkeys.js:
--------------------------------------------------------------------------------
1 | /*
2 | (c) Copyrights 2007 - 2008
3 |
4 | Original idea by by Binny V A, http://www.openjs.com/scripts/events/keyboard_shortcuts/
5 |
6 | jQuery Plugin by Tzury Bar Yochay
7 | tzury.by@gmail.com
8 | http://evalinux.wordpress.com
9 | http://facebook.com/profile.php?id=513676303
10 |
11 | Project's sites:
12 | http://code.google.com/p/js-hotkeys/
13 | http://github.com/tzuryby/hotkeys/tree/master
14 |
15 | License: same as jQuery license.
16 |
17 | USAGE:
18 | // simple usage
19 | $(document).bind('keydown', 'Ctrl+c', function(){ alert('copy anyone?');});
20 |
21 | // special options such as disableInIput
22 | $(document).bind('keydown', {combi:'Ctrl+x', disableInInput: true} , function() {});
23 |
24 | Note:
25 | This plugin wraps the following jQuery methods: $.fn.find, $.fn.bind and $.fn.unbind
26 |
27 | */
28 |
29 |
30 | (function (jQuery){
31 | // keep reference to the original $.fn.bind and $.fn.unbind
32 | jQuery.fn.__bind__ = jQuery.fn.bind;
33 | jQuery.fn.__unbind__ = jQuery.fn.unbind;
34 | jQuery.fn.__find__ = jQuery.fn.find;
35 |
36 | var hotkeys = {
37 | version: '0.7.8',
38 | override: /keydown|keypress|keyup/g,
39 | triggersMap: {},
40 |
41 | specialKeys: { 27: 'esc', 9: 'tab', 32:'space', 13: 'return', 8:'backspace', 145: 'scroll',
42 | 20: 'capslock', 144: 'numlock', 19:'pause', 45:'insert', 36:'home', 46:'del',
43 | 35:'end', 33: 'pageup', 34:'pagedown', 37:'left', 38:'up', 39:'right',40:'down',
44 | 112:'f1',113:'f2', 114:'f3', 115:'f4', 116:'f5', 117:'f6', 118:'f7', 119:'f8',
45 | 120:'f9', 121:'f10', 122:'f11', 123:'f12' },
46 |
47 | shiftNums: { "`":"~", "1":"!", "2":"@", "3":"#", "4":"$", "5":"%", "6":"^", "7":"&",
48 | "8":"*", "9":"(", "0":")", "-":"_", "=":"+", ";":":", "'":"\"", ",":"<",
49 | ".":">", "/":"?", "\\":"|" },
50 |
51 | newTrigger: function (type, combi, callback) {
52 | // i.e. {'keyup': {'ctrl': {cb: callback, disableInInput: false}}}
53 | var result = {};
54 | result[type] = {};
55 | result[type][combi] = {cb: callback, disableInInput: false};
56 | return result;
57 | }
58 | };
59 | // add firefox num pad char codes
60 | if (jQuery.browser.mozilla){
61 | hotkeys.specialKeys = jQuery.extend(hotkeys.specialKeys, { 96: '0', 97:'1', 98: '2', 99:
62 | '3', 100: '4', 101: '5', 102: '6', 103: '7', 104: '8', 105: '9' });
63 | }
64 |
65 | // a wrapper around of $.fn.find
66 | // see more at: http://groups.google.com/group/jquery-en/browse_thread/thread/18f9825e8d22f18d
67 | jQuery.fn.find = function( selector ) {
68 | this.query=selector;
69 | return jQuery.fn.__find__.apply(this, arguments);
70 | };
71 |
72 | jQuery.fn.unbind = function (type, combi, fn){
73 | if (jQuery.isFunction(combi)){
74 | fn = combi;
75 | combi = null;
76 | }
77 | if (combi && typeof combi === 'string'){
78 | var selectorId = ((this.prevObject && this.prevObject.query) || (this[0].id && this[0].id) || this[0]).toString();
79 | var hkTypes = type.split(' ');
80 | for (var x=0; x
This is a p
35 | * @before $.metadata.setType("class")
36 | * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
37 | * @desc Reads metadata from the class attribute
38 | *
39 | * @example This is a p
40 | * @before $.metadata.setType("attr", "data")
41 | * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
42 | * @desc Reads metadata from a "data" attribute
43 | *
44 | * @example This is a p
45 | * @before $.metadata.setType("elem", "script")
46 | * @after $("#one").metadata().item_id == 1; $("#one").metadata().item_label == "Label"
47 | * @desc Reads metadata from a nested script element
48 | *
49 | * @param String type The encoding type
50 | * @param String name The name of the attribute to be used to get metadata (optional)
51 | * @cat Plugins/Metadata
52 | * @descr Sets the type of encoding to be used when loading metadata for the first time
53 | * @type undefined
54 | * @see metadata()
55 | */
56 |
57 | (function($) {
58 |
59 | $.extend({
60 | metadata : {
61 | defaults : {
62 | type: 'class',
63 | name: 'metadata',
64 | cre: /({.*})/,
65 | single: 'metadata'
66 | },
67 | setType: function( type, name ){
68 | this.defaults.type = type;
69 | this.defaults.name = name;
70 | },
71 | get: function( elem, opts ){
72 | var settings = $.extend({},this.defaults,opts);
73 | // check for empty string in single property
74 | if ( !settings.single.length ) settings.single = 'metadata';
75 |
76 | var data = $.data(elem, settings.single);
77 | // returned cached data if it already exists
78 | if ( data ) return data;
79 |
80 | data = "{}";
81 |
82 | if ( settings.type == "class" ) {
83 | var m = settings.cre.exec( elem.className );
84 | if ( m )
85 | data = m[1];
86 | } else if ( settings.type == "elem" ) {
87 | if( !elem.getElementsByTagName )
88 | return undefined;
89 | var e = elem.getElementsByTagName(settings.name);
90 | if ( e.length )
91 | data = $.trim(e[0].innerHTML);
92 | } else if ( elem.getAttribute != undefined ) {
93 | var attr = elem.getAttribute( settings.name );
94 | if ( attr )
95 | data = attr;
96 | }
97 |
98 | if ( data.indexOf( '{' ) <0 )
99 | data = "{" + data + "}";
100 |
101 | data = eval("(" + data + ")");
102 |
103 | $.data( elem, settings.single, data );
104 | return data;
105 | }
106 | }
107 | });
108 |
109 | /**
110 | * Returns the metadata object for the first member of the jQuery object.
111 | *
112 | * @name metadata
113 | * @descr Returns element's metadata object
114 | * @param Object opts An object contianing settings to override the defaults
115 | * @type jQuery
116 | * @cat Plugins/Metadata
117 | */
118 | $.fn.metadata = function( opts ){
119 | return $.metadata.get( this[0], opts );
120 | };
121 |
122 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/lib/sarissa.js:
--------------------------------------------------------------------------------
1 |
2 | /* * ====================================================================
3 | * About: This a a compressed JS file from the Sarissa library.
4 | * see http://dev.abiss.gr/sarissa
5 | *
6 | * Copyright: Manos Batsis, http://dev.abiss.gr
7 | *
8 | * Licence:
9 | * Sarissa is free software distributed under the GNU GPL version 2
10 | * or higher, GNU LGPL version 2.1 or higher and Apache Software
11 | * License 2.0 or higher. The licenses are available online see:
12 | * http://www.gnu.org
13 | * http://www.apache.org
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY
16 | * KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
17 | * WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE
18 | * AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
19 | * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 | * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 | * ====================================================================*/
24 |
25 | function Sarissa(){}
26 | Sarissa.VERSION="0.9.9.4";Sarissa.PARSED_OK="Document contains no parsing errors";Sarissa.PARSED_EMPTY="Document is empty";Sarissa.PARSED_UNKNOWN_ERROR="Not well-formed or other error";Sarissa.IS_ENABLED_TRANSFORM_NODE=false;Sarissa.REMOTE_CALL_FLAG="gr.abiss.sarissa.REMOTE_CALL_FLAG";Sarissa._lastUniqueSuffix=0;Sarissa._getUniqueSuffix=function(){return Sarissa._lastUniqueSuffix++;};Sarissa._SARISSA_IEPREFIX4XSLPARAM="";Sarissa._SARISSA_HAS_DOM_IMPLEMENTATION=document.implementation&&true;Sarissa._SARISSA_HAS_DOM_CREATE_DOCUMENT=Sarissa._SARISSA_HAS_DOM_IMPLEMENTATION&&document.implementation.createDocument;Sarissa._SARISSA_HAS_DOM_FEATURE=Sarissa._SARISSA_HAS_DOM_IMPLEMENTATION&&document.implementation.hasFeature;Sarissa._SARISSA_IS_MOZ=Sarissa._SARISSA_HAS_DOM_CREATE_DOCUMENT&&Sarissa._SARISSA_HAS_DOM_FEATURE;Sarissa._SARISSA_IS_SAFARI=navigator.userAgent.toLowerCase().indexOf("safari")!=-1||navigator.userAgent.toLowerCase().indexOf("konqueror")!=-1;Sarissa._SARISSA_IS_SAFARI_OLD=Sarissa._SARISSA_IS_SAFARI&&(parseInt((navigator.userAgent.match(/AppleWebKit\/(\d+)/)||{})[1],10)<420);Sarissa._SARISSA_IS_IE=document.all&&window.ActiveXObject&&navigator.userAgent.toLowerCase().indexOf("msie")>-1&&navigator.userAgent.toLowerCase().indexOf("opera")==-1;Sarissa._SARISSA_IS_OPERA=navigator.userAgent.toLowerCase().indexOf("opera")!=-1;if(!window.Node||!Node.ELEMENT_NODE){Node={ELEMENT_NODE:1,ATTRIBUTE_NODE:2,TEXT_NODE:3,CDATA_SECTION_NODE:4,ENTITY_REFERENCE_NODE:5,ENTITY_NODE:6,PROCESSING_INSTRUCTION_NODE:7,COMMENT_NODE:8,DOCUMENT_NODE:9,DOCUMENT_TYPE_NODE:10,DOCUMENT_FRAGMENT_NODE:11,NOTATION_NODE:12};}
27 | if(Sarissa._SARISSA_IS_SAFARI_OLD){HTMLHtmlElement=document.createElement("html").constructor;Node=HTMLElement={};HTMLElement.prototype=HTMLHtmlElement.__proto__.__proto__;HTMLDocument=Document=document.constructor;var x=new DOMParser();XMLDocument=x.constructor;Element=x.parseFromString(" ","text/xml").documentElement.constructor;x=null;}
28 | if(typeof XMLDocument=="undefined"&&typeof Document!="undefined"){XMLDocument=Document;}
29 | if(Sarissa._SARISSA_IS_IE){Sarissa._SARISSA_IEPREFIX4XSLPARAM="xsl:";var _SARISSA_DOM_PROGID="";var _SARISSA_XMLHTTP_PROGID="";var _SARISSA_DOM_XMLWRITER="";Sarissa.pickRecentProgID=function(idList){var bFound=false,e;var o2Store;for(var i=0;i1){prefix=sName.substring(0,sName.indexOf(":"));sName=sName.substring(sName.indexOf(":")+1);}else{prefix="a"+Sarissa._getUniqueSuffix();}}
34 | if(sUri){oDoc.loadXML('<'+prefix+':'+sName+" xmlns:"+prefix+"=\""+sUri+"\""+" />");}else{oDoc.loadXML('<'+sName+" />");}}
35 | return oDoc;};Sarissa.getParseErrorText=function(oDoc){var parseErrorText=Sarissa.PARSED_OK;if(oDoc&&oDoc.parseError&&oDoc.parseError.errorCode&&oDoc.parseError.errorCode!=0){parseErrorText="XML Parsing Error: "+oDoc.parseError.reason+"\nLocation: "+oDoc.parseError.url+"\nLine Number "+oDoc.parseError.line+", Column "+
36 | oDoc.parseError.linepos+":\n"+oDoc.parseError.srcText+"\n";for(var i=0;i')+2);}
51 | var xml=''.concat('',s,' ');oDoc.loadXML(xml);container=oDoc.documentElement;while(container.hasChildNodes()){f.appendChild(container.firstChild);}}
52 | return f;};XSLTProcessor.prototype.setParameter=function(nsURI,name,value){value=value?value:"";if(nsURI){this.processor.addParameter(name,value,nsURI);}else{this.processor.addParameter(name,value);}
53 | nsURI=""+(nsURI||"");if(!this.paramsSet[nsURI]){this.paramsSet[nsURI]=[];}
54 | this.paramsSet[nsURI][name]=value;};XSLTProcessor.prototype.getParameter=function(nsURI,name){nsURI=""+(nsURI||"");if(this.paramsSet[nsURI]&&this.paramsSet[nsURI][name]){return this.paramsSet[nsURI][name];}else{return null;}};XSLTProcessor.prototype.clearParameters=function(){for(var nsURI in this.paramsSet){for(var name in this.paramsSet[nsURI]){if(nsURI!=""){this.processor.addParameter(name,"",nsURI);}else{this.processor.addParameter(name,"");}}}
55 | this.paramsSet=[];};}else{if(Sarissa._SARISSA_HAS_DOM_CREATE_DOCUMENT){Sarissa.__handleLoad__=function(oDoc){Sarissa.__setReadyState__(oDoc,4);};_sarissa_XMLDocument_onload=function(){Sarissa.__handleLoad__(this);};Sarissa.__setReadyState__=function(oDoc,iReadyState){oDoc.readyState=iReadyState;oDoc.readystate=iReadyState;if(oDoc.onreadystatechange!=null&&typeof oDoc.onreadystatechange=="function"){oDoc.onreadystatechange();}};Sarissa.getDomDocument=function(sUri,sName){var oDoc=document.implementation.createDocument(sUri?sUri:null,sName?sName:null,null);if(!oDoc.onreadystatechange){oDoc.onreadystatechange=null;}
56 | if(!oDoc.readyState){oDoc.readyState=0;}
57 | oDoc.addEventListener("load",_sarissa_XMLDocument_onload,false);return oDoc;};if(window.XMLDocument){}
58 | else if(Sarissa._SARISSA_HAS_DOM_FEATURE&&window.Document&&!Document.prototype.load&&document.implementation.hasFeature('LS','3.0')){Sarissa.getDomDocument=function(sUri,sName){var oDoc=document.implementation.createDocument(sUri?sUri:null,sName?sName:null,null);return oDoc;};}
59 | else{Sarissa.getDomDocument=function(sUri,sName){var oDoc=document.implementation.createDocument(sUri?sUri:null,sName?sName:null,null);if(oDoc&&(sUri||sName)&&!oDoc.documentElement){oDoc.appendChild(oDoc.createElementNS(sUri,sName));}
60 | return oDoc;};}}}
61 | if(!window.DOMParser){if(Sarissa._SARISSA_IS_SAFARI){DOMParser=function(){};DOMParser.prototype.parseFromString=function(sXml,contentType){var xmlhttp=new XMLHttpRequest();xmlhttp.open("GET","data:text/xml;charset=utf-8,"+encodeURIComponent(sXml),false);xmlhttp.send(null);return xmlhttp.responseXML;};}else if(Sarissa.getDomDocument&&Sarissa.getDomDocument()&&Sarissa.getDomDocument(null,"bar").xml){DOMParser=function(){};DOMParser.prototype.parseFromString=function(sXml,contentType){var doc=Sarissa.getDomDocument();doc.loadXML(sXml);return doc;};}}
62 | if((typeof(document.importNode)=="undefined")&&Sarissa._SARISSA_IS_IE){try{document.importNode=function(oNode,bChildren){var tmp;if(oNode.nodeName=='#text'){return document.createTextNode(oNode.data);}
63 | else{if(oNode.nodeName=="tbody"||oNode.nodeName=="tr"){tmp=document.createElement("table");}
64 | else if(oNode.nodeName=="td"){tmp=document.createElement("tr");}
65 | else if(oNode.nodeName=="option"){tmp=document.createElement("select");}
66 | else{tmp=document.createElement("div");}
67 | if(bChildren){tmp.innerHTML=oNode.xml?oNode.xml:oNode.outerHTML;}else{tmp.innerHTML=oNode.xml?oNode.cloneNode(false).xml:oNode.cloneNode(false).outerHTML;}
68 | return tmp.getElementsByTagName("*")[0];}};}catch(e){}}
69 | if(!Sarissa.getParseErrorText){Sarissa.getParseErrorText=function(oDoc){var parseErrorText=Sarissa.PARSED_OK;if((!oDoc)||(!oDoc.documentElement)){parseErrorText=Sarissa.PARSED_EMPTY;}else if(oDoc.documentElement.tagName=="parsererror"){parseErrorText=oDoc.documentElement.firstChild.data;parseErrorText+="\n"+oDoc.documentElement.firstChild.nextSibling.firstChild.data;}else if(oDoc.getElementsByTagName("parsererror").length>0){var parsererror=oDoc.getElementsByTagName("parsererror")[0];parseErrorText=Sarissa.getText(parsererror,true)+"\n";}else if(oDoc.parseError&&oDoc.parseError.errorCode!=0){parseErrorText=Sarissa.PARSED_UNKNOWN_ERROR;}
70 | return parseErrorText;};}
71 | Sarissa.getText=function(oNode,deep){var s="";var nodes=oNode.childNodes;for(var i=0;i]+>/g,""):s;};Sarissa.clearChildNodes=function(oNode){while(oNode.firstChild){oNode.removeChild(oNode.firstChild);}};Sarissa.copyChildNodes=function(nodeFrom,nodeTo,bPreserveExisting){if(Sarissa._SARISSA_IS_SAFARI&&nodeTo.nodeType==Node.DOCUMENT_NODE){nodeTo=nodeTo.documentElement;}
74 | if((!nodeFrom)||(!nodeTo)){throw"Both source and destination nodes must be provided";}
75 | if(!bPreserveExisting){Sarissa.clearChildNodes(nodeTo);}
76 | var ownerDoc=nodeTo.nodeType==Node.DOCUMENT_NODE?nodeTo:nodeTo.ownerDocument;var nodes=nodeFrom.childNodes;var i;if(typeof(ownerDoc.importNode)!="undefined"){for(i=0;i';var isLeaf=false;if(!(anyObject instanceof Object)||anyObject instanceof Number||anyObject instanceof String||anyObject instanceof Boolean||anyObject instanceof Date){s+=Sarissa.escape(""+anyObject);isLeaf=true;}else{s+="\n";var isArrayItem=anyObject instanceof Array;for(var name in anyObject){s+=Sarissa.xmlize(anyObject[name],(isArrayItem?"array-item key=\""+name+"\"":name),indentSpace+" ");}
80 | s+=indentSpace;}
81 | return(s+=(objectName.indexOf(' ')!=-1?"\n":""+objectName+">\n"));};Sarissa.escape=function(sXml){return sXml.replace(/&/g,"&").replace(//g,">").replace(/"/g,""").replace(/'/g,"'");};Sarissa.unescape=function(sXml){return sXml.replace(/'/g,"'").replace(/"/g,"\"").replace(/>/g,">").replace(/</g,"<").replace(/&/g,"&");};Sarissa.updateCursor=function(oTargetElement,sValue){if(oTargetElement&&oTargetElement.style&&oTargetElement.style.cursor!=undefined){oTargetElement.style.cursor=sValue;}};Sarissa.updateContentFromURI=function(sFromUrl,oTargetElement,xsltproc,callback,skipCache){try{Sarissa.updateCursor(oTargetElement,"wait");var xmlhttp=new XMLHttpRequest();xmlhttp.open("GET",sFromUrl,true);xmlhttp.onreadystatechange=function(){if(xmlhttp.readyState==4){try{var oDomDoc=xmlhttp.responseXML;if(oDomDoc&&Sarissa.getParseErrorText(oDomDoc)==Sarissa.PARSED_OK){Sarissa.updateContentFromNode(xmlhttp.responseXML,oTargetElement,xsltproc);if(callback){callback(sFromUrl,oTargetElement);}}
82 | else{throw Sarissa.getParseErrorText(oDomDoc);}}
83 | catch(e){if(callback){callback(sFromUrl,oTargetElement,e);}
84 | else{throw e;}}}};if(skipCache){var oldage="Sat, 1 Jan 2000 00:00:00 GMT";xmlhttp.setRequestHeader("If-Modified-Since",oldage);}
85 | xmlhttp.send("");}
86 | catch(e){Sarissa.updateCursor(oTargetElement,"auto");if(callback){callback(sFromUrl,oTargetElement,e);}
87 | else{throw e;}}};Sarissa.updateContentFromNode=function(oNode,oTargetElement,xsltproc){try{Sarissa.updateCursor(oTargetElement,"wait");Sarissa.clearChildNodes(oTargetElement);var ownerDoc=oNode.nodeType==Node.DOCUMENT_NODE?oNode:oNode.ownerDocument;if(ownerDoc.parseError&&ownerDoc.parseError.errorCode!=0){var pre=document.createElement("pre");pre.appendChild(document.createTextNode(Sarissa.getParseErrorText(ownerDoc)));oTargetElement.appendChild(pre);}
88 | else{if(xsltproc){oNode=xsltproc.transformToDocument(oNode);}
89 | if(oTargetElement.tagName.toLowerCase()=="textarea"||oTargetElement.tagName.toLowerCase()=="input"){oTargetElement.value=new XMLSerializer().serializeToString(oNode);}
90 | else{try{oTargetElement.appendChild(oTargetElement.ownerDocument.importNode(oNode,true));}
91 | catch(e){oTargetElement.innerHTML=new XMLSerializer().serializeToString(oNode);}}}}
92 | catch(e){throw e;}
93 | finally{Sarissa.updateCursor(oTargetElement,"auto");}};Sarissa.formToQueryString=function(oForm){var qs="";for(var i=0;i 0) {
31 | $(this).parents("li").andSelf().children("a").removeClass("unchecked checked").addClass("undetermined");
32 | return false;
33 | }
34 | else $(this).children("a").removeClass("unchecked undetermined").addClass("checked");
35 | });
36 | }
37 | else n.children("a").removeClass("unchecked").addClass("checked");
38 | return true;
39 | },
40 | uncheck : function (n) {
41 | if(!n) return false;
42 | var t = $.tree.reference(n);
43 | n = t.get_node(n);
44 | if(n.children("a").hasClass("unchecked")) return true;
45 |
46 | var opts = $.extend(true, {}, $.tree.plugins.checkbox.defaults, t.settings.plugins.checkbox);
47 | if(opts.three_state) {
48 | n.find("li").andSelf().children("a").removeClass("checked undetermined").addClass("unchecked");
49 | n.parents("li").each(function () {
50 | if($(this).find("a.checked, a.undetermined").size() - 1 > 0) {
51 | $(this).parents("li").andSelf().children("a").removeClass("unchecked checked").addClass("undetermined");
52 | return false;
53 | }
54 | else $(this).children("a").removeClass("checked undetermined").addClass("unchecked");
55 | });
56 | }
57 | else n.children("a").removeClass("checked").addClass("unchecked");
58 | return true;
59 | },
60 | toggle : function (n) {
61 | if(!n) return false;
62 | var t = $.tree.reference(n);
63 | n = t.get_node(n);
64 | if(n.children("a").hasClass("checked")) $.tree.plugins.checkbox.uncheck(n);
65 | else $.tree.plugins.checkbox.check(n);
66 | },
67 |
68 | callbacks : {
69 | onchange : function(n, t) {
70 | $.tree.plugins.checkbox.toggle(n);
71 | }
72 | }
73 | }
74 | });
75 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/plugins/jquery.tree.contextmenu.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | $.extend($.tree.plugins, {
3 | "contextmenu" : {
4 | object : $(""),
5 | data : {
6 | t : false,
7 | a : false,
8 | r : false
9 | },
10 |
11 | defaults : {
12 | class_name : "hover",
13 | items : {
14 | create : {
15 | label : "Create",
16 | icon : "create",
17 | visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return 0; return TREE_OBJ.check("creatable", NODE); },
18 | action : function (NODE, TREE_OBJ) { TREE_OBJ.create(false, TREE_OBJ.get_node(NODE[0])); },
19 | separator_after : true
20 | },
21 | rename : {
22 | label : "Rename",
23 | icon : "rename",
24 | visible : function (NODE, TREE_OBJ) { if(NODE.length != 1) return false; return TREE_OBJ.check("renameable", NODE); },
25 | action : function (NODE, TREE_OBJ) { TREE_OBJ.rename(NODE); }
26 | },
27 | remove : {
28 | label : "Delete",
29 | icon : "remove",
30 | visible : function (NODE, TREE_OBJ) { var ok = true; $.each(NODE, function () { if(TREE_OBJ.check("deletable", this) == false) ok = false; return false; }); return ok; },
31 | action : function (NODE, TREE_OBJ) { $.each(NODE, function () { TREE_OBJ.remove(this); }); }
32 | }
33 | }
34 | },
35 | show : function(obj, t) {
36 | var opts = $.extend(true, {}, $.tree.plugins.contextmenu.defaults, t.settings.plugins.contextmenu);
37 | obj = $(obj);
38 | $.tree.plugins.contextmenu.object.empty();
39 | var str = "";
40 | var cnt = 0;
41 | for(var i in opts.items) {
42 | if(!opts.items.hasOwnProperty(i)) continue;
43 | if(opts.items[i] === false) continue;
44 | var r = 1;
45 | if(typeof opts.items[i].visible == "function") r = opts.items[i].visible.call(null, $.tree.plugins.contextmenu.data.a, t);
46 | if(r == -1) continue;
47 | else cnt ++;
48 | if(opts.items[i].separator_before === true) str += " ";
49 | str += '';
50 | if(opts.items[i].icon) str += " ";
51 | else str += " ";
52 | str += "" + opts.items[i].label + ' ';
53 | if(opts.items[i].separator_after === true) str += " ";
54 | }
55 | var tmp = obj.children("a:visible").offset();
56 | $.tree.plugins.contextmenu.object.attr("class","tree-context tree-" + t.settings.ui.theme_name.toString() + "-context").html(str);
57 | var h = $.tree.plugins.contextmenu.object.height();
58 | var w = $.tree.plugins.contextmenu.object.width();
59 | var x = tmp.left;
60 | var y = tmp.top + parseInt(obj.children("a:visible").height()) + 2;
61 | var max_y = $(window).height() + $(window).scrollTop();
62 | var max_x = $(window).width() + $(window).scrollLeft();
63 | if(y + h > max_y) y = Math.max( (max_y - h - 2), 0);
64 | if(x + w > max_x) x = Math.max( (max_x - w - 2), 0);
65 | $.tree.plugins.contextmenu.object.css({ "left" : (x), "top" : (y) }).fadeIn("fast");
66 | },
67 | hide : function () {
68 | if(!$.tree.plugins.contextmenu.data.t) return;
69 | var opts = $.extend(true, {}, $.tree.plugins.contextmenu.defaults, $.tree.plugins.contextmenu.data.t.settings.plugins.contextmenu);
70 | if($.tree.plugins.contextmenu.data.r && $.tree.plugins.contextmenu.data.a) {
71 | $.tree.plugins.contextmenu.data.a.children("a, span").removeClass(opts.class_name);
72 | }
73 | $.tree.plugins.contextmenu.data = { a : false, r : false, t : false };
74 | $.tree.plugins.contextmenu.object.fadeOut("fast");
75 | },
76 | exec : function (cmd) {
77 | if($.tree.plugins.contextmenu.data.t == false) return;
78 | var opts = $.extend(true, {}, $.tree.plugins.contextmenu.defaults, $.tree.plugins.contextmenu.data.t.settings.plugins.contextmenu);
79 | try { opts.items[cmd].action.apply(null, [$.tree.plugins.contextmenu.data.a, $.tree.plugins.contextmenu.data.t]); } catch(e) { };
80 | },
81 |
82 | callbacks : {
83 | oninit : function () {
84 | if(!$.tree.plugins.contextmenu.css) {
85 | var css = '#jstree-contextmenu { display:none; position:absolute; z-index:2000; list-style-type:none; margin:0; padding:0; left:-2000px; top:-2000px; } .tree-context { margin:20px; padding:0; width:180px; border:1px solid #979797; padding:2px; background:#f5f5f5; list-style-type:none; }.tree-context li { height:22px; margin:0 0 0 27px; padding:0; background:#ffffff; border-left:1px solid #e0e0e0; }.tree-context li a { position:relative; display:block; height:22px; line-height:22px; margin:0 0 0 -28px; text-decoration:none; color:black; padding:0; }.tree-context li a ins { text-decoration:none; float:left; width:16px; height:16px; margin:0 0 0 0; background-color:#f0f0f0; border:1px solid #f0f0f0; border-width:3px 5px 3px 6px; line-height:16px; }.tree-context li a span { display:block; background:#f0f0f0; margin:0 0 0 29px; padding-left:5px; }.tree-context li.separator { background:#f0f0f0; height:2px; line-height:2px; font-size:1px; border:0; margin:0; padding:0; }.tree-context li.separator span { display:block; margin:0px 0 0px 27px; height:1px; border-top:1px solid #e0e0e0; border-left:1px solid #e0e0e0; line-height:1px; font-size:1px; background:white; }.tree-context li a:hover { border:1px solid #d8f0fa; height:20px; line-height:20px; }.tree-context li a:hover span { background:#e7f4f9; margin-left:28px; }.tree-context li a:hover ins { background-color:#e7f4f9; border-color:#e7f4f9; border-width:2px 5px 2px 5px; }.tree-context li a.disabled { color:gray; }.tree-context li a.disabled ins { }.tree-context li a.disabled:hover { border:0; height:22px; line-height:22px; }.tree-context li a.disabled:hover span { background:#f0f0f0; margin-left:29px; }.tree-context li a.disabled:hover ins { border-color:#f0f0f0; background-color:#f0f0f0; border-width:3px 5px 3px 6px; }';
86 | $.tree.plugins.contextmenu.css = this.add_sheet({ str : css });
87 | }
88 | },
89 | onrgtclk : function (n, t, e) {
90 | var opts = $.extend(true, {}, $.tree.plugins.contextmenu.defaults, t.settings.plugins.contextmenu);
91 | n = $(n);
92 | if(n.size() == 0) return;
93 | $.tree.plugins.contextmenu.data.t = t;
94 | if(!n.children("a:eq(0)").hasClass("clicked")) {
95 | $.tree.plugins.contextmenu.data.a = n;
96 | $.tree.plugins.contextmenu.data.r = true;
97 | n.children("a").addClass(opts.class_name);
98 | e.target.blur();
99 | }
100 | else {
101 | $.tree.plugins.contextmenu.data.r = false;
102 | $.tree.plugins.contextmenu.data.a = (t.selected_arr && t.selected_arr.length > 1) ? t.selected_arr : t.selected;
103 | }
104 | $.tree.plugins.contextmenu.show(n, t);
105 | e.preventDefault();
106 | e.stopPropagation();
107 | // return false; // commented out because you might want to do something in your own callback
108 | },
109 | onchange : function () { $.tree.plugins.contextmenu.hide(); },
110 | beforedata : function () { $.tree.plugins.contextmenu.hide(); },
111 | ondestroy : function () { $.tree.plugins.contextmenu.hide(); }
112 | }
113 | }
114 | });
115 | $(function () {
116 | $.tree.plugins.contextmenu.object.hide().appendTo("body");
117 | $("a", $.tree.plugins.contextmenu.object[0])
118 | .live("click", function (event) {
119 | if(!$(this).hasClass("disabled")) {
120 | $.tree.plugins.contextmenu.exec.apply(null, [$(this).attr("rel")]);
121 | $.tree.plugins.contextmenu.hide();
122 | }
123 | event.stopPropagation();
124 | event.preventDefault();
125 | return false;
126 | })
127 | $(document).bind("mousedown", function(event) { if($(event.target).parents("#jstree-contextmenu").size() == 0) $.tree.plugins.contextmenu.hide(); });
128 | });
129 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/plugins/jquery.tree.cookie.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | if(typeof $.cookie == "undefined") throw "jsTree cookie: jQuery cookie plugin not included.";
3 |
4 | $.extend($.tree.plugins, {
5 | "cookie" : {
6 | defaults : {
7 | prefix : "", // a prefix that will be used for all cookies for this tree
8 | options : {
9 | expires: false,
10 | path: false,
11 | domain: false,
12 | secure: false
13 | },
14 | types : {
15 | selected : true, // should we set the selected cookie
16 | open : true // should we set the open cookie
17 | },
18 | keep_selected : false, // should we merge with the selected option or overwrite it
19 | keep_opened : false // should we merge with the opened option or overwrite it
20 | },
21 | set_cookie : function (type) {
22 | var opts = $.extend(true, {}, $.tree.plugins.cookie.defaults, this.settings.plugins.cookie);
23 | if(opts.types[type] !== true) return false;
24 | switch(type) {
25 | case "selected":
26 | if(this.settings.rules.multiple != false && this.selected_arr.length > 1) {
27 | var val = Array();
28 | $.each(this.selected_arr, function () {
29 | if(this.attr("id")) { val.push(this.attr("id")); }
30 | });
31 | val = val.join(",");
32 | }
33 | else var val = this.selected ? this.selected.attr("id") : false;
34 | $.cookie(opts.prefix + 'selected', val, opts.options);
35 | break;
36 | case "open":
37 | var str = "";
38 | this.container.find("li.open").each(function (i) { if(this.id) { str += this.id + ","; } });
39 | $.cookie(opts.prefix + 'open', str.replace(/,$/ig,""), opts.options);
40 | break;
41 | }
42 | },
43 | callbacks : {
44 | oninit : function (t) {
45 | var opts = $.extend(true, {}, $.tree.plugins.cookie.defaults, this.settings.plugins.cookie);
46 | var tmp = false;
47 | tmp = $.cookie(opts.prefix + 'open');
48 | if(tmp) {
49 | tmp = tmp.split(",");
50 | if(opts.keep_opened) this.settings.opened = $.unique($.merge(tmp, this.settings.opened));
51 | else this.settings.opened = tmp;
52 | }
53 | tmp = $.cookie(opts.prefix + 'selected');
54 | if(tmp) {
55 | tmp = tmp.split(",");
56 | if(opts.keep_selected) this.settings.selected = $.unique($.merge(tmp, this.settings.opened));
57 | else this.settings.selected = tmp;
58 | }
59 | },
60 | onchange : function() { $.tree.plugins.cookie.set_cookie.apply(this, ["selected"]); },
61 | onopen : function() { $.tree.plugins.cookie.set_cookie.apply(this, ["open"]); },
62 | onclose : function() { $.tree.plugins.cookie.set_cookie.apply(this, ["open"]); },
63 | ondelete : function() { $.tree.plugins.cookie.set_cookie.apply(this, ["open"]); },
64 | oncopy : function() { $.tree.plugins.cookie.set_cookie.apply(this, ["open"]); },
65 | oncreate : function() { $.tree.plugins.cookie.set_cookie.apply(this, ["open"]); },
66 | onmoved : function() { $.tree.plugins.cookie.set_cookie.apply(this, ["open"]); }
67 | }
68 | }
69 | });
70 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/plugins/jquery.tree.hotkeys.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | if(typeof window.hotkeys == "undefined") throw "jsTree hotkeys: jQuery hotkeys plugin not included.";
3 |
4 | $.extend($.tree.plugins, {
5 | "hotkeys" : {
6 | bound : [],
7 | disabled : false,
8 | defaults : {
9 | hover_mode : false,
10 | functions : {
11 | "up" : function () { $.tree.plugins.hotkeys.get_prev.apply(this); return false; },
12 | "down" : function () { $.tree.plugins.hotkeys.get_next.apply(this); return false; },
13 | "left" : function () { $.tree.plugins.hotkeys.get_left.apply(this); return false; },
14 | "right" : function () { $.tree.plugins.hotkeys.get_right.apply(this); return false; },
15 | "f2" : function () { if(this.selected) this.rename(); return false; },
16 | "del" : function () { if(this.selected) this.remove(); return false; },
17 | "ctrl+c": function () { if(this.selected) this.copy(); return false; },
18 | "ctrl+x": function () { if(this.selected) this.cut(); return false; },
19 | "ctrl+v": function () { if(this.selected) this.paste(); return false; }
20 | }
21 | },
22 | exec : function(key) {
23 | if($.tree.plugins.hotkeys.disabled) return false;
24 |
25 | var t = $.tree.focused();
26 | if(typeof t.settings.plugins.hotkeys == "undefined") return;
27 | var opts = $.extend(true, {}, $.tree.plugins.hotkeys.defaults, t.settings.plugins.hotkeys);
28 | if(typeof opts.functions[key] == "function") return opts.functions[key].apply(t);
29 | },
30 | get_next : function() {
31 | var opts = $.extend(true, {}, $.tree.plugins.hotkeys.defaults, this.settings.plugins.hotkeys);
32 | var obj = this.hovered || this.selected;
33 | return opts.hover_mode ? this.hover_branch(this.next(obj)) : this.select_branch(this.next(obj));
34 | },
35 | get_prev : function() {
36 | var opts = $.extend(true, {}, $.tree.plugins.hotkeys.defaults, this.settings.plugins.hotkeys);
37 | var obj = this.hovered || this.selected;
38 | return opts.hover_mode ? this.hover_branch(this.prev(obj)) : this.select_branch(this.prev(obj));
39 | },
40 | get_left : function() {
41 | var opts = $.extend(true, {}, $.tree.plugins.hotkeys.defaults, this.settings.plugins.hotkeys);
42 | var obj = this.hovered || this.selected;
43 | if(obj) {
44 | if(obj.hasClass("open")) this.close_branch(obj);
45 | else {
46 | return opts.hover_mode ? this.hover_branch(this.parent(obj)) : this.select_branch(this.parent(obj));
47 | }
48 | }
49 | },
50 | get_right : function() {
51 | var opts = $.extend(true, {}, $.tree.plugins.hotkeys.defaults, this.settings.plugins.hotkeys);
52 | var obj = this.hovered || this.selected;
53 | if(obj) {
54 | if(obj.hasClass("closed")) this.open_branch(obj);
55 | else {
56 | return opts.hover_mode ? this.hover_branch(obj.find("li:eq(0)")) : this.select_branch(obj.find("li:eq(0)"));
57 | }
58 | }
59 | },
60 |
61 | callbacks : {
62 | oninit : function (t) {
63 | var opts = $.extend(true, {}, $.tree.plugins.hotkeys.defaults, this.settings.plugins.hotkeys);
64 | for(var i in opts.functions) {
65 | if(opts.functions.hasOwnProperty(i) && $.inArray(i, $.tree.plugins.hotkeys.bound) == -1) {
66 | (function (k) {
67 | $(document).bind("keydown", { combi : k, disableInInput: true }, function (event) {
68 | return $.tree.plugins.hotkeys.exec(k);
69 | });
70 | })(i);
71 | $.tree.plugins.hotkeys.bound.push(i);
72 | }
73 | }
74 | }
75 | }
76 | }
77 | });
78 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/plugins/jquery.tree.metadata.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | if(typeof $.metadata == "undefined") throw "jsTree metadata: jQuery metadata plugin not included.";
3 |
4 | $.extend($.tree.plugins, {
5 | "metadata" : {
6 | defaults : {
7 | attribute : "data"
8 | },
9 | callbacks : {
10 | check : function(rule, obj, value, tree) {
11 | var opts = $.extend(true, {}, $.tree.plugins.metadata.defaults, this.settings.plugins.metadata);
12 | if(typeof $(obj).metadata({ type : "attr", name : opts.attribute })[rule] != "undefined") return $(obj).metadata()[rule];
13 | }
14 | }
15 | }
16 | });
17 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/plugins/jquery.tree.themeroller.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | $.extend($.tree.plugins, {
3 | "themeroller" : {
4 | defaults : {
5 |
6 | },
7 | callbacks : {
8 | oninit : function (t) {
9 | if(this.settings.ui.theme_name != "themeroller") return;
10 | var opts = $.extend(true, {}, $.tree.plugins.themeroller.defaults, this.settings.plugins.themeroller);
11 | this.container.addClass("ui-widget ui-widget-content");
12 | $("#" + this.container.attr("id") + " li a").live("mouseover", function () { $(this).addClass("ui-state-hover"); });
13 | $("#" + this.container.attr("id") + " li a").live("mouseout", function () { $(this).removeClass("ui-state-hover"); });
14 | },
15 | onparse : function (s, t) {
16 | if(this.settings.ui.theme_name != "themeroller") return;
17 | var opts = $.extend(true, {}, $.tree.plugins.themeroller.defaults, this.settings.plugins.themeroller);
18 | return $(s).find("a").not(".ui-state-default").addClass("ui-state-default").children("ins").addClass("ui-icon").end().end().end();
19 | },
20 | onselect : function(n, t) {
21 | if(this.settings.ui.theme_name != "themeroller") return;
22 | var opts = $.extend(true, {}, $.tree.plugins.themeroller.defaults, this.settings.plugins.themeroller);
23 | $(n).children("a").addClass("ui-state-active");
24 | },
25 | ondeselect : function(n, t) {
26 | if(this.settings.ui.theme_name != "themeroller") return;
27 | var opts = $.extend(true, {}, $.tree.plugins.themeroller.defaults, this.settings.plugins.themeroller);
28 | $(n).children("a").removeClass("ui-state-active");
29 | }
30 | }
31 | }
32 | });
33 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/plugins/jquery.tree.xml_flat.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | if(typeof Sarissa == "undefined") throw "jsTree xml_flat: Sarissa is not included.";
3 |
4 | $.extend($.tree.datastores, {
5 | "xml_flat" : function () {
6 | return {
7 | get : function(obj, t, opts) {
8 | var str = "";
9 | if(!obj || $(obj).size() == 0) {
10 | obj = t.container.children("ul").children("li");
11 | }
12 | else obj = $(obj);
13 |
14 | if(obj.size() > 1) {
15 | var _this = this;
16 | var str = '';
17 | obj.each(function () {
18 | opts.callback = true;
19 | str += _this.get(this, t, opts);
20 | });
21 | str += ' ';
22 | return str;
23 | }
24 |
25 | if(!opts) var opts = {};
26 | if(!opts.outer_attrib) opts.outer_attrib = [ "id", "rel", "class" ];
27 | if(!opts.inner_attrib) opts.inner_attrib = [ ];
28 | if(!opts.callback) str += '';
29 |
30 | str += '- 0) str += ' ' + opts.outer_attrib[i] + '="' + val.toString() + '" ';
36 | delete val;
37 | }
38 | str += '>';
39 |
40 | str += '
';
41 | if(t.settings.languages.length) {
42 | for(var i in t.settings.languages) {
43 | if(!t.settings.languages.hasOwnProperty(i)) continue;
44 | str += this.process_inner(obj.children("a." + t.settings.languages[i]), t, opts, t.settings.languages[i]);
45 | }
46 | }
47 | else {
48 | str += this.process_inner(obj.children("a"), t, opts);
49 | }
50 | str += ' ';
51 | str += ' ';
52 |
53 | if(obj.children("ul").size() > 0) {
54 | var _this = this;
55 | opts.callback = true;
56 | obj.children("ul").children("li").each(function () {
57 | str += _this.get(this, t, opts);
58 | });
59 | opts.callback = false;
60 | }
61 | if(!opts.callback) str += ' ';
62 | return str;
63 | },
64 | process_inner : function(obj, t, opts, lang) {
65 | var str = ' 0) str += ' ' + opts.inner_attrib[j] + '="' + val.toString() + '" ';
79 | delete val;
80 | }
81 | }
82 | }
83 | str += '> ';
84 | return str;
85 | },
86 |
87 | parse : function(data, t, opts, callback) {
88 | var processor = new XSLTProcessor();
89 | processor.importStylesheet($.tree.datastores.xml_flat.xsl);
90 |
91 | var result = $((new XMLSerializer()).serializeToString(processor.transformToDocument(data)));
92 | if(result.is("ul")) result = result.html();
93 | else result = result.find("ul").html();
94 | if(callback) callback.call(null,result);
95 |
96 | // Disabled because of Chrome issues
97 | // if(callback) callback.call(null,(new XMLSerializer()).serializeToString(processor.transformToDocument(data)).replace(/^]*>/i,"").replace(/<\/ul>$/i,""));
98 | },
99 | load : function(data, t, opts, callback) {
100 | if(opts.static) {
101 | callback.call(null, (new DOMParser()).parseFromString(opts.static,'text/xml'));
102 | }
103 | else {
104 | $.ajax({
105 | 'type' : opts.method,
106 | 'url' : opts.url,
107 | 'data' : data,
108 | 'dataType' : "xml",
109 | 'success' : function (d, textStatus) {
110 | callback.call(null, d);
111 | },
112 | 'error' : function (xhttp, textStatus, errorThrown) {
113 | callback.call(null, false);
114 | t.error(errorThrown + " " + textStatus);
115 | }
116 | });
117 | }
118 | }
119 | }
120 | }
121 | });
122 | $.tree.datastores.xml_flat.xsl = (new DOMParser()).parseFromString(' last open closed leaf background-image:url( ); ','text/xml');
123 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/plugins/jquery.tree.xml_nested.js:
--------------------------------------------------------------------------------
1 | (function ($) {
2 | if(typeof Sarissa == "undefined") throw "jsTree xml_nested: Sarissa is not included.";
3 |
4 | $.extend($.tree.datastores, {
5 | "xml_nested" : function () {
6 | return {
7 | get : function(obj, tree, opts) {
8 | var str = "";
9 | if(!obj || $(obj).size() == 0) {
10 | obj = tree.container.children("ul").children("li");
11 | }
12 | else obj = $(obj);
13 |
14 | if(obj.size() > 1) {
15 | var _this = this;
16 | var str = '';
17 | obj.each(function () {
18 | str += _this.get(this, tree, $.extend(true, {}, opts, { callback : true }));
19 | });
20 | str += ' ';
21 | return str;
22 | }
23 |
24 | if(!opts) var opts = {};
25 | if(!opts.outer_attrib) opts.outer_attrib = [ "id", "rel", "class" ];
26 | if(!opts.inner_attrib) opts.inner_attrib = [ ];
27 | if(!opts.callback) str += '';
28 |
29 | str += '- 0) str += ' ' + opts.outer_attrib[i] + '="' + val.toString() + '" ';
34 | delete val;
35 | }
36 | str += '>';
37 |
38 | str += '
';
39 | if(tree.settings.languages.length) {
40 | for(var i in tree.settings.languages) {
41 | if(!tree.settings.languages.hasOwnProperty(i)) continue;
42 | str += this.process_inner(obj.children("a." + tree.settings.languages[i]), tree, opts, tree.settings.languages[i]);
43 | }
44 | }
45 | else {
46 | str += this.process_inner(obj.children("a"), tree, opts);
47 | }
48 | str += ' ';
49 |
50 | if(obj.children("ul").size() > 0) {
51 | var _this = this;
52 | obj.children("ul").children("li").each(function () {
53 | str += _this.get(this, tree, $.extend(true, {}, opts, { callback : true }));
54 | });
55 | }
56 | str += ' ';
57 |
58 | if(!opts.callback) str += ' ';
59 | return str;
60 | },
61 | process_inner : function(obj, tree, opts, lang) {
62 | var str = ' 0) str += ' ' + opts.inner_attrib[j] + '="' + val.toString() + '" ';
76 | delete val;
77 | }
78 | }
79 | }
80 | str += '> ';
81 | return str;
82 | },
83 | parse : function(data, tree, opts, callback) {
84 | var processor = new XSLTProcessor();
85 | processor.importStylesheet($.tree.datastores.xml_nested.xsl);
86 |
87 | var result = $((new XMLSerializer()).serializeToString(processor.transformToDocument(data)).replace('',''));
88 | // Opera bug
89 | if(result.size() > 1) result = result.eq(1);
90 | if(result.is("ul")) result = result.html();
91 | else result = result.find("ul:eq(0)").html();
92 | if(callback) callback.call(null,result);
93 |
94 | // Disabled because of Chrome issues
95 | // if(callback) callback.call(null,(new XMLSerializer()).serializeToString(processor.transformToDocument(data)).replace(/^]*>/i,"").replace(/<\/ul>$/i,""));
96 | },
97 | load : function(data, tree, opts, callback) {
98 | if(opts.staticData) {
99 | callback.call(null, (new DOMParser()).parseFromString(opts.staticData,'text/xml'));
100 | }
101 | else {
102 | $.ajax({
103 | 'type' : opts.method,
104 | 'url' : opts.url,
105 | 'data' : data,
106 | 'dataType' : "xml",
107 | 'success' : function (d, textStatus) {
108 | callback.call(null, d);
109 | },
110 | 'error' : function (xhttp, textStatus, errorThrown) {
111 | callback.call(null, false);
112 | tree.error(errorThrown + " " + textStatus);
113 | }
114 | });
115 | }
116 | }
117 | }
118 | }
119 | });
120 | $.tree.datastores.xml_nested.xsl = (new DOMParser()).parseFromString(' ','text/xml');
121 | })(jQuery);
--------------------------------------------------------------------------------
/public/node-zk/stylesheets/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 50px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | a {
7 | color: #00B7FF;
8 | }
--------------------------------------------------------------------------------
/public/node-zk/themes/apple/bg.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/apple/bg.jpg
--------------------------------------------------------------------------------
/public/node-zk/themes/apple/dot_for_ie.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/apple/dot_for_ie.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/apple/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/apple/icons.png
--------------------------------------------------------------------------------
/public/node-zk/themes/apple/style.css:
--------------------------------------------------------------------------------
1 | /* BACKGROUND */
2 | .tree-apple .ltr, .tree-apple .rtl { background:url("bg.jpg") left top repeat; min-width:100%; _width:100%; margin-left:0; margin-right:0; display:table; }
3 | .tree-apple .ltr > li.leaf, .tree-apple .rtl > li.leaf { background-image:none; }
4 |
5 | /* LOCKED */
6 | .tree-apple .locked li a { color:gray; }
7 | /* DOTS */
8 | .tree-apple ul { background-position:6px 1px; background-repeat:repeat-y; background-image:url(data:image/gif;base64,R0lGODlhAgACAIAAAB4dGf///yH5BAEAAAEALAAAAAACAAIAAAICRF4AOw==); _background-image:url("dot_for_ie.gif"); *background-image:url("dot_for_ie.gif"); }
9 | .tree-apple li { background-position:-64px -16px; background-repeat:no-repeat; background-image:url("icons.png"); }
10 | /* NO DOTS */
11 | .tree-apple .no_dots, .tree-apple .no_dots ul { background:transparent; }
12 | .tree-apple .no_dots li.leaf { background-image:none; background-color:transparent; }
13 | /* OPEN or CLOSED */
14 | .tree-apple li.open { background:url("icons.png") -32px -48px no-repeat; }
15 | .tree-apple li.closed, #jstree-dragged.tree-apple li li.open { background:url("icons.png") -48px -32px no-repeat; }
16 | #jstree-marker { background-image:url("icons.png"); }
17 | /* DEFAULT, HOVER, CLICKED, LOADING STATES */
18 | .tree-apple li a, .tree-apple li span { border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; }
19 | .tree-apple li a:hover, .tree-apple li a.hover, .tree-apple li span { background: #e7f4f9; border:1px solid #d8f0fa; padding:0px 3px 0px 3px; }
20 | .tree-apple li a.clicked, .tree-apple li a.clicked:hover, .tree-apple li span.clicked { background: #beebff; border:1px solid #99defd; padding:0px 3px 0px 3px; }
21 | /* ICONS */
22 | .tree-apple ins { background-image:url("icons.png"); background-position:0 0; background-repeat:no-repeat; }
23 | .tree-apple ul li a.loading ins { background-image:url("throbber.gif") !important; background-position:0 0 !important; } /* UL is added to make selector stronger */
24 | .tree-apple li a ins.forbidden { background-position:-16px -16px; }
25 | .tree-apple .locked li a ins { background-position:0 -48px; }
26 | .tree-apple li span ins { background-position:-16px 0; }
27 | #jstree-dragged.tree-apple ins { background:url("icons.png") -16px -32px no-repeat; }
28 | #jstree-dragged.tree-apple ins.forbidden { background:url("icons.png") -16px -16px no-repeat; }
29 |
30 | /* CONTEXT MENU */
31 | .tree-apple-context a ins { background-image:url("icons.png"); background-repeat:no-repeat; background-position:-64px -64px; }
32 | .tree-apple-context a ins.create { background-position:0 -16px; }
33 | .tree-apple-context a ins.rename { background-position:-16px 0px; }
34 | .tree-apple-context a ins.remove { background-position:0 -32px; }
--------------------------------------------------------------------------------
/public/node-zk/themes/apple/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/apple/throbber.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/checkbox/dot_for_ie.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/checkbox/dot_for_ie.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/checkbox/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/checkbox/icons.png
--------------------------------------------------------------------------------
/public/node-zk/themes/checkbox/style.css:
--------------------------------------------------------------------------------
1 | /* LOCKED */
2 | .tree-checkbox .locked li a { color:gray; }
3 | /* DOTS */
4 | .tree-checkbox ul { background-position:6px 1px; background-repeat:repeat-y; background-image:url(data:image/gif;base64,R0lGODlhAgACAIAAAB4dGf///yH5BAEAAAEALAAAAAACAAIAAAICRF4AOw==); _background-image:url("dot_for_ie.gif"); *background-image:url("dot_for_ie.gif"); }
5 | .tree-checkbox li { background-position:-64px -16px; background-repeat:no-repeat; background-image:url("icons.png"); }
6 | /* NO DOTS */
7 | .tree-checkbox .no_dots, .tree-checkbox .no_dots ul { background:transparent; }
8 | .tree-checkbox .no_dots li.leaf { background-image:none; background-color:transparent; }
9 | /* OPEN or CLOSED */
10 | .tree-checkbox li.open { background:url("icons.png") -32px -48px no-repeat; }
11 | .tree-checkbox li.closed, #jstree-dragged.tree-checkbox li li.open { background:url("icons.png") -48px -32px no-repeat; }
12 | #jstree-marker { background-image:url("icons.png"); }
13 | /* DEFAULT, HOVER, CLICKED, LOADING STATES */
14 | .tree-checkbox li a, .tree-checkbox li span { border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; }
15 | /*
16 | .tree-checkbox li a:hover, .tree-checkbox li a.hover, .tree-checkbox li span { background: #e7f4f9; border:1px solid #d8f0fa; padding:0px 3px 0px 3px; }
17 | .tree-checkbox li a.clicked, .tree-checkbox li a.clicked:hover, .tree-checkbox li span.clicked { background: #beebff; border:1px solid #99defd; padding:0px 3px 0px 3px; }
18 | */
19 | /* ICONS */
20 | .tree-checkbox ins { background-image:url("icons.png"); background-position:0 0; background-repeat:no-repeat; }
21 | .tree-checkbox ul li a.loading ins { background-image:url("throbber.gif") !important; background-position:0 0 !important; } /* UL is added to make selector stronger */
22 | .tree-checkbox li a ins.forbidden { background-position:-16px -48px; }
23 |
24 | .tree-checkbox li a.undetermined ins { background-position:0px -16px; }
25 | .tree-checkbox li a.checked ins { background-position:0px -32px; }
26 |
27 | .tree-checkbox li a:hover ins { background-position:-16px 0px; }
28 | .tree-checkbox li a.undetermined:hover ins { background-position:-16px -16px; }
29 | .tree-checkbox li a.checked:hover ins { background-position:-16px -32px; }
30 |
31 | #jstree-dragged.tree-checkbox ins { background:url("icons.png") 0 -48px no-repeat; }
32 | #jstree-dragged.tree-checkbox ins.forbidden { background:url("icons.png") -16px -48px no-repeat; }
33 |
34 | /* CONTEXT MENU */
35 | .tree-checkbox-context a ins { background-image:url("icons.png"); background-repeat:no-repeat; background-position:-64px -64px; }
36 | .tree-checkbox-context a ins.create { background-position:0 -16px; }
37 | .tree-checkbox-context a ins.rename { background-position:-16px 0px; }
38 | .tree-checkbox-context a ins.remove { background-position:0 -32px; }
--------------------------------------------------------------------------------
/public/node-zk/themes/checkbox/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/checkbox/throbber.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/classic/dot_for_ie.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/classic/dot_for_ie.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/classic/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/classic/icons.png
--------------------------------------------------------------------------------
/public/node-zk/themes/classic/style.css:
--------------------------------------------------------------------------------
1 | /* LOCKED */
2 | .tree-classic .locked li a { color:gray; }
3 | /* DOTS */
4 | .tree-classic ul { background-position:6px 1px; background-repeat:repeat-y; background-image:url(data:image/gif;base64,R0lGODlhAgACAIAAAB4dGf///yH5BAEAAAEALAAAAAACAAIAAAICRF4AOw==); _background-image:url("dot_for_ie.gif"); *background-image:url("dot_for_ie.gif"); }
5 | .tree-classic li { background-position:-64px -16px; background-repeat:no-repeat; background-image:url("icons.png"); }
6 | /* NO DOTS */
7 | .tree-classic .no_dots, .tree-classic .no_dots ul { background:transparent; }
8 | .tree-classic .no_dots li.leaf { background-image:none; background-color:transparent; }
9 | /* OPEN or CLOSED */
10 | .tree-classic li.open { background:url("icons.png") -32px -48px no-repeat; }
11 | .tree-classic li.closed, #jstree-dragged.tree-classic li li.open { background:url("icons.png") -48px -32px no-repeat; }
12 | #jstree-marker { background-image:url("icons.png"); }
13 | /* DEFAULT, HOVER, CLICKED, LOADING STATES */
14 | .tree-classic li a:hover, .tree-classic li a.hover, .tree-classic li span { /*background: #e7f4f9; border:1px solid #d8f0fa; padding:0px 3px 0px 3px;*/ }
15 | .tree-classic li a.clicked, .tree-classic li a.clicked:hover, .tree-classic li span.clicked { background: navy; border:1px solid navy; color:white; padding:0px 3px 0px 3px; }
16 | /* ICONS */
17 | .tree-classic ins { background-image:url("icons.png"); background-position:0 0; background-repeat:no-repeat; }
18 | .tree-classic ul li a.loading ins { background-image:url("throbber.gif") !important; background-position:0 0 !important; } /* UL is added to make selector stronger */
19 | .tree-classic li.closed a ins, .tree-classic li.leaf a ins { background-position:0 0px; } /* UL is added to make selector stronger */
20 | .tree-classic ul li a.loading ins { background-image:url("throbber.gif"); background-position:0 0; } /* UL is added to make selector stronger */
21 | .tree-classic li a ins.forbidden { background-position:-16px -16px; }
22 | .tree-classic .locked li a ins { background-position:0 -48px; }
23 | .tree-classic li span ins { background-position:-16px 0; }
24 | #jstree-dragged.tree-classic ins { background:url("icons.png") -16px -32px no-repeat; }
25 | #jstree-dragged.tree-classic ins.forbidden { background:url("icons.png") -16px -16px no-repeat; }
26 |
27 | /* CONTEXT MENU */
28 | .tree-classic-context a ins { background-image:url("icons.png"); background-repeat:no-repeat; background-position:-64px -64px; }
29 | .tree-classic-context a ins.create { background-position:0 -16px; }
30 | .tree-classic-context a ins.rename { background-position:-16px 0px; }
31 | .tree-classic-context a ins.remove { background-position:-32px -16px; }
--------------------------------------------------------------------------------
/public/node-zk/themes/classic/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/classic/throbber.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/default/dot_for_ie.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/default/dot_for_ie.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/default/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/default/icons.png
--------------------------------------------------------------------------------
/public/node-zk/themes/default/style.css:
--------------------------------------------------------------------------------
1 | /* LOCKED */
2 | .tree-default .locked li a { color:gray; }
3 | /* DOTS */
4 | .tree-default ul { background-position:6px 1px; background-repeat:repeat-y; background-image:url(data:image/gif;base64,R0lGODlhAgACAIAAAB4dGf///yH5BAEAAAEALAAAAAACAAIAAAICRF4AOw==); _background-image:url("dot_for_ie.gif"); *background-image:url("dot_for_ie.gif"); }
5 | .tree-default li { background-position:-64px -16px; background-repeat:no-repeat; background-image:url("icons.png"); }
6 | /* NO DOTS */
7 | .tree-default .no_dots, .tree-default .no_dots ul { background:transparent; }
8 | .tree-default .no_dots li.leaf { background-image:none; background-color:transparent; }
9 | /* OPEN or CLOSED */
10 | .tree-default li.open { background:url("icons.png") -32px -48px no-repeat; }
11 | .tree-default li.closed, #jstree-dragged.tree-default li li.open { background:url("icons.png") -48px -32px no-repeat; }
12 | #jstree-marker { background-image:url("icons.png"); }
13 | /* DEFAULT, HOVER, CLICKED, LOADING STATES */
14 | .tree-default li a, .tree-default li span { border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; }
15 | .tree-default li a:hover, .tree-default li a.hover, .tree-default li span { background: #e7f4f9; border:1px solid #d8f0fa; padding:0px 3px 0px 3px; }
16 | .tree-default li a.clicked, .tree-default li a.clicked:hover, .tree-default li span.clicked { background: #beebff; border:1px solid #99defd; padding:0px 3px 0px 3px; }
17 | /* ICONS */
18 | .tree-default ins { background-image:url("icons.png"); background-position:0 0; background-repeat:no-repeat; }
19 | .tree-default ul li a.loading ins { background-image:url("throbber.gif") !important; background-position:0 0 !important; } /* UL is added to make selector stronger */
20 | .tree-default li a ins.forbidden { background-position:-16px -16px; }
21 | .tree-default .locked li a ins { background-position:0 -48px; }
22 | .tree-default li span ins { background-position:-16px 0; }
23 | #jstree-dragged.tree-default ins { background:url("icons.png") -16px -32px no-repeat; }
24 | #jstree-dragged.tree-default ins.forbidden { background:url("icons.png") -16px -16px no-repeat; }
25 |
26 | /* CONTEXT MENU */
27 | .tree-default-context a ins { background-image:url("icons.png"); background-repeat:no-repeat; background-position:-64px -64px; }
28 | .tree-default-context a ins.create { background-position:0 -16px; }
29 | .tree-default-context a ins.rename { background-position:-16px 0px; }
30 | .tree-default-context a ins.remove { background-position:0 -32px; }
--------------------------------------------------------------------------------
/public/node-zk/themes/default/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/default/throbber.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/themeroller/dot_for_ie.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/themeroller/dot_for_ie.gif
--------------------------------------------------------------------------------
/public/node-zk/themes/themeroller/icons.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/themeroller/icons.png
--------------------------------------------------------------------------------
/public/node-zk/themes/themeroller/style.css:
--------------------------------------------------------------------------------
1 | /* LOCKED */
2 | .tree-themeroller .locked li a { color:gray; }
3 | /* DOTS */
4 | .tree-themeroller ul { background-position:6px 1px; background-repeat:repeat-y; background-image:url(data:image/gif;base64,R0lGODlhAgACAIAAAB4dGf///yH5BAEAAAEALAAAAAACAAIAAAICRF4AOw==); _background-image:url("dot_for_ie.gif"); *background-image:url("dot_for_ie.gif"); }
5 | .tree-themeroller li { background-position:-64px -16px; background-repeat:no-repeat; background-image:url("icons.png"); }
6 | /* NO DOTS */
7 | .tree-themeroller .no_dots, .tree-themeroller .no_dots ul { background:transparent; }
8 | .tree-themeroller .no_dots li.leaf { background-image:none; background-color:transparent; }
9 | /* OPEN or CLOSED */
10 | .tree-themeroller li.open { background:url("icons.png") -32px -48px no-repeat; }
11 | .tree-themeroller li.closed, #jstree-dragged.tree-themeroller li li.open { background:url("icons.png") -48px -32px no-repeat; }
12 | #jstree-marker { background-image:url("icons.png"); }
13 |
14 | .tree-themeroller li, .tree-themeroller li a, .tree-themeroller li a ins { line-height:16px !important; }
15 | .tree-themeroller li a .ui-icon { overflow:visible; }
16 |
17 | /* DEFAULT, HOVER, CLICKED, LOADING STATES
18 | .tree-themeroller li a, .tree-themeroller li span { border-radius:3px; -moz-border-radius:3px; -webkit-border-radius:3px; }
19 | .tree-themeroller li a:hover, .tree-themeroller li a.hover, .tree-themeroller li span { background: #e7f4f9; border:1px solid #d8f0fa; padding:0px 3px 0px 3px; }
20 | .tree-themeroller li a.clicked, .tree-themeroller li a.clicked:hover, .tree-themeroller li span.clicked { background: #beebff; border:1px solid #99defd; padding:0px 3px 0px 3px; }
21 | */
22 | /* ICONS */
23 | .tree-themeroller ul li a.loading ins { background-image:url("throbber.gif") !important; background-position:0 0 !important; } /* UL is added to make selector stronger */
24 | /*
25 | .tree-themeroller ins { background-image:url("icons.png"); background-position:0 0; background-repeat:no-repeat; }
26 | .tree-themeroller li a ins.forbidden { background-position:-16px -16px; }
27 | .tree-themeroller .locked li a ins { background-position:0 -48px; }
28 | .tree-themeroller li span ins { background-position:-16px 0; }
29 | */
30 |
31 | #jstree-dragged.tree-themeroller ins { background:url("icons.png") -16px -32px no-repeat; }
32 | #jstree-dragged.tree-themeroller ins.forbidden { background:url("icons.png") -16px -16px no-repeat; }
33 |
34 | /* CONTEXT MENU
35 | .tree-themeroller-context a ins { background-image:url("icons.png"); background-repeat:no-repeat; background-position:-64px -64px; }
36 | .tree-themeroller-context a ins.create { background-position:0 -16px; }
37 | .tree-themeroller-context a ins.rename { background-position:-16px 0px; }
38 | .tree-themeroller-context a ins.remove { background-position:0 -32px; }
39 | */
--------------------------------------------------------------------------------
/public/node-zk/themes/themeroller/throbber.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/killme2008/node-zk-browser/99786f4e72fce94862539d06c1840eb6322dd7e9/public/node-zk/themes/themeroller/throbber.gif
--------------------------------------------------------------------------------
/start.sh:
--------------------------------------------------------------------------------
1 | LOGFILE=$(dirname $0)/logs/node-zk-browser.log
2 | export ZK_HOST="localhost:2181"
3 | nohup node $(dirname $0)/app.js 2>&1 >>$LOGFILE &
4 |
5 |
--------------------------------------------------------------------------------
/test/app.test.js:
--------------------------------------------------------------------------------
1 |
2 | // Run $ expresso
3 |
4 | /**
5 | * Module dependencies.
6 | */
7 |
8 | var app = require('../app')
9 | , assert = require('assert');
10 |
11 |
12 | module.exports = {
13 | 'GET /': function(){
14 | assert.response(app,
15 | { url: '/' },
16 | { status: 200, headers: { 'Content-Type': 'text/html; charset=utf-8' }},
17 | function(res){
18 | assert.includes(res.body, 'Express ');
19 | });
20 | }
21 | };
--------------------------------------------------------------------------------
/user.json:
--------------------------------------------------------------------------------
1 | {
2 | "admin" : "admin"
3 | }
4 |
--------------------------------------------------------------------------------
/views/create.ejs:
--------------------------------------------------------------------------------
1 |
2 | Create path
3 |
4 |
15 |
16 |
17 |
18 |
19 |
20 |
21 | <% if(user) { %>
22 |
Welcome,<%= user %>
23 | <% }else{ %>
24 |
Signin
25 |
26 |
33 |
34 | <% } %>
35 |
36 |
37 |