├── .eslintrc ├── .gitignore ├── CHANGELOG.md ├── LICENSE.md ├── README.md ├── bower.json ├── demo └── index.html ├── dist └── jquery.ddslick.min.js ├── gulpfile.js ├── jquery.ddslick.js ├── jquery.ddslick.min.js ├── package.json └── src └── jquery.ddslick.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "indent": [2], 4 | "quotes": [2, "double"], 5 | "linebreak-style": [2, "unix"], 6 | "semi": [2, "always"] 7 | }, 8 | "globals": { 9 | "define" : true, 10 | "module" : true, 11 | "require" : true 12 | }, 13 | "env": { 14 | "browser": true, 15 | "jquery": true 16 | }, 17 | "extends": "eslint:recommended" 18 | } 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | bower_components/ 3 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 1.0.0 2 | 3 | - Adds a license, code linting, bower.json, package.json, and a build process. 4 | 5 | ## 1.0.2 6 | 7 | - AMD and Node/CommonJS module support. 8 | - Prevents listener from firing when initializing drop down. 9 | - Adds the close drop down listener only once. 10 | - Ability to customize animation time. 11 | - Respecting the drop down holder id. 12 | 13 | ## 1.0.3 14 | 15 | - jQuery dependency updated, <3.0 has XSS vulnerabilities 16 | - Demo file included for integration testing 17 | - Accessibility improvements 18 | - Use 409 | 412 | 413 | 414 | 415 |
416 | Source: 417 |
 418 | //Make it slick!
 419 | $("#make-it-slick").on("click", function(){
 420 |     $("#demo-htmlselect").ddslick();
 421 | });
 422 | //Restore Original
 423 | $("#restore").on("click", function(){
 424 |     $("#demo-htmlselect").ddslick("destroy");
 425 | });
 426 | 
427 |

428 | Use HTML5 data attributes data-imagesrc and data-description 429 | with your regular HTML select elements to add images and description. The plugin 430 | will retrieve text, value, and selected attributes 431 | from the elements itself.
432 | Click here to see the HTML select element for this example. 433 |

434 |
435 |
436 |
437 |
438 |

439 | 3 440 | GET selected dropdown option 441 |

442 |
443 |
444 |
445 |
446 |
447 |
448 | 451 |
452 |
453 |
454 |
455 | Source: 456 |
 457 | $("#demoShowSelected").ddslick({
 458 |     data: ddData,
 459 |     selectText: "Select your favorite social network",
 460 | });
 461 | $("#showSelectedData").on("click", function () {
 462 |     var ddData = $("#demoShowSelected").data("ddslick");
 463 |     displaySelectedData("2: Getting Selected Dropdown Data" , ddData);
 464 | });
 465 | 
466 |

467 | You may use jquery .data() with your selector to get data from plugin. $("#demoShowSelected").data("ddslick"); 468 | will return a js object that contains: 469 |

470 | 475 |
476 |
477 |
478 |
479 |

480 | 4 481 | SET selected dropdown option 482 |

483 |
484 |
485 |

486 | Try an index between 0 to 3 487 |

488 | 489 | 492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
500 | Source: 501 |
 502 | $("#demoSetSelected").ddslick({
 503 |     data: ddData,
 504 |     selectText: "Select your favorite social network"
 505 | });
 506 | $("#btnSetSelected").on("click", function () {
 507 |     var i = $("#setIndex").val();
 508 |     if(i >= 0 && i <5)
 509 |        $("#demoSetSelected").ddslick("select", {index: i });
 510 |     else
 511 |        $("#setIndexMsg").effect("highlight",2400);
 512 | });
 513 | 
514 |

515 | You may use plugin’s select method like 516 | $("#demoSetSelected").ddslick("select", 517 | {index: i }); 518 |
519 | to select a particular index. 520 |

521 | 522 |
523 |
524 |
525 |
526 |

527 | 5 528 | onSelected callback function 529 |

530 |
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 | Source: 539 |
 540 | $("#demoCallback").ddslick({
 541 |     data: ddData,
 542 |     selectText: "Select your favorite social network",
 543 |     onSelected: function(data){
 544 |         displaySelectedData("3: Callback Function on Dropdown Selection" , data);
 545 |     }
 546 | });
 547 | 
