Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
sdkjs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
sdkjs
Commits
b86f6286
Commit
b86f6286
authored
Jul 06, 2016
by
Oleg Korshul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
focus
parent
e30d1027
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
274 additions
and
77 deletions
+274
-77
common/text_input.js
common/text_input.js
+274
-77
No files found.
common/text_input.js
View file @
b86f6286
...
...
@@ -53,6 +53,7 @@
process
:
1
,
end
:
2
};
function
CTextInput
(
api
)
{
this
.
Api
=
api
;
...
...
@@ -74,6 +75,8 @@
this
.
IsLockTargetMode
=
false
;
this
.
IsUseFirstTextInputAfterComposition
=
false
;
this
.
nativeFocusElement
=
null
;
}
CTextInput
.
prototype
=
...
...
@@ -134,7 +137,8 @@
oHtmlDivScrollable
.
appendChild
(
this
.
HtmlDiv
);
oHtmlParent
.
parentNode
.
appendChild
(
oHtmlDivScrollable
);
oHtmlParent
.
onresize
=
function
(
e
)
{
oHtmlParent
.
onresize
=
function
(
e
)
{
var
_elem
=
document
.
getElementById
(
"
area_id_parent
"
);
var
style
=
getComputedStyle
(
oHtmlParent
);
_elem
.
style
.
left
=
style
.
left
;
...
...
@@ -150,20 +154,44 @@
// events:
var
oThis
=
this
;
this
.
HtmlArea
[
"
onkeydown
"
]
=
function
(
e
)
{
return
oThis
.
onKeyDown
(
e
);
};
this
.
HtmlArea
[
"
onkeypress
"
]
=
function
(
e
)
{
return
oThis
.
onKeyPress
(
e
);
};
this
.
HtmlArea
[
"
onkeyup
"
]
=
function
(
e
)
{
return
oThis
.
onKeyUp
(
e
);
};
this
.
HtmlArea
[
"
onkeydown
"
]
=
function
(
e
)
{
return
oThis
.
onKeyDown
(
e
);
};
this
.
HtmlArea
[
"
onkeypress
"
]
=
function
(
e
)
{
return
oThis
.
onKeyPress
(
e
);
};
this
.
HtmlArea
[
"
onkeyup
"
]
=
function
(
e
)
{
return
oThis
.
onKeyUp
(
e
);
};
this
.
HtmlArea
.
addEventListener
(
"
input
"
,
function
(
e
)
{
return
oThis
.
onInput
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
textInput
"
,
function
(
e
)
{
return
oThis
.
onTextInput
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
input
"
,
function
(
e
)
{
return
oThis
.
onInput
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
textInput
"
,
function
(
e
)
{
return
oThis
.
onTextInput
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
compositionstart
"
,
function
(
e
)
{
return
oThis
.
onCompositionStart
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
compositionupdate
"
,
function
(
e
)
{
return
oThis
.
onCompositionUpdate
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
compositionend
"
,
function
(
e
)
{
return
oThis
.
onCompositionEnd
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
compositionstart
"
,
function
(
e
)
{
return
oThis
.
onCompositionStart
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
compositionupdate
"
,
function
(
e
)
{
return
oThis
.
onCompositionUpdate
(
e
);
},
false
);
this
.
HtmlArea
.
addEventListener
(
"
compositionend
"
,
function
(
e
)
{
return
oThis
.
onCompositionEnd
(
e
);
},
false
);
this
.
show
(
false
);
/
/ TODO:
/
*
setInterval(function(){
if (oThis.Api.asc_IsFocus() && !AscCommon.g_clipboardBase.IsFocus() && !AscCommon.g_clipboardBase.IsWorking())
{
...
...
@@ -171,6 +199,7 @@
oThis.HtmlArea.focus();
}
}, 10);
*/
this
.
Api
.
Input_UpdatePos
();
},
...
...
@@ -193,7 +222,8 @@
*/
var
oThis
=
this
;
setTimeout
(
function
(){
setTimeout
(
function
()
{
oThis
.
checkFocus
();
oThis
.
initTimer
();
},
40
);
...
...
@@ -263,11 +293,71 @@
}
},
emulateNativeKeyDown
:
function
(
e
)
{
var
oEvent
=
document
.
createEvent
(
'
KeyboardEvent
'
);
/*
var _event = new KeyboardEvent("keydown", {
bubbles : true,
cancelable : true,
char : e.charCode,
shiftKey : e.shiftKey,
ctrlKey : e.ctrlKey,
metaKey : e.metaKey,
altKey : e.altKey,
keyCode : e.keyCode,
which : e.which,
key : e.key
});
*/
// Chromium Hack
Object
.
defineProperty
(
oEvent
,
'
keyCode
'
,
{
get
:
function
()
{
return
this
.
keyCodeVal
;
}
});
Object
.
defineProperty
(
oEvent
,
'
which
'
,
{
get
:
function
()
{
return
this
.
keyCodeVal
;
}
});
var
k
=
e
.
keyCode
;
if
(
oEvent
.
initKeyboardEvent
)
{
oEvent
.
initKeyboardEvent
(
"
keydown
"
,
true
,
true
,
window
,
false
,
false
,
false
,
false
,
k
,
k
);
}
else
{
oEvent
.
initKeyEvent
(
"
keydown
"
,
true
,
true
,
window
,
false
,
false
,
false
,
false
,
k
,
0
);
}
oEvent
.
keyCodeVal
=
k
;
var
_elem
=
_getElementKeyboardDown
(
this
.
nativeFocusElement
,
3
);
_elem
.
dispatchEvent
(
oEvent
);
return
oEvent
.
defaultPrevented
;
},
onKeyDown
:
function
(
e
)
{
if
(
c_oCompositionState
.
end
!=
this
.
compositionState
)
return
;
if
(
null
!=
this
.
nativeFocusElement
)
{
if
(
this
.
emulateNativeKeyDown
(
e
))
{
e
.
preventDefault
();
return
false
;
}
}
// некоторые рукописные вводы не присылают keyUp
var
_code
=
e
.
keyCode
;
if
(
_code
!=
8
&&
_code
!=
46
)
...
...
@@ -319,7 +409,10 @@
this
.
Api
.
asc_LockTargetUpdate
(
true
);
var
oThis
=
this
;
this
.
LockerTargetTimer
=
setTimeout
(
function
(){
oThis
.
unlockTarget
();
},
1000
);
this
.
LockerTargetTimer
=
setTimeout
(
function
()
{
oThis
.
unlockTarget
();
},
1000
);
},
unlockTarget
:
function
()
...
...
@@ -440,6 +533,29 @@
}
};
function
_getAttirbute
(
_elem
,
_attr
,
_depth
)
{
var
_elemTest
=
_elem
;
for
(
var
_level
=
0
;
_elemTest
&&
(
_level
<
_depth
);
++
_level
,
_elemTest
=
_elemTest
.
parentNode
)
{
var
_res
=
_elemTest
.
getAttribute
(
_attr
);
if
(
null
!=
_res
)
return
_res
;
}
return
null
;
}
function
_getElementKeyboardDown
(
_elem
,
_depth
)
{
var
_elemTest
=
_elem
;
for
(
var
_level
=
0
;
_elemTest
&&
(
_level
<
_depth
);
++
_level
,
_elemTest
=
_elemTest
.
parentNode
)
{
var
_res
=
_elemTest
.
getAttribute
(
"
oo_editor_keyboard
"
);
if
(
null
!=
_res
)
return
_elemTest
;
}
return
null
;
}
window
[
'
AscCommon
'
]
=
window
[
'
AscCommon
'
]
||
{};
window
[
'
AscCommon
'
].
CTextInput
=
CTextInput
;
...
...
@@ -448,5 +564,86 @@
window
[
'
AscCommon
'
].
g_inputContext
=
new
CTextInput
(
api
);
window
[
'
AscCommon
'
].
g_inputContext
.
init
(
target_id
);
window
[
'
AscCommon
'
].
g_clipboardBase
.
Init
(
api
);
document
.
addEventListener
(
"
focus
"
,
function
(
e
)
{
var
t
=
window
[
'
AscCommon
'
].
g_inputContext
;
t
.
nativeFocusElement
=
e
.
target
;
//console.log(t.nativeFocusElement);
if
(
t
.
nativeFocusElement
.
id
==
t
.
HtmlArea
.
id
)
{
t
.
Api
.
asc_enableKeyEvents
(
true
);
t
.
nativeFocusElement
=
null
;
return
;
}
if
(
t
.
nativeFocusElement
.
id
==
window
[
'
AscCommon
'
].
g_clipboardBase
.
CommonDivId
)
{
t
.
nativeFocusElement
=
null
;
return
;
}
var
_isElementEditable
=
false
;
if
(
true
)
{
// detect _isElementEditable
var
_name
=
t
.
nativeFocusElement
.
nodeName
;
if
(
_name
)
_name
=
_name
.
toUpperCase
();
if
(
"
INPUT
"
==
_name
||
"
TEXTAREA
"
==
_name
)
_isElementEditable
=
true
;
else
if
(
"
DIV
"
==
_name
)
{
if
(
t
.
nativeFocusElement
.
getAttribute
(
"
contenteditable
"
)
==
"
true
"
)
_isElementEditable
=
true
;
}
}
if
(
"
IFRAME
"
==
_name
)
{
// перехват клавиатуры
t
.
Api
.
asc_enableKeyEvents
(
false
);
t
.
nativeFocusElement
=
null
;
return
;
}
// перехватывает ли элемент ввод
var
_oo_editor_input
=
_getAttirbute
(
t
.
nativeFocusElement
,
"
oo_editor_input
"
,
3
);
// нужно ли прокидывать нажатие клавиш элементу (ТОЛЬКО keyDown)
var
_oo_editor_keyboard
=
_getAttirbute
(
t
.
nativeFocusElement
,
"
oo_editor_keyboard
"
,
3
);
if
(
_oo_editor_keyboard
==
"
true
"
)
_oo_editor_input
=
undefined
;
if
(
_oo_editor_input
==
"
true
"
)
{
// перехват клавиатуры
t
.
Api
.
asc_enableKeyEvents
(
false
);
t
.
nativeFocusElement
=
null
;
return
;
}
if
(
_isElementEditable
&&
(
_oo_editor_input
!=
"
false
"
))
{
// перехват клавиатуры
t
.
Api
.
asc_enableKeyEvents
(
false
);
t
.
nativeFocusElement
=
null
;
return
;
}
// итак, ввод у нас. теперь определяем, нужна ли клавиатура элементу
if
(
_oo_editor_keyboard
!=
"
true
"
)
t
.
nativeFocusElement
=
null
;
var
_elem
=
t
.
nativeFocusElement
;
t
.
HtmlArea
.
focus
();
t
.
nativeFocusElement
=
_elem
;
t
.
Api
.
asc_enableKeyEvents
(
true
);
},
true
);
// send focus
window
[
'
AscCommon
'
].
g_inputContext
.
HtmlArea
.
focus
();
};
})(
window
);
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment