Skip to content

Commit a7f305f

Browse files
committed
Add events.js to /resources/ and update script reference in key* entries
Closes jquery#208
1 parent d7240b8 commit a7f305f

File tree

4 files changed

+35
-4
lines changed

4 files changed

+35
-4
lines changed

entries/keydown.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ input { display: block; margin-bottom: .25em; }
8787
<button id="other">
8888
Trigger the handler
8989
</button>
90-
<script type="text/javascript" src="/scripts/events.js"></script>]]></html>
90+
<script type="text/javascript" src="/resources/events.js"></script>]]></html>
9191
</example>
9292
<category slug="events/keyboard-events"/>
9393
<category slug="version/1.0"/>

entries/keypress.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
<p>Note that <code>keydown</code> and <code>keyup</code> provide a code indicating which key is pressed, while <code>keypress</code> indicates which character was entered. For example, a lowercase "a" will be reported as 65 by <code>keydown</code> and <code>keyup</code>, but as 97 by <code>keypress</code>. An uppercase "A" is reported as 65 by all events. Because of this distinction, when catching special keystrokes such as arrow keys, <code>.keydown()</code> or <code>.keyup()</code> is a better choice.</p>
5353
</longdesc>
5454
<example>
55-
<desc>Show the event object when a key is pressed in the input. Note: This demo relies on a simple $.print() plugin (http://api.jquery.com/scripts/events.js) for the event object's output.</desc>
55+
<desc>Show the event object when a key is pressed in the input. Note: This demo relies on a simple $.print() plugin (http://api.jquery.com/resources/events.js) for the event object's output.</desc>
5656
<code><![CDATA[
5757
var xTriggered = 0;
5858
$("#target").keypress(function(event) {
@@ -92,7 +92,7 @@ input { display: block; margin-bottom: .25em; }
9292
<button id="other">
9393
Trigger the handler
9494
</button>
95-
<script src="http://api.jquery.com/scripts/events.js"></script>
95+
<script src="http://api.jquery.com/resources/events.js"></script>
9696
]]></html>
9797
</example>
9898
<category slug="events/keyboard-events"/>

entries/keyup.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ input { display: block; margin-bottom: .25em; }
8989
<button id="other">
9090
Trigger the handler
9191
</button>
92-
<script type="text/javascript" src="/scripts/events.js"></script>]]></html>
92+
<script type="text/javascript" src="/resources/events.js"></script>]]></html>
9393
</example>
9494
<category slug="events/keyboard-events"/>
9595
<category slug="version/1.0"/>

resources/events.js

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
jQuery.print = function(message, insertionType) {
2+
if (typeof(message) == 'object') {
3+
var string = '{<br />',
4+
values = [],
5+
counter = 0;
6+
$.each(message, function(key, value) {
7+
if (value && value.nodeName) {
8+
var domnode = '&lt;' + value.nodeName.toLowerCase();
9+
domnode += value.className ? ' class="' + value.className + '"' : '';
10+
domnode += value.id ? ' id="' + value.id + '"' : '';
11+
domnode += '&gt;';
12+
value = domnode;
13+
}
14+
values[counter++] = key + ': ' + value;
15+
});
16+
string += values.join(',<br />');
17+
string += '<br />}';
18+
message = string;
19+
}
20+
21+
var $output = $('#print-output');
22+
23+
if ($output.length === 0) {
24+
$output = $('<div id="print-output" />').appendTo('body');
25+
}
26+
27+
var $newMessage = $('<div class="print-output-line" />');
28+
$newMessage.html(message);
29+
insertionType = insertionType || 'append';
30+
$output[insertionType]($newMessage);
31+
};

0 commit comments

Comments
 (0)