Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit12119d2

Browse files
committed
calculating in iframe's coordinate
Instead of parent window's.The fact is that caret.js will not calculate the iframe's offset.
1 parent1ffc4b5 commit12119d2

File tree

6 files changed

+30
-43
lines changed

6 files changed

+30
-43
lines changed

‎README.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Usage
2222

2323
// Get caret position
2424
$('#inputor').caret('position');// => {left: 15, top: 30, height: 20}
25-
$('#inputor').caret('iframe', iframe1).caret('position')
2625

2726
// Get caret offset
2827
$('#inputor').caret('offset');// => {left: 300, top: 400, height: 20}
@@ -38,15 +37,18 @@ $('#inputor').caret('offset', fixPos);
3837

3938
// more
4039

41-
// Get caret position from first char in inputor.
40+
// Get caret position fromthefirst char in the inputor.
4241
$('#inputor').caret('pos');// => 15
4342

4443
// Set caret position in the inputor
4544
// not working in contentEditable mode
4645
$('#inputor').caret('pos',15);
4746

4847
// set iframe context
48+
// NOTE: Related to the iframe's cooridinate.
49+
// You might want to get the iframe's offset/position on your own
4950
$('#inputor').caret('offset', {iframe: theIframe});
51+
$('#inputor').caret('position', {iframe: theIframe});
5052
$('#inputor').caret('pos',15, {iframe: theIframe});
5153

5254
```

‎dist/jquery.caret.js‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,9 @@
4242
EditableCaret.prototype.getPosition=function(){
4343
varinputor_offset,offset;
4444
offset=this.getOffset();
45-
if(!oFrame){
46-
inputor_offset=this.$inputor.offset();
47-
offset.left-=inputor_offset.left;
48-
offset.top-=inputor_offset.top;
49-
}
45+
inputor_offset=this.$inputor.offset();
46+
offset.left-=inputor_offset.left;
47+
offset.top-=inputor_offset.top;
5048
returnoffset;
5149
};
5250

@@ -104,7 +102,7 @@
104102
}elseif(oDocument.selection){
105103
offset=this.getOldIEOffset();
106104
}
107-
if(offset&&!oFrame){
105+
if(offset){
108106
offset.top+=$(oWindow).scrollTop();
109107
offset.left+=$(oWindow).scrollLeft();
110108
}
@@ -314,13 +312,8 @@
314312
}
315313
},
316314
offset:function(pos){
317-
variOffset,offset;
315+
varoffset;
318316
offset=this.getOffset(pos);
319-
if(oFrame){
320-
iOffset=$(oFrame).offset();
321-
offset.top+=iOffset.top;
322-
offset.left+=iOffset.left;
323-
}
324317
returnoffset;
325318
}
326319
};

‎dist/jquery.caret.min.js‎

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎index.html‎

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919

2020
functionresetOffset($textField){
2121
varoffset=$textField.caret('offset');
22-
resizeBox(offset);
2322
varposition=$textField.caret('position');
24-
$('.position-box').css({'width':position.left,'height':position.top})
25-
$('.position-indicator')
26-
.html("Position: left: "+position.left+", "+"top: "+position.top+" ");
23+
resizeBox(offset,position);
2724
returnoffset
2825
}
29-
functionresizeBox(offset){
26+
functionresizeBox(offset,position){
3027
$('.coordinate-box').css({'width':offset.left,'height':offset.top})
3128
$('.cursor')
3229
.offset({left:offset.left,top:offset.top+offset.height+2})
3330
.find('.offset-indicator')
3431
.html("Offset: left: "+offset.left+", "+"top: "+offset.top+" "+"height: "+offset.height);
32+
$('.position-box').css({'width':position.left,'height':position.top})
33+
$('.position-indicator')
34+
.html("Position: left: "+position.left+", "+"top: "+position.top+" ");
3535
}
3636

3737
$input.on('focus keyup mouseup',function(){
@@ -64,7 +64,11 @@
6464
ifrBody.id='ifrBody';
6565
ifrBody.innerHTML='For <strong>WYSIWYG</strong> such as <strong>ckeditor</strong>'
6666
$(ifrBody).on('keyup mouseup',function(){
67-
resizeBox($(ifrBody).caret('offset',{iframe:ifr}));
67+
offset=$(ifrBody).caret('offset',{iframe:ifr});
68+
offset.left+=$(ifr).offset().left;
69+
offset.top+=$(ifr).offset().top;
70+
position=$(ifrBody).caret('position',{iframe:ifr});
71+
resizeBox(offset,position);
6872
});
6973

7074

‎src/jquery.caret.coffee‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,9 @@
3838
getIEPosition:->this.getPosition()
3939
getPosition:->
4040
offset=this.getOffset()
41-
if!oFrame
42-
inputor_offset=@$inputor.offset()
43-
offset.left-=inputor_offset.left
44-
offset.top-=inputor_offset.top
41+
inputor_offset=@$inputor.offset()
42+
offset.left-=inputor_offset.left
43+
offset.top-=inputor_offset.top
4544
offset
4645

4746
getOldIEPos:->
@@ -81,7 +80,7 @@
8180
elseifoDocument.selection# ie < 9
8281
offset=this.getOldIEOffset()
8382

84-
if offsetand!oFrame
83+
if offset
8584
offset.top+=$(oWindow).scrollTop()
8685
offset.left+=$(oWindow).scrollLeft()
8786

@@ -268,10 +267,6 @@
268267

269268
offset: (pos)->
270269
offset=this.getOffset(pos)
271-
if oFrame
272-
iOffset=$(oFrame).offset()
273-
offset.top+=iOffset.top
274-
offset.left+=iOffset.left
275270
offset
276271

277272
oDocument=null

‎src/jquery.caret.js‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,9 @@
4343
EditableCaret.prototype.getPosition=function(){
4444
varinputor_offset,offset;
4545
offset=this.getOffset();
46-
if(!oFrame){
47-
inputor_offset=this.$inputor.offset();
48-
offset.left-=inputor_offset.left;
49-
offset.top-=inputor_offset.top;
50-
}
46+
inputor_offset=this.$inputor.offset();
47+
offset.left-=inputor_offset.left;
48+
offset.top-=inputor_offset.top;
5149
returnoffset;
5250
};
5351

@@ -105,7 +103,7 @@
105103
}elseif(oDocument.selection){
106104
offset=this.getOldIEOffset();
107105
}
108-
if(offset&&!oFrame){
106+
if(offset){
109107
offset.top+=$(oWindow).scrollTop();
110108
offset.left+=$(oWindow).scrollLeft();
111109
}
@@ -315,13 +313,8 @@
315313
}
316314
},
317315
offset:function(pos){
318-
variOffset,offset;
316+
varoffset;
319317
offset=this.getOffset(pos);
320-
if(oFrame){
321-
iOffset=$(oFrame).offset();
322-
offset.top+=iOffset.top;
323-
offset.left+=iOffset.left;
324-
}
325318
returnoffset;
326319
}
327320
};

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp