| 1 | <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> |
|---|
| 2 | <html> |
|---|
| 3 | |
|---|
| 4 | <head> |
|---|
| 5 | |
|---|
| 6 | <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script> |
|---|
| 7 | <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/jquery-ui.min.js" type="text/javascript"></script> |
|---|
| 8 | |
|---|
| 9 | <style type="text/css"> |
|---|
| 10 | body { font-size: 62.5%; } |
|---|
| 11 | label, input { display:block; } |
|---|
| 12 | input.text { margin-bottom:12px; width:95%; padding: .4em; } |
|---|
| 13 | fieldset { padding:0; border:0; margin-top:25px; } |
|---|
| 14 | h1 { font-size: 1.2em; margin: .6em 0; } |
|---|
| 15 | div#users-contain { width: 350px; margin: 20px 0; } |
|---|
| 16 | div#users-contain table { margin: 1em 0; border-collapse: collapse; width: 100%; } |
|---|
| 17 | div#users-contain table td, div#users-contain table th { border: 1px solid #eee; padding: .6em 10px; text-align: left; } |
|---|
| 18 | .ui-button { outline: 0; margin:0; padding: .4em 1em .5em; text-decoration:none; !important; cursor:pointer; position: relative; text-align: center; } |
|---|
| 19 | .ui-dialog .ui-state-highlight, .ui-dialog .ui-state-error { padding: .3em; } |
|---|
| 20 | |
|---|
| 21 | |
|---|
| 22 | </style> |
|---|
| 23 | <script type="text/javascript"> |
|---|
| 24 | $(function() { |
|---|
| 25 | |
|---|
| 26 | var name = $("#name"), |
|---|
| 27 | email = $("#email"), |
|---|
| 28 | password = $("#password"), |
|---|
| 29 | allFields = $([]).add(name).add(email).add(password), |
|---|
| 30 | tips = $("#validateTips"); |
|---|
| 31 | |
|---|
| 32 | function updateTips(t) { |
|---|
| 33 | tips.text(t).effect("highlight",{},1500); |
|---|
| 34 | } |
|---|
| 35 | |
|---|
| 36 | function checkLength(o,n,min,max) { |
|---|
| 37 | |
|---|
| 38 | if ( o.val().length > max || o.val().length < min ) { |
|---|
| 39 | o.addClass('ui-state-error'); |
|---|
| 40 | updateTips("Length of " + n + " must be between "+min+" and "+max+"."); |
|---|
| 41 | return false; |
|---|
| 42 | } else { |
|---|
| 43 | return true; |
|---|
| 44 | } |
|---|
| 45 | |
|---|
| 46 | } |
|---|
| 47 | |
|---|
| 48 | function checkRegexp(o,regexp,n) { |
|---|
| 49 | |
|---|
| 50 | if ( !( regexp.test( o.val() ) ) ) { |
|---|
| 51 | o.addClass('ui-state-error'); |
|---|
| 52 | updateTips(n); |
|---|
| 53 | return false; |
|---|
| 54 | } else { |
|---|
| 55 | return true; |
|---|
| 56 | } |
|---|
| 57 | |
|---|
| 58 | } |
|---|
| 59 | |
|---|
| 60 | $("#dialog").dialog({ |
|---|
| 61 | bgiframe: true, |
|---|
| 62 | autoOpen: false, |
|---|
| 63 | height: 300, |
|---|
| 64 | modal: true, |
|---|
| 65 | buttons: { |
|---|
| 66 | 'Create an account': function() { |
|---|
| 67 | var bValid = true; |
|---|
| 68 | allFields.removeClass('ui-state-error'); |
|---|
| 69 | |
|---|
| 70 | bValid = bValid && checkLength(name,"username",3,16); |
|---|
| 71 | bValid = bValid && checkLength(email,"email",6,80); |
|---|
| 72 | bValid = bValid && checkLength(password,"password",5,16); |
|---|
| 73 | |
|---|
| 74 | bValid = bValid && checkRegexp(name,/^[a-z]([0-9a-z_])+$/i,"Username may consist of a-z, 0-9, underscores, begin with a letter."); |
|---|
| 75 | // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/ |
|---|
| 76 | bValid = bValid && checkRegexp(email,/^((([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+(\.([a-z]|\d|[!#\$%&'\*\+\-\/=\?\^_`{\|}~]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])+)*)|((\x22)((((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(([\x01-\x08\x0b\x0c\x0e-\x1f\x7f]|\x21|[\x23-\x5b]|[\x5d-\x7e]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(\\([\x01-\x09\x0b\x0c\x0d-\x7f]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))))*(((\x20|\x09)*(\x0d\x0a))?(\x20|\x09)+)?(\x22)))@((([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|\d|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.)+(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])|(([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])([a-z]|\d|-|\.|_|~|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])*([a-z]|[\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])))\.?$/i,"eg. ui@jquery.com"); |
|---|
| 77 | bValid = bValid && checkRegexp(password,/^([0-9a-zA-Z])+$/,"Password field only allow : a-z 0-9"); |
|---|
| 78 | |
|---|
| 79 | if (bValid) { |
|---|
| 80 | $('#users tbody').append('<tr>' + |
|---|
| 81 | '<td>' + name.val() + '</td>' + |
|---|
| 82 | '<td>' + email.val() + '</td>' + |
|---|
| 83 | '<td>' + password.val() + '</td>' + |
|---|
| 84 | '</tr>'); |
|---|
| 85 | $(this).dialog('close'); |
|---|
| 86 | } |
|---|
| 87 | }, |
|---|
| 88 | Cancel: function() { |
|---|
| 89 | $(this).dialog('close'); |
|---|
| 90 | } |
|---|
| 91 | }, |
|---|
| 92 | close: function() { |
|---|
| 93 | allFields.val('').removeClass('ui-state-error'); |
|---|
| 94 | } |
|---|
| 95 | }); |
|---|
| 96 | |
|---|
| 97 | |
|---|
| 98 | |
|---|
| 99 | $('#create-user').click(function() { |
|---|
| 100 | $('#dialog').dialog('open'); |
|---|
| 101 | }) |
|---|
| 102 | .hover( |
|---|
| 103 | function(){ |
|---|
| 104 | $(this).addClass("ui-state-hover"); |
|---|
| 105 | }, |
|---|
| 106 | function(){ |
|---|
| 107 | $(this).removeClass("ui-state-hover"); |
|---|
| 108 | } |
|---|
| 109 | ).mousedown(function(){ |
|---|
| 110 | $(this).addClass("ui-state-active"); |
|---|
| 111 | }) |
|---|
| 112 | .mouseup(function(){ |
|---|
| 113 | $(this).removeClass("ui-state-active"); |
|---|
| 114 | }); |
|---|
| 115 | |
|---|
| 116 | }); |
|---|
| 117 | </script> |
|---|
| 118 | |
|---|
| 119 | </head> |
|---|
| 120 | |
|---|
| 121 | <div class="demo"> |
|---|
| 122 | |
|---|
| 123 | <div id="dialog" title="Create new user"> |
|---|
| 124 | <p id="validateTips">All form fields are required.</p> |
|---|
| 125 | |
|---|
| 126 | <form> |
|---|
| 127 | <fieldset> |
|---|
| 128 | <label for="name">Name</label> |
|---|
| 129 | <input type="text" name="name" id="name" class="text ui-widget-content ui-corner-all" /> |
|---|
| 130 | <label for="email">Email</label> |
|---|
| 131 | <input type="text" name="email" id="email" value="" class="text ui-widget-content ui-corner-all" /> |
|---|
| 132 | <label for="password">Password</label> |
|---|
| 133 | <input type="password" name="password" id="password" value="" class="text ui-widget-content ui-corner-all" /> |
|---|
| 134 | </fieldset> |
|---|
| 135 | </form> |
|---|
| 136 | </div> |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | <div id="users-contain" class="ui-widget"> |
|---|
| 140 | |
|---|
| 141 | <h1>Existing Users:</h1> |
|---|
| 142 | |
|---|
| 143 | |
|---|
| 144 | <table id="users" class="ui-widget ui-widget-content"> |
|---|
| 145 | <thead> |
|---|
| 146 | <tr class="ui-widget-header "> |
|---|
| 147 | <th>Name</th> |
|---|
| 148 | <th>Email</th> |
|---|
| 149 | <th>Password</th> |
|---|
| 150 | </tr> |
|---|
| 151 | </thead> |
|---|
| 152 | <tbody> |
|---|
| 153 | <tr> |
|---|
| 154 | <td>John Doe</td> |
|---|
| 155 | <td>john.doe@example.com</td> |
|---|
| 156 | <td>johndoe1</td> |
|---|
| 157 | </tr> |
|---|
| 158 | </tbody> |
|---|
| 159 | </table> |
|---|
| 160 | </div> |
|---|
| 161 | <button id="create-user" class="ui-button ui-state-default ui-corner-all">Create new user</button> |
|---|
| 162 | |
|---|
| 163 | </div><!-- End demo --> |
|---|
| 164 | |
|---|
| 165 | <div class="demo-description"> |
|---|
| 166 | |
|---|
| 167 | <p>Use a modal dialog to require that the user enter data during a multi-step process. Embed form markup in the content area, set the <code>modal</code> option to true, and specify primary and secondary user actions with the <code>buttons</code> option.</p> |
|---|
| 168 | |
|---|
| 169 | </div><!-- End demo-description --> |
|---|
| 170 | |
|---|
| 171 | </html> |
|---|