Вход Регистрация
Файл: framework/web/js/source/jquery.treeview.async.js
Строк: 136
<?php
/*
 * Async Treeview 0.1 - Lazy-loading extension for Treeview
 *
 * http://bassistance.de/jquery-plugins/jquery-plugin-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$
 *
 */

;(function($) {

function 
load(settingsrootchildcontainer) {
    function 
createNode(parent) {
        var 
current = $("<li/>").attr("id"this.id || "").html("<span>" this.text "</span>").appendTo(parent);
        if (
this.classes) {
            
current.children("span").addClass(this.classes);
        }
        if (
this.expanded) {
            
current.addClass("open");
        }
        if (
this.hasChildren || this.children && this.children.length) {
            var 
branch = $("<ul/>").appendTo(current);
            if (
this.hasChildren) {
                
current.addClass("hasChildren");
                
createNode.call({
                    
classes"placeholder",
                    
text"&nbsp;",
                    
children:[]
                }, 
branch);
            }
            if (
this.children && this.children.length) {
                $.
each(this.childrencreateNode, [branch])
            }
        }
    }
    $.
ajax($.extend(true, {
        
urlsettings.url,
        
dataType"json",
        
data: {
            
rootroot
        
},
        
success: function(response) {
            
child.empty();
            $.
each(responsecreateNode, [child]);
            $(
container).treeview({addchild});
        }
    }, 
settings.ajax));
    
/*
    $.getJSON(settings.url, {root: root}, function(response) {
        function createNode(parent) {
            var current = $("<li/>").attr("id", this.id || "").html("<span>" + this.text + "</span>").appendTo(parent);
            if (this.classes) {
                current.children("span").addClass(this.classes);
            }
            if (this.expanded) {
                current.addClass("open");
            }
            if (this.hasChildren || this.children && this.children.length) {
                var branch = $("<ul/>").appendTo(current);
                if (this.hasChildren) {
                    current.addClass("hasChildren");
                    createNode.call({
                        classes: "placeholder",
                        text: "&nbsp;",
                        children:[]
                    }, branch);
                }
                if (this.children && this.children.length) {
                    $.each(this.children, createNode, [branch])
                }
            }
        }
        child.empty();
        $.each(response, createNode, [child]);
        $(container).treeview({add: child});
    });
    */
}

var 
proxied = $.fn.treeview;
$.fn.
treeview = function(settings) {
    if (!
settings.url) {
        return 
proxied.apply(thisarguments);
    }
    var 
container this;
    if (!
container.children().size())
        
load(settings"source"thiscontainer);
    var 
userToggle settings.toggle;
    return 
proxied.call(this, $.extend({}, settings, {
        
collapsedtrue,
        
toggle: function() {
            var 
$this = $(this);
            if (
$this.hasClass("hasChildren")) {
                var 
childList $this.removeClass("hasChildren").find("ul");
                
load(settingsthis.idchildListcontainer);
            }
            if (
userToggle) {
                
userToggle.apply(thisarguments);
            }
        }
    }));
};

})(
jQuery);
?>
Онлайн: 0
Реклама