| [1602] | 1 | var dotclear = {}; |
|---|
| 2 | dotclear.img_plus_src = '../../admin/images/expand.png'; |
|---|
| 3 | dotclear.img_plus_alt = 'uncover'; |
|---|
| 4 | dotclear.img_minus_src = '../../admin/images/hide.png'; |
|---|
| 5 | dotclear.img_minus_alt = 'hide'; |
|---|
| 6 | |
|---|
| 7 | jQuery.fn.toggleWithLegend = function(target,s) { |
|---|
| 8 | var defaults = { |
|---|
| 9 | img_on_src: dotclear.img_plus_src, |
|---|
| 10 | img_on_alt: dotclear.img_plus_alt, |
|---|
| 11 | img_off_src: dotclear.img_minus_src, |
|---|
| 12 | img_off_alt: dotclear.img_minus_alt, |
|---|
| 13 | hide: true, |
|---|
| 14 | speed: 0, |
|---|
| 15 | legend_click: false, |
|---|
| 16 | fn: false, // A function called on first display, |
|---|
| 17 | cookie: false, |
|---|
| 18 | reverse_cookie: false // Reverse cookie behavior |
|---|
| 19 | }; |
|---|
| 20 | var p = jQuery.extend(defaults,s); |
|---|
| 21 | |
|---|
| 22 | if (!target) { return this; } |
|---|
| 23 | |
|---|
| 24 | var set_cookie = p.hide ^ p.reverse_cookie; |
|---|
| 25 | if (p.cookie && jQuery.cookie(p.cookie)) { |
|---|
| 26 | p.hide = p.reverse_cookie; |
|---|
| 27 | } |
|---|
| 28 | |
|---|
| 29 | var toggle = function(i,speed) { |
|---|
| 30 | speed = speed || 0; |
|---|
| 31 | if (p.hide) { |
|---|
| 32 | $(i).get(0).src = p.img_on_src; |
|---|
| 33 | $(i).get(0).alt = p.img_on_alt; |
|---|
| 34 | target.hide(speed); |
|---|
| 35 | } else { |
|---|
| 36 | $(i).get(0).src = p.img_off_src; |
|---|
| 37 | $(i).get(0).alt = p.img_off_alt; |
|---|
| 38 | target.show(speed); |
|---|
| 39 | if (p.fn) { |
|---|
| 40 | p.fn.apply(target); |
|---|
| 41 | p.fn = false; |
|---|
| 42 | } |
|---|
| 43 | } |
|---|
| 44 | |
|---|
| 45 | if (p.cookie && set_cookie) { |
|---|
| 46 | if (p.hide ^ p.reverse_cookie) { |
|---|
| 47 | jQuery.cookie(p.cookie,'',{expires: -1}); |
|---|
| 48 | } else { |
|---|
| 49 | jQuery.cookie(p.cookie,1,{expires: 30}); |
|---|
| 50 | } |
|---|
| 51 | } |
|---|
| 52 | |
|---|
| 53 | p.hide = !p.hide; |
|---|
| 54 | }; |
|---|
| 55 | |
|---|
| 56 | return this.each(function() { |
|---|
| 57 | var i = document.createElement('img'); |
|---|
| 58 | i.src = p.img_off_src; |
|---|
| 59 | i.alt = p.img_off_alt; |
|---|
| 60 | var a = document.createElement('a'); |
|---|
| 61 | a.href= '#'; |
|---|
| 62 | $(a).append(i); |
|---|
| 63 | $(a).css({ |
|---|
| 64 | border: 'none', |
|---|
| 65 | outline: 'none' |
|---|
| 66 | }); |
|---|
| 67 | |
|---|
| 68 | var ctarget = p.legend_click ? this : a; |
|---|
| 69 | |
|---|
| 70 | $(ctarget).css('cursor','pointer'); |
|---|
| 71 | if (p.legend_click) { |
|---|
| 72 | $(ctarget).find('label').css('cursor','pointer'); |
|---|
| 73 | } |
|---|
| 74 | $(ctarget).click(function() { |
|---|
| 75 | toggle(i,p.speed); |
|---|
| 76 | return false; |
|---|
| 77 | }); |
|---|
| 78 | |
|---|
| 79 | |
|---|
| 80 | toggle($(i).get(0)); |
|---|
| 81 | $(this).prepend(' ').prepend(a); |
|---|
| 82 | }); |
|---|
| 83 | }; |
|---|