var activeRequests = 0; $(function() { $('#change').text('I changed it'); $('#drag').draggable(); $('#drop').droppable({ drop: function(event, ui) { ui.draggable.remove(); $(this).html('Dropped!'); } }); $('#clickable').click(function() { var link = $(this); setTimeout(function() { $(link).after('Has been clicked'); $(link).after(''); $(link).after(''); $('#change').remove(); }, 500); 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)); }); $('#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('
has been reloaded
'); }, 250) }); $('#reload-list').click(function() { setTimeout(function() { $('#the-list').html('
  • Foo
  • Bar
  • '); }, 550) }); $('#change-title').click(function() { setTimeout(function() { $('title').text('changed title') }, 250) }); $('#click-test').on({ dblclick: function() { $(this).after('Has been double clicked'); }, contextmenu: function(e) { e.preventDefault(); $(this).after('Has been right clicked'); } }); $('#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); }); $('#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-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'); }) });