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

Commit37d4c5e

Browse files
committed
disable auto decovery iframe
and change the apiichord/At.js#160
1 parent35b03e3 commit37d4c5e

File tree

5 files changed

+59
-60
lines changed

5 files changed

+59
-60
lines changed

‎README.md‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,11 +47,8 @@ $('#inputor').caret('pos'); // => 15
4747
$('#inputor').caret('pos',15);
4848

4949
// set iframe context
50-
// oftenly you don't need to set iframe context because caret.js will find the iframe object automatically
51-
// but some iframe editor will prevent caret.js to finding for security reasons,
52-
// so you may have to set the iframe manually
53-
$('#inputor').caret({iframe: theIframe});
54-
$('#inputor').caret('offset');
55-
$('#inputor').caret('pos',15);
50+
<!--$('#inputor').caret({iframe: theIframe});-->
51+
$('#inputor').caret('offset', {iframe: theIframe});
52+
$('#inputor').caret('pos',15, {iframe: theIframe});
5653

5754
```

‎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: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@
6565
ifrBody.contentEditable=true;
6666
ifrBody.id='ifrBody';
6767
ifrBody.innerHTML='For <strong>WYSIWYG</strong> such as <strong>ckeditor</strong>'
68-
$(ifrBody).caret({iframe:ifr});
6968
$(ifrBody).on('keyup mouseup',function(){
70-
resizeBox($(ifrBody).caret('offset'));
69+
resizeBox($(ifrBody).caret('offset',{iframe:ifr}));
7170
});
7271

7372

‎src/jquery.caret.coffee‎

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -274,32 +274,33 @@
274274
oDocument=null
275275
oWindow=null
276276
oFrame=null
277-
setContextBy= (iframe)->
278-
oFrame= iframe
279-
oWindow=iframe.contentWindow
280-
oDocument=iframe.contentDocument||oWindow.document
281-
configure= ($dom,settings)->
282-
if$.isPlainObject(settings)andiframe=settings.iframe
283-
$dom.data('caret-iframe', iframe)
284-
setContextBy iframe
285-
elseififrame=$dom.data('caret-iframe')
286-
setContextBy iframe
277+
setContextBy= (settings)->
278+
ififrame=settings?.iframe
279+
oFrame= iframe
280+
oWindow=iframe.contentWindow
281+
oDocument=iframe.contentDocument||oWindow.document
287282
else
288-
oDocument= $dom[0].ownerDocument
289-
oWindow=oDocument.defaultView||oDocument.parentWindow
290-
try
291-
oFrame=oWindow.frameElement
292-
catch error
293-
# throws error in cross-domain iframes
294-
$.fn.caret= (method)->
283+
oFrame=undefined
284+
oWindow=window
285+
oDocument=document
286+
discoveryIframeOf= ($dom)->
287+
oDocument= $dom[0].ownerDocument
288+
oWindow=oDocument.defaultView||oDocument.parentWindow
289+
try
290+
oFrame=oWindow.frameElement
291+
catch error
292+
# throws error in cross-domain iframes
293+
294+
$.fn.caret= (method,value,settings)->
295295
# http://stackoverflow.com/questions/16010204/get-reference-of-window-object-from-a-dom-element
296-
iftypeof methodis'object'
297-
configurethis, method
298-
this
299-
elseif methods[method]
300-
configurethis
296+
if methods[method]
297+
if$.isPlainObject(value)
298+
setContextBy value
299+
value=undefined
300+
else
301+
setContextBy settings
301302
caret=ifUtils.contentEditable(this)thennewEditableCaret(this)elsenewInputCaret(this)
302-
methods[method].apply caret,Array::slice.call(arguments,1)
303+
methods[method].apply caret,[value]
303304
else
304305
$.error"Method#{method} does not exist on jQuery.caret"
305306

‎src/jquery.caret.js‎

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
}
2525
})(function($){
2626
"use strict";
27-
varEditableCaret,InputCaret,Mirror,Utils,configure,methods,oDocument,oFrame,oWindow,pluginName,setContextBy;
27+
varEditableCaret,InputCaret,Mirror,Utils,discoveryIframeOf,methods,oDocument,oFrame,oWindow,pluginName,setContextBy;
2828
pluginName='caret';
2929
EditableCaret=(function(){
3030
functionEditableCaret($inputor){
@@ -319,37 +319,39 @@
319319
oDocument=null;
320320
oWindow=null;
321321
oFrame=null;
322-
setContextBy=function(iframe){
323-
oFrame=iframe;
324-
oWindow=iframe.contentWindow;
325-
returnoDocument=iframe.contentDocument||oWindow.document;
326-
};
327-
configure=function($dom,settings){
328-
varerror,iframe;
329-
if($.isPlainObject(settings)&&(iframe=settings.iframe)){
330-
$dom.data('caret-iframe',iframe);
331-
returnsetContextBy(iframe);
332-
}elseif(iframe=$dom.data('caret-iframe')){
333-
returnsetContextBy(iframe);
322+
setContextBy=function(settings){
323+
variframe;
324+
if(iframe=settings!=null ?settings.iframe :void0){
325+
oFrame=iframe;
326+
oWindow=iframe.contentWindow;
327+
returnoDocument=iframe.contentDocument||oWindow.document;
334328
}else{
335-
oDocument=$dom[0].ownerDocument;
336-
oWindow=oDocument.defaultView||oDocument.parentWindow;
337-
try{
338-
returnoFrame=oWindow.frameElement;
339-
}catch(_error){
340-
error=_error;
341-
}
329+
oFrame=void0;
330+
oWindow=window;
331+
returnoDocument=document;
332+
}
333+
};
334+
discoveryIframeOf=function($dom){
335+
varerror;
336+
oDocument=$dom[0].ownerDocument;
337+
oWindow=oDocument.defaultView||oDocument.parentWindow;
338+
try{
339+
returnoFrame=oWindow.frameElement;
340+
}catch(_error){
341+
error=_error;
342342
}
343343
};
344-
$.fn.caret=function(method){
344+
$.fn.caret=function(method,value,settings){
345345
varcaret;
346-
if(typeofmethod==='object'){
347-
configure(this,method);
348-
returnthis;
349-
}elseif(methods[method]){
350-
configure(this);
346+
if(methods[method]){
347+
if($.isPlainObject(value)){
348+
setContextBy(value);
349+
value=void0;
350+
}else{
351+
setContextBy(settings);
352+
}
351353
caret=Utils.contentEditable(this) ?newEditableCaret(this) :newInputCaret(this);
352-
returnmethods[method].apply(caret,Array.prototype.slice.call(arguments,1));
354+
returnmethods[method].apply(caret,[value]);
353355
}else{
354356
return$.error("Method "+method+" does not exist on jQuery.caret");
355357
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp