').insertAfter(editable.input.$input);
});
//
// Input formatter
//
// Initialize editable
$('#input-formatter').editable({
emptytext: 'Your birth date'
});
// Initialize plugin and insert in editable popup on show
$('#input-formatter').on('shown', function(e, editable) {
editable.input.$input.formatter({
pattern: '{{99}}/{{99}}/{{9999}}'
});
$('99/99/9999
').insertAfter(editable.input.$input);
});
// Select2 select
// ------------------------------
// Data
var select2_countries = [];
$.each(
{
"BD": "Bangladesh",
"BE": "Belgium",
"BF": "Burkina Faso",
"BG": "Bulgaria",
"BA": "Bosnia and Herzegovina",
"BB": "Barbados",
"WF": "Wallis and Futuna",
"BL": "Saint Bartelemey",
"BM": "Bermuda",
"BN": "Brunei Darussalam",
"BO": "Bolivia",
"BH": "Bahrain",
"BI": "Burundi",
"BJ": "Benin",
"BT": "Bhutan",
"JM": "Jamaica",
"BV": "Bouvet Island",
"BW": "Botswana",
"WS": "Samoa",
"BR": "Brazil",
"BS": "Bahamas",
"JE": "Jersey",
"BY": "Belarus",
"O1": "Other Country",
"LV": "Latvia",
"RW": "Rwanda",
"RS": "Serbia",
"TL": "Timor-Leste",
"RE": "Reunion",
"LU": "Luxembourg",
"TJ": "Tajikistan",
"RO": "Romania",
"PG": "Papua New Guinea",
"GW": "Guinea-Bissau",
"GU": "Guam",
"GT": "Guatemala",
"GS": "South Georgia and the South Sandwich Islands",
"GR": "Greece",
}, function(k, v) {
select2_countries.push({id: k, text: v});
}
);
// Single select
$('#select2-single').editable({
source: select2_countries,
select2: {
width: 200,
placeholder: 'Select country',
allowClear: true
}
});
// Multiple select
$('#select2-multiple').editable({
showbuttons: 'bottom',
select2: {
width: 300,
tags: ['html', 'javascript', 'css', 'ajax'],
tokenSeparators: [",", " "],
multiple: true,
placeholder: 'Select something'
}
});
//
// Remote source
//
// Initialize
$('#select2-single-remote').editable({
select2: {
width: '300',
placeholder: 'Select Country',
minimumInputLength: 1,
ajax: { // instead of writing the function to execute the request we use Select2's convenient helper
url: "http://api.rottentomatoes.com/api/public/v1.0/movies.json",
dataType: 'jsonp',
data: function (term, page) {
return {
q: term, // search term
page_limit: 10,
apikey: "ju6z9mjyajq2djue3gbvv26t" // please do not use so this example keeps working
};
},
results: function (data, page) { // parse the results into the format expected by Select2.
// since we are using custom formatting functions we do not need to alter remote JSON data
return {results: data.movies};
}
},
initSelection: function(element, callback) {
// the input tag has a value attribute preloaded that points to a preselected movie's id
// this function resolves that id attribute to an object that select2 can render
// using its formatResult renderer - that way the movie name is shown preselected
var id=$(element).val();
if (id!=="") {
$.ajax("http://api.rottentomatoes.com/api/public/v1.0/movies/"+id+".json", {
data: {
apikey: "ju6z9mjyajq2djue3gbvv26t"
},
dataType: "jsonp"
}).done(function(data) { callback(data); });
}
},
formatResult: movieFormatResult, // omitted for brevity, see the source of this page
formatSelection: movieFormatSelection, // omitted for brevity, see the source of this page
dropdownCssClass: "bigdrop", // apply css that makes the dropdown taller
escapeMarkup: function (m) { return m; } // we do not want to escape markup since we are displaying html in results
}
});
// Format results
function movieFormatResult(movie) {
var markup = "