Refactored some of the click position code.
This commit is contained in:
parent
404956deec
commit
4a8e98372d
|
@ -130,7 +130,7 @@ Editor.prototype.connect_note_controls = function ( store_control_buttons ) {
|
|||
}
|
||||
}
|
||||
|
||||
Editor.prototype.create_iframe = function ( position_after, click_x, click_y ) {
|
||||
Editor.prototype.create_iframe = function ( position_after, click_position ) {
|
||||
var iframe_id = "note_" + this.id;
|
||||
|
||||
// if there is already an iframe for this Editor, bail
|
||||
|
@ -205,7 +205,7 @@ Editor.prototype.create_iframe = function ( position_after, click_x, click_y ) {
|
|||
}
|
||||
|
||||
function finish_init() {
|
||||
self.position_cursor( click_x, click_y );
|
||||
self.position_cursor( click_position );
|
||||
self.connect_handlers();
|
||||
}
|
||||
|
||||
|
@ -258,7 +258,7 @@ Editor.prototype.enable_design_mode = function () {
|
|||
}
|
||||
}
|
||||
|
||||
Editor.prototype.position_cursor = function ( click_x, click_y ) {
|
||||
Editor.prototype.position_cursor = function ( click_position ) {
|
||||
if ( this.init_focus ) {
|
||||
this.init_focus = false;
|
||||
if ( this.iframe )
|
||||
|
@ -276,15 +276,15 @@ Editor.prototype.position_cursor = function ( click_x, click_y ) {
|
|||
return;
|
||||
|
||||
// if requested, move the text cursor to a specific location
|
||||
if ( click_x && click_y ) {
|
||||
if ( click_position ) {
|
||||
var FRAME_BORDER_WIDTH = 2;
|
||||
|
||||
if ( this.iframe.contentWindow && this.iframe.contentWindow.getSelection ) { // browsers such as Firefox
|
||||
} else if ( this.document.selection ) { // browsers such as IE
|
||||
var range = this.document.selection.createRange();
|
||||
range.moveToPoint(
|
||||
click_x - this.iframe.offsetLeft - FRAME_BORDER_WIDTH,
|
||||
click_y - this.iframe.offsetTop - FRAME_BORDER_WIDTH
|
||||
click_position.x - this.iframe.offsetLeft - FRAME_BORDER_WIDTH,
|
||||
click_position.y - this.iframe.offsetTop - FRAME_BORDER_WIDTH
|
||||
);
|
||||
range.select();
|
||||
}
|
||||
|
@ -710,11 +710,13 @@ Editor.prototype.mouse_clicked = function ( event ) {
|
|||
// if no link was clicked, then make the clicked editor into an iframe
|
||||
if ( !link_clicked && this.div ) {
|
||||
this.init_focus = true;
|
||||
this.create_iframe(
|
||||
null,
|
||||
event.x || window.event.x,
|
||||
event.y || window.event.y
|
||||
);
|
||||
|
||||
if ( MSIE )
|
||||
var click_position = { "x": window.event.x, "y": window.event.y };
|
||||
else
|
||||
var click_position = event.mouse().page;
|
||||
|
||||
this.create_iframe( null, click_position );
|
||||
}
|
||||
|
||||
// in case the cursor has moved, update the state
|
||||
|
|
Reference in New Issue