#2439 library version update JQuery / JQuery.Selection / JQuery.hotkey (#3183)

This commit is contained in:
Takahito Yamatoya 2017-09-18 18:45:57 +09:00 committed by stuart nelson
parent 3369422327
commit 5d707d3aa3
4 changed files with 199 additions and 192 deletions

File diff suppressed because one or more lines are too long

View file

@ -13,7 +13,7 @@
(function(jQuery){
jQuery.hotkeys = {
version: "0.8",
version: "0.8+",
specialKeys: {
8: "backspace", 9: "tab", 13: "return", 16: "shift", 17: "ctrl", 18: "alt", 19: "pause",
@ -22,7 +22,8 @@
96: "0", 97: "1", 98: "2", 99: "3", 100: "4", 101: "5", 102: "6", 103: "7",
104: "8", 105: "9", 106: "*", 107: "+", 109: "-", 110: ".", 111 : "/",
112: "f1", 113: "f2", 114: "f3", 115: "f4", 116: "f5", 117: "f6", 118: "f7", 119: "f8",
120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 191: "/", 224: "meta"
120: "f9", 121: "f10", 122: "f11", 123: "f12", 144: "numlock", 145: "scroll", 188: ",", 190: ".",
191: "/", 224: "meta"
},
shiftNums: {
@ -33,19 +34,31 @@
};
function keyHandler( handleObj ) {
// Only care when a possible input has been specified
if ( typeof handleObj.data !== "string" ) {
var origHandler = handleObj.handler,
//use namespace as keys so it works with event delegation as well
//will also allow removing listeners of a specific key combination
//and support data objects
keys = (handleObj.namespace || "").toLowerCase().split(" ");
keys = jQuery.map(keys, function(key) { return key.split("."); });
//no need to modify handler if no keys specified
//Added keys[0].substring(0, 12) to work with jQuery ui 1.9.0
//Added accordion, tabs and menu, then jquery ui can use keys.
if (keys.length === 1 && (keys[0] === "" ||
keys[0].substring(0, 12) === "autocomplete" ||
keys[0].substring(0, 9) === "accordion" ||
keys[0].substring(0, 4) === "tabs" ||
keys[0].substring(0, 4) === "menu")) {
return;
}
var origHandler = handleObj.handler,
keys = handleObj.data.toLowerCase().split(" "),
textAcceptingInputTypes = ["text", "password", "number", "email", "url", "range", "date", "month", "week", "time", "datetime", "datetime-local", "search", "color"];
handleObj.handler = function( event ) {
// Don't fire in text-accepting inputs that we didn't directly bind to
// important to note that $.fn.prop is only available on jquery 1.6+
if ( this !== event.target && (/textarea|select/i.test( event.target.nodeName ) ||
jQuery.inArray(event.target.type, textAcceptingInputTypes) > -1 ) ) {
event.target.type === "text" || $(event.target).prop('contenteditable') == 'true' )) {
return;
}
@ -56,20 +69,20 @@
// check combinations (alt|ctrl|shift+anything)
if ( event.altKey && special !== "alt" ) {
modif += "alt+";
modif += "alt_";
}
if ( event.ctrlKey && special !== "ctrl" ) {
modif += "ctrl+";
modif += "ctrl_";
}
// TODO: Need to make sure this works consistently across platforms
if ( event.metaKey && !event.ctrlKey && special !== "meta" ) {
modif += "meta+";
modif += "meta_";
}
if ( event.shiftKey && special !== "shift" ) {
modif += "shift+";
modif += "shift_";
}
if ( special ) {
@ -80,7 +93,7 @@
possible[ modif + jQuery.hotkeys.shiftNums[ character ] ] = true;
// "$" can be triggered as "Shift+4" or "Shift+$" or just "$"
if ( modif === "shift+" ) {
if ( modif === "shift_" ) {
possible[ jQuery.hotkeys.shiftNums[ character ] ] = true;
}
}

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
/*!
* jQuery.selection - jQuery Plugin
*
* Copyright (c) 2010-2012 IWASAKI Koji (@madapaja).
* Copyright (c) 2010-2014 IWASAKI Koji (@madapaja).
* http://blog.madapaja.net/
* Under The MIT License
*
@ -26,13 +26,13 @@
*/
(function($, win, doc) {
/**
* 要素の文字列選択状態を取得します
* get caret status of the selection of the element
*
* @param {Element} element 対象要素
* @param {Element} element target DOM element
* @return {Object} return
* @return {String} return.text 選択されている文字列
* @return {Integer} return.start 選択開始位置
* @return {Integer} return.end 選択終了位置
* @return {String} return.text selected text
* @return {Number} return.start start position of the selection
* @return {Number} return.end end position of the selection
*/
var _getCaretInfo = function(element){
var res = {
@ -42,13 +42,13 @@
};
if (!element.value) {
/* 値がない、もしくは空文字列 */
/* no value or empty string */
return res;
}
try {
if (win.getSelection) {
/* IE 以外 */
/* except IE */
res.start = element.selectionStart;
res.end = element.selectionEnd;
res.text = element.value.slice(res.start, res.end);
@ -57,8 +57,7 @@
element.focus();
var range = doc.selection.createRange(),
range2 = doc.body.createTextRange(),
tmpLength;
range2 = doc.body.createTextRange();
res.text = range.text;
@ -74,24 +73,24 @@
res.end = res.start + range.text.length;
}
} catch (e) {
/* あきらめる */
/* give up */
}
return res;
};
/**
* 要素に対するキャレット操作
* caret operation for the element
* @type {Object}
*/
var _CaretOperation = {
/**
* 要素のキャレット位置を取得します
* get caret position
*
* @param {Element} element 対象要素
* @param {Element} element target element
* @return {Object} return
* @return {Integer} return.start 選択開始位置
* @return {Integer} return.end 選択終了位置
* @return {Number} return.start start position for the selection
* @return {Number} return.end end position for the selection
*/
getPos: function(element) {
var tmp = _getCaretInfo(element);
@ -99,20 +98,20 @@
},
/**
* 要素のキャレット位置を設定します
* set caret position
*
* @param {Element} element 対象要素
* @param {Object} toRange 設定するキャレット位置
* @param {Integer} toRange.start 選択開始位置
* @param {Integer} toRange.end 選択終了位置
* @param {String} caret キャレットモード "keep" | "start" | "end" のいずれか
* @param {Element} element target element
* @param {Object} toRange caret position
* @param {Number} toRange.start start position for the selection
* @param {Number} toRange.end end position for the selection
* @param {String} caret caret mode: any of the following: "keep" | "start" | "end"
*/
setPos: function(element, toRange, caret) {
caret = this._caretMode(caret);
if (caret == 'start') {
if (caret === 'start') {
toRange.end = toRange.start;
} else if (caret == 'end') {
} else if (caret === 'end') {
toRange.start = toRange.end;
}
@ -135,29 +134,29 @@
element.setSelectionRange(toRange.start, toRange.end);
}
} catch (e) {
/* あきらめる */
/* give up */
}
},
/**
* 要素内の選択文字列を取得します
* get selected text
*
* @param {Element} element 対象要素
* @return {String} return 選択文字列
* @param {Element} element target element
* @return {String} return selected text
*/
getText: function(element) {
return _getCaretInfo(element).text;
},
/**
* キャレットモードを選択します
* get caret mode
*
* @param {String} caret キャレットモード
* @return {String} return "keep" | "start" | "end" のいずれか
* @param {String} caret caret mode
* @return {String} return any of the following: "keep" | "start" | "end"
*/
_caretMode: function(caret) {
caret = caret || "keep";
if (caret == false) {
if (caret === false) {
caret = 'end';
}
@ -175,11 +174,11 @@
},
/**
* 選択文字列を置き換えます
* replace selected text
*
* @param {Element} element 対象要素
* @param {String} text 置き換える文字列
* @param {String} caret キャレットモード "keep" | "start" | "end" のいずれか
* @param {Element} element target element
* @param {String} text replacement text
* @param {String} caret caret mode: any of the following: "keep" | "start" | "end"
*/
replace: function(element, text, caret) {
var tmp = _getCaretInfo(element),
@ -194,11 +193,11 @@
},
/**
* 文字列を選択文字列の前に挿入します
* insert before the selected text
*
* @param {Element} element 対象要素
* @param {String} text 挿入文字列
* @param {String} caret キャレットモード "keep" | "start" | "end" のいずれか
* @param {Element} element target element
* @param {String} text insertion text
* @param {String} caret caret mode: any of the following: "keep" | "start" | "end"
*/
insertBefore: function(element, text, caret) {
var tmp = _getCaretInfo(element),
@ -213,11 +212,11 @@
},
/**
* 文字列を選択文字列の後に挿入します
* insert after the selected text
*
* @param {Element} element 対象要素
* @param {String} text 挿入文字列
* @param {String} caret キャレットモード "keep" | "start" | "end" のいずれか
* @param {Element} element target element
* @param {String} text insertion text
* @param {String} caret caret mode: any of the following: "keep" | "start" | "end"
*/
insertAfter: function(element, text, caret) {
var tmp = _getCaretInfo(element),
@ -232,16 +231,16 @@
}
};
/* jQuery.selection を追加 */
/* add jQuery.selection */
$.extend({
/**
* ウィンドウの選択されている文字列を取得
* get selected text on the window
*
* @param {String} mode 選択モード "text" | "html" のいずれか
* @param {String} mode selection mode: any of the following: "text" | "html"
* @return {String} return
*/
selection: function(mode) {
var getText = ((mode || 'text').toLowerCase() == 'text');
var getText = ((mode || 'text').toLowerCase() === 'text');
try {
if (win.getSelection) {
@ -272,14 +271,14 @@
}
}
} catch (e) {
/* あきらめる */
/* give up */
}
return '';
}
});
/* selection を追加 */
/* add selection */
$.fn.extend({
selection: function(mode, opts) {
opts = opts || {};
@ -287,71 +286,66 @@
switch (mode) {
/**
* selection('getPos')
* キャレット位置を取得します
* get caret position
*
* @return {Object} return
* @return {Integer} return.start 選択開始位置
* @return {Integer} return.end 選択終了位置
* @return {Number} return.start start position for the selection
* @return {Number} return.end end position for the selection
*/
case 'getPos':
return _CaretOperation.getPos(this[0]);
break;
/**
* selection('setPos', opts)
* キャレット位置を設定します
* set caret position
*
* @param {Integer} opts.start 選択開始位置
* @param {Integer} opts.end 選択終了位置
* @param {Number} opts.start start position for the selection
* @param {Number} opts.end end position for the selection
*/
case 'setPos':
return this.each(function() {
_CaretOperation.setPos(this, opts);
});
break;
/**
* selection('replace', opts)
* 選択文字列を置き換えます
* replace the selected text
*
* @param {String} opts.text 置き換える文字列
* @param {String} opts.caret キャレットモード "keep" | "start" | "end" のいずれか
* @param {String} opts.text replacement text
* @param {String} opts.caret caret mode: any of the following: "keep" | "start" | "end"
*/
case 'replace':
return this.each(function() {
_CaretOperation.replace(this, opts.text, opts.caret);
});
break;
/**
* selection('insert', opts)
* 選択文字列の前もしくは後に文字列を挿入えます
* insert before/after the selected text
*
* @param {String} opts.text 挿入文字列
* @param {String} opts.caret キャレットモード "keep" | "start" | "end" のいずれか
* @param {String} opts.mode 挿入モード "before" | "after" のいずれか
* @param {String} opts.text insertion text
* @param {String} opts.caret caret mode: any of the following: "keep" | "start" | "end"
* @param {String} opts.mode insertion mode: any of the following: "before" | "after"
*/
case 'insert':
return this.each(function() {
if (opts.mode == 'before') {
if (opts.mode === 'before') {
_CaretOperation.insertBefore(this, opts.text, opts.caret);
} else {
_CaretOperation.insertAfter(this, opts.text, opts.caret);
}
});
break;
/**
* selection('get')
* 選択されている文字列を取得
* get selected text
*
* @return {String} return
*/
case 'get':
/* falls through */
default:
return _CaretOperation.getText(this[0]);
break;
}
return this;