Created
October 25, 2009 14:42
-
-
Save mrchrisadams/218091 to your computer and use it in GitHub Desktop.
This file contains 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
example_string = "http://localhost:3000/images/icons/drop_down_triangle_rollover.png" | |
// need to make | |
example_string = "http://localhost:3000/images/icons/drop_down_triangle_active_rollover.png" | |
// firebug returns this: | |
// >>> "http://localhost:3000/images/icons/drop_down_triangle_rollover.png?".replace(/((:?_rollover)?.png)/, ('_active' + $1 )) | |
// "http://localhost:3000/images/icons/drop_down_triangle_active[object HTMLDivElement]?" |
This file contains 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
ImageToggler = $.klass(Toggler, { | |
initialize: function() { | |
this.img_src = this.element.attr('src'); | |
this.active_image = this.element.attr('src').replace(/.png|_rollover.png/, '_active.png'); | |
this.normal_image = this.element.attr('src').replace(/_active/, ''); | |
}, | |
onclick: function() { | |
img = this.element.attr('src') | |
if (this.element.attr('src').match(/_active/)) { | |
this.element.attr('src', img.replace(/_active/, '')) | |
} | |
else { | |
// trying to optionally return _active_rollover.png, or _active.png, | |
this.element.attr('src', img.replace(/((_rollover)?.png)/, ('_active' + $1 ))); | |
} | |
} | |
}); |
This file contains 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
four states needed: | |
standard: | |
http://localhost:3000/images/icons/drop_down_triangle.png | |
standard rollover: | |
http://localhost:3000/images/icons/drop_down_triangle.png | |
active: | |
http://localhost:3000/images/icons/drop_down_triangle_rollover.png | |
active rollover: | |
http://localhost:3000/images/icons/drop_down_triangle_active_rollover.png |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment