Project

General

Profile

Download (2.36 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2

    
3
/** 
4
 * Copyright (C) 2007 EDIT
5
 * European Distributed Institute of Taxonomy
6
 * http://www.e-taxonomy.eu
7
 *
8
 * The contents of this file are subject to the Mozilla Public License Version 1.1
9
 * See LICENSE.TXT at the top of this package for the full license terms.
10
 */
11

    
12
(function($){
13
 /**
14
  * 
15
  */
16
  $.fn.cdm_taxontree_widget = function(options) {
17
		
18
		var opts = $.extend({},$.fn.cdm_taxontree_widget.defaults, options);
19
		
20
		return this.each(function() {
21
		  
22
		  // init taxontree
23
		  $(this).find('ul.cdm_taxontree').cdm_taxontree(true, options);
24

    
25
		  var widget = $(this);
26
		  var optionList = $('.cdm_taxontree_widget select');
27
		  	  	  
28
		  bind_select_click(optionList, $(this).find('ul.cdm_taxontree'), opts.multiselect);
29
		  	  	  
30
			/*$(this).find('ul.cdm_taxontree li .widget_select').click(function(event){
31
		    event.stopPropagation();
32
		    var value = $(this).attr('title');
33
        if(select.children('[value='+value+']').length > 0){
34
          // remove from select
35
          select.children('[value='+value+']').remove();
36
        } else {
37
         // add to select
38
         if(!opts.multiselect){
39
           // remove all from select
40
           select.children().remove();
41
         }
42
         select.append('<option value="'+value+'" selected="selected">'+value+'</option>')
43
        }
44
			 }); // END click()
45
			 */
46
		}); // END each(		
47
	}; // END cdm_taxontree_widget() 
48
		 
49
	function bind_select_click(optionList, treelist, isMultiselect){
50
	 
51
	   treelist.find('li .widget_select').click(function(event){
52
        event.stopPropagation();
53
        var value = $(this).attr('title');
54
        if(optionList.children('[value='+value+']').length > 0){
55
          // remove from select
56
          optionList.children('[value='+value+']').remove();
57
        } else {
58
         // add to select
59
         if(!isMultiselect){
60
           // remove all from select
61
           optionList.children().remove();
62
         }
63
         optionList.append('<option value="'+value+'" selected="selected">'+value+'</option>')
64
        }
65
       });
66
	 
67
	} // END bind_select_click()
68
	 
69
})(jQuery);
70

    
71
$.fn.cdm_taxontree_widget.defaults = {  // set up default options
72
	element_name:           'widgetval',  // 
73
	multiselect:            false,        //
74
};
75

    
76
//$(document).ready(function() {$('.cdm_taxontree_widget').cdm_taxontree_widget();});
(2-2/6)