Guest User

Autoexpand

a guest
Jun 2nd, 2012
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.78 KB | None | 0 0
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
  3. <head>
  4. <meta http-equiv="Content-Language" content="en" />
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <title>Autoexpand Demo - Interface plugin for jQuery</title>
  7.  
  8. <!-- Use your current version of jQuery below -->
  9. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
  10.  
  11. <!-- "Autoexpand" form "Interface Elements for jQuery" is installed here -->
  12. <script type="text/javascript" src="iexpander.js"></script>
  13.  
  14. <style type="text/css" media="all">
  15.  
  16. body{
  17. background: #fff;
  18. height: 100%;
  19. }
  20. .input1{
  21. font-family: Arial, Helvetica, sans-serif;
  22. font-size: 18pt;
  23. font-weight: bold;
  24. }
  25. .input2{
  26. font-family: "Times New Roman", Times, serif;
  27. font-size: 20px;
  28. font-style: italic;
  29. }
  30. .textarea1{
  31. font-family: Arial, Helvetica, sans-serif;
  32. font-size: 18pt;
  33. font-weight: bold;
  34. word-spacing:
  35. }
  36. .input3{
  37. font-family: "Times New Roman", Times, serif;
  38. font-size: 30px;
  39. background-color: #000000;
  40. color: #00ff00;
  41. font-style: italic;
  42. }
  43.  
  44. </style>
  45.  
  46. <script type="text/javascript">
  47. /*
  48.  
  49. An asset file has been loaded as seen in "Manage Resources" tab for jsFiddle on left panel.
  50.  
  51. The asset file is from "Interface Elements for jQuery" collection that requires no other dependencies.
  52. Visit http://interface.eyecon.ro/ and check out the Documentation section for Examples.
  53.  
  54. This particular asset file is "Autoexpand" and is a tiny 2kb in size (iexpander.js is file name).
  55. It takes into account many font related CSS that may be used and is based on .keyup and .keypress.
  56. The source file shows it takes care of "HTML pasted contents" into the input box wonderfully (e.g., removes newlines).
  57.  
  58. Best of all, it is free for private or commerical use via dual licensed (MIT license and GPL).
  59.  
  60. */
  61.  
  62.  
  63. // Below will define each item on the page with maximum width in PX. Last item also includes height.
  64. // Typically this is in jQuery Document Ready function but loading mechanism from jsFiddle is used instead.
  65. // EDIT: This version is outside jsFiddle sandbox so jQuery Document Ready IS used.
  66. // Reference: http://jsfiddle.net/yQwkL/
  67. //
  68. $(document).ready(function(){
  69.  
  70. $('.input1').Autoexpand(400);
  71. $('.input2').Autoexpand(800);
  72. $('.input3').Autoexpand(2000);
  73. $('.textarea1').Autoexpand([500, 500]);
  74.  
  75. });
  76.  
  77.  
  78. // Below is just for demo's "automatically EXPAND" and "RESET" shown on webpage.
  79. //
  80. function populateBOX(){
  81. $('.input3').attr('value','This input box has been resized automatically.').Autoexpand();
  82. }
  83.  
  84. function resetBOX(){
  85. $('.input3').attr('value','stackoverflow').Autoexpand();
  86. }
  87.  
  88. </script>
  89. </head>
  90. <body>
  91.  
  92. <p>This input box is limited to 400px in width.</p>
  93. <form action=""><input type="text" size="2" class="input1" value="limit 400px" /></form><br /><br />
  94.  
  95. <p>This input box is limited to 800px in width.</p>
  96. <form action=""><input type="text" size="2" class="input2" value="limit 800px" /></form><br /><br />
  97.  
  98. <p>This input box is limited to 500px in width and height.</p>
  99. <textarea cols="1" rows="1" class="textarea1">limit 500px and 500px</textarea><br /><br />
  100.  
  101. <p>This input box like the others above will <b>AUTOSIZE</b> up to 2000px width.</p>
  102. <form action=""><input type="text" size="2" class="input3" value="stackoverflow" style="width:50px;" /></form><br /><br />
  103.  
  104. <a href="#" onclick="populateBOX(); return false;">Click to automatically EXPAND last input box with text.</a><br /><br />
  105. <a href="#" onclick="resetBOX(); return false;">Click to RESET last input box</a>
  106.  
  107. </body>
  108. </html>
Advertisement
Add Comment
Please, Sign In to add comment