Created
September 25, 2011 18:13
-
-
Save thilo/1240916 to your computer and use it in GitHub Desktop.
A Singleton UI Widget. I wonder if this is a sane approach?
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
// a ui dialog that can only appear one at a time uses jquery dialog | |
Widgets.UI = function() { | |
//gather the dom elements that made up the UI | |
var dialog = $('#dialog'), | |
linkTargetField = dialog.find("#link-target"), | |
saveBotton = dialog.find('#save'), | |
//changing state | |
node = undefined; | |
//event handler | |
saveBotton.click(function() { | |
node.attr('href', linkTargetField.val()); | |
dialog.dialog('close') | |
}); | |
// singleton to set state and open dialog. | |
return Widgets.UI || function($node) { | |
linkTargetField.val($node.attr('href')); | |
node = $node; | |
dialog.dialog({modal: true}); | |
} | |
//calling initialization directly | |
}(); | |
//usage | |
Widgets.UI($("#link")); |
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
<div id="dialog" style="display:none"> | |
<label for="link-target">Link URL</label> | |
<input type="text" id="link-target" placeholder="http://example.com/"> | |
<input type="button" value="Done" id="save"> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment