JqueryUI - Selectmenu - Custom Rendering


SUBMITTED BY: jlolk3r

DATE: Feb. 1, 2016, 8:44 a.m.

FORMAT: HTML

SIZE: 4.4 kB

HITS: 3310

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1">
  6. <title>jQuery UI Selectmenu - Custom Rendering</title>
  7. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  8. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  9. <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  10. <link rel="stylesheet" href="/resources/demos/style.css">
  11. <script>
  12. $(function() {
  13. $.widget( "custom.iconselectmenu", $.ui.selectmenu, {
  14. _renderItem: function( ul, item ) {
  15. var li = $( "<li>", { text: item.label } );
  16. if ( item.disabled ) {
  17. li.addClass( "ui-state-disabled" );
  18. }
  19. $( "<span>", {
  20. style: item.element.attr( "data-style" ),
  21. "class": "ui-icon " + item.element.attr( "data-class" )
  22. })
  23. .appendTo( li );
  24. return li.appendTo( ul );
  25. }
  26. });
  27. $( "#filesA" )
  28. .iconselectmenu()
  29. .iconselectmenu( "menuWidget" )
  30. .addClass( "ui-menu-icons" );
  31. $( "#filesB" )
  32. .iconselectmenu()
  33. .iconselectmenu( "menuWidget" )
  34. .addClass( "ui-menu-icons customicons" );
  35. $( "#people" )
  36. .iconselectmenu()
  37. .iconselectmenu( "menuWidget")
  38. .addClass( "ui-menu-icons avatar" );
  39. });
  40. </script>
  41. <style>
  42. h2 {
  43. margin: 30px 0 0 0
  44. }
  45. fieldset {
  46. border: 0;
  47. }
  48. label {
  49. display: block;
  50. }
  51. select {
  52. width: 200px;
  53. }
  54. /* select with custom icons */
  55. .ui-selectmenu-menu .ui-menu.customicons .ui-menu-item {
  56. padding: 0.5em 0 0.5em 3em;
  57. }
  58. .ui-selectmenu-menu .ui-menu.customicons .ui-menu-item .ui-icon {
  59. height: 24px;
  60. width: 24px;
  61. top: 0.1em;
  62. }
  63. .ui-icon.video {
  64. background: url("images/24-video-square.png") 0 0 no-repeat;
  65. }
  66. .ui-icon.podcast {
  67. background: url("images/24-podcast-square.png") 0 0 no-repeat;
  68. }
  69. .ui-icon.rss {
  70. background: url("images/24-rss-square.png") 0 0 no-repeat;
  71. }
  72. /* select with CSS avatar icons */
  73. option.avatar {
  74. background-repeat: no-repeat !important;
  75. padding-left: 20px;
  76. }
  77. .avatar .ui-icon {
  78. background-position: left top;
  79. }
  80. </style>
  81. </head>
  82. <body>
  83. <div class="demo">
  84. <form action="#">
  85. <h2>Selectmenu with framework icons</h2>
  86. <fieldset>
  87. <label for="filesA">Select a File:</label>
  88. <select name="filesA" id="filesA">
  89. <option value="jquery" data-class="ui-icon-script">jQuery.js</option>
  90. <option value="jquerylogo" data-class="ui-icon-image">jQuery Logo</option>
  91. <option value="jqueryui" data-class="ui-icon-script">ui.jQuery.js</option>
  92. <option value="jqueryuilogo" selected="selected" data-class="ui-icon-image">jQuery UI Logo</option>
  93. <option value="somefile" disabled="disabled" data-class="ui-icon-help">Some unknown file</option>
  94. </select>
  95. </fieldset>
  96. <h2>Selectmenu with custom icon images</h2>
  97. <fieldset>
  98. <label for="filesB">Select a podcast:</label>
  99. <select name="filesB" id="filesB">
  100. <option value="mypodcast" data-class="podcast">John Resig Podcast</option>
  101. <option value="myvideo" data-class="video">Scott González Video</option>
  102. <option value="myrss" data-class="rss">jQuery RSS XML</option>
  103. </select>
  104. </fieldset>
  105. <h2>Selectmenu with custom avatar 16x16 images as CSS background</h2>
  106. <fieldset>
  107. <label for="people">Select a Person:</label>
  108. <select name="people" id="people">
  109. <option value="1" data-class="avatar" data-style="background-image: url(&apos;http://www.gravatar.com/avatar/b3e04a46e85ad3e165d66f5d927eb609?d=monsterid&amp;r=g&amp;s=16&apos;);">John Resig</option>
  110. <option value="2" data-class="avatar" data-style="background-image: url(&apos;http://www.gravatar.com/avatar/e42b1e5c7cfd2be0933e696e292a4d5f?d=monsterid&amp;r=g&amp;s=16&apos;);">Tauren Mills</option>
  111. <option value="3" data-class="avatar" data-style="background-image: url(&apos;http://www.gravatar.com/avatar/bdeaec11dd663f26fa58ced0eb7facc8?d=monsterid&amp;r=g&amp;s=16&apos;);">Jane Doe</option>
  112. </select>
  113. </fieldset>
  114. </form>
  115. </div>
  116. </body>
  117. </html>

comments powered by Disqus