Update jquery.ime from upstream
Version 0.1.0.20130522 Changes: * Correct the versioning by adding build date metadata * Remove an unwanted css style * Avoid screen jump on click of IME menu items * AltGr+M doesn't create a µ * Code cleanup Change-Id: Ia9ccd89a24f4d8627cf3a16f59984ad79f3d49f5
This commit is contained in:
@@ -63,10 +63,6 @@ span.ime-disable-shortcut {
|
|||||||
padding-right: 4px;
|
padding-right: 4px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.ime-disable-link:hover span {
|
|
||||||
color: #eee;
|
|
||||||
}
|
|
||||||
|
|
||||||
.ime-list-title,
|
.ime-list-title,
|
||||||
.ime-lang-title {
|
.ime-lang-title {
|
||||||
color: #39d;
|
color: #39d;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
/*! jquery.ime - v0.1.0 - 2013-05-17
|
/*! jquery.ime - v0.1.0+20130522
|
||||||
* https://github.com/wikimedia/jquery.ime
|
* https://github.com/wikimedia/jquery.ime
|
||||||
* Copyright (c) 2013 Santhosh Thottingal; Licensed GPL, MIT */
|
* Copyright (c) 2013 Santhosh Thottingal; Licensed GPL, MIT */
|
||||||
( function ( $ ) {
|
( function ( $ ) {
|
||||||
@@ -483,6 +483,8 @@
|
|||||||
( function ( $ ) {
|
( function ( $ ) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
var selectorTemplate, MutationObserver;
|
||||||
|
|
||||||
function IMESelector ( element, options ) {
|
function IMESelector ( element, options ) {
|
||||||
this.$element = $( element );
|
this.$element = $( element );
|
||||||
this.options = $.extend( {}, IMESelector.defaults, options );
|
this.options = $.extend( {}, IMESelector.defaults, options );
|
||||||
@@ -544,7 +546,7 @@
|
|||||||
'marginTop': '-20px'
|
'marginTop': '-20px'
|
||||||
}, 500, function () {
|
}, 500, function () {
|
||||||
imeselector.$imeSetting.hide();
|
imeselector.$imeSetting.hide();
|
||||||
// Restore properties for next time it becomes visible:
|
// Restore properties for the next time it becomes visible:
|
||||||
imeselector.$imeSetting.css( 'opacity', 1 );
|
imeselector.$imeSetting.css( 'opacity', 1 );
|
||||||
imeselector.$imeSetting.css( 'margin-top', 0 );
|
imeselector.$imeSetting.css( 'margin-top', 0 );
|
||||||
} );
|
} );
|
||||||
@@ -563,12 +565,14 @@
|
|||||||
this.$menu.addClass( 'open' );
|
this.$menu.addClass( 'open' );
|
||||||
this.stopTimer();
|
this.stopTimer();
|
||||||
this.$imeSetting.show();
|
this.$imeSetting.show();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
hide: function () {
|
hide: function () {
|
||||||
this.$menu.removeClass( 'open' );
|
this.$menu.removeClass( 'open' );
|
||||||
this.resetTimer();
|
this.resetTimer();
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -588,9 +592,11 @@
|
|||||||
|
|
||||||
imeselector.$imeSetting.on( 'click.ime', function ( e ) {
|
imeselector.$imeSetting.on( 'click.ime', function ( e ) {
|
||||||
var t = $( e.target );
|
var t = $( e.target );
|
||||||
|
|
||||||
if ( t.hasClass( 'imeselector-toggle' ) ) {
|
if ( t.hasClass( 'imeselector-toggle' ) ) {
|
||||||
imeselector.toggle();
|
imeselector.toggle();
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
imeselector.$element.on( 'blur.ime', function () {
|
imeselector.$element.on( 'blur.ime', function () {
|
||||||
@@ -601,7 +607,8 @@
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
imeselector.$imeSetting.mouseenter( function () {
|
imeselector.$imeSetting.mouseenter( function () {
|
||||||
// We don't want the selector to disappear while the user is trying to click it
|
// We don't want the selector to disappear
|
||||||
|
// while the user is trying to click it
|
||||||
imeselector.stopTimer();
|
imeselector.stopTimer();
|
||||||
imeselector.$imeSetting.addClass( 'onfocus' );
|
imeselector.$imeSetting.addClass( 'onfocus' );
|
||||||
} ).mouseleave( function () {
|
} ).mouseleave( function () {
|
||||||
@@ -611,23 +618,22 @@
|
|||||||
|
|
||||||
imeselector.$menu.on( 'click.ime', 'li', function() {
|
imeselector.$menu.on( 'click.ime', 'li', function() {
|
||||||
imeselector.$element.focus();
|
imeselector.$element.focus();
|
||||||
|
return false;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
imeselector.$menu.on( 'click.ime', 'li.ime-im', function ( e ) {
|
imeselector.$menu.on( 'click.ime', 'li.ime-im', function () {
|
||||||
imeselector.selectIM( $( this ).data( 'ime-inputmethod' ) );
|
imeselector.selectIM( $( this ).data( 'ime-inputmethod' ) );
|
||||||
e.stopPropagation();
|
return false;
|
||||||
} );
|
} );
|
||||||
|
|
||||||
imeselector.$menu.on( 'click.ime', 'li.ime-lang', function ( e ) {
|
imeselector.$menu.on( 'click.ime', 'li.ime-lang', function () {
|
||||||
imeselector.selectLanguage( $( this ).attr( 'lang' ) );
|
imeselector.selectLanguage( $( this ).attr( 'lang' ) );
|
||||||
e.stopPropagation();
|
return false;
|
||||||
e.preventDefault();
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
imeselector.$menu.on( 'click.ime', 'div.ime-disable', function ( e ) {
|
imeselector.$menu.on( 'click.ime', 'div.ime-disable', function () {
|
||||||
imeselector.disableIM();
|
imeselector.disableIM();
|
||||||
e.stopPropagation();
|
return false;
|
||||||
e.preventDefault();
|
|
||||||
} );
|
} );
|
||||||
|
|
||||||
imeselector.$element.on( 'focus.ime', function ( e ) {
|
imeselector.$element.on( 'focus.ime', function ( e ) {
|
||||||
@@ -646,8 +652,8 @@
|
|||||||
imeselector.$element.on( 'mouseup.ime', $.proxy( this.position, this ) );
|
imeselector.$element.on( 'mouseup.ime', $.proxy( this.position, this ) );
|
||||||
imeselector.$element.on( 'keydown.ime', $.proxy( this.keydown, this ) );
|
imeselector.$element.on( 'keydown.ime', $.proxy( this.keydown, this ) );
|
||||||
|
|
||||||
// Update IM selector position when window is resized
|
// Update IM selector position when the window is resized
|
||||||
// or browser window is zoomed in or zoomed out
|
// or the browser window is zoomed in or zoomed out
|
||||||
$( window ).resize( function () {
|
$( window ).resize( function () {
|
||||||
imeselector.position();
|
imeselector.position();
|
||||||
} );
|
} );
|
||||||
@@ -661,7 +667,9 @@
|
|||||||
*/
|
*/
|
||||||
keydown: function ( e ) {
|
keydown: function ( e ) {
|
||||||
var ime = $( e.target ).data( 'ime' );
|
var ime = $( e.target ).data( 'ime' );
|
||||||
|
|
||||||
this.focus(); // shows the trigger in case it is hidden
|
this.focus(); // shows the trigger in case it is hidden
|
||||||
|
|
||||||
if ( isShortcutKey( e ) ) {
|
if ( isShortcutKey( e ) ) {
|
||||||
if ( ime.isActive() ) {
|
if ( ime.isActive() ) {
|
||||||
this.disableIM();
|
this.disableIM();
|
||||||
@@ -686,33 +694,42 @@
|
|||||||
* Position the im selector relative to the edit area
|
* Position the im selector relative to the edit area
|
||||||
*/
|
*/
|
||||||
position: function () {
|
position: function () {
|
||||||
this.focus(); // shows the trigger in case it is hidden
|
|
||||||
var imeSelector = this,
|
var imeSelector = this,
|
||||||
position, top, left, room;
|
position, top, left, room;
|
||||||
|
|
||||||
|
this.focus(); // shows the trigger in case it is hidden
|
||||||
|
|
||||||
position = this.$element.offset();
|
position = this.$element.offset();
|
||||||
top = position.top + this.$element.outerHeight();
|
top = position.top + this.$element.outerHeight();
|
||||||
left = position.left;
|
left = position.left;
|
||||||
// RTL element position fix:
|
|
||||||
|
// RTL element position fix
|
||||||
if ( this.$element.css( 'direction' ) === 'ltr' ) {
|
if ( this.$element.css( 'direction' ) === 'ltr' ) {
|
||||||
left = position.left + this.$element.outerWidth() -
|
left = position.left + this.$element.outerWidth() -
|
||||||
this.$imeSetting.outerWidth();
|
this.$imeSetting.outerWidth();
|
||||||
}
|
}
|
||||||
room = $( window ).height() - top;
|
|
||||||
|
// While determining whether to place the selector above or below the input box,
|
||||||
|
// take into account the value of scrollTop, to avoid the selector from always
|
||||||
|
// getting placed above the input box since window.height would be less than top
|
||||||
|
// if the page has been scrolled.
|
||||||
|
room = $( window ).height() + $( document ).scrollTop() - top;
|
||||||
|
|
||||||
if ( room < this.$imeSetting.outerHeight() ) {
|
if ( room < this.$imeSetting.outerHeight() ) {
|
||||||
top = position.top - this.$imeSetting.outerHeight();
|
top = position.top - this.$imeSetting.outerHeight();
|
||||||
|
|
||||||
this.$menu.css( 'top',
|
this.$menu
|
||||||
|
.addClass( 'position-top' )
|
||||||
|
.css( 'top',
|
||||||
- ( this.$menu.outerHeight() +
|
- ( this.$menu.outerHeight() +
|
||||||
this.$imeSetting.outerHeight() )
|
this.$imeSetting.outerHeight() )
|
||||||
)
|
);
|
||||||
.addClass( 'position-top' );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.$element.parents().each( function() {
|
this.$element.parents().each( function() {
|
||||||
if ( $( this ).css( 'position' ) === 'fixed' ) {
|
if ( $( this ).css( 'position' ) === 'fixed' ) {
|
||||||
imeSelector.$imeSetting.css( 'position', 'fixed' );
|
imeSelector.$imeSetting.css( 'position', 'fixed' );
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
} );
|
} );
|
||||||
@@ -722,15 +739,15 @@
|
|||||||
left: left
|
left: left
|
||||||
} );
|
} );
|
||||||
|
|
||||||
if ( parseInt( this.$menu.css( 'min-width' ) ) > left ) {
|
if ( parseInt( this.$menu.css( 'min-width' ), 10 ) > left ) {
|
||||||
// RTL element position fix
|
// RTL element position fix
|
||||||
if ( this.$element.css( 'direction' ) === 'rtl' ) {
|
if ( this.$element.css( 'direction' ) === 'rtl' ) {
|
||||||
this.$menu
|
this.$menu
|
||||||
.css( { left: 0 } )
|
.css( 'left', 0 )
|
||||||
.addClass( 'left' );
|
.addClass( 'left' );
|
||||||
} else {
|
} else {
|
||||||
this.$menu
|
this.$menu
|
||||||
.css( { left: position.left } )
|
.css( 'left', position.left )
|
||||||
.addClass( 'right' );
|
.addClass( 'right' );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -742,20 +759,21 @@
|
|||||||
* @param languageCode
|
* @param languageCode
|
||||||
*/
|
*/
|
||||||
selectLanguage: function ( languageCode ) {
|
selectLanguage: function ( languageCode ) {
|
||||||
var language, ime;
|
var ime,
|
||||||
|
|
||||||
ime = this.$element.data( 'ime' );
|
|
||||||
language = $.ime.languages[languageCode];
|
language = $.ime.languages[languageCode];
|
||||||
|
|
||||||
if ( !language ) {
|
if ( !language ) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ime = this.$element.data( 'ime' );
|
||||||
|
|
||||||
if ( ime.getLanguage() === languageCode ) {
|
if ( ime.getLanguage() === languageCode ) {
|
||||||
// nothing to do. It is same as the current language
|
// Nothing to do. It is same as the current language,
|
||||||
// but check whether input method changed
|
// but check whether the input method changed.
|
||||||
if ( ime.inputmethod &&
|
if ( ime.inputmethod &&
|
||||||
ime.inputmethod.id === $.ime.preferences.getIM( languageCode ) ) {
|
ime.inputmethod.id === $.ime.preferences.getIM( languageCode )
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -778,14 +796,19 @@
|
|||||||
*/
|
*/
|
||||||
decideLanguage : function () {
|
decideLanguage : function () {
|
||||||
if ( $.ime.preferences.getLanguage() ) {
|
if ( $.ime.preferences.getLanguage() ) {
|
||||||
// There has been an override by the user return the language selected by user
|
// There has been an override by the user,
|
||||||
|
// so return the language selected by user
|
||||||
return $.ime.preferences.getLanguage();
|
return $.ime.preferences.getLanguage();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this.$element.attr('lang' ) &&
|
if ( this.$element.attr('lang' ) &&
|
||||||
$.ime.languages[this.$element.attr('lang')] ) {
|
$.ime.languages[ this.$element.attr( 'lang' ) ]
|
||||||
|
) {
|
||||||
return this.$element.attr( 'lang' );
|
return this.$element.attr( 'lang' );
|
||||||
}
|
}
|
||||||
// There is either no IMs for the given language attr or there is no lang attr at all.
|
|
||||||
|
// There is either no IMs for the given language attr
|
||||||
|
// or there is no lang attr at all.
|
||||||
return $.ime.preferences.getDefaultLanguage();
|
return $.ime.preferences.getDefaultLanguage();
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -806,6 +829,7 @@
|
|||||||
|
|
||||||
if ( inputmethodId === 'system' ) {
|
if ( inputmethodId === 'system' ) {
|
||||||
this.disableIM();
|
this.disableIM();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -814,18 +838,17 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
ime.load( inputmethodId, function () {
|
ime.load( inputmethodId, function () {
|
||||||
var name;
|
|
||||||
|
|
||||||
imeselector.inputmethod = $.ime.inputmethods[inputmethodId];
|
imeselector.inputmethod = $.ime.inputmethods[inputmethodId];
|
||||||
imeselector.hide();
|
imeselector.hide();
|
||||||
ime.enable();
|
ime.enable();
|
||||||
name = imeselector.inputmethod.name;
|
|
||||||
ime.setIM( inputmethodId );
|
ime.setIM( inputmethodId );
|
||||||
imeselector.$imeSetting.find( 'a.ime-name' ).text( name );
|
imeselector.$imeSetting.find( 'a.ime-name' ).text(
|
||||||
|
imeselector.inputmethod.name
|
||||||
|
);
|
||||||
|
|
||||||
imeselector.position();
|
imeselector.position();
|
||||||
|
|
||||||
// save this preference
|
// Save this preference
|
||||||
$.ime.preferences.save();
|
$.ime.preferences.save();
|
||||||
} );
|
} );
|
||||||
},
|
},
|
||||||
@@ -841,7 +864,7 @@
|
|||||||
this.hide();
|
this.hide();
|
||||||
this.position();
|
this.position();
|
||||||
|
|
||||||
// save this preference
|
// Save this preference
|
||||||
$.ime.preferences.save();
|
$.ime.preferences.save();
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -858,8 +881,8 @@
|
|||||||
languageCode,
|
languageCode,
|
||||||
language;
|
language;
|
||||||
|
|
||||||
// Language list can be very long. So we use a container with
|
// Language list can be very long, so we use a container with
|
||||||
// overflow auto.
|
// overflow auto
|
||||||
$languageListWrapper = $( '<div class="ime-language-list-wrapper">' );
|
$languageListWrapper = $( '<div class="ime-language-list-wrapper">' );
|
||||||
$languageList = $( '<ul class="ime-language-list">' );
|
$languageList = $( '<ul class="ime-language-list">' );
|
||||||
|
|
||||||
@@ -937,6 +960,7 @@
|
|||||||
return this.each( function () {
|
return this.each( function () {
|
||||||
var $this = $( this ),
|
var $this = $( this ),
|
||||||
data = $this.data( 'imeselector' );
|
data = $this.data( 'imeselector' );
|
||||||
|
|
||||||
if ( !data ) {
|
if ( !data ) {
|
||||||
$this.data( 'imeselector', ( data = new IMESelector( this, options ) ) );
|
$this.data( 'imeselector', ( data = new IMESelector( this, options ) ) );
|
||||||
}
|
}
|
||||||
@@ -978,12 +1002,13 @@
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var selectorTemplate = '<div class="imeselector imeselector-toggle">'
|
selectorTemplate = '<div class="imeselector imeselector-toggle">' +
|
||||||
+ '<a class="ime-name imeselector-toggle" href="#"></a>'
|
'<a class="ime-name imeselector-toggle" href="#"></a>' +
|
||||||
+ '<b class="ime-setting-caret imeselector-toggle"></b></div>',
|
'<b class="ime-setting-caret imeselector-toggle"></b></div>';
|
||||||
|
|
||||||
MutationObserver = window.MutationObserver || window.WebKitMutationObserver
|
MutationObserver = window.MutationObserver ||
|
||||||
|| window.MozMutationObserver;
|
window.WebKitMutationObserver ||
|
||||||
|
window.MozMutationObserver;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether a keypress event corresponds to the shortcut key
|
* Check whether a keypress event corresponds to the shortcut key
|
||||||
@@ -994,7 +1019,7 @@
|
|||||||
function isShortcutKey ( event ) {
|
function isShortcutKey ( event ) {
|
||||||
// 77 - The letter M, for Ctrl-M
|
// 77 - The letter M, for Ctrl-M
|
||||||
// 13 - The Enter key
|
// 13 - The Enter key
|
||||||
return event.ctrlKey && ( event.which === 77 || event.which === 13 );
|
return event.ctrlKey && !event.altKey && ( event.which === 77 || event.which === 13 );
|
||||||
}
|
}
|
||||||
|
|
||||||
function isDOMAttrModifiedSupported () {
|
function isDOMAttrModifiedSupported () {
|
||||||
@@ -1020,11 +1045,7 @@
|
|||||||
|
|
||||||
$.fn.attrchange = function ( callback ) {
|
$.fn.attrchange = function ( callback ) {
|
||||||
if ( MutationObserver ) {
|
if ( MutationObserver ) {
|
||||||
var observer,
|
var observer;
|
||||||
options = {
|
|
||||||
subtree: false,
|
|
||||||
attributes: true
|
|
||||||
};
|
|
||||||
|
|
||||||
observer = new MutationObserver( function ( mutations ) {
|
observer = new MutationObserver( function ( mutations ) {
|
||||||
mutations.forEach( function ( e ) {
|
mutations.forEach( function ( e ) {
|
||||||
@@ -1033,9 +1054,11 @@
|
|||||||
} );
|
} );
|
||||||
|
|
||||||
return this.each( function () {
|
return this.each( function () {
|
||||||
observer.observe( this, options );
|
observer.observe( this, {
|
||||||
|
subtree: false,
|
||||||
|
attributes: true
|
||||||
|
} );
|
||||||
} );
|
} );
|
||||||
|
|
||||||
} else if ( isDOMAttrModifiedSupported() ) {
|
} else if ( isDOMAttrModifiedSupported() ) {
|
||||||
return this.on( 'DOMAttrModified', function ( e ) {
|
return this.on( 'DOMAttrModified', function ( e ) {
|
||||||
callback.call( this, e.attrName );
|
callback.call( this, e.attrName );
|
||||||
@@ -1046,11 +1069,8 @@
|
|||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
}( jQuery ) );
|
}( jQuery ) );
|
||||||
|
|
||||||
|
|
||||||
( function ( $ ) {
|
( function ( $ ) {
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user