jquery.treeview.js 22.9 KB
Newer Older
1 2
/*
 * Treeview 1.5pre - jQuery plugin to hide and show branches of a tree
3
 *
4 5 6 7 8 9 10 11 12 13 14 15 16
 * http://bassistance.de/jquery-plugins/jquery-plugin-treeview/
 * http://docs.jquery.com/Plugins/Treeview
 *
 * Copyright (c) 2007 Jörn Zaefferer
 *
 * Dual licensed under the MIT and GPL licenses:
 *   http://www.opensource.org/licenses/mit-license.php
 *   http://www.gnu.org/licenses/gpl.html
 *
 * Revision: $Id: jquery.treeview.js 5759 2008-07-01 07:50:28Z joern.zaefferer $
 *
 */

17 18
//Add custom i18n.js

19 20 21 22 23 24 25
//名前空間用のオブジェクトを用意する
var JQ_TREEVIEW = {};
JQ_TREEVIEW.CLASS_FOLDER = "folder";
JQ_TREEVIEW.CLASS_FOLDER_ZERO = "folderZero";
JQ_TREEVIEW.CLASS_FILE = "file";
JQ_TREEVIEW.CLASS_FILE_ZERO = "fileZero";

26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
;(function($) {

	// TODO rewrite as a widget, removing all the extra plugins
	$.extend($.fn, {
		swapClass: function(c1, c2) {
			var c1Elements = this.filter('.' + c1);
			this.filter('.' + c2).removeClass(c2).addClass(c1);
			c1Elements.removeClass(c1).addClass(c2);
			return this;
		},
		replaceClass: function(c1, c2) {
			return this.filter('.' + c1).removeClass(c1).addClass(c2).end();
		},
		hoverClass: function(className) {
			className = className || "hover";
			return this.hover(function() {
				$(this).addClass(className);
			}, function() {
				$(this).removeClass(className);
			});
		},
		heightToggle: function(animated, callback) {
			animated ?
				this.animate({ height: "toggle" }, animated, callback) :
				this.each(function(){
					jQuery(this)[ jQuery(this).is(":hidden") ? "show" : "hide" ]();
					if(callback)
						callback.apply(this, arguments);
				});
		},
		heightHide: function(animated, callback) {
			if (animated) {
				this.animate({ height: "hide" }, animated, callback);
			} else {
				this.hide();
				if (callback)
62
					this.each(callback);
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81
			}
		},
		prepareBranches: function(settings) {
			if (!settings.prerendered) {
				// mark last tree items
				this.filter(":last-child:not(ul)").addClass(CLASSES.last);
				// collapse whole tree, or only those marked as closed, anyway except those marked as open
				this.filter((settings.collapsed ? "" : "." + CLASSES.closed) + ":not(." + CLASSES.open + ")").find(">ul").hide();
			}
			// return all items with sublists
			return this.filter(":has(>ul)");
		},
		applyClasses: function(settings, toggler) {
			// TODO use event delegation
			this.filter(":has(>ul):not(:has(>a))").find(">span").unbind("click.treeview").bind("click.treeview", function(event) {
				// don't handle click events on children, eg. checkboxes
				if ( this == event.target )
					toggler.apply($(this).next());
			}).add( $("a", this) ).hoverClass();
82

83 84 85 86 87
			if (!settings.prerendered) {
				// handle closed ones first
				this.filter(":has(>ul:hidden)")
						.addClass(CLASSES.expandable)
						.replaceClass(CLASSES.last, CLASSES.lastExpandable);
88

89 90 91 92
				// handle open ones
				this.not(":has(>ul:hidden)")
						.addClass(CLASSES.collapsable)
						.replaceClass(CLASSES.last, CLASSES.lastCollapsable);
93

94 95 96 97 98 99 100 101 102 103 104 105
	            // create hitarea if not present
				var hitarea = this.find("div." + CLASSES.hitarea);
				if (!hitarea.length)
					hitarea = this.prepend("<div class=\"" + CLASSES.hitarea + "\"/>").find("div." + CLASSES.hitarea);
				hitarea.removeClass().addClass(CLASSES.hitarea).each(function() {
					var classes = "";
					$.each($(this).parent().attr("class").split(" "), function() {
						classes += this + "-hitarea ";
					});
					$(this).addClass( classes );
				})
			}
106

107 108 109 110
			// apply event to hitarea
			this.find("div." + CLASSES.hitarea).click( toggler );
		},
		treeview: function(settings) {
111

112 113 114
			settings = $.extend({
				cookieId: "treeview"
			}, settings);
115

116 117 118 119 120 121
			if ( settings.toggle ) {
				var callback = settings.toggle;
				settings.toggle = function() {
					return callback.apply($(this).parent()[0], arguments);
				};
			}
122

123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
			// factory for treecontroller
			function treeController(tree, control) {
				// factory for click handlers
				function handler(filter) {
					return function() {
						// reuse toggle event handler, applying the elements to toggle
						// start searching for all hitareas
						toggler.apply( $("div." + CLASSES.hitarea, tree).filter(function() {
							// for plain toggle, no filter is provided, otherwise we need to check the parent element
							return filter ? $(this).parent("." + filter).length : true;
						}) );
						return false;
					};
				}
				// click on first element to collapse tree
				$("a:eq(0)", control).click( handler(CLASSES.collapsable) );
				// click on second to expand tree
				$("a:eq(1)", control).click( handler(CLASSES.expandable) );
				// click on third to toggle tree
142
				$("a:eq(2)", control).click( handler() );
143
			}
144

145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175
			// handle toggle event
			function toggler() {
				$(this)
					.parent()
					// swap classes for hitarea
					.find(">.hitarea")
						.swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
						.swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
					.end()
					// swap classes for parent li
					.swapClass( CLASSES.collapsable, CLASSES.expandable )
					.swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
					// find child lists
					.find( ">ul" )
					// toggle them
					.heightToggle( settings.animated, settings.toggle );
				if ( settings.unique ) {
					$(this).parent()
						.siblings()
						// swap classes for hitarea
						.find(">.hitarea")
							.replaceClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
							.replaceClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea )
						.end()
						.replaceClass( CLASSES.collapsable, CLASSES.expandable )
						.replaceClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
						.find( ">ul" )
						.heightHide( settings.animated, settings.toggle );
				}
			}
			this.data("toggler", toggler);
176

177 178 179 180 181 182 183 184 185 186
			function serialize() {
				function binary(arg) {
					return arg ? 1 : 0;
				}
				var data = [];
				branches.each(function(i, e) {
					data[i] = $(e).is(":has(>ul:visible)") ? 1 : 0;
				});
				$.cookie(settings.cookieId, data.join(""), settings.cookieOptions );
			}
187

188 189 190 191 192 193 194 195 196
			function deserialize() {
				var stored = $.cookie(settings.cookieId);
				if ( stored ) {
					var data = stored.split("");
					branches.each(function(i, e) {
						$(e).find(">ul")[ parseInt(data[i]) ? "show" : "hide" ]();
					});
				}
			}
197

198 199
			// add treeview class to activate styles
			this.addClass("treeview");
200

201 202
			// prepare branches and find all tree items with child lists
			var branches = this.find("li").prepareBranches(settings);
203

204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233
			switch(settings.persist) {
			case "cookie":
				var toggleCallback = settings.toggle;
				settings.toggle = function() {
					serialize();
					if (toggleCallback) {
						toggleCallback.apply(this, arguments);
					}
				};
				deserialize();
				break;
			case "location":
				var current = this.find("a").filter(function() {
					return this.href.toLowerCase() == location.href.toLowerCase();
				});
				if ( current.length ) {
					// TODO update the open/closed classes
					var items = current.addClass("selected").parents("ul, li").add( current.next() ).show();
					if (settings.prerendered) {
						// if prerendered is on, replicate the basic class swapping
						items.filter("li")
							.swapClass( CLASSES.collapsable, CLASSES.expandable )
							.swapClass( CLASSES.lastCollapsable, CLASSES.lastExpandable )
							.find(">.hitarea")
								.swapClass( CLASSES.collapsableHitarea, CLASSES.expandableHitarea )
								.swapClass( CLASSES.lastCollapsableHitarea, CLASSES.lastExpandableHitarea );
					}
				}
				break;
			}
234

235
			branches.applyClasses(settings, toggler);
236

237 238 239 240 241
			// if control option is set, create the treecontroller and show it
			if ( settings.control ) {
				treeController(this, settings.control);
				$(settings.control).show();
			}
242

243 244 245
			return this;
		}
	});
246

247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
	// classes used by the plugin
	// need to be styled via external stylesheet, see first example
	$.treeview = {};
	var CLASSES = ($.treeview.classes = {
		open: "open",
		closed: "closed",
		expandable: "expandable",
		expandableHitarea: "expandable-hitarea",
		lastExpandableHitarea: "lastExpandable-hitarea",
		collapsable: "collapsable",
		collapsableHitarea: "collapsable-hitarea",
		lastCollapsableHitarea: "lastCollapsable-hitarea",
		lastCollapsable: "lastCollapsable",
		lastExpandable: "lastExpandable",
		last: "last",
		hitarea: "hitarea"
	});
264

265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299
})(jQuery);

