var activeRequests = 0;
$(function() {
$('#change').text('I changed it');
$('#drag, #drag_scroll, #drag_link').draggable();
$('#drop, #drop_scroll').droppable({
tolerance: 'touch',
drop: function(event, ui) {
ui.draggable.remove();
$(this).html('Dropped!');
}
});
$('#drag_html5, #drag_html5_scroll').on('dragstart', function(ev){
ev.originalEvent.dataTransfer.setData("text", ev.target.id);
});
$('#drop_html5, #drop_html5_scroll').on('dragover', function(ev){
$(this).after('
DragOver with client position: ' + ev.clientX + ',' + ev.clientY)
if ($(this).hasClass('drop')) { ev.preventDefault(); }
});
$('#drop_html5, #drop_html5_scroll').on('drop', function(ev){
ev.preventDefault();
var oev = ev.originalEvent;
if (oev.dataTransfer.items) {
for (var i = 0; i < oev.dataTransfer.items.length; i++){
var item = oev.dataTransfer.items[i];
if (item.kind === 'file'){
var file = item.getAsFile();
$(this).append('HTML5 Dropped file: ' + file.name);
} else {
var _this = this;
var callback = (function(type){
return function(s){
$(_this).append('HTML5 Dropped string: ' + type + ' ' + s)
}
})(item.type);
item.getAsString(callback);
}
}
} else {
$(this).html('HTML5 Dropped ' + oev.dataTransfer.getData("text"));
for (var i = 0; i < oev.dataTransfer.files.length; i++) {
$(this).append('HTML5 Dropped file: ' + oev.dataTransfer.files[i].name);
}
for (var i = 0; i < oev.dataTransfer.types.length; i++) {
var type = oev.dataTransfer.types[i];
$(this).append('HTML5 Dropped string: ' + type + ' ' + oev.dataTransfer.getData(type));
}
}
});
$('#clickable').click(function(e) {
var link = $(this);
setTimeout(function() {
$(link).after('
Has been clicked');
$(link).after('
');
$(link).after('
');
$('#change').remove();
}, 1000);
return false;
});
$('#slow-click').click(function() {
var link = $(this);
setTimeout(function() {
$(link).after('
Slow link clicked');
}, 4000);
return false;
});
$('#waiter').change(function() {
activeRequests = 1;
setTimeout(function() {
activeRequests = 0;
}, 500);
});
$('#with_focus_event').focus(function() {
$('body').append('
Focus Event triggered
');
});
$('#with_change_event').change(function() {
$('body').append($('
').text(this.value));
});
$('#with_change_event').on('input', function() {
$('body').append($('
').text(this.value));
});
$('#checkbox_with_event').click(function() {
$('body').append('
Checkbox event triggered
');
});
$('#fire_ajax_request').click(function() {
$.ajax({url: "/slow_response", context: document.body, success: function() {
$('body').append('
Ajax request done
');
}});
});
$('#reload-link').click(function() {
setTimeout(function() {
$('#reload-me').replaceWith('
');
}, 250)
});
$('#reload-list').click(function() {
setTimeout(function() {
$('#the-list').html('
FooBar');
}, 550)
});
$('#change-title').click(function() {
setTimeout(function() {
$('title').text('changed title')
}, 400)
});
$('#change-size').click(function() {
setTimeout(function() {
document.getElementById('change').style.fontSize = '50px';
}, 500)
});
$('#click-test').on({
click: function(e) {
var desc = "";
if (e.altKey) desc += 'alt ';
if (e.ctrlKey) desc += 'control ';
if (e.metaKey) desc += 'meta ';
if (e.shiftKey) desc += 'shift ';
var pos = this.getBoundingClientRect();
$(this).after('
Has been ' + desc + 'clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '');
},
dblclick: function(e) {
var desc = "";
if (e.altKey) desc += 'alt ';
if (e.ctrlKey) desc += 'control ';
if (e.metaKey) desc += 'meta ';
if (e.shiftKey) desc += 'shift ';
var pos = this.getBoundingClientRect();
$(this).after('
Has been ' + desc + 'double clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '');
},
contextmenu: function(e) {
e.preventDefault();
var desc = "";
if (e.altKey) desc += 'alt ';
if (e.ctrlKey) desc += 'control ';
if (e.metaKey) desc += 'meta ';
if (e.shiftKey) desc += 'shift ';
var pos = this.getBoundingClientRect();
$(this).after('
Has been ' + desc + 'right clicked at ' + (e.clientX - pos.left) + ',' + (e.clientY - pos.top) + '');
}
});
$('#open-alert').click(function() {
alert('Alert opened [*Yay?*]');
$(this).attr('opened', 'true');
});
$('#open-delayed-alert').click(function() {
var link = this;
setTimeout(function() {
alert('Delayed alert opened');
$(link).attr('opened', 'true');
}, 250);
});
$('#open-slow-alert').click(function() {
var link = this;
setTimeout(function() {
alert('Delayed alert opened');
$(link).attr('opened', 'true');
}, 3000);
});
$('#alert-page-change').click(function() {
alert('Page is changing');
return true;
});
$('#open-confirm').click(function() {
if(confirm('Confirm opened')) {
$(this).attr('confirmed', 'true');
} else {
$(this).attr('confirmed', 'false');
}
});
$('#open-prompt').click(function() {
var response = prompt('Prompt opened');
if(response === null) {
$(this).attr('response', 'dismissed');
} else {
$(this).attr('response', response);
}
});
$('#open-prompt-with-default').click(function() {
var response = prompt('Prompt opened', 'Default value!');
if(response === null) {
$(this).attr('response', 'dismissed');
} else {
$(this).attr('response', response);
}
});
$('#open-twice').click(function() {
if (confirm('Are you sure?')) {
if (!confirm('Are you really sure?')) {
$(this).attr('confirmed', 'false');
}
}
});
$('#delayed-page-change').click(function() {
setTimeout(function() {
window.location.pathname = '/with_html'
}, 500)
});
$('#with-key-events').keydown(function(e){
$('#key-events-output').append('keydown:'+e.which+' ')
});
$('#disable-on-click').click(function(e){
var input = this;
setTimeout(function() {
input.disabled = true;
}, 500)
});
$('#set-storage').click(function(e){
sessionStorage.setItem('session', 'session_value');
localStorage.setItem('local', 'local value');
});
$('#multiple-file, #hidden_file').change(function(e){
$('body').append($('
File input changed
'));
})
});