Advertisement
Guest User

Alternative Text

a guest
May 14th, 2011
2,596
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //Submitting an alternative text
  2. //This scans for all the images on the pages and checks if an alternative text is present or not. If not, one can enter and submit the alternative text.
  3.  
  4. $(function() {
  5.  
  6.   $('body').append('<div id="dialog-form" />');
  7.  
  8.   $('#dialog-form').append('<p>Add an alternative text for the image</p>');
  9.   $('#dialog-form').append('<form></form>');
  10.   $('#dialog-form form').append('<input type="text" value="" name="farfalla-addalt" />');
  11.  
  12.   $.each($('img'), function() {
  13.        
  14.         if($(this).parent()!='a') {
  15.  
  16.             $(this).wrap('<div class="farfalla_addalt ui-corner-all" />');         
  17.  
  18.         } else {
  19.            
  20.             $(this).parent().wrap('<div class="farfalla_addalt ui-corner-all" />');            
  21.            
  22.         };
  23.            
  24.         if($(this).attr('alt')==""){
  25.            
  26.             $(this).parent('div')
  27.                 .addClass('ui-state-error')
  28.                 .width($(this).width())
  29.                 .append('<div class="addalt_overlay ui-state-error" style="display:none"><p><span class="ui-icon ui-icon-alert" style="float: left; margin-right: .3em;"></span>This image has no alternative text! Click here to add...</p></div>');
  30.  
  31.         } else {
  32.  
  33.             $(this).parent('div')
  34.                 .width($(this).width())
  35.                 .append('<div class="addalt_overlay" style="display:none"><p>'+$(this).attr('alt')+'</p></div>');      
  36.        
  37.         }
  38.  
  39.     }
  40.    
  41.   );
  42.  
  43.  
  44.     $('.addalt_overlay').click(
  45.         function(){
  46.             $('#dialog-form').dialog('open');  
  47.     });
  48.  
  49.   $.each($('.farfalla_addalt'), function() {
  50.  
  51.     $(this).hover(
  52.         function(){
  53.             $(this).children('div').show(300);
  54.         },
  55.         function(){
  56.             $(this).children('div').hide(300);
  57.         });
  58.  
  59.     });
  60.  
  61.         $( "#dialog-form" ).dialog({
  62.             autoOpen: false,
  63.             height: 300,
  64.             width: 350,
  65.             modal: true,
  66.             buttons: {
  67.                 "Send your proposal": function() {
  68.  
  69.                     var bValid = true;
  70.  
  71.                     allFields.removeClass( "ui-state-error" );
  72.  
  73. /*
  74.                     bValid = bValid && checkLength( name, "username", 3, 16 );
  75.                     bValid = bValid && checkLength( email, "email", 6, 80 );
  76.                     bValid = bValid && checkLength( password, "password", 5, 16 );
  77. */
  78.  
  79. /*
  80.                     bValid = bValid && checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
  81.                     // From jquery.validate.js (by joern), contributed by Scott Gonzalez: http://projects.scottsplayground.com/email_address_validation/
  82.                     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" );
  83.                     bValid = bValid && checkRegexp( password, /^([0-9a-zA-Z])+$/, "Password field only allow : a-z 0-9" );
  84. */
  85.  
  86.  
  87.                     if ( bValid ) {
  88.                         $( "#users tbody" ).append( "<tr>" +
  89.                             "<td>" + name.val() + "</td>" +
  90.                             "<td>" + email.val() + "</td>" +
  91.                             "<td>" + password.val() + "</td>" +
  92.                         "</tr>" );
  93.                         $( this ).dialog( "close" );
  94.                     }
  95.  
  96.                 },
  97.                 Cancel: function() {
  98.                     $( this ).dialog( "close" );
  99.                 }
  100.             },
  101.             close: function() {
  102.                 allFields.val( "" ).removeClass( "ui-state-error" );
  103.             }
  104.         });
  105.  
  106.  
  107.  
  108. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement