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;
|
var iframe_id = "note_" + this.id;
|
||||||
|
|
||||||
// if there is already an iframe for this Editor, bail
|
// 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() {
|
function finish_init() {
|
||||||
self.position_cursor( click_x, click_y );
|
self.position_cursor( click_position );
|
||||||
self.connect_handlers();
|
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 ) {
|
if ( this.init_focus ) {
|
||||||
this.init_focus = false;
|
this.init_focus = false;
|
||||||
if ( this.iframe )
|
if ( this.iframe )
|
||||||
|
@ -276,15 +276,15 @@ Editor.prototype.position_cursor = function ( click_x, click_y ) {
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// if requested, move the text cursor to a specific location
|
// if requested, move the text cursor to a specific location
|
||||||
if ( click_x && click_y ) {
|
if ( click_position ) {
|
||||||
var FRAME_BORDER_WIDTH = 2;
|
var FRAME_BORDER_WIDTH = 2;
|
||||||
|
|
||||||
if ( this.iframe.contentWindow && this.iframe.contentWindow.getSelection ) { // browsers such as Firefox
|
if ( this.iframe.contentWindow && this.iframe.contentWindow.getSelection ) { // browsers such as Firefox
|
||||||
} else if ( this.document.selection ) { // browsers such as IE
|
} else if ( this.document.selection ) { // browsers such as IE
|
||||||
var range = this.document.selection.createRange();
|
var range = this.document.selection.createRange();
|
||||||
range.moveToPoint(
|
range.moveToPoint(
|
||||||
click_x - this.iframe.offsetLeft - FRAME_BORDER_WIDTH,
|
click_position.x - this.iframe.offsetLeft - FRAME_BORDER_WIDTH,
|
||||||
click_y - this.iframe.offsetTop - FRAME_BORDER_WIDTH
|
click_position.y - this.iframe.offsetTop - FRAME_BORDER_WIDTH
|
||||||
);
|
);
|
||||||
range.select();
|
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 no link was clicked, then make the clicked editor into an iframe
|
||||||
if ( !link_clicked && this.div ) {
|
if ( !link_clicked && this.div ) {
|
||||||
this.init_focus = true;
|
this.init_focus = true;
|
||||||
this.create_iframe(
|
|
||||||
null,
|
if ( MSIE )
|
||||||
event.x || window.event.x,
|
var click_position = { "x": window.event.x, "y": window.event.y };
|
||||||
event.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
|
// in case the cursor has moved, update the state
|
||||||
|
|
Reference in New Issue