Update Autocomplete plugin for reusable notice forms in 1.0.x. It's fun!
Now pulls the fetch API URL from a dedicated <span> with a data attribute ('data-url', should pass HTML 5 validators for our future overlords)
This commit is contained in:
parent
ec828a094c
commit
4915b0cb9e
|
@ -1,4 +1,15 @@
|
||||||
$(document).ready(function(){
|
(function(SN, $) {
|
||||||
|
|
||||||
|
var origInit = SN.Init.NoticeFormSetup;
|
||||||
|
SN.Init.NoticeFormSetup = function(form) {
|
||||||
|
origInit(form);
|
||||||
|
|
||||||
|
// Only attach to traditional-style forms
|
||||||
|
var textarea = form.find('.notice_data-text:first');
|
||||||
|
if (textarea.length == 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
function fullName(row) {
|
function fullName(row) {
|
||||||
if (typeof row.fullname == "string" && row.fullname != '') {
|
if (typeof row.fullname == "string" && row.fullname != '') {
|
||||||
return row.nickname + ' (' + row.fullname + ')';
|
return row.nickname + ' (' + row.fullname + ')';
|
||||||
|
@ -6,7 +17,9 @@ $(document).ready(function(){
|
||||||
return row.nickname;
|
return row.nickname;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$('#notice_data-text').autocomplete($('address .url')[0].href+'main/autocomplete/suggest', {
|
|
||||||
|
var apiUrl = $('#autocomplete-api').attr('data-url');
|
||||||
|
textarea.autocomplete(apiUrl, {
|
||||||
multiple: true,
|
multiple: true,
|
||||||
multipleSeparator: " ",
|
multipleSeparator: " ",
|
||||||
minChars: 1,
|
minChars: 1,
|
||||||
|
@ -35,4 +48,6 @@ $(document).ready(function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
};
|
||||||
|
|
||||||
|
})(SN, jQuery);
|
||||||
|
|
|
@ -51,6 +51,8 @@ class AutocompletePlugin extends Plugin
|
||||||
|
|
||||||
function onEndShowScripts($action){
|
function onEndShowScripts($action){
|
||||||
if (common_logged_in()) {
|
if (common_logged_in()) {
|
||||||
|
$action->element('span', array('id' => 'autocomplete-api',
|
||||||
|
'data-url' => common_local_url('autocomplete')));
|
||||||
$action->script($this->path('jquery-autocomplete/jquery.autocomplete.pack.js'));
|
$action->script($this->path('jquery-autocomplete/jquery.autocomplete.pack.js'));
|
||||||
$action->script($this->path('Autocomplete.js'));
|
$action->script($this->path('Autocomplete.js'));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user