From 1a855dc54caa5ef70149718a69f7bfdc14f79469 Mon Sep 17 00:00:00 2001 From: Zaran Date: Sun, 6 May 2012 18:51:04 -0700 Subject: More work on the registration --- alias-angular/app/lib/jquery.forms.js | 73 +++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 alias-angular/app/lib/jquery.forms.js (limited to 'alias-angular/app/lib/jquery.forms.js') 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 = $('
'); + if ( this.find('title').length !== 0 ){ + result.append('

' + this.find('title') + '

'); + } + + if ( this.find('instructions').length !== 0 ){ + result.append('

' + + this.find('instructions') + '

'); + } + + 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('

' + + $(this).find('desc').text() + + '

'); + } + + if ( $(this).attr('label') !== undefined ){ + result.append(''); + } + + switch(type){ + case("text-single"): + var 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('
'); + } + }); + 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); + -- cgit v1.2.3-70-g09d2