// ====================================================
// Function for treeview [start]
// ====================================================

/* variable using for node ID */
var nodeId = 0;

function TreeNode() {
    var currDate = new Date();
    this.Id = "node" + currDate.toIdString();
    this.Value = "";
    this.Text = "New text";
    this.Tooltip = this.Text;
    this.ChildNodes = new Array();
    this.IsClosed = true;
    this.IsCategory = true;
    this.ContentCount = 0;
    this.ChildsCount = 0;
    this.ExpandAfterBuild = false;
    /*
    AddChild = function(newNode) {
        ChildNodes.push(newNode);
    };
    RemoveChild = function(index) {
        ChildNodes.splice(index, 1);
    };
    */
};

// Add category node
function AddCategory(targetTreeView, sourceTreeNode, targetTreeNode, callbackFunction) {
	var branches;
	var scriptCallback = "";
300 301
	var tmpClass = JQ_TREEVIEW.CLASS_FOLDER;

302
	if (callbackFunction != undefined && callbackFunction != null) {
303 304 305 306 307 308 309 310

		scriptCallback += ' onclick="';
		scriptCallback += "var currNode = new TreeNode(); currNode.Id = '" + sourceTreeNode.Id + "'; currNode.Text = '" + sourceTreeNode.Text + "';";
		scriptCallback += "currNode.Value = '" + sourceTreeNode.Value + "'; currNode.Tooltip = '" + sourceTreeNode.Tooltip + "'; currNode.IsClosed = " + sourceTreeNode.IsClosed + ";";
		scriptCallback += "currNode.IsCategory = " + sourceTreeNode.IsCategory + ";";
		scriptCallback += callbackFunction + "(currNode);";
		scriptCallback += '"';

311 312
	}
	if (targetTreeNode != undefined && targetTreeNode != null) {
313 314 315
		if (sourceTreeNode.IsClosed == true) {  // Collapse
			if (targetTreeView.IsShowTotal == true && sourceTreeNode.ContentCount > 0) {  // Show total count
				branches = $("<li class='closed'><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='folder' " + scriptCallback + ">" + sourceTreeNode.Text + "</" + targetTreeView.CategoryTagName + ">&nbsp;(" + sourceTreeNode.ContentCount + ")<ul id='" + sourceTreeNode.Id + "'>" +
316
					"</ul></li>").appendTo("#" + targetTreeNode.Id);
317 318 319 320 321 322 323
			}
			else {
				if(sourceTreeNode.ContentCount == 0){
					scriptCallback = "";
					tmpClass = JQ_TREEVIEW.CLASS_FOLDER_ZERO;
				}
				branches = $("<li class='closed'><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='" + tmpClass + "' " + scriptCallback + ">" + sourceTreeNode.Text + "</" + targetTreeView.CategoryTagName + "><ul id='" + sourceTreeNode.Id + "'>" +
324
					"</ul></li>").appendTo("#" + targetTreeNode.Id);
325 326 327 328 329
			}
		}
		else {
			if (targetTreeView.IsShowTotal == true && sourceTreeNode.ContentCount > 0) {  // Show total count
				branches = $("<li ><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='folder'" + scriptCallback + ">" + sourceTreeNode.Text + "</" + targetTreeView.CategoryTagName + ">&nbsp;(" + sourceTreeNode.ContentCount + ")<ul id='" + sourceTreeNode.Id + "'>" +
330
					"</ul></li>").appendTo("#" + targetTreeNode.Id);
331 332 333 334 335 336 337
			}
			else {
				if(sourceTreeNode.ContentCount == 0){
					scriptCallback = "";
					tmpClass = JQ_TREEVIEW.CLASS_FOLDER_ZERO;
				}
				branches = $("<li ><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='" + tmpClass + "'" + scriptCallback + ">" + sourceTreeNode.Text + "</" + targetTreeView.CategoryTagName + "><ul id='" + sourceTreeNode.Id + "'>" +
338
					"</ul></li>").appendTo("#" + targetTreeNode.Id);
339 340
			}
		}
341 342
	}
	else {
343 344 345
		if (sourceTreeNode.IsClosed == true) {  // Collapse
			if (targetTreeView.IsShowTotal == true  && sourceTreeNode.ContentCount > 0) {  // Show total count
				branches = $("<li class='closed'><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='folder'" + scriptCallback + ">" + sourceTreeNode.Text + "</" + targetTreeView.CategoryTagName + ">&nbsp;(" + sourceTreeNode.ContentCount + ")<ul id='" + sourceTreeNode.Id + "'>" +
346
					"</ul></li>").appendTo("#" + targetTreeView.Id);
347 348 349 350 351 352 353
			}
			else {
				if(sourceTreeNode.ContentCount == 0){
					scriptCallback = "";
					tmpClass = JQ_TREEVIEW.CLASS_FOLDER_ZERO;
				}
				branches = $("<li class='closed'><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='" + tmpClass + "'" + scriptCallback + ">" + sourceTreeNode.Text + "</" + targetTreeView.CategoryTagName + "><ul id='" + sourceTreeNode.Id + "'>" +
354
					"</ul></li>").appendTo("#" + targetTreeView.Id);
355 356 357 358 359
			}
		}
		else {
			if (targetTreeView.IsShowTotal == true && sourceTreeNode.ContentCount > 0) {  // Show total count
				branches = $("<li><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='folder'" + scriptCallback + ">" + sourceTreeNode.Text + "</" + targetTreeView.CategoryTagName + ">&nbsp;(" + sourceTreeNode.ContentCount + ")<ul id='" + sourceTreeNode.Id + "'>" +
360
					"</ul></li>").appendTo("#" + targetTreeView.Id);
361 362 363 364 365 366 367
			}
			else {
				if(sourceTreeNode.ContentCount == 0){
					scriptCallback = "";
					tmpClass = JQ_TREEVIEW.CLASS_FOLDER_ZERO;
				}
				branches = $("<li><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='" + tmpClass + "'" + scriptCallback + ">" + sourceTreeNode.Text + "</" + targetTreeView.CategoryTagName + "><ul id='" + sourceTreeNode.Id + "'>" +
368
					"</ul></li>").appendTo("#" + targetTreeView.Id);
369 370
			}
		}
371 372 373 374 375 376
	}

	if (sourceTreeNode.ExpandAfterBuild == true) {
	    // Add node to expand after build treeview
	    targetTreeView.ExpandNodes.push(sourceTreeNode.Id);
	}
377

378 379 380 381 382 383 384 385
	/*$("#" + targetTreeView.Id).treeview({
	    add: branches
	});*/
};
// Add item
function AddItem(targetTreeView, sourceTreeNodeItem, targetTreeNode, callbackFunction) {
	var branches;
	var scriptCallback = "";
386
	var tmpClass = JQ_TREEVIEW.CLASS_FILE;
387 388

	if (callbackFunction != undefined && callbackFunction != null) {
389 390 391 392 393 394 395 396
		scriptCallback += ' id="' + sourceTreeNodeItem.Id + '"';
		scriptCallback += ' onclick="';
		//scriptCallback += "var currNode = new TreeNode(); currNode.Id = '" + sourceTreeNodeItem.Id + "'; currNode.Text = '" + sourceTreeNodeItem.Text + "';";
		scriptCallback += "var currNode = new TreeNode(); currNode.Id = '" + sourceTreeNodeItem.Id + "';";
		scriptCallback += "currNode.Value = '" + sourceTreeNodeItem.Value + "'; currNode.Tooltip = '" + sourceTreeNodeItem.Tooltip + "'; currNode.IsClosed = " + sourceTreeNodeItem.IsClosed + ";";
		scriptCallback += "currNode.IsCategory = " + sourceTreeNodeItem.IsCategory + ";";
		scriptCallback += callbackFunction + "(currNode);";
		scriptCallback += '"';
397 398 399 400

	}

	if (targetTreeNode != undefined && targetTreeNode != null) {
401 402 403 404 405 406
		// Nodes of root
		if (targetTreeView.IsShowTotal == true && sourceTreeNodeItem.ContentCount > 0) {
			branches = $("<li><" + targetTreeView.CategoryTagName + " class='file'" + scriptCallback + ">" + sourceTreeNodeItem.Text + "</" + targetTreeView.CategoryTagName + ">&nbsp;(" + sourceTreeNodeItem.ContentCount + ")</li>").appendTo("#" + targetTreeNode.Id);
		}
		else {
			if(sourceTreeNodeItem.ContentCount == 0){
407 408
				//#19124 インデックスのページ移動が効かなくなった対応 targetTreeView.treeViewType
				if (callbackFunction != undefined && callbackFunction != null && targetTreeView.treeViewType == "normal") {
409 410 411 412 413
					scriptCallback = ' id="' + sourceTreeNodeItem.Id + '"';
				}
				tmpClass = JQ_TREEVIEW.CLASS_FILE_ZERO;
			}
			branches = $("<li><" + targetTreeView.CategoryTagName + " class='" + tmpClass + "'" + scriptCallback + ">" + sourceTreeNodeItem.Text + "</" + targetTreeView.CategoryTagName + ">&nbsp;</li>").appendTo("#" + targetTreeNode.Id);
414 415 416
	    }
	}
	else {
417 418 419 420 421 422
		if (sourceTreeNodeItem.Id == "all") {  // All nodes
			if (targetTreeView.IsShowTotal == true && targetTreeView.TotalCount > 0) {
				branches = $("<li><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='file lang root' lang='txtAll'" + scriptCallback + ">" + sourceTreeNodeItem.Text + "</" + targetTreeView.CategoryTagName + ">&nbsp;(" + targetTreeView.TotalCount + ")</li>").appendTo("#" + targetTreeView.Id);
			}
			else {
				if(targetTreeView.TotalCount == 0){
423 424
					//#19124 インデックスのページ移動が効かなくなった対応 targetTreeView.treeViewType
					if (callbackFunction != undefined && callbackFunction != null && targetTreeView.treeViewType == "normal") {
425 426 427 428 429 430 431 432
						scriptCallback = ' id="' + sourceTreeNodeItem.Id + '"';
					}
					tmpClass = JQ_TREEVIEW.CLASS_FILE_ZERO;
				}
				branches = $("<li><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='" + tmpClass + " lang root' lang='txtAll'" + scriptCallback + ">" + sourceTreeNodeItem.Text + "</" + targetTreeView.CategoryTagName + "></li>").appendTo("#" + targetTreeView.Id);
			}
		}
		else {  // Node of root but not be "all node"
433
			if (targetTreeView.IsShowTotal == true && sourceTreeNodeItem.ContentCount > 0) {
434 435 436
				branches = $("<li><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='file'" + scriptCallback + ">" + sourceTreeNodeItem.Text + "</" + targetTreeView.CategoryTagName + ">&nbsp;(" + sourceTreeNodeItem.ContentCount + ")</li>").appendTo("#" + targetTreeView.Id);
			}
			else {
437
				if(sourceTreeNodeItem.ContentCount == 0){
438 439
					//#19124 インデックスのページ移動が効かなくなった対応 targetTreeView.treeViewType
					if (callbackFunction != undefined && callbackFunction != null && targetTreeView.treeViewType == "normal") {
440 441 442 443 444 445 446
						scriptCallback = ' id="' + sourceTreeNodeItem.Id + '"';
					}
					tmpClass = JQ_TREEVIEW.CLASS_FILE_ZERO;
				}
				branches = $("<li><" + targetTreeView.CategoryTagName + " style='padding-left: 5px;' class='" + tmpClass + "'" + scriptCallback + ">" + sourceTreeNodeItem.Text + "</" + targetTreeView.CategoryTagName + "></li>").appendTo("#" + targetTreeView.Id);
			}
		}
447
	}
448

449 450 451 452 453 454 455 456 457
	/*$("#" + targetTreeView.Id).treeview({
	    add: branches
	});*/
};

// Add node loopback
function AddChildNode(tree, parenTreeNode, childDataNode, callbackFunctionName) {

    if (childDataNode.IsCategory) {
458

459 460 461 462 463 464 465
	    // Count contents of childs
	    childDataNode.ChildsCount = Number(childDataNode.ContentCount) + CountChilds(childDataNode.ChildNodes);
	    if (childDataNode.ChildsCount > 0) {
            // Set unique id
	        childDataNode.Id += nodeId++;

	        if (childDataNode.ChildsCount != childDataNode.ContentCount) {
466

467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497
	            // Add category
	            AddCategory(tree, childDataNode, parenTreeNode, callbackFunctionName);
	            if (childDataNode.ChildNodes.length > 0) {
	                for (var nIndex = 0; nIndex < childDataNode.ChildNodes.length; nIndex++) {
	                    // Call loop back
	                    AddChildNode(tree, childDataNode, childDataNode.ChildNodes[nIndex], callbackFunctionName);
	                }
	            }
	        }
	        else {
                // Add as item
	            childDataNode.IsCategory = false;
	            AddItem(tree, childDataNode, parenTreeNode, callbackFunctionName);
	        }
	    }
	}
	else {
	    if (childDataNode.ContentCount > 0) {
	        // Set unique id
	        childDataNode.Id += nodeId++;

            // Add single item
	        AddItem(tree, childDataNode, parenTreeNode, callbackFunctionName);
	    }
	}
};

// Add node loopback
function AddChildNodeIndex(tree, parenTreeNode, childDataNode, callbackFunctionName) {

    if (childDataNode.IsCategory) {
498

499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530
        // Set unique id
        childDataNode.Id += nodeId++;


        if (childDataNode.ChildNodes.length > 0) {
            // Add category
            AddCategory(tree, childDataNode, parenTreeNode, callbackFunctionName);

            for (var nIndex = 0; nIndex < childDataNode.ChildNodes.length; nIndex++) {
                // Call loop back
                AddChildNodeIndex(tree, childDataNode, childDataNode.ChildNodes[nIndex], callbackFunctionName);
            }
        }
        else {
            // Add as item
            childDataNode.IsCategory = false;
            AddItem(tree, childDataNode, parenTreeNode, callbackFunctionName);
        }
	}
	else {
        // Set unique id
        childDataNode.Id += nodeId++;

        // Add single item
        AddItem(tree, childDataNode, parenTreeNode, callbackFunctionName);
	}
};

/*
  Calculate childs count
*/
function CountChilds(nodes) {
531

532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555
    var nTotal = 0;
    if (nodes) {
        for (var nIndex = 0; nIndex < nodes.length; nIndex++) {
            // Count current node
            nTotal += Number(nodes[nIndex].ContentCount);
            // Continue to count childs
            if (nodes[nIndex].ChildNodes) {
                nTotal += CountChilds(nodes[nIndex].ChildNodes);
            }
        }
    }

    return nTotal;
};


function TreeView() {
    var currDate = new Date();
    this.Id = "treeview" + currDate.toIdString();
    this.Nodes = new Array();
    this.TotalCount = 0;
    this.IsShowTotal = true;
    this.ExpandNodes = [];
    this.CategoryTagName = "span";  // Use to expand/ not expand when clicking in
556
    this.treeViewType = "normal"; //#19124 コンテンツ閲覧のインデックスでページ移動しなくなった対応のため
557 558 559 560
    this.Show = function (containerId, nodes, callbackFunctionName) {
        var tree = this;
        tree.Id = containerId;
        var newItem = new TreeNode();
561
        newItem.Text = I18N.i18nText('txtAll');
562 563 564
        newItem.Id = "all";
        newItem.IsCategory = false;
        newItem.ContentCount = this.TotalCount;
565

566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
        AddItem(tree, newItem, null, callbackFunctionName);

        if (nodes != undefined && nodes != null) {
            for (var nIndex = 0; nIndex < nodes.length; nIndex++) {
            	//alert(tree.IsShowTotal);
                if (tree.IsShowTotal == true) {
                	AddChildNode(tree, null, nodes[nIndex], callbackFunctionName);
                }
                else {
                	AddChildNodeIndex(tree, null, nodes[nIndex], callbackFunctionName);
                }
            }
        }
    };
};

function TreeViewIndex() {
   var currDate = new Date();
    this.Id = "treeview" + currDate.toIdString();
    this.Nodes = new Array();
    this.TotalCount = 0;
    this.IsShowTotal = true;
    this.CategoryTagName = "span";
589
    this.treeViewType = "index"; //#19124  コンテンツ閲覧のインデックスでページ移動しなくなった対応のため
590 591
    this.Show = function (containerId, nodes, callbackFunctionName) {
        var tree = this;
592
        tree.Id = containerId;
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609

        if (nodes != undefined && nodes != null) {
            for (var nIndex = 0; nIndex < nodes.length; nIndex++) {
            	//alert(tree.IsShowTotal);
                if (tree.IsShowTotal) {
                	AddChildNode(tree, null, nodes[nIndex], callbackFunctionName);
                }
                else {
                	AddChildNodeIndex(tree, null, nodes[nIndex], callbackFunctionName);
                }
            }
        }
    };
};
// ====================================================
// Function for treeview [ end ]
// ====================================================