548 |

549 | Use plugin’s onSelected callback function on selecting one of the drop 550 | down options. The callback data will include: 551 |

552 | 557 |
558 |
559 |
560 |
561 |

562 | 6 563 | Dropdown with default selection 564 |

565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 | Source: 574 |
 575 | $("#demoDefaultSelection").ddslick({
 576 |     data: ddData,
 577 |     defaultSelectedIndex:2
 578 | });
 579 | 
580 |

581 | Use Zero based plugin option 582 | defaultSelectedIndex to set up plugin 583 | to pre select the index, when first initializing. 584 |
585 | Note: When there is no selectText the plugin selects 586 | the first item index[0] from dropdown options. 587 |

588 |
589 |
590 |
591 |
592 |

593 | 7 594 | Dropdown with image on right 595 |

596 |
597 |
598 |
599 |
600 |
601 |
602 |
603 |
604 | Source: 605 |
 606 | $("#demoImageRight").ddslick({
 607 |     data: ddData,
 608 |     imagePosition:"right",
 609 |     selectText: "Select your favorite social network"
 610 | });
 611 | 
612 |

613 | You have the flexibility to position image either on left or right using imagePosition, 614 | depending on your preference. 615 |
616 | Also you can add your own styles to these images by modifying their CSS class 617 | .dd-option-image, .dd-selected-image 618 | on your page. For e.g. plugin sets 619 | the default max-width for images to 64px, that you can overwrite by adding these 620 | classes to your page and overwriting max-width style. 621 |

622 |
623 |
624 |
625 |
626 |

627 | 8 628 | Dropdown with truncated description 629 |

630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 | Source: 639 |
 640 | $("#demoTruncated").ddslick({
 641 |     data: ddDataLongDescription,
 642 |     selectText: "Select your favorite social network",
 643 |     truncateDescription: true,
 644 |     onSelected: function(data){
 645 |         displaySelectedData("5: Dropdown with truncated description", data);
 646 |     }
 647 | });
 648 | 
649 |

650 | By default plugin will truncate the description in selected view if it overflows. 651 | You may however turn the default behavior by setting truncateDescription:false 652 | to show the complete description. Either way you still get the complete description 653 | with returned selected data. Also use .dd-desc to add your own styles 654 | to description. 655 |

656 |
657 |
658 |
659 |
660 |

661 | 9 662 | Dropdown with no image or description 663 |

664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 | Source: 673 |
 674 | var ddBasic = [
 675 |     { text: "Facebook", value: 1, },
 676 |     { text: "Twitter", value: 2, },
 677 |     { text: "LinkedIn", value: 3, },
 678 |     { text: "Foursquare", value: 4, }
 679 | ];
 680 | $("#divNoImage").ddslick({
 681 |     data: ddBasic,
 682 |     selectText: "Select your favorite social network"
 683 | });
 684 | 
685 |

686 | The plugin is built to work as beautiful even without images! 687 |

688 |
689 |
690 |
691 | 692 |
693 |
694 |
695 |
696 | 699 |
700 | 701 | 702 | 703 |
704 | 705 |
706 |

How to use with JSON data

707 |
    708 |
  1. 709 | Include the plugin javascript file along with jquery: 710 |
     711 | <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
     712 | <script type="text/javascript" src="https://cdn.rawgit.com/jsmodules/ddslick/master/dist/jquery.ddslick.min.js" ></script>
     713 | 
    714 |
  2. 715 |
  3. 716 | Create an empty placeholder for the custom dropdown: eg: 717 |
     718 | <div id="myDropdown"></div>
     719 | 
    720 |
  4. 721 |
  5. 722 | Get the dropdown options (JSON Data) to be binded to plugin: 723 |
     724 | //Dropdown plugin data
     725 | var ddData = [
     726 |     {
     727 |         text: "Facebook",
     728 |         value: 1,
     729 |         selected: false,
     730 |         description: "Description with Facebook",
     731 |         imageSrc: "http://i.imgur.com/XkuTj3B.png"
     732 |     },
     733 |     {
     734 |         text: "Twitter",
     735 |         value: 2,
     736 |         selected: false,
     737 |         description: "Description with Twitter",
     738 |         imageSrc: "http://i.imgur.com/8ScLNnk.png"
     739 |     },
     740 |     {
     741 |         text: "LinkedIn",
     742 |         value: 3,
     743 |         selected: true,
     744 |         description: "Description with LinkedIn",
     745 |         imageSrc: "http://i.imgur.com/aDNdibj.png"
     746 |     },
     747 |     {
     748 |         text: "Foursquare",
     749 |         value: 4,
     750 |         selected: false,
     751 |         description: "Description with Foursquare",
     752 |         imageSrc: "http://i.imgur.com/kFAk2DX.png"
     753 |     }
     754 | ];
     755 | 
    756 |
  6. 757 |
  7. 758 | Attach plugin to this placeholder like: 759 |
     760 | $("#myDropdown").ddslick({
     761 |     data:ddData,
     762 |     width:300,
     763 |     selectText: "Select your preferred social network",
     764 |     imagePosition:"right",
     765 |     onSelected: function(selectedData){
     766 |         //callback function: do something with selectedData;
     767 |     }
     768 | });
     769 | 
    770 | Note: Use onSelected callback function to do something after the dropdown option is selected. The selectedData will contain the selected text, value, description, imageSrc. 771 |
  8. 772 |
773 |
774 |
775 |
776 |

How to use with HTML <select> and <option>

777 |
    778 |
  1. 779 | Include the plugin javascript file along with jquery: 780 |
     781 | <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.0.0/jquery.min.js"></script>
     782 | <script type="text/javascript" src="https://cdn.rawgit.com/jsmodules/ddslick/master/dist/jquery.ddslick.min.js" ></script>
     783 | 
    784 |
  2. 785 |
  3. 786 | Add HTML5 data attributes to your select elements: eg: 787 |
     788 | <select id="demo-htmlselect">
     789 |     <option value="0" data-imagesrc="http://i.imgur.com/XkuTj3B.png"
     790 |         data-description="Description with Facebook">Facebook</option>
     791 |     <option value="1" data-imagesrc="http://i.imgur.com/8ScLNnk.png"
     792 |         data-description="Description with Twitter">Twitter</option>
     793 |     <option value="2" selected="selected" data-imagesrc="http://i.imgur.com/aDNdibj.png"
     794 |         data-description="Description with LinkedIn">LinkedIn</option>
     795 |     <option value="3" data-imagesrc="http://i.imgur.com/kFAk2DX.png"
     796 |         data-description="Description with Foursquare">Foursquare</option>
     797 | </select>
     798 | 
    799 |
  4. 800 |
  5. 801 | Attach plugin to this HTML select element: 802 |
     803 | $("#myDropdown").ddslick({
     804 |     onSelected: function(selectedData){
     805 |         //callback function: do something with selectedData;
     806 |     }
     807 | });
     808 | 
    809 |
  6. 810 |
811 |
812 |
813 | 814 | 815 | 816 |
817 |

Plugin Options:

818 | 831 |

Plugin Methods:

832 | 838 |
839 |
840 | 841 | 842 | 1021 | 1022 | 1023 | 1024 | 1025 | 1026 | 1027 | -------------------------------------------------------------------------------- /dist/jquery.ddslick.min.js: -------------------------------------------------------------------------------- 1 | !function(e){"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof module&&module.exports?module.exports=e(require("jquery")):e(window.jQuery)}(function(e){function d(e,d){var i=e.find(".dd-option-value[value= '"+d+"']").parents("li").prevAll().length;t(e,i)}function t(d,t,i){var o=d.data("ddslick"),s=d.find(".dd-selected"),l=d.find(".dd-options"),r=s.siblings(".dd-selected-value"),c=d.find(".dd-option").eq(t),p=o.settings,f=o.settings.data[t];if(d.find(".dd-option").removeClass("dd-option-selected"),c.addClass("dd-option-selected"),l.attr("aria-activedescendant",c.attr("id")),o.selectedIndex=t,o.selectedItem=c,o.selectedData=f,p.showSelectedHTML){var u=e("
");f.imageSrc&&u.append(e("").addClass("dd-selected-image"+("right"===p.imagePosition?" dd-image-right":"")).attr("src",f.imageSrc)),f.text&&u.append(e("