Advertisement
Guest User

Untitled

a guest
Aug 21st, 2014
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.1/themes/smoothness/jquery-ui.css">
  2. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  3. <script src="//code.jquery.com/ui/1.11.1/jquery-ui.js"></script>
  4. <link rel="stylesheet" href="//jqueryui.com/jquery-wp-content/themes/jqueryui.com/style.css">
  5. <script>
  6. $(function() {
  7. $.widget( "custom.iconselectmenu", $.ui.selectmenu, {
  8. _renderItem: function( ul, item ) {
  9. var li = $( "<li>", { text: item.label } );
  10.  
  11. if ( item.disabled ) {
  12. li.addClass( "ui-state-disabled" );
  13. }
  14.  
  15. $( "<span>", {
  16. style: item.element.attr( "data-style" ),
  17. "class": "ui-icon " + item.element.attr( "data-class" )
  18. })
  19. .appendTo( li );
  20.  
  21. return li.appendTo( ul );
  22. }
  23. });
  24.  
  25. $( "#filesA" )
  26. .iconselectmenu()
  27. .iconselectmenu( "menuWidget" )
  28. .addClass( "ui-menu-icons" );
  29.  
  30. $( "#filesB" )
  31. .iconselectmenu()
  32. .iconselectmenu( "menuWidget" )
  33. .addClass( "ui-menu-icons customicons" );
  34.  
  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.  
  55. /* select with custom icons */
  56. .ui-selectmenu-menu .ui-menu.customicons .ui-menu-item {
  57. padding: 0.5em 0 0.5em 3em;
  58. }
  59. .ui-selectmenu-menu .ui-menu.customicons .ui-menu-item .ui-icon {
  60. height: 24px;
  61. width: 24px;
  62. top: 0.1em;
  63. }
  64. .ui-icon.video {
  65. background: url("images/24-video-square.png") 0 0 no-repeat;
  66. }
  67. .ui-icon.podcast {
  68. background: url("images/24-podcast-square.png") 0 0 no-repeat;
  69. }
  70. .ui-icon.rss {
  71. background: url("images/24-rss-square.png") 0 0 no-repeat;
  72. }
  73.  
  74. /* select with CSS avatar icons */
  75. option.avatar {
  76. background-repeat: no-repeat !important;
  77. padding-left: 20px;
  78. }
  79. .avatar .ui-icon {
  80. background-position: left top;
  81. }
  82. </style>
  83. </head>
  84. <body>
  85.  
  86. <div class="demo">
  87.  
  88. <form action="#">
  89.  
  90. <h2>Selectmenu with custom avatar 16x16 images as CSS background</h2>
  91. <fieldset>
  92. <label for="people">Select a Person:</label>
  93. <select name="people" id="people">
  94. <option value="1" data-class="avatar" data-style="background-image: url(&apos;http://retsmgr.discovermls.com/images/delete-16x16.gif&apos;);">John Resig</option>
  95. <option value="2" data-class="avatar" data-style="background-image: url(&apos;http://retsmgr.discovermls.com/images/delete-16x16.gif&apos;);">Tauren Mills</option>
  96. <option value="3" data-class="avatar" data-style="background-image: url(&apos;http://retsmgr.discovermls.com/images/delete-16x16.gif&apos;);">Jane Doe</option>
  97. </select>
  98. </fieldset>
  99. </form>
  100.  
  101. </div>
  102.  
  103. $('#people-menu').click(function(event){
  104. if($(event.target).is('span.avatar')) {
  105. $(event.target).parent('li').hide();
  106. }
  107. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement