|
1 |
| -/** |
| 1 | +/** |
2 | 2 | * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
|
3 | 3 | * For licensing, see LICENSE.md or http://ckeditor.com/license
|
4 | 4 | */
|
5 | 5 |
|
6 | 6 | ( function() {
|
7 | 7 | 'use strict';
|
8 | 8 |
|
| 9 | + /** |
| 10 | + * JSONP communication. |
| 11 | + * |
| 12 | + * @private |
| 13 | + * @singleton |
| 14 | + * @class CKEDITOR.plugins.embedBase._jsonp |
| 15 | + */ |
| 16 | + var Jsonp = { |
| 17 | + /** |
| 18 | + * Creates a `<script>` element and attaches it to the document `<body>`. |
| 19 | + * |
| 20 | + * @private |
| 21 | + */ |
| 22 | + _attachScript: function( url, errorCallback ) { |
| 23 | + // ATM we cannot use CKE scriptloader here, because it will make sure that script |
| 24 | + // with given URL is added only once. |
| 25 | + var script = new CKEDITOR.dom.element( 'script' ); |
| 26 | + script.setAttribute( 'src', url ); |
| 27 | + script.on( 'error', errorCallback ); |
| 28 | + |
| 29 | + CKEDITOR.document.getBody().append( script ); |
| 30 | + |
| 31 | + return script; |
| 32 | + }, |
| 33 | + |
| 34 | + /** |
| 35 | + * Sends a request using the JSONP technique. |
| 36 | + * |
| 37 | + * @param {CKEDITOR.template} urlTemplate The template of the URL to be requested. All properties |
| 38 | + * passed in `urlParams` can be used, plus a `{callback}`, which represent a JSONP callback, must be defined. |
| 39 | + * @param {Object} urlParams Parameters to be passed to the `urlTemplate`. |
| 40 | + * @param {Function} callback |
| 41 | + * @param {Function} [errorCallback] |
| 42 | + * @returns {Object} The request object with a `cancel()` method. |
| 43 | + */ |
| 44 | + sendRequest: function( urlTemplate, urlParams, callback, errorCallback ) { |
| 45 | + var request = {}; |
| 46 | + urlParams = urlParams || {}; |
| 47 | + |
| 48 | + var callbackKey = CKEDITOR.tools.getNextNumber(), |
| 49 | + scriptElement; |
| 50 | + |
| 51 | + urlParams.callback = 'CKEDITOR._.jsonpCallbacks[' + callbackKey + ']'; |
| 52 | + |
| 53 | + CKEDITOR._.jsonpCallbacks[ callbackKey ] = function( response ) { |
| 54 | + // On IEs scripts are sometimes loaded synchronously. It is bad for two reasons: |
| 55 | + // * nature of sendRequest() is unstable, |
| 56 | + // * scriptElement does not exist yet. |
| 57 | + setTimeout( function() { |
| 58 | + cleanUp(); |
| 59 | + callback( response ); |
| 60 | + } ); |
| 61 | + }; |
| 62 | + |
| 63 | + scriptElement = this._attachScript( urlTemplate.output( urlParams ), function() { |
| 64 | + cleanUp(); |
| 65 | + errorCallback && errorCallback(); |
| 66 | + } ); |
| 67 | + |
| 68 | + request.cancel = cleanUp; |
| 69 | + |
| 70 | + function cleanUp() { |
| 71 | + if ( scriptElement ) { |
| 72 | + scriptElement.remove(); |
| 73 | + delete CKEDITOR._.jsonpCallbacks[ callbackKey ]; |
| 74 | + scriptElement = null; |
| 75 | + } |
| 76 | + } |
| 77 | + |
| 78 | + return request; |
| 79 | + } |
| 80 | + }; |
| 81 | + |
9 | 82 | CKEDITOR.plugins.add( 'embedbase', {
|
10 | 83 | lang: 'cs,da,de,de-ch,en,eo,eu,fr,gl,id,it,ko,ku,nb,nl,pl,pt-br,ru,sv,tr,ug,uk,zh,zh-cn', // %REMOVE_LINE_CORE%
|
11 | 84 | requires: 'widget,notificationaggregator',
|
|
394 | 467 | return '<img src="' + CKEDITOR.tools.htmlEncodeAttr( response.url ) + '" ' +
|
395 | 468 | 'alt="' + CKEDITOR.tools.htmlEncodeAttr( response.title || '' ) + '" style="max-width:100%;height:auto" />';
|
396 | 469 | } else if ( response.type == 'video' || response.type == 'rich' ) {
|
| 470 | + // Embedded iframes are added to page's focus list. Adding negative tabindex attribute |
| 471 | + // removes their ability to be focused by user. (#14538) |
| 472 | + response.html = response.html.replace( /<iframe/g, '<iframe tabindex="-1"' ); |
| 473 | + |
397 | 474 | return response.html;
|
398 | 475 | }
|
399 | 476 |
|
|
521 | 598 | */
|
522 | 599 | }
|
523 | 600 |
|
524 |
| - /** |
525 |
| - * JSONP communication. |
526 |
| - * |
527 |
| - * @private |
528 |
| - * @singleton |
529 |
| - * @class CKEDITOR.plugins.embedBase._jsonp |
530 |
| - */ |
531 |
| - var Jsonp = { |
532 |
| - /** |
533 |
| - * Creates a `<script>` element and attaches it to the document `<body>`. |
534 |
| - * |
535 |
| - * @private |
536 |
| - */ |
537 |
| - _attachScript: function( url, errorCallback ) { |
538 |
| - // ATM we cannot use CKE scriptloader here, because it will make sure that script |
539 |
| - // with given URL is added only once. |
540 |
| - var script = new CKEDITOR.dom.element( 'script' ); |
541 |
| - script.setAttribute( 'src', url ); |
542 |
| - script.on( 'error', errorCallback ); |
543 |
| - |
544 |
| - CKEDITOR.document.getBody().append( script ); |
545 |
| - |
546 |
| - return script; |
547 |
| - }, |
548 |
| - |
549 |
| - /** |
550 |
| - * Sends a request using the JSONP technique. |
551 |
| - * |
552 |
| - * @param {CKEDITOR.template} urlTemplate The template of the URL to be requested. All properties |
553 |
| - * passed in `urlParams` can be used, plus a `{callback}`, which represent a JSONP callback, must be defined. |
554 |
| - * @param {Object} urlParams Parameters to be passed to the `urlTemplate`. |
555 |
| - * @param {Function} callback |
556 |
| - * @param {Function} [errorCallback] |
557 |
| - * @returns {Object} The request object with a `cancel()` method. |
558 |
| - */ |
559 |
| - sendRequest: function( urlTemplate, urlParams, callback, errorCallback ) { |
560 |
| - var request = {}; |
561 |
| - urlParams = urlParams || {}; |
562 |
| - |
563 |
| - var callbackKey = CKEDITOR.tools.getNextNumber(), |
564 |
| - scriptElement; |
565 |
| - |
566 |
| - urlParams.callback = 'CKEDITOR._.jsonpCallbacks[' + callbackKey + ']'; |
567 |
| - |
568 |
| - CKEDITOR._.jsonpCallbacks[ callbackKey ] = function( response ) { |
569 |
| - // On IEs scripts are sometimes loaded synchronously. It is bad for two reasons: |
570 |
| - // * nature of sendRequest() is unstable, |
571 |
| - // * scriptElement does not exist yet. |
572 |
| - setTimeout( function() { |
573 |
| - cleanUp(); |
574 |
| - callback( response ); |
575 |
| - } ); |
576 |
| - }; |
577 |
| - |
578 |
| - scriptElement = this._attachScript( urlTemplate.output( urlParams ), function() { |
579 |
| - cleanUp(); |
580 |
| - errorCallback && errorCallback(); |
581 |
| - } ); |
582 |
| - |
583 |
| - request.cancel = cleanUp; |
584 |
| - |
585 |
| - function cleanUp() { |
586 |
| - if ( scriptElement ) { |
587 |
| - scriptElement.remove(); |
588 |
| - delete CKEDITOR._.jsonpCallbacks[ callbackKey ]; |
589 |
| - scriptElement = null; |
590 |
| - } |
591 |
| - } |
592 |
| - |
593 |
| - return request; |
594 |
| - } |
595 |
| - }; |
596 |
| - |
597 | 601 | /**
|
598 | 602 | * Class representing the request object. It is created by the {@link CKEDITOR.plugins.embedBase.baseDefinition#loadContent}
|
599 | 603 | * method and is passed to other methods and events of this class.
|
|
0 commit comments