Ticket #12525: solution-for-all-bugs-ckeditor-in-bootstrap-modal-test.html

File solution-for-all-bugs-ckeditor-in-bootstrap-modal-test.html, 2.4 KB (added by pittlu, 6 years ago)
Line 
1<html>
2<head>
3<meta charset="utf-8">
4<meta http-equiv="X-UA-Compatible" content="IE=edge">
5<meta name="viewport" content="width=device-width, initial-scale=1">
6<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
7<!--[if lt IE 9]>
8  <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
9  <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
10<![endif]-->
11<script src="http://cdn.ckeditor.com/4.4.5/standard/ckeditor.js"></script>
12</head>
13<body>
14
15<!-- Button trigger modal -->
16<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
17  Launch demo modal
18</button>
19
20<!-- Modal -->
21<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
22  <div class="modal-dialog">
23    <div class="modal-content">
24      <div class="modal-header">
25        <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>
26        <h4 class="modal-title" id="myModalLabel">CKEditor In twitter Bootstrap Test</h4>
27      </div>
28      <div class="modal-body">
29        <form>
30            <textarea name="editor1" id="editor1" rows="10" cols="80">
31                This is my textarea to be replaced with CKEditor.
32            </textarea>
33            <script>
34                // Replace the <textarea id="editor1"> with a CKEditor
35                // instance, using default configuration.
36                CKEDITOR.replace( 'editor1' );
37            </script>
38        </form>
39      </div>
40    </div>
41  </div>
42</div>
43
44<script src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
45<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
46<script>
47
48//The final solution code for all bugs ckeditor in twitter bootstrap3' modal
49$.fn.modal.Constructor.prototype.enforceFocus = function() {
50        var $modalElement = this.$element;
51        $(document).on('focusin.modal',function(e) {
52                var $parent = $(e.target.parentNode);
53                if ($modalElement[0] !== e.target
54                                && !$modalElement.has(e.target).length
55                                && $(e.target).parentsUntil('*[role="dialog"]').length === 0) {
56                        $modalElement.focus();
57                }
58        });
59};
60</script>
61</body>
62</html>
© 2003 – 2019 CKSource – Frederico Knabben. All rights reserved. | Terms of use | Privacy policy