55 * See the COPYING-README file.
66 */
77
8+ /* global OC, t */
9+
10+ /**
11+ * The callback will be fired as soon as enter is pressed by the
12+ * user or 1 second after the last data entry
13+ *
14+ * @param callback
15+ */
16+ jQuery . fn . keyUpDelayedOrEnter = function ( callback ) {
17+ var cb = callback ;
18+ var that = this ;
19+ this . keyup ( _ . debounce ( function ( event ) {
20+ // enter is already handled in keypress
21+ if ( event . keyCode === 13 ) {
22+ return ;
23+ }
24+ if ( that . val ( ) !== '' ) {
25+ cb ( ) ;
26+ }
27+ } , 1000 ) ) ;
28+
29+ this . keypress ( function ( ) {
30+ if ( event . keyCode === 13 && that . val ( ) !== '' ) {
31+ event . preventDefault ( ) ;
32+ cb ( ) ;
33+ }
34+ } ) ;
35+ } ;
36+
37+
838/**
939 * Post the email address change to the server.
1040 */
@@ -42,13 +72,12 @@ function changeDisplayName(){
4272 }
4373 OC . msg . finishedSaving ( '#displaynameform .msg' , data ) ;
4474 } ) ;
45- return false ;
4675 }
4776}
4877
4978function updateAvatar ( hidedefault ) {
50- $headerdiv = $ ( '#header .avatardiv' ) ;
51- $displaydiv = $ ( '#displayavatar .avatardiv' ) ;
79+ var $headerdiv = $ ( '#header .avatardiv' ) ;
80+ var $displaydiv = $ ( '#displayavatar .avatardiv' ) ;
5281
5382 if ( hidedefault ) {
5483 $headerdiv . hide ( ) ;
@@ -65,11 +94,12 @@ function updateAvatar (hidedefault) {
6594}
6695
6796function showAvatarCropper ( ) {
68- $cropper = $ ( '#cropper' ) ;
97+ var $cropper = $ ( '#cropper' ) ;
6998 $cropper . prepend ( "<img>" ) ;
70- $cropperImage = $ ( '#cropper img' ) ;
99+ var $cropperImage = $ ( '#cropper img' ) ;
71100
72- $cropperImage . attr ( 'src' , OC . generateUrl ( '/avatar/tmp' ) + '?requesttoken=' + oc_requesttoken + '#' + Math . floor ( Math . random ( ) * 1000 ) ) ;
101+ $cropperImage . attr ( 'src' ,
102+ OC . generateUrl ( '/avatar/tmp' ) + '?requesttoken=' + oc_requesttoken + '#' + Math . floor ( Math . random ( ) * 1000 ) ) ;
73103
74104 // Looks weird, but on('load', ...) doesn't work in IE8
75105 $cropperImage . ready ( function ( ) {
@@ -90,12 +120,12 @@ function showAvatarCropper() {
90120function sendCropData ( ) {
91121 cleanCropper ( ) ;
92122
93- var cropperdata = $ ( '#cropper' ) . data ( ) ;
123+ var cropperData = $ ( '#cropper' ) . data ( ) ;
94124 var data = {
95- x : cropperdata . x ,
96- y : cropperdata . y ,
97- w : cropperdata . w ,
98- h : cropperdata . h
125+ x : cropperData . x ,
126+ y : cropperData . y ,
127+ w : cropperData . w ,
128+ h : cropperData . h
99129 } ;
100130 $ . post ( OC . generateUrl ( '/avatar/cropped' ) , { crop : data } , avatarResponseHandler ) ;
101131}
@@ -105,7 +135,7 @@ function saveCoords(c) {
105135}
106136
107137function cleanCropper ( ) {
108- $cropper = $ ( '#cropper' ) ;
138+ var $cropper = $ ( '#cropper' ) ;
109139 $ ( '#displayavatar' ) . show ( ) ;
110140 $cropper . hide ( ) ;
111141 $ ( '.jcrop-holder' ) . remove ( ) ;
@@ -114,7 +144,7 @@ function cleanCropper() {
114144}
115145
116146function avatarResponseHandler ( data ) {
117- $warning = $ ( '#avatar .warning' ) ;
147+ var $warning = $ ( '#avatar .warning' ) ;
118148 $warning . hide ( ) ;
119149 if ( data . status === "success" ) {
120150 updateAvatar ( ) ;
@@ -157,41 +187,8 @@ $(document).ready(function(){
157187
158188 } ) ;
159189
160- $ ( '#displayName' ) . keyup ( function ( ) {
161- if ( $ ( '#displayName' ) . val ( ) !== '' ) {
162- if ( typeof timeout !== 'undefined' ) {
163- clearTimeout ( timeout ) ;
164- }
165- timeout = setTimeout ( changeDisplayName , 1000 ) ;
166- }
167- } ) ;
168-
169-
170- $ ( '#email' ) . keyup ( function ( event ) {
171- if ( $ ( '#email' ) . val ( ) !== '' ) {
172- // if this is the enter key changeEmailAddress() is already invoked
173- // so it doesn't need to be triggered again
174- if ( event . keyCode === 13 ) {
175- return ;
176- }
177- if ( typeof timeout !== 'undefined' ) {
178- clearTimeout ( timeout ) ;
179- }
180- timeout = setTimeout ( changeEmailAddress , 1000 ) ;
181- }
182- } ) ;
183-
184- $ ( '#email' ) . keypress ( function ( event ) {
185- // check for enter key and non empty email
186- if ( event . keyCode === 13 && $ ( '#email' ) . val ( ) !== '' ) {
187- event . preventDefault ( )
188- // clear timeout of previous keyup event - prevents duplicate changeEmailAddress call
189- if ( typeof timeout !== 'undefined' ) {
190- clearTimeout ( timeout ) ;
191- }
192- changeEmailAddress ( ) ;
193- }
194- } ) ;
190+ $ ( '#displayName' ) . keyUpDelayedOrEnter ( changeDisplayName ) ;
191+ $ ( '#email' ) . keyUpDelayedOrEnter ( changeEmailAddress ) ;
195192
196193 $ ( "#languageinput" ) . change ( function ( ) {
197194 // Serialize the data
@@ -256,7 +253,7 @@ $(document).ready(function(){
256253 $ . ajax ( {
257254 type : 'DELETE' ,
258255 url : OC . generateUrl ( '/avatar/' ) ,
259- success : function ( msg ) {
256+ success : function ( ) {
260257 updateAvatar ( true ) ;
261258 $ ( '#removeavatar' ) . hide ( ) ;
262259 }
@@ -321,7 +318,7 @@ OC.Encryption.msg={
321318 } ,
322319 finishedDecrypting :function ( selector , data ) {
323320 if ( data . status === "success" ) {
324- $ ( selector ) . html ( data . data . message )
321+ $ ( selector ) . html ( data . data . message )
325322 . addClass ( 'success' )
326323 . stop ( true , true )
327324 . delay ( 3000 ) ;
0 commit comments