Вход Регистрация
Файл: includes/jquery/treeview/jquery.treeview.js
Строк: 282
<?php
/*
 * Treeview 1.4 - jQuery plugin to hide and show branches of a tree
 * 
 * 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 4684 2008-02-07 19:08:06Z joern.zaefferer $
 *
 */

;(function($) {

    $.
extend($.fn, {
        
swapClass: function(c1c2) {
            var 
c1Elements this.filter('.' c1);
            
this.filter('.' c2).removeClass(c2).addClass(c1);
            
c1Elements.removeClass(c1).addClass(c2);
            return 
this;
        },
        
replaceClass: function(c1c2) {
            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(animatedcallback) {
            
animated ?
                
this.animate({ height"toggle" }, animatedcallback) :
                
this.each(function(){
                    
jQuery(this)[ jQuery(this).is(":hidden") ? "show" "hide" ]();
                    if(
callback)
                        
callback.apply(thisarguments);
                });
        },
        
heightHide: function(animatedcallback) {
            if (
animated) {
                
this.animate({ height"hide" }, animatedcallback);
            } else {
                
this.hide();
                if (
callback)
                    
this.each(callback);                
            }
        },
        
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(settingstoggler) {
            
this.filter(":has(>ul):not(:has(>a))").find(">span").click(function(event) {
                
toggler.apply($(this).next());
            }).
add( $("a"this) ).hoverClass();
            
            if (!
settings.prerendered) {
                
// handle closed ones first
                
this.filter(":has(>ul:hidden)")
                        .
addClass(CLASSES.expandable)
                        .
replaceClass(CLASSES.lastCLASSES.lastExpandable);
                        
                
// handle open ones
                
this.not(":has(>ul:hidden)")
                        .
addClass(CLASSES.collapsable)
                        .
replaceClass(CLASSES.lastCLASSES.lastCollapsable);
                        
                
// create hitarea
                
this.prepend("<div class="" + CLASSES.hitarea + ""/>").find("div." CLASSES.hitarea).each(function() {
                    var 
classes "";
                    $.
each($(this).parent().attr("class").split(" "), function() {
                        
classes += this "-hitarea ";
                    });
                    $(
this).addClassclasses );
                });
            }
            
            
// apply event to hitarea
            
this.find("div." CLASSES.hitarea).clicktoggler );
        },
        
treeview: function(settings) {
            
            
settings = $.extend({
                
cookieId"treeview"
            
}, settings);
            
            if (
settings.add) {
                return 
this.trigger("add", [settings.add]);
            }
            
            if ( 
settings.toggle ) {
                var 
callback settings.toggle;
                
settings.toggle = function() {
                    return 
callback.apply($(this).parent()[0], arguments);
                };
            }
        
            
// factory for treecontroller
            
function treeController(treecontrol) {
                
// 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.hitareatree).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).clickhandler(CLASSES.collapsable) );
                
// click on second to expand tree
                
$("a:eq(1)"control).clickhandler(CLASSES.expandable) );
                
// click on third to toggle tree
                
$("a:eq(2)"control).clickhandler() ); 
            }
        
            
// handle toggle event
            
function toggler() {
                $(
this)
                    .
parent()
                    
// swap classes for hitarea
                    
.find(">.hitarea")
                        .
swapClassCLASSES.collapsableHitareaCLASSES.expandableHitarea )
                        .
swapClassCLASSES.lastCollapsableHitareaCLASSES.lastExpandableHitarea )
                    .
end()
                    
// swap classes for parent li
                    
.swapClassCLASSES.collapsableCLASSES.expandable )
                    .
swapClassCLASSES.lastCollapsableCLASSES.lastExpandable )
                    
// find child lists
                    
.find">ul" )
                    
// toggle them
                    
.heightTogglesettings.animatedsettings.toggle );
                if ( 
settings.unique ) {
                    $(
this).parent()
                        .
siblings()
                        
// swap classes for hitarea
                        
.find(">.hitarea")
                            .
replaceClassCLASSES.collapsableHitareaCLASSES.expandableHitarea )
                            .
replaceClassCLASSES.lastCollapsableHitareaCLASSES.lastExpandableHitarea )
                        .
end()
                        .
replaceClassCLASSES.collapsableCLASSES.expandable )
                        .
replaceClassCLASSES.lastCollapsableCLASSES.lastExpandable )
                        .
find">ul" )
                        .
heightHidesettings.animatedsettings.toggle );
                }
            }
            
            function 
serialize() {
                function 
binary(arg) {
                    return 
arg 0;
                }
                var 
data = [];
                
branches.each(function(ie) {
                    
data[i] = $(e).is(":has(>ul:visible)") ? 0;
                });
                $.
cookie(settings.cookieIddata.join("") );
            }
            
            function 
deserialize() {
                var 
stored = $.cookie(settings.cookieId);
                if ( 
stored ) {
                    var 
data stored.split("");
                    
branches.each(function(ie) {
                        $(
e).find(">ul")[ parseInt(data[i]) ? "show" "hide" ]();
                    });
                }
            }
            
            
// add treeview class to activate styles
            
this.addClass("treeview");
            
            
// prepare branches and find all tree items with child lists
            
var branches this.find("li").prepareBranches(settings);
            
            switch(
settings.persist) {
            case 
"cookie":
                var 
toggleCallback settings.toggle;
                
settings.toggle = function() {
                    
serialize();
                    if (
toggleCallback) {
                        
toggleCallback.apply(thisarguments);
                    }
                };
                
deserialize();
                break;
            case 
"location":
                var 
current this.find("a").filter(function() { return this.href.toLowerCase() == location.href.toLowerCase(); });
                if ( 
current.length ) {
                    
current.addClass("selected").parents("ul, li").addcurrent.next() ).show();
                }
                break;
            }
            
            
branches.applyClasses(settingstoggler);
                
            
// if control option is set, create the treecontroller and show it
            
if ( settings.control ) {
                
treeController(thissettings.control);
                $(
settings.control).show();
            }
            
            return 
this.bind("add", function(eventbranches) {
                $(
branches).prev()
                    .
removeClass(CLASSES.last)
                    .
removeClass(CLASSES.lastCollapsable)
                    .
removeClass(CLASSES.lastExpandable)
                .
find(">.hitarea")
                    .
removeClass(CLASSES.lastCollapsableHitarea)
                    .
removeClass(CLASSES.lastExpandableHitarea);
                $(
branches).find("li").andSelf().prepareBranches(settings).applyClasses(settingstoggler);
            });
        }
    });
    
    
// classes used by the plugin
    // need to be styled via external stylesheet, see first example
    
var CLASSES = $.fn.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"
    
};
    
    
// provide backwards compability
    
$.fn.Treeview = $.fn.treeview;
    
})(
jQuery);
?>
Онлайн: 0
Реклама