diff options
| author | Zaran <zaran.krleza@gmail.com> | 2012-05-06 18:51:04 -0700 |
|---|---|---|
| committer | Zaran <zaran.krleza@gmail.com> | 2012-05-06 18:51:04 -0700 |
| commit | 1a855dc54caa5ef70149718a69f7bfdc14f79469 (patch) | |
| tree | 746e241e5077d70694e53c457b4d8d1cd4ba83f7 /alias-angular/app/lib/jquery.forms.js | |
| parent | 12bfb29d647c9750a0a773ed406f48e085099a01 (diff) | |
| download | alias-1a855dc54caa5ef70149718a69f7bfdc14f79469.tar.gz | |
More work on the registration
Diffstat (limited to 'alias-angular/app/lib/jquery.forms.js')
| -rw-r--r-- | alias-angular/app/lib/jquery.forms.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/alias-angular/app/lib/jquery.forms.js b/alias-angular/app/lib/jquery.forms.js new file mode 100644 index 0000000..1912729 --- /dev/null +++ b/alias-angular/app/lib/jquery.forms.js @@ -0,0 +1,73 @@ +/** + * Rendering of an xmpp form as an html form + * See http://xmpp.org/extensions/xep-0004.html + */ +(function( $ ){ + + var methods = { + + render: function(){ + var result = $('<form></form>'); + if ( this.find('title').length !== 0 ){ + result.append('<p class="title">' + this.find('title') + '</p>'); + } + + if ( this.find('instructions').length !== 0 ){ + result.append('<p class="instructions">' + + this.find('instructions') + '</p>'); + } + + this.find('field').each(function(index){ + var type = $(this).attr("type"); + var name = $(this).attr("var"); + var required = $(this).find('required').length !== 0; + + if ( $(this).find('desc').length !== 0 ){ + result.append('<p class="description">' + + $(this).find('desc').text() + + '</p>'); + } + + if ( $(this).attr('label') !== undefined ){ + result.append('<label for="form-' + name + '">' + + $(this).attr('label') + + (required ? ' (*): ' : ': ') + + '</label>'); + } + + switch(type){ + case("text-single"): + var input = $('<input/>'); + input.attr('type', 'text'); + input.attr('name', name); + input.attr('id', 'form-' + name); + + if ( $(this).find('value').length !== 0 ){ + input.attr('value', $(this).find('value').text()); + } + result.append(input); + result.append('<br/>'); + } + }); + return result; + } + }; + + /* + * Register the 'xmppForm' method to the jQuery objects + * the first argument of this method is the submethod + * you want to call + */ + $.fn.xmppForm = function(method) { + if ( methods[method] ) { + return methods[method].apply(this, Array.prototype.slice + .call(arguments, 1)); + } else if ( typeof method === 'object' || !method ) { + return methods.init.apply(this, arguments); + } else { + $.error('Method ' + method + ' does not exist on jQuery.xmppForm'); + } + }; + +})(jQuery); + |
