1
0
mirror of https://github.com/owncloud/bookmarks.git synced 2025-02-18 15:54:28 +01:00

Bookmark: prevent adding empty bookmarks fix #149

This commit is contained in:
Brice Maron 2012-11-05 21:12:00 +00:00
parent 20a779eea9
commit 8d69711a08
2 changed files with 33 additions and 3 deletions

View File

@ -4,6 +4,12 @@
#firstrun .button { font-size: 0.7em; }
#firstrun #selections { font-size:0.8em; font-weight: normal; width: 100%; margin: 2em auto auto auto; clear: both; }
input.disabled, input.disabled:hover {
cursor: not-allowed;
background-color: #ddd;
color: gray;
}
#leftcontent {
padding-top: 1em;
}

View File

@ -6,12 +6,12 @@ var bookmarks_sorting = 'bookmarks_sorting_recent';
var bookmark_view = 'image';
$(document).ready(function() {
watchUrlField();
$('.centercontent').click(clickSideBar);
$('#view_type input').click(clickSwitchView);
$('#add_form').submit(addBookmark);
// $('#bm_import_submit').click(attachSettingEvent);
$('#bm_import').change(attachSettingEvent);
$('#add_url').on('keydown keyup change click', watchUrlField);
$('#settingsbtn').on('click keydown', function() {
if( $('#bookmark_settings').hasClass('open'))
$('#bookmark_settings').switchClass( "open", "" );
@ -189,9 +189,33 @@ function createEditDialog(record){
});
}
function watchUrlField(){
var form = $('#add_form');
var el = $('#add_url');
var button = $('#bookmark_add_submit');
form.unbind('submit');
if(! acceptUrl(el.val()) ) {
form.bind('submit',function(e){e.preventDefault()});
button.addClass('disabled');
}
else{
button.removeClass('disabled');
form.bind('submit',addBookmark);
}
}
function acceptUrl(url) {
return url.replace(/^\s+/g,'').replace(/\s+$/g,'') != '';
}
function addBookmark(event) {
event.preventDefault();
url = $('#add_url').val();
//If trim is empty
if(! acceptUrl(url) ) {
return;
}
$('#add_url').val('');
bookmark = { url: url, description:'', title:'', from_own: '1'};
$.ajax({