Created
July 30, 2010 23:14
-
-
Save imathis/501480 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| %a(href="#" toggles="#advanced_search, #simple_search") Advanced Search |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var FS = FS || {}; | |
| FS.Toggler = Class.create({ | |
| options: { | |
| trigger: 'a[toggles]' | |
| }, | |
| initialize: function(options){ | |
| this.options = $H(this.options).merge($H(options)); | |
| var elements = $$(this.options.get('trigger')); | |
| elements.each(function(el){ | |
| el.observe('click', function(event){event.stop(); this.click(el);}.bind(this)); | |
| el.store('toggle-elements', this.getElementsFromString(el.readAttribute('toggles'))); | |
| }.bind(this)) | |
| }, | |
| click: function(el){ | |
| el.retrieve('toggle-elements').invoke('toggle'); | |
| }, | |
| getElementsFromString: function(elementString){ | |
| return elementString.split(',').map(function(str){ | |
| str = str.strip(); | |
| return (str.include(".") || str.include(" ") ? $$(str) : $(str.replace('#', ''))) | |
| }).flatten(); | |
| } | |
| }); | |
| document.observe("dom:loaded", function() { | |
| new FS.Toggler(); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment