Created
April 25, 2012 00:52
-
-
Save vitorpacheco/2485008 to your computer and use it in GitHub Desktop.
jQuery Plugins
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
| $.fn.addItems = function(data) { | |
| return this.each(function() { | |
| var list = $(this) | |
| list.empty() | |
| if (data.length != []) { | |
| $.each(data, function(index, text) { | |
| list.append("<option value="+index+">"+text+"</option>") | |
| }) | |
| } else { | |
| list.append("<option>Nenhuma opção encontrada</option>") | |
| } | |
| }) | |
| } |
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
| $.fn.changeHandler = function(options) { | |
| var opts = $.extend({}, $.fn.changeHandler.defaults, options) | |
| this.bind("change", opts, function(event) { | |
| var selected = $("option:selected", this).val() | |
| var postData = {} | |
| postData[event.data.postName] = selected | |
| $.ajax({ | |
| type: "POST", | |
| url: event.data.url, | |
| data: postData, | |
| success: function(data) { | |
| $(event.data.updateId).addItems(data) | |
| $(event.data.updateId).removeAttr('disabled') | |
| } | |
| }) | |
| return false | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment