| 1 |
<!DOCTYPE html> |
| 2 |
<!--[if lt IE 7]><html class="no-js lt-ie9 lt-ie8 lt-ie7"><![endif]--> |
| 3 |
<!--[if IE 7]><html class="no-js lt-ie9 lt-ie8"><![endif]--> |
| 4 |
<!--[if IE 8]><html class="no-js lt-ie9"><![endif]--> |
| 5 |
<!--[if gt IE 8]><!--><html class="no-js"><!--<![endif]--> |
| 6 |
<head> |
| 7 |
<meta charset="utf-8"> |
| 8 |
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> |
| 9 |
<title>Selectize.js Demo</title> |
| 10 |
<meta name="description" content=""> |
| 11 |
<meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"> |
| 12 |
<link rel="stylesheet" href="css/normalize.css"> |
| 13 |
<link rel="stylesheet" href="css/stylesheet.css"> |
| 14 |
<!--[if IE 8]><script src="js/es5.js"></script><![endif]--> |
| 15 |
<script src="js/jquery.min.js"></script> |
| 16 |
<script src="../dist/js/standalone/selectize.js"></script> |
| 17 |
<script src="js/index.js"></script> |
| 18 |
<style type="text/css"> |
| 19 |
.selectize-control.contacts .selectize-input > div { |
| 20 |
padding: 1px 10px; |
| 21 |
font-size: 13px; |
| 22 |
font-weight: normal; |
| 23 |
-webkit-font-smoothing: auto; |
| 24 |
color: #f7fbff; |
| 25 |
text-shadow: 0 1px 0 rgba(8,32,65,0.2); |
| 26 |
background: #2183f5; |
| 27 |
background: -moz-linear-gradient(top, #2183f5 0%, #1d77f3 100%); |
| 28 |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#2183f5), color-stop(100%,#1d77f3)); |
| 29 |
background: -webkit-linear-gradient(top, #2183f5 0%,#1d77f3 100%); |
| 30 |
background: -o-linear-gradient(top, #2183f5 0%,#1d77f3 100%); |
| 31 |
background: -ms-linear-gradient(top, #2183f5 0%,#1d77f3 100%); |
| 32 |
background: linear-gradient(to bottom, #2183f5 0%,#1d77f3 100%); |
| 33 |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#2183f5', endColorstr='#1d77f3',GradientType=0 ); |
| 34 |
border: 1px solid #0f65d2; |
| 35 |
-webkit-border-radius: 999px; |
| 36 |
-moz-border-radius: 999px; |
| 37 |
border-radius: 999px; |
| 38 |
-webkit-box-shadow: 0 1px 1px rgba(0,0,0,0.15); |
| 39 |
-moz-box-shadow: 0 1px 1px rgba(0,0,0,0.15); |
| 40 |
box-shadow: 0 1px 1px rgba(0,0,0,0.15); |
| 41 |
} |
| 42 |
.selectize-control.contacts .selectize-input > div.active { |
| 43 |
background: #0059c7; |
| 44 |
background: -moz-linear-gradient(top, #0059c7 0%, #0051c1 100%); |
| 45 |
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#0059c7), color-stop(100%,#0051c1)); |
| 46 |
background: -webkit-linear-gradient(top, #0059c7 0%,#0051c1 100%); |
| 47 |
background: -o-linear-gradient(top, #0059c7 0%,#0051c1 100%); |
| 48 |
background: -ms-linear-gradient(top, #0059c7 0%,#0051c1 100%); |
| 49 |
background: linear-gradient(to bottom, #0059c7 0%,#0051c1 100%); |
| 50 |
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#0059c7', endColorstr='#0051c1',GradientType=0 ); |
| 51 |
border-color: #0051c1; |
| 52 |
} |
| 53 |
.selectize-control.contacts .selectize-input > div .email { |
| 54 |
opacity: 0.8; |
| 55 |
} |
| 56 |
.selectize-control.contacts .selectize-input > div .name + .email { |
| 57 |
margin-left: 5px; |
| 58 |
} |
| 59 |
.selectize-control.contacts .selectize-input > div .email:before { |
| 60 |
content: '<'; |
| 61 |
} |
| 62 |
.selectize-control.contacts .selectize-input > div .email:after { |
| 63 |
content: '>'; |
| 64 |
} |
| 65 |
.selectize-control.contacts .selectize-dropdown .caption { |
| 66 |
font-size: 12px; |
| 67 |
display: block; |
| 68 |
color: #a0a0a0; |
| 69 |
} |
| 70 |
</style> |
| 71 |
</head> |
| 72 |
<body> |
| 73 |
<div id="wrapper"> |
| 74 |
<h1>Selectize.js</h1> |
| 75 |
<div class="demo"> |
| 76 |
<h2>Email Contacts</h2> |
| 77 |
<p>An example showing how you might go about creating contact selector like those used in Email apps.</p> |
| 78 |
<div class="control-group"> |
| 79 |
<label for="select-to">To:</label> |
| 80 |
<select id="select-to" class="contacts" placeholder="Pick some people..."></select> |
| 81 |
</div> |
| 82 |
<script> |
| 83 |
// <select id="select-to"></select> |
| 84 |
|
| 85 |
var REGEX_EMAIL = '([a-z0-9!#$%&\'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&\'*+/=?^_`{|}~-]+)*@' + |
| 86 |
'(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)'; |
| 87 |
|
| 88 |
var formatName = function(item) { |
| 89 |
return $.trim((item.first_name || '') + ' ' + (item.last_name || '')); |
| 90 |
}; |
| 91 |
|
| 92 |
$('#select-to').selectize({ |
| 93 |
persist: false, |
| 94 |
maxItems: null, |
| 95 |
valueField: 'email', |
| 96 |
labelField: 'name', |
| 97 |
searchField: ['first_name', 'last_name', 'email'], |
| 98 |
sortField: [ |
| 99 |
{field: 'first_name', direction: 'asc'}, |
| 100 |
{field: 'last_name', direction: 'asc'} |
| 101 |
], |
| 102 |
options: [ |
| 103 |
{email: '[email protected]', first_name: 'Nikola', last_name: 'Tesla'}, |
| 104 |
{email: '[email protected]', first_name: 'Brian', last_name: 'Reavis'}, |
| 105 |
{email: '[email protected]'} |
| 106 |
], |
| 107 |
render: { |
| 108 |
item: function(item, escape) { |
| 109 |
var name = formatName(item); |
| 110 |
return '<div>' + |
| 111 |
(name ? '<span class="name">' + escape(name) + '</span>' : '') + |
| 112 |
(item.email ? '<span class="email">' + escape(item.email) + '</span>' : '') + |
| 113 |
'</div>'; |
| 114 |
}, |
| 115 |
option: function(item, escape) { |
| 116 |
var name = formatName(item); |
| 117 |
var label = name || item.email; |
| 118 |
var caption = name ? item.email : null; |
| 119 |
return '<div>' + |
| 120 |
'<span class="label">' + escape(label) + '</span>' + |
| 121 |
(caption ? '<span class="caption">' + escape(caption) + '</span>' : '') + |
| 122 |
'</div>'; |
| 123 |
} |
| 124 |
}, |
| 125 |
createFilter: function(input) { |
| 126 |
var regexpA = new RegExp('^' + REGEX_EMAIL + '$', 'i'); |
| 127 |
var regexpB = new RegExp('^([^<]*)\<' + REGEX_EMAIL + '\>$', 'i'); |
| 128 |
return regexpA.test(input) || regexpB.test(input); |
| 129 |
}, |
| 130 |
create: function(input) { |
| 131 |
if ((new RegExp('^' + REGEX_EMAIL + '$', 'i')).test(input)) { |
| 132 |
return {email: input}; |
| 133 |
} |
| 134 |
var match = input.match(new RegExp('^([^<]*)\<' + REGEX_EMAIL + '\>$', 'i')); |
| 135 |
if (match) { |
| 136 |
var name = $.trim(match[1]); |
| 137 |
var pos_space = name.indexOf(' '); |
| 138 |
var first_name = name.substring(0, pos_space); |
| 139 |
var last_name = name.substring(pos_space + 1); |
| 140 |
|
| 141 |
return { |
| 142 |
email: match[2], |
| 143 |
first_name: first_name, |
| 144 |
last_name: last_name |
| 145 |
}; |
| 146 |
} |
| 147 |
alert('Invalid email address.'); |
| 148 |
return false; |
| 149 |
} |
| 150 |
}); |
| 151 |
</script> |
| 152 |
</div> |
| 153 |
</div> |
| 154 |
</body> |
| 155 |
</html> |