Advertisement
pickledegg

Untitled

Jan 23rd, 2013
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
jQuery 1.07 KB | None | 0 0
  1. ;(function($){
  2.    
  3.     var defaults = {
  4.         question: "Which is your favourite Javascript library?",
  5.         url: "",
  6.         buttonText: "Answer!",
  7.         categories: ["jQuery", "YUI", "Dojo", "ExtJS", "Zepto"]
  8.     }
  9.  
  10.     function Nupoll(element,options){
  11.        
  12.         this.config = $.extend({}, defaults, options);
  13.         this.element = element;
  14.         this.init();
  15.     }
  16.  
  17.  
  18.     Nupoll.prototype.init = function(){
  19.  
  20.         $("<h1/>",{
  21.                 text: this.config.question
  22.             }).appendTo(this.element);
  23.        
  24.             var form  = $("<form/>").appendTo(this.element);
  25.             var x, y;
  26.  
  27.             for (x = 0, y = this.config.categories.length; x < y; x++){
  28.                 $("<input/>",{
  29.                     type: "radio",
  30.                     name: "categories",
  31.                     id: this.config.categories[x],
  32.                     value: this.config.categories[x]
  33.                 }).appendTo(form);
  34.  
  35.                 $("<label/>",{
  36.                     text: this.config.categories[x],
  37.                     "for" : this.config.categories[x]
  38.                 }).appendTo(form);
  39.             }
  40.             $("<button/>",{
  41.                 text: this.config.buttonText
  42.             }).appendTo(form);
  43.     }
  44.  
  45.     $.fn.nupoll = function(options){
  46.         new Nupoll(this.first(),options);
  47.         return this.first;
  48.     };
  49.    
  50. }(jQuery));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement