" + item[this.propertyToSearch] + "
"+settings.searchingText+"
"); 644 | show_dropdown(); 645 | } 646 | } 647 | 648 | function show_dropdown_hint () { 649 | if(settings.hintText) { 650 | dropdown.html(""+settings.hintText+"
"); 651 | show_dropdown(); 652 | } 653 | } 654 | 655 | // Highlight the query part of the search term 656 | function highlight_term(value, term) { 657 | return value.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + term + ")(?![^<>]*>)(?![^&;]+;)", "gi"), "$1"); 658 | } 659 | 660 | function find_value_and_highlight_term(template, value, term) { 661 | return template.replace(new RegExp("(?![^&;]+;)(?!<[^<>]*)(" + value + ")(?![^<>]*>)(?![^&;]+;)", "g"), highlight_term(value, term)); 662 | } 663 | 664 | // Populate the results dropdown with some results 665 | function populate_dropdown (query, results) { 666 | if(results && results.length) { 667 | dropdown.empty(); 668 | var dropdown_ul = $(""+settings.noResultsText+"
"); 710 | show_dropdown(); 711 | } 712 | } 713 | } 714 | 715 | // Highlight an item in the results dropdown 716 | function select_dropdown_item (item) { 717 | if(item) { 718 | if(selected_dropdown_item) { 719 | deselect_dropdown_item($(selected_dropdown_item)); 720 | } 721 | 722 | item.addClass(settings.classes.selectedDropdownItem); 723 | selected_dropdown_item = item.get(0); 724 | } 725 | } 726 | 727 | // Remove highlighting from an item in the results dropdown 728 | function deselect_dropdown_item (item) { 729 | item.removeClass(settings.classes.selectedDropdownItem); 730 | selected_dropdown_item = null; 731 | } 732 | 733 | // Do a search and show the "searching" dropdown if the input is longer 734 | // than settings.minChars 735 | function do_search() { 736 | var query = input_box.val(); 737 | 738 | if(query && query.length) { 739 | if(selected_token) { 740 | deselect_token($(selected_token), POSITION.AFTER); 741 | } 742 | 743 | if(query.length >= settings.minChars) { 744 | show_dropdown_searching(); 745 | clearTimeout(timeout); 746 | 747 | timeout = setTimeout(function(){ 748 | run_search(query); 749 | }, settings.searchDelay); 750 | } else { 751 | hide_dropdown(); 752 | } 753 | } 754 | } 755 | 756 | // Do the actual search 757 | function run_search(query) { 758 | var cache_key = query + computeURL(); 759 | var cached_results = cache.get(cache_key); 760 | if(cached_results) { 761 | populate_dropdown(query, cached_results); 762 | } else { 763 | // Are we doing an ajax search or local data search? 764 | if(settings.url) { 765 | var url = computeURL(); 766 | // Extract exisiting get params 767 | var ajax_params = {}; 768 | ajax_params.data = {}; 769 | if(url.indexOf("?") > -1) { 770 | var parts = url.split("?"); 771 | ajax_params.url = parts[0]; 772 | 773 | var param_array = parts[1].split("&"); 774 | $.each(param_array, function (index, value) { 775 | var kv = value.split("="); 776 | ajax_params.data[kv[0]] = kv[1]; 777 | }); 778 | } else { 779 | ajax_params.url = url; 780 | } 781 | 782 | // Prepare the request 783 | ajax_params.data[settings.queryParam] = query; 784 | ajax_params.type = settings.method; 785 | ajax_params.dataType = settings.contentType; 786 | if(settings.crossDomain) { 787 | ajax_params.dataType = "jsonp"; 788 | } 789 | 790 | // Attach the success callback 791 | ajax_params.success = function(results) { 792 | if($.isFunction(settings.onResult)) { 793 | results = settings.onResult.call(hidden_input, results); 794 | } 795 | cache.add(cache_key, settings.jsonContainer ? results[settings.jsonContainer] : results); 796 | 797 | // only populate the dropdown if the results are associated with the active search query 798 | if(input_box.val().toLowerCase() === query.toLowerCase()) { 799 | populate_dropdown(query, settings.jsonContainer ? results[settings.jsonContainer] : results); 800 | } 801 | }; 802 | 803 | // Make the request 804 | $.ajax(ajax_params); 805 | } else if(settings.local_data) { 806 | // Do the search through local data 807 | var results = $.grep(settings.local_data, function (row) { 808 | //return row[settings.propertyToSearch].toLowerCase().indexOf(query.toLowerCase()) > -1; 809 | return row[settings.propertyToSearch].indexOf(query.toLowerCase()) > -1; 810 | }); 811 | 812 | if($.isFunction(settings.onResult)) { 813 | results = settings.onResult.call(hidden_input, results); 814 | } 815 | cache.add(cache_key, results); 816 | populate_dropdown(query, results); 817 | } 818 | } 819 | } 820 | 821 | // compute the dynamic URL 822 | function computeURL() { 823 | var url = settings.url; 824 | if(typeof settings.url == 'function') { 825 | url = settings.url.call(); 826 | } 827 | return url; 828 | } 829 | }; 830 | 831 | // Really basic cache for the results 832 | $.TokenList.Cache = function (options) { 833 | var settings = $.extend({ 834 | max_size: 500 835 | }, options); 836 | 837 | var data = {}; 838 | var size = 0; 839 | 840 | var flush = function () { 841 | data = {}; 842 | size = 0; 843 | }; 844 | 845 | this.add = function (query, results) { 846 | if(size > settings.max_size) { 847 | flush(); 848 | } 849 | 850 | if(!data[query]) { 851 | size += 1; 852 | } 853 | 854 | data[query] = results; 855 | }; 856 | 857 | this.get = function (query) { 858 | return data[query]; 859 | }; 860 | }; 861 | }(jQuery)); 862 | -------------------------------------------------------------------------------- /resources/tokeninput/token-input-facebook.css: -------------------------------------------------------------------------------- 1 | /* Example tokeninput style #2: Facebook style */ 2 | ul.token-input-list-facebook { 3 | overflow: hidden; 4 | height: auto !important; 5 | height: 1%; 6 | width: 100%; 7 | border: 1px solid transparent; 8 | cursor: text; 9 | font-size: 12px; 10 | min-height: 1px; 11 | /*z-index: 1;*/ 12 | margin: 0; 13 | padding: 0; 14 | list-style-type: none; 15 | clear: left; 16 | } 17 | 18 | ul.token-input-list-facebook li input { 19 | width: 30px; 20 | padding: 1px 4px; 21 | background-color: #fafafa; 22 | border: 1px dashed #91bacf; 23 | margin: 3px; 24 | border-radius: 3px; 25 | -moz-border-radius: 3px; 26 | -webkit-border-radius: 3px; 27 | font-size: 12px; 28 | line-height: 16px; 29 | } 30 | 31 | ul.token-input-list-facebook li input:focus { 32 | background-color: #d8edf9; 33 | border: 1px solid #72b3d7; 34 | } 35 | 36 | li.token-input-token-facebook { 37 | overflow: hidden; 38 | height: 16px; 39 | margin: 3px; 40 | padding: 1px 4px; 41 | background-color: #eff2f7; 42 | color: #444; 43 | cursor: default; 44 | border: 1px solid #99C4DB; 45 | font-size: 12px; 46 | border-radius: 3px; 47 | -moz-border-radius: 3px; 48 | -webkit-border-radius: 3px; 49 | float: left; 50 | white-space: nowrap; 51 | } 52 | .token-input-token-facebook p{ 53 | font-size: 12px; 54 | line-height: 16px; 55 | } 56 | 57 | li.token-input-token-facebook p { 58 | display: inline; 59 | padding: 0; 60 | margin: 0; 61 | font-family: Arial; 62 | } 63 | 64 | li.token-input-token-facebook span { 65 | color: #007FC5; 66 | margin-left: 4px; 67 | font-weight: bold; 68 | cursor: pointer; 69 | font-family: arial; 70 | } 71 | 72 | li.token-input-selected-token-facebook { 73 | background-color: #007FC5; 74 | border: 1px solid #3b5998; 75 | color: #fff; 76 | } 77 | 78 | li.token-input-selected-token-facebook span { 79 | color: #fff; 80 | } 81 | 82 | li.token-input-input-token-facebook { 83 | float: left; 84 | margin: 0; 85 | padding: 0; 86 | list-style-type: none; 87 | } 88 | 89 | div.token-input-dropdown-facebook { 90 | position: absolute; 91 | width: 400px; 92 | background-color: #fff; 93 | overflow: hidden; 94 | border: 1px solid #b1b1b1; 95 | cursor: default; 96 | font-size: 12px; 97 | z-index: 10000 !important; 98 | border-radius: 3px; 99 | -moz-border-radius: 3px; 100 | -webkit-border-radius: 3px; 101 | } 102 | 103 | div.token-input-dropdown-facebook p { 104 | margin: 0; 105 | padding: 8px 5px; 106 | color: #007FC5; 107 | font-size: 12px; 108 | line-height: 12px; 109 | font-weight: bold; 110 | } 111 | 112 | div.token-input-dropdown-facebook ul { 113 | margin: 0; 114 | padding: 0; 115 | } 116 | 117 | div.token-input-dropdown-facebook ul li { 118 | padding: 5px; 119 | margin: 0; 120 | list-style-type: none; 121 | } 122 | 123 | div.token-input-dropdown-facebook ul li em { 124 | 125 | font-weight: bold; 126 | font-style: normal; 127 | } 128 | 129 | div.token-input-dropdown-facebook ul li.token-input-selected-dropdown-item-facebook { 130 | background-color: #007FC5; 131 | color: #fff; 132 | padding: 5px; 133 | } 134 | 135 | -------------------------------------------------------------------------------- /resources/tokeninput/token-input-mac.css: -------------------------------------------------------------------------------- 1 | /* Example tokeninput style #2: Mac Style */ 2 | fieldset.token-input-mac { 3 | position: relative; 4 | padding: 0; 5 | margin: 5px 0; 6 | background: #fff; 7 | width: 400px; 8 | border: 1px solid #A4BDEC; 9 | border-radius: 10px; 10 | -moz-border-radius: 10px; 11 | -webkit-border-radius: 10px; 12 | } 13 | 14 | fieldset.token-input-mac.token-input-dropdown-mac { 15 | border-radius: 10px 10px 0 0; 16 | -moz-border-radius: 10px 10px 0 0; 17 | -webkit-border-radius: 10px 10px 0 0; 18 | box-shadow: 0 5px 20px 0 rgba(0,0,0,0.25); 19 | -moz-box-shadow: 0 5px 20px 0 rgba(0,0,0,0.25); 20 | -webkit-box-shadow: 0 5px 20px 0 rgba(0,0,0,0.25); 21 | } 22 | 23 | ul.token-input-list-mac { 24 | overflow: hidden; 25 | height: auto !important; 26 | height: 1%; 27 | cursor: text; 28 | font-size: 12px; 29 | font-family: Verdana; 30 | min-height: 1px; 31 | z-index: 10000; 32 | margin: 0; 33 | padding: 3px; 34 | background: transparent; 35 | } 36 | 37 | ul.token-input-list-mac.error { 38 | border: 1px solid #C52020; 39 | } 40 | 41 | ul.token-input-list-mac li { 42 | list-style-type: none; 43 | } 44 | 45 | li.token-input-token-mac p { 46 | display: inline; 47 | padding: 0; 48 | margin: 0; 49 | } 50 | 51 | li.token-input-token-mac span { 52 | color: #a6b3cf; 53 | margin-left: 5px; 54 | font-weight: bold; 55 | cursor: pointer; 56 | } 57 | 58 | /* TOKENS */ 59 | 60 | li.token-input-token-mac { 61 | font-family: "Lucida Grande", Arial, serif; 62 | font-size: 9pt; 63 | line-height: 12pt; 64 | overflow: hidden; 65 | height: 16px; 66 | margin: 3px; 67 | padding: 0 10px; 68 | background: none; 69 | background-color: #dee7f8; 70 | color: #000; 71 | cursor: default; 72 | border: 1px solid #a4bdec; 73 | border-radius: 15px; 74 | -moz-border-radius: 15px; 75 | -webkit-border-radius: 15px; 76 | float: left; 77 | } 78 | 79 | li.token-input-highlighted-token-mac { 80 | background-color: #bbcef1; 81 | border: 1px solid #598bec; 82 | color: #000; 83 | } 84 | 85 | li.token-input-selected-token-mac { 86 | background-color: #598bec; 87 | border: 1px solid transparent; 88 | color: #fff; 89 | } 90 | 91 | li.token-input-highlighted-token-mac span.token-input-delete-token-mac { 92 | color: #000; 93 | } 94 | 95 | li.token-input-selected-token-mac span.token-input-delete-token-mac { 96 | color: #fff; 97 | } 98 | 99 | li.token-input-input-token-mac { 100 | border: none; 101 | background: transparent; 102 | float: left; 103 | padding: 0; 104 | margin: 0; 105 | } 106 | 107 | li.token-input-input-token-mac input { 108 | border: 0; 109 | width: 100px; 110 | padding: 3px; 111 | background-color: transparent; 112 | margin: 0; 113 | } 114 | 115 | div.token-input-dropdown-mac { 116 | position: absolute; 117 | border: 1px solid #A4BDEC; 118 | border-top: none; 119 | left: -1px; 120 | right: -1px; 121 | background-color: #fff; 122 | overflow: hidden; 123 | cursor: default; 124 | font-size: 10pt; 125 | font-family: "Lucida Grande", Arial, serif; 126 | padding: 5px; 127 | border-radius: 0 0 10px 10px; 128 | -moz-border-radius: 0 0 10px 10px; 129 | -webkit-border-radius: 0 0 10px 10px; 130 | box-shadow: 0 5px 20px 0 rgba(0,0,0,0.25); 131 | -moz-box-shadow: 0 5px 20px 0 rgba(0,0,0,0.25); 132 | -webkit-box-shadow: 0 5px 20px 0 rgba(0,0,0,0.25); 133 | clip:rect(0px, 1000px, 1000px, -10px); 134 | } 135 | 136 | div.token-input-dropdown-mac p { 137 | font-size: 8pt; 138 | margin: 0; 139 | padding: 0 5px; 140 | font-style: italic; 141 | color: #aaa; 142 | } 143 | 144 | div.token-input-dropdown-mac h3.token-input-dropdown-category-mac { 145 | font-family: "Lucida Grande", Arial, serif; 146 | font-size: 10pt; 147 | font-weight: bold; 148 | border: none; 149 | padding: 0 5px; 150 | margin: 0; 151 | } 152 | 153 | div.token-input-dropdown-mac ul { 154 | margin: 0; 155 | padding: 0; 156 | } 157 | 158 | div.token-input-dropdown-mac ul li { 159 | list-style-type: none; 160 | cursor: pointer; 161 | background: none; 162 | background-color: #fff; 163 | margin: 0; 164 | padding: 0 0 0 25px; 165 | } 166 | 167 | div.token-input-dropdown-mac ul li.token-input-dropdown-item-mac { 168 | background-color: #fff; 169 | } 170 | 171 | div.token-input-dropdown-mac ul li.token-input-dropdown-item-mac.odd { 172 | background-color: #ECF4F9; 173 | border-radius: 15px; 174 | -moz-border-radius: 15px; 175 | -webkit-border-radius: 15px; 176 | } 177 | 178 | div.token-input-dropdown-mac ul li.token-input-dropdown-item-mac span.token-input-dropdown-item-description-mac { 179 | float: right; 180 | font-size: 8pt; 181 | font-style: italic; 182 | padding: 0 10px 0 0; 183 | color: #999; 184 | } 185 | 186 | div.token-input-dropdown-mac ul li strong { 187 | font-weight: bold; 188 | text-decoration: underline; 189 | font-style: none; 190 | } 191 | 192 | div.token-input-dropdown-mac ul li.token-input-selected-dropdown-item-mac, 193 | div.token-input-dropdown-mac ul li.token-input-selected-dropdown-item-mac.odd { 194 | background-color: #598bec; 195 | color: #fff; 196 | border-radius: 15px; 197 | -moz-border-radius: 15px; 198 | -webkit-border-radius: 15px; 199 | } 200 | 201 | div.token-input-dropdown-mac ul li.token-input-selected-dropdown-item-mac span.token-input-dropdown-item-description-mac, 202 | div.token-input-dropdown-mac ul li.token-input-selected-dropdown-item-mac.odd span.token-input-dropdown-item-description-mac { 203 | color: #fff; 204 | } 205 | -------------------------------------------------------------------------------- /resources/tokeninput/token-input.css: -------------------------------------------------------------------------------- 1 | /* Example tokeninput style #1: Token vertical list*/ 2 | ul.token-input-list { 3 | overflow: hidden; 4 | height: auto !important; 5 | height: 1%; 6 | width: 400px; 7 | border: 1px solid #999; 8 | cursor: text; 9 | font-size: 12px; 10 | font-family: Verdana; 11 | z-index: 10000; 12 | margin: 0; 13 | padding: 0; 14 | background-color: #fff; 15 | list-style-type: none; 16 | clear: left; 17 | } 18 | 19 | ul.token-input-list li { 20 | list-style-type: none; 21 | } 22 | 23 | ul.token-input-list li input { 24 | border: 0; 25 | width: 350px; 26 | padding: 3px 8px; 27 | background-color: white; 28 | -webkit-appearance: caret; 29 | } 30 | 31 | li.token-input-token { 32 | overflow: hidden; 33 | height: auto !important; 34 | height: 1%; 35 | margin: 3px; 36 | padding: 3px 5px; 37 | background-color: #d0efa0; 38 | color: #000; 39 | font-weight: bold; 40 | cursor: default; 41 | display: block; 42 | } 43 | 44 | li.token-input-token p { 45 | float: left; 46 | padding: 0; 47 | margin: 0; 48 | } 49 | 50 | li.token-input-token span { 51 | float: right; 52 | color: #777; 53 | cursor: pointer; 54 | } 55 | 56 | li.token-input-selected-token { 57 | background-color: #08844e; 58 | color: #fff; 59 | } 60 | 61 | li.token-input-selected-token span { 62 | color: #bbb; 63 | } 64 | 65 | div.token-input-dropdown { 66 | position: absolute; 67 | width: 400px; 68 | background-color: #fff; 69 | overflow: hidden; 70 | border-left: 1px solid #ccc; 71 | border-right: 1px solid #ccc; 72 | border-bottom: 1px solid #ccc; 73 | cursor: default; 74 | font-size: 12px; 75 | font-family: Verdana; 76 | z-index: 10000; 77 | } 78 | 79 | div.token-input-dropdown p { 80 | margin: 0; 81 | padding: 5px; 82 | font-weight: bold; 83 | color: #777; 84 | } 85 | 86 | div.token-input-dropdown ul { 87 | margin: 0; 88 | padding: 0; 89 | } 90 | 91 | div.token-input-dropdown ul li { 92 | background-color: #fff; 93 | padding: 3px; 94 | list-style-type: none; 95 | } 96 | 97 | div.token-input-dropdown ul li.token-input-dropdown-item { 98 | background-color: #fafafa; 99 | } 100 | 101 | div.token-input-dropdown ul li.token-input-dropdown-item2 { 102 | background-color: #fff; 103 | } 104 | 105 | div.token-input-dropdown ul li em { 106 | font-weight: bold; 107 | font-style: normal; 108 | } 109 | 110 | div.token-input-dropdown ul li.token-input-selected-dropdown-item { 111 | background-color: #d0efa0; 112 | } 113 | 114 | --------------------------------------------------------------------------------