index.html 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <title>Caret.js</title>
  5. <meta http-equiv="x-ua-compatible" content="IE=Edge"/>
  6. <meta name="viewport" content="width=device-width initial-scale=1.0 user-scalable=no">
  7. <link href='http://fonts.googleapis.com/css?family=PT+Sans:400,700' rel='stylesheet' type='text/css'>
  8. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
  9. <script type="text/javascript" src="src/jquery.caret.js"></script>
  10. <!-- // <script type="text/javascript" src="ckeditor/ckeditor.js"></script> -->
  11. <!-- // <script type="text/javascript" src="http://cdn.staticfile.org/ckeditor/4.2/ckeditor.js"></script> -->
  12. <script type="text/javascript">
  13. $(function () {
  14. var $input = $('#input');
  15. var $editable = $('#editable');
  16. function resetOffset($textField) {
  17. var offset = $textField.caret('offset');
  18. var position = $textField.caret('position');
  19. resizeBox(offset, position);
  20. return offset
  21. }
  22. function resizeBox (offset, position) {
  23. $('.offset-box').css({'width': offset.left, 'height': offset.top})
  24. $('.indicators')
  25. .offset({left: offset.left, top: offset.top + offset.height + 2})
  26. .find('.offset-indicator')
  27. .html("Offset: left: " + offset.left + ", " + "top: " + offset.top + "&nbsp;" + "height: " + offset.height);
  28. $('.position-box').css({'width': position.left, 'height': position.top})
  29. $('.position-indicator')
  30. .html("Position: left: " + position.left + ", " + "top: " + position.top + "&nbsp;");
  31. }
  32. $input.on('focus keyup mouseup', function(){
  33. resetOffset($input);
  34. });
  35. $editable.on('focus keyup mouseup', function(){
  36. resetOffset($editable)
  37. });
  38. $(window).resize(function() {
  39. if ($input.is(":focus"))
  40. resetOffset($input);
  41. else
  42. resetOffset($editable);
  43. });
  44. $input.caret('pos', 53).focus();
  45. // CKEDITOR.config.toolbar = [[ 'Source', '-', 'Bold', 'Italic' ]];
  46. // CKEDITOR.replace( 'ckEditor', {
  47. // });
  48. // CKEDITOR.instances.ckEditor.on('instanceReady', function() {
  49. // ifr = $('.cke_wysiwyg_frame')[0];
  50. // $ckBody = $('body', ifr.contentDocument);
  51. // $ckBody.on('keyup mouseup', function() {
  52. // offset = $ckBody.caret('offset');
  53. // resizeBox(offset);
  54. // });
  55. ifr = $('#iframe1')[0];
  56. ifrBody = ifr.contentDocument.body;
  57. ifrBody.contentEditable = true;
  58. ifrBody.id = 'ifrBody';
  59. ifrBody.innerHTML = 'For <strong>WYSIWYG</strong> such as <strong>ckeditor</strong>'
  60. $(ifrBody).on('keyup mouseup', function() {
  61. offset = $(ifrBody).caret('offset', {iframe: ifr});
  62. offset.left += $(ifr).offset().left;
  63. offset.top += $(ifr).offset().top;
  64. position = $(ifrBody).caret('position', {iframe: ifr});
  65. resizeBox(offset, position);
  66. });
  67. });
  68. </script>
  69. <style type="text/css">
  70. html, body {
  71. background:#F9F9F9;
  72. padding: 0;
  73. margin: 0;
  74. font: 14px/1.6 "Lucida Grande", "Helvetica", sans-serif;
  75. color: #333;
  76. }
  77. h1,h2,h3,h4 {
  78. font-family: 'PT Sans', sans-serif;
  79. line-height: 40px;
  80. color: inherit;
  81. font-weight: bold;
  82. margin: 10px 0;
  83. text-rendering: optimizelegibility;
  84. }
  85. h2,h3 {
  86. color: gray;
  87. }
  88. header {
  89. margin-top:70px;
  90. margin-bottom: 50px;
  91. }
  92. header h1 {
  93. text-align: center;
  94. font-size:56px;
  95. }
  96. h1 i {
  97. color: rgb(182, 180, 180);
  98. font-style: normal;
  99. font-weight: normal;
  100. }
  101. span {
  102. position: absolute;
  103. display: inline-block;
  104. }
  105. a {
  106. color: #4183C4;
  107. text-decoration: none;
  108. }
  109. a:hover {
  110. text-decoration: underline;
  111. }
  112. strong {
  113. color: #424242;
  114. }
  115. .wrapper {
  116. width: 55%;
  117. padding: 20px;
  118. margin: 0 auto;
  119. }
  120. @media only screen and (max-width: 600px) {
  121. .wrapper {
  122. width: 95%;
  123. }
  124. }
  125. @media only screen and (max-width: 1120px) {
  126. .wrapper {
  127. width: 80%;
  128. }
  129. }
  130. .inputor {
  131. overflow: auto;
  132. height: 160px;
  133. width: 90%;
  134. border: 1px solid #dadada;
  135. border-radius: 4px;
  136. padding: 5px 8px;
  137. outline: 0 none;
  138. margin: 10px 0;
  139. background: white;
  140. }
  141. .inputor:focus {
  142. border: 1px solid rgb(6, 150, 247);
  143. }
  144. .github {
  145. text-align: center;
  146. }
  147. footer {
  148. margin: 30px 0;
  149. }
  150. .offset-box {
  151. border-right: 2px dashed gray;
  152. border-bottom: 2px dashed gray;
  153. position: absolute;
  154. top: 0;
  155. left: 0;
  156. z-index: 999;
  157. }
  158. .offset-box > .position-box {
  159. border-right: 2px dashed rgb(6, 150, 247);
  160. border-bottom: 2px dashed rgb(6, 150, 247);
  161. position: absolute;
  162. bottom: 0;
  163. right: 0;
  164. z-index: 10000;
  165. }
  166. .indicators > .offset-indicator {
  167. border: 1px solid gray;
  168. position: absolute;
  169. z-index: 999;
  170. padding: 0 3px;
  171. border-radius: 3px;
  172. }
  173. .indicators > .position-indicator {
  174. border: 1px solid rgb(6, 150, 247);
  175. position: absolute;
  176. bottom: -50px;
  177. padding: 0 3px;
  178. border-radius: 3px;
  179. }
  180. </style>
  181. </head>
  182. <body>
  183. <div class="container wrapper">
  184. <!-- <a id="github" href="https://github.com/ichord/Caret.js" target="_blank"><img style="position: absolute; top: 0; right: 0; border: 0; z-index:999" src="http://s3.amazonaws.com/github/ribbons/forkme_right_darkblue_121621.png" alt="Fork me on GitHub"></a> -->
  185. <header>
  186. <h1>Caret<i>.js</i></h1>
  187. </header>
  188. <div id="main">
  189. <h2>Textarea</h2>
  190. <textarea id="input" class="inputor">
  191. Type something here for fun!!
  192. </textarea>
  193. <h2>ContentEditable</h2>
  194. <div id="editable" class="inputor" contentEditable="true">
  195. Hello, some <b>bold</b> and <i>italic</i> and <b><i>bold</i></b> text
  196. </div>
  197. <h2>iframe body</h2>
  198. <iframe id="iframe1" src="" class="inputor">
  199. </iframe>
  200. <div class="offset-box">
  201. <div class="position-box"></div>
  202. </div>
  203. <div class="indicators">
  204. <div class="offset-indicator"></div>
  205. <div class="position-indicator"></div>
  206. </div>
  207. <footer>
  208. <h2>
  209. -> <a class="github" href="https://github.com/ichord/Caret.js">Fork me on GitHub!</a>
  210. </h2>
  211. </footer>
  212. </div>
  213. </div>
  214. </body>
  215. </html>