Advanced Access Manager - Version 2.1

Version Description

  • Fixed issue with Admin Menu restrictions (thanks to MikeB2B)
  • Added Polish Translation
  • Fixed issue with Widgets restriction
  • Improved internal User & Role handling
  • Implemented caching mechanism
  • Extended Update mechanism (remove the AAM cache after update)
  • Added New ConfigPress setting aam.caching (by default is FALSE)
  • Improved Metabox & Widgets filtering mechanism
  • Added French Translation (by Moskito7)
  • Added "My Feature" Tab
  • Regenerated .pot file
Download this release

Release Info

Developer vasyl_m
Plugin Icon 128x128 Advanced Access Manager
Version 2.1
Comparing to
See all releases

Code changes from version 2.0 to 2.1

Files changed (161) hide show
  1. aam.php +41 -57
  2. application/control/object.php +22 -0
  3. application/control/object/backup.php +7 -0
  4. application/control/object/capability.php +7 -0
  5. application/control/object/configpress.php +19 -7
  6. application/control/object/event.php +7 -0
  7. application/control/object/menu.php +13 -3
  8. application/control/object/metabox.php +1 -1
  9. application/control/object/post.php +26 -1
  10. application/control/object/term.php +18 -6
  11. application/control/subject.php +122 -13
  12. application/control/subject/role.php +41 -1
  13. application/control/subject/user.php +1 -1
  14. application/control/subject/visitor.php +46 -15
  15. application/core/migrate.php +9 -8
  16. application/core/update.php +79 -15
  17. application/view/ajax.php +1 -1
  18. application/view/event.php +2 -1
  19. application/view/manager.php +4 -1
  20. application/view/post.php +4 -1
  21. application/view/tmpl/menu.phtml +1 -1
  22. config.php +5 -2
  23. extension/AAM_Multisite_Support/extension.php +2 -2
  24. extension/AAM_My_Feature/extension.php +133 -0
  25. extension/AAM_My_Feature/images/message-active.png +0 -0
  26. extension/AAM_My_Feature/images/message.png +0 -0
  27. extension/AAM_My_Feature/images/talk-active.png +0 -0
  28. extension/AAM_My_Feature/images/talk.png +0 -0
  29. extension/AAM_My_Feature/images/worker.png +0 -0
  30. extension/AAM_My_Feature/index.php +14 -0
  31. extension/AAM_My_Feature/my_feature.css +66 -0
  32. extension/AAM_My_Feature/my_feature.js +20 -0
  33. extension/AAM_My_Feature/ui.phtml +23 -0
  34. lang/aam-fr_FR.mo +0 -0
  35. lang/aam-fr_FR.po +337 -0
  36. lang/aam-pl_PL.mo +0 -0
  37. lang/aam-pl_PL.po +336 -0
  38. lang/aam.pot +105 -55
  39. media/css/images/capability/add-active.png +0 -0
  40. media/css/images/capability/add.png +0 -0
  41. media/css/images/capability/checked.png +0 -0
  42. media/css/images/capability/copy-active.png +0 -0
  43. media/css/images/capability/copy.png +0 -0
  44. media/css/images/capability/delete-active.png +0 -0
  45. media/css/images/capability/delete.png +0 -0
  46. media/css/images/capability/filter-active.png +0 -0
  47. media/css/images/capability/filter.png +0 -0
  48. media/css/images/capability/restore-active.png +0 -0
  49. media/css/images/capability/restore.png +0 -0
  50. media/css/images/capability/select-active.png +0 -0
  51. media/css/images/capability/select.png +0 -0
  52. media/css/images/capability/unchecked.png +0 -0
  53. media/css/images/cmanager/add-active.png +0 -0
  54. media/css/images/cmanager/add.png +0 -0
  55. media/css/images/cmanager/block-user-active.png +0 -0
  56. media/css/images/cmanager/block-user.png +0 -0
  57. media/css/images/cmanager/delete-active.png +0 -0
  58. media/css/images/cmanager/delete.png +0 -0
  59. media/css/images/cmanager/edit-active.png +0 -0
  60. media/css/images/cmanager/edit-user-active.png +0 -0
  61. media/css/images/cmanager/edit-user.png +0 -0
  62. media/css/images/cmanager/edit.png +0 -0
  63. media/css/images/cmanager/filter-active.png +0 -0
  64. media/css/images/cmanager/filter.png +0 -0
  65. media/css/images/cmanager/multisite-active.png +0 -0
  66. media/css/images/cmanager/multisite.png +0 -0
  67. media/css/images/cmanager/refresh-active.png +0 -0
  68. media/css/images/cmanager/refresh.png +0 -0
  69. media/css/images/cmanager/role-active.png +0 -0
  70. media/css/images/cmanager/role.png +0 -0
  71. media/css/images/cmanager/select-active.png +0 -0
  72. media/css/images/cmanager/select.png +0 -0
  73. media/css/images/cmanager/settings-active.png +0 -0
  74. media/css/images/cmanager/settings.png +0 -0
  75. media/css/images/cmanager/user-active.png +0 -0
  76. media/css/images/cmanager/user.png +0 -0
  77. media/css/images/cmanager/visitor-active.png +0 -0
  78. media/css/images/cmanager/visitor.png +0 -0
  79. media/css/images/configpress/pdf-active.png +0 -0
  80. media/css/images/configpress/pdf.png +0 -0
  81. media/css/images/cpanel/help-forum-active.png +0 -0
  82. media/css/images/cpanel/help-forum.png +0 -0
  83. media/css/images/cpanel/message-active.png +0 -0
  84. media/css/images/cpanel/message.png +0 -0
  85. media/css/images/cpanel/restore-active.png +0 -0
  86. media/css/images/cpanel/restore.png +0 -0
  87. media/css/images/cpanel/save-active.png +0 -0
  88. media/css/images/cpanel/save.png +0 -0
  89. media/css/images/cpanel/star-active.png +0 -0
  90. media/css/images/cpanel/star.png +0 -0
  91. media/css/images/cpanel/twitter-active.png +0 -0
  92. media/css/images/cpanel/twitter.png +0 -0
  93. media/css/images/event/add-active.png +0 -0
  94. media/css/images/event/add.png +0 -0
  95. media/css/images/event/delete-active.png +0 -0
  96. media/css/images/event/delete.png +0 -0
  97. media/css/images/event/edit-active.png +0 -0
  98. media/css/images/event/edit.png +0 -0
  99. media/css/images/extension/download-active.png +0 -0
  100. media/css/images/extension/download.png +0 -0
  101. media/css/images/extension/forum-active.png +0 -0
  102. media/css/images/extension/forum.png +0 -0
  103. media/css/images/extension/link-active.png +0 -0
  104. media/css/images/extension/link.png +0 -0
  105. media/css/images/extension/message-active.png +0 -0
  106. media/css/images/extension/message.png +0 -0
  107. media/css/images/extension/ok-active.png +0 -0
  108. media/css/images/extension/ok.png +0 -0
  109. media/css/images/extension/plus-active.png +0 -0
  110. media/css/images/extension/plus.png +0 -0
  111. media/css/images/extension/purchase-active.png +0 -0
  112. media/css/images/extension/purchase.png +0 -0
  113. media/css/images/extension/twitter-active.png +0 -0
  114. media/css/images/extension/twitter.png +0 -0
  115. media/css/images/extension/youtube-active.png +0 -0
  116. media/css/images/extension/youtube.png +0 -0
  117. media/css/images/feature-active.png +0 -0
  118. media/css/images/lock.png +0 -0
  119. media/css/images/menu/checked.png +0 -0
  120. media/css/images/menu/sorting-active.png +0 -0
  121. media/css/images/menu/sorting.png +0 -0
  122. media/css/images/menu/unchecked.png +0 -0
  123. media/css/images/menu/visibility-active.png +0 -0
  124. media/css/images/menu/visibility.png +0 -0
  125. media/css/images/metabox/add-active.png +0 -0
  126. media/css/images/metabox/add.png +0 -0
  127. media/css/images/metabox/checked.png +0 -0
  128. media/css/images/metabox/link-active.png +0 -0
  129. media/css/images/metabox/link.png +0 -0
  130. media/css/images/metabox/refresh-active.png +0 -0
  131. media/css/images/metabox/refresh.png +0 -0
  132. media/css/images/metabox/unchecked.png +0 -0
  133. media/css/images/post/checked.png +0 -0
  134. media/css/images/post/edit-active.png +0 -0
  135. media/css/images/post/edit.png +0 -0
  136. media/css/images/post/filter-active.png +0 -0
  137. media/css/images/post/filter.png +0 -0
  138. media/css/images/post/info-active.png +0 -0
  139. media/css/images/post/info.png +0 -0
  140. media/css/images/post/lock-big.png +0 -0
  141. media/css/images/post/lock.png +0 -0
  142. media/css/images/post/post.png +0 -0
  143. media/css/images/post/refresh-active.png +0 -0
  144. media/css/images/post/refresh.png +0 -0
  145. media/css/images/post/settings-active.png +0 -0
  146. media/css/images/post/settings.png +0 -0
  147. media/css/images/post/unchecked.png +0 -0
  148. media/css/images/search-active.png +0 -0
  149. media/css/images/search.png +0 -0
  150. media/css/images/sort_asc.png +0 -0
  151. media/css/images/sort_asc_disabled.png +0 -0
  152. media/css/images/sort_both.png +0 -0
  153. media/css/images/sort_desc.png +0 -0
  154. media/css/images/sort_desc_disabled.png +0 -0
  155. media/css/images/table-filtered.png +0 -0
  156. media/css/images/ui-icons_222222_256x240.png +0 -0
  157. media/css/images/ui-icons_454545_256x240.png +0 -0
  158. media/css/images/ui-icons_888888_256x240.png +0 -0
  159. media/js/aam.js +2 -2
  160. media/js/codemirror.js +1 -5829
  161. readme.txt +17 -2
aam.php CHANGED
@@ -1,9 +1,8 @@
1
  <?php
2
-
3
  /**
4
  Plugin Name: Advanced Access Manager
5
  Description: Manage User and Role Access to WordPress Backend and Frontend.
6
- Version: 2.0
7
  Author: Vasyl Martyniuk <support@wpaam.com>
8
  Author URI: http://www.wpaam.com
9
 
@@ -80,13 +79,7 @@ class aam {
80
  //manager AAM Ajax Requests
81
  add_action('wp_ajax_aam', array($this, 'ajax'));
82
  //manager WordPress metaboxes
83
- //add_action("do_meta_boxes", array($this, 'metaboxes'), 1, 3);
84
  add_action("in_admin_header", array($this, 'metaboxes'), 999);
85
- //add_action("add_meta_boxes", array($this, 'filterMetaboxes'), 999, 2);
86
- //add_filter(
87
- // 'get_user_option_meta-box-order_dashboard',
88
- // array($this, 'dashboardFilter'), 999, 3
89
- //);
90
  //manager user search and authentication control
91
  add_filter('user_search_columns', array($this, 'searchColumns'));
92
  //terms & post restriction handlers
@@ -117,6 +110,9 @@ class aam {
117
 
118
  //load extensions only when admin
119
  $this->loadExtensions();
 
 
 
120
  }
121
 
122
  /**
@@ -127,7 +123,7 @@ class aam {
127
  * @access public
128
  */
129
  public function checkUpdate() {
130
- if (class_exists('aam_Core_Update') && (AAM_APPL_ENV != 'development')) {
131
  $update = new aam_Core_Update($this);
132
  $update->run();
133
  }
@@ -219,10 +215,11 @@ class aam {
219
  */
220
  public function getTerms($area, $terms) {
221
  if (is_array($terms)) {
222
- $object = $this->getUser()->getObject(aam_Control_Object_Term::UID);
223
  foreach ($terms as $i => $term) {
224
  if (is_object($term)) {
225
- $object->init($term->term_id);
 
 
226
  if ($object->has($area, aam_Control_Object_Term::ACTION_LIST)) {
227
  unset($terms[$i]);
228
  }
@@ -244,10 +241,12 @@ class aam {
244
  * @todo Cache this process
245
  */
246
  public function getPages($pages){
247
- $object = $this->getUser()->getObject(aam_Control_Object_Post::UID);
248
  if (is_array($pages)){
249
  foreach($pages as $i => $page){
250
- $object->init($page);
 
 
251
  if ($object->has('frontend', aam_Control_Object_Post::ACTION_EXCLUDE)){
252
  unset($pages[$i]);
253
  }
@@ -268,17 +267,18 @@ class aam {
268
  */
269
  public function getNavigationMenu($pages){
270
  if (is_array($pages)){
271
- $post = $this->getUser()->getObject(aam_Control_Object_Post::UID);
272
- $term = $this->getUser()->getObject(aam_Control_Object_Term::UID);
273
  foreach($pages as $i => $page){
274
  if ($page->type === 'taxonomy'){
275
- $object = $term;
 
 
276
  $exclude = aam_Control_Object_Term::ACTION_EXCLUDE;
277
  } else {
278
- $object = $post;
 
 
279
  $exclude = aam_Control_Object_Post::ACTION_EXCLUDE;
280
  }
281
- $object->init($page->object_id);
282
 
283
  if ($object->has('frontend', $exclude)){
284
  unset($pages[$i]);
@@ -782,10 +782,10 @@ class aam {
782
  */
783
  public function ajax() {
784
  check_ajax_referer('aam_ajax');
785
-
786
  //clean buffer to make sure that nothing messing around with system
787
  while (@ob_end_clean());
788
-
789
  //process ajax request
790
  $model = new aam_View_Ajax;
791
  echo $model->run();
@@ -802,51 +802,24 @@ class aam {
802
  public function metaboxes() {
803
  global $post;
804
 
805
- $post_type = ($post instanceof WP_Post ? $post->post_type : '');
 
 
 
 
 
 
 
806
 
807
  if (aam_Core_Request::get('aam_meta_init')) {
808
  $model = new aam_View_Metabox;
809
- $model->run($post_type);
810
  } else {
811
  $this->getUser()->getObject(aam_Control_Object_Metabox::UID)
812
- ->filterBackend($post_type, 'dashboard');
813
  }
814
  }
815
 
816
- /**
817
- * Filter Dashboard Widgets & Metaboxes
818
- *
819
- * @param array $result
820
- * @param mixed $option
821
- * @param mixed $user
822
- *
823
- * @return void
824
- *
825
- * @access public
826
- * @deprecated since 2.0 Beta 3
827
- */
828
- public function dashboardFilter($result, $option, $user) {
829
- $this->getUser()->getObject(
830
- aam_Control_Object_Metabox::UID)->filterBackend('dashboard');
831
- }
832
-
833
- /**
834
- * Filter Screen Metaboxes
835
- *
836
- * @param string $post_type
837
- * @param WP_Post $post
838
- *
839
- * @return void
840
- *
841
- * @access public
842
- * @deprecated since 2.0 Beta 3
843
- */
844
- public function filterMetaboxes($post_type, $post) {
845
- $this->getUser()->getObject(aam_Control_Object_Metabox::UID)->filterBackend(
846
- $post_type, $post
847
- );
848
- }
849
-
850
  /**
851
  * Register Admin Menu
852
  *
@@ -983,6 +956,17 @@ class aam {
983
  $this->_user = $user;
984
  }
985
 
 
 
 
 
 
 
 
 
 
 
 
986
  /**
987
  * Load Installed extensions
988
  *
1
  <?php
 
2
  /**
3
  Plugin Name: Advanced Access Manager
4
  Description: Manage User and Role Access to WordPress Backend and Frontend.
5
+ Version: 2.1
6
  Author: Vasyl Martyniuk <support@wpaam.com>
7
  Author URI: http://www.wpaam.com
8
 
79
  //manager AAM Ajax Requests
80
  add_action('wp_ajax_aam', array($this, 'ajax'));
81
  //manager WordPress metaboxes
 
82
  add_action("in_admin_header", array($this, 'metaboxes'), 999);
 
 
 
 
 
83
  //manager user search and authentication control
84
  add_filter('user_search_columns', array($this, 'searchColumns'));
85
  //terms & post restriction handlers
110
 
111
  //load extensions only when admin
112
  $this->loadExtensions();
113
+
114
+ //add shutdown action
115
+ add_action('shutdown', array($this, 'shutdown'), 1);
116
  }
117
 
118
  /**
123
  * @access public
124
  */
125
  public function checkUpdate() {
126
+ if (aam_Core_API::getBlogOption('aam_updated', '', 1) != AAM_VERSION) {
127
  $update = new aam_Core_Update($this);
128
  $update->run();
129
  }
215
  */
216
  public function getTerms($area, $terms) {
217
  if (is_array($terms)) {
 
218
  foreach ($terms as $i => $term) {
219
  if (is_object($term)) {
220
+ $object = $this->getUser()->getObject(
221
+ aam_Control_Object_Term::UID, $term->term_id
222
+ );
223
  if ($object->has($area, aam_Control_Object_Term::ACTION_LIST)) {
224
  unset($terms[$i]);
225
  }
241
  * @todo Cache this process
242
  */
243
  public function getPages($pages){
244
+
245
  if (is_array($pages)){
246
  foreach($pages as $i => $page){
247
+ $object = $this->getUser()->getObject(
248
+ aam_Control_Object_Post::UID, $page->ID
249
+ );
250
  if ($object->has('frontend', aam_Control_Object_Post::ACTION_EXCLUDE)){
251
  unset($pages[$i]);
252
  }
267
  */
268
  public function getNavigationMenu($pages){
269
  if (is_array($pages)){
 
 
270
  foreach($pages as $i => $page){
271
  if ($page->type === 'taxonomy'){
272
+ $object = $this->getUser()->getObject(
273
+ aam_Control_Object_Term::UID, $page->object_id
274
+ );
275
  $exclude = aam_Control_Object_Term::ACTION_EXCLUDE;
276
  } else {
277
+ $object = $this->getUser()->getObject(
278
+ aam_Control_Object_Post::UID, $page->object_id
279
+ );
280
  $exclude = aam_Control_Object_Post::ACTION_EXCLUDE;
281
  }
 
282
 
283
  if ($object->has('frontend', $exclude)){
284
  unset($pages[$i]);
782
  */
783
  public function ajax() {
784
  check_ajax_referer('aam_ajax');
785
+
786
  //clean buffer to make sure that nothing messing around with system
787
  while (@ob_end_clean());
788
+
789
  //process ajax request
790
  $model = new aam_View_Ajax;
791
  echo $model->run();
802
  public function metaboxes() {
803
  global $post;
804
 
805
+ //make sure that nobody is playing with screen options
806
+ if ($post instanceof WP_Post){
807
+ $screen = $post->post_type;
808
+ } elseif($screen_object = get_current_screen()) {
809
+ $screen = $screen_object->id;
810
+ } else {
811
+ $screen = '';
812
+ }
813
 
814
  if (aam_Core_Request::get('aam_meta_init')) {
815
  $model = new aam_View_Metabox;
816
+ $model->run($screen);
817
  } else {
818
  $this->getUser()->getObject(aam_Control_Object_Metabox::UID)
819
+ ->filterBackend($screen);
820
  }
821
  }
822
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
823
  /**
824
  * Register Admin Menu
825
  *
956
  $this->_user = $user;
957
  }
958
 
959
+ /**
960
+ * Execute before shutdown actions
961
+ *
962
+ * @return void
963
+ *
964
+ * @access public
965
+ */
966
+ public function shutdown(){
967
+ $this->getUser()->saveCache();
968
+ }
969
+
970
  /**
971
  * Load Installed extensions
972
  *
application/control/object.php CHANGED
@@ -43,6 +43,28 @@ abstract class aam_Control_Object {
43
  $this->init($object_id);
44
  }
45
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
  /**
47
  * Initialize object
48
  *
43
  $this->init($object_id);
44
  }
45
 
46
+ /**
47
+ * Sleep method
48
+ *
49
+ * Used for caching mechanism
50
+ *
51
+ * @return array
52
+ *
53
+ * @access public
54
+ */
55
+ public function __sleep(){
56
+ return array('_option');
57
+ }
58
+
59
+ /**
60
+ * Indicate either object can be cached on not
61
+ *
62
+ * @return boolean
63
+ *
64
+ * @access public
65
+ */
66
+ abstract public function cacheObject();
67
+
68
  /**
69
  * Initialize object
70
  *
application/control/object/backup.php CHANGED
@@ -67,6 +67,13 @@ class aam_Control_Object_Backup extends aam_Control_Object {
67
  return self::UID;
68
  }
69
 
 
 
 
 
 
 
 
70
  /**
71
  *
72
  * @param type $option
67
  return self::UID;
68
  }
69
 
70
+ /**
71
+ * @inheritdoc
72
+ */
73
+ public function cacheObject(){
74
+ return false;
75
+ }
76
+
77
  /**
78
  *
79
  * @param type $option
application/control/object/capability.php CHANGED
@@ -42,6 +42,13 @@ class aam_Control_Object_Capability extends aam_Control_Object {
42
  }
43
  }
44
 
 
 
 
 
 
 
 
45
  /**
46
  *
47
  * @param type $object_id
42
  }
43
  }
44
 
45
+ /**
46
+ * @inheritdoc
47
+ */
48
+ public function cacheObject(){
49
+ return false;
50
+ }
51
+
52
  /**
53
  *
54
  * @param type $object_id
application/control/object/configpress.php CHANGED
@@ -38,6 +38,20 @@ class aam_Control_Object_ConfigPress extends aam_Control_Object {
38
  */
39
  private $_tree = null;
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  /**
42
  *
43
  * @param type $config_press
@@ -74,13 +88,11 @@ class aam_Control_Object_ConfigPress extends aam_Control_Object {
74
  * @param type $object_id
75
  */
76
  public function init($object_id) {
77
- if (empty($this->_option)) {
78
- $filename = aam_Core_API::getBlogOption('aam_' . self::UID, '');
79
- if ($filename && file_exists(AAM_TEMP_DIR . $filename)) {
80
- $this->setOption($filename);
81
- $this->setConfig(file_get_contents(AAM_TEMP_DIR . $filename));
82
- $this->parseConfig(AAM_TEMP_DIR . $filename);
83
- }
84
  }
85
  }
86
 
38
  */
39
  private $_tree = null;
40
 
41
+ /**
42
+ * @inheritdoc
43
+ */
44
+ public function __sleep(){
45
+ return array('_option', '_config', '_tree');
46
+ }
47
+
48
+ /**
49
+ * @inheritdoc
50
+ */
51
+ public function cacheObject(){
52
+ return false;
53
+ }
54
+
55
  /**
56
  *
57
  * @param type $config_press
88
  * @param type $object_id
89
  */
90
  public function init($object_id) {
91
+ $filename = aam_Core_API::getBlogOption('aam_' . self::UID, '');
92
+ if ($filename && file_exists(AAM_TEMP_DIR . $filename)) {
93
+ $this->setOption($filename);
94
+ $this->setConfig(file_get_contents(AAM_TEMP_DIR . $filename));
95
+ $this->parseConfig(AAM_TEMP_DIR . $filename);
 
 
96
  }
97
  }
98
 
application/control/object/event.php CHANGED
@@ -36,6 +36,13 @@ class aam_Control_Object_Event extends aam_Control_Object {
36
  }
37
  }
38
 
 
 
 
 
 
 
 
39
  /**
40
  *
41
  * @return type
36
  }
37
  }
38
 
39
+ /**
40
+ * @inheritdoc
41
+ */
42
+ public function cacheObject(){
43
+ return true;
44
+ }
45
+
46
  /**
47
  *
48
  * @return type
application/control/object/menu.php CHANGED
@@ -114,6 +114,13 @@ class aam_Control_Object_Menu extends aam_Control_Object {
114
  }
115
  }
116
 
 
 
 
 
 
 
 
117
  /**
118
  *
119
  * @return type
@@ -153,11 +160,14 @@ class aam_Control_Object_Menu extends aam_Control_Object {
153
  */
154
  public function has($menu) {
155
  $response = false;
156
- if (isset($this->_option[$menu])) {
157
- $response = (intval($this->_option[$menu]) ? true : false);
 
 
 
158
  }
159
 
160
  return $response;
161
  }
162
 
163
- }
114
  }
115
  }
116
 
117
+ /**
118
+ * @inheritdoc
119
+ */
120
+ public function cacheObject(){
121
+ return true;
122
+ }
123
+
124
  /**
125
  *
126
  * @return type
160
  */
161
  public function has($menu) {
162
  $response = false;
163
+ //decode URL in case of any special characters like &amp;
164
+ $menu_decoded = htmlspecialchars_decode($menu);
165
+ //check if menu is restricted
166
+ if (isset($this->_option[$menu_decoded])) {
167
+ $response = (intval($this->_option[$menu_decoded]) ? true : false);
168
  }
169
 
170
  return $response;
171
  }
172
 
173
+ }
application/control/object/metabox.php CHANGED
@@ -1 +1 @@
1
- <?php
2
  * ======================================================================
3
  * LICENSE: This file is subject to the terms and conditions defined in *
4
  * file 'license.txt', which is part of this source code package. *
5
  * ======================================================================
6
  */
7
  *
8
  * @package AAM
9
  * @author Vasyl Martyniuk <support@wpaam.com>
10
  * @copyright Copyright C 2013 Vasyl Martyniuk
11
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
12
  */
13
  /**
14
  *
15
  */
16
  const UID = 'metabox';
17
  /**
18
  *
19
  * @var type
20
  */
21
  private $_option = array();
22
  /**
23
  *
24
  * @global type $wp_registered_widgets
25
  * @param type $sidebar_widgets
26
  * @return type
27
  */
28
  public function filterFrontend($sidebar_widgets) {
29
  global $wp_registered_widgets;
30
  if (is_array($wp_registered_widgets)) {
31
  foreach ($wp_registered_widgets as $id => $data) {
32
  if (is_object($data['callback'][0])) {
33
  $callback = get_class($data['callback'][0]);
34
  } elseif (is_string($data['callback'][0])) {
35
  $callback = $data['callback'][0];
36
  }
37
  if ($this->has('widgets', $callback)) {
38
  unregister_widget($callback);
39
  //remove it from registered widget global var!!
40
  //INFORM: Why Unregister Widget does not clear global var?
41
  unset($wp_registered_widgets[$id]);
42
  }
43
  }
44
  }
45
  return $sidebar_widgets;
46
  }
47
  /**
48
  *
49
  * @global type $wp_meta_boxes
50
  * @param type $screen
51
  * @param type $post
52
  */
53
  public function filterBackend($screen, $post = null) {
54
  global $wp_meta_boxes;
55
  if (is_array($wp_meta_boxes)) {
56
  foreach ($wp_meta_boxes as $screen_id => $zones) {
57
  if ($screen == $screen_id) {
58
  foreach ($zones as $zone => $priorities) {
59
  foreach ($priorities as $priority => $metaboxes) {
60
  foreach ($metaboxes as $metabox => $data) {
61
  if ($this->has($screen_id, $metabox)) {
62
  remove_meta_box($metabox, $screen_id, $zone);
63
  }
64
  }
65
  }
66
  }
67
  }
68
  }
69
  }
70
  }
71
  /**
72
  *
73
  * @param type $metaboxes
74
  */
75
  public function save($metaboxes = null) {
76
  if (is_array($metaboxes)) {
77
  $this->getSubject()->updateOption($metaboxes, self::UID);
78
  }
79
  }
80
  /**
81
  *
82
  * @return type
83
  */
84
  public function backup() {
85
  return $this->getSubject()->readOption(self::UID, '', array());
86
  }
87
  /**
88
  *
89
  * @return type
90
  */
91
  public function getUID() {
92
  return self::UID;
93
  }
94
  /**
95
  *
96
  * @param type $option
97
  */
98
  public function setOption($option) {
99
  $this->_option = (is_array($option) ? $option : array());
100
  }
101
  /**
102
  *
103
  * @return type
104
  */
105
  public function getOption() {
106
  return $this->_option;
107
  }
108
  /**
109
  *
110
  * @param type $group
111
  * @param type $metabox
112
  * @return type
113
  */
114
  public function has($group, $metabox) {
115
  $response = false;
116
  if (isset($this->_option[$group][$metabox])) {
117
  $response = (intval($this->_option[$group][$metabox]) ? true : false);
118
  }
119
  return $response;
120
  }
 
121
  * ======================================================================
122
  * LICENSE: This file is subject to the terms and conditions defined in *
123
  * file 'license.txt', which is part of this source code package. *
124
  * ======================================================================
125
  */
126
  *
127
  * @package AAM
128
  * @author Vasyl Martyniuk <support@wpaam.com>
129
  * @copyright Copyright C 2013 Vasyl Martyniuk
130
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
131
  */
132
  /**
133
  *
134
  */
135
  const UID = 'metabox';
136
  /**
137
  *
138
  * @var type
139
  */
140
  private $_option = array();
141
  /**
142
  *
143
  * @global type $wp_registered_widgets
144
  * @param type $sidebar_widgets
145
  * @return type
146
  */
147
  public function filterFrontend($sidebar_widgets) {
148
  global $wp_registered_widgets;
149
  if (is_array($wp_registered_widgets)) {
150
  foreach ($wp_registered_widgets as $id => $data) {
151
  if (is_object($data['callback'][0])) {
152
  $callback = get_class($data['callback'][0]);
153
  } elseif (is_string($data['callback'][0])) {
154
  $callback = $data['callback'][0];
155
  }
156
  if ($this->has('widgets', $callback)) {
157
  unregister_widget($callback);
158
  //remove it from registered widget global var!!
159
  //INFORM: Why Unregister Widget does not clear global var?
160
  unset($wp_registered_widgets[$id]);
161
  }
162
  }
163
  }
164
  return $sidebar_widgets;
165
  }
166
  /**
167
  *
168
  * @global type $wp_meta_boxes
169
  * @param type $screen
170
  * @param type $post
171
  */
172
  public function filterBackend($screen, $post = null) {
173
  global $wp_meta_boxes;
174
  if (is_array($wp_meta_boxes)) {
175
  foreach ($wp_meta_boxes as $screen_id => $zones) {
176
  if ($screen == $screen_id) {
177
  foreach ($zones as $zone => $priorities) {
178
  foreach ($priorities as $priority => $metaboxes) {
179
  foreach ($metaboxes as $metabox => $data) {
180
  if ($this->has($screen_id, $metabox)) {
181
  remove_meta_box($metabox, $screen_id, $zone);
182
  }
183
  }
184
  }
185
  }
186
  }
187
  }
188
  }
189
  }
190
  /**
191
  *
192
  * @param type $metaboxes
193
  */
194
  public function save($metaboxes = null) {
195
  if (is_array($metaboxes)) {
196
  $this->getSubject()->updateOption($metaboxes, self::UID);
197
  }
198
  }
199
  /**
200
  * @inheritdoc
201
  */
202
  public function cacheObject(){
203
  return true;
204
  }
205
  /**
206
  *
207
  * @return type
208
  */
209
  public function backup() {
210
  return $this->getSubject()->readOption(self::UID, '', array());
211
  }
212
  /**
213
  *
214
  * @return type
215
  */
216
  public function getUID() {
217
  return self::UID;
218
  }
219
  /**
220
  *
221
  * @param type $option
222
  */
223
  public function setOption($option) {
224
  $this->_option = (is_array($option) ? $option : array());
225
  }
226
  /**
227
  *
228
  * @return type
229
  */
230
  public function getOption() {
231
  return $this->_option;
232
  }
233
  /**
234
  *
235
  * @param type $group
236
  * @param type $metabox
237
  * @return type
238
  */
239
  public function has($group, $metabox) {
240
  $response = false;
241
  if (isset($this->_option[$group][$metabox])) {
242
  $response = (intval($this->_option[$group][$metabox]) ? true : false);
243
  }
244
  return $response;
245
  }
 
1
  * ======================================================================
2
  * LICENSE: This file is subject to the terms and conditions defined in *
3
  * file 'license.txt', which is part of this source code package. *
4
  * ======================================================================
5
  */
6
  *
7
  * @package AAM
8
  * @author Vasyl Martyniuk <support@wpaam.com>
9
  * @copyright Copyright C 2013 Vasyl Martyniuk
10
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
11
  */
12
  /**
13
  *
14
  */
15
  const UID = 'metabox';
16
  /**
17
  *
18
  * @var type
19
  */
20
  private $_option = array();
21
  /**
22
  *
23
  * @global type $wp_registered_widgets
24
  * @param type $sidebar_widgets
25
  * @return type
26
  */
27
  public function filterFrontend($sidebar_widgets) {
28
  global $wp_registered_widgets;
29
  if (is_array($wp_registered_widgets)) {
30
  foreach ($wp_registered_widgets as $id => $data) {
31
  if (is_object($data['callback'][0])) {
32
  $callback = get_class($data['callback'][0]);
33
  } elseif (is_string($data['callback'][0])) {
34
  $callback = $data['callback'][0];
35
  }
36
  if ($this->has('widgets', $callback)) {
37
  unregister_widget($callback);
38
  //remove it from registered widget global var!!
39
  //INFORM: Why Unregister Widget does not clear global var?
40
  unset($wp_registered_widgets[$id]);
41
  }
42
  }
43
  }
44
  return $sidebar_widgets;
45
  }
46
  /**
47
  *
48
  * @global type $wp_meta_boxes
49
  * @param type $screen
50
  * @param type $post
51
  */
52
  public function filterBackend($screen, $post = null) {
53
  global $wp_meta_boxes;
54
  if (is_array($wp_meta_boxes)) {
55
  foreach ($wp_meta_boxes as $screen_id => $zones) {
56
  if ($screen == $screen_id) {
57
  foreach ($zones as $zone => $priorities) {
58
  foreach ($priorities as $priority => $metaboxes) {
59
  foreach ($metaboxes as $metabox => $data) {
60
  if ($this->has($screen_id, $metabox)) {
61
  remove_meta_box($metabox, $screen_id, $zone);
62
  }
63
  }
64
  }
65
  }
66
  }
67
  }
68
  }
69
  }
70
  /**
71
  *
72
  * @param type $metaboxes
73
  */
74
  public function save($metaboxes = null) {
75
  if (is_array($metaboxes)) {
76
  $this->getSubject()->updateOption($metaboxes, self::UID);
77
  }
78
  }
79
  /**
80
  *
81
  * @return type
82
  */
83
  public function backup() {
84
  return $this->getSubject()->readOption(self::UID, '', array());
85
  }
86
  /**
87
  *
88
  * @return type
89
  */
90
  public function getUID() {
91
  return self::UID;
92
  }
93
  /**
94
  *
95
  * @param type $option
96
  */
97
  public function setOption($option) {
98
  $this->_option = (is_array($option) ? $option : array());
99
  }
100
  /**
101
  *
102
  * @return type
103
  */
104
  public function getOption() {
105
  return $this->_option;
106
  }
107
  /**
108
  *
109
  * @param type $group
110
  * @param type $metabox
111
  * @return type
112
  */
113
  public function has($group, $metabox) {
114
  $response = false;
115
  if (isset($this->_option[$group][$metabox])) {
116
  $response = (intval($this->_option[$group][$metabox]) ? true : false);
117
  }
118
  return $response;
119
  }
120
+ <?php
121
  * ======================================================================
122
  * LICENSE: This file is subject to the terms and conditions defined in *
123
  * file 'license.txt', which is part of this source code package. *
124
  * ======================================================================
125
  */
126
  *
127
  * @package AAM
128
  * @author Vasyl Martyniuk <support@wpaam.com>
129
  * @copyright Copyright C 2013 Vasyl Martyniuk
130
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
131
  */
132
  /**
133
  *
134
  */
135
  const UID = 'metabox';
136
  /**
137
  *
138
  * @var type
139
  */
140
  private $_option = array();
141
  /**
142
  *
143
  * @global type $wp_registered_widgets
144
  * @param type $sidebar_widgets
145
  * @return type
146
  */
147
  public function filterFrontend($sidebar_widgets) {
148
  global $wp_registered_widgets;
149
  if (is_array($wp_registered_widgets)) {
150
  foreach ($wp_registered_widgets as $id => $data) {
151
  if (is_object($data['callback'][0])) {
152
  $callback = get_class($data['callback'][0]);
153
  } elseif (is_string($data['callback'][0])) {
154
  $callback = $data['callback'][0];
155
  }
156
  if ($this->has('widgets', $callback)) {
157
  unregister_widget($callback);
158
  //remove it from registered widget global var!!
159
  //INFORM: Why Unregister Widget does not clear global var?
160
  unset($wp_registered_widgets[$id]);
161
  }
162
  }
163
  }
164
  return $sidebar_widgets;
165
  }
166
  /**
167
  *
168
  * @global type $wp_meta_boxes
169
  * @param type $screen
170
  * @param type $post
171
  */
172
  public function filterBackend($screen, $post = null) {
173
  global $wp_meta_boxes;
174
  if (is_array($wp_meta_boxes)) {
175
  foreach ($wp_meta_boxes as $screen_id => $zones) {
176
  if ($screen == $screen_id) {
177
  foreach ($zones as $zone => $priorities) {
178
  foreach ($priorities as $priority => $metaboxes) {
179
  foreach ($metaboxes as $metabox => $data) {
180
  if ($this->has($screen_id, $metabox)) {
181
  remove_meta_box($metabox, $screen_id, $zone);
182
  }
183
  }
184
  }
185
  }
186
  }
187
  }
188
  }
189
  }
190
  /**
191
  *
192
  * @param type $metaboxes
193
  */
194
  public function save($metaboxes = null) {
195
  if (is_array($metaboxes)) {
196
  $this->getSubject()->updateOption($metaboxes, self::UID);
197
  }
198
  }
199
  /**
200
  * @inheritdoc
201
  */
202
  public function cacheObject(){
203
  return true;
204
  }
205
  /**
206
  *
207
  * @return type
208
  */
209
  public function backup() {
210
  return $this->getSubject()->readOption(self::UID, '', array());
211
  }
212
  /**
213
  *
214
  * @return type
215
  */
216
  public function getUID() {
217
  return self::UID;
218
  }
219
  /**
220
  *
221
  * @param type $option
222
  */
223
  public function setOption($option) {
224
  $this->_option = (is_array($option) ? $option : array());
225
  }
226
  /**
227
  *
228
  * @return type
229
  */
230
  public function getOption() {
231
  return $this->_option;
232
  }
233
  /**
234
  *
235
  * @param type $group
236
  * @param type $metabox
237
  * @return type
238
  */
239
  public function has($group, $metabox) {
240
  $response = false;
241
  if (isset($this->_option[$group][$metabox])) {
242
  $response = (intval($this->_option[$group][$metabox]) ? true : false);
243
  }
244
  return $response;
245
  }
application/control/object/post.php CHANGED
@@ -62,6 +62,20 @@ class aam_Control_Object_Post extends aam_Control_Object {
62
  */
63
  private $_option = array();
64
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
65
  /**
66
  *
67
  * @param type $params
@@ -115,8 +129,13 @@ class aam_Control_Object_Post extends aam_Control_Object {
115
  }
116
 
117
  /**
 
118
  *
119
- * @param type $object
 
 
 
 
120
  */
121
  public function init($object) {
122
  //make sure that we are dealing with WP_Post object
@@ -132,7 +151,13 @@ class aam_Control_Object_Post extends aam_Control_Object {
132
  }
133
 
134
  /**
 
135
  *
 
 
 
 
 
136
  */
137
  public function read() {
138
  $option = get_post_meta($this->getPost()->ID, $this->getOptionName(), true);
62
  */
63
  private $_option = array();
64
 
65
+ /**
66
+ * @inheritdoc
67
+ */
68
+ public function __sleep(){
69
+ return array('_post', '_option');
70
+ }
71
+
72
+ /**
73
+ * @inheritdoc
74
+ */
75
+ public function cacheObject(){
76
+ return true;
77
+ }
78
+
79
  /**
80
  *
81
  * @param type $params
129
  }
130
 
131
  /**
132
+ * Init Post Object
133
  *
134
+ * @param WP_Post|Int $object
135
+ *
136
+ * @return void
137
+ *
138
+ * @access public
139
  */
140
  public function init($object) {
141
  //make sure that we are dealing with WP_Post object
151
  }
152
 
153
  /**
154
+ * Read the Post AAM Metadata
155
  *
156
+ * Get all settings related to specified post
157
+ *
158
+ * @return void
159
+ *
160
+ * @access public
161
  */
162
  public function read() {
163
  $option = get_post_meta($this->getPost()->ID, $this->getOptionName(), true);
application/control/object/term.php CHANGED
@@ -25,9 +25,9 @@ class aam_Control_Object_Term extends aam_Control_Object {
25
  *
26
  */
27
  const ACTION_BROWSE = 'browse';
28
-
29
  /**
30
- *
31
  */
32
  const ACTION_EXCLUDE = 'exclude';
33
 
@@ -35,9 +35,9 @@ class aam_Control_Object_Term extends aam_Control_Object {
35
  *
36
  */
37
  const ACTION_EDIT = 'edit';
38
-
39
  /**
40
- *
41
  */
42
  const ACTION_LIST = 'list';
43
 
@@ -53,6 +53,13 @@ class aam_Control_Object_Term extends aam_Control_Object {
53
  */
54
  private $_option = array();
55
 
 
 
 
 
 
 
 
56
  /**
57
  *
58
  * @param type $params
@@ -114,8 +121,6 @@ class aam_Control_Object_Term extends aam_Control_Object {
114
  $this->setOption(
115
  apply_filters('aam_term_access_option', $access, $this->getSubject())
116
  );
117
- } else {
118
- aam_Core_Console::write("Term {$object_id} does not exist");
119
  }
120
  }
121
  }
@@ -198,6 +203,13 @@ class aam_Control_Object_Term extends aam_Control_Object {
198
  return $this->_option;
199
  }
200
 
 
 
 
 
 
 
 
201
  /**
202
  *
203
  * @param type $area
25
  *
26
  */
27
  const ACTION_BROWSE = 'browse';
28
+
29
  /**
30
+ *
31
  */
32
  const ACTION_EXCLUDE = 'exclude';
33
 
35
  *
36
  */
37
  const ACTION_EDIT = 'edit';
38
+
39
  /**
40
+ *
41
  */
42
  const ACTION_LIST = 'list';
43
 
53
  */
54
  private $_option = array();
55
 
56
+ /**
57
+ * @inheritdoc
58
+ */
59
+ public function __sleep(){
60
+ return array('_term', '_option');
61
+ }
62
+
63
  /**
64
  *
65
  * @param type $params
121
  $this->setOption(
122
  apply_filters('aam_term_access_option', $access, $this->getSubject())
123
  );
 
 
124
  }
125
  }
126
  }
203
  return $this->_option;
204
  }
205
 
206
+ /**
207
+ * @inheritdoc
208
+ */
209
+ public function cacheObject(){
210
+ return true;
211
+ }
212
+
213
  /**
214
  *
215
  * @param type $area
application/control/subject.php CHANGED
@@ -28,7 +28,7 @@ abstract class aam_Control_Subject {
28
  private $_id;
29
 
30
  /**
31
- * Subject itself
32
  *
33
  * It can be WP_User or WP_Role, based on what class has been used
34
  *
@@ -49,6 +49,17 @@ abstract class aam_Control_Subject {
49
  */
50
  private $_objects = array();
51
 
 
 
 
 
 
 
 
 
 
 
 
52
  /**
53
  * Constructor
54
  *
@@ -63,6 +74,44 @@ abstract class aam_Control_Subject {
63
  $this->setId($id);
64
  //retrieve and set subject itself
65
  $this->setSubject($this->retrieveSubject());
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  }
67
 
68
  /**
@@ -166,6 +215,19 @@ abstract class aam_Control_Subject {
166
  $this->_subject = $subject;
167
  }
168
 
 
 
 
 
 
 
 
 
 
 
 
 
 
169
  /**
170
  * Get Access Objects
171
  *
@@ -188,23 +250,36 @@ abstract class aam_Control_Subject {
188
  * @access public
189
  */
190
  public function getObject($object, $object_id = 0) {
191
- if (!isset($this->_objects[$object])) {
 
 
 
 
 
192
  $class_name = 'aam_Control_Object_' . ucfirst($object);
193
  if (class_exists($class_name)) {
194
- $this->_objects[$object] = new $class_name($this, $object_id);
 
 
195
  } else {
196
- $this->_objects[$object] = apply_filters(
197
- 'aam_object', null, $this, $object_id
198
  );
199
  }
200
- }
201
 
202
- //make sure that object exists, otherwise log it
203
- if (is_null($this->_objects[$object])) {
204
- aam_Core_Console::write("Object {$object} does not exist");
 
 
 
 
 
 
 
205
  }
206
 
207
- return $this->_objects[$object];
208
  }
209
 
210
  /**
@@ -250,6 +325,37 @@ abstract class aam_Control_Subject {
250
  */
251
  abstract public function getCapabilities();
252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
253
  /**
254
  * Save Access Parameters
255
  *
@@ -263,10 +369,10 @@ abstract class aam_Control_Subject {
263
  //initialize the backup first
264
  $backup = array();
265
 
266
- foreach ($params as $object_id => $dump) {
267
- if ($object = $this->getObject($object_id)) {
268
  if (method_exists($object, 'backup')) {
269
- $backup[$object_id] = $object->backup();
270
  }
271
  $object->save($dump);
272
  }
@@ -274,6 +380,9 @@ abstract class aam_Control_Subject {
274
 
275
  //store backup
276
  $this->getObject(aam_Control_Object_Backup::UID)->save($backup);
 
 
 
277
  }
278
 
279
  /**
28
  private $_id;
29
 
30
  /**
31
+ * WordPres Subject
32
  *
33
  * It can be WP_User or WP_Role, based on what class has been used
34
  *
49
  */
50
  private $_objects = array();
51
 
52
+ /**
53
+ * Update Cache flag
54
+ *
55
+ * If there is any new object instantiated, update cache too
56
+ *
57
+ * @var boolean
58
+ *
59
+ * @access private
60
+ */
61
+ private $_updateCache = false;
62
+
63
  /**
64
  * Constructor
65
  *
74
  $this->setId($id);
75
  //retrieve and set subject itself
76
  $this->setSubject($this->retrieveSubject());
77
+ //retrieve cache if there is any
78
+ $this->initCache();
79
+ }
80
+
81
+ /**
82
+ * Initialize cache
83
+ *
84
+ * @return void
85
+ *
86
+ * @access public
87
+ */
88
+ public function initCache(){
89
+ $cpress = $this->getObject(aam_Control_Object_ConfigPress::UID);
90
+ if ($cpress->getParam('aam.caching', 'false') === "true"){
91
+ $this->setObjects($this->readCache());
92
+ foreach($this->_objects as $objects){
93
+ foreach($objects as $object){
94
+ $object->setSubject($this);
95
+ }
96
+ }
97
+ }
98
+ }
99
+
100
+ /**
101
+ * Desctruct the subject
102
+ *
103
+ * Execute extra actions during application shutdown
104
+ *
105
+ * @return void
106
+ *
107
+ * @access public
108
+ */
109
+ public function saveCache(){
110
+ $cpress = $this->getObject(aam_Control_Object_ConfigPress::UID);
111
+ if (($this->_updateCache === true)
112
+ && ($cpress->getParam('aam.caching', 'false') === "true")){
113
+ $this->updateCache();
114
+ }
115
  }
116
 
117
  /**
215
  $this->_subject = $subject;
216
  }
217
 
218
+ /**
219
+ * Set Objects
220
+ *
221
+ * If there is any cache, set the complete set of objects
222
+ *
223
+ * @return void
224
+ *
225
+ * @access public
226
+ */
227
+ public function setObjects($objects) {
228
+ $this->_objects = $objects;
229
+ }
230
+
231
  /**
232
  * Get Access Objects
233
  *
250
  * @access public
251
  */
252
  public function getObject($object, $object_id = 0) {
253
+ //make sure that object group is defined
254
+ if (!isset($this->_objects[$object])){
255
+ $this->_objects[$object] = array();
256
+ }
257
+ //check if there is an object with specified ID
258
+ if (!isset($this->_objects[$object][$object_id])) {
259
  $class_name = 'aam_Control_Object_' . ucfirst($object);
260
  if (class_exists($class_name)) {
261
+ $this->_objects[$object][$object_id] = new $class_name(
262
+ $this, $object_id
263
+ );
264
  } else {
265
+ $this->_objects[$object][$object_id] = apply_filters(
266
+ 'aam_object', $this, $object, $object_id
267
  );
268
  }
 
269
 
270
+ //optimize the memory. make sure that the number of objects is not longer
271
+ //than 50, othewise remove first one (most likely it is not used)
272
+ if (count($this->_objects[$object]) > 50){
273
+ array_shift($this->_objects[$object]); //remove the first
274
+ }
275
+
276
+ //set update cache flag to true if object can be cached
277
+ if ($this->_objects[$object][$object_id]->cacheObject() === true){
278
+ $this->_updateCache = true;
279
+ }
280
  }
281
 
282
+ return $this->_objects[$object][$object_id];
283
  }
284
 
285
  /**
325
  */
326
  abstract public function getCapabilities();
327
 
328
+ /**
329
+ * Read Cache
330
+ *
331
+ * Cache all settings to speed-up the AAM execution
332
+ *
333
+ * @return void
334
+ *
335
+ * @access public
336
+ */
337
+ abstract public function readCache();
338
+
339
+ /**
340
+ * Update Cache
341
+ *
342
+ * If there is any change to cache, update it and save to database
343
+ *
344
+ * @return boolean
345
+ *
346
+ * @access public
347
+ */
348
+ abstract public function updateCache();
349
+
350
+ /**
351
+ * Clear the Subject Cache
352
+ *
353
+ * @return boolean
354
+ *
355
+ * @access public
356
+ */
357
+ abstract public function clearCache();
358
+
359
  /**
360
  * Save Access Parameters
361
  *
369
  //initialize the backup first
370
  $backup = array();
371
 
372
+ foreach ($params as $object_type => $dump) {
373
+ if ($object = $this->getObject($object_type)) {
374
  if (method_exists($object, 'backup')) {
375
+ $backup[$object_type] = $object->backup();
376
  }
377
  $object->save($dump);
378
  }
380
 
381
  //store backup
382
  $this->getObject(aam_Control_Object_Backup::UID)->save($backup);
383
+
384
+ //clear cache
385
+ $this->clearCache();
386
  }
387
 
388
  /**
application/control/subject/role.php CHANGED
@@ -111,7 +111,7 @@ class aam_Control_Subject_Role extends aam_Control_Subject {
111
  public function removeCapability($capability) {
112
  return $this->getSubject()->remove_cap($capability);
113
  }
114
-
115
  /**
116
  * Check if Subject has capability
117
  *
@@ -194,4 +194,44 @@ class aam_Control_Subject_Role extends aam_Control_Subject {
194
  return self::UID;
195
  }
196
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  }
111
  public function removeCapability($capability) {
112
  return $this->getSubject()->remove_cap($capability);
113
  }
114
+
115
  /**
116
  * Check if Subject has capability
117
  *
194
  return self::UID;
195
  }
196
 
197
+ /**
198
+ * Get Role Cache
199
+ *
200
+ * AAM does not store individual Role cache that is why this function returns
201
+ * always empty array
202
+ *
203
+ * @return array
204
+ *
205
+ * @access public
206
+ */
207
+ public function readCache(){
208
+ return array();
209
+ }
210
+
211
+ /**
212
+ * Update Role Cache
213
+ *
214
+ * This function does nothing because AAM does not store Role's cache
215
+ *
216
+ * @return boolean
217
+ *
218
+ * @access public
219
+ */
220
+ public function updateCache(){
221
+ return true;
222
+ }
223
+
224
+ /**
225
+ * Clear Role Cache
226
+ *
227
+ * This function does nothing because AAM does not store Role's cache
228
+ *
229
+ * @return boolean
230
+ *
231
+ * @access public
232
+ */
233
+ public function clearCache(){
234
+ return true;
235
+ }
236
+
237
  }
application/control/subject/user.php CHANGED
@@ -1 +1 @@
1
- <?php
2
  * ======================================================================
3
  * LICENSE: This file is subject to the terms and conditions defined in *
4
  * file 'license.txt', which is part of this source code package. *
5
  * ======================================================================
6
  */
7
  *
8
  * @package AAM
9
  * @author Vasyl Martyniuk <support@wpaam.com>
10
  * @copyright Copyright C 2013 Vasyl Martyniuk
11
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
12
  */
13
  /**
14
  * Subject UID: USER
15
  */
16
  const UID = 'user';
17
 
18
  /**
19
  * AAM Capability Key
20
  *
21
  * WordPress does not allow to have different set of capabilities for one user
22
  * between sites. aam_capability key stores the set of capabilities stored after
23
  * individual user edit and merge them with system capabilities.
24
  * The merging process overwrites allcaps.
25
  *
26
  * @var array
27
  *
28
  * @access private
29
  */
30
  private $_cap_key = '';
31
  /**
32
  *
33
  * @param type $id
34
  */
35
  public function __construct($id) {
36
  parent::__construct($id);
37
 
38
  //initialize list of capabilities
39
  //$this->getObject(aam_Control_Object_Capability::UID);
40
 
41
  //overwrite default set of capabilities if AAM capset is defined
42
  if ($this->isDefaultCapSet() === false){
43
  //make sure that aam_capability is actually array
44
  if (is_array($this->getSubject()->aam_caps)){
45
  $allcaps = array_merge(
46
  $this->getSubject()->allcaps, $this->getSubject()->aam_caps
47
  );
48
  $this->getSubject()->allcaps = $allcaps;
49
  }
50
  }
51
  }
52
  /**
53
  *
54
  * @return type
55
  */
56
  public function delete() {
57
  $response = false;
58
  if (current_user_can('delete_users')
59
  && ($this->getId() !== get_current_user_id())) {
60
  $response = wp_delete_user($this->getId());
61
  }
62
  return $response;
63
  }
64
  /**
65
  *
66
  * @global type $wpdb
67
  * @return boolean
68
  */
69
  public function block() {
70
  global $wpdb;
71
  $response = false;
72
  if (current_user_can('edit_users')
73
  && ($this->getId() != get_current_user_id())) {
74
  $status = ($this->getSubject()->user_status == 0 ? 1 : 0);
75
  if ($wpdb->update(
76
  $wpdb->users,
77
  array('user_status' => $status),
78
  array('ID' => $this->getId())
79
  )) {
80
  $this->getSubject()->user_status = $status;
81
  clean_user_cache($this->getSubject());
82
  $response = true;
83
  }
84
  }
85
  return $response;
86
  }
87
  /**
88
  * Retrieve User based on ID
89
  *
90
  * @return WP_Role|null
91
  *
92
  * @access protected
93
  */
94
  protected function retrieveSubject() {
95
  global $current_user;
96
  if ($current_user instanceof WP_User && $current_user->ID == $this->getId()) {
97
  $subject = $current_user;
98
  } else {
99
  $subject = new WP_User($this->getId());
100
  }
101
 
102
  //retrieve aam capabilities
103
  $this->_cap_key = 'aam_capability';
104
  $subject->aam_caps = get_user_option($this->_cap_key, $this->getId());
105
 
106
  return $subject;
107
  }
108
 
109
  /**
110
  * Check if user has default capability set
111
  *
112
  * @return boolean
113
  *
114
  * @access public
115
  */
116
  public function isDefaultCapSet(){
117
  return empty($this->getSubject()->aam_caps);
118
  }
119
  /**
120
  *
121
  * @return type
122
  */
123
  public function getCapabilities() {
124
  return $this->getSubject()->allcaps;
125
  }
126
  /**
127
  *
128
  * @param type $capability
129
  * @return type
130
  */
131
  public function hasCapability($capability) {
132
  return user_can($this->getSubject(), $capability);
133
  }
134
 
135
  /**
136
  * Check if Subject has capability
137
  *
138
  * Keep compatible with WordPress core
139
  *
140
  * @param string $capability
141
  *
142
  * @return boolean
143
  *
144
  * @access public
145
  */
146
  public function addCapability($capability) {
147
  return $this->updateCapability($capability, true);
148
  }
149
  /**
150
  * Remove Capability
151
  *
152
  * @param string $capability
153
  *
154
  * @return boolean
155
  *
156
  * @access public
157
  */
158
  public function removeCapability($capability) {
159
  return $this->updateCapability($capability, false);
160
  }
161
 
162
  /**
163
  * Reset User Capability
164
  *
165
  * @return array
166
  *
167
  * @access public
168
  */
169
  public function resetCapability(){
170
  return delete_user_option($this->getId(), $this->_cap_key);
171
  }
172
 
173
  /**
174
  * Update User's Capability Set
175
  *
176
  * @param string $capability
177
  * @param boolean $grand
178
  *
179
  * @return boolean
180
  *
181
  * @access public
182
  */
183
  public function updateCapability($capability, $grand){
184
  //make sure that we have right array
185
  if (is_array($this->getSubject()->aam_caps)){
186
  $aam_caps = $this->getSubject()->aam_caps;
187
  } else {
188
  $aam_caps = array();
189
  }
190
 
191
  //add capability
192
  $aam_caps[$capability] = $grand;
193
  //update user data. TODO - Keep eyes on this part
194
  $this->getSubject()->data->aam_caps = $aam_caps;
195
  //save and return the result of operation
196
  return update_user_option($this->getId(), $this->_cap_key, $aam_caps);
197
  }
198
  /**
199
  *
200
  * @param type $value
201
  * @param type $object
202
  * @param type $object_id
203
  * @return type
204
  */
205
  public function updateOption($value, $object, $object_id = '') {
206
  return update_user_option(
207
  $this->getId(), $this->getOptionName($object, $object_id), $value
208
  );
209
  }
210
  /**
211
  *
212
  * @param type $object
213
  * @param type $object_id
214
  * @return type
215
  */
216
  public function readOption($object, $object_id = '') {
217
  $option = get_user_option(
218
  $this->getOptionName($object, $object_id), $this->getId()
219
  );
220
  if (empty($option)) {
221
  //try to get this option from the User's Role
222
  $roles = $this->getSubject()->roles;
223
  //first user role is counted only. AAM does not support multi-roles
224
  $subject_role = array_shift($roles);
225
  //in case of multisite & current user does not belong to the site
226
  if ($subject_role){
227
  $role = new aam_Control_Subject_Role($subject_role);
228
  $option = $role->getObject($object, $object_id)->getOption();
229
  }
230
  }
231
  return $option;
232
  }
233
  /**
234
  *
235
  * @param type $object
236
  * @param type $object_id
237
  * @return type
238
  */
239
  public function deleteOption($object, $object_id = '') {
240
  return delete_user_option(
241
  $this->getId(), $this->getOptionName($object, $object_id)
242
  );
243
  }
244
  /**
245
  *
246
  * @param type $object
247
  * @param type $object_id
248
  * @return type
249
  */
250
  protected function getOptionName($object, $object_id) {
251
  return "aam_{$object}" . ($object_id ? "_{$object_id}" : '');
252
  }
253
  /**
254
  *
255
  * @return type
256
  */
257
  public function getUID() {
258
  return self::UID;
259
  }
 
260
  * ======================================================================
261
  * LICENSE: This file is subject to the terms and conditions defined in *
262
  * file 'license.txt', which is part of this source code package. *
263
  * ======================================================================
264
  */
265
  *
266
  * @package AAM
267
  * @author Vasyl Martyniuk <support@wpaam.com>
268
  * @copyright Copyright C 2013 Vasyl Martyniuk
269
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
270
  */
271
  /**
272
  * Subject UID: USER
273
  */
274
  const UID = 'user';
275
  /**
276
  * AAM Capability Key
277
  *
278
  * WordPress does not allow to have different set of capabilities for one user
279
  * between sites. aam_capability key stores the set of capabilities stored after
280
  * individual user edit and merge them with system capabilities.
281
  * The merging process overwrites allcaps.
282
  *
283
  * @var array
284
  *
285
  * @access private
286
  */
287
  private $_cap_key = '';
288
  /**
289
  *
290
  * @param type $id
291
  */
292
  public function __construct($id) {
293
  parent::__construct($id);
294
  //overwrite default set of capabilities if AAM capset is defined
295
  if ($this->isDefaultCapSet() === false){
296
  //make sure that aam_capability is actually array
297
  if (is_array($this->getSubject()->aam_caps)){
298
  $allcaps = array_merge(
299
  $this->getSubject()->allcaps, $this->getSubject()->aam_caps
300
  );
301
  $this->getSubject()->allcaps = $allcaps;
302
  }
303
  }
304
  }
305
  /**
306
  *
307
  * @return type
308
  */
309
  public function delete() {
310
  $response = false;
311
  if (current_user_can('delete_users')
312
  && ($this->getId() !== get_current_user_id())) {
313
  $response = wp_delete_user($this->getId());
314
  }
315
  return $response;
316
  }
317
  /**
318
  *
319
  * @global type $wpdb
320
  * @return boolean
321
  */
322
  public function block() {
323
  global $wpdb;
324
  $response = false;
325
  if (current_user_can('edit_users')
326
  && ($this->getId() != get_current_user_id())) {
327
  $status = ($this->getSubject()->user_status == 0 ? 1 : 0);
328
  if ($wpdb->update(
329
  $wpdb->users,
330
  array('user_status' => $status),
331
  array('ID' => $this->getId())
332
  )) {
333
  $this->getSubject()->user_status = $status;
334
  clean_user_cache($this->getSubject());
335
  $response = true;
336
  }
337
  }
338
  return $response;
339
  }
340
  /**
341
  * Retrieve User based on ID
342
  *
343
  * @return WP_Role|null
344
  *
345
  * @access protected
346
  */
347
  protected function retrieveSubject() {
348
  global $current_user;
349
  if ($current_user instanceof WP_User && $current_user->ID == $this->getId()) {
350
  $subject = $current_user;
351
  } else {
352
  $subject = new WP_User($this->getId());
353
  }
354
  //retrieve aam capabilities if are not retrieved yet
355
  $this->_cap_key = 'aam_capability';
356
  $subject->aam_caps = get_user_option($this->_cap_key, $this->getId());
357
  return $subject;
358
  }
359
  /**
360
  * Check if user has default capability set
361
  *
362
  * @return boolean
363
  *
364
  * @access public
365
  */
366
  public function isDefaultCapSet(){
367
  return empty($this->getSubject()->aam_caps);
368
  }
369
  /**
370
  *
371
  * @return type
372
  */
373
  public function getCapabilities() {
374
  return $this->getSubject()->allcaps;
375
  }
376
  /**
377
  *
378
  * @param type $capability
379
  * @return type
380
  */
381
  public function hasCapability($capability) {
382
  return user_can($this->getSubject(), $capability);
383
  }
384
  /**
385
  * Check if Subject has capability
386
  *
387
  * Keep compatible with WordPress core
388
  *
389
  * @param string $capability
390
  *
391
  * @return boolean
392
  *
393
  * @access public
394
  */
395
  public function addCapability($capability) {
396
  return $this->updateCapability($capability, true);
397
  }
398
  /**
399
  * Remove Capability
400
  *
401
  * @param string $capability
402
  *
403
  * @return boolean
404
  *
405
  * @access public
406
  */
407
  public function removeCapability($capability) {
408
  return $this->updateCapability($capability, false);
409
  }
410
  /**
411
  * Reset User Capability
412
  *
413
  * @return array
414
  *
415
  * @access public
416
  */
417
  public function resetCapability(){
418
  return delete_user_option($this->getId(), $this->_cap_key);
419
  }
420
  /**
421
  * Update User's Capability Set
422
  *
423
  * @param string $capability
424
  * @param boolean $grand
425
  *
426
  * @return boolean
427
  *
428
  * @access public
429
  */
430
  public function updateCapability($capability, $grand){
431
  //make sure that we have right array
432
  if (is_array($this->getSubject()->aam_caps)){
433
  $aam_caps = $this->getSubject()->aam_caps;
434
  } else {
435
  $aam_caps = array();
436
  }
437
  //add capability
438
  $aam_caps[$capability] = $grand;
439
  //update user data. TODO - Keep eyes on this part
440
  $this->getSubject()->data->aam_caps = $aam_caps;
441
  //save and return the result of operation
442
  return update_user_option($this->getId(), $this->_cap_key, $aam_caps);
443
  }
444
  /**
445
  *
446
  * @param type $value
447
  * @param type $object
448
  * @param type $object_id
449
  * @return type
450
  */
451
  public function updateOption($value, $object, $object_id = '') {
452
  return update_user_option(
453
  $this->getId(), $this->getOptionName($object, $object_id), $value
454
  );
455
  }
456
  /**
457
  *
458
  * @param type $object
459
  * @param type $object_id
460
  * @return type
461
  */
462
  public function readOption($object, $object_id = '') {
463
  $option = get_user_option(
464
  $this->getOptionName($object, $object_id), $this->getId()
465
  );
466
  if (empty($option)) {
467
  //try to get this option from the User's Role
468
  $roles = $this->getSubject()->roles;
469
  //first user role is counted only. AAM does not support multi-roles
470
  $subject_role = array_shift($roles);
471
  //in case of multisite & current user does not belong to the site
472
  if ($subject_role){
473
  $role = new aam_Control_Subject_Role($subject_role);
474
  $option = $role->getObject($object, $object_id)->getOption();
475
  }
476
  }
477
  return $option;
478
  }
479
  /**
480
  *
481
  * @param type $object
482
  * @param type $object_id
483
  * @return type
484
  */
485
  public function deleteOption($object, $object_id = '') {
486
  return delete_user_option(
487
  $this->getId(), $this->getOptionName($object, $object_id)
488
  );
489
  }
490
  /**
491
  *
492
  * @param type $object
493
  * @param type $object_id
494
  * @return type
495
  */
496
  protected function getOptionName($object, $object_id) {
497
  return "aam_{$object}" . ($object_id ? "_{$object_id}" : '');
498
  }
499
  /**
500
  * Get Subject UID
501
  *
502
  * @return string
503
  *
504
  * @access public
505
  */
506
  public function getUID() {
507
  return self::UID;
508
  }
509
  /**
510
  * Get User's Cache
511
  *
512
  * Read User's option aam_cache and return it
513
  *
514
  * @return array
515
  *
516
  * @access public
517
  */
518
  public function readCache(){
519
  $cache = get_user_option('aam_cache', $this->getId());
520
  return (is_array($cache) ? $cache : array());
521
  }
522
  /**
523
  * Insert or Update User's Cache
524
  *
525
  * @return boolean
526
  *
527
  * @access public
528
  */
529
  public function updateCache(){
530
  return update_user_option($this->getId(), 'aam_cache', $this->getObjects());
531
  }
532
  /**
533
  * Delete User's Cache
534
  *
535
  * @return boolean
536
  *
537
  * @access public
538
  */
539
  public function clearCache(){
540
  return delete_user_option($this->getId(), 'aam_cache');
541
  }
 
1
  * ======================================================================
2
  * LICENSE: This file is subject to the terms and conditions defined in *
3
  * file 'license.txt', which is part of this source code package. *
4
  * ======================================================================
5
  */
6
  *
7
  * @package AAM
8
  * @author Vasyl Martyniuk <support@wpaam.com>
9
  * @copyright Copyright C 2013 Vasyl Martyniuk
10
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
11
  */
12
  /**
13
  * Subject UID: USER
14
  */
15
  const UID = 'user';
16
 
17
  /**
18
  * AAM Capability Key
19
  *
20
  * WordPress does not allow to have different set of capabilities for one user
21
  * between sites. aam_capability key stores the set of capabilities stored after
22
  * individual user edit and merge them with system capabilities.
23
  * The merging process overwrites allcaps.
24
  *
25
  * @var array
26
  *
27
  * @access private
28
  */
29
  private $_cap_key = '';
30
  /**
31
  *
32
  * @param type $id
33
  */
34
  public function __construct($id) {
35
  parent::__construct($id);
36
 
37
  //initialize list of capabilities
38
  //$this->getObject(aam_Control_Object_Capability::UID);
39
 
40
  //overwrite default set of capabilities if AAM capset is defined
41
  if ($this->isDefaultCapSet() === false){
42
  //make sure that aam_capability is actually array
43
  if (is_array($this->getSubject()->aam_caps)){
44
  $allcaps = array_merge(
45
  $this->getSubject()->allcaps, $this->getSubject()->aam_caps
46
  );
47
  $this->getSubject()->allcaps = $allcaps;
48
  }
49
  }
50
  }
51
  /**
52
  *
53
  * @return type
54
  */
55
  public function delete() {
56
  $response = false;
57
  if (current_user_can('delete_users')
58
  && ($this->getId() !== get_current_user_id())) {
59
  $response = wp_delete_user($this->getId());
60
  }
61
  return $response;
62
  }
63
  /**
64
  *
65
  * @global type $wpdb
66
  * @return boolean
67
  */
68
  public function block() {
69
  global $wpdb;
70
  $response = false;
71
  if (current_user_can('edit_users')
72
  && ($this->getId() != get_current_user_id())) {
73
  $status = ($this->getSubject()->user_status == 0 ? 1 : 0);
74
  if ($wpdb->update(
75
  $wpdb->users,
76
  array('user_status' => $status),
77
  array('ID' => $this->getId())
78
  )) {
79
  $this->getSubject()->user_status = $status;
80
  clean_user_cache($this->getSubject());
81
  $response = true;
82
  }
83
  }
84
  return $response;
85
  }
86
  /**
87
  * Retrieve User based on ID
88
  *
89
  * @return WP_Role|null
90
  *
91
  * @access protected
92
  */
93
  protected function retrieveSubject() {
94
  global $current_user;
95
  if ($current_user instanceof WP_User && $current_user->ID == $this->getId()) {
96
  $subject = $current_user;
97
  } else {
98
  $subject = new WP_User($this->getId());
99
  }
100
 
101
  //retrieve aam capabilities
102
  $this->_cap_key = 'aam_capability';
103
  $subject->aam_caps = get_user_option($this->_cap_key, $this->getId());
104
 
105
  return $subject;
106
  }
107
 
108
  /**
109
  * Check if user has default capability set
110
  *
111
  * @return boolean
112
  *
113
  * @access public
114
  */
115
  public function isDefaultCapSet(){
116
  return empty($this->getSubject()->aam_caps);
117
  }
118
  /**
119
  *
120
  * @return type
121
  */
122
  public function getCapabilities() {
123
  return $this->getSubject()->allcaps;
124
  }
125
  /**
126
  *
127
  * @param type $capability
128
  * @return type
129
  */
130
  public function hasCapability($capability) {
131
  return user_can($this->getSubject(), $capability);
132
  }
133
 
134
  /**
135
  * Check if Subject has capability
136
  *
137
  * Keep compatible with WordPress core
138
  *
139
  * @param string $capability
140
  *
141
  * @return boolean
142
  *
143
  * @access public
144
  */
145
  public function addCapability($capability) {
146
  return $this->updateCapability($capability, true);
147
  }
148
  /**
149
  * Remove Capability
150
  *
151
  * @param string $capability
152
  *
153
  * @return boolean
154
  *
155
  * @access public
156
  */
157
  public function removeCapability($capability) {
158
  return $this->updateCapability($capability, false);
159
  }
160
 
161
  /**
162
  * Reset User Capability
163
  *
164
  * @return array
165
  *
166
  * @access public
167
  */
168
  public function resetCapability(){
169
  return delete_user_option($this->getId(), $this->_cap_key);
170
  }
171
 
172
  /**
173
  * Update User's Capability Set
174
  *
175
  * @param string $capability
176
  * @param boolean $grand
177
  *
178
  * @return boolean
179
  *
180
  * @access public
181
  */
182
  public function updateCapability($capability, $grand){
183
  //make sure that we have right array
184
  if (is_array($this->getSubject()->aam_caps)){
185
  $aam_caps = $this->getSubject()->aam_caps;
186
  } else {
187
  $aam_caps = array();
188
  }
189
 
190
  //add capability
191
  $aam_caps[$capability] = $grand;
192
  //update user data. TODO - Keep eyes on this part
193
  $this->getSubject()->data->aam_caps = $aam_caps;
194
  //save and return the result of operation
195
  return update_user_option($this->getId(), $this->_cap_key, $aam_caps);
196
  }
197
  /**
198
  *
199
  * @param type $value
200
  * @param type $object
201
  * @param type $object_id
202
  * @return type
203
  */
204
  public function updateOption($value, $object, $object_id = '') {
205
  return update_user_option(
206
  $this->getId(), $this->getOptionName($object, $object_id), $value
207
  );
208
  }
209
  /**
210
  *
211
  * @param type $object
212
  * @param type $object_id
213
  * @return type
214
  */
215
  public function readOption($object, $object_id = '') {
216
  $option = get_user_option(
217
  $this->getOptionName($object, $object_id), $this->getId()
218
  );
219
  if (empty($option)) {
220
  //try to get this option from the User's Role
221
  $roles = $this->getSubject()->roles;
222
  //first user role is counted only. AAM does not support multi-roles
223
  $subject_role = array_shift($roles);
224
  //in case of multisite & current user does not belong to the site
225
  if ($subject_role){
226
  $role = new aam_Control_Subject_Role($subject_role);
227
  $option = $role->getObject($object, $object_id)->getOption();
228
  }
229
  }
230
  return $option;
231
  }
232
  /**
233
  *
234
  * @param type $object
235
  * @param type $object_id
236
  * @return type
237
  */
238
  public function deleteOption($object, $object_id = '') {
239
  return delete_user_option(
240
  $this->getId(), $this->getOptionName($object, $object_id)
241
  );
242
  }
243
  /**
244
  *
245
  * @param type $object
246
  * @param type $object_id
247
  * @return type
248
  */
249
  protected function getOptionName($object, $object_id) {
250
  return "aam_{$object}" . ($object_id ? "_{$object_id}" : '');
251
  }
252
  /**
253
  *
254
  * @return type
255
  */
256
  public function getUID() {
257
  return self::UID;
258
  }
259
+ <?php
260
  * ======================================================================
261
  * LICENSE: This file is subject to the terms and conditions defined in *
262
  * file 'license.txt', which is part of this source code package. *
263
  * ======================================================================
264
  */
265
  *
266
  * @package AAM
267
  * @author Vasyl Martyniuk <support@wpaam.com>
268
  * @copyright Copyright C 2013 Vasyl Martyniuk
269
  * @license GNU General Public License {@link http://www.gnu.org/licenses/}
270
  */
271
  /**
272
  * Subject UID: USER
273
  */
274
  const UID = 'user';
275
  /**
276
  * AAM Capability Key
277
  *
278
  * WordPress does not allow to have different set of capabilities for one user
279
  * between sites. aam_capability key stores the set of capabilities stored after
280
  * individual user edit and merge them with system capabilities.
281
  * The merging process overwrites allcaps.
282
  *
283
  * @var array
284
  *
285
  * @access private
286
  */
287
  private $_cap_key = '';
288
  /**
289
  *
290
  * @param type $id
291
  */
292
  public function __construct($id) {
293
  parent::__construct($id);
294
  //overwrite default set of capabilities if AAM capset is defined
295
  if ($this->isDefaultCapSet() === false){
296
  //make sure that aam_capability is actually array
297
  if (is_array($this->getSubject()->aam_caps)){
298
  $allcaps = array_merge(
299
  $this->getSubject()->allcaps, $this->getSubject()->aam_caps
300
  );
301
  $this->getSubject()->allcaps = $allcaps;
302
  }
303
  }
304
  }
305
  /**
306
  *
307
  * @return type
308
  */
309
  public function delete() {
310
  $response = false;
311
  if (current_user_can('delete_users')
312
  && ($this->getId() !== get_current_user_id())) {
313
  $response = wp_delete_user($this->getId());
314
  }
315
  return $response;
316
  }
317
  /**
318
  *
319
  * @global type $wpdb
320
  * @return boolean
321
  */
322
  public function block() {
323
  global $wpdb;
324
  $response = false;
325
  if (current_user_can('edit_users')
326
  && ($this->getId() != get_current_user_id())) {
327
  $status = ($this->getSubject()->user_status == 0 ? 1 : 0);
328
  if ($wpdb->update(
329
  $wpdb->users,
330
  array('user_status' => $status),
331
  array('ID' => $this->getId())
332
  )) {
333
  $this->getSubject()->user_status = $status;
334
  clean_user_cache($this->getSubject());
335
  $response = true;
336
  }
337
  }
338
  return $response;
339
  }
340
  /**
341
  * Retrieve User based on ID
342
  *
343
  * @return WP_Role|null
344
  *
345
  * @access protected
346
  */
347
  protected function retrieveSubject() {
348
  global $current_user;
349
  if ($current_user instanceof WP_User && $current_user->ID == $this->getId()) {
350
  $subject = $current_user;
351
  } else {
352
  $subject = new WP_User($this->getId());
353
  }
354
  //retrieve aam capabilities if are not retrieved yet
355
  $this->_cap_key = 'aam_capability';
356
  $subject->aam_caps = get_user_option($this->_cap_key, $this->getId());
357
  return $subject;
358
  }
359
  /**
360
  * Check if user has default capability set
361
  *
362
  * @return boolean
363
  *
364
  * @access public
365
  */
366
  public function isDefaultCapSet(){
367
  return empty($this->getSubject()->aam_caps);
368
  }
369
  /**
370
  *
371
  * @return type
372
  */
373
  public function getCapabilities() {
374
  return $this->getSubject()->allcaps;
375
  }
376
  /**
377
  *
378
  * @param type $capability
379
  * @return type
380
  */
381
  public function hasCapability($capability) {
382
  return user_can($this->getSubject(), $capability);
383
  }
384
  /**
385
  * Check if Subject has capability
386
  *
387
  * Keep compatible with WordPress core
388
  *
389
  * @param string $capability
390
  *
391
  * @return boolean
392
  *
393
  * @access public
394
  */
395
  public function addCapability($capability) {
396
  return $this->updateCapability($capability, true);
397
  }
398
  /**
399
  * Remove Capability
400
  *
401
  * @param string $capability
402
  *
403
  * @return boolean
404
  *
405
  * @access public
406
  */
407
  public function removeCapability($capability) {
408
  return $this->updateCapability($capability, false);
409
  }
410
  /**
411
  * Reset User Capability
412
  *
413
  * @return array
414
  *
415
  * @access public
416
  */
417
  public function resetCapability(){
418
  return delete_user_option($this->getId(), $this->_cap_key);
419
  }
420
  /**
421
  * Update User's Capability Set
422
  *
423
  * @param string $capability
424
  * @param boolean $grand
425
  *
426
  * @return boolean
427
  *
428
  * @access public
429
  */
430
  public function updateCapability($capability, $grand){
431
  //make sure that we have right array
432
  if (is_array($this->getSubject()->aam_caps)){
433
  $aam_caps = $this->getSubject()->aam_caps;
434
  } else {
435
  $aam_caps = array();
436
  }
437
  //add capability
438
  $aam_caps[$capability] = $grand;
439
  //update user data. TODO - Keep eyes on this part
440
  $this->getSubject()->data->aam_caps = $aam_caps;
441
  //save and return the result of operation
442
  return update_user_option($this->getId(), $this->_cap_key, $aam_caps);
443
  }
444
  /**
445
  *
446
  * @param type $value
447
  * @param type $object
448
  * @param type $object_id
449
  * @return type
450
  */
451
  public function updateOption($value, $object, $object_id = '') {
452
  return update_user_option(
453
  $this->getId(), $this->getOptionName($object, $object_id), $value
454
  );
455
  }
456
  /**
457
  *
458
  * @param type $object
459
  * @param type $object_id
460
  * @return type
461
  */
462
  public function readOption($object, $object_id = '') {
463
  $option = get_user_option(
464
  $this->getOptionName($object, $object_id), $this->getId()
465
  );
466
  if (empty($option)) {
467
  //try to get this option from the User's Role
468
  $roles = $this->getSubject()->roles;
469
  //first user role is counted only. AAM does not support multi-roles
470
  $subject_role = array_shift($roles);
471
  //in case of multisite & current user does not belong to the site
472
  if ($subject_role){
473
  $role = new aam_Control_Subject_Role($subject_role);
474
  $option = $role->getObject($object, $object_id)->getOption();
475
  }
476
  }
477
  return $option;
478
  }
479
  /**
480
  *
481
  * @param type $object
482
  * @param type $object_id
483
  * @return type
484
  */
485
  public function deleteOption($object, $object_id = '') {
486
  return delete_user_option(
487
  $this->getId(), $this->getOptionName($object, $object_id)
488
  );
489
  }
490
  /**
491
  *
492
  * @param type $object
493
  * @param type $object_id
494
  * @return type
495
  */
496
  protected function getOptionName($object, $object_id) {
497
  return "aam_{$object}" . ($object_id ? "_{$object_id}" : '');
498
  }
499
  /**
500
  * Get Subject UID
501
  *
502
  * @return string
503
  *
504
  * @access public
505
  */
506
  public function getUID() {
507
  return self::UID;
508
  }
509
  /**
510
  * Get User's Cache
511
  *
512
  * Read User's option aam_cache and return it
513
  *
514
  * @return array
515
  *
516
  * @access public
517
  */
518
  public function readCache(){
519
  $cache = get_user_option('aam_cache', $this->getId());
520
  return (is_array($cache) ? $cache : array());
521
  }
522
  /**
523
  * Insert or Update User's Cache
524
  *
525
  * @return boolean
526
  *
527
  * @access public
528
  */
529
  public function updateCache(){
530
  return update_user_option($this->getId(), 'aam_cache', $this->getObjects());
531
  }
532
  /**
533
  * Delete User's Cache
534
  *
535
  * @return boolean
536
  *
537
  * @access public
538
  */
539
  public function clearCache(){
540
  return delete_user_option($this->getId(), 'aam_cache');
541
  }
application/control/subject/visitor.php CHANGED
@@ -20,7 +20,7 @@ class aam_Control_Subject_Visitor extends aam_Control_Subject
20
  * Subject UID: VISITOR
21
  */
22
  const UID = 'visitor';
23
-
24
  /**
25
  * Constructor
26
  *
@@ -42,8 +42,7 @@ class aam_Control_Subject_Visitor extends aam_Control_Subject
42
  *
43
  * @access protected
44
  */
45
- protected function retrieveSubject()
46
- {
47
  return new stdClass();
48
  }
49
 
@@ -51,8 +50,7 @@ class aam_Control_Subject_Visitor extends aam_Control_Subject
51
  *
52
  * @return type
53
  */
54
- public function getCapabilities()
55
- {
56
  return array();
57
  }
58
 
@@ -63,8 +61,7 @@ class aam_Control_Subject_Visitor extends aam_Control_Subject
63
  * @param type $object_id
64
  * @return type
65
  */
66
- public function updateOption($value, $object, $object_id = '')
67
- {
68
  return aam_Core_API::updateBlogOption(
69
  $this->getOptionName($object, $object_id), $value
70
  );
@@ -76,8 +73,7 @@ class aam_Control_Subject_Visitor extends aam_Control_Subject
76
  * @param type $object_id
77
  * @return type
78
  */
79
- public function readOption($object, $object_id = '')
80
- {
81
  return aam_Core_API::getBlogOption(
82
  $this->getOptionName($object, $object_id)
83
  );
@@ -89,8 +85,7 @@ class aam_Control_Subject_Visitor extends aam_Control_Subject
89
  * @param type $object_id
90
  * @return type
91
  */
92
- public function deleteOption($object, $object_id = '')
93
- {
94
  return aam_Core_API::deleteBlogOption(
95
  $this->getOptionName($object, $object_id)
96
  );
@@ -102,8 +97,7 @@ class aam_Control_Subject_Visitor extends aam_Control_Subject
102
  * @param type $object_id
103
  * @return type
104
  */
105
- protected function getOptionName($object, $object_id)
106
- {
107
  return 'aam_' . self::UID . "_{$object}" . ($object_id ? "_{$object_id}" : '');
108
  }
109
 
@@ -111,9 +105,46 @@ class aam_Control_Subject_Visitor extends aam_Control_Subject
111
  *
112
  * @return type
113
  */
114
- public function getUID()
115
- {
116
  return self::UID;
117
  }
118
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
119
  }
20
  * Subject UID: VISITOR
21
  */
22
  const UID = 'visitor';
23
+
24
  /**
25
  * Constructor
26
  *
42
  *
43
  * @access protected
44
  */
45
+ protected function retrieveSubject(){
 
46
  return new stdClass();
47
  }
48
 
50
  *
51
  * @return type
52
  */
53
+ public function getCapabilities(){
 
54
  return array();
55
  }
56
 
61
  * @param type $object_id
62
  * @return type
63
  */
64
+ public function updateOption($value, $object, $object_id = ''){
 
65
  return aam_Core_API::updateBlogOption(
66
  $this->getOptionName($object, $object_id), $value
67
  );
73
  * @param type $object_id
74
  * @return type
75
  */
76
+ public function readOption($object, $object_id = ''){
 
77
  return aam_Core_API::getBlogOption(
78
  $this->getOptionName($object, $object_id)
79
  );
85
  * @param type $object_id
86
  * @return type
87
  */
88
+ public function deleteOption($object, $object_id = ''){
 
89
  return aam_Core_API::deleteBlogOption(
90
  $this->getOptionName($object, $object_id)
91
  );
97
  * @param type $object_id
98
  * @return type
99
  */
100
+ protected function getOptionName($object, $object_id){
 
101
  return 'aam_' . self::UID . "_{$object}" . ($object_id ? "_{$object_id}" : '');
102
  }
103
 
105
  *
106
  * @return type
107
  */
108
+ public function getUID(){
 
109
  return self::UID;
110
  }
111
 
112
+ /**
113
+ * Get Visitor's Cache
114
+ *
115
+ * Read Visitor's option aam_visitor_cache and return it
116
+ *
117
+ * @return array
118
+ *
119
+ * @access public
120
+ */
121
+ public function readCache(){
122
+ $cache = aam_Core_API::getBlogOption('aam_visitor_cache', array());
123
+ return (is_array($cache) ? $cache : array());
124
+ }
125
+
126
+ /**
127
+ * Insert or Update Visitor's Cache
128
+ *
129
+ * @return boolean
130
+ *
131
+ * @access public
132
+ */
133
+ public function updateCache(){
134
+ return aam_Core_API::updateBlogOption(
135
+ 'aam_visitor_cache', $this->getObjects()
136
+ );
137
+ }
138
+
139
+ /**
140
+ * Delete Visitor's Cache
141
+ *
142
+ * @return boolean
143
+ *
144
+ * @access public
145
+ */
146
+ public function clearCache(){
147
+ return aam_Core_API::deleteBlogOption('aam_visitor_cache');
148
+ }
149
+
150
  }
application/core/migrate.php CHANGED
@@ -335,7 +335,7 @@ final class aam_Core_Migrate {
335
  } else {
336
  $settings = array();
337
  }
338
-
339
  return $this->saveSettings('Role', $role, $settings);
340
  }
341
 
@@ -371,20 +371,21 @@ final class aam_Core_Migrate {
371
  if (count($settings['restrictions']['post'])) {
372
  $post = $subject->getObject(aam_Control_Object_Post::UID);
373
  foreach ($settings['restrictions']['post'] as $post_id => $data) {
374
- $post->setOption(null); //clean up for next iteration
375
- $post->init($post_id);
376
- if (@$post->getPost()->ID) {
 
377
  $post->save(array('post' => $data));
378
  }
379
  }
380
  }
381
 
382
  if (count($settings['restrictions']['taxonomy'])) {
383
- $term = $subject->getObject(aam_Control_Object_Term::UID);
384
  foreach ($settings['restrictions']['taxonomy'] as $term_id => $data) {
385
- $term->setOption(null);
386
- $term->init($term_id);
387
- if (@$term->getTerm()->term_id) {
 
388
  $term->save(array('term' => $data));
389
  }
390
  }
335
  } else {
336
  $settings = array();
337
  }
338
+
339
  return $this->saveSettings('Role', $role, $settings);
340
  }
341
 
371
  if (count($settings['restrictions']['post'])) {
372
  $post = $subject->getObject(aam_Control_Object_Post::UID);
373
  foreach ($settings['restrictions']['post'] as $post_id => $data) {
374
+ $post = $subject->getObject(
375
+ aam_Control_Object_Post::UID, $post_id
376
+ );
377
+ if ($post->getPost() instanceof WP_Post) {
378
  $post->save(array('post' => $data));
379
  }
380
  }
381
  }
382
 
383
  if (count($settings['restrictions']['taxonomy'])) {
 
384
  foreach ($settings['restrictions']['taxonomy'] as $term_id => $data) {
385
+ $term = $subject->getObject(
386
+ aam_Control_Object_Term::UID, $term_id
387
+ );
388
+ if (is_object($term->getTerm())) {
389
  $term->save(array('term' => $data));
390
  }
391
  }
application/core/update.php CHANGED
@@ -18,33 +18,35 @@ final class aam_Core_Update {
18
 
19
  /**
20
  * List of stages
21
- *
22
  * @var array
23
- *
24
  * @access private
25
  */
26
  private $_stages = array();
27
 
28
  /**
29
  * Constructoor
30
- *
31
  * @return void
32
- *
33
  * @access public
34
  */
35
  public function __construct() {
36
  //register update stages
37
  $this->_stages = apply_filters('aam_update_stages', array(
38
  array($this, 'downloadRepository'),
39
- array($this, 'removeUpdate')
 
 
40
  ));
41
  }
42
 
43
  /**
44
  * Run the update if necessary
45
- *
46
  * @return void
47
- *
48
  * @access public
49
  */
50
  public function run() {
@@ -58,12 +60,12 @@ final class aam_Core_Update {
58
 
59
  /**
60
  * Download the Extension Repository
61
- *
62
- * This forces the system to retrieve the new set of extensions based on
63
  * license key
64
- *
65
  * @return boolean
66
- *
67
  * @access public
68
  */
69
  public function downloadRepository() {
@@ -79,16 +81,78 @@ final class aam_Core_Update {
79
  }
80
 
81
  /**
82
- * Remove the update file
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
  *
84
- * This will stop to run the update again
85
  *
86
  * @return boolean
87
  *
88
  * @access public
89
  */
90
- public function removeUpdate() {
91
- return rename(__FILE__, dirname(__FILE__) . '/__' . basename(__FILE__));
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  }
93
 
94
  }
18
 
19
  /**
20
  * List of stages
21
+ *
22
  * @var array
23
+ *
24
  * @access private
25
  */
26
  private $_stages = array();
27
 
28
  /**
29
  * Constructoor
30
+ *
31
  * @return void
32
+ *
33
  * @access public
34
  */
35
  public function __construct() {
36
  //register update stages
37
  $this->_stages = apply_filters('aam_update_stages', array(
38
  array($this, 'downloadRepository'),
39
+ array($this, 'flashCache'),
40
+ //array($this, 'muPlugin'), - TODO. Deactivated for futher use
41
+ array($this, 'updateFlag')
42
  ));
43
  }
44
 
45
  /**
46
  * Run the update if necessary
47
+ *
48
  * @return void
49
+ *
50
  * @access public
51
  */
52
  public function run() {
60
 
61
  /**
62
  * Download the Extension Repository
63
+ *
64
+ * This forces the system to retrieve the new set of extensions based on
65
  * license key
66
+ *
67
  * @return boolean
68
+ *
69
  * @access public
70
  */
71
  public function downloadRepository() {
81
  }
82
 
83
  /**
84
+ * Flash all cache
85
+ *
86
+ * @return boolean
87
+ *
88
+ * @access public
89
+ */
90
+ public function flashCache(){
91
+ global $wpdb;
92
+
93
+ //clear visitor's cache first
94
+ if (is_multisite()) {
95
+ //get all sites first and iterate through each
96
+ $query = 'SELECT blog_id FROM ' . $wpdb->blogs;
97
+ $blog_list = $wpdb->get_results($query);
98
+ if (is_array($blog_list)) {
99
+ foreach ($blog_list as $blog) {
100
+ $query = 'DELETE FROM ' . $wpdb->get_blog_prefix($blog->blog_id) . 'options ';
101
+ $query .= 'WHERE `option_name` = "aam_visitor_cache"';
102
+ $wpdb->query($query);
103
+ }
104
+ }
105
+ } else {
106
+ $query = 'DELETE FROM ' . $wpdb->options . ' ';
107
+ $query .= 'WHERE `option_name` = "aam_visitor_cache"';
108
+ $wpdb->query($query);
109
+ }
110
+
111
+ //clear users cache
112
+ $query = 'DELETE FROM ' . $wpdb->usermeta . ' ';
113
+ $query .= 'WHERE `meta_key` = "aam_cache"';
114
+ $wpdb->query($query);
115
+
116
+ return true;
117
+ }
118
+
119
+ /**
120
+ * Create Must-Use Plugin
121
  *
122
+ * Is used to hook into the earliest system load
123
  *
124
  * @return boolean
125
  *
126
  * @access public
127
  */
128
+ public function muPlugin() {
129
+ $base_dir = WP_CONTENT_DIR . '/mu-plugins';
130
+
131
+ $continue = (file_exists($base_dir) ? true : @mkdir($base_dir, 0755));
132
+
133
+ if ($continue) {
134
+ $hook_file = $base_dir . '/aam.php';
135
+ //remove current hook and replace with newer version
136
+ if (file_exists($hook_file)) {
137
+ @unlink($hook_file);
138
+ }
139
+ @copy(dirname(__FILE__) . '/mu.php', $base_dir . '/aam.php');
140
+ }
141
+
142
+ return true;
143
+ }
144
+
145
+ /**
146
+ * Change the Update flag
147
+ *
148
+ * This will stop to run the update again
149
+ *
150
+ * @return boolean
151
+ *
152
+ * @access public
153
+ */
154
+ public function updateFlag() {
155
+ return aam_Core_API::updateBlogOption('aam_updated', AAM_VERSION, 1);
156
  }
157
 
158
  }
application/view/ajax.php CHANGED
@@ -447,7 +447,7 @@ class aam_View_Ajax extends aam_View_Abstract{
447
  */
448
  protected function save() {
449
  $model = new aam_View_Manager;
450
-
451
  return $model->save();
452
  }
453
 
447
  */
448
  protected function save() {
449
  $model = new aam_View_Manager;
450
+
451
  return $model->save();
452
  }
453
 
application/view/event.php CHANGED
@@ -21,7 +21,8 @@ class aam_View_Event extends aam_View_Abstract {
21
  */
22
  public function retrieveEventList() {
23
  $response = array('aaData' => array());
24
- foreach ($this->getSubject()->getObject(aam_Control_Object_Event::UID)->getOption() as $event) {
 
25
  $response['aaData'][] = array(
26
  $event['event'],
27
  $event['event_specifier'],
21
  */
22
  public function retrieveEventList() {
23
  $response = array('aaData' => array());
24
+ $events = $this->getSubject()->getObject(aam_Control_Object_Event::UID);
25
+ foreach ($events->getOption() as $event) {
26
  $response['aaData'][] = array(
27
  $event['event'],
28
  $event['event_specifier'],
application/view/manager.php CHANGED
@@ -288,7 +288,7 @@ class aam_View_Manager extends aam_View_Abstract {
288
  if (!isset($options[aam_Control_Object_Event::UID])) {
289
  $options[aam_Control_Object_Event::UID] = array();
290
  }
291
-
292
  return apply_filters('aam_prepare_option_list', $options);
293
  }
294
 
@@ -302,6 +302,9 @@ class aam_View_Manager extends aam_View_Abstract {
302
 
303
  $this->getSubject()->save($this->prepareSaveOptions($params));
304
 
 
 
 
305
  return json_encode(
306
  array(
307
  'status' => 'success',
288
  if (!isset($options[aam_Control_Object_Event::UID])) {
289
  $options[aam_Control_Object_Event::UID] = array();
290
  }
291
+
292
  return apply_filters('aam_prepare_option_list', $options);
293
  }
294
 
302
 
303
  $this->getSubject()->save($this->prepareSaveOptions($params));
304
 
305
+ //clear cache
306
+ $this->getSubject()->clearCache();
307
+
308
  return json_encode(
309
  array(
310
  'status' => 'success',
application/view/post.php CHANGED
@@ -413,6 +413,9 @@ class aam_View_Post extends aam_View_Abstract {
413
  $object->save($access);
414
  aam_Core_API::updateBlogOption('aam_access_limit', $limit_counter + 1);
415
 
 
 
 
416
  $response = array('status' => 'success');
417
  } else {
418
  $response = array(
@@ -446,7 +449,7 @@ class aam_View_Post extends aam_View_Abstract {
446
  return json_encode(array(
447
  'settings' => $object->getOption(),
448
  'counter' => apply_filters(
449
- 'wpaccess_restrict_limit',
450
  aam_Core_API::getBlogOption('aam_access_limit', 0)
451
  )
452
  ));
413
  $object->save($access);
414
  aam_Core_API::updateBlogOption('aam_access_limit', $limit_counter + 1);
415
 
416
+ //clear cache
417
+ $this->getSubject()->clearCache();
418
+
419
  $response = array('status' => 'success');
420
  } else {
421
  $response = array(
449
  return json_encode(array(
450
  'settings' => $object->getOption(),
451
  'counter' => apply_filters(
452
+ 'wpaccess_restrict_limit',
453
  aam_Core_API::getBlogOption('aam_access_limit', 0)
454
  )
455
  ));
application/view/tmpl/menu.phtml CHANGED
@@ -29,7 +29,7 @@ $menu = $this->getMenu();
29
  <h4><?php echo $menu['name']; ?></h4>
30
  <div>
31
  <div class="whole-menu">
32
- <label for="m<?php echo $menu_id; ?>"><?php echo __('Restrict All', 'aam'); ?></label>
33
  <input type="checkbox" id="m<?php echo $menu_id; ?>" name="aam[<?php echo aam_Control_Object_Menu::UID; ?>][<?php echo $menu['id']; ?>]" <?php echo ($this->hasRestrictedAll($menu) ? 'checked="checked"' : ''); ?> class="whole_menu" />
34
  <label for="m<?php echo $menu_id; ?>"><span></span></label>
35
  </div>
29
  <h4><?php echo $menu['name']; ?></h4>
30
  <div>
31
  <div class="whole-menu">
32
+ <label for="m<?php echo $menu_id; ?>"><?php echo __('Hide All', 'aam'); ?></label>
33
  <input type="checkbox" id="m<?php echo $menu_id; ?>" name="aam[<?php echo aam_Control_Object_Menu::UID; ?>][<?php echo $menu['id']; ?>]" <?php echo ($this->hasRestrictedAll($menu) ? 'checked="checked"' : ''); ?> class="whole_menu" />
34
  <label for="m<?php echo $menu_id; ?>"><span></span></label>
35
  </div>
config.php CHANGED
@@ -1,11 +1,14 @@
1
  <?php
2
-
3
  /**
4
  * ======================================================================
5
  * LICENSE: This file is subject to the terms and conditions defined in *
6
  * file 'license.txt', which is part of this source code package. *
7
  * ======================================================================
8
  */
 
 
 
 
9
  define('AAM_BASE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
10
 
11
  //jean.yves.dumaine@gmail.com feedback - thank you
@@ -79,7 +82,7 @@ load_plugin_textdomain('aam', false, basename(AAM_BASE_DIR) . '/lang');
79
  function aam_migration_note() {
80
  if (class_exists('aam_Core_Migrate') && !aam_Core_API::getBlogOption('aam_migrated')) {
81
  echo "<div class='update-nag'>";
82
- echo __('Migrate your setting to new AAM platform. ', 'aam');
83
  echo '<a href="#" id="aam_migrate">' . __('Click to Migrate', 'aam') . '</a>';
84
  echo '</div>';
85
  }
1
  <?php
 
2
  /**
3
  * ======================================================================
4
  * LICENSE: This file is subject to the terms and conditions defined in *
5
  * file 'license.txt', which is part of this source code package. *
6
  * ======================================================================
7
  */
8
+
9
+ //AAM Version for Update purpose
10
+ define('AAM_VERSION', '2.1');
11
+
12
  define('AAM_BASE_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
13
 
14
  //jean.yves.dumaine@gmail.com feedback - thank you
82
  function aam_migration_note() {
83
  if (class_exists('aam_Core_Migrate') && !aam_Core_API::getBlogOption('aam_migrated')) {
84
  echo "<div class='update-nag'>";
85
+ echo __('Migrate your old AAM settings to the new AAM platform. ', 'aam');
86
  echo '<a href="#" id="aam_migrate">' . __('Click to Migrate', 'aam') . '</a>';
87
  echo '</div>';
88
  }
extension/AAM_Multisite_Support/extension.php CHANGED
@@ -138,9 +138,9 @@ class AAM_Extension_Multisite {
138
  */
139
  public function content() {
140
  ob_start();
141
- require_once dirname(__FILE__) . '/ui.phtml';
142
  $content = ob_get_contents();
143
- ob_clean();
144
 
145
  return $content;
146
  }
138
  */
139
  public function content() {
140
  ob_start();
141
+ require dirname(__FILE__) . '/ui.phtml';
142
  $content = ob_get_contents();
143
+ ob_end_clean();
144
 
145
  return $content;
146
  }
extension/AAM_My_Feature/extension.php ADDED
@@ -0,0 +1,133 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ /**
4
+ * ======================================================================
5
+ * LICENSE: This file is subject to the terms and conditions defined in *
6
+ * file 'license.txt', which is part of this source code package. *
7
+ * ======================================================================
8
+ */
9
+
10
+ /**
11
+ *
12
+ * @package AAM
13
+ * @author Vasyl Martyniuk <support@wpaam.com>
14
+ * @copyright Copyright C 2013 Vasyl Martyniuk
15
+ * @license GNU General Public License {@link http://www.gnu.org/licenses/}
16
+ */
17
+ class AAM_Extension_MyFeature {
18
+
19
+ /**
20
+ *
21
+ * @var type
22
+ */
23
+ private $_parent = null;
24
+
25
+ /**
26
+ *
27
+ * @var type
28
+ */
29
+ private $_subject = null;
30
+
31
+ /**
32
+ *
33
+ * @param aam|aam_View_Connector $parent
34
+ */
35
+ public function __construct(aam $parent) {
36
+ $this->setParent($parent);
37
+
38
+ if (is_admin()) {
39
+ add_action('admin_print_scripts', array($this, 'printScripts'));
40
+ add_action('admin_print_styles', array($this, 'printStyles'));
41
+ add_filter('aam_ui_features', array($this, 'feature'), 10);
42
+ }
43
+ }
44
+
45
+ public function feature($features) {
46
+ //add feature
47
+ $features['my_feature'] = array(
48
+ 'id' => 'my_feature',
49
+ 'position' => 35,
50
+ 'title' => __('My Feature', 'aam'),
51
+ 'anonimus' => true,
52
+ 'content' => array($this, 'content'),
53
+ 'help' => __('My customly developed feature', 'aam')
54
+ );
55
+
56
+ return $features;
57
+ }
58
+
59
+ /**
60
+ *
61
+ * @return type
62
+ */
63
+ public function content() {
64
+ ob_start();
65
+ require dirname(__FILE__) . '/ui.phtml';
66
+ $content = ob_get_contents();
67
+ ob_end_clean();
68
+
69
+ return $content;
70
+ }
71
+
72
+ /**
73
+ * Print necessary scripts
74
+ *
75
+ * @return void
76
+ *
77
+ * @access public
78
+ */
79
+ public function printScripts() {
80
+ if ($this->getParent()->isAAMScreen()) {
81
+ wp_enqueue_script(
82
+ 'aam-my-feature-admin',
83
+ AAM_MY_FEATURE_BASE_URL . '/my_feature.js',
84
+ array('aam-admin')
85
+ );
86
+ }
87
+ }
88
+
89
+ /**
90
+ *
91
+ */
92
+ public function printStyles() {
93
+ if ($this->getParent()->isAAMScreen()) {
94
+ wp_enqueue_style(
95
+ 'aam-my-feature-admin',
96
+ AAM_MY_FEATURE_BASE_URL . '/my_feature.css'
97
+ );
98
+ }
99
+ }
100
+
101
+ /**
102
+ *
103
+ * @param aam $parent
104
+ */
105
+ public function setParent(aam $parent) {
106
+ $this->_parent = $parent;
107
+ }
108
+
109
+ /**
110
+ *
111
+ * @return aam
112
+ */
113
+ public function getParent() {
114
+ return $this->_parent;
115
+ }
116
+
117
+ /**
118
+ *
119
+ * @param type $subject
120
+ */
121
+ public function setSubject($subject) {
122
+ $this->_subject = $subject;
123
+ }
124
+
125
+ /**
126
+ *
127
+ * @return type
128
+ */
129
+ public function getSubject() {
130
+ return $this->_subject;
131
+ }
132
+
133
+ }
extension/AAM_My_Feature/images/message-active.png ADDED
Binary file
extension/AAM_My_Feature/images/message.png ADDED
Binary file
extension/AAM_My_Feature/images/talk-active.png ADDED
Binary file
extension/AAM_My_Feature/images/talk.png ADDED
Binary file
extension/AAM_My_Feature/images/worker.png ADDED
Binary file
extension/AAM_My_Feature/index.php ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ======================================================================
4
+ * LICENSE: This file is subject to the terms and conditions defined in *
5
+ * file 'license.txt', which is part of this source code package. *
6
+ * ======================================================================
7
+ */
8
+
9
+ $dirname = basename(dirname(__FILE__));
10
+ define('AAM_MY_FEATURE_BASE_URL', AAM_BASE_URL . 'extension/' . $dirname);
11
+
12
+ require_once dirname(__FILE__) . '/extension.php';
13
+
14
+ return new AAM_Extension_MyFeature($this->getParent());
extension/AAM_My_Feature/my_feature.css ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * ======================================================================
3
+ * LICENSE: This file is subject to the terms and conditions defined in *
4
+ * file 'license.txt', which is part of this source code package. *
5
+ * ======================================================================
6
+ */
7
+ .my-feature-banner{
8
+ width: 100%;
9
+ background: transparent url('images/worker.png') no-repeat center 10px;
10
+ padding-top: 150px;
11
+ -moz-box-sizing: border-box;
12
+ box-sizing: border-box;
13
+ -webkit-box-sizing: border-box;
14
+ }
15
+
16
+ .my-feature-banner .banner-style{
17
+ margin: 0px 10px;
18
+ font-family: "Trebuchet MS", Helvetica, sans-serif;
19
+ font-size: 1.2em;
20
+ font-weight: bold;
21
+ text-align: center;
22
+ }
23
+
24
+ .my-feature-actions{
25
+ width: 100%;
26
+ margin-top: 10px;
27
+ text-align: center;
28
+ }
29
+
30
+ .my-feature-action{
31
+ min-width: 48px;
32
+ height: 70px;
33
+ display: inline-block;
34
+ text-decoration: none;
35
+ position: relative;
36
+ }
37
+
38
+ .my-feature-action span{
39
+ display: block;
40
+ margin-top: 50px;
41
+ text-align: center;
42
+ width: 100%;
43
+ font-size: 0.8em;
44
+ text-transform: uppercase;
45
+ font-weight: bold;
46
+ color: #333333;
47
+ font-family: "Trebuchet MS", Helvetica, sans-serif;
48
+ }
49
+
50
+ .my-feature-message-action{
51
+ background: transparent url('images/message.png') no-repeat center 6px;
52
+ }
53
+
54
+ .my-feature-message-action:hover{
55
+ background: transparent url('images/message-active.png') no-repeat center 6px;
56
+ }
57
+
58
+ .my-feature-forum-action{
59
+ background: transparent url('images/talk.png') no-repeat center 0;
60
+ margin-left: 60px;
61
+ }
62
+
63
+ .my-feature-forum-action:hover{
64
+ background: transparent url('images/talk-active.png') no-repeat center 0;
65
+ margin-left: 60px;
66
+ }
extension/AAM_My_Feature/my_feature.js ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /**
2
+ * ======================================================================
3
+ * LICENSE: This file is subject to the terms and conditions defined in *
4
+ * file 'license.txt', which is part of this source code package. *
5
+ * ======================================================================
6
+ */
7
+
8
+ AAM.prototype.myFeature = function() {
9
+ //Send Email to Us
10
+ jQuery('.my-feature-message-action').bind('click', function(event) {
11
+ event.preventDefault();
12
+ jQuery('#aam_message').trigger('click');
13
+ });
14
+ };
15
+
16
+ jQuery(document).ready(function() {
17
+ aamInterface.addAction('aam_init_features', function() {
18
+ aamInterface.myFeature();
19
+ });
20
+ });
extension/AAM_My_Feature/ui.phtml ADDED
@@ -0,0 +1,23 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /**
3
+ * ======================================================================
4
+ * LICENSE: This file is subject to the terms and conditions defined in *
5
+ * file 'license.txt', which is part of this source code package. *
6
+ * ======================================================================
7
+ */
8
+ ?>
9
+ <div class="feature-content-container" id="my_feature_content">
10
+ <div class="my-feature-banner">
11
+ <p class="banner-style">
12
+ <?php echo __('Do you need a custom feature? Ask us and we will develop it for you.', 'aam'); ?>
13
+ </p>
14
+ </div>
15
+ <div class="my-feature-actions">
16
+ <a href="#" class="my-feature-action my-feature-message-action">
17
+ <span><?php echo __('Email Us', 'aam'); ?></span>
18
+ </a>
19
+ <a href="http://wpaam.com/forum/viewtopic.php?f=7&t=72" target="_blank" class="my-feature-action my-feature-forum-action">
20
+ <span><?php echo __('Ask on Forum', 'aam'); ?></span>
21
+ </a>
22
+ </div>
23
+ </div>
lang/aam-fr_FR.mo ADDED
Binary file
lang/aam-fr_FR.po ADDED
@@ -0,0 +1,337 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: AAM\n"
4
+ "POT-Creation-Date: 2013-12-01 14:07-0500\n"
5
+ "PO-Revision-Date: 2014-01-15 23:25+0100\n"
6
+ "Last-Translator: Moskito7 <moskito7@wanadoo.fr>\n"
7
+ "Language-Team: WPAAM <support@wpaam.com>\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "Language: fr_FR\n"
12
+ "X-Generator: Poedit 1.5.4\n"
13
+
14
+ #: aam.php:243 aam.php:248 aam.php:267
15
+ msgid "Access denied"
16
+ msgstr "Accès refusé"
17
+
18
+ #: aam.php:691 aam.php:692
19
+ msgid "AAM"
20
+ msgstr "AAM"
21
+
22
+ #: aam.php:701 aam.php:702
23
+ msgid "Access Control"
24
+ msgstr "Contrôle d'accès"
25
+
26
+ #: aam.php:709 aam.php:710
27
+ msgid "Extensions"
28
+ msgstr "Extensions"
29
+
30
+ #: application/view/capability.php:98 application/view/capability.php:179
31
+ msgid "System"
32
+ msgstr "Système"
33
+
34
+ #: application/view/capability.php:99 application/view/capability.php:181
35
+ msgid "Post & Page"
36
+ msgstr "Articles et Pages"
37
+
38
+ #: application/view/capability.php:100 application/view/capability.php:183
39
+ msgid "Backend Interface"
40
+ msgstr "Interface d'administration"
41
+
42
+ #: application/view/capability.php:101
43
+ msgid "Miscellaneous"
44
+ msgstr "Divers"
45
+
46
+ #: application/view/capability.php:185
47
+ msgid "Miscelaneous"
48
+ msgstr "Divers"
49
+
50
+ #: application/view/manager.php:59
51
+ msgid "Roles"
52
+ msgstr "Rôles"
53
+
54
+ #: application/view/manager.php:60
55
+ msgid "Role Manager"
56
+ msgstr "Gestionnaire de rôle"
57
+
58
+ #: application/view/manager.php:68
59
+ msgid "Users"
60
+ msgstr "Utilisateurs"
61
+
62
+ #: application/view/manager.php:69
63
+ msgid "User Manager"
64
+ msgstr "Gestionnaire d'utilisateurs"
65
+
66
+ #: application/view/manager.php:77
67
+ msgid "Visitor"
68
+ msgstr "Visiteur"
69
+
70
+ #: application/view/manager.php:78
71
+ msgid "Visitor Manager"
72
+ msgstr "Gestionnaire de visiteurs"
73
+
74
+ #: application/view/manager.php:95
75
+ msgid "Admin Menu"
76
+ msgstr "Menu d'administration"
77
+
78
+ #: application/view/manager.php:98
79
+ msgid ""
80
+ "Control Access to Admin Menu. Restrict access to entire Menu or Submenu. "
81
+ "<b>Notice</b>, the menu is rendered based on Role's or User's capabilities."
82
+ msgstr ""
83
+ "Contrôler l'accès au menu d'administration. Restreindre l'accès au menu "
84
+ "entier ou à un sous-menu. <b>Note</b>, l'affichage des menus est basé sur le "
85
+ "rôle ou les capacités de l'utilisateur."
86
+
87
+ #: application/view/manager.php:103
88
+ msgid "Metabox & Widget"
89
+ msgstr "Métabox & Widget"
90
+
91
+ #: application/view/manager.php:106
92
+ msgid ""
93
+ "Filter the list of Metaboxes or Widgets for selected Role or User. If "
94
+ "metabox or widget is not listed, try to click <b>Refresh the List</b> button "
95
+ "or Copy & Paste direct link to page where specific metabox or widget is "
96
+ "shown and hit <b>Retrieve Metaboxes from Link</b> button."
97
+ msgstr ""
98
+ "Filtrer la liste des métabox ou widgets pour le rôle ou l'utilisateur "
99
+ "sélectionné. Si une métabox ou un widget n'est pas listé, essayez de cliquer "
100
+ "sur le bouton <b>Rafraîchir la liste</b> ou copier et coller directement le "
101
+ "lien vers la page où la métabox ou le widget est affiché et cliquez sur le "
102
+ "bouton <b>Récupérer une métabox à partir d'un lien</b>."
103
+
104
+ #: application/view/manager.php:111
105
+ msgid "Capability"
106
+ msgstr "Capacités"
107
+
108
+ #: application/view/manager.php:114
109
+ msgid ""
110
+ "Manage the list of Capabilities for selected User or Role. <b>Notice</b>, "
111
+ "list of user's capabilities are inherited from user's Role.<br/><b>Warning!</"
112
+ "b> Be very careful with capabilities. Deleting or unchecking any capability "
113
+ "may cause temporary or permanent constrol lost over some features or "
114
+ "WordPress dashboard."
115
+ msgstr ""
116
+ "Gérer la liste des capacités pour l'utilisateur ou le rôle sélectionné. "
117
+ "<b>Note</b>, la liste des capacités de l'utilisateur est héritée du rôle de "
118
+ "l'utilisateur.</br><b>Attention !</b> Faites très attention avec les "
119
+ "capacités. Supprimer ou décocher n'importe quelle capacité pourrait "
120
+ "entrainer la perte temporaire ou définitive de certaines fonctionnalités ou "
121
+ "du tableau de bord de Wordpress."
122
+
123
+ #: application/view/manager.php:119
124
+ msgid "Posts & Categories"
125
+ msgstr "Articles et Catégories"
126
+
127
+ #: application/view/manager.php:122
128
+ msgid ""
129
+ "Manage access to individual <b>Post</b> or <b>Term</b>. Notice, under "
130
+ "<b>Post</b>, we assume any post, page or custom post type. And under "
131
+ "<b>Term</b> - any term like Post Categories."
132
+ msgstr ""
133
+ "Gérer l'accès individuellement aux <b>articles</b> ou <b>termes</b>. Note, "
134
+ "on entend par <b>article</b> n'importe quel article, page ou type d'article. "
135
+ "Et par <b>terme</b> n'importe quel élément comme des catégories d'articles."
136
+
137
+ #: application/view/manager.php:127
138
+ msgid "Event Manager"
139
+ msgstr "Gestionnaire d'événements"
140
+
141
+ #: application/view/manager.php:130
142
+ msgid ""
143
+ "Define your own action when some event appeared in your WordPress blog. This "
144
+ "sections allows you to trigger an action on event like post content change, "
145
+ "or page status update. You can setup to send email notification, change the "
146
+ "post status or write your own custom event handler."
147
+ msgstr ""
148
+ "Définir votre propre action lorsqu'un événement apparaît sur votre blog "
149
+ "WordPress. Cette section vous permet de déclencher une action sur un "
150
+ "événement comme le changement de contenu d'un article, ou une mise à jour de "
151
+ "l'état de la page. Vous pouvez configurer l'envoi d'une notification par E-"
152
+ "mail, la modification du statut de l'article ou écrire votre propre "
153
+ "gestionnaire d'événements."
154
+
155
+ #: application/view/manager.php:135
156
+ msgid "ConfigPress"
157
+ msgstr "ConfigPress"
158
+
159
+ #: application/view/manager.php:138
160
+ msgid ""
161
+ "Control <b>AAM</b> behavior with ConfigPress. For more details please check "
162
+ "<b>ConfigPress tutorial</b>."
163
+ msgstr ""
164
+ "Contrôler le comportement de <b>AAM</b> avec ConfigPress. Pour plus de "
165
+ "détails regardez le <b>tutoriel ConfigPress</b>."
166
+
167
+ #: application/view/manager.php:342
168
+ msgid "Rollback Settings"
169
+ msgstr "Rétablir les paramètres"
170
+
171
+ #: application/view/manager.php:343
172
+ msgid "Cancel"
173
+ msgstr "Annuler"
174
+
175
+ #: application/view/manager.php:344
176
+ msgid "Send E-mail"
177
+ msgstr "Envoyer un E-mail"
178
+
179
+ #: application/view/manager.php:345 application/view/manager.php:351
180
+ msgid "Add New Role"
181
+ msgstr "Ajouter un rôle"
182
+
183
+ #: application/view/manager.php:346
184
+ msgid "Manage"
185
+ msgstr "Gérer"
186
+
187
+ #: application/view/manager.php:347
188
+ msgid "Edit"
189
+ msgstr "Editer"
190
+
191
+ #: application/view/manager.php:348
192
+ msgid "Delete"
193
+ msgstr "Supprimer"
194
+
195
+ #: application/view/manager.php:349
196
+ msgid "Filtered"
197
+ msgstr "Filtré"
198
+
199
+ #: application/view/manager.php:350
200
+ msgid "Clear"
201
+ msgstr "Nettoyer"
202
+
203
+ #: application/view/manager.php:352
204
+ msgid "Save Changes"
205
+ msgstr "Sauvegarder les modifications"
206
+
207
+ #: application/view/manager.php:353
208
+ #, php-format
209
+ msgid ""
210
+ "System detected %d user(s) with this role. All Users with Role <b>%s</b> "
211
+ "will be deleted automatically!"
212
+ msgstr ""
213
+ "Le système a détecté %d utilisateur(s) avec ce rôle. Tous les utilisateurs "
214
+ "avec le rôle <b>%s</b> seront automatiquement supprimés !"
215
+
216
+ #: application/view/manager.php:354
217
+ #, php-format
218
+ msgid "Are you sure that you want to delete role <b>%s</b>?"
219
+ msgstr "Êtes-vous certain de vouloir supprimer <b>%s</b> ?"
220
+
221
+ #: application/view/manager.php:355
222
+ msgid "Delete Role"
223
+ msgstr "Supprimer le rôle"
224
+
225
+ #: application/view/manager.php:356
226
+ msgid "Add User"
227
+ msgstr "Ajouter un utilisateur"
228
+
229
+ #: application/view/manager.php:357
230
+ msgid "Filter Users"
231
+ msgstr "Filtrer les utilisateurs"
232
+
233
+ #: application/view/manager.php:358 application/view/manager.php:374
234
+ msgid "Refresh List"
235
+ msgstr "Rafraîchir la liste"
236
+
237
+ #: application/view/manager.php:359
238
+ msgid "Block"
239
+ msgstr "Bloquer"
240
+
241
+ #: application/view/manager.php:360
242
+ #, php-format
243
+ msgid "Are you sure you want to delete user <b>%s</b>?"
244
+ msgstr "Êtes-vous certain de vouloir supprimer l'utilisateur <b>%s</b> ?"
245
+
246
+ #: application/view/manager.php:361
247
+ msgid "Filter Capabilities by Category"
248
+ msgstr "Filtrer les capacités par catégorie"
249
+
250
+ #: application/view/manager.php:362
251
+ msgid "Inherit Capabilities"
252
+ msgstr "Capacités héritées"
253
+
254
+ #: application/view/manager.php:363
255
+ msgid "Add New Capability"
256
+ msgstr "Ajouter une nouvelle capacité"
257
+
258
+ #: application/view/manager.php:364
259
+ #, php-format
260
+ msgid "Are you sure that you want to delete capability <b>%s</b>?"
261
+ msgstr "Êtes-vous certain de vouloir supprimer la capacité <b>%s</b> ?"
262
+
263
+ #: application/view/manager.php:365
264
+ msgid "Delete Capability"
265
+ msgstr "Supprimer la capacité"
266
+
267
+ #: application/view/manager.php:366
268
+ msgid "Select Role"
269
+ msgstr "Sélectionner le rôle"
270
+
271
+ #: application/view/manager.php:367
272
+ msgid "Add Capability"
273
+ msgstr "Ajouter la capacité"
274
+
275
+ #: application/view/manager.php:368
276
+ msgid "Add Event"
277
+ msgstr "Ajouter un événement"
278
+
279
+ #: application/view/manager.php:369
280
+ msgid "Edit Event"
281
+ msgstr "Editer un événement"
282
+
283
+ #: application/view/manager.php:370 application/view/manager.php:372
284
+ msgid "Delete Event"
285
+ msgstr "Supprimer un événement"
286
+
287
+ #: application/view/manager.php:371
288
+ msgid "Save Event"
289
+ msgstr "Sauvegarder un événement"
290
+
291
+ #: application/view/manager.php:373
292
+ msgid "Filter Posts by Post Type"
293
+ msgstr "Filtrer les articles par type"
294
+
295
+ #: application/view/manager.php:375
296
+ msgid "Restore Default"
297
+ msgstr "Restaurer les paramètres par défaut"
298
+
299
+ #: application/view/manager.php:376
300
+ msgid "Apply"
301
+ msgstr "Appliquer"
302
+
303
+ #: application/view/manager.php:377
304
+ msgid "Edit Term"
305
+ msgstr "Editer les termes"
306
+
307
+ #: application/view/manager.php:378
308
+ msgid "Manager Access"
309
+ msgstr "Gestionnaire d'accès"
310
+
311
+ #: application/view/manager.php:379
312
+ msgid "Unlock Default Accesss Control"
313
+ msgstr "Déverrouiller le contrôle d'accès par défaut"
314
+
315
+ #: application/view/manager.php:380
316
+ msgid "Close"
317
+ msgstr "Fermer"
318
+
319
+ #: application/view/manager.php:381
320
+ msgid "Edit Role"
321
+ msgstr "Editer le rôle"
322
+
323
+ #: application/view/metabox.php:179
324
+ msgid "Dashboard Widgets"
325
+ msgstr "Widgets du tableau de bord"
326
+
327
+ #: application/view/metabox.php:183
328
+ msgid "Frontend Widgets"
329
+ msgstr "Widgets du site"
330
+
331
+ #: application/view/post.php:181
332
+ msgid "[empty]"
333
+ msgstr "[vide]"
334
+
335
+ #: application/view/post.php:345 application/view/post.php:353
336
+ msgid "All"
337
+ msgstr "Tout"
lang/aam-pl_PL.mo ADDED
Binary file
lang/aam-pl_PL.po ADDED
@@ -0,0 +1,336 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: AAM v2.0\n"
4
+ "POT-Creation-Date: 2013-12-01 14:07-0500\n"
5
+ "PO-Revision-Date: 2014-01-13 10:49+0100\n"
6
+ "Last-Translator: Gustaw Lasek <biuro@servitium.pl>\n"
7
+ "Language-Team: Servitium <biuro@servitium.pl>\n"
8
+ "MIME-Version: 1.0\n"
9
+ "Content-Type: text/plain; charset=UTF-8\n"
10
+ "Content-Transfer-Encoding: 8bit\n"
11
+ "X-Generator: Poedit 1.5.7\n"
12
+ "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10>=2 && n%10<=4 && (n%100<10 "
13
+ "|| n%100>=20) ? 1 : 2);\n"
14
+ "Language: pl_PL\n"
15
+
16
+ #: aam.php:243 aam.php:248 aam.php:267
17
+ msgid "Access denied"
18
+ msgstr "Brak dostępu"
19
+
20
+ #: aam.php:691 aam.php:692
21
+ msgid "AAM"
22
+ msgstr "AAM"
23
+
24
+ #: aam.php:701 aam.php:702
25
+ msgid "Access Control"
26
+ msgstr "Kontrola dostępu"
27
+
28
+ #: aam.php:709 aam.php:710
29
+ msgid "Extensions"
30
+ msgstr "Rozszerzenia"
31
+
32
+ #: application/view/capability.php:98 application/view/capability.php:179
33
+ msgid "System"
34
+ msgstr "System"
35
+
36
+ #: application/view/capability.php:99 application/view/capability.php:181
37
+ msgid "Post & Page"
38
+ msgstr "Wpisy i Strony"
39
+
40
+ #: application/view/capability.php:100 application/view/capability.php:183
41
+ msgid "Backend Interface"
42
+ msgstr "Interfejs panelu zarządzania"
43
+
44
+ #: application/view/capability.php:101
45
+ msgid "Miscellaneous"
46
+ msgstr "Pozostałe"
47
+
48
+ #: application/view/capability.php:185
49
+ msgid "Miscelaneous"
50
+ msgstr "Pozostałe"
51
+
52
+ #: application/view/manager.php:59
53
+ msgid "Roles"
54
+ msgstr "Role"
55
+
56
+ #: application/view/manager.php:60
57
+ msgid "Role Manager"
58
+ msgstr "Zarządzanie rolami"
59
+
60
+ #: application/view/manager.php:68
61
+ msgid "Users"
62
+ msgstr "Użytkownicy"
63
+
64
+ #: application/view/manager.php:69
65
+ msgid "User Manager"
66
+ msgstr "Zarządzanie użytkownikami"
67
+
68
+ #: application/view/manager.php:77
69
+ msgid "Visitor"
70
+ msgstr "Gość"
71
+
72
+ #: application/view/manager.php:78
73
+ msgid "Visitor Manager"
74
+ msgstr "Zarządzaj gośćmi"
75
+
76
+ #: application/view/manager.php:95
77
+ msgid "Admin Menu"
78
+ msgstr "Admin Menu"
79
+
80
+ #: application/view/manager.php:98
81
+ msgid ""
82
+ "Control Access to Admin Menu. Restrict access to entire Menu or Submenu. "
83
+ "<b>Notice</b>, the menu is rendered based on Role's or User's capabilities."
84
+ msgstr ""
85
+ "Kontroluj dostęp do menu administracyjnego. Ogranicz dostęp do całych "
86
+ "pozycji menu lub do pozycji podmenu. <b>Wskazówka</b> menu jest dynamicznie "
87
+ "generowane zależnie od ról i uprawnień."
88
+
89
+ #: application/view/manager.php:103
90
+ msgid "Metabox & Widget"
91
+ msgstr "Metaboxy i Widżety"
92
+
93
+ #: application/view/manager.php:106
94
+ msgid ""
95
+ "Filter the list of Metaboxes or Widgets for selected Role or User. If "
96
+ "metabox or widget is not listed, try to click <b>Refresh the List</b> button "
97
+ "or Copy & Paste direct link to page where specific metabox or widget is "
98
+ "shown and hit <b>Retrieve Metaboxes from Link</b> button."
99
+ msgstr ""
100
+ "Filtruj listę Widżetów i Metaboksów dla wybranej roli lub użytkownika. "
101
+ "Jeżeli brakuje Metaboxów i/lub Widżetów na liście, kliknij ikonkę <b>Odśwież "
102
+ "listę</b> lub skopiuj i wklej bezpośredni odnośnik do strony, gdzie "
103
+ "wyświetlają się braujące Metaboksy i/lub Widżety i kliknij ikonkę plusa "
104
+ "<b>Wczytaj elementy ze strony</b>"
105
+
106
+ #: application/view/manager.php:111
107
+ msgid "Capability"
108
+ msgstr "Szczegółowe prawa"
109
+
110
+ #: application/view/manager.php:114
111
+ msgid ""
112
+ "Manage the list of Capabilities for selected User or Role. <b>Notice</b>, "
113
+ "list of user's capabilities are inherited from user's Role.<br/><b>Warning!</"
114
+ "b> Be very careful with capabilities. Deleting or unchecking any capability "
115
+ "may cause temporary or permanent constrol lost over some features or "
116
+ "WordPress dashboard."
117
+ msgstr ""
118
+ "Zarządzaj listą uprawnień dla wybranego użytkownia lub roli. <b>Wskazówka</"
119
+ "b> Lista uprawnień jest dziedziczona z roli/ról uzytkownika. <b>Ostrzeżenie!"
120
+ "</b> Bądź ostrony z uprawnieniami. Usuwanie lub odbieranie uprawnień może "
121
+ "spowodować tymczasowy lub całkowity brak dostępu do panelu administracyjnego "
122
+ "WordPress."
123
+
124
+ #: application/view/manager.php:119
125
+ msgid "Posts & Categories"
126
+ msgstr "Wpisy i Kategorie"
127
+
128
+ #: application/view/manager.php:122
129
+ msgid ""
130
+ "Manage access to individual <b>Post</b> or <b>Term</b>. Notice, under "
131
+ "<b>Post</b>, we assume any post, page or custom post type. And under "
132
+ "<b>Term</b> - any term like Post Categories."
133
+ msgstr ""
134
+ "Zarządzaj dostępen do poszczególnych <b>Wpisów</b> i/lub <b>Typów</b>. "
135
+ "Wyjaśnienie, <b>Wpisy</b> rozumiane jako dowolne strony, wpisy lub "
136
+ "niestandardowe typy wpisów. <b>Typy</b> rozumiane jako dowolne kategorie."
137
+
138
+ #: application/view/manager.php:127
139
+ msgid "Event Manager"
140
+ msgstr "Menadżer reguł"
141
+
142
+ #: application/view/manager.php:130
143
+ msgid ""
144
+ "Define your own action when some event appeared in your WordPress blog. This "
145
+ "sections allows you to trigger an action on event like post content change, "
146
+ "or page status update. You can setup to send email notification, change the "
147
+ "post status or write your own custom event handler."
148
+ msgstr ""
149
+ "Zdefiniuj własną akcję dla zdarzeń wystepujących w Twoim WordPress. Ta "
150
+ "skecja pozwala ustawić akcję na jakieś zdarzenie np.: zmiana treści wpisu/"
151
+ "strony lub statusu. Możesz skonfigurować wysyłanie powiadomień email, "
152
+ "zmienić status wpisu/strony lub zdefiniować własną obsługę zdarzenia. "
153
+
154
+ #: application/view/manager.php:135
155
+ msgid "ConfigPress"
156
+ msgstr "Konfiguracja"
157
+
158
+ #: application/view/manager.php:138
159
+ msgid ""
160
+ "Control <b>AAM</b> behavior with ConfigPress. For more details please check "
161
+ "<b>ConfigPress tutorial</b>."
162
+ msgstr ""
163
+ "Konfiguruj <b>AAM</b> przez ConfigPress. Aby uzyskać więcej informacji "
164
+ "zapoznaj się <b>poradnikiem ConfigPress</b>."
165
+
166
+ #: application/view/manager.php:342
167
+ msgid "Rollback Settings"
168
+ msgstr "Wycofaj ustawienia"
169
+
170
+ #: application/view/manager.php:343
171
+ msgid "Cancel"
172
+ msgstr "Anuluj"
173
+
174
+ #: application/view/manager.php:344
175
+ msgid "Send E-mail"
176
+ msgstr "Wyślij E-mail"
177
+
178
+ #: application/view/manager.php:345 application/view/manager.php:351
179
+ msgid "Add New Role"
180
+ msgstr "Dodaj nową rolę"
181
+
182
+ #: application/view/manager.php:346
183
+ msgid "Manage"
184
+ msgstr "Zarządzaj/Edytuj"
185
+
186
+ #: application/view/manager.php:347
187
+ msgid "Edit"
188
+ msgstr "Edytuj"
189
+
190
+ #: application/view/manager.php:348
191
+ msgid "Delete"
192
+ msgstr "Usuń"
193
+
194
+ #: application/view/manager.php:349
195
+ msgid "Filtered"
196
+ msgstr "Przefiltrowane"
197
+
198
+ #: application/view/manager.php:350
199
+ msgid "Clear"
200
+ msgstr "Wyczyść"
201
+
202
+ #: application/view/manager.php:352
203
+ msgid "Save Changes"
204
+ msgstr "Zapisz zmiany"
205
+
206
+ #: application/view/manager.php:353
207
+ #, php-format
208
+ msgid ""
209
+ "System detected %d user(s) with this role. All Users with Role <b>%s</b> "
210
+ "will be deleted automatically!"
211
+ msgstr ""
212
+ "System wykrył użytkownika/ów z tej roli. Wszyscy użytkownicy z tą rolą "
213
+ "zostaną usunięci!"
214
+
215
+ #: application/view/manager.php:354
216
+ #, php-format
217
+ msgid "Are you sure that you want to delete role <b>%s</b>?"
218
+ msgstr "Czy na pewno chcesz usunąć rolę/e?"
219
+
220
+ #: application/view/manager.php:355
221
+ msgid "Delete Role"
222
+ msgstr "Usuń rolę"
223
+
224
+ #: application/view/manager.php:356
225
+ msgid "Add User"
226
+ msgstr "Dodaj użytkownika"
227
+
228
+ #: application/view/manager.php:357
229
+ msgid "Filter Users"
230
+ msgstr "FIltruj uzytkowników"
231
+
232
+ #: application/view/manager.php:358 application/view/manager.php:374
233
+ msgid "Refresh List"
234
+ msgstr "Odśwież listę"
235
+
236
+ #: application/view/manager.php:359
237
+ msgid "Block"
238
+ msgstr "Zablokuj"
239
+
240
+ #: application/view/manager.php:360
241
+ #, php-format
242
+ msgid "Are you sure you want to delete user <b>%s</b>?"
243
+ msgstr "Czy na pewno chcesz usunąć użytkownika/ów?"
244
+
245
+ #: application/view/manager.php:361
246
+ msgid "Filter Capabilities by Category"
247
+ msgstr "Filtruj prawa wg kategorii"
248
+
249
+ #: application/view/manager.php:362
250
+ msgid "Inherit Capabilities"
251
+ msgstr "Dziedzicz prawa"
252
+
253
+ #: application/view/manager.php:363
254
+ msgid "Add New Capability"
255
+ msgstr "Dodaj nowe prawo"
256
+
257
+ #: application/view/manager.php:364
258
+ #, php-format
259
+ msgid "Are you sure that you want to delete capability <b>%s</b>?"
260
+ msgstr "Czy na pewno chcesz usunąć pozycję/e?"
261
+
262
+ #: application/view/manager.php:365
263
+ msgid "Delete Capability"
264
+ msgstr "Usuń pozycję"
265
+
266
+ #: application/view/manager.php:366
267
+ msgid "Select Role"
268
+ msgstr "Wybierz rolę"
269
+
270
+ #: application/view/manager.php:367
271
+ msgid "Add Capability"
272
+ msgstr "Dodaj pozycję"
273
+
274
+ #: application/view/manager.php:368
275
+ msgid "Add Event"
276
+ msgstr "Dodaj regułę"
277
+
278
+ #: application/view/manager.php:369
279
+ msgid "Edit Event"
280
+ msgstr "Edytuj regułę"
281
+
282
+ #: application/view/manager.php:370 application/view/manager.php:372
283
+ msgid "Delete Event"
284
+ msgstr "Usuń regułę"
285
+
286
+ #: application/view/manager.php:371
287
+ msgid "Save Event"
288
+ msgstr "Zapisz regułę"
289
+
290
+ #: application/view/manager.php:373
291
+ msgid "Filter Posts by Post Type"
292
+ msgstr "Filtruj wpisy typy wpisów"
293
+
294
+ #: application/view/manager.php:375
295
+ msgid "Restore Default"
296
+ msgstr "Przywróć domyślne"
297
+
298
+ #: application/view/manager.php:376
299
+ msgid "Apply"
300
+ msgstr "Zastosuj"
301
+
302
+ #: application/view/manager.php:377
303
+ msgid "Edit Term"
304
+ msgstr "Edytuj termin"
305
+
306
+ #: application/view/manager.php:378
307
+ msgid "Manager Access"
308
+ msgstr "Menadżer dostępu"
309
+
310
+ #: application/view/manager.php:379
311
+ msgid "Unlock Default Accesss Control"
312
+ msgstr "Odblokuj domyślną kontrolę dostępu"
313
+
314
+ #: application/view/manager.php:380
315
+ msgid "Close"
316
+ msgstr "Zamknij"
317
+
318
+ #: application/view/manager.php:381
319
+ msgid "Edit Role"
320
+ msgstr "Edytuj rolę"
321
+
322
+ #: application/view/metabox.php:179
323
+ msgid "Dashboard Widgets"
324
+ msgstr "Widżety panelu"
325
+
326
+ #: application/view/metabox.php:183
327
+ msgid "Frontend Widgets"
328
+ msgstr "Widżety strony"
329
+
330
+ #: application/view/post.php:181
331
+ msgid "[empty]"
332
+ msgstr "[puste]"
333
+
334
+ #: application/view/post.php:345 application/view/post.php:353
335
+ msgid "All"
336
+ msgstr "Wszystkie"
lang/aam.pot CHANGED
@@ -1,50 +1,68 @@
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: AAM\n"
4
- "POT-Creation-Date: 2013-12-01 14:07-0500\n"
5
- "PO-Revision-Date: 2013-12-01 14:08-0500\n"
6
- "Last-Translator: Vasyl Martyniuk <martyniuk.vasyl@gmail.com>\n"
7
- "Language-Team: WPAAM <support@wpaam.com>\n"
 
8
  "MIME-Version: 1.0\n"
9
  "Content-Type: text/plain; charset=UTF-8\n"
10
  "Content-Transfer-Encoding: 8bit\n"
 
 
 
 
 
11
 
12
- #: aam.php:243 aam.php:248 aam.php:267
13
  msgid "Access denied"
14
  msgstr ""
15
 
16
- #: aam.php:691 aam.php:692
17
  msgid "AAM"
18
  msgstr ""
19
 
20
- #: aam.php:701 aam.php:702
21
  msgid "Access Control"
22
  msgstr ""
23
 
24
- #: aam.php:709 aam.php:710
25
  msgid "Extensions"
26
  msgstr ""
27
 
28
- #: application/view/capability.php:98 application/view/capability.php:179
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
29
  msgid "System"
30
  msgstr ""
31
 
32
- #: application/view/capability.php:99 application/view/capability.php:181
33
  msgid "Post & Page"
34
  msgstr ""
35
 
36
- #: application/view/capability.php:100 application/view/capability.php:183
37
  msgid "Backend Interface"
38
  msgstr ""
39
 
40
- #: application/view/capability.php:101
41
  msgid "Miscellaneous"
42
  msgstr ""
43
 
44
- #: application/view/capability.php:185
45
- msgid "Miscelaneous"
46
- msgstr ""
47
-
48
  #: application/view/manager.php:59
49
  msgid "Roles"
50
  msgstr ""
@@ -137,165 +155,169 @@ msgid ""
137
  "<b>ConfigPress tutorial</b>."
138
  msgstr ""
139
 
140
- #: application/view/manager.php:342
141
  msgid "Rollback Settings"
142
  msgstr ""
143
 
144
- #: application/view/manager.php:343
145
  msgid "Cancel"
146
  msgstr ""
147
 
148
- #: application/view/manager.php:344
149
  msgid "Send E-mail"
150
  msgstr ""
151
 
152
- #: application/view/manager.php:345 application/view/manager.php:351
153
  msgid "Add New Role"
154
  msgstr ""
155
 
156
- #: application/view/manager.php:346
157
  msgid "Manage"
158
  msgstr ""
159
 
160
- #: application/view/manager.php:347
161
  msgid "Edit"
162
  msgstr ""
163
 
164
- #: application/view/manager.php:348
165
  msgid "Delete"
166
  msgstr ""
167
 
168
- #: application/view/manager.php:349
169
  msgid "Filtered"
170
  msgstr ""
171
 
172
- #: application/view/manager.php:350
173
  msgid "Clear"
174
  msgstr ""
175
 
176
- #: application/view/manager.php:352
177
  msgid "Save Changes"
178
  msgstr ""
179
 
180
- #: application/view/manager.php:353
181
  #, php-format
182
  msgid ""
183
  "System detected %d user(s) with this role. All Users with Role <b>%s</b> "
184
  "will be deleted automatically!"
185
  msgstr ""
186
 
187
- #: application/view/manager.php:354
188
  #, php-format
189
  msgid "Are you sure that you want to delete role <b>%s</b>?"
190
  msgstr ""
191
 
192
- #: application/view/manager.php:355
193
  msgid "Delete Role"
194
  msgstr ""
195
 
196
- #: application/view/manager.php:356
197
  msgid "Add User"
198
  msgstr ""
199
 
200
- #: application/view/manager.php:357
201
  msgid "Filter Users"
202
  msgstr ""
203
 
204
- #: application/view/manager.php:358 application/view/manager.php:374
205
  msgid "Refresh List"
206
  msgstr ""
207
 
208
- #: application/view/manager.php:359
209
  msgid "Block"
210
  msgstr ""
211
 
212
- #: application/view/manager.php:360
213
  #, php-format
214
  msgid "Are you sure you want to delete user <b>%s</b>?"
215
  msgstr ""
216
 
217
- #: application/view/manager.php:361
218
  msgid "Filter Capabilities by Category"
219
  msgstr ""
220
 
221
- #: application/view/manager.php:362
222
  msgid "Inherit Capabilities"
223
  msgstr ""
224
 
225
- #: application/view/manager.php:363
226
  msgid "Add New Capability"
227
  msgstr ""
228
 
229
- #: application/view/manager.php:364
230
  #, php-format
231
  msgid "Are you sure that you want to delete capability <b>%s</b>?"
232
  msgstr ""
233
 
234
- #: application/view/manager.php:365
235
  msgid "Delete Capability"
236
  msgstr ""
237
 
238
- #: application/view/manager.php:366
239
  msgid "Select Role"
240
  msgstr ""
241
 
242
- #: application/view/manager.php:367
243
  msgid "Add Capability"
244
  msgstr ""
245
 
246
- #: application/view/manager.php:368
247
  msgid "Add Event"
248
  msgstr ""
249
 
250
- #: application/view/manager.php:369
251
  msgid "Edit Event"
252
  msgstr ""
253
 
254
- #: application/view/manager.php:370 application/view/manager.php:372
255
  msgid "Delete Event"
256
  msgstr ""
257
 
258
- #: application/view/manager.php:371
259
  msgid "Save Event"
260
  msgstr ""
261
 
262
- #: application/view/manager.php:373
263
  msgid "Filter Posts by Post Type"
264
  msgstr ""
265
 
266
- #: application/view/manager.php:375
267
  msgid "Restore Default"
268
  msgstr ""
269
 
270
- #: application/view/manager.php:376
271
  msgid "Apply"
272
  msgstr ""
273
 
274
- #: application/view/manager.php:377
275
  msgid "Edit Term"
276
  msgstr ""
277
 
278
- #: application/view/manager.php:378
279
  msgid "Manager Access"
280
  msgstr ""
281
 
282
- #: application/view/manager.php:379
283
  msgid "Unlock Default Accesss Control"
284
  msgstr ""
285
 
286
- #: application/view/manager.php:380
287
  msgid "Close"
288
  msgstr ""
289
 
290
- #: application/view/manager.php:381
291
  msgid "Edit Role"
292
  msgstr ""
293
 
294
- #: application/view/metabox.php:179
 
 
 
 
295
  msgid "Dashboard Widgets"
296
  msgstr ""
297
 
298
- #: application/view/metabox.php:183
299
  msgid "Frontend Widgets"
300
  msgstr ""
301
 
@@ -306,3 +328,31 @@ msgstr ""
306
  #: application/view/post.php:345 application/view/post.php:353
307
  msgid "All"
308
  msgstr ""
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  msgid ""
2
  msgstr ""
3
  "Project-Id-Version: AAM\n"
4
+ "POT-Creation-Date: 2014-01-23 20:56-0500\n"
5
+ "PO-Revision-Date: 2014-01-23 20:56-0500\n"
6
+ "Last-Translator: WPAAM <support@wpaam.com>\n"
7
+ "Language-Team: \n"
8
+ "Language: en\n"
9
  "MIME-Version: 1.0\n"
10
  "Content-Type: text/plain; charset=UTF-8\n"
11
  "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.6.3\n"
13
+ "X-Poedit-Basepath: d:\\xampp\\htdocs\\multisite\\wp-content\\plugins\\aam\\\n"
14
+ "Plural-Forms: nplurals=2; plural=(n != 1);\n"
15
+ "X-Poedit-KeywordsList: __\n"
16
+ "X-Poedit-SearchPath-0: .\n"
17
 
18
+ #: aam.php:346 aam.php:351 aam.php:379
19
  msgid "Access denied"
20
  msgstr ""
21
 
22
+ #: aam.php:833 aam.php:834
23
  msgid "AAM"
24
  msgstr ""
25
 
26
+ #: aam.php:843 aam.php:844
27
  msgid "Access Control"
28
  msgstr ""
29
 
30
+ #: aam.php:851 aam.php:852
31
  msgid "Extensions"
32
  msgstr ""
33
 
34
+ #: config.php:58
35
+ msgid "<b>wp-content</b> folder is not writable or does not exists. "
36
+ msgstr ""
37
+
38
+ #: config.php:60
39
+ msgid "Read more."
40
+ msgstr ""
41
+
42
+ #: config.php:85
43
+ msgid "Migrate your old AAM settings to the new AAM platform. "
44
+ msgstr ""
45
+
46
+ #: config.php:86
47
+ msgid "Click to Migrate"
48
+ msgstr ""
49
+
50
+ #: application/view/capability.php:100 application/view/capability.php:199
51
  msgid "System"
52
  msgstr ""
53
 
54
+ #: application/view/capability.php:101 application/view/capability.php:201
55
  msgid "Post & Page"
56
  msgstr ""
57
 
58
+ #: application/view/capability.php:102 application/view/capability.php:203
59
  msgid "Backend Interface"
60
  msgstr ""
61
 
62
+ #: application/view/capability.php:103 application/view/capability.php:205
63
  msgid "Miscellaneous"
64
  msgstr ""
65
 
 
 
 
 
66
  #: application/view/manager.php:59
67
  msgid "Roles"
68
  msgstr ""
155
  "<b>ConfigPress tutorial</b>."
156
  msgstr ""
157
 
158
+ #: application/view/manager.php:339
159
  msgid "Rollback Settings"
160
  msgstr ""
161
 
162
+ #: application/view/manager.php:340
163
  msgid "Cancel"
164
  msgstr ""
165
 
166
+ #: application/view/manager.php:341
167
  msgid "Send E-mail"
168
  msgstr ""
169
 
170
+ #: application/view/manager.php:342 application/view/manager.php:348
171
  msgid "Add New Role"
172
  msgstr ""
173
 
174
+ #: application/view/manager.php:343
175
  msgid "Manage"
176
  msgstr ""
177
 
178
+ #: application/view/manager.php:344
179
  msgid "Edit"
180
  msgstr ""
181
 
182
+ #: application/view/manager.php:345
183
  msgid "Delete"
184
  msgstr ""
185
 
186
+ #: application/view/manager.php:346
187
  msgid "Filtered"
188
  msgstr ""
189
 
190
+ #: application/view/manager.php:347
191
  msgid "Clear"
192
  msgstr ""
193
 
194
+ #: application/view/manager.php:349
195
  msgid "Save Changes"
196
  msgstr ""
197
 
198
+ #: application/view/manager.php:350
199
  #, php-format
200
  msgid ""
201
  "System detected %d user(s) with this role. All Users with Role <b>%s</b> "
202
  "will be deleted automatically!"
203
  msgstr ""
204
 
205
+ #: application/view/manager.php:351
206
  #, php-format
207
  msgid "Are you sure that you want to delete role <b>%s</b>?"
208
  msgstr ""
209
 
210
+ #: application/view/manager.php:352
211
  msgid "Delete Role"
212
  msgstr ""
213
 
214
+ #: application/view/manager.php:353
215
  msgid "Add User"
216
  msgstr ""
217
 
218
+ #: application/view/manager.php:354
219
  msgid "Filter Users"
220
  msgstr ""
221
 
222
+ #: application/view/manager.php:355 application/view/manager.php:371
223
  msgid "Refresh List"
224
  msgstr ""
225
 
226
+ #: application/view/manager.php:356
227
  msgid "Block"
228
  msgstr ""
229
 
230
+ #: application/view/manager.php:357
231
  #, php-format
232
  msgid "Are you sure you want to delete user <b>%s</b>?"
233
  msgstr ""
234
 
235
+ #: application/view/manager.php:358
236
  msgid "Filter Capabilities by Category"
237
  msgstr ""
238
 
239
+ #: application/view/manager.php:359
240
  msgid "Inherit Capabilities"
241
  msgstr ""
242
 
243
+ #: application/view/manager.php:360
244
  msgid "Add New Capability"
245
  msgstr ""
246
 
247
+ #: application/view/manager.php:361
248
  #, php-format
249
  msgid "Are you sure that you want to delete capability <b>%s</b>?"
250
  msgstr ""
251
 
252
+ #: application/view/manager.php:362
253
  msgid "Delete Capability"
254
  msgstr ""
255
 
256
+ #: application/view/manager.php:363
257
  msgid "Select Role"
258
  msgstr ""
259
 
260
+ #: application/view/manager.php:364
261
  msgid "Add Capability"
262
  msgstr ""
263
 
264
+ #: application/view/manager.php:365
265
  msgid "Add Event"
266
  msgstr ""
267
 
268
+ #: application/view/manager.php:366
269
  msgid "Edit Event"
270
  msgstr ""
271
 
272
+ #: application/view/manager.php:367 application/view/manager.php:369
273
  msgid "Delete Event"
274
  msgstr ""
275
 
276
+ #: application/view/manager.php:368
277
  msgid "Save Event"
278
  msgstr ""
279
 
280
+ #: application/view/manager.php:370
281
  msgid "Filter Posts by Post Type"
282
  msgstr ""
283
 
284
+ #: application/view/manager.php:372
285
  msgid "Restore Default"
286
  msgstr ""
287
 
288
+ #: application/view/manager.php:373
289
  msgid "Apply"
290
  msgstr ""
291
 
292
+ #: application/view/manager.php:374
293
  msgid "Edit Term"
294
  msgstr ""
295
 
296
+ #: application/view/manager.php:375
297
  msgid "Manager Access"
298
  msgstr ""
299
 
300
+ #: application/view/manager.php:376
301
  msgid "Unlock Default Accesss Control"
302
  msgstr ""
303
 
304
+ #: application/view/manager.php:377
305
  msgid "Close"
306
  msgstr ""
307
 
308
+ #: application/view/manager.php:378
309
  msgid "Edit Role"
310
  msgstr ""
311
 
312
+ #: application/view/manager.php:379
313
+ msgid "Restore Default Capabilities"
314
+ msgstr ""
315
+
316
+ #: application/view/metabox.php:185
317
  msgid "Dashboard Widgets"
318
  msgstr ""
319
 
320
+ #: application/view/metabox.php:189
321
  msgid "Frontend Widgets"
322
  msgstr ""
323
 
328
  #: application/view/post.php:345 application/view/post.php:353
329
  msgid "All"
330
  msgstr ""
331
+
332
+ #: extension/AAM_Multisite_Support/extension.php:125
333
+ msgid "Sites"
334
+ msgstr ""
335
+
336
+ #: extension/AAM_Multisite_Support/extension.php:126
337
+ msgid "Site Manager"
338
+ msgstr ""
339
+
340
+ #: extension/AAM_Multisite_Support/extension.php:189
341
+ msgid "Set Default"
342
+ msgstr ""
343
+
344
+ #: extension/AAM_Multisite_Support/extension.php:190
345
+ msgid "Unset Default"
346
+ msgstr ""
347
+
348
+ #: extension/AAM_Multisite_Support/extension.php:191
349
+ msgid "Set as Default"
350
+ msgstr ""
351
+
352
+ #: extension/AAM_My_Feature/extension.php:50
353
+ msgid "My Feature"
354
+ msgstr ""
355
+
356
+ #: extension/AAM_My_Feature/extension.php:53
357
+ msgid "My customly developed feature"
358
+ msgstr ""
media/css/images/capability/add-active.png CHANGED
Binary file
media/css/images/capability/add.png CHANGED
Binary file
media/css/images/capability/checked.png CHANGED
Binary file
media/css/images/capability/copy-active.png CHANGED
Binary file
media/css/images/capability/copy.png CHANGED
Binary file
media/css/images/capability/delete-active.png CHANGED
Binary file
media/css/images/capability/delete.png CHANGED
Binary file
media/css/images/capability/filter-active.png CHANGED
Binary file
media/css/images/capability/filter.png CHANGED
Binary file
media/css/images/capability/restore-active.png CHANGED
Binary file
media/css/images/capability/restore.png CHANGED
Binary file
media/css/images/capability/select-active.png CHANGED
Binary file
media/css/images/capability/select.png CHANGED
Binary file
media/css/images/capability/unchecked.png CHANGED
Binary file
media/css/images/cmanager/add-active.png CHANGED
Binary file
media/css/images/cmanager/add.png CHANGED
Binary file
media/css/images/cmanager/block-user-active.png CHANGED
Binary file
media/css/images/cmanager/block-user.png CHANGED
Binary file
media/css/images/cmanager/delete-active.png CHANGED
Binary file
media/css/images/cmanager/delete.png CHANGED
Binary file
media/css/images/cmanager/edit-active.png CHANGED
Binary file
media/css/images/cmanager/edit-user-active.png CHANGED
Binary file
media/css/images/cmanager/edit-user.png CHANGED
Binary file
media/css/images/cmanager/edit.png CHANGED
Binary file
media/css/images/cmanager/filter-active.png CHANGED
Binary file
media/css/images/cmanager/filter.png CHANGED
Binary file
media/css/images/cmanager/multisite-active.png DELETED
Binary file
media/css/images/cmanager/multisite.png DELETED
Binary file
media/css/images/cmanager/refresh-active.png CHANGED
Binary file
media/css/images/cmanager/refresh.png CHANGED
Binary file
media/css/images/cmanager/role-active.png CHANGED
Binary file
media/css/images/cmanager/role.png CHANGED
Binary file
media/css/images/cmanager/select-active.png CHANGED
Binary file
media/css/images/cmanager/select.png CHANGED
Binary file
media/css/images/cmanager/settings-active.png CHANGED
Binary file
media/css/images/cmanager/settings.png CHANGED
Binary file
media/css/images/cmanager/user-active.png CHANGED
Binary file
media/css/images/cmanager/user.png CHANGED
Binary file
media/css/images/cmanager/visitor-active.png CHANGED
Binary file
media/css/images/cmanager/visitor.png CHANGED
Binary file
media/css/images/configpress/pdf-active.png CHANGED
Binary file
media/css/images/configpress/pdf.png CHANGED
Binary file
media/css/images/cpanel/help-forum-active.png CHANGED
Binary file
media/css/images/cpanel/help-forum.png CHANGED
Binary file
media/css/images/cpanel/message-active.png CHANGED
Binary file
media/css/images/cpanel/message.png CHANGED
Binary file
media/css/images/cpanel/restore-active.png CHANGED
Binary file
media/css/images/cpanel/restore.png CHANGED
Binary file
media/css/images/cpanel/save-active.png CHANGED
Binary file
media/css/images/cpanel/save.png CHANGED
Binary file
media/css/images/cpanel/star-active.png CHANGED
Binary file
media/css/images/cpanel/star.png CHANGED
Binary file
media/css/images/cpanel/twitter-active.png CHANGED
Binary file
media/css/images/cpanel/twitter.png CHANGED
Binary file
media/css/images/event/add-active.png CHANGED
Binary file
media/css/images/event/add.png CHANGED
Binary file
media/css/images/event/delete-active.png CHANGED
Binary file
media/css/images/event/delete.png CHANGED
Binary file
media/css/images/event/edit-active.png CHANGED
Binary file
media/css/images/event/edit.png CHANGED
Binary file
media/css/images/extension/download-active.png CHANGED
Binary file
media/css/images/extension/download.png CHANGED
Binary file
media/css/images/extension/forum-active.png CHANGED
Binary file
media/css/images/extension/forum.png CHANGED
Binary file
media/css/images/extension/link-active.png CHANGED
Binary file
media/css/images/extension/link.png CHANGED
Binary file
media/css/images/extension/message-active.png CHANGED
Binary file
media/css/images/extension/message.png CHANGED
Binary file
media/css/images/extension/ok-active.png CHANGED
Binary file
media/css/images/extension/ok.png CHANGED
Binary file
media/css/images/extension/plus-active.png CHANGED
Binary file
media/css/images/extension/plus.png CHANGED
Binary file
media/css/images/extension/purchase-active.png DELETED
Binary file
media/css/images/extension/purchase.png DELETED
Binary file
media/css/images/extension/twitter-active.png CHANGED
Binary file
media/css/images/extension/twitter.png CHANGED
Binary file
media/css/images/extension/youtube-active.png CHANGED
Binary file
media/css/images/extension/youtube.png CHANGED
Binary file
media/css/images/feature-active.png CHANGED
Binary file
media/css/images/lock.png CHANGED
Binary file
media/css/images/menu/checked.png CHANGED
Binary file
media/css/images/menu/sorting-active.png DELETED
Binary file
media/css/images/menu/sorting.png DELETED
Binary file
media/css/images/menu/unchecked.png CHANGED
Binary file
media/css/images/menu/visibility-active.png DELETED
Binary file
media/css/images/menu/visibility.png DELETED
Binary file
media/css/images/metabox/add-active.png CHANGED
Binary file
media/css/images/metabox/add.png CHANGED
Binary file
media/css/images/metabox/checked.png CHANGED
Binary file
media/css/images/metabox/link-active.png CHANGED
Binary file
media/css/images/metabox/link.png CHANGED
Binary file
media/css/images/metabox/refresh-active.png CHANGED
Binary file
media/css/images/metabox/refresh.png CHANGED
Binary file
media/css/images/metabox/unchecked.png CHANGED
Binary file
media/css/images/post/checked.png CHANGED
Binary file
media/css/images/post/edit-active.png CHANGED
Binary file
media/css/images/post/edit.png CHANGED
Binary file
media/css/images/post/filter-active.png CHANGED
Binary file
media/css/images/post/filter.png CHANGED
Binary file
media/css/images/post/info-active.png CHANGED
Binary file
media/css/images/post/info.png CHANGED
Binary file
media/css/images/post/lock-big.png CHANGED
Binary file
media/css/images/post/lock.png CHANGED
Binary file
media/css/images/post/post.png CHANGED
Binary file
media/css/images/post/refresh-active.png CHANGED
Binary file
media/css/images/post/refresh.png CHANGED
Binary file
media/css/images/post/settings-active.png CHANGED
Binary file
media/css/images/post/settings.png CHANGED
Binary file
media/css/images/post/unchecked.png CHANGED
Binary file
media/css/images/search-active.png CHANGED
Binary file
media/css/images/search.png CHANGED
Binary file
media/css/images/sort_asc.png CHANGED
Binary file
media/css/images/sort_asc_disabled.png CHANGED
Binary file
media/css/images/sort_both.png CHANGED
Binary file
media/css/images/sort_desc.png CHANGED
Binary file
media/css/images/sort_desc_disabled.png CHANGED
Binary file
media/css/images/table-filtered.png CHANGED
Binary file
media/css/images/ui-icons_222222_256x240.png CHANGED
Binary file
media/css/images/ui-icons_454545_256x240.png CHANGED
Binary file
media/css/images/ui-icons_888888_256x240.png CHANGED
Binary file
media/js/aam.js CHANGED
@@ -1264,7 +1264,7 @@ AAM.prototype.initSettings = function() {
1264
  jQuery(this).bind('click', function() {
1265
  jQuery('.feature-list .feature-item').removeClass(
1266
  'feature-item-active'
1267
- );
1268
  jQuery(this).addClass('feature-item-active');
1269
  jQuery('.feature-content .feature-content-container').hide();
1270
  jQuery('#' + jQuery(this).attr('feature') + '_content').show();
@@ -1272,7 +1272,7 @@ AAM.prototype.initSettings = function() {
1272
  jQuery('.aam-help > span').hide();
1273
  jQuery('#feature_help_' + jQuery(this).attr('feature')).css(
1274
  'display', 'table-cell'
1275
- );
1276
  });
1277
  });
1278
 
1264
  jQuery(this).bind('click', function() {
1265
  jQuery('.feature-list .feature-item').removeClass(
1266
  'feature-item-active'
1267
+ );
1268
  jQuery(this).addClass('feature-item-active');
1269
  jQuery('.feature-content .feature-content-container').hide();
1270
  jQuery('#' + jQuery(this).attr('feature') + '_content').show();
1272
  jQuery('.aam-help > span').hide();
1273
  jQuery('#feature_help_' + jQuery(this).attr('feature')).css(
1274
  'display', 'table-cell'
1275
+ );
1276
  });
1277
  });
1278
 
media/js/codemirror.js CHANGED
@@ -1,5829 +1 @@
1
- // CodeMirror version 3.16
2
- //
3
- // CodeMirror is the only global var we claim
4
- window.CodeMirror = (function() {
5
- "use strict";
6
-
7
- // BROWSER SNIFFING
8
-
9
- // Crude, but necessary to handle a number of hard-to-feature-detect
10
- // bugs and behavior differences.
11
- var gecko = /gecko\/\d/i.test(navigator.userAgent);
12
- var ie = /MSIE \d/.test(navigator.userAgent);
13
- var ie_lt8 = ie && (document.documentMode == null || document.documentMode < 8);
14
- var ie_lt9 = ie && (document.documentMode == null || document.documentMode < 9);
15
- var webkit = /WebKit\//.test(navigator.userAgent);
16
- var qtwebkit = webkit && /Qt\/\d+\.\d+/.test(navigator.userAgent);
17
- var chrome = /Chrome\//.test(navigator.userAgent);
18
- var opera = /Opera\//.test(navigator.userAgent);
19
- var safari = /Apple Computer/.test(navigator.vendor);
20
- var khtml = /KHTML\//.test(navigator.userAgent);
21
- var mac_geLion = /Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent);
22
- var mac_geMountainLion = /Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent);
23
- var phantom = /PhantomJS/.test(navigator.userAgent);
24
-
25
- var ios = /AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent);
26
- // This is woefully incomplete. Suggestions for alternative methods welcome.
27
- var mobile = ios || /Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent);
28
- var mac = ios || /Mac/.test(navigator.platform);
29
- var windows = /win/i.test(navigator.platform);
30
-
31
- var opera_version = opera && navigator.userAgent.match(/Version\/(\d*\.\d*)/);
32
- if (opera_version) opera_version = Number(opera_version[1]);
33
- if (opera_version && opera_version >= 15) { opera = false; webkit = true; }
34
- // Some browsers use the wrong event properties to signal cmd/ctrl on OS X
35
- var flipCtrlCmd = mac && (qtwebkit || opera && (opera_version == null || opera_version < 12.11));
36
- var captureMiddleClick = gecko || (ie && !ie_lt9);
37
-
38
- // Optimize some code when these features are not used
39
- var sawReadOnlySpans = false, sawCollapsedSpans = false;
40
-
41
- // CONSTRUCTOR
42
-
43
- function CodeMirror(place, options) {
44
- if (!(this instanceof CodeMirror)) return new CodeMirror(place, options);
45
-
46
- this.options = options = options || {};
47
- // Determine effective options based on given values and defaults.
48
- for (var opt in defaults) if (!options.hasOwnProperty(opt) && defaults.hasOwnProperty(opt))
49
- options[opt] = defaults[opt];
50
- setGuttersForLineNumbers(options);
51
-
52
- var docStart = typeof options.value == "string" ? 0 : options.value.first;
53
- var display = this.display = makeDisplay(place, docStart);
54
- display.wrapper.CodeMirror = this;
55
- updateGutters(this);
56
- if (options.autofocus && !mobile) focusInput(this);
57
-
58
- this.state = {keyMaps: [],
59
- overlays: [],
60
- modeGen: 0,
61
- overwrite: false, focused: false,
62
- suppressEdits: false, pasteIncoming: false,
63
- draggingText: false,
64
- highlight: new Delayed()};
65
-
66
- themeChanged(this);
67
- if (options.lineWrapping)
68
- this.display.wrapper.className += " CodeMirror-wrap";
69
-
70
- var doc = options.value;
71
- if (typeof doc == "string") doc = new Doc(options.value, options.mode);
72
- operation(this, attachDoc)(this, doc);
73
-
74
- // Override magic textarea content restore that IE sometimes does
75
- // on our hidden textarea on reload
76
- if (ie) setTimeout(bind(resetInput, this, true), 20);
77
-
78
- registerEventHandlers(this);
79
- // IE throws unspecified error in certain cases, when
80
- // trying to access activeElement before onload
81
- var hasFocus; try { hasFocus = (document.activeElement == display.input); } catch(e) { }
82
- if (hasFocus || (options.autofocus && !mobile)) setTimeout(bind(onFocus, this), 20);
83
- else onBlur(this);
84
-
85
- operation(this, function() {
86
- for (var opt in optionHandlers)
87
- if (optionHandlers.propertyIsEnumerable(opt))
88
- optionHandlers[opt](this, options[opt], Init);
89
- for (var i = 0; i < initHooks.length; ++i) initHooks[i](this);
90
- })();
91
- }
92
-
93
- // DISPLAY CONSTRUCTOR
94
-
95
- function makeDisplay(place, docStart) {
96
- var d = {};
97
-
98
- var input = d.input = elt("textarea", null, null, "position: absolute; padding: 0; width: 1px; height: 1em; outline: none; font-size: 4px;");
99
- if (webkit) input.style.width = "1000px";
100
- else input.setAttribute("wrap", "off");
101
- // if border: 0; -- iOS fails to open keyboard (issue #1287)
102
- if (ios) input.style.border = "1px solid black";
103
- input.setAttribute("autocorrect", "off"); input.setAttribute("autocapitalize", "off"); input.setAttribute("spellcheck", "false");
104
-
105
- // Wraps and hides input textarea
106
- d.inputDiv = elt("div", [input], null, "overflow: hidden; position: relative; width: 3px; height: 0px;");
107
- // The actual fake scrollbars.
108
- d.scrollbarH = elt("div", [elt("div", null, null, "height: 1px")], "CodeMirror-hscrollbar");
109
- d.scrollbarV = elt("div", [elt("div", null, null, "width: 1px")], "CodeMirror-vscrollbar");
110
- d.scrollbarFiller = elt("div", null, "CodeMirror-scrollbar-filler");
111
- d.gutterFiller = elt("div", null, "CodeMirror-gutter-filler");
112
- // DIVs containing the selection and the actual code
113
- d.lineDiv = elt("div", null, "CodeMirror-code");
114
- d.selectionDiv = elt("div", null, null, "position: relative; z-index: 1");
115
- // Blinky cursor, and element used to ensure cursor fits at the end of a line
116
- d.cursor = elt("div", "\u00a0", "CodeMirror-cursor");
117
- // Secondary cursor, shown when on a 'jump' in bi-directional text
118
- d.otherCursor = elt("div", "\u00a0", "CodeMirror-cursor CodeMirror-secondarycursor");
119
- // Used to measure text size
120
- d.measure = elt("div", null, "CodeMirror-measure");
121
- // Wraps everything that needs to exist inside the vertically-padded coordinate system
122
- d.lineSpace = elt("div", [d.measure, d.selectionDiv, d.lineDiv, d.cursor, d.otherCursor],
123
- null, "position: relative; outline: none");
124
- // Moved around its parent to cover visible view
125
- d.mover = elt("div", [elt("div", [d.lineSpace], "CodeMirror-lines")], null, "position: relative");
126
- // Set to the height of the text, causes scrolling
127
- d.sizer = elt("div", [d.mover], "CodeMirror-sizer");
128
- // D is needed because behavior of elts with overflow: auto and padding is inconsistent across browsers
129
- d.heightForcer = elt("div", null, null, "position: absolute; height: " + scrollerCutOff + "px; width: 1px;");
130
- // Will contain the gutters, if any
131
- d.gutters = elt("div", null, "CodeMirror-gutters");
132
- d.lineGutter = null;
133
- // Provides scrolling
134
- d.scroller = elt("div", [d.sizer, d.heightForcer, d.gutters], "CodeMirror-scroll");
135
- d.scroller.setAttribute("tabIndex", "-1");
136
- // The element in which the editor lives.
137
- d.wrapper = elt("div", [d.inputDiv, d.scrollbarH, d.scrollbarV,
138
- d.scrollbarFiller, d.gutterFiller, d.scroller], "CodeMirror");
139
- // Work around IE7 z-index bug
140
- if (ie_lt8) { d.gutters.style.zIndex = -1; d.scroller.style.paddingRight = 0; }
141
- if (place.appendChild) place.appendChild(d.wrapper); else place(d.wrapper);
142
-
143
- // Needed to hide big blue blinking cursor on Mobile Safari
144
- if (ios) input.style.width = "0px";
145
- if (!webkit) d.scroller.draggable = true;
146
- // Needed to handle Tab key in KHTML
147
- if (khtml) { d.inputDiv.style.height = "1px"; d.inputDiv.style.position = "absolute"; }
148
- // Need to set a minimum width to see the scrollbar on IE7 (but must not set it on IE8).
149
- else if (ie_lt8) d.scrollbarH.style.minWidth = d.scrollbarV.style.minWidth = "18px";
150
-
151
- // Current visible range (may be bigger than the view window).
152
- d.viewOffset = d.lastSizeC = 0;
153
- d.showingFrom = d.showingTo = docStart;
154
-
155
- // Used to only resize the line number gutter when necessary (when
156
- // the amount of lines crosses a boundary that makes its width change)
157
- d.lineNumWidth = d.lineNumInnerWidth = d.lineNumChars = null;
158
- // See readInput and resetInput
159
- d.prevInput = "";
160
- // Set to true when a non-horizontal-scrolling widget is added. As
161
- // an optimization, widget aligning is skipped when d is false.
162
- d.alignWidgets = false;
163
- // Flag that indicates whether we currently expect input to appear
164
- // (after some event like 'keypress' or 'input') and are polling
165
- // intensively.
166
- d.pollingFast = false;
167
- // Self-resetting timeout for the poller
168
- d.poll = new Delayed();
169
-
170
- d.cachedCharWidth = d.cachedTextHeight = null;
171
- d.measureLineCache = [];
172
- d.measureLineCachePos = 0;
173
-
174
- // Tracks when resetInput has punted to just putting a short
175
- // string instead of the (large) selection.
176
- d.inaccurateSelection = false;
177
-
178
- // Tracks the maximum line length so that the horizontal scrollbar
179
- // can be kept static when scrolling.
180
- d.maxLine = null;
181
- d.maxLineLength = 0;
182
- d.maxLineChanged = false;
183
-
184
- // Used for measuring wheel scrolling granularity
185
- d.wheelDX = d.wheelDY = d.wheelStartX = d.wheelStartY = null;
186
-
187
- return d;
188
- }
189
-
190
- // STATE UPDATES
191
-
192
- // Used to get the editor into a consistent state again when options change.
193
-
194
- function loadMode(cm) {
195
- cm.doc.mode = CodeMirror.getMode(cm.options, cm.doc.modeOption);
196
- cm.doc.iter(function(line) {
197
- if (line.stateAfter) line.stateAfter = null;
198
- if (line.styles) line.styles = null;
199
- });
200
- cm.doc.frontier = cm.doc.first;
201
- startWorker(cm, 100);
202
- cm.state.modeGen++;
203
- if (cm.curOp) regChange(cm);
204
- }
205
-
206
- function wrappingChanged(cm) {
207
- if (cm.options.lineWrapping) {
208
- cm.display.wrapper.className += " CodeMirror-wrap";
209
- cm.display.sizer.style.minWidth = "";
210
- } else {
211
- cm.display.wrapper.className = cm.display.wrapper.className.replace(" CodeMirror-wrap", "");
212
- computeMaxLength(cm);
213
- }
214
- estimateLineHeights(cm);
215
- regChange(cm);
216
- clearCaches(cm);
217
- setTimeout(function(){updateScrollbars(cm);}, 100);
218
- }
219
-
220
- function estimateHeight(cm) {
221
- var th = textHeight(cm.display), wrapping = cm.options.lineWrapping;
222
- var perLine = wrapping && Math.max(5, cm.display.scroller.clientWidth / charWidth(cm.display) - 3);
223
- return function(line) {
224
- if (lineIsHidden(cm.doc, line))
225
- return 0;
226
- else if (wrapping)
227
- return (Math.ceil(line.text.length / perLine) || 1) * th;
228
- else
229
- return th;
230
- };
231
- }
232
-
233
- function estimateLineHeights(cm) {
234
- var doc = cm.doc, est = estimateHeight(cm);
235
- doc.iter(function(line) {
236
- var estHeight = est(line);
237
- if (estHeight != line.height) updateLineHeight(line, estHeight);
238
- });
239
- }
240
-
241
- function keyMapChanged(cm) {
242
- var map = keyMap[cm.options.keyMap], style = map.style;
243
- cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-keymap-\S+/g, "") +
244
- (style ? " cm-keymap-" + style : "");
245
- cm.state.disableInput = map.disableInput;
246
- }
247
-
248
- function themeChanged(cm) {
249
- cm.display.wrapper.className = cm.display.wrapper.className.replace(/\s*cm-s-\S+/g, "") +
250
- cm.options.theme.replace(/(^|\s)\s*/g, " cm-s-");
251
- clearCaches(cm);
252
- }
253
-
254
- function guttersChanged(cm) {
255
- updateGutters(cm);
256
- regChange(cm);
257
- setTimeout(function(){alignHorizontally(cm);}, 20);
258
- }
259
-
260
- function updateGutters(cm) {
261
- var gutters = cm.display.gutters, specs = cm.options.gutters;
262
- removeChildren(gutters);
263
- for (var i = 0; i < specs.length; ++i) {
264
- var gutterClass = specs[i];
265
- var gElt = gutters.appendChild(elt("div", null, "CodeMirror-gutter " + gutterClass));
266
- if (gutterClass == "CodeMirror-linenumbers") {
267
- cm.display.lineGutter = gElt;
268
- gElt.style.width = (cm.display.lineNumWidth || 1) + "px";
269
- }
270
- }
271
- gutters.style.display = i ? "" : "none";
272
- }
273
-
274
- function lineLength(doc, line) {
275
- if (line.height == 0) return 0;
276
- var len = line.text.length, merged, cur = line;
277
- while (merged = collapsedSpanAtStart(cur)) {
278
- var found = merged.find();
279
- cur = getLine(doc, found.from.line);
280
- len += found.from.ch - found.to.ch;
281
- }
282
- cur = line;
283
- while (merged = collapsedSpanAtEnd(cur)) {
284
- var found = merged.find();
285
- len -= cur.text.length - found.from.ch;
286
- cur = getLine(doc, found.to.line);
287
- len += cur.text.length - found.to.ch;
288
- }
289
- return len;
290
- }
291
-
292
- function computeMaxLength(cm) {
293
- var d = cm.display, doc = cm.doc;
294
- d.maxLine = getLine(doc, doc.first);
295
- d.maxLineLength = lineLength(doc, d.maxLine);
296
- d.maxLineChanged = true;
297
- doc.iter(function(line) {
298
- var len = lineLength(doc, line);
299
- if (len > d.maxLineLength) {
300
- d.maxLineLength = len;
301
- d.maxLine = line;
302
- }
303
- });
304
- }
305
-
306
- // Make sure the gutters options contains the element
307
- // "CodeMirror-linenumbers" when the lineNumbers option is true.
308
- function setGuttersForLineNumbers(options) {
309
- var found = false;
310
- for (var i = 0; i < options.gutters.length; ++i) {
311
- if (options.gutters[i] == "CodeMirror-linenumbers") {
312
- if (options.lineNumbers) found = true;
313
- else options.gutters.splice(i--, 1);
314
- }
315
- }
316
- if (!found && options.lineNumbers)
317
- options.gutters.push("CodeMirror-linenumbers");
318
- }
319
-
320
- // SCROLLBARS
321
-
322
- // Re-synchronize the fake scrollbars with the actual size of the
323
- // content. Optionally force a scrollTop.
324
- function updateScrollbars(cm) {
325
- var d = cm.display, docHeight = cm.doc.height;
326
- var totalHeight = docHeight + paddingVert(d);
327
- d.sizer.style.minHeight = d.heightForcer.style.top = totalHeight + "px";
328
- d.gutters.style.height = Math.max(totalHeight, d.scroller.clientHeight - scrollerCutOff) + "px";
329
- var scrollHeight = Math.max(totalHeight, d.scroller.scrollHeight);
330
- var needsH = d.scroller.scrollWidth > (d.scroller.clientWidth + 1);
331
- var needsV = scrollHeight > (d.scroller.clientHeight + 1);
332
- if (needsV) {
333
- d.scrollbarV.style.display = "block";
334
- d.scrollbarV.style.bottom = needsH ? scrollbarWidth(d.measure) + "px" : "0";
335
- d.scrollbarV.firstChild.style.height =
336
- (scrollHeight - d.scroller.clientHeight + d.scrollbarV.clientHeight) + "px";
337
- } else {
338
- d.scrollbarV.style.display = "";
339
- d.scrollbarV.firstChild.style.height = "0";
340
- }
341
- if (needsH) {
342
- d.scrollbarH.style.display = "block";
343
- d.scrollbarH.style.right = needsV ? scrollbarWidth(d.measure) + "px" : "0";
344
- d.scrollbarH.firstChild.style.width =
345
- (d.scroller.scrollWidth - d.scroller.clientWidth + d.scrollbarH.clientWidth) + "px";
346
- } else {
347
- d.scrollbarH.style.display = "";
348
- d.scrollbarH.firstChild.style.width = "0";
349
- }
350
- if (needsH && needsV) {
351
- d.scrollbarFiller.style.display = "block";
352
- d.scrollbarFiller.style.height = d.scrollbarFiller.style.width = scrollbarWidth(d.measure) + "px";
353
- } else d.scrollbarFiller.style.display = "";
354
- if (needsH && cm.options.coverGutterNextToScrollbar && cm.options.fixedGutter) {
355
- d.gutterFiller.style.display = "block";
356
- d.gutterFiller.style.height = scrollbarWidth(d.measure) + "px";
357
- d.gutterFiller.style.width = d.gutters.offsetWidth + "px";
358
- } else d.gutterFiller.style.display = "";
359
-
360
- if (mac_geLion && scrollbarWidth(d.measure) === 0)
361
- d.scrollbarV.style.minWidth = d.scrollbarH.style.minHeight = mac_geMountainLion ? "18px" : "12px";
362
- }
363
-
364
- function visibleLines(display, doc, viewPort) {
365
- var top = display.scroller.scrollTop, height = display.wrapper.clientHeight;
366
- if (typeof viewPort == "number") top = viewPort;
367
- else if (viewPort) {top = viewPort.top; height = viewPort.bottom - viewPort.top;}
368
- top = Math.floor(top - paddingTop(display));
369
- var bottom = Math.ceil(top + height);
370
- return {from: lineAtHeight(doc, top), to: lineAtHeight(doc, bottom)};
371
- }
372
-
373
- // LINE NUMBERS
374
-
375
- function alignHorizontally(cm) {
376
- var display = cm.display;
377
- if (!display.alignWidgets && (!display.gutters.firstChild || !cm.options.fixedGutter)) return;
378
- var comp = compensateForHScroll(display) - display.scroller.scrollLeft + cm.doc.scrollLeft;
379
- var gutterW = display.gutters.offsetWidth, l = comp + "px";
380
- for (var n = display.lineDiv.firstChild; n; n = n.nextSibling) if (n.alignable) {
381
- for (var i = 0, a = n.alignable; i < a.length; ++i) a[i].style.left = l;
382
- }
383
- if (cm.options.fixedGutter)
384
- display.gutters.style.left = (comp + gutterW) + "px";
385
- }
386
-
387
- function maybeUpdateLineNumberWidth(cm) {
388
- if (!cm.options.lineNumbers) return false;
389
- var doc = cm.doc, last = lineNumberFor(cm.options, doc.first + doc.size - 1), display = cm.display;
390
- if (last.length != display.lineNumChars) {
391
- var test = display.measure.appendChild(elt("div", [elt("div", last)],
392
- "CodeMirror-linenumber CodeMirror-gutter-elt"));
393
- var innerW = test.firstChild.offsetWidth, padding = test.offsetWidth - innerW;
394
- display.lineGutter.style.width = "";
395
- display.lineNumInnerWidth = Math.max(innerW, display.lineGutter.offsetWidth - padding);
396
- display.lineNumWidth = display.lineNumInnerWidth + padding;
397
- display.lineNumChars = display.lineNumInnerWidth ? last.length : -1;
398
- display.lineGutter.style.width = display.lineNumWidth + "px";
399
- return true;
400
- }
401
- return false;
402
- }
403
-
404
- function lineNumberFor(options, i) {
405
- return String(options.lineNumberFormatter(i + options.firstLineNumber));
406
- }
407
- function compensateForHScroll(display) {
408
- return getRect(display.scroller).left - getRect(display.sizer).left;
409
- }
410
-
411
- // DISPLAY DRAWING
412
-
413
- function updateDisplay(cm, changes, viewPort, forced) {
414
- var oldFrom = cm.display.showingFrom, oldTo = cm.display.showingTo, updated;
415
- var visible = visibleLines(cm.display, cm.doc, viewPort);
416
- for (;;) {
417
- if (!updateDisplayInner(cm, changes, visible, forced)) break;
418
- forced = false;
419
- updated = true;
420
- updateSelection(cm);
421
- updateScrollbars(cm);
422
-
423
- // Clip forced viewport to actual scrollable area
424
- if (viewPort)
425
- viewPort = Math.min(cm.display.scroller.scrollHeight - cm.display.scroller.clientHeight,
426
- typeof viewPort == "number" ? viewPort : viewPort.top);
427
- visible = visibleLines(cm.display, cm.doc, viewPort);
428
- if (visible.from >= cm.display.showingFrom && visible.to <= cm.display.showingTo)
429
- break;
430
- changes = [];
431
- }
432
-
433
- if (updated) {
434
- signalLater(cm, "update", cm);
435
- if (cm.display.showingFrom != oldFrom || cm.display.showingTo != oldTo)
436
- signalLater(cm, "viewportChange", cm, cm.display.showingFrom, cm.display.showingTo);
437
- }
438
- return updated;
439
- }
440
-
441
- // Uses a set of changes plus the current scroll position to
442
- // determine which DOM updates have to be made, and makes the
443
- // updates.
444
- function updateDisplayInner(cm, changes, visible, forced) {
445
- var display = cm.display, doc = cm.doc;
446
- if (!display.wrapper.clientWidth) {
447
- display.showingFrom = display.showingTo = doc.first;
448
- display.viewOffset = 0;
449
- return;
450
- }
451
-
452
- // Bail out if the visible area is already rendered and nothing changed.
453
- if (!forced && changes.length == 0 &&
454
- visible.from > display.showingFrom && visible.to < display.showingTo)
455
- return;
456
-
457
- if (maybeUpdateLineNumberWidth(cm))
458
- changes = [{from: doc.first, to: doc.first + doc.size}];
459
- var gutterW = display.sizer.style.marginLeft = display.gutters.offsetWidth + "px";
460
- display.scrollbarH.style.left = cm.options.fixedGutter ? gutterW : "0";
461
-
462
- // Used to determine which lines need their line numbers updated
463
- var positionsChangedFrom = Infinity;
464
- if (cm.options.lineNumbers)
465
- for (var i = 0; i < changes.length; ++i)
466
- if (changes[i].diff && changes[i].from < positionsChangedFrom) { positionsChangedFrom = changes[i].from; }
467
-
468
- var end = doc.first + doc.size;
469
- var from = Math.max(visible.from - cm.options.viewportMargin, doc.first);
470
- var to = Math.min(end, visible.to + cm.options.viewportMargin);
471
- if (display.showingFrom < from && from - display.showingFrom < 20) from = Math.max(doc.first, display.showingFrom);
472
- if (display.showingTo > to && display.showingTo - to < 20) to = Math.min(end, display.showingTo);
473
- if (sawCollapsedSpans) {
474
- from = lineNo(visualLine(doc, getLine(doc, from)));
475
- while (to < end && lineIsHidden(doc, getLine(doc, to))) ++to;
476
- }
477
-
478
- // Create a range of theoretically intact lines, and punch holes
479
- // in that using the change info.
480
- var intact = [{from: Math.max(display.showingFrom, doc.first),
481
- to: Math.min(display.showingTo, end)}];
482
- if (intact[0].from >= intact[0].to) intact = [];
483
- else intact = computeIntact(intact, changes);
484
- // When merged lines are present, we might have to reduce the
485
- // intact ranges because changes in continued fragments of the
486
- // intact lines do require the lines to be redrawn.
487
- if (sawCollapsedSpans)
488
- for (var i = 0; i < intact.length; ++i) {
489
- var range = intact[i], merged;
490
- while (merged = collapsedSpanAtEnd(getLine(doc, range.to - 1))) {
491
- var newTo = merged.find().from.line;
492
- if (newTo > range.from) range.to = newTo;
493
- else { intact.splice(i--, 1); break; }
494
- }
495
- }
496
-
497
- // Clip off the parts that won't be visible
498
- var intactLines = 0;
499
- for (var i = 0; i < intact.length; ++i) {
500
- var range = intact[i];
501
- if (range.from < from) range.from = from;
502
- if (range.to > to) range.to = to;
503
- if (range.from >= range.to) intact.splice(i--, 1);
504
- else intactLines += range.to - range.from;
505
- }
506
- if (!forced && intactLines == to - from && from == display.showingFrom && to == display.showingTo) {
507
- updateViewOffset(cm);
508
- return;
509
- }
510
- intact.sort(function(a, b) {return a.from - b.from;});
511
-
512
- // Avoid crashing on IE's "unspecified error" when in iframes
513
- try {
514
- var focused = document.activeElement;
515
- } catch(e) {}
516
- if (intactLines < (to - from) * .7) display.lineDiv.style.display = "none";
517
- patchDisplay(cm, from, to, intact, positionsChangedFrom);
518
- display.lineDiv.style.display = "";
519
- if (focused && document.activeElement != focused && focused.offsetHeight) focused.focus();
520
-
521
- var different = from != display.showingFrom || to != display.showingTo ||
522
- display.lastSizeC != display.wrapper.clientHeight;
523
- // This is just a bogus formula that detects when the editor is
524
- // resized or the font size changes.
525
- if (different) {
526
- display.lastSizeC = display.wrapper.clientHeight;
527
- startWorker(cm, 400);
528
- }
529
- display.showingFrom = from; display.showingTo = to;
530
-
531
- updateHeightsInViewport(cm);
532
- updateViewOffset(cm);
533
-
534
- return true;
535
- }
536
-
537
- function updateHeightsInViewport(cm) {
538
- var display = cm.display;
539
- var prevBottom = display.lineDiv.offsetTop;
540
- for (var node = display.lineDiv.firstChild, height; node; node = node.nextSibling) if (node.lineObj) {
541
- if (ie_lt8) {
542
- var bot = node.offsetTop + node.offsetHeight;
543
- height = bot - prevBottom;
544
- prevBottom = bot;
545
- } else {
546
- var box = getRect(node);
547
- height = box.bottom - box.top;
548
- }
549
- var diff = node.lineObj.height - height;
550
- if (height < 2) height = textHeight(display);
551
- if (diff > .001 || diff < -.001) {
552
- updateLineHeight(node.lineObj, height);
553
- var widgets = node.lineObj.widgets;
554
- if (widgets) for (var i = 0; i < widgets.length; ++i)
555
- widgets[i].height = widgets[i].node.offsetHeight;
556
- }
557
- }
558
- }
559
-
560
- function updateViewOffset(cm) {
561
- var off = cm.display.viewOffset = heightAtLine(cm, getLine(cm.doc, cm.display.showingFrom));
562
- // Position the mover div to align with the current virtual scroll position
563
- cm.display.mover.style.top = off + "px";
564
- }
565
-
566
- function computeIntact(intact, changes) {
567
- for (var i = 0, l = changes.length || 0; i < l; ++i) {
568
- var change = changes[i], intact2 = [], diff = change.diff || 0;
569
- for (var j = 0, l2 = intact.length; j < l2; ++j) {
570
- var range = intact[j];
571
- if (change.to <= range.from && change.diff) {
572
- intact2.push({from: range.from + diff, to: range.to + diff});
573
- } else if (change.to <= range.from || change.from >= range.to) {
574
- intact2.push(range);
575
- } else {
576
- if (change.from > range.from)
577
- intact2.push({from: range.from, to: change.from});
578
- if (change.to < range.to)
579
- intact2.push({from: change.to + diff, to: range.to + diff});
580
- }
581
- }
582
- intact = intact2;
583
- }
584
- return intact;
585
- }
586
-
587
- function getDimensions(cm) {
588
- var d = cm.display, left = {}, width = {};
589
- for (var n = d.gutters.firstChild, i = 0; n; n = n.nextSibling, ++i) {
590
- left[cm.options.gutters[i]] = n.offsetLeft;
591
- width[cm.options.gutters[i]] = n.offsetWidth;
592
- }
593
- return {fixedPos: compensateForHScroll(d),
594
- gutterTotalWidth: d.gutters.offsetWidth,
595
- gutterLeft: left,
596
- gutterWidth: width,
597
- wrapperWidth: d.wrapper.clientWidth};
598
- }
599
-
600
- function patchDisplay(cm, from, to, intact, updateNumbersFrom) {
601
- var dims = getDimensions(cm);
602
- var display = cm.display, lineNumbers = cm.options.lineNumbers;
603
- if (!intact.length && (!webkit || !cm.display.currentWheelTarget))
604
- removeChildren(display.lineDiv);
605
- var container = display.lineDiv, cur = container.firstChild;
606
-
607
- function rm(node) {
608
- var next = node.nextSibling;
609
- if (webkit && mac && cm.display.currentWheelTarget == node) {
610
- node.style.display = "none";
611
- node.lineObj = null;
612
- } else {
613
- node.parentNode.removeChild(node);
614
- }
615
- return next;
616
- }
617
-
618
- var nextIntact = intact.shift(), lineN = from;
619
- cm.doc.iter(from, to, function(line) {
620
- if (nextIntact && nextIntact.to == lineN) nextIntact = intact.shift();
621
- if (lineIsHidden(cm.doc, line)) {
622
- if (line.height != 0) updateLineHeight(line, 0);
623
- if (line.widgets && cur && cur.previousSibling) for (var i = 0; i < line.widgets.length; ++i) {
624
- var w = line.widgets[i];
625
- if (w.showIfHidden) {
626
- var prev = cur.previousSibling;
627
- if (/pre/i.test(prev.nodeName)) {
628
- var wrap = elt("div", null, null, "position: relative");
629
- prev.parentNode.replaceChild(wrap, prev);
630
- wrap.appendChild(prev);
631
- prev = wrap;
632
- }
633
- var wnode = prev.appendChild(elt("div", [w.node], "CodeMirror-linewidget"));
634
- if (!w.handleMouseEvents) wnode.ignoreEvents = true;
635
- positionLineWidget(w, wnode, prev, dims);
636
- }
637
- }
638
- } else if (nextIntact && nextIntact.from <= lineN && nextIntact.to > lineN) {
639
- // This line is intact. Skip to the actual node. Update its
640
- // line number if needed.
641
- while (cur.lineObj != line) cur = rm(cur);
642
- if (lineNumbers && updateNumbersFrom <= lineN && cur.lineNumber)
643
- setTextContent(cur.lineNumber, lineNumberFor(cm.options, lineN));
644
- cur = cur.nextSibling;
645
- } else {
646
- // For lines with widgets, make an attempt to find and reuse
647
- // the existing element, so that widgets aren't needlessly
648
- // removed and re-inserted into the dom
649
- if (line.widgets) for (var j = 0, search = cur, reuse; search && j < 20; ++j, search = search.nextSibling)
650
- if (search.lineObj == line && /div/i.test(search.nodeName)) { reuse = search; break; }
651
- // This line needs to be generated.
652
- var lineNode = buildLineElement(cm, line, lineN, dims, reuse);
653
- if (lineNode != reuse) {
654
- container.insertBefore(lineNode, cur);
655
- } else {
656
- while (cur != reuse) cur = rm(cur);
657
- cur = cur.nextSibling;
658
- }
659
-
660
- lineNode.lineObj = line;
661
- }
662
- ++lineN;
663
- });
664
- while (cur) cur = rm(cur);
665
- }
666
-
667
- function buildLineElement(cm, line, lineNo, dims, reuse) {
668
- var lineElement = lineContent(cm, line);
669
- var markers = line.gutterMarkers, display = cm.display, wrap;
670
-
671
- if (!cm.options.lineNumbers && !markers && !line.bgClass && !line.wrapClass && !line.widgets)
672
- return lineElement;
673
-
674
- // Lines with gutter elements, widgets or a background class need
675
- // to be wrapped again, and have the extra elements added to the
676
- // wrapper div
677
-
678
- if (reuse) {
679
- reuse.alignable = null;
680
- var isOk = true, widgetsSeen = 0, insertBefore = null;
681
- for (var n = reuse.firstChild, next; n; n = next) {
682
- next = n.nextSibling;
683
- if (!/\bCodeMirror-linewidget\b/.test(n.className)) {
684
- reuse.removeChild(n);
685
- } else {
686
- for (var i = 0; i < line.widgets.length; ++i) {
687
- var widget = line.widgets[i];
688
- if (widget.node == n.firstChild) {
689
- if (!widget.above && !insertBefore) insertBefore = n;
690
- positionLineWidget(widget, n, reuse, dims);
691
- ++widgetsSeen;
692
- break;
693
- }
694
- }
695
- if (i == line.widgets.length) { isOk = false; break; }
696
- }
697
- }
698
- reuse.insertBefore(lineElement, insertBefore);
699
- if (isOk && widgetsSeen == line.widgets.length) {
700
- wrap = reuse;
701
- reuse.className = line.wrapClass || "";
702
- }
703
- }
704
- if (!wrap) {
705
- wrap = elt("div", null, line.wrapClass, "position: relative");
706
- wrap.appendChild(lineElement);
707
- }
708
- // Kludge to make sure the styled element lies behind the selection (by z-index)
709
- if (line.bgClass)
710
- wrap.insertBefore(elt("div", null, line.bgClass + " CodeMirror-linebackground"), wrap.firstChild);
711
- if (cm.options.lineNumbers || markers) {
712
- var gutterWrap = wrap.insertBefore(elt("div", null, null, "position: absolute; left: " +
713
- (cm.options.fixedGutter ? dims.fixedPos : -dims.gutterTotalWidth) + "px"),
714
- wrap.firstChild);
715
- if (cm.options.fixedGutter) (wrap.alignable || (wrap.alignable = [])).push(gutterWrap);
716
- if (cm.options.lineNumbers && (!markers || !markers["CodeMirror-linenumbers"]))
717
- wrap.lineNumber = gutterWrap.appendChild(
718
- elt("div", lineNumberFor(cm.options, lineNo),
719
- "CodeMirror-linenumber CodeMirror-gutter-elt",
720
- "left: " + dims.gutterLeft["CodeMirror-linenumbers"] + "px; width: "
721
- + display.lineNumInnerWidth + "px"));
722
- if (markers)
723
- for (var k = 0; k < cm.options.gutters.length; ++k) {
724
- var id = cm.options.gutters[k], found = markers.hasOwnProperty(id) && markers[id];
725
- if (found)
726
- gutterWrap.appendChild(elt("div", [found], "CodeMirror-gutter-elt", "left: " +
727
- dims.gutterLeft[id] + "px; width: " + dims.gutterWidth[id] + "px"));
728
- }
729
- }
730
- if (ie_lt8) wrap.style.zIndex = 2;
731
- if (line.widgets && wrap != reuse) for (var i = 0, ws = line.widgets; i < ws.length; ++i) {
732
- var widget = ws[i], node = elt("div", [widget.node], "CodeMirror-linewidget");
733
- if (!widget.handleMouseEvents) node.ignoreEvents = true;
734
- positionLineWidget(widget, node, wrap, dims);
735
- if (widget.above)
736
- wrap.insertBefore(node, cm.options.lineNumbers && line.height != 0 ? gutterWrap : lineElement);
737
- else
738
- wrap.appendChild(node);
739
- signalLater(widget, "redraw");
740
- }
741
- return wrap;
742
- }
743
-
744
- function positionLineWidget(widget, node, wrap, dims) {
745
- if (widget.noHScroll) {
746
- (wrap.alignable || (wrap.alignable = [])).push(node);
747
- var width = dims.wrapperWidth;
748
- node.style.left = dims.fixedPos + "px";
749
- if (!widget.coverGutter) {
750
- width -= dims.gutterTotalWidth;
751
- node.style.paddingLeft = dims.gutterTotalWidth + "px";
752
- }
753
- node.style.width = width + "px";
754
- }
755
- if (widget.coverGutter) {
756
- node.style.zIndex = 5;
757
- node.style.position = "relative";
758
- if (!widget.noHScroll) node.style.marginLeft = -dims.gutterTotalWidth + "px";
759
- }
760
- }
761
-
762
- // SELECTION / CURSOR
763
-
764
- function updateSelection(cm) {
765
- var display = cm.display;
766
- var collapsed = posEq(cm.doc.sel.from, cm.doc.sel.to);
767
- if (collapsed || cm.options.showCursorWhenSelecting)
768
- updateSelectionCursor(cm);
769
- else
770
- display.cursor.style.display = display.otherCursor.style.display = "none";
771
- if (!collapsed)
772
- updateSelectionRange(cm);
773
- else
774
- display.selectionDiv.style.display = "none";
775
-
776
- // Move the hidden textarea near the cursor to prevent scrolling artifacts
777
- if (cm.options.moveInputWithCursor) {
778
- var headPos = cursorCoords(cm, cm.doc.sel.head, "div");
779
- var wrapOff = getRect(display.wrapper), lineOff = getRect(display.lineDiv);
780
- display.inputDiv.style.top = Math.max(0, Math.min(display.wrapper.clientHeight - 10,
781
- headPos.top + lineOff.top - wrapOff.top)) + "px";
782
- display.inputDiv.style.left = Math.max(0, Math.min(display.wrapper.clientWidth - 10,
783
- headPos.left + lineOff.left - wrapOff.left)) + "px";
784
- }
785
- }
786
-
787
- // No selection, plain cursor
788
- function updateSelectionCursor(cm) {
789
- var display = cm.display, pos = cursorCoords(cm, cm.doc.sel.head, "div");
790
- display.cursor.style.left = pos.left + "px";
791
- display.cursor.style.top = pos.top + "px";
792
- display.cursor.style.height = Math.max(0, pos.bottom - pos.top) * cm.options.cursorHeight + "px";
793
- display.cursor.style.display = "";
794
-
795
- if (pos.other) {
796
- display.otherCursor.style.display = "";
797
- display.otherCursor.style.left = pos.other.left + "px";
798
- display.otherCursor.style.top = pos.other.top + "px";
799
- display.otherCursor.style.height = (pos.other.bottom - pos.other.top) * .85 + "px";
800
- } else { display.otherCursor.style.display = "none"; }
801
- }
802
-
803
- // Highlight selection
804
- function updateSelectionRange(cm) {
805
- var display = cm.display, doc = cm.doc, sel = cm.doc.sel;
806
- var fragment = document.createDocumentFragment();
807
- var clientWidth = display.lineSpace.offsetWidth, pl = paddingLeft(cm.display);
808
-
809
- function add(left, top, width, bottom) {
810
- if (top < 0) top = 0;
811
- fragment.appendChild(elt("div", null, "CodeMirror-selected", "position: absolute; left: " + left +
812
- "px; top: " + top + "px; width: " + (width == null ? clientWidth - left : width) +
813
- "px; height: " + (bottom - top) + "px"));
814
- }
815
-
816
- function drawForLine(line, fromArg, toArg) {
817
- var lineObj = getLine(doc, line);
818
- var lineLen = lineObj.text.length;
819
- var start, end;
820
- function coords(ch, bias) {
821
- return charCoords(cm, Pos(line, ch), "div", lineObj, bias);
822
- }
823
-
824
- iterateBidiSections(getOrder(lineObj), fromArg || 0, toArg == null ? lineLen : toArg, function(from, to, dir) {
825
- var leftPos = coords(from, "left"), rightPos, left, right;
826
- if (from == to) {
827
- rightPos = leftPos;
828
- left = right = leftPos.left;
829
- } else {
830
- rightPos = coords(to - 1, "right");
831
- if (dir == "rtl") { var tmp = leftPos; leftPos = rightPos; rightPos = tmp; }
832
- left = leftPos.left;
833
- right = rightPos.right;
834
- }
835
- if (fromArg == null && from == 0) left = pl;
836
- if (rightPos.top - leftPos.top > 3) { // Different lines, draw top part
837
- add(left, leftPos.top, null, leftPos.bottom);
838
- left = pl;
839
- if (leftPos.bottom < rightPos.top) add(left, leftPos.bottom, null, rightPos.top);
840
- }
841
- if (toArg == null && to == lineLen) right = clientWidth;
842
- if (!start || leftPos.top < start.top || leftPos.top == start.top && leftPos.left < start.left)
843
- start = leftPos;
844
- if (!end || rightPos.bottom > end.bottom || rightPos.bottom == end.bottom && rightPos.right > end.right)
845
- end = rightPos;
846
- if (left < pl + 1) left = pl;
847
- add(left, rightPos.top, right - left, rightPos.bottom);
848
- });
849
- return {start: start, end: end};
850
- }
851
-
852
- if (sel.from.line == sel.to.line) {
853
- drawForLine(sel.from.line, sel.from.ch, sel.to.ch);
854
- } else {
855
- var fromLine = getLine(doc, sel.from.line), toLine = getLine(doc, sel.to.line);
856
- var singleVLine = visualLine(doc, fromLine) == visualLine(doc, toLine);
857
- var leftEnd = drawForLine(sel.from.line, sel.from.ch, singleVLine ? fromLine.text.length : null).end;
858
- var rightStart = drawForLine(sel.to.line, singleVLine ? 0 : null, sel.to.ch).start;
859
- if (singleVLine) {
860
- if (leftEnd.top < rightStart.top - 2) {
861
- add(leftEnd.right, leftEnd.top, null, leftEnd.bottom);
862
- add(pl, rightStart.top, rightStart.left, rightStart.bottom);
863
- } else {
864
- add(leftEnd.right, leftEnd.top, rightStart.left - leftEnd.right, leftEnd.bottom);
865
- }
866
- }
867
- if (leftEnd.bottom < rightStart.top)
868
- add(pl, leftEnd.bottom, null, rightStart.top);
869
- }
870
-
871
- removeChildrenAndAdd(display.selectionDiv, fragment);
872
- display.selectionDiv.style.display = "";
873
- }
874
-
875
- // Cursor-blinking
876
- function restartBlink(cm) {
877
- if (!cm.state.focused) return;
878
- var display = cm.display;
879
- clearInterval(display.blinker);
880
- var on = true;
881
- display.cursor.style.visibility = display.otherCursor.style.visibility = "";
882
- if (cm.options.cursorBlinkRate > 0)
883
- display.blinker = setInterval(function() {
884
- display.cursor.style.visibility = display.otherCursor.style.visibility = (on = !on) ? "" : "hidden";
885
- }, cm.options.cursorBlinkRate);
886
- }
887
-
888
- // HIGHLIGHT WORKER
889
-
890
- function startWorker(cm, time) {
891
- if (cm.doc.mode.startState && cm.doc.frontier < cm.display.showingTo)
892
- cm.state.highlight.set(time, bind(highlightWorker, cm));
893
- }
894
-
895
- function highlightWorker(cm) {
896
- var doc = cm.doc;
897
- if (doc.frontier < doc.first) doc.frontier = doc.first;
898
- if (doc.frontier >= cm.display.showingTo) return;
899
- var end = +new Date + cm.options.workTime;
900
- var state = copyState(doc.mode, getStateBefore(cm, doc.frontier));
901
- var changed = [], prevChange;
902
- doc.iter(doc.frontier, Math.min(doc.first + doc.size, cm.display.showingTo + 500), function(line) {
903
- if (doc.frontier >= cm.display.showingFrom) { // Visible
904
- var oldStyles = line.styles;
905
- line.styles = highlightLine(cm, line, state);
906
- var ischange = !oldStyles || oldStyles.length != line.styles.length;
907
- for (var i = 0; !ischange && i < oldStyles.length; ++i) ischange = oldStyles[i] != line.styles[i];
908
- if (ischange) {
909
- if (prevChange && prevChange.end == doc.frontier) prevChange.end++;
910
- else changed.push(prevChange = {start: doc.frontier, end: doc.frontier + 1});
911
- }
912
- line.stateAfter = copyState(doc.mode, state);
913
- } else {
914
- processLine(cm, line, state);
915
- line.stateAfter = doc.frontier % 5 == 0 ? copyState(doc.mode, state) : null;
916
- }
917
- ++doc.frontier;
918
- if (+new Date > end) {
919
- startWorker(cm, cm.options.workDelay);
920
- return true;
921
- }
922
- });
923
- if (changed.length)
924
- operation(cm, function() {
925
- for (var i = 0; i < changed.length; ++i)
926
- regChange(this, changed[i].start, changed[i].end);
927
- })();
928
- }
929
-
930
- // Finds the line to start with when starting a parse. Tries to
931
- // find a line with a stateAfter, so that it can start with a
932
- // valid state. If that fails, it returns the line with the
933
- // smallest indentation, which tends to need the least context to
934
- // parse correctly.
935
- function findStartLine(cm, n, precise) {
936
- var minindent, minline, doc = cm.doc, maxScan = cm.doc.mode.innerMode ? 1000 : 100;
937
- for (var search = n, lim = n - maxScan; search > lim; --search) {
938
- if (search <= doc.first) return doc.first;
939
- var line = getLine(doc, search - 1);
940
- if (line.stateAfter && (!precise || search <= doc.frontier)) return search;
941
- var indented = countColumn(line.text, null, cm.options.tabSize);
942
- if (minline == null || minindent > indented) {
943
- minline = search - 1;
944
- minindent = indented;
945
- }
946
- }
947
- return minline;
948
- }
949
-
950
- function getStateBefore(cm, n, precise) {
951
- var doc = cm.doc, display = cm.display;
952
- if (!doc.mode.startState) return true;
953
- var pos = findStartLine(cm, n, precise), state = pos > doc.first && getLine(doc, pos-1).stateAfter;
954
- if (!state) state = startState(doc.mode);
955
- else state = copyState(doc.mode, state);
956
- doc.iter(pos, n, function(line) {
957
- processLine(cm, line, state);
958
- var save = pos == n - 1 || pos % 5 == 0 || pos >= display.showingFrom && pos < display.showingTo;
959
- line.stateAfter = save ? copyState(doc.mode, state) : null;
960
- ++pos;
961
- });
962
- return state;
963
- }
964
-
965
- // POSITION MEASUREMENT
966
-
967
- function paddingTop(display) {return display.lineSpace.offsetTop;}
968
- function paddingVert(display) {return display.mover.offsetHeight - display.lineSpace.offsetHeight;}
969
- function paddingLeft(display) {
970
- var e = removeChildrenAndAdd(display.measure, elt("pre", null, null, "text-align: left")).appendChild(elt("span", "x"));
971
- return e.offsetLeft;
972
- }
973
-
974
- function measureChar(cm, line, ch, data, bias) {
975
- var dir = -1;
976
- data = data || measureLine(cm, line);
977
-
978
- for (var pos = ch;; pos += dir) {
979
- var r = data[pos];
980
- if (r) break;
981
- if (dir < 0 && pos == 0) dir = 1;
982
- }
983
- bias = pos > ch ? "left" : pos < ch ? "right" : bias;
984
- if (bias == "left" && r.leftSide) r = r.leftSide;
985
- else if (bias == "right" && r.rightSide) r = r.rightSide;
986
- return {left: pos < ch ? r.right : r.left,
987
- right: pos > ch ? r.left : r.right,
988
- top: r.top,
989
- bottom: r.bottom};
990
- }
991
-
992
- function findCachedMeasurement(cm, line) {
993
- var cache = cm.display.measureLineCache;
994
- for (var i = 0; i < cache.length; ++i) {
995
- var memo = cache[i];
996
- if (memo.text == line.text && memo.markedSpans == line.markedSpans &&
997
- cm.display.scroller.clientWidth == memo.width &&
998
- memo.classes == line.textClass + "|" + line.bgClass + "|" + line.wrapClass)
999
- return memo;
1000
- }
1001
- }
1002
-
1003
- function clearCachedMeasurement(cm, line) {
1004
- var exists = findCachedMeasurement(cm, line);
1005
- if (exists) exists.text = exists.measure = exists.markedSpans = null;
1006
- }
1007
-
1008
- function measureLine(cm, line) {
1009
- // First look in the cache
1010
- var cached = findCachedMeasurement(cm, line);
1011
- if (cached) return cached.measure;
1012
-
1013
- // Failing that, recompute and store result in cache
1014
- var measure = measureLineInner(cm, line);
1015
- var cache = cm.display.measureLineCache;
1016
- var memo = {text: line.text, width: cm.display.scroller.clientWidth,
1017
- markedSpans: line.markedSpans, measure: measure,
1018
- classes: line.textClass + "|" + line.bgClass + "|" + line.wrapClass};
1019
- if (cache.length == 16) cache[++cm.display.measureLineCachePos % 16] = memo;
1020
- else cache.push(memo);
1021
- return measure;
1022
- }
1023
-
1024
- function measureLineInner(cm, line) {
1025
- var display = cm.display, measure = emptyArray(line.text.length);
1026
- var pre = lineContent(cm, line, measure, true);
1027
-
1028
- // IE does not cache element positions of inline elements between
1029
- // calls to getBoundingClientRect. This makes the loop below,
1030
- // which gathers the positions of all the characters on the line,
1031
- // do an amount of layout work quadratic to the number of
1032
- // characters. When line wrapping is off, we try to improve things
1033
- // by first subdividing the line into a bunch of inline blocks, so
1034
- // that IE can reuse most of the layout information from caches
1035
- // for those blocks. This does interfere with line wrapping, so it
1036
- // doesn't work when wrapping is on, but in that case the
1037
- // situation is slightly better, since IE does cache line-wrapping
1038
- // information and only recomputes per-line.
1039
- if (ie && !ie_lt8 && !cm.options.lineWrapping && pre.childNodes.length > 100) {
1040
- var fragment = document.createDocumentFragment();
1041
- var chunk = 10, n = pre.childNodes.length;
1042
- for (var i = 0, chunks = Math.ceil(n / chunk); i < chunks; ++i) {
1043
- var wrap = elt("div", null, null, "display: inline-block");
1044
- for (var j = 0; j < chunk && n; ++j) {
1045
- wrap.appendChild(pre.firstChild);
1046
- --n;
1047
- }
1048
- fragment.appendChild(wrap);
1049
- }
1050
- pre.appendChild(fragment);
1051
- }
1052
-
1053
- removeChildrenAndAdd(display.measure, pre);
1054
-
1055
- var outer = getRect(display.lineDiv);
1056
- var vranges = [], data = emptyArray(line.text.length), maxBot = pre.offsetHeight;
1057
- // Work around an IE7/8 bug where it will sometimes have randomly
1058
- // replaced our pre with a clone at this point.
1059
- if (ie_lt9 && display.measure.first != pre)
1060
- removeChildrenAndAdd(display.measure, pre);
1061
-
1062
- function measureRect(rect) {
1063
- var top = rect.top - outer.top, bot = rect.bottom - outer.top;
1064
- if (bot > maxBot) bot = maxBot;
1065
- if (top < 0) top = 0;
1066
- for (var i = vranges.length - 2; i >= 0; i -= 2) {
1067
- var rtop = vranges[i], rbot = vranges[i+1];
1068
- if (rtop > bot || rbot < top) continue;
1069
- if (rtop <= top && rbot >= bot ||
1070
- top <= rtop && bot >= rbot ||
1071
- Math.min(bot, rbot) - Math.max(top, rtop) >= (bot - top) >> 1) {
1072
- vranges[i] = Math.min(top, rtop);
1073
- vranges[i+1] = Math.max(bot, rbot);
1074
- break;
1075
- }
1076
- }
1077
- if (i < 0) { i = vranges.length; vranges.push(top, bot); }
1078
- return {left: rect.left - outer.left,
1079
- right: rect.right - outer.left,
1080
- top: i, bottom: null};
1081
- }
1082
- function finishRect(rect) {
1083
- rect.bottom = vranges[rect.top+1];
1084
- rect.top = vranges[rect.top];
1085
- }
1086
-
1087
- for (var i = 0, cur; i < measure.length; ++i) if (cur = measure[i]) {
1088
- var node = cur, rect = null;
1089
- // A widget might wrap, needs special care
1090
- if (/\bCodeMirror-widget\b/.test(cur.className) && cur.getClientRects) {
1091
- if (cur.firstChild.nodeType == 1) node = cur.firstChild;
1092
- var rects = node.getClientRects();
1093
- if (rects.length > 1) {
1094
- rect = data[i] = measureRect(rects[0]);
1095
- rect.rightSide = measureRect(rects[rects.length - 1]);
1096
- }
1097
- }
1098
- if (!rect) rect = data[i] = measureRect(getRect(node));
1099
- if (cur.measureRight) rect.right = getRect(cur.measureRight).left;
1100
- if (cur.leftSide) rect.leftSide = measureRect(getRect(cur.leftSide));
1101
- }
1102
- removeChildren(cm.display.measure);
1103
- for (var i = 0, cur; i < data.length; ++i) if (cur = data[i]) {
1104
- finishRect(cur);
1105
- if (cur.leftSide) finishRect(cur.leftSide);
1106
- if (cur.rightSide) finishRect(cur.rightSide);
1107
- }
1108
- return data;
1109
- }
1110
-
1111
- function measureLineWidth(cm, line) {
1112
- var hasBadSpan = false;
1113
- if (line.markedSpans) for (var i = 0; i < line.markedSpans; ++i) {
1114
- var sp = line.markedSpans[i];
1115
- if (sp.collapsed && (sp.to == null || sp.to == line.text.length)) hasBadSpan = true;
1116
- }
1117
- var cached = !hasBadSpan && findCachedMeasurement(cm, line);
1118
- if (cached) return measureChar(cm, line, line.text.length, cached.measure, "right").right;
1119
-
1120
- var pre = lineContent(cm, line, null, true);
1121
- var end = pre.appendChild(zeroWidthElement(cm.display.measure));
1122
- removeChildrenAndAdd(cm.display.measure, pre);
1123
- return getRect(end).right - getRect(cm.display.lineDiv).left;
1124
- }
1125
-
1126
- function clearCaches(cm) {
1127
- cm.display.measureLineCache.length = cm.display.measureLineCachePos = 0;
1128
- cm.display.cachedCharWidth = cm.display.cachedTextHeight = null;
1129
- if (!cm.options.lineWrapping) cm.display.maxLineChanged = true;
1130
- cm.display.lineNumChars = null;
1131
- }
1132
-
1133
- function pageScrollX() { return window.pageXOffset || (document.documentElement || document.body).scrollLeft; }
1134
- function pageScrollY() { return window.pageYOffset || (document.documentElement || document.body).scrollTop; }
1135
-
1136
- // Context is one of "line", "div" (display.lineDiv), "local"/null (editor), or "page"
1137
- function intoCoordSystem(cm, lineObj, rect, context) {
1138
- if (lineObj.widgets) for (var i = 0; i < lineObj.widgets.length; ++i) if (lineObj.widgets[i].above) {
1139
- var size = widgetHeight(lineObj.widgets[i]);
1140
- rect.top += size; rect.bottom += size;
1141
- }
1142
- if (context == "line") return rect;
1143
- if (!context) context = "local";
1144
- var yOff = heightAtLine(cm, lineObj);
1145
- if (context == "local") yOff += paddingTop(cm.display);
1146
- else yOff -= cm.display.viewOffset;
1147
- if (context == "page" || context == "window") {
1148
- var lOff = getRect(cm.display.lineSpace);
1149
- yOff += lOff.top + (context == "window" ? 0 : pageScrollY());
1150
- var xOff = lOff.left + (context == "window" ? 0 : pageScrollX());
1151
- rect.left += xOff; rect.right += xOff;
1152
- }
1153
- rect.top += yOff; rect.bottom += yOff;
1154
- return rect;
1155
- }
1156
-
1157
- // Context may be "window", "page", "div", or "local"/null
1158
- // Result is in "div" coords
1159
- function fromCoordSystem(cm, coords, context) {
1160
- if (context == "div") return coords;
1161
- var left = coords.left, top = coords.top;
1162
- // First move into "page" coordinate system
1163
- if (context == "page") {
1164
- left -= pageScrollX();
1165
- top -= pageScrollY();
1166
- } else if (context == "local" || !context) {
1167
- var localBox = getRect(cm.display.sizer);
1168
- left += localBox.left;
1169
- top += localBox.top;
1170
- }
1171
-
1172
- var lineSpaceBox = getRect(cm.display.lineSpace);
1173
- return {left: left - lineSpaceBox.left, top: top - lineSpaceBox.top};
1174
- }
1175
-
1176
- function charCoords(cm, pos, context, lineObj, bias) {
1177
- if (!lineObj) lineObj = getLine(cm.doc, pos.line);
1178
- return intoCoordSystem(cm, lineObj, measureChar(cm, lineObj, pos.ch, null, bias), context);
1179
- }
1180
-
1181
- function cursorCoords(cm, pos, context, lineObj, measurement) {
1182
- lineObj = lineObj || getLine(cm.doc, pos.line);
1183
- if (!measurement) measurement = measureLine(cm, lineObj);
1184
- function get(ch, right) {
1185
- var m = measureChar(cm, lineObj, ch, measurement, right ? "right" : "left");
1186
- if (right) m.left = m.right; else m.right = m.left;
1187
- return intoCoordSystem(cm, lineObj, m, context);
1188
- }
1189
- function getBidi(ch, partPos) {
1190
- var part = order[partPos], right = part.level % 2;
1191
- if (ch == bidiLeft(part) && partPos && part.level < order[partPos - 1].level) {
1192
- part = order[--partPos];
1193
- ch = bidiRight(part) - (part.level % 2 ? 0 : 1);
1194
- right = true;
1195
- } else if (ch == bidiRight(part) && partPos < order.length - 1 && part.level < order[partPos + 1].level) {
1196
- part = order[++partPos];
1197
- ch = bidiLeft(part) - part.level % 2;
1198
- right = false;
1199
- }
1200
- if (right && ch == part.to && ch > part.from) return get(ch - 1);
1201
- return get(ch, right);
1202
- }
1203
- var order = getOrder(lineObj), ch = pos.ch;
1204
- if (!order) return get(ch);
1205
- var partPos = getBidiPartAt(order, ch);
1206
- var val = getBidi(ch, partPos);
1207
- if (bidiOther != null) val.other = getBidi(ch, bidiOther);
1208
- return val;
1209
- }
1210
-
1211
- function PosWithInfo(line, ch, outside, xRel) {
1212
- var pos = new Pos(line, ch);
1213
- pos.xRel = xRel;
1214
- if (outside) pos.outside = true;
1215
- return pos;
1216
- }
1217
-
1218
- // Coords must be lineSpace-local
1219
- function coordsChar(cm, x, y) {
1220
- var doc = cm.doc;
1221
- y += cm.display.viewOffset;
1222
- if (y < 0) return PosWithInfo(doc.first, 0, true, -1);
1223
- var lineNo = lineAtHeight(doc, y), last = doc.first + doc.size - 1;
1224
- if (lineNo > last)
1225
- return PosWithInfo(doc.first + doc.size - 1, getLine(doc, last).text.length, true, 1);
1226
- if (x < 0) x = 0;
1227
-
1228
- for (;;) {
1229
- var lineObj = getLine(doc, lineNo);
1230
- var found = coordsCharInner(cm, lineObj, lineNo, x, y);
1231
- var merged = collapsedSpanAtEnd(lineObj);
1232
- var mergedPos = merged && merged.find();
1233
- if (merged && (found.ch > mergedPos.from.ch || found.ch == mergedPos.from.ch && found.xRel > 0))
1234
- lineNo = mergedPos.to.line;
1235
- else
1236
- return found;
1237
- }
1238
- }
1239
-
1240
- function coordsCharInner(cm, lineObj, lineNo, x, y) {
1241
- var innerOff = y - heightAtLine(cm, lineObj);
1242
- var wrongLine = false, adjust = 2 * cm.display.wrapper.clientWidth;
1243
- var measurement = measureLine(cm, lineObj);
1244
-
1245
- function getX(ch) {
1246
- var sp = cursorCoords(cm, Pos(lineNo, ch), "line",
1247
- lineObj, measurement);
1248
- wrongLine = true;
1249
- if (innerOff > sp.bottom) return sp.left - adjust;
1250
- else if (innerOff < sp.top) return sp.left + adjust;
1251
- else wrongLine = false;
1252
- return sp.left;
1253
- }
1254
-
1255
- var bidi = getOrder(lineObj), dist = lineObj.text.length;
1256
- var from = lineLeft(lineObj), to = lineRight(lineObj);
1257
- var fromX = getX(from), fromOutside = wrongLine, toX = getX(to), toOutside = wrongLine;
1258
-
1259
- if (x > toX) return PosWithInfo(lineNo, to, toOutside, 1);
1260
- // Do a binary search between these bounds.
1261
- for (;;) {
1262
- if (bidi ? to == from || to == moveVisually(lineObj, from, 1) : to - from <= 1) {
1263
- var ch = x < fromX || x - fromX <= toX - x ? from : to;
1264
- var xDiff = x - (ch == from ? fromX : toX);
1265
- while (isExtendingChar.test(lineObj.text.charAt(ch))) ++ch;
1266
- var pos = PosWithInfo(lineNo, ch, ch == from ? fromOutside : toOutside,
1267
- xDiff < 0 ? -1 : xDiff ? 1 : 0);
1268
- return pos;
1269
- }
1270
- var step = Math.ceil(dist / 2), middle = from + step;
1271
- if (bidi) {
1272
- middle = from;
1273
- for (var i = 0; i < step; ++i) middle = moveVisually(lineObj, middle, 1);
1274
- }
1275
- var middleX = getX(middle);
1276
- if (middleX > x) {to = middle; toX = middleX; if (toOutside = wrongLine) toX += 1000; dist = step;}
1277
- else {from = middle; fromX = middleX; fromOutside = wrongLine; dist -= step;}
1278
- }
1279
- }
1280
-
1281
- var measureText;
1282
- function textHeight(display) {
1283
- if (display.cachedTextHeight != null) return display.cachedTextHeight;
1284
- if (measureText == null) {
1285
- measureText = elt("pre");
1286
- // Measure a bunch of lines, for browsers that compute
1287
- // fractional heights.
1288
- for (var i = 0; i < 49; ++i) {
1289
- measureText.appendChild(document.createTextNode("x"));
1290
- measureText.appendChild(elt("br"));
1291
- }
1292
- measureText.appendChild(document.createTextNode("x"));
1293
- }
1294
- removeChildrenAndAdd(display.measure, measureText);
1295
- var height = measureText.offsetHeight / 50;
1296
- if (height > 3) display.cachedTextHeight = height;
1297
- removeChildren(display.measure);
1298
- return height || 1;
1299
- }
1300
-
1301
- function charWidth(display) {
1302
- if (display.cachedCharWidth != null) return display.cachedCharWidth;
1303
- var anchor = elt("span", "x");
1304
- var pre = elt("pre", [anchor]);
1305
- removeChildrenAndAdd(display.measure, pre);
1306
- var width = anchor.offsetWidth;
1307
- if (width > 2) display.cachedCharWidth = width;
1308
- return width || 10;
1309
- }
1310
-
1311
- // OPERATIONS
1312
-
1313
- // Operations are used to wrap changes in such a way that each
1314
- // change won't have to update the cursor and display (which would
1315
- // be awkward, slow, and error-prone), but instead updates are
1316
- // batched and then all combined and executed at once.
1317
-
1318
- var nextOpId = 0;
1319
- function startOperation(cm) {
1320
- cm.curOp = {
1321
- // An array of ranges of lines that have to be updated. See
1322
- // updateDisplay.
1323
- changes: [],
1324
- forceUpdate: false,
1325
- updateInput: null,
1326
- userSelChange: null,
1327
- textChanged: null,
1328
- selectionChanged: false,
1329
- cursorActivity: false,
1330
- updateMaxLine: false,
1331
- updateScrollPos: false,
1332
- id: ++nextOpId
1333
- };
1334
- if (!delayedCallbackDepth++) delayedCallbacks = [];
1335
- }
1336
-
1337
- function endOperation(cm) {
1338
- var op = cm.curOp, doc = cm.doc, display = cm.display;
1339
- cm.curOp = null;
1340
-
1341
- if (op.updateMaxLine) computeMaxLength(cm);
1342
- if (display.maxLineChanged && !cm.options.lineWrapping && display.maxLine) {
1343
- var width = measureLineWidth(cm, display.maxLine);
1344
- display.sizer.style.minWidth = Math.max(0, width + 3 + scrollerCutOff) + "px";
1345
- display.maxLineChanged = false;
1346
- var maxScrollLeft = Math.max(0, display.sizer.offsetLeft + display.sizer.offsetWidth - display.scroller.clientWidth);
1347
- if (maxScrollLeft < doc.scrollLeft && !op.updateScrollPos)
1348
- setScrollLeft(cm, Math.min(display.scroller.scrollLeft, maxScrollLeft), true);
1349
- }
1350
- var newScrollPos, updated;
1351
- if (op.updateScrollPos) {
1352
- newScrollPos = op.updateScrollPos;
1353
- } else if (op.selectionChanged && display.scroller.clientHeight) { // don't rescroll if not visible
1354
- var coords = cursorCoords(cm, doc.sel.head);
1355
- newScrollPos = calculateScrollPos(cm, coords.left, coords.top, coords.left, coords.bottom);
1356
- }
1357
- if (op.changes.length || op.forceUpdate || newScrollPos && newScrollPos.scrollTop != null) {
1358
- updated = updateDisplay(cm, op.changes, newScrollPos && newScrollPos.scrollTop, op.forceUpdate);
1359
- if (cm.display.scroller.offsetHeight) cm.doc.scrollTop = cm.display.scroller.scrollTop;
1360
- }
1361
- if (!updated && op.selectionChanged) updateSelection(cm);
1362
- if (op.updateScrollPos) {
1363
- display.scroller.scrollTop = display.scrollbarV.scrollTop = doc.scrollTop = newScrollPos.scrollTop;
1364
- display.scroller.scrollLeft = display.scrollbarH.scrollLeft = doc.scrollLeft = newScrollPos.scrollLeft;
1365
- alignHorizontally(cm);
1366
- if (op.scrollToPos)
1367
- scrollPosIntoView(cm, clipPos(cm.doc, op.scrollToPos), op.scrollToPosMargin);
1368
- } else if (newScrollPos) {
1369
- scrollCursorIntoView(cm);
1370
- }
1371
- if (op.selectionChanged) restartBlink(cm);
1372
-
1373
- if (cm.state.focused && op.updateInput)
1374
- resetInput(cm, op.userSelChange);
1375
-
1376
- var hidden = op.maybeHiddenMarkers, unhidden = op.maybeUnhiddenMarkers;
1377
- if (hidden) for (var i = 0; i < hidden.length; ++i)
1378
- if (!hidden[i].lines.length) signal(hidden[i], "hide");
1379
- if (unhidden) for (var i = 0; i < unhidden.length; ++i)
1380
- if (unhidden[i].lines.length) signal(unhidden[i], "unhide");
1381
-
1382
- var delayed;
1383
- if (!--delayedCallbackDepth) {
1384
- delayed = delayedCallbacks;
1385
- delayedCallbacks = null;
1386
- }
1387
- if (op.textChanged)
1388
- signal(cm, "change", cm, op.textChanged);
1389
- if (op.cursorActivity) signal(cm, "cursorActivity", cm);
1390
- if (delayed) for (var i = 0; i < delayed.length; ++i) delayed[i]();
1391
- }
1392
-
1393
- // Wraps a function in an operation. Returns the wrapped function.
1394
- function operation(cm1, f) {
1395
- return function() {
1396
- var cm = cm1 || this, withOp = !cm.curOp;
1397
- if (withOp) startOperation(cm);
1398
- try { var result = f.apply(cm, arguments); }
1399
- finally { if (withOp) endOperation(cm); }
1400
- return result;
1401
- };
1402
- }
1403
- function docOperation(f) {
1404
- return function() {
1405
- var withOp = this.cm && !this.cm.curOp, result;
1406
- if (withOp) startOperation(this.cm);
1407
- try { result = f.apply(this, arguments); }
1408
- finally { if (withOp) endOperation(this.cm); }
1409
- return result;
1410
- };
1411
- }
1412
- function runInOp(cm, f) {
1413
- var withOp = !cm.curOp, result;
1414
- if (withOp) startOperation(cm);
1415
- try { result = f(); }
1416
- finally { if (withOp) endOperation(cm); }
1417
- return result;
1418
- }
1419
-
1420
- function regChange(cm, from, to, lendiff) {
1421
- if (from == null) from = cm.doc.first;
1422
- if (to == null) to = cm.doc.first + cm.doc.size;
1423
- cm.curOp.changes.push({from: from, to: to, diff: lendiff});
1424
- }
1425
-
1426
- // INPUT HANDLING
1427
-
1428
- function slowPoll(cm) {
1429
- if (cm.display.pollingFast) return;
1430
- cm.display.poll.set(cm.options.pollInterval, function() {
1431
- readInput(cm);
1432
- if (cm.state.focused) slowPoll(cm);
1433
- });
1434
- }
1435
-
1436
- function fastPoll(cm) {
1437
- var missed = false;
1438
- cm.display.pollingFast = true;
1439
- function p() {
1440
- var changed = readInput(cm);
1441
- if (!changed && !missed) {missed = true; cm.display.poll.set(60, p);}
1442
- else {cm.display.pollingFast = false; slowPoll(cm);}
1443
- }
1444
- cm.display.poll.set(20, p);
1445
- }
1446
-
1447
- // prevInput is a hack to work with IME. If we reset the textarea
1448
- // on every change, that breaks IME. So we look for changes
1449
- // compared to the previous content instead. (Modern browsers have
1450
- // events that indicate IME taking place, but these are not widely
1451
- // supported or compatible enough yet to rely on.)
1452
- function readInput(cm) {
1453
- var input = cm.display.input, prevInput = cm.display.prevInput, doc = cm.doc, sel = doc.sel;
1454
- if (!cm.state.focused || hasSelection(input) || isReadOnly(cm) || cm.state.disableInput) return false;
1455
- if (cm.state.pasteIncoming && cm.state.fakedLastChar) {
1456
- input.value = input.value.substring(0, input.value.length - 1);
1457
- cm.state.fakedLastChar = false;
1458
- }
1459
- var text = input.value;
1460
- if (text == prevInput && posEq(sel.from, sel.to)) return false;
1461
- if (ie && !ie_lt9 && cm.display.inputHasSelection === text) {
1462
- resetInput(cm, true);
1463
- return false;
1464
- }
1465
-
1466
- var withOp = !cm.curOp;
1467
- if (withOp) startOperation(cm);
1468
- sel.shift = false;
1469
- var same = 0, l = Math.min(prevInput.length, text.length);
1470
- while (same < l && prevInput.charCodeAt(same) == text.charCodeAt(same)) ++same;
1471
- var from = sel.from, to = sel.to;
1472
- if (same < prevInput.length)
1473
- from = Pos(from.line, from.ch - (prevInput.length - same));
1474
- else if (cm.state.overwrite && posEq(from, to) && !cm.state.pasteIncoming)
1475
- to = Pos(to.line, Math.min(getLine(doc, to.line).text.length, to.ch + (text.length - same)));
1476
-
1477
- var updateInput = cm.curOp.updateInput;
1478
- var changeEvent = {from: from, to: to, text: splitLines(text.slice(same)),
1479
- origin: cm.state.pasteIncoming ? "paste" : "+input"};
1480
- makeChange(cm.doc, changeEvent, "end");
1481
- cm.curOp.updateInput = updateInput;
1482
- signalLater(cm, "inputRead", cm, changeEvent);
1483
-
1484
- if (text.length > 1000 || text.indexOf("\n") > -1) input.value = cm.display.prevInput = "";
1485
- else cm.display.prevInput = text;
1486
- if (withOp) endOperation(cm);
1487
- cm.state.pasteIncoming = false;
1488
- return true;
1489
- }
1490
-
1491
- function resetInput(cm, user) {
1492
- var minimal, selected, doc = cm.doc;
1493
- if (!posEq(doc.sel.from, doc.sel.to)) {
1494
- cm.display.prevInput = "";
1495
- minimal = hasCopyEvent &&
1496
- (doc.sel.to.line - doc.sel.from.line > 100 || (selected = cm.getSelection()).length > 1000);
1497
- var content = minimal ? "-" : selected || cm.getSelection();
1498
- cm.display.input.value = content;
1499
- if (cm.state.focused) selectInput(cm.display.input);
1500
- if (ie && !ie_lt9) cm.display.inputHasSelection = content;
1501
- } else if (user) {
1502
- cm.display.prevInput = cm.display.input.value = "";
1503
- if (ie && !ie_lt9) cm.display.inputHasSelection = null;
1504
- }
1505
- cm.display.inaccurateSelection = minimal;
1506
- }
1507
-
1508
- function focusInput(cm) {
1509
- if (cm.options.readOnly != "nocursor" && (!mobile || document.activeElement != cm.display.input))
1510
- cm.display.input.focus();
1511
- }
1512
-
1513
- function isReadOnly(cm) {
1514
- return cm.options.readOnly || cm.doc.cantEdit;
1515
- }
1516
-
1517
- // EVENT HANDLERS
1518
-
1519
- function registerEventHandlers(cm) {
1520
- var d = cm.display;
1521
- on(d.scroller, "mousedown", operation(cm, onMouseDown));
1522
- if (ie)
1523
- on(d.scroller, "dblclick", operation(cm, function(e) {
1524
- if (signalDOMEvent(cm, e)) return;
1525
- var pos = posFromMouse(cm, e);
1526
- if (!pos || clickInGutter(cm, e) || eventInWidget(cm.display, e)) return;
1527
- e_preventDefault(e);
1528
- var word = findWordAt(getLine(cm.doc, pos.line).text, pos);
1529
- extendSelection(cm.doc, word.from, word.to);
1530
- }));
1531
- else
1532
- on(d.scroller, "dblclick", function(e) { signalDOMEvent(cm, e) || e_preventDefault(e); });
1533
- on(d.lineSpace, "selectstart", function(e) {
1534
- if (!eventInWidget(d, e)) e_preventDefault(e);
1535
- });
1536
- // Gecko browsers fire contextmenu *after* opening the menu, at
1537
- // which point we can't mess with it anymore. Context menu is
1538
- // handled in onMouseDown for Gecko.
1539
- if (!captureMiddleClick) on(d.scroller, "contextmenu", function(e) {onContextMenu(cm, e);});
1540
-
1541
- on(d.scroller, "scroll", function() {
1542
- if (d.scroller.clientHeight) {
1543
- setScrollTop(cm, d.scroller.scrollTop);
1544
- setScrollLeft(cm, d.scroller.scrollLeft, true);
1545
- signal(cm, "scroll", cm);
1546
- }
1547
- });
1548
- on(d.scrollbarV, "scroll", function() {
1549
- if (d.scroller.clientHeight) setScrollTop(cm, d.scrollbarV.scrollTop);
1550
- });
1551
- on(d.scrollbarH, "scroll", function() {
1552
- if (d.scroller.clientHeight) setScrollLeft(cm, d.scrollbarH.scrollLeft);
1553
- });
1554
-
1555
- on(d.scroller, "mousewheel", function(e){onScrollWheel(cm, e);});
1556
- on(d.scroller, "DOMMouseScroll", function(e){onScrollWheel(cm, e);});
1557
-
1558
- function reFocus() { if (cm.state.focused) setTimeout(bind(focusInput, cm), 0); }
1559
- on(d.scrollbarH, "mousedown", reFocus);
1560
- on(d.scrollbarV, "mousedown", reFocus);
1561
- // Prevent wrapper from ever scrolling
1562
- on(d.wrapper, "scroll", function() { d.wrapper.scrollTop = d.wrapper.scrollLeft = 0; });
1563
-
1564
- var resizeTimer;
1565
- function onResize() {
1566
- if (resizeTimer == null) resizeTimer = setTimeout(function() {
1567
- resizeTimer = null;
1568
- // Might be a text scaling operation, clear size caches.
1569
- d.cachedCharWidth = d.cachedTextHeight = knownScrollbarWidth = null;
1570
- clearCaches(cm);
1571
- runInOp(cm, bind(regChange, cm));
1572
- }, 100);
1573
- }
1574
- on(window, "resize", onResize);
1575
- // Above handler holds on to the editor and its data structures.
1576
- // Here we poll to unregister it when the editor is no longer in
1577
- // the document, so that it can be garbage-collected.
1578
- function unregister() {
1579
- for (var p = d.wrapper.parentNode; p && p != document.body; p = p.parentNode) {}
1580
- if (p) setTimeout(unregister, 5000);
1581
- else off(window, "resize", onResize);
1582
- }
1583
- setTimeout(unregister, 5000);
1584
-
1585
- on(d.input, "keyup", operation(cm, function(e) {
1586
- if (signalDOMEvent(cm, e) || cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
1587
- if (e.keyCode == 16) cm.doc.sel.shift = false;
1588
- }));
1589
- on(d.input, "input", bind(fastPoll, cm));
1590
- on(d.input, "keydown", operation(cm, onKeyDown));
1591
- on(d.input, "keypress", operation(cm, onKeyPress));
1592
- on(d.input, "focus", bind(onFocus, cm));
1593
- on(d.input, "blur", bind(onBlur, cm));
1594
-
1595
- function drag_(e) {
1596
- if (signalDOMEvent(cm, e) || cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))) return;
1597
- e_stop(e);
1598
- }
1599
- if (cm.options.dragDrop) {
1600
- on(d.scroller, "dragstart", function(e){onDragStart(cm, e);});
1601
- on(d.scroller, "dragenter", drag_);
1602
- on(d.scroller, "dragover", drag_);
1603
- on(d.scroller, "drop", operation(cm, onDrop));
1604
- }
1605
- on(d.scroller, "paste", function(e) {
1606
- if (eventInWidget(d, e)) return;
1607
- focusInput(cm);
1608
- fastPoll(cm);
1609
- });
1610
- on(d.input, "paste", function() {
1611
- // Workaround for webkit bug https://bugs.webkit.org/show_bug.cgi?id=90206
1612
- // Add a char to the end of textarea before paste occur so that
1613
- // selection doesn't span to the end of textarea.
1614
- if (webkit && !cm.state.fakedLastChar && !(new Date - cm.state.lastMiddleDown < 200)) {
1615
- var start = d.input.selectionStart, end = d.input.selectionEnd;
1616
- d.input.value += "$";
1617
- d.input.selectionStart = start;
1618
- d.input.selectionEnd = end;
1619
- cm.state.fakedLastChar = true;
1620
- }
1621
- cm.state.pasteIncoming = true;
1622
- fastPoll(cm);
1623
- });
1624
-
1625
- function prepareCopy() {
1626
- if (d.inaccurateSelection) {
1627
- d.prevInput = "";
1628
- d.inaccurateSelection = false;
1629
- d.input.value = cm.getSelection();
1630
- selectInput(d.input);
1631
- }
1632
- }
1633
- on(d.input, "cut", prepareCopy);
1634
- on(d.input, "copy", prepareCopy);
1635
-
1636
- // Needed to handle Tab key in KHTML
1637
- if (khtml) on(d.sizer, "mouseup", function() {
1638
- if (document.activeElement == d.input) d.input.blur();
1639
- focusInput(cm);
1640
- });
1641
- }
1642
-
1643
- function eventInWidget(display, e) {
1644
- for (var n = e_target(e); n != display.wrapper; n = n.parentNode) {
1645
- if (!n || n.ignoreEvents || n.parentNode == display.sizer && n != display.mover) return true;
1646
- }
1647
- }
1648
-
1649
- function posFromMouse(cm, e, liberal) {
1650
- var display = cm.display;
1651
- if (!liberal) {
1652
- var target = e_target(e);
1653
- if (target == display.scrollbarH || target == display.scrollbarH.firstChild ||
1654
- target == display.scrollbarV || target == display.scrollbarV.firstChild ||
1655
- target == display.scrollbarFiller || target == display.gutterFiller) return null;
1656
- }
1657
- var x, y, space = getRect(display.lineSpace);
1658
- // Fails unpredictably on IE[67] when mouse is dragged around quickly.
1659
- try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
1660
- return coordsChar(cm, x - space.left, y - space.top);
1661
- }
1662
-
1663
- var lastClick, lastDoubleClick;
1664
- function onMouseDown(e) {
1665
- if (signalDOMEvent(this, e)) return;
1666
- var cm = this, display = cm.display, doc = cm.doc, sel = doc.sel;
1667
- sel.shift = e.shiftKey;
1668
-
1669
- if (eventInWidget(display, e)) {
1670
- if (!webkit) {
1671
- display.scroller.draggable = false;
1672
- setTimeout(function(){display.scroller.draggable = true;}, 100);
1673
- }
1674
- return;
1675
- }
1676
- if (clickInGutter(cm, e)) return;
1677
- var start = posFromMouse(cm, e);
1678
-
1679
- switch (e_button(e)) {
1680
- case 3:
1681
- if (captureMiddleClick) onContextMenu.call(cm, cm, e);
1682
- return;
1683
- case 2:
1684
- if (webkit) cm.state.lastMiddleDown = +new Date;
1685
- if (start) extendSelection(cm.doc, start);
1686
- setTimeout(bind(focusInput, cm), 20);
1687
- e_preventDefault(e);
1688
- return;
1689
- }
1690
- // For button 1, if it was clicked inside the editor
1691
- // (posFromMouse returning non-null), we have to adjust the
1692
- // selection.
1693
- if (!start) {if (e_target(e) == display.scroller) e_preventDefault(e); return;}
1694
-
1695
- if (!cm.state.focused) onFocus(cm);
1696
-
1697
- var now = +new Date, type = "single";
1698
- if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
1699
- type = "triple";
1700
- e_preventDefault(e);
1701
- setTimeout(bind(focusInput, cm), 20);
1702
- selectLine(cm, start.line);
1703
- } else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
1704
- type = "double";
1705
- lastDoubleClick = {time: now, pos: start};
1706
- e_preventDefault(e);
1707
- var word = findWordAt(getLine(doc, start.line).text, start);
1708
- extendSelection(cm.doc, word.from, word.to);
1709
- } else { lastClick = {time: now, pos: start}; }
1710
-
1711
- var last = start;
1712
- if (cm.options.dragDrop && dragAndDrop && !isReadOnly(cm) && !posEq(sel.from, sel.to) &&
1713
- !posLess(start, sel.from) && !posLess(sel.to, start) && type == "single") {
1714
- var dragEnd = operation(cm, function(e2) {
1715
- if (webkit) display.scroller.draggable = false;
1716
- cm.state.draggingText = false;
1717
- off(document, "mouseup", dragEnd);
1718
- off(display.scroller, "drop", dragEnd);
1719
- if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
1720
- e_preventDefault(e2);
1721
- extendSelection(cm.doc, start);
1722
- focusInput(cm);
1723
- }
1724
- });
1725
- // Let the drag handler handle this.
1726
- if (webkit) display.scroller.draggable = true;
1727
- cm.state.draggingText = dragEnd;
1728
- // IE's approach to draggable
1729
- if (display.scroller.dragDrop) display.scroller.dragDrop();
1730
- on(document, "mouseup", dragEnd);
1731
- on(display.scroller, "drop", dragEnd);
1732
- return;
1733
- }
1734
- e_preventDefault(e);
1735
- if (type == "single") extendSelection(cm.doc, clipPos(doc, start));
1736
-
1737
- var startstart = sel.from, startend = sel.to, lastPos = start;
1738
-
1739
- function doSelect(cur) {
1740
- if (posEq(lastPos, cur)) return;
1741
- lastPos = cur;
1742
-
1743
- if (type == "single") {
1744
- extendSelection(cm.doc, clipPos(doc, start), cur);
1745
- return;
1746
- }
1747
-
1748
- startstart = clipPos(doc, startstart);
1749
- startend = clipPos(doc, startend);
1750
- if (type == "double") {
1751
- var word = findWordAt(getLine(doc, cur.line).text, cur);
1752
- if (posLess(cur, startstart)) extendSelection(cm.doc, word.from, startend);
1753
- else extendSelection(cm.doc, startstart, word.to);
1754
- } else if (type == "triple") {
1755
- if (posLess(cur, startstart)) extendSelection(cm.doc, startend, clipPos(doc, Pos(cur.line, 0)));
1756
- else extendSelection(cm.doc, startstart, clipPos(doc, Pos(cur.line + 1, 0)));
1757
- }
1758
- }
1759
-
1760
- var editorSize = getRect(display.wrapper);
1761
- // Used to ensure timeout re-tries don't fire when another extend
1762
- // happened in the meantime (clearTimeout isn't reliable -- at
1763
- // least on Chrome, the timeouts still happen even when cleared,
1764
- // if the clear happens after their scheduled firing time).
1765
- var counter = 0;
1766
-
1767
- function extend(e) {
1768
- var curCount = ++counter;
1769
- var cur = posFromMouse(cm, e, true);
1770
- if (!cur) return;
1771
- if (!posEq(cur, last)) {
1772
- if (!cm.state.focused) onFocus(cm);
1773
- last = cur;
1774
- doSelect(cur);
1775
- var visible = visibleLines(display, doc);
1776
- if (cur.line >= visible.to || cur.line < visible.from)
1777
- setTimeout(operation(cm, function(){if (counter == curCount) extend(e);}), 150);
1778
- } else {
1779
- var outside = e.clientY < editorSize.top ? -20 : e.clientY > editorSize.bottom ? 20 : 0;
1780
- if (outside) setTimeout(operation(cm, function() {
1781
- if (counter != curCount) return;
1782
- display.scroller.scrollTop += outside;
1783
- extend(e);
1784
- }), 50);
1785
- }
1786
- }
1787
-
1788
- function done(e) {
1789
- counter = Infinity;
1790
- e_preventDefault(e);
1791
- focusInput(cm);
1792
- off(document, "mousemove", move);
1793
- off(document, "mouseup", up);
1794
- }
1795
-
1796
- var move = operation(cm, function(e) {
1797
- if (!ie && !e_button(e)) done(e);
1798
- else extend(e);
1799
- });
1800
- var up = operation(cm, done);
1801
- on(document, "mousemove", move);
1802
- on(document, "mouseup", up);
1803
- }
1804
-
1805
- function clickInGutter(cm, e) {
1806
- var display = cm.display;
1807
- try { var mX = e.clientX, mY = e.clientY; }
1808
- catch(e) { return false; }
1809
-
1810
- if (mX >= Math.floor(getRect(display.gutters).right)) return false;
1811
- e_preventDefault(e);
1812
- if (!hasHandler(cm, "gutterClick")) return true;
1813
-
1814
- var lineBox = getRect(display.lineDiv);
1815
- if (mY > lineBox.bottom) return true;
1816
- mY -= lineBox.top - display.viewOffset;
1817
-
1818
- for (var i = 0; i < cm.options.gutters.length; ++i) {
1819
- var g = display.gutters.childNodes[i];
1820
- if (g && getRect(g).right >= mX) {
1821
- var line = lineAtHeight(cm.doc, mY);
1822
- var gutter = cm.options.gutters[i];
1823
- signalLater(cm, "gutterClick", cm, line, gutter, e);
1824
- break;
1825
- }
1826
- }
1827
- return true;
1828
- }
1829
-
1830
- // Kludge to work around strange IE behavior where it'll sometimes
1831
- // re-fire a series of drag-related events right after the drop (#1551)
1832
- var lastDrop = 0;
1833
-
1834
- function onDrop(e) {
1835
- var cm = this;
1836
- if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e) || (cm.options.onDragEvent && cm.options.onDragEvent(cm, addStop(e))))
1837
- return;
1838
- e_preventDefault(e);
1839
- if (ie) lastDrop = +new Date;
1840
- var pos = posFromMouse(cm, e, true), files = e.dataTransfer.files;
1841
- if (!pos || isReadOnly(cm)) return;
1842
- if (files && files.length && window.FileReader && window.File) {
1843
- var n = files.length, text = Array(n), read = 0;
1844
- var loadFile = function(file, i) {
1845
- var reader = new FileReader;
1846
- reader.onload = function() {
1847
- text[i] = reader.result;
1848
- if (++read == n) {
1849
- pos = clipPos(cm.doc, pos);
1850
- makeChange(cm.doc, {from: pos, to: pos, text: splitLines(text.join("\n")), origin: "paste"}, "around");
1851
- }
1852
- };
1853
- reader.readAsText(file);
1854
- };
1855
- for (var i = 0; i < n; ++i) loadFile(files[i], i);
1856
- } else {
1857
- // Don't do a replace if the drop happened inside of the selected text.
1858
- if (cm.state.draggingText && !(posLess(pos, cm.doc.sel.from) || posLess(cm.doc.sel.to, pos))) {
1859
- cm.state.draggingText(e);
1860
- // Ensure the editor is re-focused
1861
- setTimeout(bind(focusInput, cm), 20);
1862
- return;
1863
- }
1864
- try {
1865
- var text = e.dataTransfer.getData("Text");
1866
- if (text) {
1867
- var curFrom = cm.doc.sel.from, curTo = cm.doc.sel.to;
1868
- setSelection(cm.doc, pos, pos);
1869
- if (cm.state.draggingText) replaceRange(cm.doc, "", curFrom, curTo, "paste");
1870
- cm.replaceSelection(text, null, "paste");
1871
- focusInput(cm);
1872
- onFocus(cm);
1873
- }
1874
- }
1875
- catch(e){}
1876
- }
1877
- }
1878
-
1879
- function onDragStart(cm, e) {
1880
- if (ie && (!cm.state.draggingText || +new Date - lastDrop < 100)) { e_stop(e); return; }
1881
- if (signalDOMEvent(cm, e) || eventInWidget(cm.display, e)) return;
1882
-
1883
- var txt = cm.getSelection();
1884
- e.dataTransfer.setData("Text", txt);
1885
-
1886
- // Use dummy image instead of default browsers image.
1887
- // Recent Safari (~6.0.2) have a tendency to segfault when this happens, so we don't do it there.
1888
- if (e.dataTransfer.setDragImage && !safari) {
1889
- var img = elt("img", null, null, "position: fixed; left: 0; top: 0;");
1890
- if (opera) {
1891
- img.width = img.height = 1;
1892
- cm.display.wrapper.appendChild(img);
1893
- // Force a relayout, or Opera won't use our image for some obscure reason
1894
- img._top = img.offsetTop;
1895
- }
1896
- e.dataTransfer.setDragImage(img, 0, 0);
1897
- if (opera) img.parentNode.removeChild(img);
1898
- }
1899
- }
1900
-
1901
- function setScrollTop(cm, val) {
1902
- if (Math.abs(cm.doc.scrollTop - val) < 2) return;
1903
- cm.doc.scrollTop = val;
1904
- if (!gecko) updateDisplay(cm, [], val);
1905
- if (cm.display.scroller.scrollTop != val) cm.display.scroller.scrollTop = val;
1906
- if (cm.display.scrollbarV.scrollTop != val) cm.display.scrollbarV.scrollTop = val;
1907
- if (gecko) updateDisplay(cm, []);
1908
- startWorker(cm, 100);
1909
- }
1910
- function setScrollLeft(cm, val, isScroller) {
1911
- if (isScroller ? val == cm.doc.scrollLeft : Math.abs(cm.doc.scrollLeft - val) < 2) return;
1912
- val = Math.min(val, cm.display.scroller.scrollWidth - cm.display.scroller.clientWidth);
1913
- cm.doc.scrollLeft = val;
1914
- alignHorizontally(cm);
1915
- if (cm.display.scroller.scrollLeft != val) cm.display.scroller.scrollLeft = val;
1916
- if (cm.display.scrollbarH.scrollLeft != val) cm.display.scrollbarH.scrollLeft = val;
1917
- }
1918
-
1919
- // Since the delta values reported on mouse wheel events are
1920
- // unstandardized between browsers and even browser versions, and
1921
- // generally horribly unpredictable, this code starts by measuring
1922
- // the scroll effect that the first few mouse wheel events have,
1923
- // and, from that, detects the way it can convert deltas to pixel
1924
- // offsets afterwards.
1925
- //
1926
- // The reason we want to know the amount a wheel event will scroll
1927
- // is that it gives us a chance to update the display before the
1928
- // actual scrolling happens, reducing flickering.
1929
-
1930
- var wheelSamples = 0, wheelPixelsPerUnit = null;
1931
- // Fill in a browser-detected starting value on browsers where we
1932
- // know one. These don't have to be accurate -- the result of them
1933
- // being wrong would just be a slight flicker on the first wheel
1934
- // scroll (if it is large enough).
1935
- if (ie) wheelPixelsPerUnit = -.53;
1936
- else if (gecko) wheelPixelsPerUnit = 15;
1937
- else if (chrome) wheelPixelsPerUnit = -.7;
1938
- else if (safari) wheelPixelsPerUnit = -1/3;
1939
-
1940
- function onScrollWheel(cm, e) {
1941
- var dx = e.wheelDeltaX, dy = e.wheelDeltaY;
1942
- if (dx == null && e.detail && e.axis == e.HORIZONTAL_AXIS) dx = e.detail;
1943
- if (dy == null && e.detail && e.axis == e.VERTICAL_AXIS) dy = e.detail;
1944
- else if (dy == null) dy = e.wheelDelta;
1945
-
1946
- var display = cm.display, scroll = display.scroller;
1947
- // Quit if there's nothing to scroll here
1948
- if (!(dx && scroll.scrollWidth > scroll.clientWidth ||
1949
- dy && scroll.scrollHeight > scroll.clientHeight)) return;
1950
-
1951
- // Webkit browsers on OS X abort momentum scrolls when the target
1952
- // of the scroll event is removed from the scrollable element.
1953
- // This hack (see related code in patchDisplay) makes sure the
1954
- // element is kept around.
1955
- if (dy && mac && webkit) {
1956
- for (var cur = e.target; cur != scroll; cur = cur.parentNode) {
1957
- if (cur.lineObj) {
1958
- cm.display.currentWheelTarget = cur;
1959
- break;
1960
- }
1961
- }
1962
- }
1963
-
1964
- // On some browsers, horizontal scrolling will cause redraws to
1965
- // happen before the gutter has been realigned, causing it to
1966
- // wriggle around in a most unseemly way. When we have an
1967
- // estimated pixels/delta value, we just handle horizontal
1968
- // scrolling entirely here. It'll be slightly off from native, but
1969
- // better than glitching out.
1970
- if (dx && !gecko && !opera && wheelPixelsPerUnit != null) {
1971
- if (dy)
1972
- setScrollTop(cm, Math.max(0, Math.min(scroll.scrollTop + dy * wheelPixelsPerUnit, scroll.scrollHeight - scroll.clientHeight)));
1973
- setScrollLeft(cm, Math.max(0, Math.min(scroll.scrollLeft + dx * wheelPixelsPerUnit, scroll.scrollWidth - scroll.clientWidth)));
1974
- e_preventDefault(e);
1975
- display.wheelStartX = null; // Abort measurement, if in progress
1976
- return;
1977
- }
1978
-
1979
- if (dy && wheelPixelsPerUnit != null) {
1980
- var pixels = dy * wheelPixelsPerUnit;
1981
- var top = cm.doc.scrollTop, bot = top + display.wrapper.clientHeight;
1982
- if (pixels < 0) top = Math.max(0, top + pixels - 50);
1983
- else bot = Math.min(cm.doc.height, bot + pixels + 50);
1984
- updateDisplay(cm, [], {top: top, bottom: bot});
1985
- }
1986
-
1987
- if (wheelSamples < 20) {
1988
- if (display.wheelStartX == null) {
1989
- display.wheelStartX = scroll.scrollLeft; display.wheelStartY = scroll.scrollTop;
1990
- display.wheelDX = dx; display.wheelDY = dy;
1991
- setTimeout(function() {
1992
- if (display.wheelStartX == null) return;
1993
- var movedX = scroll.scrollLeft - display.wheelStartX;
1994
- var movedY = scroll.scrollTop - display.wheelStartY;
1995
- var sample = (movedY && display.wheelDY && movedY / display.wheelDY) ||
1996
- (movedX && display.wheelDX && movedX / display.wheelDX);
1997
- display.wheelStartX = display.wheelStartY = null;
1998
- if (!sample) return;
1999
- wheelPixelsPerUnit = (wheelPixelsPerUnit * wheelSamples + sample) / (wheelSamples + 1);
2000
- ++wheelSamples;
2001
- }, 200);
2002
- } else {
2003
- display.wheelDX += dx; display.wheelDY += dy;
2004
- }
2005
- }
2006
- }
2007
-
2008
- function doHandleBinding(cm, bound, dropShift) {
2009
- if (typeof bound == "string") {
2010
- bound = commands[bound];
2011
- if (!bound) return false;
2012
- }
2013
- // Ensure previous input has been read, so that the handler sees a
2014
- // consistent view of the document
2015
- if (cm.display.pollingFast && readInput(cm)) cm.display.pollingFast = false;
2016
- var doc = cm.doc, prevShift = doc.sel.shift, done = false;
2017
- try {
2018
- if (isReadOnly(cm)) cm.state.suppressEdits = true;
2019
- if (dropShift) doc.sel.shift = false;
2020
- done = bound(cm) != Pass;
2021
- } finally {
2022
- doc.sel.shift = prevShift;
2023
- cm.state.suppressEdits = false;
2024
- }
2025
- return done;
2026
- }
2027
-
2028
- function allKeyMaps(cm) {
2029
- var maps = cm.state.keyMaps.slice(0);
2030
- if (cm.options.extraKeys) maps.push(cm.options.extraKeys);
2031
- maps.push(cm.options.keyMap);
2032
- return maps;
2033
- }
2034
-
2035
- var maybeTransition;
2036
- function handleKeyBinding(cm, e) {
2037
- // Handle auto keymap transitions
2038
- var startMap = getKeyMap(cm.options.keyMap), next = startMap.auto;
2039
- clearTimeout(maybeTransition);
2040
- if (next && !isModifierKey(e)) maybeTransition = setTimeout(function() {
2041
- if (getKeyMap(cm.options.keyMap) == startMap) {
2042
- cm.options.keyMap = (next.call ? next.call(null, cm) : next);
2043
- keyMapChanged(cm);
2044
- }
2045
- }, 50);
2046
-
2047
- var name = keyName(e, true), handled = false;
2048
- if (!name) return false;
2049
- var keymaps = allKeyMaps(cm);
2050
-
2051
- if (e.shiftKey) {
2052
- // First try to resolve full name (including 'Shift-'). Failing
2053
- // that, see if there is a cursor-motion command (starting with
2054
- // 'go') bound to the keyname without 'Shift-'.
2055
- handled = lookupKey("Shift-" + name, keymaps, function(b) {return doHandleBinding(cm, b, true);})
2056
- || lookupKey(name, keymaps, function(b) {
2057
- if (typeof b == "string" ? /^go[A-Z]/.test(b) : b.motion)
2058
- return doHandleBinding(cm, b);
2059
- });
2060
- } else {
2061
- handled = lookupKey(name, keymaps, function(b) { return doHandleBinding(cm, b); });
2062
- }
2063
-
2064
- if (handled) {
2065
- e_preventDefault(e);
2066
- restartBlink(cm);
2067
- if (ie_lt9) { e.oldKeyCode = e.keyCode; e.keyCode = 0; }
2068
- signalLater(cm, "keyHandled", cm, name, e);
2069
- }
2070
- return handled;
2071
- }
2072
-
2073
- function handleCharBinding(cm, e, ch) {
2074
- var handled = lookupKey("'" + ch + "'", allKeyMaps(cm),
2075
- function(b) { return doHandleBinding(cm, b, true); });
2076
- if (handled) {
2077
- e_preventDefault(e);
2078
- restartBlink(cm);
2079
- signalLater(cm, "keyHandled", cm, "'" + ch + "'", e);
2080
- }
2081
- return handled;
2082
- }
2083
-
2084
- var lastStoppedKey = null;
2085
- function onKeyDown(e) {
2086
- var cm = this;
2087
- if (!cm.state.focused) onFocus(cm);
2088
- if (signalDOMEvent(cm, e) || cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
2089
- if (ie && e.keyCode == 27) e.returnValue = false;
2090
- var code = e.keyCode;
2091
- // IE does strange things with escape.
2092
- cm.doc.sel.shift = code == 16 || e.shiftKey;
2093
- // First give onKeyEvent option a chance to handle this.
2094
- var handled = handleKeyBinding(cm, e);
2095
- if (opera) {
2096
- lastStoppedKey = handled ? code : null;
2097
- // Opera has no cut event... we try to at least catch the key combo
2098
- if (!handled && code == 88 && !hasCopyEvent && (mac ? e.metaKey : e.ctrlKey))
2099
- cm.replaceSelection("");
2100
- }
2101
- }
2102
-
2103
- function onKeyPress(e) {
2104
- var cm = this;
2105
- if (signalDOMEvent(cm, e) || cm.options.onKeyEvent && cm.options.onKeyEvent(cm, addStop(e))) return;
2106
- var keyCode = e.keyCode, charCode = e.charCode;
2107
- if (opera && keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
2108
- if (((opera && (!e.which || e.which < 10)) || khtml) && handleKeyBinding(cm, e)) return;
2109
- var ch = String.fromCharCode(charCode == null ? keyCode : charCode);
2110
- if (this.options.electricChars && this.doc.mode.electricChars &&
2111
- this.options.smartIndent && !isReadOnly(this) &&
2112
- this.doc.mode.electricChars.indexOf(ch) > -1)
2113
- setTimeout(operation(cm, function() {indentLine(cm, cm.doc.sel.to.line, "smart");}), 75);
2114
- if (handleCharBinding(cm, e, ch)) return;
2115
- if (ie && !ie_lt9) cm.display.inputHasSelection = null;
2116
- fastPoll(cm);
2117
- }
2118
-
2119
- function onFocus(cm) {
2120
- if (cm.options.readOnly == "nocursor") return;
2121
- if (!cm.state.focused) {
2122
- signal(cm, "focus", cm);
2123
- cm.state.focused = true;
2124
- if (cm.display.wrapper.className.search(/\bCodeMirror-focused\b/) == -1)
2125
- cm.display.wrapper.className += " CodeMirror-focused";
2126
- if (!cm.curOp) {
2127
- resetInput(cm, true);
2128
- if (webkit) setTimeout(bind(resetInput, cm, true), 0); // Issue #1730
2129
- }
2130
- }
2131
- slowPoll(cm);
2132
- restartBlink(cm);
2133
- }
2134
- function onBlur(cm) {
2135
- if (cm.state.focused) {
2136
- signal(cm, "blur", cm);
2137
- cm.state.focused = false;
2138
- cm.display.wrapper.className = cm.display.wrapper.className.replace(" CodeMirror-focused", "");
2139
- }
2140
- clearInterval(cm.display.blinker);
2141
- setTimeout(function() {if (!cm.state.focused) cm.doc.sel.shift = false;}, 150);
2142
- }
2143
-
2144
- var detectingSelectAll;
2145
- function onContextMenu(cm, e) {
2146
- if (signalDOMEvent(cm, e, "contextmenu")) return;
2147
- var display = cm.display, sel = cm.doc.sel;
2148
- if (eventInWidget(display, e)) return;
2149
-
2150
- var pos = posFromMouse(cm, e), scrollPos = display.scroller.scrollTop;
2151
- if (!pos || opera) return; // Opera is difficult.
2152
- if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
2153
- operation(cm, setSelection)(cm.doc, pos, pos);
2154
-
2155
- var oldCSS = display.input.style.cssText;
2156
- display.inputDiv.style.position = "absolute";
2157
- display.input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
2158
- "px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: white; outline: none;" +
2159
- "border-width: 0; outline: none; overflow: hidden; opacity: .05; -ms-opacity: .05; filter: alpha(opacity=5);";
2160
- focusInput(cm);
2161
- resetInput(cm, true);
2162
- // Adds "Select all" to context menu in FF
2163
- if (posEq(sel.from, sel.to)) display.input.value = display.prevInput = " ";
2164
-
2165
- function prepareSelectAllHack() {
2166
- if (display.input.selectionStart != null) {
2167
- var extval = display.input.value = " " + (posEq(sel.from, sel.to) ? "" : display.input.value);
2168
- display.prevInput = " ";
2169
- display.input.selectionStart = 1; display.input.selectionEnd = extval.length;
2170
- }
2171
- }
2172
- function rehide() {
2173
- display.inputDiv.style.position = "relative";
2174
- display.input.style.cssText = oldCSS;
2175
- if (ie_lt9) display.scrollbarV.scrollTop = display.scroller.scrollTop = scrollPos;
2176
- slowPoll(cm);
2177
-
2178
- // Try to detect the user choosing select-all
2179
- if (display.input.selectionStart != null) {
2180
- if (!ie || ie_lt9) prepareSelectAllHack();
2181
- clearTimeout(detectingSelectAll);
2182
- var i = 0, poll = function(){
2183
- if (display.prevInput == " " && display.input.selectionStart == 0)
2184
- operation(cm, commands.selectAll)(cm);
2185
- else if (i++ < 10) detectingSelectAll = setTimeout(poll, 500);
2186
- else resetInput(cm);
2187
- };
2188
- detectingSelectAll = setTimeout(poll, 200);
2189
- }
2190
- }
2191
-
2192
- if (ie && !ie_lt9) prepareSelectAllHack();
2193
- if (captureMiddleClick) {
2194
- e_stop(e);
2195
- var mouseup = function() {
2196
- off(window, "mouseup", mouseup);
2197
- setTimeout(rehide, 20);
2198
- };
2199
- on(window, "mouseup", mouseup);
2200
- } else {
2201
- setTimeout(rehide, 50);
2202
- }
2203
- }
2204
-
2205
- // UPDATING
2206
-
2207
- var changeEnd = CodeMirror.changeEnd = function(change) {
2208
- if (!change.text) return change.to;
2209
- return Pos(change.from.line + change.text.length - 1,
2210
- lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0));
2211
- };
2212
-
2213
- // Make sure a position will be valid after the given change.
2214
- function clipPostChange(doc, change, pos) {
2215
- if (!posLess(change.from, pos)) return clipPos(doc, pos);
2216
- var diff = (change.text.length - 1) - (change.to.line - change.from.line);
2217
- if (pos.line > change.to.line + diff) {
2218
- var preLine = pos.line - diff, lastLine = doc.first + doc.size - 1;
2219
- if (preLine > lastLine) return Pos(lastLine, getLine(doc, lastLine).text.length);
2220
- return clipToLen(pos, getLine(doc, preLine).text.length);
2221
- }
2222
- if (pos.line == change.to.line + diff)
2223
- return clipToLen(pos, lst(change.text).length + (change.text.length == 1 ? change.from.ch : 0) +
2224
- getLine(doc, change.to.line).text.length - change.to.ch);
2225
- var inside = pos.line - change.from.line;
2226
- return clipToLen(pos, change.text[inside].length + (inside ? 0 : change.from.ch));
2227
- }
2228
-
2229
- // Hint can be null|"end"|"start"|"around"|{anchor,head}
2230
- function computeSelAfterChange(doc, change, hint) {
2231
- if (hint && typeof hint == "object") // Assumed to be {anchor, head} object
2232
- return {anchor: clipPostChange(doc, change, hint.anchor),
2233
- head: clipPostChange(doc, change, hint.head)};
2234
-
2235
- if (hint == "start") return {anchor: change.from, head: change.from};
2236
-
2237
- var end = changeEnd(change);
2238
- if (hint == "around") return {anchor: change.from, head: end};
2239
- if (hint == "end") return {anchor: end, head: end};
2240
-
2241
- // hint is null, leave the selection alone as much as possible
2242
- var adjustPos = function(pos) {
2243
- if (posLess(pos, change.from)) return pos;
2244
- if (!posLess(change.to, pos)) return end;
2245
-
2246
- var line = pos.line + change.text.length - (change.to.line - change.from.line) - 1, ch = pos.ch;
2247
- if (pos.line == change.to.line) ch += end.ch - change.to.ch;
2248
- return Pos(line, ch);
2249
- };
2250
- return {anchor: adjustPos(doc.sel.anchor), head: adjustPos(doc.sel.head)};
2251
- }
2252
-
2253
- function filterChange(doc, change, update) {
2254
- var obj = {
2255
- canceled: false,
2256
- from: change.from,
2257
- to: change.to,
2258
- text: change.text,
2259
- origin: change.origin,
2260
- cancel: function() { this.canceled = true; }
2261
- };
2262
- if (update) obj.update = function(from, to, text, origin) {
2263
- if (from) this.from = clipPos(doc, from);
2264
- if (to) this.to = clipPos(doc, to);
2265
- if (text) this.text = text;
2266
- if (origin !== undefined) this.origin = origin;
2267
- };
2268
- signal(doc, "beforeChange", doc, obj);
2269
- if (doc.cm) signal(doc.cm, "beforeChange", doc.cm, obj);
2270
-
2271
- if (obj.canceled) return null;
2272
- return {from: obj.from, to: obj.to, text: obj.text, origin: obj.origin};
2273
- }
2274
-
2275
- // Replace the range from from to to by the strings in replacement.
2276
- // change is a {from, to, text [, origin]} object
2277
- function makeChange(doc, change, selUpdate, ignoreReadOnly) {
2278
- if (doc.cm) {
2279
- if (!doc.cm.curOp) return operation(doc.cm, makeChange)(doc, change, selUpdate, ignoreReadOnly);
2280
- if (doc.cm.state.suppressEdits) return;
2281
- }
2282
-
2283
- if (hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange")) {
2284
- change = filterChange(doc, change, true);
2285
- if (!change) return;
2286
- }
2287
-
2288
- // Possibly split or suppress the update based on the presence
2289
- // of read-only spans in its range.
2290
- var split = sawReadOnlySpans && !ignoreReadOnly && removeReadOnlyRanges(doc, change.from, change.to);
2291
- if (split) {
2292
- for (var i = split.length - 1; i >= 1; --i)
2293
- makeChangeNoReadonly(doc, {from: split[i].from, to: split[i].to, text: [""]});
2294
- if (split.length)
2295
- makeChangeNoReadonly(doc, {from: split[0].from, to: split[0].to, text: change.text}, selUpdate);
2296
- } else {
2297
- makeChangeNoReadonly(doc, change, selUpdate);
2298
- }
2299
- }
2300
-
2301
- function makeChangeNoReadonly(doc, change, selUpdate) {
2302
- var selAfter = computeSelAfterChange(doc, change, selUpdate);
2303
- addToHistory(doc, change, selAfter, doc.cm ? doc.cm.curOp.id : NaN);
2304
-
2305
- makeChangeSingleDoc(doc, change, selAfter, stretchSpansOverChange(doc, change));
2306
- var rebased = [];
2307
-
2308
- linkedDocs(doc, function(doc, sharedHist) {
2309
- if (!sharedHist && indexOf(rebased, doc.history) == -1) {
2310
- rebaseHist(doc.history, change);
2311
- rebased.push(doc.history);
2312
- }
2313
- makeChangeSingleDoc(doc, change, null, stretchSpansOverChange(doc, change));
2314
- });
2315
- }
2316
-
2317
- function makeChangeFromHistory(doc, type) {
2318
- if (doc.cm && doc.cm.state.suppressEdits) return;
2319
-
2320
- var hist = doc.history;
2321
- var event = (type == "undo" ? hist.done : hist.undone).pop();
2322
- if (!event) return;
2323
-
2324
- var anti = {changes: [], anchorBefore: event.anchorAfter, headBefore: event.headAfter,
2325
- anchorAfter: event.anchorBefore, headAfter: event.headBefore,
2326
- generation: hist.generation};
2327
- (type == "undo" ? hist.undone : hist.done).push(anti);
2328
- hist.generation = event.generation || ++hist.maxGeneration;
2329
-
2330
- var filter = hasHandler(doc, "beforeChange") || doc.cm && hasHandler(doc.cm, "beforeChange");
2331
-
2332
- for (var i = event.changes.length - 1; i >= 0; --i) {
2333
- var change = event.changes[i];
2334
- change.origin = type;
2335
- if (filter && !filterChange(doc, change, false)) {
2336
- (type == "undo" ? hist.done : hist.undone).length = 0;
2337
- return;
2338
- }
2339
-
2340
- anti.changes.push(historyChangeFromChange(doc, change));
2341
-
2342
- var after = i ? computeSelAfterChange(doc, change, null)
2343
- : {anchor: event.anchorBefore, head: event.headBefore};
2344
- makeChangeSingleDoc(doc, change, after, mergeOldSpans(doc, change));
2345
- var rebased = [];
2346
-
2347
- linkedDocs(doc, function(doc, sharedHist) {
2348
- if (!sharedHist && indexOf(rebased, doc.history) == -1) {
2349
- rebaseHist(doc.history, change);
2350
- rebased.push(doc.history);
2351
- }
2352
- makeChangeSingleDoc(doc, change, null, mergeOldSpans(doc, change));
2353
- });
2354
- }
2355
- }
2356
-
2357
- function shiftDoc(doc, distance) {
2358
- function shiftPos(pos) {return Pos(pos.line + distance, pos.ch);}
2359
- doc.first += distance;
2360
- if (doc.cm) regChange(doc.cm, doc.first, doc.first, distance);
2361
- doc.sel.head = shiftPos(doc.sel.head); doc.sel.anchor = shiftPos(doc.sel.anchor);
2362
- doc.sel.from = shiftPos(doc.sel.from); doc.sel.to = shiftPos(doc.sel.to);
2363
- }
2364
-
2365
- function makeChangeSingleDoc(doc, change, selAfter, spans) {
2366
- if (doc.cm && !doc.cm.curOp)
2367
- return operation(doc.cm, makeChangeSingleDoc)(doc, change, selAfter, spans);
2368
-
2369
- if (change.to.line < doc.first) {
2370
- shiftDoc(doc, change.text.length - 1 - (change.to.line - change.from.line));
2371
- return;
2372
- }
2373
- if (change.from.line > doc.lastLine()) return;
2374
-
2375
- // Clip the change to the size of this doc
2376
- if (change.from.line < doc.first) {
2377
- var shift = change.text.length - 1 - (doc.first - change.from.line);
2378
- shiftDoc(doc, shift);
2379
- change = {from: Pos(doc.first, 0), to: Pos(change.to.line + shift, change.to.ch),
2380
- text: [lst(change.text)], origin: change.origin};
2381
- }
2382
- var last = doc.lastLine();
2383
- if (change.to.line > last) {
2384
- change = {from: change.from, to: Pos(last, getLine(doc, last).text.length),
2385
- text: [change.text[0]], origin: change.origin};
2386
- }
2387
-
2388
- change.removed = getBetween(doc, change.from, change.to);
2389
-
2390
- if (!selAfter) selAfter = computeSelAfterChange(doc, change, null);
2391
- if (doc.cm) makeChangeSingleDocInEditor(doc.cm, change, spans, selAfter);
2392
- else updateDoc(doc, change, spans, selAfter);
2393
- }
2394
-
2395
- function makeChangeSingleDocInEditor(cm, change, spans, selAfter) {
2396
- var doc = cm.doc, display = cm.display, from = change.from, to = change.to;
2397
-
2398
- var recomputeMaxLength = false, checkWidthStart = from.line;
2399
- if (!cm.options.lineWrapping) {
2400
- checkWidthStart = lineNo(visualLine(doc, getLine(doc, from.line)));
2401
- doc.iter(checkWidthStart, to.line + 1, function(line) {
2402
- if (line == display.maxLine) {
2403
- recomputeMaxLength = true;
2404
- return true;
2405
- }
2406
- });
2407
- }
2408
-
2409
- if (!posLess(doc.sel.head, change.from) && !posLess(change.to, doc.sel.head))
2410
- cm.curOp.cursorActivity = true;
2411
-
2412
- updateDoc(doc, change, spans, selAfter, estimateHeight(cm));
2413
-
2414
- if (!cm.options.lineWrapping) {
2415
- doc.iter(checkWidthStart, from.line + change.text.length, function(line) {
2416
- var len = lineLength(doc, line);
2417
- if (len > display.maxLineLength) {
2418
- display.maxLine = line;
2419
- display.maxLineLength = len;
2420
- display.maxLineChanged = true;
2421
- recomputeMaxLength = false;
2422
- }
2423
- });
2424
- if (recomputeMaxLength) cm.curOp.updateMaxLine = true;
2425
- }
2426
-
2427
- // Adjust frontier, schedule worker
2428
- doc.frontier = Math.min(doc.frontier, from.line);
2429
- startWorker(cm, 400);
2430
-
2431
- var lendiff = change.text.length - (to.line - from.line) - 1;
2432
- // Remember that these lines changed, for updating the display
2433
- regChange(cm, from.line, to.line + 1, lendiff);
2434
-
2435
- if (hasHandler(cm, "change")) {
2436
- var changeObj = {from: from, to: to,
2437
- text: change.text,
2438
- removed: change.removed,
2439
- origin: change.origin};
2440
- if (cm.curOp.textChanged) {
2441
- for (var cur = cm.curOp.textChanged; cur.next; cur = cur.next) {}
2442
- cur.next = changeObj;
2443
- } else cm.curOp.textChanged = changeObj;
2444
- }
2445
- }
2446
-
2447
- function replaceRange(doc, code, from, to, origin) {
2448
- if (!to) to = from;
2449
- if (posLess(to, from)) { var tmp = to; to = from; from = tmp; }
2450
- if (typeof code == "string") code = splitLines(code);
2451
- makeChange(doc, {from: from, to: to, text: code, origin: origin}, null);
2452
- }
2453
-
2454
- // POSITION OBJECT
2455
-
2456
- function Pos(line, ch) {
2457
- if (!(this instanceof Pos)) return new Pos(line, ch);
2458
- this.line = line; this.ch = ch;
2459
- }
2460
- CodeMirror.Pos = Pos;
2461
-
2462
- function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
2463
- function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
2464
- function copyPos(x) {return Pos(x.line, x.ch);}
2465
-
2466
- // SELECTION
2467
-
2468
- function clipLine(doc, n) {return Math.max(doc.first, Math.min(n, doc.first + doc.size - 1));}
2469
- function clipPos(doc, pos) {
2470
- if (pos.line < doc.first) return Pos(doc.first, 0);
2471
- var last = doc.first + doc.size - 1;
2472
- if (pos.line > last) return Pos(last, getLine(doc, last).text.length);
2473
- return clipToLen(pos, getLine(doc, pos.line).text.length);
2474
- }
2475
- function clipToLen(pos, linelen) {
2476
- var ch = pos.ch;
2477
- if (ch == null || ch > linelen) return Pos(pos.line, linelen);
2478
- else if (ch < 0) return Pos(pos.line, 0);
2479
- else return pos;
2480
- }
2481
- function isLine(doc, l) {return l >= doc.first && l < doc.first + doc.size;}
2482
-
2483
- // If shift is held, this will move the selection anchor. Otherwise,
2484
- // it'll set the whole selection.
2485
- function extendSelection(doc, pos, other, bias) {
2486
- if (doc.sel.shift || doc.sel.extend) {
2487
- var anchor = doc.sel.anchor;
2488
- if (other) {
2489
- var posBefore = posLess(pos, anchor);
2490
- if (posBefore != posLess(other, anchor)) {
2491
- anchor = pos;
2492
- pos = other;
2493
- } else if (posBefore != posLess(pos, other)) {
2494
- pos = other;
2495
- }
2496
- }
2497
- setSelection(doc, anchor, pos, bias);
2498
- } else {
2499
- setSelection(doc, pos, other || pos, bias);
2500
- }
2501
- if (doc.cm) doc.cm.curOp.userSelChange = true;
2502
- }
2503
-
2504
- function filterSelectionChange(doc, anchor, head) {
2505
- var obj = {anchor: anchor, head: head};
2506
- signal(doc, "beforeSelectionChange", doc, obj);
2507
- if (doc.cm) signal(doc.cm, "beforeSelectionChange", doc.cm, obj);
2508
- obj.anchor = clipPos(doc, obj.anchor); obj.head = clipPos(doc, obj.head);
2509
- return obj;
2510
- }
2511
-
2512
- // Update the selection. Last two args are only used by
2513
- // updateDoc, since they have to be expressed in the line
2514
- // numbers before the update.
2515
- function setSelection(doc, anchor, head, bias, checkAtomic) {
2516
- if (!checkAtomic && hasHandler(doc, "beforeSelectionChange") || doc.cm && hasHandler(doc.cm, "beforeSelectionChange")) {
2517
- var filtered = filterSelectionChange(doc, anchor, head);
2518
- head = filtered.head;
2519
- anchor = filtered.anchor;
2520
- }
2521
-
2522
- var sel = doc.sel;
2523
- sel.goalColumn = null;
2524
- // Skip over atomic spans.
2525
- if (checkAtomic || !posEq(anchor, sel.anchor))
2526
- anchor = skipAtomic(doc, anchor, bias, checkAtomic != "push");
2527
- if (checkAtomic || !posEq(head, sel.head))
2528
- head = skipAtomic(doc, head, bias, checkAtomic != "push");
2529
-
2530
- if (posEq(sel.anchor, anchor) && posEq(sel.head, head)) return;
2531
-
2532
- sel.anchor = anchor; sel.head = head;
2533
- var inv = posLess(head, anchor);
2534
- sel.from = inv ? head : anchor;
2535
- sel.to = inv ? anchor : head;
2536
-
2537
- if (doc.cm)
2538
- doc.cm.curOp.updateInput = doc.cm.curOp.selectionChanged =
2539
- doc.cm.curOp.cursorActivity = true;
2540
-
2541
- signalLater(doc, "cursorActivity", doc);
2542
- }
2543
-
2544
- function reCheckSelection(cm) {
2545
- setSelection(cm.doc, cm.doc.sel.from, cm.doc.sel.to, null, "push");
2546
- }
2547
-
2548
- function skipAtomic(doc, pos, bias, mayClear) {
2549
- var flipped = false, curPos = pos;
2550
- var dir = bias || 1;
2551
- doc.cantEdit = false;
2552
- search: for (;;) {
2553
- var line = getLine(doc, curPos.line);
2554
- if (line.markedSpans) {
2555
- for (var i = 0; i < line.markedSpans.length; ++i) {
2556
- var sp = line.markedSpans[i], m = sp.marker;
2557
- if ((sp.from == null || (m.inclusiveLeft ? sp.from <= curPos.ch : sp.from < curPos.ch)) &&
2558
- (sp.to == null || (m.inclusiveRight ? sp.to >= curPos.ch : sp.to > curPos.ch))) {
2559
- if (mayClear) {
2560
- signal(m, "beforeCursorEnter");
2561
- if (m.explicitlyCleared) {
2562
- if (!line.markedSpans) break;
2563
- else {--i; continue;}
2564
- }
2565
- }
2566
- if (!m.atomic) continue;
2567
- var newPos = m.find()[dir < 0 ? "from" : "to"];
2568
- if (posEq(newPos, curPos)) {
2569
- newPos.ch += dir;
2570
- if (newPos.ch < 0) {
2571
- if (newPos.line > doc.first) newPos = clipPos(doc, Pos(newPos.line - 1));
2572
- else newPos = null;
2573
- } else if (newPos.ch > line.text.length) {
2574
- if (newPos.line < doc.first + doc.size - 1) newPos = Pos(newPos.line + 1, 0);
2575
- else newPos = null;
2576
- }
2577
- if (!newPos) {
2578
- if (flipped) {
2579
- // Driven in a corner -- no valid cursor position found at all
2580
- // -- try again *with* clearing, if we didn't already
2581
- if (!mayClear) return skipAtomic(doc, pos, bias, true);
2582
- // Otherwise, turn off editing until further notice, and return the start of the doc
2583
- doc.cantEdit = true;
2584
- return Pos(doc.first, 0);
2585
- }
2586
- flipped = true; newPos = pos; dir = -dir;
2587
- }
2588
- }
2589
- curPos = newPos;
2590
- continue search;
2591
- }
2592
- }
2593
- }
2594
- return curPos;
2595
- }
2596
- }
2597
-
2598
- // SCROLLING
2599
-
2600
- function scrollCursorIntoView(cm) {
2601
- var coords = scrollPosIntoView(cm, cm.doc.sel.head, cm.options.cursorScrollMargin);
2602
- if (!cm.state.focused) return;
2603
- var display = cm.display, box = getRect(display.sizer), doScroll = null;
2604
- if (coords.top + box.top < 0) doScroll = true;
2605
- else if (coords.bottom + box.top > (window.innerHeight || document.documentElement.clientHeight)) doScroll = false;
2606
- if (doScroll != null && !phantom) {
2607
- var hidden = display.cursor.style.display == "none";
2608
- if (hidden) {
2609
- display.cursor.style.display = "";
2610
- display.cursor.style.left = coords.left + "px";
2611
- display.cursor.style.top = (coords.top - display.viewOffset) + "px";
2612
- }
2613
- display.cursor.scrollIntoView(doScroll);
2614
- if (hidden) display.cursor.style.display = "none";
2615
- }
2616
- }
2617
-
2618
- function scrollPosIntoView(cm, pos, margin) {
2619
- if (margin == null) margin = 0;
2620
- for (;;) {
2621
- var changed = false, coords = cursorCoords(cm, pos);
2622
- var scrollPos = calculateScrollPos(cm, coords.left, coords.top - margin, coords.left, coords.bottom + margin);
2623
- var startTop = cm.doc.scrollTop, startLeft = cm.doc.scrollLeft;
2624
- if (scrollPos.scrollTop != null) {
2625
- setScrollTop(cm, scrollPos.scrollTop);
2626
- if (Math.abs(cm.doc.scrollTop - startTop) > 1) changed = true;
2627
- }
2628
- if (scrollPos.scrollLeft != null) {
2629
- setScrollLeft(cm, scrollPos.scrollLeft);
2630
- if (Math.abs(cm.doc.scrollLeft - startLeft) > 1) changed = true;
2631
- }
2632
- if (!changed) return coords;
2633
- }
2634
- }
2635
-
2636
- function scrollIntoView(cm, x1, y1, x2, y2) {
2637
- var scrollPos = calculateScrollPos(cm, x1, y1, x2, y2);
2638
- if (scrollPos.scrollTop != null) setScrollTop(cm, scrollPos.scrollTop);
2639
- if (scrollPos.scrollLeft != null) setScrollLeft(cm, scrollPos.scrollLeft);
2640
- }
2641
-
2642
- function calculateScrollPos(cm, x1, y1, x2, y2) {
2643
- var display = cm.display, snapMargin = textHeight(cm.display);
2644
- if (y1 < 0) y1 = 0;
2645
- var screen = display.scroller.clientHeight - scrollerCutOff, screentop = display.scroller.scrollTop, result = {};
2646
- var docBottom = cm.doc.height + paddingVert(display);
2647
- var atTop = y1 < snapMargin, atBottom = y2 > docBottom - snapMargin;
2648
- if (y1 < screentop) {
2649
- result.scrollTop = atTop ? 0 : y1;
2650
- } else if (y2 > screentop + screen) {
2651
- var newTop = Math.min(y1, (atBottom ? docBottom : y2) - screen);
2652
- if (newTop != screentop) result.scrollTop = newTop;
2653
- }
2654
-
2655
- var screenw = display.scroller.clientWidth - scrollerCutOff, screenleft = display.scroller.scrollLeft;
2656
- x1 += display.gutters.offsetWidth; x2 += display.gutters.offsetWidth;
2657
- var gutterw = display.gutters.offsetWidth;
2658
- var atLeft = x1 < gutterw + 10;
2659
- if (x1 < screenleft + gutterw || atLeft) {
2660
- if (atLeft) x1 = 0;
2661
- result.scrollLeft = Math.max(0, x1 - 10 - gutterw);
2662
- } else if (x2 > screenw + screenleft - 3) {
2663
- result.scrollLeft = x2 + 10 - screenw;
2664
- }
2665
- return result;
2666
- }
2667
-
2668
- function updateScrollPos(cm, left, top) {
2669
- cm.curOp.updateScrollPos = {scrollLeft: left == null ? cm.doc.scrollLeft : left,
2670
- scrollTop: top == null ? cm.doc.scrollTop : top};
2671
- }
2672
-
2673
- function addToScrollPos(cm, left, top) {
2674
- var pos = cm.curOp.updateScrollPos || (cm.curOp.updateScrollPos = {scrollLeft: cm.doc.scrollLeft, scrollTop: cm.doc.scrollTop});
2675
- var scroll = cm.display.scroller;
2676
- pos.scrollTop = Math.max(0, Math.min(scroll.scrollHeight - scroll.clientHeight, pos.scrollTop + top));
2677
- pos.scrollLeft = Math.max(0, Math.min(scroll.scrollWidth - scroll.clientWidth, pos.scrollLeft + left));
2678
- }
2679
-
2680
- // API UTILITIES
2681
-
2682
- function indentLine(cm, n, how, aggressive) {
2683
- var doc = cm.doc;
2684
- if (how == null) how = "add";
2685
- if (how == "smart") {
2686
- if (!cm.doc.mode.indent) how = "prev";
2687
- else var state = getStateBefore(cm, n);
2688
- }
2689
-
2690
- var tabSize = cm.options.tabSize;
2691
- var line = getLine(doc, n), curSpace = countColumn(line.text, null, tabSize);
2692
- var curSpaceString = line.text.match(/^\s*/)[0], indentation;
2693
- if (how == "smart") {
2694
- indentation = cm.doc.mode.indent(state, line.text.slice(curSpaceString.length), line.text);
2695
- if (indentation == Pass) {
2696
- if (!aggressive) return;
2697
- how = "prev";
2698
- }
2699
- }
2700
- if (how == "prev") {
2701
- if (n > doc.first) indentation = countColumn(getLine(doc, n-1).text, null, tabSize);
2702
- else indentation = 0;
2703
- } else if (how == "add") {
2704
- indentation = curSpace + cm.options.indentUnit;
2705
- } else if (how == "subtract") {
2706
- indentation = curSpace - cm.options.indentUnit;
2707
- } else if (typeof how == "number") {
2708
- indentation = curSpace + how;
2709
- }
2710
- indentation = Math.max(0, indentation);
2711
-
2712
- var indentString = "", pos = 0;
2713
- if (cm.options.indentWithTabs)
2714
- for (var i = Math.floor(indentation / tabSize); i; --i) {pos += tabSize; indentString += "\t";}
2715
- if (pos < indentation) indentString += spaceStr(indentation - pos);
2716
-
2717
- if (indentString != curSpaceString)
2718
- replaceRange(cm.doc, indentString, Pos(n, 0), Pos(n, curSpaceString.length), "+input");
2719
- line.stateAfter = null;
2720
- }
2721
-
2722
- function changeLine(cm, handle, op) {
2723
- var no = handle, line = handle, doc = cm.doc;
2724
- if (typeof handle == "number") line = getLine(doc, clipLine(doc, handle));
2725
- else no = lineNo(handle);
2726
- if (no == null) return null;
2727
- if (op(line, no)) regChange(cm, no, no + 1);
2728
- else return null;
2729
- return line;
2730
- }
2731
-
2732
- function findPosH(doc, pos, dir, unit, visually) {
2733
- var line = pos.line, ch = pos.ch, origDir = dir;
2734
- var lineObj = getLine(doc, line);
2735
- var possible = true;
2736
- function findNextLine() {
2737
- var l = line + dir;
2738
- if (l < doc.first || l >= doc.first + doc.size) return (possible = false);
2739
- line = l;
2740
- return lineObj = getLine(doc, l);
2741
- }
2742
- function moveOnce(boundToLine) {
2743
- var next = (visually ? moveVisually : moveLogically)(lineObj, ch, dir, true);
2744
- if (next == null) {
2745
- if (!boundToLine && findNextLine()) {
2746
- if (visually) ch = (dir < 0 ? lineRight : lineLeft)(lineObj);
2747
- else ch = dir < 0 ? lineObj.text.length : 0;
2748
- } else return (possible = false);
2749
- } else ch = next;
2750
- return true;
2751
- }
2752
-
2753
- if (unit == "char") moveOnce();
2754
- else if (unit == "column") moveOnce(true);
2755
- else if (unit == "word" || unit == "group") {
2756
- var sawType = null, group = unit == "group";
2757
- for (var first = true;; first = false) {
2758
- if (dir < 0 && !moveOnce(!first)) break;
2759
- var cur = lineObj.text.charAt(ch) || "\n";
2760
- var type = isWordChar(cur) ? "w"
2761
- : !group ? null
2762
- : /\s/.test(cur) ? null
2763
- : "p";
2764
- if (sawType && sawType != type) {
2765
- if (dir < 0) {dir = 1; moveOnce();}
2766
- break;
2767
- }
2768
- if (type) sawType = type;
2769
- if (dir > 0 && !moveOnce(!first)) break;
2770
- }
2771
- }
2772
- var result = skipAtomic(doc, Pos(line, ch), origDir, true);
2773
- if (!possible) result.hitSide = true;
2774
- return result;
2775
- }
2776
-
2777
- function findPosV(cm, pos, dir, unit) {
2778
- var doc = cm.doc, x = pos.left, y;
2779
- if (unit == "page") {
2780
- var pageSize = Math.min(cm.display.wrapper.clientHeight, window.innerHeight || document.documentElement.clientHeight);
2781
- y = pos.top + dir * (pageSize - (dir < 0 ? 1.5 : .5) * textHeight(cm.display));
2782
- } else if (unit == "line") {
2783
- y = dir > 0 ? pos.bottom + 3 : pos.top - 3;
2784
- }
2785
- for (;;) {
2786
- var target = coordsChar(cm, x, y);
2787
- if (!target.outside) break;
2788
- if (dir < 0 ? y <= 0 : y >= doc.height) { target.hitSide = true; break; }
2789
- y += dir * 5;
2790
- }
2791
- return target;
2792
- }
2793
-
2794
- function findWordAt(line, pos) {
2795
- var start = pos.ch, end = pos.ch;
2796
- if (line) {
2797
- if ((pos.xRel < 0 || end == line.length) && start) --start; else ++end;
2798
- var startChar = line.charAt(start);
2799
- var check = isWordChar(startChar) ? isWordChar
2800
- : /\s/.test(startChar) ? function(ch) {return /\s/.test(ch);}
2801
- : function(ch) {return !/\s/.test(ch) && !isWordChar(ch);};
2802
- while (start > 0 && check(line.charAt(start - 1))) --start;
2803
- while (end < line.length && check(line.charAt(end))) ++end;
2804
- }
2805
- return {from: Pos(pos.line, start), to: Pos(pos.line, end)};
2806
- }
2807
-
2808
- function selectLine(cm, line) {
2809
- extendSelection(cm.doc, Pos(line, 0), clipPos(cm.doc, Pos(line + 1, 0)));
2810
- }
2811
-
2812
- // PROTOTYPE
2813
-
2814
- // The publicly visible API. Note that operation(null, f) means
2815
- // 'wrap f in an operation, performed on its `this` parameter'
2816
-
2817
- CodeMirror.prototype = {
2818
- constructor: CodeMirror,
2819
- focus: function(){window.focus(); focusInput(this); onFocus(this); fastPoll(this);},
2820
-
2821
- setOption: function(option, value) {
2822
- var options = this.options, old = options[option];
2823
- if (options[option] == value && option != "mode") return;
2824
- options[option] = value;
2825
- if (optionHandlers.hasOwnProperty(option))
2826
- operation(this, optionHandlers[option])(this, value, old);
2827
- },
2828
-
2829
- getOption: function(option) {return this.options[option];},
2830
- getDoc: function() {return this.doc;},
2831
-
2832
- addKeyMap: function(map, bottom) {
2833
- this.state.keyMaps[bottom ? "push" : "unshift"](map);
2834
- },
2835
- removeKeyMap: function(map) {
2836
- var maps = this.state.keyMaps;
2837
- for (var i = 0; i < maps.length; ++i)
2838
- if (maps[i] == map || (typeof maps[i] != "string" && maps[i].name == map)) {
2839
- maps.splice(i, 1);
2840
- return true;
2841
- }
2842
- },
2843
-
2844
- addOverlay: operation(null, function(spec, options) {
2845
- var mode = spec.token ? spec : CodeMirror.getMode(this.options, spec);
2846
- if (mode.startState) throw new Error("Overlays may not be stateful.");
2847
- this.state.overlays.push({mode: mode, modeSpec: spec, opaque: options && options.opaque});
2848
- this.state.modeGen++;
2849
- regChange(this);
2850
- }),
2851
- removeOverlay: operation(null, function(spec) {
2852
- var overlays = this.state.overlays;
2853
- for (var i = 0; i < overlays.length; ++i) {
2854
- var cur = overlays[i].modeSpec;
2855
- if (cur == spec || typeof spec == "string" && cur.name == spec) {
2856
- overlays.splice(i, 1);
2857
- this.state.modeGen++;
2858
- regChange(this);
2859
- return;
2860
- }
2861
- }
2862
- }),
2863
-
2864
- indentLine: operation(null, function(n, dir, aggressive) {
2865
- if (typeof dir != "string" && typeof dir != "number") {
2866
- if (dir == null) dir = this.options.smartIndent ? "smart" : "prev";
2867
- else dir = dir ? "add" : "subtract";
2868
- }
2869
- if (isLine(this.doc, n)) indentLine(this, n, dir, aggressive);
2870
- }),
2871
- indentSelection: operation(null, function(how) {
2872
- var sel = this.doc.sel;
2873
- if (posEq(sel.from, sel.to)) return indentLine(this, sel.from.line, how);
2874
- var e = sel.to.line - (sel.to.ch ? 0 : 1);
2875
- for (var i = sel.from.line; i <= e; ++i) indentLine(this, i, how);
2876
- }),
2877
-
2878
- // Fetch the parser token for a given character. Useful for hacks
2879
- // that want to inspect the mode state (say, for completion).
2880
- getTokenAt: function(pos, precise) {
2881
- var doc = this.doc;
2882
- pos = clipPos(doc, pos);
2883
- var state = getStateBefore(this, pos.line, precise), mode = this.doc.mode;
2884
- var line = getLine(doc, pos.line);
2885
- var stream = new StringStream(line.text, this.options.tabSize);
2886
- while (stream.pos < pos.ch && !stream.eol()) {
2887
- stream.start = stream.pos;
2888
- var style = mode.token(stream, state);
2889
- }
2890
- return {start: stream.start,
2891
- end: stream.pos,
2892
- string: stream.current(),
2893
- className: style || null, // Deprecated, use 'type' instead
2894
- type: style || null,
2895
- state: state};
2896
- },
2897
-
2898
- getTokenTypeAt: function(pos) {
2899
- pos = clipPos(this.doc, pos);
2900
- var styles = getLineStyles(this, getLine(this.doc, pos.line));
2901
- var before = 0, after = (styles.length - 1) / 2, ch = pos.ch;
2902
- if (ch == 0) return styles[2];
2903
- for (;;) {
2904
- var mid = (before + after) >> 1;
2905
- if ((mid ? styles[mid * 2 - 1] : 0) >= ch) after = mid;
2906
- else if (styles[mid * 2 + 1] < ch) before = mid + 1;
2907
- else return styles[mid * 2 + 2];
2908
- }
2909
- },
2910
-
2911
- getModeAt: function(pos) {
2912
- var mode = this.doc.mode;
2913
- if (!mode.innerMode) return mode;
2914
- return CodeMirror.innerMode(mode, this.getTokenAt(pos).state).mode;
2915
- },
2916
-
2917
- getHelper: function(pos, type) {
2918
- if (!helpers.hasOwnProperty(type)) return;
2919
- var help = helpers[type], mode = this.getModeAt(pos);
2920
- return mode[type] && help[mode[type]] ||
2921
- mode.helperType && help[mode.helperType] ||
2922
- help[mode.name];
2923
- },
2924
-
2925
- getStateAfter: function(line, precise) {
2926
- var doc = this.doc;
2927
- line = clipLine(doc, line == null ? doc.first + doc.size - 1: line);
2928
- return getStateBefore(this, line + 1, precise);
2929
- },
2930
-
2931
- cursorCoords: function(start, mode) {
2932
- var pos, sel = this.doc.sel;
2933
- if (start == null) pos = sel.head;
2934
- else if (typeof start == "object") pos = clipPos(this.doc, start);
2935
- else pos = start ? sel.from : sel.to;
2936
- return cursorCoords(this, pos, mode || "page");
2937
- },
2938
-
2939
- charCoords: function(pos, mode) {
2940
- return charCoords(this, clipPos(this.doc, pos), mode || "page");
2941
- },
2942
-
2943
- coordsChar: function(coords, mode) {
2944
- coords = fromCoordSystem(this, coords, mode || "page");
2945
- return coordsChar(this, coords.left, coords.top);
2946
- },
2947
-
2948
- lineAtHeight: function(height, mode) {
2949
- height = fromCoordSystem(this, {top: height, left: 0}, mode || "page").top;
2950
- return lineAtHeight(this.doc, height + this.display.viewOffset);
2951
- },
2952
- heightAtLine: function(line, mode) {
2953
- var end = false, last = this.doc.first + this.doc.size - 1;
2954
- if (line < this.doc.first) line = this.doc.first;
2955
- else if (line > last) { line = last; end = true; }
2956
- var lineObj = getLine(this.doc, line);
2957
- return intoCoordSystem(this, getLine(this.doc, line), {top: 0, left: 0}, mode || "page").top +
2958
- (end ? lineObj.height : 0);
2959
- },
2960
-
2961
- defaultTextHeight: function() { return textHeight(this.display); },
2962
- defaultCharWidth: function() { return charWidth(this.display); },
2963
-
2964
- setGutterMarker: operation(null, function(line, gutterID, value) {
2965
- return changeLine(this, line, function(line) {
2966
- var markers = line.gutterMarkers || (line.gutterMarkers = {});
2967
- markers[gutterID] = value;
2968
- if (!value && isEmpty(markers)) line.gutterMarkers = null;
2969
- return true;
2970
- });
2971
- }),
2972
-
2973
- clearGutter: operation(null, function(gutterID) {
2974
- var cm = this, doc = cm.doc, i = doc.first;
2975
- doc.iter(function(line) {
2976
- if (line.gutterMarkers && line.gutterMarkers[gutterID]) {
2977
- line.gutterMarkers[gutterID] = null;
2978
- regChange(cm, i, i + 1);
2979
- if (isEmpty(line.gutterMarkers)) line.gutterMarkers = null;
2980
- }
2981
- ++i;
2982
- });
2983
- }),
2984
-
2985
- addLineClass: operation(null, function(handle, where, cls) {
2986
- return changeLine(this, handle, function(line) {
2987
- var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
2988
- if (!line[prop]) line[prop] = cls;
2989
- else if (new RegExp("(?:^|\\s)" + cls + "(?:$|\\s)").test(line[prop])) return false;
2990
- else line[prop] += " " + cls;
2991
- return true;
2992
- });
2993
- }),
2994
-
2995
- removeLineClass: operation(null, function(handle, where, cls) {
2996
- return changeLine(this, handle, function(line) {
2997
- var prop = where == "text" ? "textClass" : where == "background" ? "bgClass" : "wrapClass";
2998
- var cur = line[prop];
2999
- if (!cur) return false;
3000
- else if (cls == null) line[prop] = null;
3001
- else {
3002
- var found = cur.match(new RegExp("(?:^|\\s+)" + cls + "(?:$|\\s+)"));
3003
- if (!found) return false;
3004
- var end = found.index + found[0].length;
3005
- line[prop] = cur.slice(0, found.index) + (!found.index || end == cur.length ? "" : " ") + cur.slice(end) || null;
3006
- }
3007
- return true;
3008
- });
3009
- }),
3010
-
3011
- addLineWidget: operation(null, function(handle, node, options) {
3012
- return addLineWidget(this, handle, node, options);
3013
- }),
3014
-
3015
- removeLineWidget: function(widget) { widget.clear(); },
3016
-
3017
- lineInfo: function(line) {
3018
- if (typeof line == "number") {
3019
- if (!isLine(this.doc, line)) return null;
3020
- var n = line;
3021
- line = getLine(this.doc, line);
3022
- if (!line) return null;
3023
- } else {
3024
- var n = lineNo(line);
3025
- if (n == null) return null;
3026
- }
3027
- return {line: n, handle: line, text: line.text, gutterMarkers: line.gutterMarkers,
3028
- textClass: line.textClass, bgClass: line.bgClass, wrapClass: line.wrapClass,
3029
- widgets: line.widgets};
3030
- },
3031
-
3032
- getViewport: function() { return {from: this.display.showingFrom, to: this.display.showingTo};},
3033
-
3034
- addWidget: function(pos, node, scroll, vert, horiz) {
3035
- var display = this.display;
3036
- pos = cursorCoords(this, clipPos(this.doc, pos));
3037
- var top = pos.bottom, left = pos.left;
3038
- node.style.position = "absolute";
3039
- display.sizer.appendChild(node);
3040
- if (vert == "over") {
3041
- top = pos.top;
3042
- } else if (vert == "above" || vert == "near") {
3043
- var vspace = Math.max(display.wrapper.clientHeight, this.doc.height),
3044
- hspace = Math.max(display.sizer.clientWidth, display.lineSpace.clientWidth);
3045
- // Default to positioning above (if specified and possible); otherwise default to positioning below
3046
- if ((vert == 'above' || pos.bottom + node.offsetHeight > vspace) && pos.top > node.offsetHeight)
3047
- top = pos.top - node.offsetHeight;
3048
- else if (pos.bottom + node.offsetHeight <= vspace)
3049
- top = pos.bottom;
3050
- if (left + node.offsetWidth > hspace)
3051
- left = hspace - node.offsetWidth;
3052
- }
3053
- node.style.top = top + "px";
3054
- node.style.left = node.style.right = "";
3055
- if (horiz == "right") {
3056
- left = display.sizer.clientWidth - node.offsetWidth;
3057
- node.style.right = "0px";
3058
- } else {
3059
- if (horiz == "left") left = 0;
3060
- else if (horiz == "middle") left = (display.sizer.clientWidth - node.offsetWidth) / 2;
3061
- node.style.left = left + "px";
3062
- }
3063
- if (scroll)
3064
- scrollIntoView(this, left, top, left + node.offsetWidth, top + node.offsetHeight);
3065
- },
3066
-
3067
- triggerOnKeyDown: operation(null, onKeyDown),
3068
-
3069
- execCommand: function(cmd) {return commands[cmd](this);},
3070
-
3071
- findPosH: function(from, amount, unit, visually) {
3072
- var dir = 1;
3073
- if (amount < 0) { dir = -1; amount = -amount; }
3074
- for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
3075
- cur = findPosH(this.doc, cur, dir, unit, visually);
3076
- if (cur.hitSide) break;
3077
- }
3078
- return cur;
3079
- },
3080
-
3081
- moveH: operation(null, function(dir, unit) {
3082
- var sel = this.doc.sel, pos;
3083
- if (sel.shift || sel.extend || posEq(sel.from, sel.to))
3084
- pos = findPosH(this.doc, sel.head, dir, unit, this.options.rtlMoveVisually);
3085
- else
3086
- pos = dir < 0 ? sel.from : sel.to;
3087
- extendSelection(this.doc, pos, pos, dir);
3088
- }),
3089
-
3090
- deleteH: operation(null, function(dir, unit) {
3091
- var sel = this.doc.sel;
3092
- if (!posEq(sel.from, sel.to)) replaceRange(this.doc, "", sel.from, sel.to, "+delete");
3093
- else replaceRange(this.doc, "", sel.from, findPosH(this.doc, sel.head, dir, unit, false), "+delete");
3094
- this.curOp.userSelChange = true;
3095
- }),
3096
-
3097
- findPosV: function(from, amount, unit, goalColumn) {
3098
- var dir = 1, x = goalColumn;
3099
- if (amount < 0) { dir = -1; amount = -amount; }
3100
- for (var i = 0, cur = clipPos(this.doc, from); i < amount; ++i) {
3101
- var coords = cursorCoords(this, cur, "div");
3102
- if (x == null) x = coords.left;
3103
- else coords.left = x;
3104
- cur = findPosV(this, coords, dir, unit);
3105
- if (cur.hitSide) break;
3106
- }
3107
- return cur;
3108
- },
3109
-
3110
- moveV: operation(null, function(dir, unit) {
3111
- var sel = this.doc.sel;
3112
- var pos = cursorCoords(this, sel.head, "div");
3113
- if (sel.goalColumn != null) pos.left = sel.goalColumn;
3114
- var target = findPosV(this, pos, dir, unit);
3115
-
3116
- if (unit == "page") addToScrollPos(this, 0, charCoords(this, target, "div").top - pos.top);
3117
- extendSelection(this.doc, target, target, dir);
3118
- sel.goalColumn = pos.left;
3119
- }),
3120
-
3121
- toggleOverwrite: function(value) {
3122
- if (value != null && value == this.state.overwrite) return;
3123
- if (this.state.overwrite = !this.state.overwrite)
3124
- this.display.cursor.className += " CodeMirror-overwrite";
3125
- else
3126
- this.display.cursor.className = this.display.cursor.className.replace(" CodeMirror-overwrite", "");
3127
- },
3128
- hasFocus: function() { return this.state.focused; },
3129
-
3130
- scrollTo: operation(null, function(x, y) {
3131
- updateScrollPos(this, x, y);
3132
- }),
3133
- getScrollInfo: function() {
3134
- var scroller = this.display.scroller, co = scrollerCutOff;
3135
- return {left: scroller.scrollLeft, top: scroller.scrollTop,
3136
- height: scroller.scrollHeight - co, width: scroller.scrollWidth - co,
3137
- clientHeight: scroller.clientHeight - co, clientWidth: scroller.clientWidth - co};
3138
- },
3139
-
3140
- scrollIntoView: operation(null, function(pos, margin) {
3141
- if (typeof pos == "number") pos = Pos(pos, 0);
3142
- if (!margin) margin = 0;
3143
- var coords = pos;
3144
-
3145
- if (!pos || pos.line != null) {
3146
- this.curOp.scrollToPos = pos ? clipPos(this.doc, pos) : this.doc.sel.head;
3147
- this.curOp.scrollToPosMargin = margin;
3148
- coords = cursorCoords(this, this.curOp.scrollToPos);
3149
- }
3150
- var sPos = calculateScrollPos(this, coords.left, coords.top - margin, coords.right, coords.bottom + margin);
3151
- updateScrollPos(this, sPos.scrollLeft, sPos.scrollTop);
3152
- }),
3153
-
3154
- setSize: operation(null, function(width, height) {
3155
- function interpret(val) {
3156
- return typeof val == "number" || /^\d+$/.test(String(val)) ? val + "px" : val;
3157
- }
3158
- if (width != null) this.display.wrapper.style.width = interpret(width);
3159
- if (height != null) this.display.wrapper.style.height = interpret(height);
3160
- if (this.options.lineWrapping)
3161
- this.display.measureLineCache.length = this.display.measureLineCachePos = 0;
3162
- this.curOp.forceUpdate = true;
3163
- }),
3164
-
3165
- operation: function(f){return runInOp(this, f);},
3166
-
3167
- refresh: operation(null, function() {
3168
- clearCaches(this);
3169
- updateScrollPos(this, this.doc.scrollLeft, this.doc.scrollTop);
3170
- regChange(this);
3171
- }),
3172
-
3173
- swapDoc: operation(null, function(doc) {
3174
- var old = this.doc;
3175
- old.cm = null;
3176
- attachDoc(this, doc);
3177
- clearCaches(this);
3178
- resetInput(this, true);
3179
- updateScrollPos(this, doc.scrollLeft, doc.scrollTop);
3180
- return old;
3181
- }),
3182
-
3183
- getInputField: function(){return this.display.input;},
3184
- getWrapperElement: function(){return this.display.wrapper;},
3185
- getScrollerElement: function(){return this.display.scroller;},
3186
- getGutterElement: function(){return this.display.gutters;}
3187
- };
3188
- eventMixin(CodeMirror);
3189
-
3190
- // OPTION DEFAULTS
3191
-
3192
- var optionHandlers = CodeMirror.optionHandlers = {};
3193
-
3194
- // The default configuration options.
3195
- var defaults = CodeMirror.defaults = {};
3196
-
3197
- function option(name, deflt, handle, notOnInit) {
3198
- CodeMirror.defaults[name] = deflt;
3199
- if (handle) optionHandlers[name] =
3200
- notOnInit ? function(cm, val, old) {if (old != Init) handle(cm, val, old);} : handle;
3201
- }
3202
-
3203
- var Init = CodeMirror.Init = {toString: function(){return "CodeMirror.Init";}};
3204
-
3205
- // These two are, on init, called from the constructor because they
3206
- // have to be initialized before the editor can start at all.
3207
- option("value", "", function(cm, val) {
3208
- cm.setValue(val);
3209
- }, true);
3210
- option("mode", null, function(cm, val) {
3211
- cm.doc.modeOption = val;
3212
- loadMode(cm);
3213
- }, true);
3214
-
3215
- option("indentUnit", 2, loadMode, true);
3216
- option("indentWithTabs", false);
3217
- option("smartIndent", true);
3218
- option("tabSize", 4, function(cm) {
3219
- loadMode(cm);
3220
- clearCaches(cm);
3221
- regChange(cm);
3222
- }, true);
3223
- option("electricChars", true);
3224
- option("rtlMoveVisually", !windows);
3225
-
3226
- option("theme", "default", function(cm) {
3227
- themeChanged(cm);
3228
- guttersChanged(cm);
3229
- }, true);
3230
- option("keyMap", "default", keyMapChanged);
3231
- option("extraKeys", null);
3232
-
3233
- option("onKeyEvent", null);
3234
- option("onDragEvent", null);
3235
-
3236
- option("lineWrapping", false, wrappingChanged, true);
3237
- option("gutters", [], function(cm) {
3238
- setGuttersForLineNumbers(cm.options);
3239
- guttersChanged(cm);
3240
- }, true);
3241
- option("fixedGutter", true, function(cm, val) {
3242
- cm.display.gutters.style.left = val ? compensateForHScroll(cm.display) + "px" : "0";
3243
- cm.refresh();
3244
- }, true);
3245
- option("coverGutterNextToScrollbar", false, updateScrollbars, true);
3246
- option("lineNumbers", false, function(cm) {
3247
- setGuttersForLineNumbers(cm.options);
3248
- guttersChanged(cm);
3249
- }, true);
3250
- option("firstLineNumber", 1, guttersChanged, true);
3251
- option("lineNumberFormatter", function(integer) {return integer;}, guttersChanged, true);
3252
- option("showCursorWhenSelecting", false, updateSelection, true);
3253
-
3254
- option("readOnly", false, function(cm, val) {
3255
- if (val == "nocursor") {onBlur(cm); cm.display.input.blur();}
3256
- else if (!val) resetInput(cm, true);
3257
- });
3258
- option("dragDrop", true);
3259
-
3260
- option("cursorBlinkRate", 530);
3261
- option("cursorScrollMargin", 0);
3262
- option("cursorHeight", 1);
3263
- option("workTime", 100);
3264
- option("workDelay", 100);
3265
- option("flattenSpans", true);
3266
- option("pollInterval", 100);
3267
- option("undoDepth", 40, function(cm, val){cm.doc.history.undoDepth = val;});
3268
- option("historyEventDelay", 500);
3269
- option("viewportMargin", 10, function(cm){cm.refresh();}, true);
3270
- option("maxHighlightLength", 10000, function(cm){loadMode(cm); cm.refresh();}, true);
3271
- option("moveInputWithCursor", true, function(cm, val) {
3272
- if (!val) cm.display.inputDiv.style.top = cm.display.inputDiv.style.left = 0;
3273
- });
3274
-
3275
- option("tabindex", null, function(cm, val) {
3276
- cm.display.input.tabIndex = val || "";
3277
- });
3278
- option("autofocus", null);
3279
-
3280
- // MODE DEFINITION AND QUERYING
3281
-
3282
- // Known modes, by name and by MIME
3283
- var modes = CodeMirror.modes = {}, mimeModes = CodeMirror.mimeModes = {};
3284
-
3285
- CodeMirror.defineMode = function(name, mode) {
3286
- if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
3287
- if (arguments.length > 2) {
3288
- mode.dependencies = [];
3289
- for (var i = 2; i < arguments.length; ++i) mode.dependencies.push(arguments[i]);
3290
- }
3291
- modes[name] = mode;
3292
- };
3293
-
3294
- CodeMirror.defineMIME = function(mime, spec) {
3295
- mimeModes[mime] = spec;
3296
- };
3297
-
3298
- CodeMirror.resolveMode = function(spec) {
3299
- if (typeof spec == "string" && mimeModes.hasOwnProperty(spec)) {
3300
- spec = mimeModes[spec];
3301
- } else if (spec && typeof spec.name == "string" && mimeModes.hasOwnProperty(spec.name)) {
3302
- var found = mimeModes[spec.name];
3303
- spec = createObj(found, spec);
3304
- spec.name = found.name;
3305
- } else if (typeof spec == "string" && /^[\w\-]+\/[\w\-]+\+xml$/.test(spec)) {
3306
- return CodeMirror.resolveMode("application/xml");
3307
- }
3308
- if (typeof spec == "string") return {name: spec};
3309
- else return spec || {name: "null"};
3310
- };
3311
-
3312
- CodeMirror.getMode = function(options, spec) {
3313
- var spec = CodeMirror.resolveMode(spec);
3314
- var mfactory = modes[spec.name];
3315
- if (!mfactory) return CodeMirror.getMode(options, "text/plain");
3316
- var modeObj = mfactory(options, spec);
3317
- if (modeExtensions.hasOwnProperty(spec.name)) {
3318
- var exts = modeExtensions[spec.name];
3319
- for (var prop in exts) {
3320
- if (!exts.hasOwnProperty(prop)) continue;
3321
- if (modeObj.hasOwnProperty(prop)) modeObj["_" + prop] = modeObj[prop];
3322
- modeObj[prop] = exts[prop];
3323
- }
3324
- }
3325
- modeObj.name = spec.name;
3326
-
3327
- return modeObj;
3328
- };
3329
-
3330
- CodeMirror.defineMode("null", function() {
3331
- return {token: function(stream) {stream.skipToEnd();}};
3332
- });
3333
- CodeMirror.defineMIME("text/plain", "null");
3334
-
3335
- var modeExtensions = CodeMirror.modeExtensions = {};
3336
- CodeMirror.extendMode = function(mode, properties) {
3337
- var exts = modeExtensions.hasOwnProperty(mode) ? modeExtensions[mode] : (modeExtensions[mode] = {});
3338
- copyObj(properties, exts);
3339
- };
3340
-
3341
- // EXTENSIONS
3342
-
3343
- CodeMirror.defineExtension = function(name, func) {
3344
- CodeMirror.prototype[name] = func;
3345
- };
3346
- CodeMirror.defineDocExtension = function(name, func) {
3347
- Doc.prototype[name] = func;
3348
- };
3349
- CodeMirror.defineOption = option;
3350
-
3351
- var initHooks = [];
3352
- CodeMirror.defineInitHook = function(f) {initHooks.push(f);};
3353
-
3354
- var helpers = CodeMirror.helpers = {};
3355
- CodeMirror.registerHelper = function(type, name, value) {
3356
- if (!helpers.hasOwnProperty(type)) helpers[type] = CodeMirror[type] = {};
3357
- helpers[type][name] = value;
3358
- };
3359
-
3360
- // UTILITIES
3361
-
3362
- CodeMirror.isWordChar = isWordChar;
3363
-
3364
- // MODE STATE HANDLING
3365
-
3366
- // Utility functions for working with state. Exported because modes
3367
- // sometimes need to do this.
3368
- function copyState(mode, state) {
3369
- if (state === true) return state;
3370
- if (mode.copyState) return mode.copyState(state);
3371
- var nstate = {};
3372
- for (var n in state) {
3373
- var val = state[n];
3374
- if (val instanceof Array) val = val.concat([]);
3375
- nstate[n] = val;
3376
- }
3377
- return nstate;
3378
- }
3379
- CodeMirror.copyState = copyState;
3380
-
3381
- function startState(mode, a1, a2) {
3382
- return mode.startState ? mode.startState(a1, a2) : true;
3383
- }
3384
- CodeMirror.startState = startState;
3385
-
3386
- CodeMirror.innerMode = function(mode, state) {
3387
- while (mode.innerMode) {
3388
- var info = mode.innerMode(state);
3389
- if (!info || info.mode == mode) break;
3390
- state = info.state;
3391
- mode = info.mode;
3392
- }
3393
- return info || {mode: mode, state: state};
3394
- };
3395
-
3396
- // STANDARD COMMANDS
3397
-
3398
- var commands = CodeMirror.commands = {
3399
- selectAll: function(cm) {cm.setSelection(Pos(cm.firstLine(), 0), Pos(cm.lastLine()));},
3400
- killLine: function(cm) {
3401
- var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
3402
- if (!sel && cm.getLine(from.line).length == from.ch)
3403
- cm.replaceRange("", from, Pos(from.line + 1, 0), "+delete");
3404
- else cm.replaceRange("", from, sel ? to : Pos(from.line), "+delete");
3405
- },
3406
- deleteLine: function(cm) {
3407
- var l = cm.getCursor().line;
3408
- cm.replaceRange("", Pos(l, 0), Pos(l), "+delete");
3409
- },
3410
- delLineLeft: function(cm) {
3411
- var cur = cm.getCursor();
3412
- cm.replaceRange("", Pos(cur.line, 0), cur, "+delete");
3413
- },
3414
- undo: function(cm) {cm.undo();},
3415
- redo: function(cm) {cm.redo();},
3416
- goDocStart: function(cm) {cm.extendSelection(Pos(cm.firstLine(), 0));},
3417
- goDocEnd: function(cm) {cm.extendSelection(Pos(cm.lastLine()));},
3418
- goLineStart: function(cm) {
3419
- cm.extendSelection(lineStart(cm, cm.getCursor().line));
3420
- },
3421
- goLineStartSmart: function(cm) {
3422
- var cur = cm.getCursor(), start = lineStart(cm, cur.line);
3423
- var line = cm.getLineHandle(start.line);
3424
- var order = getOrder(line);
3425
- if (!order || order[0].level == 0) {
3426
- var firstNonWS = Math.max(0, line.text.search(/\S/));
3427
- var inWS = cur.line == start.line && cur.ch <= firstNonWS && cur.ch;
3428
- cm.extendSelection(Pos(start.line, inWS ? 0 : firstNonWS));
3429
- } else cm.extendSelection(start);
3430
- },
3431
- goLineEnd: function(cm) {
3432
- cm.extendSelection(lineEnd(cm, cm.getCursor().line));
3433
- },
3434
- goLineRight: function(cm) {
3435
- var top = cm.charCoords(cm.getCursor(), "div").top + 5;
3436
- cm.extendSelection(cm.coordsChar({left: cm.display.lineDiv.offsetWidth + 100, top: top}, "div"));
3437
- },
3438
- goLineLeft: function(cm) {
3439
- var top = cm.charCoords(cm.getCursor(), "div").top + 5;
3440
- cm.extendSelection(cm.coordsChar({left: 0, top: top}, "div"));
3441
- },
3442
- goLineUp: function(cm) {cm.moveV(-1, "line");},
3443
- goLineDown: function(cm) {cm.moveV(1, "line");},
3444
- goPageUp: function(cm) {cm.moveV(-1, "page");},
3445
- goPageDown: function(cm) {cm.moveV(1, "page");},
3446
- goCharLeft: function(cm) {cm.moveH(-1, "char");},
3447
- goCharRight: function(cm) {cm.moveH(1, "char");},
3448
- goColumnLeft: function(cm) {cm.moveH(-1, "column");},
3449
- goColumnRight: function(cm) {cm.moveH(1, "column");},
3450
- goWordLeft: function(cm) {cm.moveH(-1, "word");},
3451
- goGroupRight: function(cm) {cm.moveH(1, "group");},
3452
- goGroupLeft: function(cm) {cm.moveH(-1, "group");},
3453
- goWordRight: function(cm) {cm.moveH(1, "word");},
3454
- delCharBefore: function(cm) {cm.deleteH(-1, "char");},
3455
- delCharAfter: function(cm) {cm.deleteH(1, "char");},
3456
- delWordBefore: function(cm) {cm.deleteH(-1, "word");},
3457
- delWordAfter: function(cm) {cm.deleteH(1, "word");},
3458
- delGroupBefore: function(cm) {cm.deleteH(-1, "group");},
3459
- delGroupAfter: function(cm) {cm.deleteH(1, "group");},
3460
- indentAuto: function(cm) {cm.indentSelection("smart");},
3461
- indentMore: function(cm) {cm.indentSelection("add");},
3462
- indentLess: function(cm) {cm.indentSelection("subtract");},
3463
- insertTab: function(cm) {cm.replaceSelection("\t", "end", "+input");},
3464
- defaultTab: function(cm) {
3465
- if (cm.somethingSelected()) cm.indentSelection("add");
3466
- else cm.replaceSelection("\t", "end", "+input");
3467
- },
3468
- transposeChars: function(cm) {
3469
- var cur = cm.getCursor(), line = cm.getLine(cur.line);
3470
- if (cur.ch > 0 && cur.ch < line.length - 1)
3471
- cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
3472
- Pos(cur.line, cur.ch - 1), Pos(cur.line, cur.ch + 1));
3473
- },
3474
- newlineAndIndent: function(cm) {
3475
- operation(cm, function() {
3476
- cm.replaceSelection("\n", "end", "+input");
3477
- cm.indentLine(cm.getCursor().line, null, true);
3478
- })();
3479
- },
3480
- toggleOverwrite: function(cm) {cm.toggleOverwrite();}
3481
- };
3482
-
3483
- // STANDARD KEYMAPS
3484
-
3485
- var keyMap = CodeMirror.keyMap = {};
3486
- keyMap.basic = {
3487
- "Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
3488
- "End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
3489
- "Delete": "delCharAfter", "Backspace": "delCharBefore", "Tab": "defaultTab", "Shift-Tab": "indentAuto",
3490
- "Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
3491
- };
3492
- // Note that the save and find-related commands aren't defined by
3493
- // default. Unknown commands are simply ignored.
3494
- keyMap.pcDefault = {
3495
- "Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
3496
- "Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
3497
- "Ctrl-Left": "goGroupLeft", "Ctrl-Right": "goGroupRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
3498
- "Ctrl-Backspace": "delGroupBefore", "Ctrl-Delete": "delGroupAfter", "Ctrl-S": "save", "Ctrl-F": "find",
3499
- "Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
3500
- "Ctrl-[": "indentLess", "Ctrl-]": "indentMore",
3501
- fallthrough: "basic"
3502
- };
3503
- keyMap.macDefault = {
3504
- "Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
3505
- "Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goGroupLeft",
3506
- "Alt-Right": "goGroupRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delGroupBefore",
3507
- "Ctrl-Alt-Backspace": "delGroupAfter", "Alt-Delete": "delGroupAfter", "Cmd-S": "save", "Cmd-F": "find",
3508
- "Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
3509
- "Cmd-[": "indentLess", "Cmd-]": "indentMore", "Cmd-Backspace": "delLineLeft",
3510
- fallthrough: ["basic", "emacsy"]
3511
- };
3512
- keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
3513
- keyMap.emacsy = {
3514
- "Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
3515
- "Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
3516
- "Ctrl-V": "goPageDown", "Shift-Ctrl-V": "goPageUp", "Ctrl-D": "delCharAfter", "Ctrl-H": "delCharBefore",
3517
- "Alt-D": "delWordAfter", "Alt-Backspace": "delWordBefore", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
3518
- };
3519
-
3520
- // KEYMAP DISPATCH
3521
-
3522
- function getKeyMap(val) {
3523
- if (typeof val == "string") return keyMap[val];
3524
- else return val;
3525
- }
3526
-
3527
- function lookupKey(name, maps, handle) {
3528
- function lookup(map) {
3529
- map = getKeyMap(map);
3530
- var found = map[name];
3531
- if (found === false) return "stop";
3532
- if (found != null && handle(found)) return true;
3533
- if (map.nofallthrough) return "stop";
3534
-
3535
- var fallthrough = map.fallthrough;
3536
- if (fallthrough == null) return false;
3537
- if (Object.prototype.toString.call(fallthrough) != "[object Array]")
3538
- return lookup(fallthrough);
3539
- for (var i = 0, e = fallthrough.length; i < e; ++i) {
3540
- var done = lookup(fallthrough[i]);
3541
- if (done) return done;
3542
- }
3543
- return false;
3544
- }
3545
-
3546
- for (var i = 0; i < maps.length; ++i) {
3547
- var done = lookup(maps[i]);
3548
- if (done) return done != "stop";
3549
- }
3550
- }
3551
- function isModifierKey(event) {
3552
- var name = keyNames[event.keyCode];
3553
- return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
3554
- }
3555
- function keyName(event, noShift) {
3556
- if (opera && event.keyCode == 34 && event["char"]) return false;
3557
- var name = keyNames[event.keyCode];
3558
- if (name == null || event.altGraphKey) return false;
3559
- if (event.altKey) name = "Alt-" + name;
3560
- if (flipCtrlCmd ? event.metaKey : event.ctrlKey) name = "Ctrl-" + name;
3561
- if (flipCtrlCmd ? event.ctrlKey : event.metaKey) name = "Cmd-" + name;
3562
- if (!noShift && event.shiftKey) name = "Shift-" + name;
3563
- return name;
3564
- }
3565
- CodeMirror.lookupKey = lookupKey;
3566
- CodeMirror.isModifierKey = isModifierKey;
3567
- CodeMirror.keyName = keyName;
3568
-
3569
- // FROMTEXTAREA
3570
-
3571
- CodeMirror.fromTextArea = function(textarea, options) {
3572
- if (!options) options = {};
3573
- options.value = textarea.value;
3574
- if (!options.tabindex && textarea.tabindex)
3575
- options.tabindex = textarea.tabindex;
3576
- if (!options.placeholder && textarea.placeholder)
3577
- options.placeholder = textarea.placeholder;
3578
- // Set autofocus to true if this textarea is focused, or if it has
3579
- // autofocus and no other element is focused.
3580
- if (options.autofocus == null) {
3581
- var hasFocus = document.body;
3582
- // doc.activeElement occasionally throws on IE
3583
- try { hasFocus = document.activeElement; } catch(e) {}
3584
- options.autofocus = hasFocus == textarea ||
3585
- textarea.getAttribute("autofocus") != null && hasFocus == document.body;
3586
- }
3587
-
3588
- function save() {textarea.value = cm.getValue();}
3589
- if (textarea.form) {
3590
- on(textarea.form, "submit", save);
3591
- // Deplorable hack to make the submit method do the right thing.
3592
- if (!options.leaveSubmitMethodAlone) {
3593
- var form = textarea.form, realSubmit = form.submit;
3594
- try {
3595
- var wrappedSubmit = form.submit = function() {
3596
- save();
3597
- form.submit = realSubmit;
3598
- form.submit();
3599
- form.submit = wrappedSubmit;
3600
- };
3601
- } catch(e) {}
3602
- }
3603
- }
3604
-
3605
- textarea.style.display = "none";
3606
- var cm = CodeMirror(function(node) {
3607
- textarea.parentNode.insertBefore(node, textarea.nextSibling);
3608
- }, options);
3609
- cm.save = save;
3610
- cm.getTextArea = function() { return textarea; };
3611
- cm.toTextArea = function() {
3612
- save();
3613
- textarea.parentNode.removeChild(cm.getWrapperElement());
3614
- textarea.style.display = "";
3615
- if (textarea.form) {
3616
- off(textarea.form, "submit", save);
3617
- if (typeof textarea.form.submit == "function")
3618
- textarea.form.submit = realSubmit;
3619
- }
3620
- };
3621
- return cm;
3622
- };
3623
-
3624
- // STRING STREAM
3625
-
3626
- // Fed to the mode parsers, provides helper functions to make
3627
- // parsers more succinct.
3628
-
3629
- // The character stream used by a mode's parser.
3630
- function StringStream(string, tabSize) {
3631
- this.pos = this.start = 0;
3632
- this.string = string;
3633
- this.tabSize = tabSize || 8;
3634
- this.lastColumnPos = this.lastColumnValue = 0;
3635
- }
3636
-
3637
- StringStream.prototype = {
3638
- eol: function() {return this.pos >= this.string.length;},
3639
- sol: function() {return this.pos == 0;},
3640
- peek: function() {return this.string.charAt(this.pos) || undefined;},
3641
- next: function() {
3642
- if (this.pos < this.string.length)
3643
- return this.string.charAt(this.pos++);
3644
- },
3645
- eat: function(match) {
3646
- var ch = this.string.charAt(this.pos);
3647
- if (typeof match == "string") var ok = ch == match;
3648
- else var ok = ch && (match.test ? match.test(ch) : match(ch));
3649
- if (ok) {++this.pos; return ch;}
3650
- },
3651
- eatWhile: function(match) {
3652
- var start = this.pos;
3653
- while (this.eat(match)){}
3654
- return this.pos > start;
3655
- },
3656
- eatSpace: function() {
3657
- var start = this.pos;
3658
- while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
3659
- return this.pos > start;
3660
- },
3661
- skipToEnd: function() {this.pos = this.string.length;},
3662
- skipTo: function(ch) {
3663
- var found = this.string.indexOf(ch, this.pos);
3664
- if (found > -1) {this.pos = found; return true;}
3665
- },
3666
- backUp: function(n) {this.pos -= n;},
3667
- column: function() {
3668
- if (this.lastColumnPos < this.start) {
3669
- this.lastColumnValue = countColumn(this.string, this.start, this.tabSize, this.lastColumnPos, this.lastColumnValue);
3670
- this.lastColumnPos = this.start;
3671
- }
3672
- return this.lastColumnValue;
3673
- },
3674
- indentation: function() {return countColumn(this.string, null, this.tabSize);},
3675
- match: function(pattern, consume, caseInsensitive) {
3676
- if (typeof pattern == "string") {
3677
- var cased = function(str) {return caseInsensitive ? str.toLowerCase() : str;};
3678
- var substr = this.string.substr(this.pos, pattern.length);
3679
- if (cased(substr) == cased(pattern)) {
3680
- if (consume !== false) this.pos += pattern.length;
3681
- return true;
3682
- }
3683
- } else {
3684
- var match = this.string.slice(this.pos).match(pattern);
3685
- if (match && match.index > 0) return null;
3686
- if (match && consume !== false) this.pos += match[0].length;
3687
- return match;
3688
- }
3689
- },
3690
- current: function(){return this.string.slice(this.start, this.pos);}
3691
- };
3692
- CodeMirror.StringStream = StringStream;
3693
-
3694
- // TEXTMARKERS
3695
-
3696
- function TextMarker(doc, type) {
3697
- this.lines = [];
3698
- this.type = type;
3699
- this.doc = doc;
3700
- }
3701
- CodeMirror.TextMarker = TextMarker;
3702
- eventMixin(TextMarker);
3703
-
3704
- TextMarker.prototype.clear = function() {
3705
- if (this.explicitlyCleared) return;
3706
- var cm = this.doc.cm, withOp = cm && !cm.curOp;
3707
- if (withOp) startOperation(cm);
3708
- if (hasHandler(this, "clear")) {
3709
- var found = this.find();
3710
- if (found) signalLater(this, "clear", found.from, found.to);
3711
- }
3712
- var min = null, max = null;
3713
- for (var i = 0; i < this.lines.length; ++i) {
3714
- var line = this.lines[i];
3715
- var span = getMarkedSpanFor(line.markedSpans, this);
3716
- if (span.to != null) max = lineNo(line);
3717
- line.markedSpans = removeMarkedSpan(line.markedSpans, span);
3718
- if (span.from != null)
3719
- min = lineNo(line);
3720
- else if (this.collapsed && !lineIsHidden(this.doc, line) && cm)
3721
- updateLineHeight(line, textHeight(cm.display));
3722
- }
3723
- if (cm && this.collapsed && !cm.options.lineWrapping) for (var i = 0; i < this.lines.length; ++i) {
3724
- var visual = visualLine(cm.doc, this.lines[i]), len = lineLength(cm.doc, visual);
3725
- if (len > cm.display.maxLineLength) {
3726
- cm.display.maxLine = visual;
3727
- cm.display.maxLineLength = len;
3728
- cm.display.maxLineChanged = true;
3729
- }
3730
- }
3731
-
3732
- if (min != null && cm) regChange(cm, min, max + 1);
3733
- this.lines.length = 0;
3734
- this.explicitlyCleared = true;
3735
- if (this.atomic && this.doc.cantEdit) {
3736
- this.doc.cantEdit = false;
3737
- if (cm) reCheckSelection(cm);
3738
- }
3739
- if (withOp) endOperation(cm);
3740
- };
3741
-
3742
- TextMarker.prototype.find = function() {
3743
- var from, to;
3744
- for (var i = 0; i < this.lines.length; ++i) {
3745
- var line = this.lines[i];
3746
- var span = getMarkedSpanFor(line.markedSpans, this);
3747
- if (span.from != null || span.to != null) {
3748
- var found = lineNo(line);
3749
- if (span.from != null) from = Pos(found, span.from);
3750
- if (span.to != null) to = Pos(found, span.to);
3751
- }
3752
- }
3753
- if (this.type == "bookmark") return from;
3754
- return from && {from: from, to: to};
3755
- };
3756
-
3757
- TextMarker.prototype.changed = function() {
3758
- var pos = this.find(), cm = this.doc.cm;
3759
- if (!pos || !cm) return;
3760
- if (this.type != "bookmark") pos = pos.from;
3761
- var line = getLine(this.doc, pos.line);
3762
- clearCachedMeasurement(cm, line);
3763
- if (pos.line >= cm.display.showingFrom && pos.line < cm.display.showingTo) {
3764
- for (var node = cm.display.lineDiv.firstChild; node; node = node.nextSibling) if (node.lineObj == line) {
3765
- if (node.offsetHeight != line.height) updateLineHeight(line, node.offsetHeight);
3766
- break;
3767
- }
3768
- runInOp(cm, function() {
3769
- cm.curOp.selectionChanged = cm.curOp.forceUpdate = cm.curOp.updateMaxLine = true;
3770
- });
3771
- }
3772
- };
3773
-
3774
- TextMarker.prototype.attachLine = function(line) {
3775
- if (!this.lines.length && this.doc.cm) {
3776
- var op = this.doc.cm.curOp;
3777
- if (!op.maybeHiddenMarkers || indexOf(op.maybeHiddenMarkers, this) == -1)
3778
- (op.maybeUnhiddenMarkers || (op.maybeUnhiddenMarkers = [])).push(this);
3779
- }
3780
- this.lines.push(line);
3781
- };
3782
- TextMarker.prototype.detachLine = function(line) {
3783
- this.lines.splice(indexOf(this.lines, line), 1);
3784
- if (!this.lines.length && this.doc.cm) {
3785
- var op = this.doc.cm.curOp;
3786
- (op.maybeHiddenMarkers || (op.maybeHiddenMarkers = [])).push(this);
3787
- }
3788
- };
3789
-
3790
- function markText(doc, from, to, options, type) {
3791
- if (options && options.shared) return markTextShared(doc, from, to, options, type);
3792
- if (doc.cm && !doc.cm.curOp) return operation(doc.cm, markText)(doc, from, to, options, type);
3793
-
3794
- var marker = new TextMarker(doc, type);
3795
- if (type == "range" && !posLess(from, to)) return marker;
3796
- if (options) copyObj(options, marker);
3797
- if (marker.replacedWith) {
3798
- marker.collapsed = true;
3799
- marker.replacedWith = elt("span", [marker.replacedWith], "CodeMirror-widget");
3800
- if (!options.handleMouseEvents) marker.replacedWith.ignoreEvents = true;
3801
- }
3802
- if (marker.collapsed) sawCollapsedSpans = true;
3803
-
3804
- if (marker.addToHistory)
3805
- addToHistory(doc, {from: from, to: to, origin: "markText"},
3806
- {head: doc.sel.head, anchor: doc.sel.anchor}, NaN);
3807
-
3808
- var curLine = from.line, size = 0, collapsedAtStart, collapsedAtEnd, cm = doc.cm, updateMaxLine;
3809
- doc.iter(curLine, to.line + 1, function(line) {
3810
- if (cm && marker.collapsed && !cm.options.lineWrapping && visualLine(doc, line) == cm.display.maxLine)
3811
- updateMaxLine = true;
3812
- var span = {from: null, to: null, marker: marker};
3813
- size += line.text.length;
3814
- if (curLine == from.line) {span.from = from.ch; size -= from.ch;}
3815
- if (curLine == to.line) {span.to = to.ch; size -= line.text.length - to.ch;}
3816
- if (marker.collapsed) {
3817
- if (curLine == to.line) collapsedAtEnd = collapsedSpanAt(line, to.ch);
3818
- if (curLine == from.line) collapsedAtStart = collapsedSpanAt(line, from.ch);
3819
- else updateLineHeight(line, 0);
3820
- }
3821
- addMarkedSpan(line, span);
3822
- ++curLine;
3823
- });
3824
- if (marker.collapsed) doc.iter(from.line, to.line + 1, function(line) {
3825
- if (lineIsHidden(doc, line)) updateLineHeight(line, 0);
3826
- });
3827
-
3828
- if (marker.clearOnEnter) on(marker, "beforeCursorEnter", function() { marker.clear(); });
3829
-
3830
- if (marker.readOnly) {
3831
- sawReadOnlySpans = true;
3832
- if (doc.history.done.length || doc.history.undone.length)
3833
- doc.clearHistory();
3834
- }
3835
- if (marker.collapsed) {
3836
- if (collapsedAtStart != collapsedAtEnd)
3837
- throw new Error("Inserting collapsed marker overlapping an existing one");
3838
- marker.size = size;
3839
- marker.atomic = true;
3840
- }
3841
- if (cm) {
3842
- if (updateMaxLine) cm.curOp.updateMaxLine = true;
3843
- if (marker.className || marker.title || marker.startStyle || marker.endStyle || marker.collapsed)
3844
- regChange(cm, from.line, to.line + 1);
3845
- if (marker.atomic) reCheckSelection(cm);
3846
- }
3847
- return marker;
3848
- }
3849
-
3850
- // SHARED TEXTMARKERS
3851
-
3852
- function SharedTextMarker(markers, primary) {
3853
- this.markers = markers;
3854
- this.primary = primary;
3855
- for (var i = 0, me = this; i < markers.length; ++i) {
3856
- markers[i].parent = this;
3857
- on(markers[i], "clear", function(){me.clear();});
3858
- }
3859
- }
3860
- CodeMirror.SharedTextMarker = SharedTextMarker;
3861
- eventMixin(SharedTextMarker);
3862
-
3863
- SharedTextMarker.prototype.clear = function() {
3864
- if (this.explicitlyCleared) return;
3865
- this.explicitlyCleared = true;
3866
- for (var i = 0; i < this.markers.length; ++i)
3867
- this.markers[i].clear();
3868
- signalLater(this, "clear");
3869
- };
3870
- SharedTextMarker.prototype.find = function() {
3871
- return this.primary.find();
3872
- };
3873
-
3874
- function markTextShared(doc, from, to, options, type) {
3875
- options = copyObj(options);
3876
- options.shared = false;
3877
- var markers = [markText(doc, from, to, options, type)], primary = markers[0];
3878
- var widget = options.replacedWith;
3879
- linkedDocs(doc, function(doc) {
3880
- if (widget) options.replacedWith = widget.cloneNode(true);
3881
- markers.push(markText(doc, clipPos(doc, from), clipPos(doc, to), options, type));
3882
- for (var i = 0; i < doc.linked.length; ++i)
3883
- if (doc.linked[i].isParent) return;
3884
- primary = lst(markers);
3885
- });
3886
- return new SharedTextMarker(markers, primary);
3887
- }
3888
-
3889
- // TEXTMARKER SPANS
3890
-
3891
- function getMarkedSpanFor(spans, marker) {
3892
- if (spans) for (var i = 0; i < spans.length; ++i) {
3893
- var span = spans[i];
3894
- if (span.marker == marker) return span;
3895
- }
3896
- }
3897
- function removeMarkedSpan(spans, span) {
3898
- for (var r, i = 0; i < spans.length; ++i)
3899
- if (spans[i] != span) (r || (r = [])).push(spans[i]);
3900
- return r;
3901
- }
3902
- function addMarkedSpan(line, span) {
3903
- line.markedSpans = line.markedSpans ? line.markedSpans.concat([span]) : [span];
3904
- span.marker.attachLine(line);
3905
- }
3906
-
3907
- function markedSpansBefore(old, startCh, isInsert) {
3908
- if (old) for (var i = 0, nw; i < old.length; ++i) {
3909
- var span = old[i], marker = span.marker;
3910
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= startCh : span.from < startCh);
3911
- if (startsBefore || marker.type == "bookmark" && span.from == startCh && (!isInsert || !span.marker.insertLeft)) {
3912
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= startCh : span.to > startCh);
3913
- (nw || (nw = [])).push({from: span.from,
3914
- to: endsAfter ? null : span.to,
3915
- marker: marker});
3916
- }
3917
- }
3918
- return nw;
3919
- }
3920
-
3921
- function markedSpansAfter(old, endCh, isInsert) {
3922
- if (old) for (var i = 0, nw; i < old.length; ++i) {
3923
- var span = old[i], marker = span.marker;
3924
- var endsAfter = span.to == null || (marker.inclusiveRight ? span.to >= endCh : span.to > endCh);
3925
- if (endsAfter || marker.type == "bookmark" && span.from == endCh && (!isInsert || span.marker.insertLeft)) {
3926
- var startsBefore = span.from == null || (marker.inclusiveLeft ? span.from <= endCh : span.from < endCh);
3927
- (nw || (nw = [])).push({from: startsBefore ? null : span.from - endCh,
3928
- to: span.to == null ? null : span.to - endCh,
3929
- marker: marker});
3930
- }
3931
- }
3932
- return nw;
3933
- }
3934
-
3935
- function stretchSpansOverChange(doc, change) {
3936
- var oldFirst = isLine(doc, change.from.line) && getLine(doc, change.from.line).markedSpans;
3937
- var oldLast = isLine(doc, change.to.line) && getLine(doc, change.to.line).markedSpans;
3938
- if (!oldFirst && !oldLast) return null;
3939
-
3940
- var startCh = change.from.ch, endCh = change.to.ch, isInsert = posEq(change.from, change.to);
3941
- // Get the spans that 'stick out' on both sides
3942
- var first = markedSpansBefore(oldFirst, startCh, isInsert);
3943
- var last = markedSpansAfter(oldLast, endCh, isInsert);
3944
-
3945
- // Next, merge those two ends
3946
- var sameLine = change.text.length == 1, offset = lst(change.text).length + (sameLine ? startCh : 0);
3947
- if (first) {
3948
- // Fix up .to properties of first
3949
- for (var i = 0; i < first.length; ++i) {
3950
- var span = first[i];
3951
- if (span.to == null) {
3952
- var found = getMarkedSpanFor(last, span.marker);
3953
- if (!found) span.to = startCh;
3954
- else if (sameLine) span.to = found.to == null ? null : found.to + offset;
3955
- }
3956
- }
3957
- }
3958
- if (last) {
3959
- // Fix up .from in last (or move them into first in case of sameLine)
3960
- for (var i = 0; i < last.length; ++i) {
3961
- var span = last[i];
3962
- if (span.to != null) span.to += offset;
3963
- if (span.from == null) {
3964
- var found = getMarkedSpanFor(first, span.marker);
3965
- if (!found) {
3966
- span.from = offset;
3967
- if (sameLine) (first || (first = [])).push(span);
3968
- }
3969
- } else {
3970
- span.from += offset;
3971
- if (sameLine) (first || (first = [])).push(span);
3972
- }
3973
- }
3974
- }
3975
- if (sameLine && first) {
3976
- // Make sure we didn't create any zero-length spans
3977
- for (var i = 0; i < first.length; ++i)
3978
- if (first[i].from != null && first[i].from == first[i].to && first[i].marker.type != "bookmark")
3979
- first.splice(i--, 1);
3980
- if (!first.length) first = null;
3981
- }
3982
-
3983
- var newMarkers = [first];
3984
- if (!sameLine) {
3985
- // Fill gap with whole-line-spans
3986
- var gap = change.text.length - 2, gapMarkers;
3987
- if (gap > 0 && first)
3988
- for (var i = 0; i < first.length; ++i)
3989
- if (first[i].to == null)
3990
- (gapMarkers || (gapMarkers = [])).push({from: null, to: null, marker: first[i].marker});
3991
- for (var i = 0; i < gap; ++i)
3992
- newMarkers.push(gapMarkers);
3993
- newMarkers.push(last);
3994
- }
3995
- return newMarkers;
3996
- }
3997
-
3998
- function mergeOldSpans(doc, change) {
3999
- var old = getOldSpans(doc, change);
4000
- var stretched = stretchSpansOverChange(doc, change);
4001
- if (!old) return stretched;
4002
- if (!stretched) return old;
4003
-
4004
- for (var i = 0; i < old.length; ++i) {
4005
- var oldCur = old[i], stretchCur = stretched[i];
4006
- if (oldCur && stretchCur) {
4007
- spans: for (var j = 0; j < stretchCur.length; ++j) {
4008
- var span = stretchCur[j];
4009
- for (var k = 0; k < oldCur.length; ++k)
4010
- if (oldCur[k].marker == span.marker) continue spans;
4011
- oldCur.push(span);
4012
- }
4013
- } else if (stretchCur) {
4014
- old[i] = stretchCur;
4015
- }
4016
- }
4017
- return old;
4018
- }
4019
-
4020
- function removeReadOnlyRanges(doc, from, to) {
4021
- var markers = null;
4022
- doc.iter(from.line, to.line + 1, function(line) {
4023
- if (line.markedSpans) for (var i = 0; i < line.markedSpans.length; ++i) {
4024
- var mark = line.markedSpans[i].marker;
4025
- if (mark.readOnly && (!markers || indexOf(markers, mark) == -1))
4026
- (markers || (markers = [])).push(mark);
4027
- }
4028
- });
4029
- if (!markers) return null;
4030
- var parts = [{from: from, to: to}];
4031
- for (var i = 0; i < markers.length; ++i) {
4032
- var mk = markers[i], m = mk.find();
4033
- for (var j = 0; j < parts.length; ++j) {
4034
- var p = parts[j];
4035
- if (posLess(p.to, m.from) || posLess(m.to, p.from)) continue;
4036
- var newParts = [j, 1];
4037
- if (posLess(p.from, m.from) || !mk.inclusiveLeft && posEq(p.from, m.from))
4038
- newParts.push({from: p.from, to: m.from});
4039
- if (posLess(m.to, p.to) || !mk.inclusiveRight && posEq(p.to, m.to))
4040
- newParts.push({from: m.to, to: p.to});
4041
- parts.splice.apply(parts, newParts);
4042
- j += newParts.length - 1;
4043
- }
4044
- }
4045
- return parts;
4046
- }
4047
-
4048
- function collapsedSpanAt(line, ch) {
4049
- var sps = sawCollapsedSpans && line.markedSpans, found;
4050
- if (sps) for (var sp, i = 0; i < sps.length; ++i) {
4051
- sp = sps[i];
4052
- if (!sp.marker.collapsed) continue;
4053
- if ((sp.from == null || sp.from < ch) &&
4054
- (sp.to == null || sp.to > ch) &&
4055
- (!found || found.width < sp.marker.width))
4056
- found = sp.marker;
4057
- }
4058
- return found;
4059
- }
4060
- function collapsedSpanAtStart(line) { return collapsedSpanAt(line, -1); }
4061
- function collapsedSpanAtEnd(line) { return collapsedSpanAt(line, line.text.length + 1); }
4062
-
4063
- function visualLine(doc, line) {
4064
- var merged;
4065
- while (merged = collapsedSpanAtStart(line))
4066
- line = getLine(doc, merged.find().from.line);
4067
- return line;
4068
- }
4069
-
4070
- function lineIsHidden(doc, line) {
4071
- var sps = sawCollapsedSpans && line.markedSpans;
4072
- if (sps) for (var sp, i = 0; i < sps.length; ++i) {
4073
- sp = sps[i];
4074
- if (!sp.marker.collapsed) continue;
4075
- if (sp.from == null) return true;
4076
- if (sp.marker.replacedWith) continue;
4077
- if (sp.from == 0 && sp.marker.inclusiveLeft && lineIsHiddenInner(doc, line, sp))
4078
- return true;
4079
- }
4080
- }
4081
- function lineIsHiddenInner(doc, line, span) {
4082
- if (span.to == null) {
4083
- var end = span.marker.find().to, endLine = getLine(doc, end.line);
4084
- return lineIsHiddenInner(doc, endLine, getMarkedSpanFor(endLine.markedSpans, span.marker));
4085
- }
4086
- if (span.marker.inclusiveRight && span.to == line.text.length)
4087
- return true;
4088
- for (var sp, i = 0; i < line.markedSpans.length; ++i) {
4089
- sp = line.markedSpans[i];
4090
- if (sp.marker.collapsed && !sp.marker.replacedWith && sp.from == span.to &&
4091
- (sp.marker.inclusiveLeft || span.marker.inclusiveRight) &&
4092
- lineIsHiddenInner(doc, line, sp)) return true;
4093
- }
4094
- }
4095
-
4096
- function detachMarkedSpans(line) {
4097
- var spans = line.markedSpans;
4098
- if (!spans) return;
4099
- for (var i = 0; i < spans.length; ++i)
4100
- spans[i].marker.detachLine(line);
4101
- line.markedSpans = null;
4102
- }
4103
-
4104
- function attachMarkedSpans(line, spans) {
4105
- if (!spans) return;
4106
- for (var i = 0; i < spans.length; ++i)
4107
- spans[i].marker.attachLine(line);
4108
- line.markedSpans = spans;
4109
- }
4110
-
4111
- // LINE WIDGETS
4112
-
4113
- var LineWidget = CodeMirror.LineWidget = function(cm, node, options) {
4114
- if (options) for (var opt in options) if (options.hasOwnProperty(opt))
4115
- this[opt] = options[opt];
4116
- this.cm = cm;
4117
- this.node = node;
4118
- };
4119
- eventMixin(LineWidget);
4120
- function widgetOperation(f) {
4121
- return function() {
4122
- var withOp = !this.cm.curOp;
4123
- if (withOp) startOperation(this.cm);
4124
- try {var result = f.apply(this, arguments);}
4125
- finally {if (withOp) endOperation(this.cm);}
4126
- return result;
4127
- };
4128
- }
4129
- LineWidget.prototype.clear = widgetOperation(function() {
4130
- var ws = this.line.widgets, no = lineNo(this.line);
4131
- if (no == null || !ws) return;
4132
- for (var i = 0; i < ws.length; ++i) if (ws[i] == this) ws.splice(i--, 1);
4133
- if (!ws.length) this.line.widgets = null;
4134
- var aboveVisible = heightAtLine(this.cm, this.line) < this.cm.doc.scrollTop;
4135
- updateLineHeight(this.line, Math.max(0, this.line.height - widgetHeight(this)));
4136
- if (aboveVisible) addToScrollPos(this.cm, 0, -this.height);
4137
- regChange(this.cm, no, no + 1);
4138
- });
4139
- LineWidget.prototype.changed = widgetOperation(function() {
4140
- var oldH = this.height;
4141
- this.height = null;
4142
- var diff = widgetHeight(this) - oldH;
4143
- if (!diff) return;
4144
- updateLineHeight(this.line, this.line.height + diff);
4145
- var no = lineNo(this.line);
4146
- regChange(this.cm, no, no + 1);
4147
- });
4148
-
4149
- function widgetHeight(widget) {
4150
- if (widget.height != null) return widget.height;
4151
- if (!widget.node.parentNode || widget.node.parentNode.nodeType != 1)
4152
- removeChildrenAndAdd(widget.cm.display.measure, elt("div", [widget.node], null, "position: relative"));
4153
- return widget.height = widget.node.offsetHeight;
4154
- }
4155
-
4156
- function addLineWidget(cm, handle, node, options) {
4157
- var widget = new LineWidget(cm, node, options);
4158
- if (widget.noHScroll) cm.display.alignWidgets = true;
4159
- changeLine(cm, handle, function(line) {
4160
- var widgets = line.widgets || (line.widgets = []);
4161
- if (widget.insertAt == null) widgets.push(widget);
4162
- else widgets.splice(Math.min(widgets.length - 1, Math.max(0, widget.insertAt)), 0, widget);
4163
- widget.line = line;
4164
- if (!lineIsHidden(cm.doc, line) || widget.showIfHidden) {
4165
- var aboveVisible = heightAtLine(cm, line) < cm.doc.scrollTop;
4166
- updateLineHeight(line, line.height + widgetHeight(widget));
4167
- if (aboveVisible) addToScrollPos(cm, 0, widget.height);
4168
- }
4169
- return true;
4170
- });
4171
- return widget;
4172
- }
4173
-
4174
- // LINE DATA STRUCTURE
4175
-
4176
- // Line objects. These hold state related to a line, including
4177
- // highlighting info (the styles array).
4178
- var Line = CodeMirror.Line = function(text, markedSpans, estimateHeight) {
4179
- this.text = text;
4180
- attachMarkedSpans(this, markedSpans);
4181
- this.height = estimateHeight ? estimateHeight(this) : 1;
4182
- };
4183
- eventMixin(Line);
4184
-
4185
- function updateLine(line, text, markedSpans, estimateHeight) {
4186
- line.text = text;
4187
- if (line.stateAfter) line.stateAfter = null;
4188
- if (line.styles) line.styles = null;
4189
- if (line.order != null) line.order = null;
4190
- detachMarkedSpans(line);
4191
- attachMarkedSpans(line, markedSpans);
4192
- var estHeight = estimateHeight ? estimateHeight(line) : 1;
4193
- if (estHeight != line.height) updateLineHeight(line, estHeight);
4194
- }
4195
-
4196
- function cleanUpLine(line) {
4197
- line.parent = null;
4198
- detachMarkedSpans(line);
4199
- }
4200
-
4201
- // Run the given mode's parser over a line, update the styles
4202
- // array, which contains alternating fragments of text and CSS
4203
- // classes.
4204
- function runMode(cm, text, mode, state, f) {
4205
- var flattenSpans = mode.flattenSpans;
4206
- if (flattenSpans == null) flattenSpans = cm.options.flattenSpans;
4207
- var curStart = 0, curStyle = null;
4208
- var stream = new StringStream(text, cm.options.tabSize), style;
4209
- if (text == "" && mode.blankLine) mode.blankLine(state);
4210
- while (!stream.eol()) {
4211
- if (stream.pos > cm.options.maxHighlightLength) {
4212
- flattenSpans = false;
4213
- // Webkit seems to refuse to render text nodes longer than 57444 characters
4214
- stream.pos = Math.min(text.length, stream.start + 50000);
4215
- style = null;
4216
- } else {
4217
- style = mode.token(stream, state);
4218
- }
4219
- if (!flattenSpans || curStyle != style) {
4220
- if (curStart < stream.start) f(stream.start, curStyle);
4221
- curStart = stream.start; curStyle = style;
4222
- }
4223
- stream.start = stream.pos;
4224
- }
4225
- if (curStart < stream.pos) f(stream.pos, curStyle);
4226
- }
4227
-
4228
- function highlightLine(cm, line, state) {
4229
- // A styles array always starts with a number identifying the
4230
- // mode/overlays that it is based on (for easy invalidation).
4231
- var st = [cm.state.modeGen];
4232
- // Compute the base array of styles
4233
- runMode(cm, line.text, cm.doc.mode, state, function(end, style) {st.push(end, style);});
4234
-
4235
- // Run overlays, adjust style array.
4236
- for (var o = 0; o < cm.state.overlays.length; ++o) {
4237
- var overlay = cm.state.overlays[o], i = 1, at = 0;
4238
- runMode(cm, line.text, overlay.mode, true, function(end, style) {
4239
- var start = i;
4240
- // Ensure there's a token end at the current position, and that i points at it
4241
- while (at < end) {
4242
- var i_end = st[i];
4243
- if (i_end > end)
4244
- st.splice(i, 1, end, st[i+1], i_end);
4245
- i += 2;
4246
- at = Math.min(end, i_end);
4247
- }
4248
- if (!style) return;
4249
- if (overlay.opaque) {
4250
- st.splice(start, i - start, end, style);
4251
- i = start + 2;
4252
- } else {
4253
- for (; start < i; start += 2) {
4254
- var cur = st[start+1];
4255
- st[start+1] = cur ? cur + " " + style : style;
4256
- }
4257
- }
4258
- });
4259
- }
4260
-
4261
- return st;
4262
- }
4263
-
4264
- function getLineStyles(cm, line) {
4265
- if (!line.styles || line.styles[0] != cm.state.modeGen)
4266
- line.styles = highlightLine(cm, line, line.stateAfter = getStateBefore(cm, lineNo(line)));
4267
- return line.styles;
4268
- }
4269
-
4270
- // Lightweight form of highlight -- proceed over this line and
4271
- // update state, but don't save a style array.
4272
- function processLine(cm, line, state) {
4273
- var mode = cm.doc.mode;
4274
- var stream = new StringStream(line.text, cm.options.tabSize);
4275
- if (line.text == "" && mode.blankLine) mode.blankLine(state);
4276
- while (!stream.eol() && stream.pos <= cm.options.maxHighlightLength) {
4277
- mode.token(stream, state);
4278
- stream.start = stream.pos;
4279
- }
4280
- }
4281
-
4282
- var styleToClassCache = {};
4283
- function styleToClass(style) {
4284
- if (!style) return null;
4285
- return styleToClassCache[style] ||
4286
- (styleToClassCache[style] = "cm-" + style.replace(/ +/g, " cm-"));
4287
- }
4288
-
4289
- function lineContent(cm, realLine, measure, copyWidgets) {
4290
- var merged, line = realLine, empty = true;
4291
- while (merged = collapsedSpanAtStart(line))
4292
- line = getLine(cm.doc, merged.find().from.line);
4293
-
4294
- var builder = {pre: elt("pre"), col: 0, pos: 0,
4295
- measure: null, measuredSomething: false, cm: cm,
4296
- copyWidgets: copyWidgets};
4297
- if (line.textClass) builder.pre.className = line.textClass;
4298
-
4299
- do {
4300
- if (line.text) empty = false;
4301
- builder.measure = line == realLine && measure;
4302
- builder.pos = 0;
4303
- builder.addToken = builder.measure ? buildTokenMeasure : buildToken;
4304
- if ((ie || webkit) && cm.getOption("lineWrapping"))
4305
- builder.addToken = buildTokenSplitSpaces(builder.addToken);
4306
- var next = insertLineContent(line, builder, getLineStyles(cm, line));
4307
- if (measure && line == realLine && !builder.measuredSomething) {
4308
- measure[0] = builder.pre.appendChild(zeroWidthElement(cm.display.measure));
4309
- builder.measuredSomething = true;
4310
- }
4311
- if (next) line = getLine(cm.doc, next.to.line);
4312
- } while (next);
4313
-
4314
- if (measure && !builder.measuredSomething && !measure[0])
4315
- measure[0] = builder.pre.appendChild(empty ? elt("span", "\u00a0") : zeroWidthElement(cm.display.measure));
4316
- if (!builder.pre.firstChild && !lineIsHidden(cm.doc, realLine))
4317
- builder.pre.appendChild(document.createTextNode("\u00a0"));
4318
-
4319
- var order;
4320
- // Work around problem with the reported dimensions of single-char
4321
- // direction spans on IE (issue #1129). See also the comment in
4322
- // cursorCoords.
4323
- if (measure && ie && (order = getOrder(line))) {
4324
- var l = order.length - 1;
4325
- if (order[l].from == order[l].to) --l;
4326
- var last = order[l], prev = order[l - 1];
4327
- if (last.from + 1 == last.to && prev && last.level < prev.level) {
4328
- var span = measure[builder.pos - 1];
4329
- if (span) span.parentNode.insertBefore(span.measureRight = zeroWidthElement(cm.display.measure),
4330
- span.nextSibling);
4331
- }
4332
- }
4333
-
4334
- signal(cm, "renderLine", cm, realLine, builder.pre);
4335
- return builder.pre;
4336
- }
4337
-
4338
- var tokenSpecialChars = /[\t\u0000-\u0019\u00ad\u200b\u2028\u2029\uFEFF]/g;
4339
- function buildToken(builder, text, style, startStyle, endStyle, title) {
4340
- if (!text) return;
4341
- if (!tokenSpecialChars.test(text)) {
4342
- builder.col += text.length;
4343
- var content = document.createTextNode(text);
4344
- } else {
4345
- var content = document.createDocumentFragment(), pos = 0;
4346
- while (true) {
4347
- tokenSpecialChars.lastIndex = pos;
4348
- var m = tokenSpecialChars.exec(text);
4349
- var skipped = m ? m.index - pos : text.length - pos;
4350
- if (skipped) {
4351
- content.appendChild(document.createTextNode(text.slice(pos, pos + skipped)));
4352
- builder.col += skipped;
4353
- }
4354
- if (!m) break;
4355
- pos += skipped + 1;
4356
- if (m[0] == "\t") {
4357
- var tabSize = builder.cm.options.tabSize, tabWidth = tabSize - builder.col % tabSize;
4358
- content.appendChild(elt("span", spaceStr(tabWidth), "cm-tab"));
4359
- builder.col += tabWidth;
4360
- } else {
4361
- var token = elt("span", "\u2022", "cm-invalidchar");
4362
- token.title = "\\u" + m[0].charCodeAt(0).toString(16);
4363
- content.appendChild(token);
4364
- builder.col += 1;
4365
- }
4366
- }
4367
- }
4368
- if (style || startStyle || endStyle || builder.measure) {
4369
- var fullStyle = style || "";
4370
- if (startStyle) fullStyle += startStyle;
4371
- if (endStyle) fullStyle += endStyle;
4372
- var token = elt("span", [content], fullStyle);
4373
- if (title) token.title = title;
4374
- return builder.pre.appendChild(token);
4375
- }
4376
- builder.pre.appendChild(content);
4377
- }
4378
-
4379
- function buildTokenMeasure(builder, text, style, startStyle, endStyle) {
4380
- var wrapping = builder.cm.options.lineWrapping;
4381
- for (var i = 0; i < text.length; ++i) {
4382
- var ch = text.charAt(i), start = i == 0;
4383
- if (ch >= "\ud800" && ch < "\udbff" && i < text.length - 1) {
4384
- ch = text.slice(i, i + 2);
4385
- ++i;
4386
- } else if (i && wrapping && spanAffectsWrapping(text, i)) {
4387
- builder.pre.appendChild(elt("wbr"));
4388
- }
4389
- var old = builder.measure[builder.pos];
4390
- var span = builder.measure[builder.pos] =
4391
- buildToken(builder, ch, style,
4392
- start && startStyle, i == text.length - 1 && endStyle);
4393
- if (old) span.leftSide = old.leftSide || old;
4394
- // In IE single-space nodes wrap differently than spaces
4395
- // embedded in larger text nodes, except when set to
4396
- // white-space: normal (issue #1268).
4397
- if (ie && wrapping && ch == " " && i && !/\s/.test(text.charAt(i - 1)) &&
4398
- i < text.length - 1 && !/\s/.test(text.charAt(i + 1)))
4399
- span.style.whiteSpace = "normal";
4400
- builder.pos += ch.length;
4401
- }
4402
- if (text.length) builder.measuredSomething = true;
4403
- }
4404
-
4405
- function buildTokenSplitSpaces(inner) {
4406
- function split(old) {
4407
- var out = " ";
4408
- for (var i = 0; i < old.length - 2; ++i) out += i % 2 ? " " : "\u00a0";
4409
- out += " ";
4410
- return out;
4411
- }
4412
- return function(builder, text, style, startStyle, endStyle, title) {
4413
- return inner(builder, text.replace(/ {3,}/, split), style, startStyle, endStyle, title);
4414
- };
4415
- }
4416
-
4417
- function buildCollapsedSpan(builder, size, marker, ignoreWidget) {
4418
- var widget = !ignoreWidget && marker.replacedWith;
4419
- if (widget) {
4420
- if (builder.copyWidgets) widget = widget.cloneNode(true);
4421
- builder.pre.appendChild(widget);
4422
- if (builder.measure) {
4423
- if (size) {
4424
- builder.measure[builder.pos] = widget;
4425
- } else {
4426
- var elt = zeroWidthElement(builder.cm.display.measure);
4427
- if (marker.type == "bookmark" && !marker.insertLeft)
4428
- builder.measure[builder.pos] = builder.pre.appendChild(elt);
4429
- else if (builder.measure[builder.pos])
4430
- return;
4431
- else
4432
- builder.measure[builder.pos] = builder.pre.insertBefore(elt, widget);
4433
- }
4434
- builder.measuredSomething = true;
4435
- }
4436
- }
4437
- builder.pos += size;
4438
- }
4439
-
4440
- // Outputs a number of spans to make up a line, taking highlighting
4441
- // and marked text into account.
4442
- function insertLineContent(line, builder, styles) {
4443
- var spans = line.markedSpans, allText = line.text, at = 0;
4444
- if (!spans) {
4445
- for (var i = 1; i < styles.length; i+=2)
4446
- builder.addToken(builder, allText.slice(at, at = styles[i]), styleToClass(styles[i+1]));
4447
- return;
4448
- }
4449
-
4450
- var len = allText.length, pos = 0, i = 1, text = "", style;
4451
- var nextChange = 0, spanStyle, spanEndStyle, spanStartStyle, title, collapsed;
4452
- for (;;) {
4453
- if (nextChange == pos) { // Update current marker set
4454
- spanStyle = spanEndStyle = spanStartStyle = title = "";
4455
- collapsed = null; nextChange = Infinity;
4456
- var foundBookmarks = [];
4457
- for (var j = 0; j < spans.length; ++j) {
4458
- var sp = spans[j], m = sp.marker;
4459
- if (sp.from <= pos && (sp.to == null || sp.to > pos)) {
4460
- if (sp.to != null && nextChange > sp.to) { nextChange = sp.to; spanEndStyle = ""; }
4461
- if (m.className) spanStyle += " " + m.className;
4462
- if (m.startStyle && sp.from == pos) spanStartStyle += " " + m.startStyle;
4463
- if (m.endStyle && sp.to == nextChange) spanEndStyle += " " + m.endStyle;
4464
- if (m.title && !title) title = m.title;
4465
- if (m.collapsed && (!collapsed || collapsed.marker.size < m.size))
4466
- collapsed = sp;
4467
- } else if (sp.from > pos && nextChange > sp.from) {
4468
- nextChange = sp.from;
4469
- }
4470
- if (m.type == "bookmark" && sp.from == pos && m.replacedWith) foundBookmarks.push(m);
4471
- }
4472
- if (collapsed && (collapsed.from || 0) == pos) {
4473
- buildCollapsedSpan(builder, (collapsed.to == null ? len : collapsed.to) - pos,
4474
- collapsed.marker, collapsed.from == null);
4475
- if (collapsed.to == null) return collapsed.marker.find();
4476
- }
4477
- if (!collapsed && foundBookmarks.length) for (var j = 0; j < foundBookmarks.length; ++j)
4478
- buildCollapsedSpan(builder, 0, foundBookmarks[j]);
4479
- }
4480
- if (pos >= len) break;
4481
-
4482
- var upto = Math.min(len, nextChange);
4483
- while (true) {
4484
- if (text) {
4485
- var end = pos + text.length;
4486
- if (!collapsed) {
4487
- var tokenText = end > upto ? text.slice(0, upto - pos) : text;
4488
- builder.addToken(builder, tokenText, style ? style + spanStyle : spanStyle,
4489
- spanStartStyle, pos + tokenText.length == nextChange ? spanEndStyle : "", title);
4490
- }
4491
- if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
4492
- pos = end;
4493
- spanStartStyle = "";
4494
- }
4495
- text = allText.slice(at, at = styles[i++]);
4496
- style = styleToClass(styles[i++]);
4497
- }
4498
- }
4499
- }
4500
-
4501
- // DOCUMENT DATA STRUCTURE
4502
-
4503
- function updateDoc(doc, change, markedSpans, selAfter, estimateHeight) {
4504
- function spansFor(n) {return markedSpans ? markedSpans[n] : null;}
4505
- function update(line, text, spans) {
4506
- updateLine(line, text, spans, estimateHeight);
4507
- signalLater(line, "change", line, change);
4508
- }
4509
-
4510
- var from = change.from, to = change.to, text = change.text;
4511
- var firstLine = getLine(doc, from.line), lastLine = getLine(doc, to.line);
4512
- var lastText = lst(text), lastSpans = spansFor(text.length - 1), nlines = to.line - from.line;
4513
-
4514
- // First adjust the line structure
4515
- if (from.ch == 0 && to.ch == 0 && lastText == "") {
4516
- // This is a whole-line replace. Treated specially to make
4517
- // sure line objects move the way they are supposed to.
4518
- for (var i = 0, e = text.length - 1, added = []; i < e; ++i)
4519
- added.push(new Line(text[i], spansFor(i), estimateHeight));
4520
- update(lastLine, lastLine.text, lastSpans);
4521
- if (nlines) doc.remove(from.line, nlines);
4522
- if (added.length) doc.insert(from.line, added);
4523
- } else if (firstLine == lastLine) {
4524
- if (text.length == 1) {
4525
- update(firstLine, firstLine.text.slice(0, from.ch) + lastText + firstLine.text.slice(to.ch), lastSpans);
4526
- } else {
4527
- for (var added = [], i = 1, e = text.length - 1; i < e; ++i)
4528
- added.push(new Line(text[i], spansFor(i), estimateHeight));
4529
- added.push(new Line(lastText + firstLine.text.slice(to.ch), lastSpans, estimateHeight));
4530
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4531
- doc.insert(from.line + 1, added);
4532
- }
4533
- } else if (text.length == 1) {
4534
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0] + lastLine.text.slice(to.ch), spansFor(0));
4535
- doc.remove(from.line + 1, nlines);
4536
- } else {
4537
- update(firstLine, firstLine.text.slice(0, from.ch) + text[0], spansFor(0));
4538
- update(lastLine, lastText + lastLine.text.slice(to.ch), lastSpans);
4539
- for (var i = 1, e = text.length - 1, added = []; i < e; ++i)
4540
- added.push(new Line(text[i], spansFor(i), estimateHeight));
4541
- if (nlines > 1) doc.remove(from.line + 1, nlines - 1);
4542
- doc.insert(from.line + 1, added);
4543
- }
4544
-
4545
- signalLater(doc, "change", doc, change);
4546
- setSelection(doc, selAfter.anchor, selAfter.head, null, true);
4547
- }
4548
-
4549
- function LeafChunk(lines) {
4550
- this.lines = lines;
4551
- this.parent = null;
4552
- for (var i = 0, e = lines.length, height = 0; i < e; ++i) {
4553
- lines[i].parent = this;
4554
- height += lines[i].height;
4555
- }
4556
- this.height = height;
4557
- }
4558
-
4559
- LeafChunk.prototype = {
4560
- chunkSize: function() { return this.lines.length; },
4561
- removeInner: function(at, n) {
4562
- for (var i = at, e = at + n; i < e; ++i) {
4563
- var line = this.lines[i];
4564
- this.height -= line.height;
4565
- cleanUpLine(line);
4566
- signalLater(line, "delete");
4567
- }
4568
- this.lines.splice(at, n);
4569
- },
4570
- collapse: function(lines) {
4571
- lines.splice.apply(lines, [lines.length, 0].concat(this.lines));
4572
- },
4573
- insertInner: function(at, lines, height) {
4574
- this.height += height;
4575
- this.lines = this.lines.slice(0, at).concat(lines).concat(this.lines.slice(at));
4576
- for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this;
4577
- },
4578
- iterN: function(at, n, op) {
4579
- for (var e = at + n; at < e; ++at)
4580
- if (op(this.lines[at])) return true;
4581
- }
4582
- };
4583
-
4584
- function BranchChunk(children) {
4585
- this.children = children;
4586
- var size = 0, height = 0;
4587
- for (var i = 0, e = children.length; i < e; ++i) {
4588
- var ch = children[i];
4589
- size += ch.chunkSize(); height += ch.height;
4590
- ch.parent = this;
4591
- }
4592
- this.size = size;
4593
- this.height = height;
4594
- this.parent = null;
4595
- }
4596
-
4597
- BranchChunk.prototype = {
4598
- chunkSize: function() { return this.size; },
4599
- removeInner: function(at, n) {
4600
- this.size -= n;
4601
- for (var i = 0; i < this.children.length; ++i) {
4602
- var child = this.children[i], sz = child.chunkSize();
4603
- if (at < sz) {
4604
- var rm = Math.min(n, sz - at), oldHeight = child.height;
4605
- child.removeInner(at, rm);
4606
- this.height -= oldHeight - child.height;
4607
- if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
4608
- if ((n -= rm) == 0) break;
4609
- at = 0;
4610
- } else at -= sz;
4611
- }
4612
- if (this.size - n < 25) {
4613
- var lines = [];
4614
- this.collapse(lines);
4615
- this.children = [new LeafChunk(lines)];
4616
- this.children[0].parent = this;
4617
- }
4618
- },
4619
- collapse: function(lines) {
4620
- for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines);
4621
- },
4622
- insertInner: function(at, lines, height) {
4623
- this.size += lines.length;
4624
- this.height += height;
4625
- for (var i = 0, e = this.children.length; i < e; ++i) {
4626
- var child = this.children[i], sz = child.chunkSize();
4627
- if (at <= sz) {
4628
- child.insertInner(at, lines, height);
4629
- if (child.lines && child.lines.length > 50) {
4630
- while (child.lines.length > 50) {
4631
- var spilled = child.lines.splice(child.lines.length - 25, 25);
4632
- var newleaf = new LeafChunk(spilled);
4633
- child.height -= newleaf.height;
4634
- this.children.splice(i + 1, 0, newleaf);
4635
- newleaf.parent = this;
4636
- }
4637
- this.maybeSpill();
4638
- }
4639
- break;
4640
- }
4641
- at -= sz;
4642
- }
4643
- },
4644
- maybeSpill: function() {
4645
- if (this.children.length <= 10) return;
4646
- var me = this;
4647
- do {
4648
- var spilled = me.children.splice(me.children.length - 5, 5);
4649
- var sibling = new BranchChunk(spilled);
4650
- if (!me.parent) { // Become the parent node
4651
- var copy = new BranchChunk(me.children);
4652
- copy.parent = me;
4653
- me.children = [copy, sibling];
4654
- me = copy;
4655
- } else {
4656
- me.size -= sibling.size;
4657
- me.height -= sibling.height;
4658
- var myIndex = indexOf(me.parent.children, me);
4659
- me.parent.children.splice(myIndex + 1, 0, sibling);
4660
- }
4661
- sibling.parent = me.parent;
4662
- } while (me.children.length > 10);
4663
- me.parent.maybeSpill();
4664
- },
4665
- iterN: function(at, n, op) {
4666
- for (var i = 0, e = this.children.length; i < e; ++i) {
4667
- var child = this.children[i], sz = child.chunkSize();
4668
- if (at < sz) {
4669
- var used = Math.min(n, sz - at);
4670
- if (child.iterN(at, used, op)) return true;
4671
- if ((n -= used) == 0) break;
4672
- at = 0;
4673
- } else at -= sz;
4674
- }
4675
- }
4676
- };
4677
-
4678
- var nextDocId = 0;
4679
- var Doc = CodeMirror.Doc = function(text, mode, firstLine) {
4680
- if (!(this instanceof Doc)) return new Doc(text, mode, firstLine);
4681
- if (firstLine == null) firstLine = 0;
4682
-
4683
- BranchChunk.call(this, [new LeafChunk([new Line("", null)])]);
4684
- this.first = firstLine;
4685
- this.scrollTop = this.scrollLeft = 0;
4686
- this.cantEdit = false;
4687
- this.history = makeHistory();
4688
- this.cleanGeneration = 1;
4689
- this.frontier = firstLine;
4690
- var start = Pos(firstLine, 0);
4691
- this.sel = {from: start, to: start, head: start, anchor: start, shift: false, extend: false, goalColumn: null};
4692
- this.id = ++nextDocId;
4693
- this.modeOption = mode;
4694
-
4695
- if (typeof text == "string") text = splitLines(text);
4696
- updateDoc(this, {from: start, to: start, text: text}, null, {head: start, anchor: start});
4697
- };
4698
-
4699
- Doc.prototype = createObj(BranchChunk.prototype, {
4700
- constructor: Doc,
4701
- iter: function(from, to, op) {
4702
- if (op) this.iterN(from - this.first, to - from, op);
4703
- else this.iterN(this.first, this.first + this.size, from);
4704
- },
4705
-
4706
- insert: function(at, lines) {
4707
- var height = 0;
4708
- for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height;
4709
- this.insertInner(at - this.first, lines, height);
4710
- },
4711
- remove: function(at, n) { this.removeInner(at - this.first, n); },
4712
-
4713
- getValue: function(lineSep) {
4714
- var lines = getLines(this, this.first, this.first + this.size);
4715
- if (lineSep === false) return lines;
4716
- return lines.join(lineSep || "\n");
4717
- },
4718
- setValue: function(code) {
4719
- var top = Pos(this.first, 0), last = this.first + this.size - 1;
4720
- makeChange(this, {from: top, to: Pos(last, getLine(this, last).text.length),
4721
- text: splitLines(code), origin: "setValue"},
4722
- {head: top, anchor: top}, true);
4723
- },
4724
- replaceRange: function(code, from, to, origin) {
4725
- from = clipPos(this, from);
4726
- to = to ? clipPos(this, to) : from;
4727
- replaceRange(this, code, from, to, origin);
4728
- },
4729
- getRange: function(from, to, lineSep) {
4730
- var lines = getBetween(this, clipPos(this, from), clipPos(this, to));
4731
- if (lineSep === false) return lines;
4732
- return lines.join(lineSep || "\n");
4733
- },
4734
-
4735
- getLine: function(line) {var l = this.getLineHandle(line); return l && l.text;},
4736
- setLine: function(line, text) {
4737
- if (isLine(this, line))
4738
- replaceRange(this, text, Pos(line, 0), clipPos(this, Pos(line)));
4739
- },
4740
- removeLine: function(line) {
4741
- if (line) replaceRange(this, "", clipPos(this, Pos(line - 1)), clipPos(this, Pos(line)));
4742
- else replaceRange(this, "", Pos(0, 0), clipPos(this, Pos(1, 0)));
4743
- },
4744
-
4745
- getLineHandle: function(line) {if (isLine(this, line)) return getLine(this, line);},
4746
- getLineNumber: function(line) {return lineNo(line);},
4747
-
4748
- getLineHandleVisualStart: function(line) {
4749
- if (typeof line == "number") line = getLine(this, line);
4750
- return visualLine(this, line);
4751
- },
4752
-
4753
- lineCount: function() {return this.size;},
4754
- firstLine: function() {return this.first;},
4755
- lastLine: function() {return this.first + this.size - 1;},
4756
-
4757
- clipPos: function(pos) {return clipPos(this, pos);},
4758
-
4759
- getCursor: function(start) {
4760
- var sel = this.sel, pos;
4761
- if (start == null || start == "head") pos = sel.head;
4762
- else if (start == "anchor") pos = sel.anchor;
4763
- else if (start == "end" || start === false) pos = sel.to;
4764
- else pos = sel.from;
4765
- return copyPos(pos);
4766
- },
4767
- somethingSelected: function() {return !posEq(this.sel.head, this.sel.anchor);},
4768
-
4769
- setCursor: docOperation(function(line, ch, extend) {
4770
- var pos = clipPos(this, typeof line == "number" ? Pos(line, ch || 0) : line);
4771
- if (extend) extendSelection(this, pos);
4772
- else setSelection(this, pos, pos);
4773
- }),
4774
- setSelection: docOperation(function(anchor, head, bias) {
4775
- setSelection(this, clipPos(this, anchor), clipPos(this, head || anchor), bias);
4776
- }),
4777
- extendSelection: docOperation(function(from, to, bias) {
4778
- extendSelection(this, clipPos(this, from), to && clipPos(this, to), bias);
4779
- }),
4780
-
4781
- getSelection: function(lineSep) {return this.getRange(this.sel.from, this.sel.to, lineSep);},
4782
- replaceSelection: function(code, collapse, origin) {
4783
- makeChange(this, {from: this.sel.from, to: this.sel.to, text: splitLines(code), origin: origin}, collapse || "around");
4784
- },
4785
- undo: docOperation(function() {makeChangeFromHistory(this, "undo");}),
4786
- redo: docOperation(function() {makeChangeFromHistory(this, "redo");}),
4787
-
4788
- setExtending: function(val) {this.sel.extend = val;},
4789
-
4790
- historySize: function() {
4791
- var hist = this.history;
4792
- return {undo: hist.done.length, redo: hist.undone.length};
4793
- },
4794
- clearHistory: function() {this.history = makeHistory(this.history.maxGeneration);},
4795
-
4796
- markClean: function() {
4797
- this.cleanGeneration = this.changeGeneration();
4798
- },
4799
- changeGeneration: function() {
4800
- this.history.lastOp = this.history.lastOrigin = null;
4801
- return this.history.generation;
4802
- },
4803
- isClean: function (gen) {
4804
- return this.history.generation == (gen || this.cleanGeneration);
4805
- },
4806
-
4807
- getHistory: function() {
4808
- return {done: copyHistoryArray(this.history.done),
4809
- undone: copyHistoryArray(this.history.undone)};
4810
- },
4811
- setHistory: function(histData) {
4812
- var hist = this.history = makeHistory(this.history.maxGeneration);
4813
- hist.done = histData.done.slice(0);
4814
- hist.undone = histData.undone.slice(0);
4815
- },
4816
-
4817
- markText: function(from, to, options) {
4818
- return markText(this, clipPos(this, from), clipPos(this, to), options, "range");
4819
- },
4820
- setBookmark: function(pos, options) {
4821
- var realOpts = {replacedWith: options && (options.nodeType == null ? options.widget : options),
4822
- insertLeft: options && options.insertLeft};
4823
- pos = clipPos(this, pos);
4824
- return markText(this, pos, pos, realOpts, "bookmark");
4825
- },
4826
- findMarksAt: function(pos) {
4827
- pos = clipPos(this, pos);
4828
- var markers = [], spans = getLine(this, pos.line).markedSpans;
4829
- if (spans) for (var i = 0; i < spans.length; ++i) {
4830
- var span = spans[i];
4831
- if ((span.from == null || span.from <= pos.ch) &&
4832
- (span.to == null || span.to >= pos.ch))
4833
- markers.push(span.marker.parent || span.marker);
4834
- }
4835
- return markers;
4836
- },
4837
- getAllMarks: function() {
4838
- var markers = [];
4839
- this.iter(function(line) {
4840
- var sps = line.markedSpans;
4841
- if (sps) for (var i = 0; i < sps.length; ++i)
4842
- if (sps[i].from != null) markers.push(sps[i].marker);
4843
- });
4844
- return markers;
4845
- },
4846
-
4847
- posFromIndex: function(off) {
4848
- var ch, lineNo = this.first;
4849
- this.iter(function(line) {
4850
- var sz = line.text.length + 1;
4851
- if (sz > off) { ch = off; return true; }
4852
- off -= sz;
4853
- ++lineNo;
4854
- });
4855
- return clipPos(this, Pos(lineNo, ch));
4856
- },
4857
- indexFromPos: function (coords) {
4858
- coords = clipPos(this, coords);
4859
- var index = coords.ch;
4860
- if (coords.line < this.first || coords.ch < 0) return 0;
4861
- this.iter(this.first, coords.line, function (line) {
4862
- index += line.text.length + 1;
4863
- });
4864
- return index;
4865
- },
4866
-
4867
- copy: function(copyHistory) {
4868
- var doc = new Doc(getLines(this, this.first, this.first + this.size), this.modeOption, this.first);
4869
- doc.scrollTop = this.scrollTop; doc.scrollLeft = this.scrollLeft;
4870
- doc.sel = {from: this.sel.from, to: this.sel.to, head: this.sel.head, anchor: this.sel.anchor,
4871
- shift: this.sel.shift, extend: false, goalColumn: this.sel.goalColumn};
4872
- if (copyHistory) {
4873
- doc.history.undoDepth = this.history.undoDepth;
4874
- doc.setHistory(this.getHistory());
4875
- }
4876
- return doc;
4877
- },
4878
-
4879
- linkedDoc: function(options) {
4880
- if (!options) options = {};
4881
- var from = this.first, to = this.first + this.size;
4882
- if (options.from != null && options.from > from) from = options.from;
4883
- if (options.to != null && options.to < to) to = options.to;
4884
- var copy = new Doc(getLines(this, from, to), options.mode || this.modeOption, from);
4885
- if (options.sharedHist) copy.history = this.history;
4886
- (this.linked || (this.linked = [])).push({doc: copy, sharedHist: options.sharedHist});
4887
- copy.linked = [{doc: this, isParent: true, sharedHist: options.sharedHist}];
4888
- return copy;
4889
- },
4890
- unlinkDoc: function(other) {
4891
- if (other instanceof CodeMirror) other = other.doc;
4892
- if (this.linked) for (var i = 0; i < this.linked.length; ++i) {
4893
- var link = this.linked[i];
4894
- if (link.doc != other) continue;
4895
- this.linked.splice(i, 1);
4896
- other.unlinkDoc(this);
4897
- break;
4898
- }
4899
- // If the histories were shared, split them again
4900
- if (other.history == this.history) {
4901
- var splitIds = [other.id];
4902
- linkedDocs(other, function(doc) {splitIds.push(doc.id);}, true);
4903
- other.history = makeHistory();
4904
- other.history.done = copyHistoryArray(this.history.done, splitIds);
4905
- other.history.undone = copyHistoryArray(this.history.undone, splitIds);
4906
- }
4907
- },
4908
- iterLinkedDocs: function(f) {linkedDocs(this, f);},
4909
-
4910
- getMode: function() {return this.mode;},
4911
- getEditor: function() {return this.cm;}
4912
- });
4913
-
4914
- Doc.prototype.eachLine = Doc.prototype.iter;
4915
-
4916
- // The Doc methods that should be available on CodeMirror instances
4917
- var dontDelegate = "iter insert remove copy getEditor".split(" ");
4918
- for (var prop in Doc.prototype) if (Doc.prototype.hasOwnProperty(prop) && indexOf(dontDelegate, prop) < 0)
4919
- CodeMirror.prototype[prop] = (function(method) {
4920
- return function() {return method.apply(this.doc, arguments);};
4921
- })(Doc.prototype[prop]);
4922
-
4923
- eventMixin(Doc);
4924
-
4925
- function linkedDocs(doc, f, sharedHistOnly) {
4926
- function propagate(doc, skip, sharedHist) {
4927
- if (doc.linked) for (var i = 0; i < doc.linked.length; ++i) {
4928
- var rel = doc.linked[i];
4929
- if (rel.doc == skip) continue;
4930
- var shared = sharedHist && rel.sharedHist;
4931
- if (sharedHistOnly && !shared) continue;
4932
- f(rel.doc, shared);
4933
- propagate(rel.doc, doc, shared);
4934
- }
4935
- }
4936
- propagate(doc, null, true);
4937
- }
4938
-
4939
- function attachDoc(cm, doc) {
4940
- if (doc.cm) throw new Error("This document is already in use.");
4941
- cm.doc = doc;
4942
- doc.cm = cm;
4943
- estimateLineHeights(cm);
4944
- loadMode(cm);
4945
- if (!cm.options.lineWrapping) computeMaxLength(cm);
4946
- cm.options.mode = doc.modeOption;
4947
- regChange(cm);
4948
- }
4949
-
4950
- // LINE UTILITIES
4951
-
4952
- function getLine(chunk, n) {
4953
- n -= chunk.first;
4954
- while (!chunk.lines) {
4955
- for (var i = 0;; ++i) {
4956
- var child = chunk.children[i], sz = child.chunkSize();
4957
- if (n < sz) { chunk = child; break; }
4958
- n -= sz;
4959
- }
4960
- }
4961
- return chunk.lines[n];
4962
- }
4963
-
4964
- function getBetween(doc, start, end) {
4965
- var out = [], n = start.line;
4966
- doc.iter(start.line, end.line + 1, function(line) {
4967
- var text = line.text;
4968
- if (n == end.line) text = text.slice(0, end.ch);
4969
- if (n == start.line) text = text.slice(start.ch);
4970
- out.push(text);
4971
- ++n;
4972
- });
4973
- return out;
4974
- }
4975
- function getLines(doc, from, to) {
4976
- var out = [];
4977
- doc.iter(from, to, function(line) { out.push(line.text); });
4978
- return out;
4979
- }
4980
-
4981
- function updateLineHeight(line, height) {
4982
- var diff = height - line.height;
4983
- for (var n = line; n; n = n.parent) n.height += diff;
4984
- }
4985
-
4986
- function lineNo(line) {
4987
- if (line.parent == null) return null;
4988
- var cur = line.parent, no = indexOf(cur.lines, line);
4989
- for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
4990
- for (var i = 0;; ++i) {
4991
- if (chunk.children[i] == cur) break;
4992
- no += chunk.children[i].chunkSize();
4993
- }
4994
- }
4995
- return no + cur.first;
4996
- }
4997
-
4998
- function lineAtHeight(chunk, h) {
4999
- var n = chunk.first;
5000
- outer: do {
5001
- for (var i = 0, e = chunk.children.length; i < e; ++i) {
5002
- var child = chunk.children[i], ch = child.height;
5003
- if (h < ch) { chunk = child; continue outer; }
5004
- h -= ch;
5005
- n += child.chunkSize();
5006
- }
5007
- return n;
5008
- } while (!chunk.lines);
5009
- for (var i = 0, e = chunk.lines.length; i < e; ++i) {
5010
- var line = chunk.lines[i], lh = line.height;
5011
- if (h < lh) break;
5012
- h -= lh;
5013
- }
5014
- return n + i;
5015
- }
5016
-
5017
- function heightAtLine(cm, lineObj) {
5018
- lineObj = visualLine(cm.doc, lineObj);
5019
-
5020
- var h = 0, chunk = lineObj.parent;
5021
- for (var i = 0; i < chunk.lines.length; ++i) {
5022
- var line = chunk.lines[i];
5023
- if (line == lineObj) break;
5024
- else h += line.height;
5025
- }
5026
- for (var p = chunk.parent; p; chunk = p, p = chunk.parent) {
5027
- for (var i = 0; i < p.children.length; ++i) {
5028
- var cur = p.children[i];
5029
- if (cur == chunk) break;
5030
- else h += cur.height;
5031
- }
5032
- }
5033
- return h;
5034
- }
5035
-
5036
- function getOrder(line) {
5037
- var order = line.order;
5038
- if (order == null) order = line.order = bidiOrdering(line.text);
5039
- return order;
5040
- }
5041
-
5042
- // HISTORY
5043
-
5044
- function makeHistory(startGen) {
5045
- return {
5046
- // Arrays of history events. Doing something adds an event to
5047
- // done and clears undo. Undoing moves events from done to
5048
- // undone, redoing moves them in the other direction.
5049
- done: [], undone: [], undoDepth: Infinity,
5050
- // Used to track when changes can be merged into a single undo
5051
- // event
5052
- lastTime: 0, lastOp: null, lastOrigin: null,
5053
- // Used by the isClean() method
5054
- generation: startGen || 1, maxGeneration: startGen || 1
5055
- };
5056
- }
5057
-
5058
- function attachLocalSpans(doc, change, from, to) {
5059
- var existing = change["spans_" + doc.id], n = 0;
5060
- doc.iter(Math.max(doc.first, from), Math.min(doc.first + doc.size, to), function(line) {
5061
- if (line.markedSpans)
5062
- (existing || (existing = change["spans_" + doc.id] = {}))[n] = line.markedSpans;
5063
- ++n;
5064
- });
5065
- }
5066
-
5067
- function historyChangeFromChange(doc, change) {
5068
- var from = { line: change.from.line, ch: change.from.ch };
5069
- var histChange = {from: from, to: changeEnd(change), text: getBetween(doc, change.from, change.to)};
5070
- attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);
5071
- linkedDocs(doc, function(doc) {attachLocalSpans(doc, histChange, change.from.line, change.to.line + 1);}, true);
5072
- return histChange;
5073
- }
5074
-
5075
- function addToHistory(doc, change, selAfter, opId) {
5076
- var hist = doc.history;
5077
- hist.undone.length = 0;
5078
- var time = +new Date, cur = lst(hist.done);
5079
-
5080
- if (cur &&
5081
- (hist.lastOp == opId ||
5082
- hist.lastOrigin == change.origin && change.origin &&
5083
- ((change.origin.charAt(0) == "+" && doc.cm && hist.lastTime > time - doc.cm.options.historyEventDelay) ||
5084
- change.origin.charAt(0) == "*"))) {
5085
- // Merge this change into the last event
5086
- var last = lst(cur.changes);
5087
- if (posEq(change.from, change.to) && posEq(change.from, last.to)) {
5088
- // Optimized case for simple insertion -- don't want to add
5089
- // new changesets for every character typed
5090
- last.to = changeEnd(change);
5091
- } else {
5092
- // Add new sub-event
5093
- cur.changes.push(historyChangeFromChange(doc, change));
5094
- }
5095
- cur.anchorAfter = selAfter.anchor; cur.headAfter = selAfter.head;
5096
- } else {
5097
- // Can not be merged, start a new event.
5098
- cur = {changes: [historyChangeFromChange(doc, change)],
5099
- generation: hist.generation,
5100
- anchorBefore: doc.sel.anchor, headBefore: doc.sel.head,
5101
- anchorAfter: selAfter.anchor, headAfter: selAfter.head};
5102
- hist.done.push(cur);
5103
- hist.generation = ++hist.maxGeneration;
5104
- while (hist.done.length > hist.undoDepth)
5105
- hist.done.shift();
5106
- }
5107
- hist.lastTime = time;
5108
- hist.lastOp = opId;
5109
- hist.lastOrigin = change.origin;
5110
- }
5111
-
5112
- function removeClearedSpans(spans) {
5113
- if (!spans) return null;
5114
- for (var i = 0, out; i < spans.length; ++i) {
5115
- if (spans[i].marker.explicitlyCleared) { if (!out) out = spans.slice(0, i); }
5116
- else if (out) out.push(spans[i]);
5117
- }
5118
- return !out ? spans : out.length ? out : null;
5119
- }
5120
-
5121
- function getOldSpans(doc, change) {
5122
- var found = change["spans_" + doc.id];
5123
- if (!found) return null;
5124
- for (var i = 0, nw = []; i < change.text.length; ++i)
5125
- nw.push(removeClearedSpans(found[i]));
5126
- return nw;
5127
- }
5128
-
5129
- // Used both to provide a JSON-safe object in .getHistory, and, when
5130
- // detaching a document, to split the history in two
5131
- function copyHistoryArray(events, newGroup) {
5132
- for (var i = 0, copy = []; i < events.length; ++i) {
5133
- var event = events[i], changes = event.changes, newChanges = [];
5134
- copy.push({changes: newChanges, anchorBefore: event.anchorBefore, headBefore: event.headBefore,
5135
- anchorAfter: event.anchorAfter, headAfter: event.headAfter});
5136
- for (var j = 0; j < changes.length; ++j) {
5137
- var change = changes[j], m;
5138
- newChanges.push({from: change.from, to: change.to, text: change.text});
5139
- if (newGroup) for (var prop in change) if (m = prop.match(/^spans_(\d+)$/)) {
5140
- if (indexOf(newGroup, Number(m[1])) > -1) {
5141
- lst(newChanges)[prop] = change[prop];
5142
- delete change[prop];
5143
- }
5144
- }
5145
- }
5146
- }
5147
- return copy;
5148
- }
5149
-
5150
- // Rebasing/resetting history to deal with externally-sourced changes
5151
-
5152
- function rebaseHistSel(pos, from, to, diff) {
5153
- if (to < pos.line) {
5154
- pos.line += diff;
5155
- } else if (from < pos.line) {
5156
- pos.line = from;
5157
- pos.ch = 0;
5158
- }
5159
- }
5160
-
5161
- // Tries to rebase an array of history events given a change in the
5162
- // document. If the change touches the same lines as the event, the
5163
- // event, and everything 'behind' it, is discarded. If the change is
5164
- // before the event, the event's positions are updated. Uses a
5165
- // copy-on-write scheme for the positions, to avoid having to
5166
- // reallocate them all on every rebase, but also avoid problems with
5167
- // shared position objects being unsafely updated.
5168
- function rebaseHistArray(array, from, to, diff) {
5169
- for (var i = 0; i < array.length; ++i) {
5170
- var sub = array[i], ok = true;
5171
- for (var j = 0; j < sub.changes.length; ++j) {
5172
- var cur = sub.changes[j];
5173
- if (!sub.copied) { cur.from = copyPos(cur.from); cur.to = copyPos(cur.to); }
5174
- if (to < cur.from.line) {
5175
- cur.from.line += diff;
5176
- cur.to.line += diff;
5177
- } else if (from <= cur.to.line) {
5178
- ok = false;
5179
- break;
5180
- }
5181
- }
5182
- if (!sub.copied) {
5183
- sub.anchorBefore = copyPos(sub.anchorBefore); sub.headBefore = copyPos(sub.headBefore);
5184
- sub.anchorAfter = copyPos(sub.anchorAfter); sub.readAfter = copyPos(sub.headAfter);
5185
- sub.copied = true;
5186
- }
5187
- if (!ok) {
5188
- array.splice(0, i + 1);
5189
- i = 0;
5190
- } else {
5191
- rebaseHistSel(sub.anchorBefore); rebaseHistSel(sub.headBefore);
5192
- rebaseHistSel(sub.anchorAfter); rebaseHistSel(sub.headAfter);
5193
- }
5194
- }
5195
- }
5196
-
5197
- function rebaseHist(hist, change) {
5198
- var from = change.from.line, to = change.to.line, diff = change.text.length - (to - from) - 1;
5199
- rebaseHistArray(hist.done, from, to, diff);
5200
- rebaseHistArray(hist.undone, from, to, diff);
5201
- }
5202
-
5203
- // EVENT OPERATORS
5204
-
5205
- function stopMethod() {e_stop(this);}
5206
- // Ensure an event has a stop method.
5207
- function addStop(event) {
5208
- if (!event.stop) event.stop = stopMethod;
5209
- return event;
5210
- }
5211
-
5212
- function e_preventDefault(e) {
5213
- if (e.preventDefault) e.preventDefault();
5214
- else e.returnValue = false;
5215
- }
5216
- function e_stopPropagation(e) {
5217
- if (e.stopPropagation) e.stopPropagation();
5218
- else e.cancelBubble = true;
5219
- }
5220
- function e_defaultPrevented(e) {
5221
- return e.defaultPrevented != null ? e.defaultPrevented : e.returnValue == false;
5222
- }
5223
- function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
5224
- CodeMirror.e_stop = e_stop;
5225
- CodeMirror.e_preventDefault = e_preventDefault;
5226
- CodeMirror.e_stopPropagation = e_stopPropagation;
5227
-
5228
- function e_target(e) {return e.target || e.srcElement;}
5229
- function e_button(e) {
5230
- var b = e.which;
5231
- if (b == null) {
5232
- if (e.button & 1) b = 1;
5233
- else if (e.button & 2) b = 3;
5234
- else if (e.button & 4) b = 2;
5235
- }
5236
- if (mac && e.ctrlKey && b == 1) b = 3;
5237
- return b;
5238
- }
5239
-
5240
- // EVENT HANDLING
5241
-
5242
- function on(emitter, type, f) {
5243
- if (emitter.addEventListener)
5244
- emitter.addEventListener(type, f, false);
5245
- else if (emitter.attachEvent)
5246
- emitter.attachEvent("on" + type, f);
5247
- else {
5248
- var map = emitter._handlers || (emitter._handlers = {});
5249
- var arr = map[type] || (map[type] = []);
5250
- arr.push(f);
5251
- }
5252
- }
5253
-
5254
- function off(emitter, type, f) {
5255
- if (emitter.removeEventListener)
5256
- emitter.removeEventListener(type, f, false);
5257
- else if (emitter.detachEvent)
5258
- emitter.detachEvent("on" + type, f);
5259
- else {
5260
- var arr = emitter._handlers && emitter._handlers[type];
5261
- if (!arr) return;
5262
- for (var i = 0; i < arr.length; ++i)
5263
- if (arr[i] == f) { arr.splice(i, 1); break; }
5264
- }
5265
- }
5266
-
5267
- function signal(emitter, type /*, values...*/) {
5268
- var arr = emitter._handlers && emitter._handlers[type];
5269
- if (!arr) return;
5270
- var args = Array.prototype.slice.call(arguments, 2);
5271
- for (var i = 0; i < arr.length; ++i) arr[i].apply(null, args);
5272
- }
5273
-
5274
- var delayedCallbacks, delayedCallbackDepth = 0;
5275
- function signalLater(emitter, type /*, values...*/) {
5276
- var arr = emitter._handlers && emitter._handlers[type];
5277
- if (!arr) return;
5278
- var args = Array.prototype.slice.call(arguments, 2);
5279
- if (!delayedCallbacks) {
5280
- ++delayedCallbackDepth;
5281
- delayedCallbacks = [];
5282
- setTimeout(fireDelayed, 0);
5283
- }
5284
- function bnd(f) {return function(){f.apply(null, args);};};
5285
- for (var i = 0; i < arr.length; ++i)
5286
- delayedCallbacks.push(bnd(arr[i]));
5287
- }
5288
-
5289
- function signalDOMEvent(cm, e, override) {
5290
- signal(cm, override || e.type, cm, e);
5291
- return e_defaultPrevented(e) || e.codemirrorIgnore;
5292
- }
5293
-
5294
- function fireDelayed() {
5295
- --delayedCallbackDepth;
5296
- var delayed = delayedCallbacks;
5297
- delayedCallbacks = null;
5298
- for (var i = 0; i < delayed.length; ++i) delayed[i]();
5299
- }
5300
-
5301
- function hasHandler(emitter, type) {
5302
- var arr = emitter._handlers && emitter._handlers[type];
5303
- return arr && arr.length > 0;
5304
- }
5305
-
5306
- CodeMirror.on = on; CodeMirror.off = off; CodeMirror.signal = signal;
5307
-
5308
- function eventMixin(ctor) {
5309
- ctor.prototype.on = function(type, f) {on(this, type, f);};
5310
- ctor.prototype.off = function(type, f) {off(this, type, f);};
5311
- }
5312
-
5313
- // MISC UTILITIES
5314
-
5315
- // Number of pixels added to scroller and sizer to hide scrollbar
5316
- var scrollerCutOff = 30;
5317
-
5318
- // Returned or thrown by various protocols to signal 'I'm not
5319
- // handling this'.
5320
- var Pass = CodeMirror.Pass = {toString: function(){return "CodeMirror.Pass";}};
5321
-
5322
- function Delayed() {this.id = null;}
5323
- Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
5324
-
5325
- // Counts the column offset in a string, taking tabs into account.
5326
- // Used mostly to find indentation.
5327
- function countColumn(string, end, tabSize, startIndex, startValue) {
5328
- if (end == null) {
5329
- end = string.search(/[^\s\u00a0]/);
5330
- if (end == -1) end = string.length;
5331
- }
5332
- for (var i = startIndex || 0, n = startValue || 0; i < end; ++i) {
5333
- if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
5334
- else ++n;
5335
- }
5336
- return n;
5337
- }
5338
- CodeMirror.countColumn = countColumn;
5339
-
5340
- var spaceStrs = [""];
5341
- function spaceStr(n) {
5342
- while (spaceStrs.length <= n)
5343
- spaceStrs.push(lst(spaceStrs) + " ");
5344
- return spaceStrs[n];
5345
- }
5346
-
5347
- function lst(arr) { return arr[arr.length-1]; }
5348
-
5349
- function selectInput(node) {
5350
- if (ios) { // Mobile Safari apparently has a bug where select() is broken.
5351
- node.selectionStart = 0;
5352
- node.selectionEnd = node.value.length;
5353
- } else {
5354
- // Suppress mysterious IE10 errors
5355
- try { node.select(); }
5356
- catch(_e) {}
5357
- }
5358
- }
5359
-
5360
- function indexOf(collection, elt) {
5361
- if (collection.indexOf) return collection.indexOf(elt);
5362
- for (var i = 0, e = collection.length; i < e; ++i)
5363
- if (collection[i] == elt) return i;
5364
- return -1;
5365
- }
5366
-
5367
- function createObj(base, props) {
5368
- function Obj() {}
5369
- Obj.prototype = base;
5370
- var inst = new Obj();
5371
- if (props) copyObj(props, inst);
5372
- return inst;
5373
- }
5374
-
5375
- function copyObj(obj, target) {
5376
- if (!target) target = {};
5377
- for (var prop in obj) if (obj.hasOwnProperty(prop)) target[prop] = obj[prop];
5378
- return target;
5379
- }
5380
-
5381
- function emptyArray(size) {
5382
- for (var a = [], i = 0; i < size; ++i) a.push(undefined);
5383
- return a;
5384
- }
5385
-
5386
- function bind(f) {
5387
- var args = Array.prototype.slice.call(arguments, 1);
5388
- return function(){return f.apply(null, args);};
5389
- }
5390
-
5391
- var nonASCIISingleCaseWordChar = /[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/;
5392
- function isWordChar(ch) {
5393
- return /\w/.test(ch) || ch > "\x80" &&
5394
- (ch.toUpperCase() != ch.toLowerCase() || nonASCIISingleCaseWordChar.test(ch));
5395
- }
5396
-
5397
- function isEmpty(obj) {
5398
- for (var n in obj) if (obj.hasOwnProperty(n) && obj[n]) return false;
5399
- return true;
5400
- }
5401
-
5402
- var isExtendingChar = /[\u0300-\u036F\u0483-\u0487\u0488-\u0489\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\uA66F\uA670-\uA672\uA674-\uA67D\uA69F\udc00-\udfff]/;
5403
-
5404
- // DOM UTILITIES
5405
-
5406
- function elt(tag, content, className, style) {
5407
- var e = document.createElement(tag);
5408
- if (className) e.className = className;
5409
- if (style) e.style.cssText = style;
5410
- if (typeof content == "string") setTextContent(e, content);
5411
- else if (content) for (var i = 0; i < content.length; ++i) e.appendChild(content[i]);
5412
- return e;
5413
- }
5414
-
5415
- function removeChildren(e) {
5416
- for (var count = e.childNodes.length; count > 0; --count)
5417
- e.removeChild(e.firstChild);
5418
- return e;
5419
- }
5420
-
5421
- function removeChildrenAndAdd(parent, e) {
5422
- return removeChildren(parent).appendChild(e);
5423
- }
5424
-
5425
- function setTextContent(e, str) {
5426
- if (ie_lt9) {
5427
- e.innerHTML = "";
5428
- e.appendChild(document.createTextNode(str));
5429
- } else e.textContent = str;
5430
- }
5431
-
5432
- function getRect(node) {
5433
- return node.getBoundingClientRect();
5434
- }
5435
- CodeMirror.replaceGetRect = function(f) { getRect = f; };
5436
-
5437
- // FEATURE DETECTION
5438
-
5439
- // Detect drag-and-drop
5440
- var dragAndDrop = function() {
5441
- // There is *some* kind of drag-and-drop support in IE6-8, but I
5442
- // couldn't get it to work yet.
5443
- if (ie_lt9) return false;
5444
- var div = elt('div');
5445
- return "draggable" in div || "dragDrop" in div;
5446
- }();
5447
-
5448
- // For a reason I have yet to figure out, some browsers disallow
5449
- // word wrapping between certain characters *only* if a new inline
5450
- // element is started between them. This makes it hard to reliably
5451
- // measure the position of things, since that requires inserting an
5452
- // extra span. This terribly fragile set of tests matches the
5453
- // character combinations that suffer from this phenomenon on the
5454
- // various browsers.
5455
- function spanAffectsWrapping() { return false; }
5456
- if (gecko) // Only for "$'"
5457
- spanAffectsWrapping = function(str, i) {
5458
- return str.charCodeAt(i - 1) == 36 && str.charCodeAt(i) == 39;
5459
- };
5460
- else if (safari && !/Version\/([6-9]|\d\d)\b/.test(navigator.userAgent))
5461
- spanAffectsWrapping = function(str, i) {
5462
- return /\-[^ \-?]|\?[^ !\'\"\),.\-\/:;\?\]\}]/.test(str.slice(i - 1, i + 1));
5463
- };
5464
- else if (webkit && !/Chrome\/(?:29|[3-9]\d|\d\d\d)\./.test(navigator.userAgent))
5465
- spanAffectsWrapping = function(str, i) {
5466
- if (i > 1 && str.charCodeAt(i - 1) == 45) {
5467
- if (/\w/.test(str.charAt(i - 2)) && /[^\-?\.]/.test(str.charAt(i))) return true;
5468
- if (i > 2 && /[\d\.,]/.test(str.charAt(i - 2)) && /[\d\.,]/.test(str.charAt(i))) return false;
5469
- }
5470
- return /[~!#%&*)=+}\]|\"\.>,:;][({[<]|-[^\-?\.\u2010-\u201f\u2026]|\?[\w~`@#$%\^&*(_=+{[|><]|…[\w~`@#$%\^&*(_=+{[><]/.test(str.slice(i - 1, i + 1));
5471
- };
5472
-
5473
- var knownScrollbarWidth;
5474
- function scrollbarWidth(measure) {
5475
- if (knownScrollbarWidth != null) return knownScrollbarWidth;
5476
- var test = elt("div", null, null, "width: 50px; height: 50px; overflow-x: scroll");
5477
- removeChildrenAndAdd(measure, test);
5478
- if (test.offsetWidth)
5479
- knownScrollbarWidth = test.offsetHeight - test.clientHeight;
5480
- return knownScrollbarWidth || 0;
5481
- }
5482
-
5483
- var zwspSupported;
5484
- function zeroWidthElement(measure) {
5485
- if (zwspSupported == null) {
5486
- var test = elt("span", "\u200b");
5487
- removeChildrenAndAdd(measure, elt("span", [test, document.createTextNode("x")]));
5488
- if (measure.firstChild.offsetHeight != 0)
5489
- zwspSupported = test.offsetWidth <= 1 && test.offsetHeight > 2 && !ie_lt8;
5490
- }
5491
- if (zwspSupported) return elt("span", "\u200b");
5492
- else return elt("span", "\u00a0", null, "display: inline-block; width: 1px; margin-right: -1px");
5493
- }
5494
-
5495
- // See if "".split is the broken IE version, if so, provide an
5496
- // alternative way to split lines.
5497
- var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
5498
- var pos = 0, result = [], l = string.length;
5499
- while (pos <= l) {
5500
- var nl = string.indexOf("\n", pos);
5501
- if (nl == -1) nl = string.length;
5502
- var line = string.slice(pos, string.charAt(nl - 1) == "\r" ? nl - 1 : nl);
5503
- var rt = line.indexOf("\r");
5504
- if (rt != -1) {
5505
- result.push(line.slice(0, rt));
5506
- pos += rt + 1;
5507
- } else {
5508
- result.push(line);
5509
- pos = nl + 1;
5510
- }
5511
- }
5512
- return result;
5513
- } : function(string){return string.split(/\r\n?|\n/);};
5514
- CodeMirror.splitLines = splitLines;
5515
-
5516
- var hasSelection = window.getSelection ? function(te) {
5517
- try { return te.selectionStart != te.selectionEnd; }
5518
- catch(e) { return false; }
5519
- } : function(te) {
5520
- try {var range = te.ownerDocument.selection.createRange();}
5521
- catch(e) {}
5522
- if (!range || range.parentElement() != te) return false;
5523
- return range.compareEndPoints("StartToEnd", range) != 0;
5524
- };
5525
-
5526
- var hasCopyEvent = (function() {
5527
- var e = elt("div");
5528
- if ("oncopy" in e) return true;
5529
- e.setAttribute("oncopy", "return;");
5530
- return typeof e.oncopy == 'function';
5531
- })();
5532
-
5533
- // KEY NAMING
5534
-
5535
- var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
5536
- 19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
5537
- 36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
5538
- 46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 109: "-", 107: "=", 127: "Delete",
5539
- 186: ";", 187: "=", 188: ",", 189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\",
5540
- 221: "]", 222: "'", 63276: "PageUp", 63277: "PageDown", 63275: "End", 63273: "Home",
5541
- 63234: "Left", 63232: "Up", 63235: "Right", 63233: "Down", 63302: "Insert", 63272: "Delete"};
5542
- CodeMirror.keyNames = keyNames;
5543
- (function() {
5544
- // Number keys
5545
- for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
5546
- // Alphabetic keys
5547
- for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
5548
- // Function keys
5549
- for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
5550
- })();
5551
-
5552
- // BIDI HELPERS
5553
-
5554
- function iterateBidiSections(order, from, to, f) {
5555
- if (!order) return f(from, to, "ltr");
5556
- var found = false;
5557
- for (var i = 0; i < order.length; ++i) {
5558
- var part = order[i];
5559
- if (part.from < to && part.to > from || from == to && part.to == from) {
5560
- f(Math.max(part.from, from), Math.min(part.to, to), part.level == 1 ? "rtl" : "ltr");
5561
- found = true;
5562
- }
5563
- }
5564
- if (!found) f(from, to, "ltr");
5565
- }
5566
-
5567
- function bidiLeft(part) { return part.level % 2 ? part.to : part.from; }
5568
- function bidiRight(part) { return part.level % 2 ? part.from : part.to; }
5569
-
5570
- function lineLeft(line) { var order = getOrder(line); return order ? bidiLeft(order[0]) : 0; }
5571
- function lineRight(line) {
5572
- var order = getOrder(line);
5573
- if (!order) return line.text.length;
5574
- return bidiRight(lst(order));
5575
- }
5576
-
5577
- function lineStart(cm, lineN) {
5578
- var line = getLine(cm.doc, lineN);
5579
- var visual = visualLine(cm.doc, line);
5580
- if (visual != line) lineN = lineNo(visual);
5581
- var order = getOrder(visual);
5582
- var ch = !order ? 0 : order[0].level % 2 ? lineRight(visual) : lineLeft(visual);
5583
- return Pos(lineN, ch);
5584
- }
5585
- function lineEnd(cm, lineN) {
5586
- var merged, line;
5587
- while (merged = collapsedSpanAtEnd(line = getLine(cm.doc, lineN)))
5588
- lineN = merged.find().to.line;
5589
- var order = getOrder(line);
5590
- var ch = !order ? line.text.length : order[0].level % 2 ? lineLeft(line) : lineRight(line);
5591
- return Pos(lineN, ch);
5592
- }
5593
-
5594
- function compareBidiLevel(order, a, b) {
5595
- var linedir = order[0].level;
5596
- if (a == linedir) return true;
5597
- if (b == linedir) return false;
5598
- return a < b;
5599
- }
5600
- var bidiOther;
5601
- function getBidiPartAt(order, pos) {
5602
- for (var i = 0, found; i < order.length; ++i) {
5603
- var cur = order[i];
5604
- if (cur.from < pos && cur.to > pos) { bidiOther = null; return i; }
5605
- if (cur.from == pos || cur.to == pos) {
5606
- if (found == null) {
5607
- found = i;
5608
- } else if (compareBidiLevel(order, cur.level, order[found].level)) {
5609
- bidiOther = found;
5610
- return i;
5611
- } else {
5612
- bidiOther = i;
5613
- return found;
5614
- }
5615
- }
5616
- }
5617
- bidiOther = null;
5618
- return found;
5619
- }
5620
-
5621
- function moveInLine(line, pos, dir, byUnit) {
5622
- if (!byUnit) return pos + dir;
5623
- do pos += dir;
5624
- while (pos > 0 && isExtendingChar.test(line.text.charAt(pos)));
5625
- return pos;
5626
- }
5627
-
5628
- // This is somewhat involved. It is needed in order to move
5629
- // 'visually' through bi-directional text -- i.e., pressing left
5630
- // should make the cursor go left, even when in RTL text. The
5631
- // tricky part is the 'jumps', where RTL and LTR text touch each
5632
- // other. This often requires the cursor offset to move more than
5633
- // one unit, in order to visually move one unit.
5634
- function moveVisually(line, start, dir, byUnit) {
5635
- var bidi = getOrder(line);
5636
- if (!bidi) return moveLogically(line, start, dir, byUnit);
5637
- var pos = getBidiPartAt(bidi, start), part = bidi[pos];
5638
- var target = moveInLine(line, start, part.level % 2 ? -dir : dir, byUnit);
5639
-
5640
- for (;;) {
5641
- if (target > part.from && target < part.to) return target;
5642
- if (target == part.from || target == part.to) {
5643
- if (getBidiPartAt(bidi, target) == pos) return target;
5644
- part = bidi[pos += dir];
5645
- return (dir > 0) == part.level % 2 ? part.to : part.from;
5646
- } else {
5647
- part = bidi[pos += dir];
5648
- if (!part) return null;
5649
- if ((dir > 0) == part.level % 2)
5650
- target = moveInLine(line, part.to, -1, byUnit);
5651
- else
5652
- target = moveInLine(line, part.from, 1, byUnit);
5653
- }
5654
- }
5655
- }
5656
-
5657
- function moveLogically(line, start, dir, byUnit) {
5658
- var target = start + dir;
5659
- if (byUnit) while (target > 0 && isExtendingChar.test(line.text.charAt(target))) target += dir;
5660
- return target < 0 || target > line.text.length ? null : target;
5661
- }
5662
-
5663
- // Bidirectional ordering algorithm
5664
- // See http://unicode.org/reports/tr9/tr9-13.html for the algorithm
5665
- // that this (partially) implements.
5666
-
5667
- // One-char codes used for character types:
5668
- // L (L): Left-to-Right
5669
- // R (R): Right-to-Left
5670
- // r (AL): Right-to-Left Arabic
5671
- // 1 (EN): European Number
5672
- // + (ES): European Number Separator
5673
- // % (ET): European Number Terminator
5674
- // n (AN): Arabic Number
5675
- // , (CS): Common Number Separator
5676
- // m (NSM): Non-Spacing Mark
5677
- // b (BN): Boundary Neutral
5678
- // s (B): Paragraph Separator
5679
- // t (S): Segment Separator
5680
- // w (WS): Whitespace
5681
- // N (ON): Other Neutrals
5682
-
5683
- // Returns null if characters are ordered as they appear
5684
- // (left-to-right), or an array of sections ({from, to, level}
5685
- // objects) in the order in which they occur visually.
5686
- var bidiOrdering = (function() {
5687
- // Character types for codepoints 0 to 0xff
5688
- var lowTypes = "bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLL";
5689
- // Character types for codepoints 0x600 to 0x6ff
5690
- var arabicTypes = "rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmmrrrrrrrrrrrrrrrrrr";
5691
- function charType(code) {
5692
- if (code <= 0xff) return lowTypes.charAt(code);
5693
- else if (0x590 <= code && code <= 0x5f4) return "R";
5694
- else if (0x600 <= code && code <= 0x6ff) return arabicTypes.charAt(code - 0x600);
5695
- else if (0x700 <= code && code <= 0x8ac) return "r";
5696
- else return "L";
5697
- }
5698
-
5699
- var bidiRE = /[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/;
5700
- var isNeutral = /[stwN]/, isStrong = /[LRr]/, countsAsLeft = /[Lb1n]/, countsAsNum = /[1n]/;
5701
- // Browsers seem to always treat the boundaries of block elements as being L.
5702
- var outerType = "L";
5703
-
5704
- return function(str) {
5705
- if (!bidiRE.test(str)) return false;
5706
- var len = str.length, types = [];
5707
- for (var i = 0, type; i < len; ++i)
5708
- types.push(type = charType(str.charCodeAt(i)));
5709
-
5710
- // W1. Examine each non-spacing mark (NSM) in the level run, and
5711
- // change the type of the NSM to the type of the previous
5712
- // character. If the NSM is at the start of the level run, it will
5713
- // get the type of sor.
5714
- for (var i = 0, prev = outerType; i < len; ++i) {
5715
- var type = types[i];
5716
- if (type == "m") types[i] = prev;
5717
- else prev = type;
5718
- }
5719
-
5720
- // W2. Search backwards from each instance of a European number
5721
- // until the first strong type (R, L, AL, or sor) is found. If an
5722
- // AL is found, change the type of the European number to Arabic
5723
- // number.
5724
- // W3. Change all ALs to R.
5725
- for (var i = 0, cur = outerType; i < len; ++i) {
5726
- var type = types[i];
5727
- if (type == "1" && cur == "r") types[i] = "n";
5728
- else if (isStrong.test(type)) { cur = type; if (type == "r") types[i] = "R"; }
5729
- }
5730
-
5731
- // W4. A single European separator between two European numbers
5732
- // changes to a European number. A single common separator between
5733
- // two numbers of the same type changes to that type.
5734
- for (var i = 1, prev = types[0]; i < len - 1; ++i) {
5735
- var type = types[i];
5736
- if (type == "+" && prev == "1" && types[i+1] == "1") types[i] = "1";
5737
- else if (type == "," && prev == types[i+1] &&
5738
- (prev == "1" || prev == "n")) types[i] = prev;
5739
- prev = type;
5740
- }
5741
-
5742
- // W5. A sequence of European terminators adjacent to European
5743
- // numbers changes to all European numbers.
5744
- // W6. Otherwise, separators and terminators change to Other
5745
- // Neutral.
5746
- for (var i = 0; i < len; ++i) {
5747
- var type = types[i];
5748
- if (type == ",") types[i] = "N";
5749
- else if (type == "%") {
5750
- for (var end = i + 1; end < len && types[end] == "%"; ++end) {}
5751
- var replace = (i && types[i-1] == "!") || (end < len - 1 && types[end] == "1") ? "1" : "N";
5752
- for (var j = i; j < end; ++j) types[j] = replace;
5753
- i = end - 1;
5754
- }
5755
- }
5756
-
5757
- // W7. Search backwards from each instance of a European number
5758
- // until the first strong type (R, L, or sor) is found. If an L is
5759
- // found, then change the type of the European number to L.
5760
- for (var i = 0, cur = outerType; i < len; ++i) {
5761
- var type = types[i];
5762
- if (cur == "L" && type == "1") types[i] = "L";
5763
- else if (isStrong.test(type)) cur = type;
5764
- }
5765
-
5766
- // N1. A sequence of neutrals takes the direction of the
5767
- // surrounding strong text if the text on both sides has the same
5768
- // direction. European and Arabic numbers act as if they were R in
5769
- // terms of their influence on neutrals. Start-of-level-run (sor)
5770
- // and end-of-level-run (eor) are used at level run boundaries.
5771
- // N2. Any remaining neutrals take the embedding direction.
5772
- for (var i = 0; i < len; ++i) {
5773
- if (isNeutral.test(types[i])) {
5774
- for (var end = i + 1; end < len && isNeutral.test(types[end]); ++end) {}
5775
- var before = (i ? types[i-1] : outerType) == "L";
5776
- var after = (end < len - 1 ? types[end] : outerType) == "L";
5777
- var replace = before || after ? "L" : "R";
5778
- for (var j = i; j < end; ++j) types[j] = replace;
5779
- i = end - 1;
5780
- }
5781
- }
5782
-
5783
- // Here we depart from the documented algorithm, in order to avoid
5784
- // building up an actual levels array. Since there are only three
5785
- // levels (0, 1, 2) in an implementation that doesn't take
5786
- // explicit embedding into account, we can build up the order on
5787
- // the fly, without following the level-based algorithm.
5788
- var order = [], m;
5789
- for (var i = 0; i < len;) {
5790
- if (countsAsLeft.test(types[i])) {
5791
- var start = i;
5792
- for (++i; i < len && countsAsLeft.test(types[i]); ++i) {}
5793
- order.push({from: start, to: i, level: 0});
5794
- } else {
5795
- var pos = i, at = order.length;
5796
- for (++i; i < len && types[i] != "L"; ++i) {}
5797
- for (var j = pos; j < i;) {
5798
- if (countsAsNum.test(types[j])) {
5799
- if (pos < j) order.splice(at, 0, {from: pos, to: j, level: 1});
5800
- var nstart = j;
5801
- for (++j; j < i && countsAsNum.test(types[j]); ++j) {}
5802
- order.splice(at, 0, {from: nstart, to: j, level: 2});
5803
- pos = j;
5804
- } else ++j;
5805
- }
5806
- if (pos < i) order.splice(at, 0, {from: pos, to: i, level: 1});
5807
- }
5808
- }
5809
- if (order[0].level == 1 && (m = str.match(/^\s+/))) {
5810
- order[0].from = m[0].length;
5811
- order.unshift({from: 0, to: m[0].length, level: 0});
5812
- }
5813
- if (lst(order).level == 1 && (m = str.match(/\s+$/))) {
5814
- lst(order).to -= m[0].length;
5815
- order.push({from: len - m[0].length, to: len, level: 0});
5816
- }
5817
- if (order[0].level != lst(order).level)
5818
- order.push({from: len, to: len, level: order[0].level});
5819
-
5820
- return order;
5821
- };
5822
- })();
5823
-
5824
- // THE END
5825
-
5826
- CodeMirror.version = "3.16.0";
5827
-
5828
- return CodeMirror;
5829
- })();
1
+ window.CodeMirror=function(){function m(a,b){if(!(this instanceof m))return new m(a,b);this.options=b=b||{};for(var c in Rb)!b.hasOwnProperty(c)&&Rb.hasOwnProperty(c)&&(b[c]=Rb[c]);Sb(b);c=this.display=Td(a,"string"==typeof b.value?0:b.value.first);c.wrapper.CodeMirror=this;Nc(this);b.autofocus&&!Tb&&N(this);this.state={keyMaps:[],overlays:[],modeGen:0,overwrite:!1,focused:!1,suppressEdits:!1,pasteIncoming:!1,draggingText:!1,highlight:new Ub};Oc(this);b.lineWrapping&&(this.display.wrapper.className+= " CodeMirror-wrap");var d=b.value;"string"==typeof d&&(d=new I(b.value,b.mode));t(this,Pc)(this,d);B&&setTimeout(O(Y,this,!0),20);Ud(this);var e;try{e=document.activeElement==c.input}catch(f){}e||b.autofocus&&!Tb?setTimeout(O(ha,this),20):Vb(this);t(this,function(){for(var a in pa)if(pa.propertyIsEnumerable(a))pa[a](this,b[a],Qc);for(a=0;a<Wb.length;++a)Wb[a](this)})()}function Td(a,b){var c={},d=c.input=p("textarea",null,null,"position: absolute; padding: 0; width: 1px; height: 1em; outline: none; font-size: 4px;"); K?d.style.width="1000px":d.setAttribute("wrap","off");Ia&&(d.style.border="1px solid black");d.setAttribute("autocorrect","off");d.setAttribute("autocapitalize","off");d.setAttribute("spellcheck","false");c.inputDiv=p("div",[d],null,"overflow: hidden; position: relative; width: 3px; height: 0px;");c.scrollbarH=p("div",[p("div",null,null,"height: 1px")],"CodeMirror-hscrollbar");c.scrollbarV=p("div",[p("div",null,null,"width: 1px")],"CodeMirror-vscrollbar");c.scrollbarFiller=p("div",null,"CodeMirror-scrollbar-filler"); c.gutterFiller=p("div",null,"CodeMirror-gutter-filler");c.lineDiv=p("div",null,"CodeMirror-code");c.selectionDiv=p("div",null,null,"position: relative; z-index: 1");c.cursor=p("div","\u00a0","CodeMirror-cursor");c.otherCursor=p("div","\u00a0","CodeMirror-cursor CodeMirror-secondarycursor");c.measure=p("div",null,"CodeMirror-measure");c.lineSpace=p("div",[c.measure,c.selectionDiv,c.lineDiv,c.cursor,c.otherCursor],null,"position: relative; outline: none");c.mover=p("div",[p("div",[c.lineSpace],"CodeMirror-lines")], null,"position: relative");c.sizer=p("div",[c.mover],"CodeMirror-sizer");c.heightForcer=p("div",null,null,"position: absolute; height: "+qa+"px; width: 1px;");c.gutters=p("div",null,"CodeMirror-gutters");c.lineGutter=null;c.scroller=p("div",[c.sizer,c.heightForcer,c.gutters],"CodeMirror-scroll");c.scroller.setAttribute("tabIndex","-1");c.wrapper=p("div",[c.inputDiv,c.scrollbarH,c.scrollbarV,c.scrollbarFiller,c.gutterFiller,c.scroller],"CodeMirror");ra&&(c.gutters.style.zIndex=-1,c.scroller.style.paddingRight= 0);a.appendChild?a.appendChild(c.wrapper):a(c.wrapper);Ia&&(d.style.width="0px");K||(c.scroller.draggable=!0);Xb?(c.inputDiv.style.height="1px",c.inputDiv.style.position="absolute"):ra&&(c.scrollbarH.style.minWidth=c.scrollbarV.style.minWidth="18px");c.viewOffset=c.lastSizeC=0;c.showingFrom=c.showingTo=b;c.lineNumWidth=c.lineNumInnerWidth=c.lineNumChars=null;c.prevInput="";c.alignWidgets=!1;c.pollingFast=!1;c.poll=new Ub;c.cachedCharWidth=c.cachedTextHeight=null;c.measureLineCache=[];c.measureLineCachePos= 0;c.inaccurateSelection=!1;c.maxLine=null;c.maxLineLength=0;c.maxLineChanged=!1;c.wheelDX=c.wheelDY=c.wheelStartX=c.wheelStartY=null;return c}function Ja(a){a.doc.mode=m.getMode(a.options,a.doc.modeOption);a.doc.iter(function(a){a.stateAfter&&(a.stateAfter=null);a.styles&&(a.styles=null)});a.doc.frontier=a.doc.first;Ka(a,100);a.state.modeGen++;a.curOp&&D(a)}function Rc(a){var b=sa(a.display),c=a.options.lineWrapping,d=c&&Math.max(5,a.display.scroller.clientWidth/Sc(a.display)-3);return function(e){return ia(a.doc, e)?0:c?(Math.ceil(e.text.length/d)||1)*b:b}}function Tc(a){var b=a.doc,c=Rc(a);b.iter(function(a){var b=c(a);b!=a.height&&R(a,b)})}function Uc(a){var b=Z[a.options.keyMap],c=b.style;a.display.wrapper.className=a.display.wrapper.className.replace(/\s*cm-keymap-\S+/g,"")+(c?" cm-keymap-"+c:"");a.state.disableInput=b.disableInput}function Oc(a){a.display.wrapper.className=a.display.wrapper.className.replace(/\s*cm-s-\S+/g,"")+a.options.theme.replace(/(^|\s)\s*/g," cm-s-");ta(a)}function La(a){Nc(a); D(a);setTimeout(function(){Yb(a)},20)}function Nc(a){var b=a.display.gutters,c=a.options.gutters;Ma(b);for(var d=0;d<c.length;++d){var e=c[d],f=b.appendChild(p("div",null,"CodeMirror-gutter "+e));"CodeMirror-linenumbers"==e&&(a.display.lineGutter=f,f.style.width=(a.display.lineNumWidth||1)+"px")}b.style.display=d?"":"none"}function mb(a,b){if(0==b.height)return 0;for(var c=b.text.length,d,e=b;d=ua(e,-1);)d=d.find(),e=u(a,d.from.line),c+=d.from.ch-d.to.ch;for(e=b;d=nb(e);)d=d.find(),c-=e.text.length- d.from.ch,e=u(a,d.to.line),c+=e.text.length-d.to.ch;return c}function Zb(a){var b=a.display,c=a.doc;b.maxLine=u(c,c.first);b.maxLineLength=mb(c,b.maxLine);b.maxLineChanged=!0;c.iter(function(a){var e=mb(c,a);e>b.maxLineLength&&(b.maxLineLength=e,b.maxLine=a)})}function Sb(a){for(var b=!1,c=0;c<a.gutters.length;++c)"CodeMirror-linenumbers"==a.gutters[c]&&(a.lineNumbers?b=!0:a.gutters.splice(c--,1));!b&&a.lineNumbers&&a.gutters.push("CodeMirror-linenumbers")}function $b(a){var b=a.display,c=a.doc.height+ (b.mover.offsetHeight-b.lineSpace.offsetHeight);b.sizer.style.minHeight=b.heightForcer.style.top=c+"px";b.gutters.style.height=Math.max(c,b.scroller.clientHeight-qa)+"px";var c=Math.max(c,b.scroller.scrollHeight),d=b.scroller.scrollWidth>b.scroller.clientWidth+1,e=c>b.scroller.clientHeight+1;e?(b.scrollbarV.style.display="block",b.scrollbarV.style.bottom=d?Na(b.measure)+"px":"0",b.scrollbarV.firstChild.style.height=c-b.scroller.clientHeight+b.scrollbarV.clientHeight+"px"):(b.scrollbarV.style.display= "",b.scrollbarV.firstChild.style.height="0");d?(b.scrollbarH.style.display="block",b.scrollbarH.style.right=e?Na(b.measure)+"px":"0",b.scrollbarH.firstChild.style.width=b.scroller.scrollWidth-b.scroller.clientWidth+b.scrollbarH.clientWidth+"px"):(b.scrollbarH.style.display="",b.scrollbarH.firstChild.style.width="0");d&&e?(b.scrollbarFiller.style.display="block",b.scrollbarFiller.style.height=b.scrollbarFiller.style.width=Na(b.measure)+"px"):b.scrollbarFiller.style.display="";d&&a.options.coverGutterNextToScrollbar&& a.options.fixedGutter?(b.gutterFiller.style.display="block",b.gutterFiller.style.height=Na(b.measure)+"px",b.gutterFiller.style.width=b.gutters.offsetWidth+"px"):b.gutterFiller.style.display="";Vd&&0===Na(b.measure)&&(b.scrollbarV.style.minWidth=b.scrollbarH.style.minHeight=Wd?"18px":"12px")}function ac(a,b,c){var d=a.scroller.scrollTop,e=a.wrapper.clientHeight;"number"==typeof c?d=c:c&&(d=c.top,e=c.bottom-c.top);d=Math.floor(d-a.lineSpace.offsetTop);a=Math.ceil(d+e);return{from:Oa(b,d),to:Oa(b,a)}} function Yb(a){var b=a.display;if(b.alignWidgets||b.gutters.firstChild&&a.options.fixedGutter){for(var c=bc(b)-b.scroller.scrollLeft+a.doc.scrollLeft,d=b.gutters.offsetWidth,e=c+"px",f=b.lineDiv.firstChild;f;f=f.nextSibling)if(f.alignable)for(var g=0,h=f.alignable;g<h.length;++g)h[g].style.left=e;a.options.fixedGutter&&(b.gutters.style.left=c+d+"px")}}function Xd(a){if(!a.options.lineNumbers)return!1;var b=a.doc,b=cc(a.options,b.first+b.size-1);a=a.display;if(b.length!=a.lineNumChars){var c=a.measure.appendChild(p("div", [p("div",b)],"CodeMirror-linenumber CodeMirror-gutter-elt")),d=c.firstChild.offsetWidth,c=c.offsetWidth-d;a.lineGutter.style.width="";a.lineNumInnerWidth=Math.max(d,a.lineGutter.offsetWidth-c);a.lineNumWidth=a.lineNumInnerWidth+c;a.lineNumChars=a.lineNumInnerWidth?b.length:-1;a.lineGutter.style.width=a.lineNumWidth+"px";return!0}return!1}function cc(a,b){return String(a.lineNumberFormatter(b+a.firstLineNumber))}function bc(a){return y(a.scroller).left-y(a.sizer).left}function ob(a,b,c,d){for(var e= a.display.showingFrom,f=a.display.showingTo,g,h=ac(a.display,a.doc,c);Yd(a,b,h,d);){d=!1;g=!0;dc(a);$b(a);c&&(c=Math.min(a.display.scroller.scrollHeight-a.display.scroller.clientHeight,"number"==typeof c?c:c.top));h=ac(a.display,a.doc,c);if(h.from>=a.display.showingFrom&&h.to<=a.display.showingTo)break;b=[]}g&&(M(a,"update",a),a.display.showingFrom==e&&a.display.showingTo==f||M(a,"viewportChange",a,a.display.showingFrom,a.display.showingTo));return g}function Yd(a,b,c,d){var e=a.display,f=a.doc;if(!e.wrapper.clientWidth)e.showingFrom= e.showingTo=f.first,e.viewOffset=0;else if(d||!(0==b.length&&c.from>e.showingFrom&&c.to<e.showingTo)){Xd(a)&&(b=[{from:f.first,to:f.first+f.size}]);var g=e.sizer.style.marginLeft=e.gutters.offsetWidth+"px";e.scrollbarH.style.left=a.options.fixedGutter?g:"0";g=Infinity;if(a.options.lineNumbers)for(var h=0;h<b.length;++h)b[h].diff&&b[h].from<g&&(g=b[h].from);var h=f.first+f.size,k=Math.max(c.from-a.options.viewportMargin,f.first);c=Math.min(h,c.to+a.options.viewportMargin);e.showingFrom<k&&20>k-e.showingFrom&& (k=Math.max(f.first,e.showingFrom));e.showingTo>c&&20>e.showingTo-c&&(c=Math.min(h,e.showingTo));if(Pa)for(k=P($(f,u(f,k)));c<h&&ia(f,u(f,c));)++c;var l=[{from:Math.max(e.showingFrom,f.first),to:Math.min(e.showingTo,h)}],l=l[0].from>=l[0].to?[]:Zd(l,b);if(Pa)for(h=0;h<l.length;++h){b=l[h];for(var n;n=nb(u(f,b.to-1));)if(n=n.find().from.line,n>b.from)b.to=n;else{l.splice(h--,1);break}}for(h=f=0;h<l.length;++h)b=l[h],b.from<k&&(b.from=k),b.to>c&&(b.to=c),b.from>=b.to?l.splice(h--,1):f+=b.to-b.from; if(d||f!=c-k||k!=e.showingFrom||c!=e.showingTo){l.sort(function(a,b){return a.from-b.from});try{var E=document.activeElement}catch(q){}f<0.7*(c-k)&&(e.lineDiv.style.display="none");$d(a,k,c,l,g);e.lineDiv.style.display="";E&&document.activeElement!=E&&E.offsetHeight&&E.focus();if(k!=e.showingFrom||c!=e.showingTo||e.lastSizeC!=e.wrapper.clientHeight)e.lastSizeC=e.wrapper.clientHeight,Ka(a,400);e.showingFrom=k;e.showingTo=c;ae(a);Vc(a);return!0}Vc(a)}}function ae(a){a=a.display;for(var b=a.lineDiv.offsetTop, c=a.lineDiv.firstChild,d;c;c=c.nextSibling)if(c.lineObj){if(ra){var e=c.offsetTop+c.offsetHeight;d=e-b;b=e}else d=y(c),d=d.bottom-d.top;e=c.lineObj.height-d;2>d&&(d=sa(a));if(0.001<e||-0.001>e)if(R(c.lineObj,d),d=c.lineObj.widgets)for(e=0;e<d.length;++e)d[e].height=d[e].node.offsetHeight}}function Vc(a){var b=a.display.viewOffset=Qa(a,u(a.doc,a.display.showingFrom));a.display.mover.style.top=b+"px"}function Zd(a,b){for(var c=0,d=b.length||0;c<d;++c){for(var e=b[c],f=[],g=e.diff||0,h=0,k=a.length;h< k;++h){var l=a[h];e.to<=l.from&&e.diff?f.push({from:l.from+g,to:l.to+g}):e.to<=l.from||e.from>=l.to?f.push(l):(e.from>l.from&&f.push({from:l.from,to:e.from}),e.to<l.to&&f.push({from:e.to+g,to:l.to+g}))}a=f}return a}function be(a){for(var b=a.display,c={},d={},e=b.gutters.firstChild,f=0;e;e=e.nextSibling,++f)c[a.options.gutters[f]]=e.offsetLeft,d[a.options.gutters[f]]=e.offsetWidth;return{fixedPos:bc(b),gutterTotalWidth:b.gutters.offsetWidth,gutterLeft:c,gutterWidth:d,wrapperWidth:b.wrapper.clientWidth}} function $d(a,b,c,d,e){function f(b){var c=b.nextSibling;K&&va&&a.display.currentWheelTarget==b?(b.style.display="none",b.lineObj=null):b.parentNode.removeChild(b);return c}var g=be(a),h=a.display,k=a.options.lineNumbers;d.length||K&&a.display.currentWheelTarget||Ma(h.lineDiv);var l=h.lineDiv,n=l.firstChild,E=d.shift(),q=b;for(a.doc.iter(b,c,function(b){E&&E.to==q&&(E=d.shift());if(ia(a.doc,b)){if(0!=b.height&&R(b,0),b.widgets&&n&&n.previousSibling)for(var c=0;c<b.widgets.length;++c){var h=b.widgets[c]; if(h.showIfHidden){var m=n.previousSibling;if(/pre/i.test(m.nodeName)){var C=p("div",null,null,"position: relative");m.parentNode.replaceChild(C,m);C.appendChild(m);m=C}C=m.appendChild(p("div",[h.node],"CodeMirror-linewidget"));h.handleMouseEvents||(C.ignoreEvents=!0);ec(h,C,m,g)}}}else if(E&&E.from<=q&&E.to>q){for(;n.lineObj!=b;)n=f(n);k&&e<=q&&n.lineNumber&&Wc(n.lineNumber,cc(a.options,q));n=n.nextSibling}else{if(b.widgets)for(var C=0,r=n;r&&20>C;++C,r=r.nextSibling)if(r.lineObj==b&&/div/i.test(r.nodeName)){c= r;break}var C=a,u=q,H=c,r=fc(C,b),G=b.gutterMarkers,s=C.display;if(C.options.lineNumbers||G||b.bgClass||b.wrapClass||b.widgets){if(H){H.alignable=null;for(var t=!0,v=0,w=null,x=H.firstChild,z;x;x=z)if(z=x.nextSibling,/\bCodeMirror-linewidget\b/.test(x.className)){for(var y=0;y<b.widgets.length;++y){var B=b.widgets[y];if(B.node==x.firstChild){B.above||w||(w=x);ec(B,x,H,g);++v;break}}if(y==b.widgets.length){t=!1;break}}else H.removeChild(x);H.insertBefore(r,w);t&&v==b.widgets.length&&(h=H,H.className= b.wrapClass||"")}h||(h=p("div",null,b.wrapClass,"position: relative"),h.appendChild(r));b.bgClass&&h.insertBefore(p("div",null,b.bgClass+" CodeMirror-linebackground"),h.firstChild);if(C.options.lineNumbers||G)if(m=h.insertBefore(p("div",null,null,"position: absolute; left: "+(C.options.fixedGutter?g.fixedPos:-g.gutterTotalWidth)+"px"),h.firstChild),C.options.fixedGutter&&(h.alignable||(h.alignable=[])).push(m),!C.options.lineNumbers||G&&G["CodeMirror-linenumbers"]||(h.lineNumber=m.appendChild(p("div", cc(C.options,u),"CodeMirror-linenumber CodeMirror-gutter-elt","left: "+g.gutterLeft["CodeMirror-linenumbers"]+"px; width: "+s.lineNumInnerWidth+"px"))),G)for(y=0;y<C.options.gutters.length;++y)B=C.options.gutters[y],(u=G.hasOwnProperty(B)&&G[B])&&m.appendChild(p("div",[u],"CodeMirror-gutter-elt","left: "+g.gutterLeft[B]+"px; width: "+g.gutterWidth[B]+"px"));ra&&(h.style.zIndex=2);if(b.widgets&&h!=H)for(y=0,H=b.widgets;y<H.length;++y)B=H[y],G=p("div",[B.node],"CodeMirror-linewidget"),B.handleMouseEvents|| (G.ignoreEvents=!0),ec(B,G,h,g),B.above?h.insertBefore(G,C.options.lineNumbers&&0!=b.height?m:r):h.appendChild(G),M(B,"redraw")}else h=r;if(h!=c)l.insertBefore(h,n);else{for(;n!=c;)n=f(n);n=n.nextSibling}h.lineObj=b}++q});n;)n=f(n)}function ec(a,b,c,d){a.noHScroll&&((c.alignable||(c.alignable=[])).push(b),c=d.wrapperWidth,b.style.left=d.fixedPos+"px",a.coverGutter||(c-=d.gutterTotalWidth,b.style.paddingLeft=d.gutterTotalWidth+"px"),b.style.width=c+"px");a.coverGutter&&(b.style.zIndex=5,b.style.position= "relative",a.noHScroll||(b.style.marginLeft=-d.gutterTotalWidth+"px"))}function dc(a){var b=a.display,c=x(a.doc.sel.from,a.doc.sel.to);if(c||a.options.showCursorWhenSelecting){var d=a.display,e=U(a,a.doc.sel.head,"div");d.cursor.style.left=e.left+"px";d.cursor.style.top=e.top+"px";d.cursor.style.height=Math.max(0,e.bottom-e.top)*a.options.cursorHeight+"px";d.cursor.style.display="";e.other?(d.otherCursor.style.display="",d.otherCursor.style.left=e.other.left+"px",d.otherCursor.style.top=e.other.top+ "px",d.otherCursor.style.height=0.85*(e.other.bottom-e.other.top)+"px"):d.otherCursor.style.display="none"}else b.cursor.style.display=b.otherCursor.style.display="none";c?b.selectionDiv.style.display="none":ce(a);a.options.moveInputWithCursor&&(a=U(a,a.doc.sel.head,"div"),c=y(b.wrapper),d=y(b.lineDiv),b.inputDiv.style.top=Math.max(0,Math.min(b.wrapper.clientHeight-10,a.top+d.top-c.top))+"px",b.inputDiv.style.left=Math.max(0,Math.min(b.wrapper.clientWidth-10,a.left+d.left-c.left))+"px")}function ce(a){function b(a, b,c,d){0>b&&(b=0);g.appendChild(p("div",null,"CodeMirror-selected","position: absolute; left: "+a+"px; top: "+b+"px; width: "+(null==c?h-a:c)+"px; height: "+(d-b)+"px"))}function c(c,d,f){var g=u(e,c),l=g.text.length,n,m;de(V(g),d||0,null==f?l:f,function(e,u,H){var p=rb(a,r(c,e),"div",g,"left"),s,t;e==u?(s=p,H=t=p.left):(s=rb(a,r(c,u-1),"div",g,"right"),"rtl"==H&&(H=p,p=s,s=H),H=p.left,t=s.right);null==d&&0==e&&(H=k);3<s.top-p.top&&(b(H,p.top,null,p.bottom),H=k,p.bottom<s.top&&b(H,p.bottom,null,s.top)); null==f&&u==l&&(t=h);if(!n||p.top<n.top||p.top==n.top&&p.left<n.left)n=p;if(!m||s.bottom>m.bottom||s.bottom==m.bottom&&s.right>m.right)m=s;H<k+1&&(H=k);b(H,s.top,t-H,s.bottom)});return{start:n,end:m}}var d=a.display,e=a.doc,f=a.doc.sel,g=document.createDocumentFragment(),h=d.lineSpace.offsetWidth,k=W(a.display.measure,p("pre",null,null,"text-align: left")).appendChild(p("span","x")).offsetLeft;if(f.from.line==f.to.line)c(f.from.line,f.from.ch,f.to.ch);else{var l=u(e,f.from.line),n=u(e,f.to.line), n=$(e,l)==$(e,n),l=c(f.from.line,f.from.ch,n?l.text.length:null).end,f=c(f.to.line,n?0:null,f.to.ch).start;n&&(l.top<f.top-2?(b(l.right,l.top,null,l.bottom),b(k,f.top,f.left,f.bottom)):b(l.right,l.top,f.left-l.right,l.bottom));l.bottom<f.top&&b(k,l.bottom,null,f.top)}W(d.selectionDiv,g);d.selectionDiv.style.display=""}function sb(a){if(a.state.focused){var b=a.display;clearInterval(b.blinker);var c=!0;b.cursor.style.visibility=b.otherCursor.style.visibility="";0<a.options.cursorBlinkRate&&(b.blinker= setInterval(function(){b.cursor.style.visibility=b.otherCursor.style.visibility=(c=!c)?"":"hidden"},a.options.cursorBlinkRate))}}function Ka(a,b){a.doc.mode.startState&&a.doc.frontier<a.display.showingTo&&a.state.highlight.set(b,O(ee,a))}function ee(a){var b=a.doc;b.frontier<b.first&&(b.frontier=b.first);if(!(b.frontier>=a.display.showingTo)){var c=+new Date+a.options.workTime,d=wa(b.mode,Ra(a,b.frontier)),e=[],f;b.iter(b.frontier,Math.min(b.first+b.size,a.display.showingTo+500),function(g){if(b.frontier>= a.display.showingFrom){var h=g.styles;g.styles=Xc(a,g,d);for(var k=!h||h.length!=g.styles.length,l=0;!k&&l<h.length;++l)k=h[l]!=g.styles[l];k&&(f&&f.end==b.frontier?f.end++:e.push(f={start:b.frontier,end:b.frontier+1}));g.stateAfter=wa(b.mode,d)}else Yc(a,g,d),g.stateAfter=0==b.frontier%5?wa(b.mode,d):null;++b.frontier;if(+new Date>c)return Ka(a,a.options.workDelay),!0});e.length&&t(a,function(){for(var a=0;a<e.length;++a)D(this,e[a].start,e[a].end)})()}}function fe(a,b,c){var d,e,f=a.doc,g=b;for(b-= a.doc.mode.innerMode?1E3:100;g>b;--g){if(g<=f.first)return f.first;var h=u(f,g-1);if(h.stateAfter&&(!c||g<=f.frontier))return g;h=xa(h.text,null,a.options.tabSize);if(null==e||d>h)e=g-1,d=h}return e}function Ra(a,b,c){var d=a.doc,e=a.display;if(!d.mode.startState)return!0;var f=fe(a,b,c),g=f>d.first&&u(d,f-1).stateAfter,g=g?wa(d.mode,g):Zc(d.mode);d.iter(f,b,function(c){Yc(a,c,g);c.stateAfter=f==b-1||0==f%5||f>=e.showingFrom&&f<e.showingTo?wa(d.mode,g):null;++f});return g}function gc(a,b,c,d,e){var f= -1;d=d||hc(a,b);for(a=c;;a+=f){var g=d[a];if(g)break;0>f&&0==a&&(f=1)}e=a>c?"left":a<c?"right":e;"left"==e&&g.leftSide?g=g.leftSide:"right"==e&&g.rightSide&&(g=g.rightSide);return{left:a<c?g.right:g.left,right:a>c?g.left:g.right,top:g.top,bottom:g.bottom}}function ic(a,b){for(var c=a.display.measureLineCache,d=0;d<c.length;++d){var e=c[d];if(e.text==b.text&&e.markedSpans==b.markedSpans&&a.display.scroller.clientWidth==e.width&&e.classes==b.textClass+"|"+b.bgClass+"|"+b.wrapClass)return e}}function ge(a, b){var c=ic(a,b);c&&(c.text=c.measure=c.markedSpans=null)}function hc(a,b){var c=ic(a,b);if(c)return c.measure;var c=he(a,b),d=a.display.measureLineCache,e={text:b.text,width:a.display.scroller.clientWidth,markedSpans:b.markedSpans,measure:c,classes:b.textClass+"|"+b.bgClass+"|"+b.wrapClass};16==d.length?d[++a.display.measureLineCachePos%16]=e:d.push(e);return c}function he(a,b){function c(a){var b=a.top-pb.top,c=a.bottom-pb.top;c>r&&(c=r);0>b&&(b=0);for(var d=m.length-2;0<=d;d-=2){var e=m[d],f=m[d+ 1];if(!(e>c||f<b)&&(e<=b&&f>=c||b<=e&&c>=f||Math.min(c,f)-Math.max(b,e)>=c-b>>1)){m[d]=Math.min(b,e);m[d+1]=Math.max(c,f);break}}0>d&&(d=m.length,m.push(b,c));return{left:a.left-pb.left,right:a.right-pb.left,top:d,bottom:null}}function d(a){a.bottom=m[a.top+1];a.top=m[a.top]}var e=a.display,f=$c(b.text.length),g=fc(a,b,f,!0);if(B&&!ra&&!a.options.lineWrapping&&100<g.childNodes.length){for(var h=document.createDocumentFragment(),k=g.childNodes.length,l=0,n=Math.ceil(k/10);l<n;++l){for(var E=p("div", null,null,"display: inline-block"),q=0;10>q&&k;++q)E.appendChild(g.firstChild),--k;h.appendChild(E)}g.appendChild(h)}W(e.measure,g);var pb=y(e.lineDiv),m=[],h=$c(b.text.length),r=g.offsetHeight;Q&&e.measure.first!=g&&W(e.measure,g);for(l=0;l<f.length;++l)if(e=f[l])g=e,k=null,/\bCodeMirror-widget\b/.test(e.className)&&e.getClientRects&&(1==e.firstChild.nodeType&&(g=e.firstChild),n=g.getClientRects(),1<n.length&&(k=h[l]=c(n[0]),k.rightSide=c(n[n.length-1]))),k||(k=h[l]=c(y(g))),e.measureRight&&(k.right= y(e.measureRight).left),e.leftSide&&(k.leftSide=c(y(e.leftSide)));Ma(a.display.measure);for(l=0;l<h.length;++l)if(e=h[l])d(e),e.leftSide&&d(e.leftSide),e.rightSide&&d(e.rightSide);return h}function ta(a){a.display.measureLineCache.length=a.display.measureLineCachePos=0;a.display.cachedCharWidth=a.display.cachedTextHeight=null;a.options.lineWrapping||(a.display.maxLineChanged=!0);a.display.lineNumChars=null}function jc(a,b,c,d){if(b.widgets)for(var e=0;e<b.widgets.length;++e)if(b.widgets[e].above){var f= tb(b.widgets[e]);c.top+=f;c.bottom+=f}if("line"==d)return c;d||(d="local");b=Qa(a,b);b="local"==d?b+a.display.lineSpace.offsetTop:b-a.display.viewOffset;if("page"==d||"window"==d)a=y(a.display.lineSpace),b+=a.top+("window"==d?0:window.pageYOffset||(document.documentElement||document.body).scrollTop),d=a.left+("window"==d?0:window.pageXOffset||(document.documentElement||document.body).scrollLeft),c.left+=d,c.right+=d;c.top+=b;c.bottom+=b;return c}function ad(a,b,c){if("div"==c)return b;var d=b.left; b=b.top;"page"==c?(d-=window.pageXOffset||(document.documentElement||document.body).scrollLeft,b-=window.pageYOffset||(document.documentElement||document.body).scrollTop):"local"!=c&&c||(c=y(a.display.sizer),d+=c.left,b+=c.top);a=y(a.display.lineSpace);return{left:d-a.left,top:b-a.top}}function rb(a,b,c,d,e){d||(d=u(a.doc,b.line));return jc(a,d,gc(a,d,b.ch,null,e),c)}function U(a,b,c,d,e){function f(b,f){var g=gc(a,d,b,e,f?"right":"left");f?g.left=g.right:g.right=g.left;return jc(a,d,g,c)}function g(a, b){var c=h[b],d=c.level%2;a==kc(c)&&b&&c.level<h[b-1].level?(c=h[--b],a=lc(c)-(c.level%2?0:1),d=!0):a==lc(c)&&b<h.length-1&&c.level<h[b+1].level&&(c=h[++b],a=kc(c)-c.level%2,d=!1);return d&&a==c.to&&a>c.from?f(a-1):f(a,d)}d=d||u(a.doc,b.line);e||(e=hc(a,d));var h=V(d);b=b.ch;if(!h)return f(b);var k=mc(h,b),k=g(b,k);null!=ya&&(k.other=g(b,ya));return k}function ub(a,b,c,d){a=new r(a,b);a.xRel=d;c&&(a.outside=!0);return a}function nc(a,b,c){var d=a.doc;c+=a.display.viewOffset;if(0>c)return ub(d.first, 0,!0,-1);var e=Oa(d,c),f=d.first+d.size-1;if(e>f)return ub(d.first+d.size-1,u(d,f).text.length,!0,1);for(0>b&&(b=0);;){var f=u(d,e),e=ie(a,f,e,b,c),g=(f=nb(f))&&f.find();if(f&&(e.ch>g.from.ch||e.ch==g.from.ch&&0<e.xRel))e=g.to.line;else return e}}function ie(a,b,c,d,e){function f(d){d=U(a,r(c,d),"line",b,l);h=!0;if(g>d.bottom)return d.left-k;if(g<d.top)return d.left+k;h=!1;return d.left}var g=e-Qa(a,b),h=!1,k=2*a.display.wrapper.clientWidth,l=hc(a,b),n=V(b),E=b.text.length;e=vb(b);var q=wb(b),m=f(e), p=h,s=f(q),u=h;if(d>s)return ub(c,q,u,1);for(;;){if(n?q==e||q==oc(b,e,1):1>=q-e){n=d<m||d-m<=s-d?e:q;for(d-=n==e?m:s;pc.test(b.text.charAt(n));)++n;return ub(c,n,n==e?p:u,0>d?-1:d?1:0)}var C=Math.ceil(E/2),t=e+C;if(n)for(var t=e,v=0;v<C;++v)t=oc(b,t,1);v=f(t);if(v>d){q=t;s=v;if(u=h)s+=1E3;E=C}else e=t,m=v,p=h,E-=C}}function sa(a){if(null!=a.cachedTextHeight)return a.cachedTextHeight;if(null==ja){ja=p("pre");for(var b=0;49>b;++b)ja.appendChild(document.createTextNode("x")),ja.appendChild(p("br")); ja.appendChild(document.createTextNode("x"))}W(a.measure,ja);b=ja.offsetHeight/50;3<b&&(a.cachedTextHeight=b);Ma(a.measure);return b||1}function Sc(a){if(null!=a.cachedCharWidth)return a.cachedCharWidth;var b=p("span","x"),c=p("pre",[b]);W(a.measure,c);b=b.offsetWidth;2<b&&(a.cachedCharWidth=b);return b||10}function za(a){a.curOp={changes:[],forceUpdate:!1,updateInput:null,userSelChange:null,textChanged:null,selectionChanged:!1,cursorActivity:!1,updateMaxLine:!1,updateScrollPos:!1,id:++je};xb++|| (da=[])}function Aa(a){var b=a.curOp,c=a.doc,d=a.display;a.curOp=null;b.updateMaxLine&&Zb(a);if(d.maxLineChanged&&!a.options.lineWrapping&&d.maxLine){var e;e=d.maxLine;var f=!1;if(e.markedSpans)for(var g=0;g<e.markedSpans;++g){var h=e.markedSpans[g];!h.collapsed||null!=h.to&&h.to!=e.text.length||(f=!0)}(f=!f&&ic(a,e))?e=gc(a,e,e.text.length,f.measure,"right").right:(e=fc(a,e,null,!0),f=e.appendChild(Sa(a.display.measure)),W(a.display.measure,e),e=y(f).right-y(a.display.lineDiv).left);d.sizer.style.minWidth= Math.max(0,e+3+qa)+"px";d.maxLineChanged=!1;e=Math.max(0,d.sizer.offsetLeft+d.sizer.offsetWidth-d.scroller.clientWidth);e<c.scrollLeft&&!b.updateScrollPos&&Ba(a,Math.min(d.scroller.scrollLeft,e),!0)}var k,l;b.updateScrollPos?k=b.updateScrollPos:b.selectionChanged&&d.scroller.clientHeight&&(k=U(a,c.sel.head),k=yb(a,k.left,k.top,k.left,k.bottom));if(b.changes.length||b.forceUpdate||k&&null!=k.scrollTop)l=ob(a,b.changes,k&&k.scrollTop,b.forceUpdate),a.display.scroller.offsetHeight&&(a.doc.scrollTop= a.display.scroller.scrollTop);!l&&b.selectionChanged&&dc(a);if(b.updateScrollPos)d.scroller.scrollTop=d.scrollbarV.scrollTop=c.scrollTop=k.scrollTop,d.scroller.scrollLeft=d.scrollbarH.scrollLeft=c.scrollLeft=k.scrollLeft,Yb(a),b.scrollToPos&&bd(a,s(a.doc,b.scrollToPos),b.scrollToPosMargin);else if(k&&(c=bd(a,a.doc.sel.head,a.options.cursorScrollMargin),a.state.focused&&(d=a.display,k=y(d.sizer),l=null,0>c.top+k.top?l=!0:c.bottom+k.top>(window.innerHeight||document.documentElement.clientHeight)&&(l= !1),null!=l&&!ke))){if(k="none"==d.cursor.style.display)d.cursor.style.display="",d.cursor.style.left=c.left+"px",d.cursor.style.top=c.top-d.viewOffset+"px";d.cursor.scrollIntoView(l);k&&(d.cursor.style.display="none")}b.selectionChanged&&sb(a);a.state.focused&&b.updateInput&&Y(a,b.userSelChange);c=b.maybeHiddenMarkers;d=b.maybeUnhiddenMarkers;if(c)for(l=0;l<c.length;++l)c[l].lines.length||J(c[l],"hide");if(d)for(l=0;l<d.length;++l)d[l].lines.length&&J(d[l],"unhide");var n;--xb||(n=da,da=null);b.textChanged&& J(a,"change",a,b.textChanged);b.cursorActivity&&J(a,"cursorActivity",a);if(n)for(l=0;l<n.length;++l)n[l]()}function t(a,b){return function(){var c=a||this,d=!c.curOp;d&&za(c);try{var e=b.apply(c,arguments)}finally{d&&Aa(c)}return e}}function Ta(a){return function(){var b=this.cm&&!this.cm.curOp,c;b&&za(this.cm);try{c=a.apply(this,arguments)}finally{b&&Aa(this.cm)}return c}}function qc(a,b){var c=!a.curOp,d;c&&za(a);try{d=b()}finally{c&&Aa(a)}return d}function D(a,b,c,d){null==b&&(b=a.doc.first);null== c&&(c=a.doc.first+a.doc.size);a.curOp.changes.push({from:b,to:c,diff:d})}function zb(a){a.display.pollingFast||a.display.poll.set(a.options.pollInterval,function(){rc(a);a.state.focused&&zb(a)})}function Ua(a){function b(){rc(a)||c?(a.display.pollingFast=!1,zb(a)):(c=!0,a.display.poll.set(60,b))}var c=!1;a.display.pollingFast=!0;a.display.poll.set(20,b)}function rc(a){var b=a.display.input,c=a.display.prevInput,d=a.doc,e=d.sel;if(!a.state.focused||le(b)||Va(a)||a.state.disableInput)return!1;a.state.pasteIncoming&& a.state.fakedLastChar&&(b.value=b.value.substring(0,b.value.length-1),a.state.fakedLastChar=!1);var f=b.value;if(f==c&&x(e.from,e.to))return!1;if(B&&!Q&&a.display.inputHasSelection===f)return Y(a,!0),!1;var g=!a.curOp;g&&za(a);e.shift=!1;for(var h=0,k=Math.min(c.length,f.length);h<k&&c.charCodeAt(h)==f.charCodeAt(h);)++h;k=e.from;e=e.to;h<c.length?k=r(k.line,k.ch-(c.length-h)):a.state.overwrite&&x(k,e)&&!a.state.pasteIncoming&&(e=r(e.line,Math.min(u(d,e.line).text.length,e.ch+(f.length-h))));c=a.curOp.updateInput; h={from:k,to:e,text:ka(f.slice(h)),origin:a.state.pasteIncoming?"paste":"+input"};Ca(a.doc,h,"end");a.curOp.updateInput=c;M(a,"inputRead",a,h);1E3<f.length||-1<f.indexOf("\n")?b.value=a.display.prevInput="":a.display.prevInput=f;g&&Aa(a);a.state.pasteIncoming=!1;return!0}function Y(a,b){var c,d,e=a.doc;x(e.sel.from,e.sel.to)?b&&(a.display.prevInput=a.display.input.value="",B&&!Q&&(a.display.inputHasSelection=null)):(a.display.prevInput="",d=(c=cd&&(100<e.sel.to.line-e.sel.from.line||1E3<(d=a.getSelection()).length))? "-":d||a.getSelection(),a.display.input.value=d,a.state.focused&&dd(a.display.input),B&&!Q&&(a.display.inputHasSelection=d));a.display.inaccurateSelection=c}function N(a){"nocursor"==a.options.readOnly||Tb&&document.activeElement==a.display.input||a.display.input.focus()}function Va(a){return a.options.readOnly||a.doc.cantEdit}function Ud(a){function b(){a.state.focused&&setTimeout(O(N,a),0)}function c(){null==h&&(h=setTimeout(function(){h=null;g.cachedCharWidth=g.cachedTextHeight=Wa=null;ta(a);qc(a, O(D,a))},100))}function d(){for(var a=g.wrapper.parentNode;a&&a!=document.body;a=a.parentNode);a?setTimeout(d,5E3):aa(window,"resize",c)}function e(b){X(a,b)||a.options.onDragEvent&&a.options.onDragEvent(a,Xa(b))||Ya(b)}function f(){g.inaccurateSelection&&(g.prevInput="",g.inaccurateSelection=!1,g.input.value=a.getSelection(),dd(g.input))}var g=a.display;v(g.scroller,"mousedown",t(a,me));B?v(g.scroller,"dblclick",t(a,function(b){if(!X(a,b)){var c=Za(a,b);!c||ed(a,b)||la(a.display,b)||(A(b),b=sc(u(a.doc, c.line).text,c),F(a.doc,b.from,b.to))}})):v(g.scroller,"dblclick",function(b){X(a,b)||A(b)});v(g.lineSpace,"selectstart",function(a){la(g,a)||A(a)});tc||v(g.scroller,"contextmenu",function(b){fd(a,b)});v(g.scroller,"scroll",function(){g.scroller.clientHeight&&($a(a,g.scroller.scrollTop),Ba(a,g.scroller.scrollLeft,!0),J(a,"scroll",a))});v(g.scrollbarV,"scroll",function(){g.scroller.clientHeight&&$a(a,g.scrollbarV.scrollTop)});v(g.scrollbarH,"scroll",function(){g.scroller.clientHeight&&Ba(a,g.scrollbarH.scrollLeft)}); v(g.scroller,"mousewheel",function(b){gd(a,b)});v(g.scroller,"DOMMouseScroll",function(b){gd(a,b)});v(g.scrollbarH,"mousedown",b);v(g.scrollbarV,"mousedown",b);v(g.wrapper,"scroll",function(){g.wrapper.scrollTop=g.wrapper.scrollLeft=0});var h;v(window,"resize",c);setTimeout(d,5E3);v(g.input,"keyup",t(a,function(b){X(a,b)||a.options.onKeyEvent&&a.options.onKeyEvent(a,Xa(b))||16!=b.keyCode||(a.doc.sel.shift=!1)}));v(g.input,"input",O(Ua,a));v(g.input,"keydown",t(a,hd));v(g.input,"keypress",t(a,ne)); v(g.input,"focus",O(ha,a));v(g.input,"blur",O(Vb,a));a.options.dragDrop&&(v(g.scroller,"dragstart",function(b){var c=a;if(B&&(!c.state.draggingText||100>+new Date-id))Ya(b);else if(!X(c,b)&&!la(c.display,b)){var d=c.getSelection();b.dataTransfer.setData("Text",d);b.dataTransfer.setDragImage&&!uc&&(d=p("img",null,null,"position: fixed; left: 0; top: 0;"),S&&(d.width=d.height=1,c.display.wrapper.appendChild(d),d._top=d.offsetTop),b.dataTransfer.setDragImage(d,0,0),S&&d.parentNode.removeChild(d))}}), v(g.scroller,"dragenter",e),v(g.scroller,"dragover",e),v(g.scroller,"drop",t(a,oe)));v(g.scroller,"paste",function(b){la(g,b)||(N(a),Ua(a))});v(g.input,"paste",function(){if(K&&!(a.state.fakedLastChar||200>new Date-a.state.lastMiddleDown)){var b=g.input.selectionStart,c=g.input.selectionEnd;g.input.value+="$";g.input.selectionStart=b;g.input.selectionEnd=c;a.state.fakedLastChar=!0}a.state.pasteIncoming=!0;Ua(a)});v(g.input,"cut",f);v(g.input,"copy",f);Xb&&v(g.sizer,"mouseup",function(){document.activeElement== g.input&&g.input.blur();N(a)})}function la(a,b){for(var c=b.target||b.srcElement;c!=a.wrapper;c=c.parentNode)if(!c||c.ignoreEvents||c.parentNode==a.sizer&&c!=a.mover)return!0}function Za(a,b,c){var d=a.display;if(!c&&(c=b.target||b.srcElement,c==d.scrollbarH||c==d.scrollbarH.firstChild||c==d.scrollbarV||c==d.scrollbarV.firstChild||c==d.scrollbarFiller||c==d.gutterFiller))return null;var e,f,d=y(d.lineSpace);try{e=b.clientX,f=b.clientY}catch(g){return null}return nc(a,e-d.left,f-d.top)}function me(a){function b(a){if(!x(p, a))if(p=a,"single"==n)F(e.doc,s(g,k),a);else if(q=s(g,q),m=s(g,m),"double"==n){var b=sc(u(g,a.line).text,a);z(a,q)?F(e.doc,b.from,m):F(e.doc,q,b.to)}else"triple"==n&&(z(a,q)?F(e.doc,m,s(g,r(a.line,0))):F(e.doc,q,s(g,r(a.line+1,0))))}function c(a){var d=++qb,h=Za(e,a,!0);if(h)if(x(h,E)){var k=a.clientY<w.top?-20:a.clientY>w.bottom?20:0;k&&setTimeout(t(e,function(){qb==d&&(f.scroller.scrollTop+=k,c(a))}),50)}else{e.state.focused||ha(e);E=h;b(h);var l=ac(f,g);(h.line>=l.to||h.line<l.from)&&setTimeout(t(e, function(){qb==d&&c(a)}),150)}}function d(a){qb=Infinity;A(a);N(e);aa(document,"mousemove",C);aa(document,"mouseup",D)}if(!X(this,a)){var e=this,f=e.display,g=e.doc,h=g.sel;h.shift=a.shiftKey;if(la(f,a))K||(f.scroller.draggable=!1,setTimeout(function(){f.scroller.draggable=!0},100));else if(!ed(e,a)){var k=Za(e,a);switch(jd(a)){case 3:tc&&fd.call(e,e,a);return;case 2:K&&(e.state.lastMiddleDown=+new Date);k&&F(e.doc,k);setTimeout(O(N,e),20);A(a);return}if(k){e.state.focused||ha(e);var l=+new Date, n="single";Ab&&Ab.time>l-400&&x(Ab.pos,k)?(n="triple",A(a),setTimeout(O(N,e),20),pe(e,k.line)):Bb&&Bb.time>l-400&&x(Bb.pos,k)?(n="double",Ab={time:l,pos:k},A(a),l=sc(u(g,k.line).text,k),F(e.doc,l.from,l.to)):Bb={time:l,pos:k};var E=k;if(!e.options.dragDrop||!qe||Va(e)||x(h.from,h.to)||z(k,h.from)||z(h.to,k)||"single"!=n){A(a);"single"==n&&F(e.doc,s(g,k));var q=h.from,m=h.to,p=k,w=y(f.wrapper),qb=0,C=t(e,function(a){B||jd(a)?c(a):d(a)}),D=t(e,d);v(document,"mousemove",C);v(document,"mouseup",D)}else{var J= t(e,function(b){K&&(f.scroller.draggable=!1);e.state.draggingText=!1;aa(document,"mouseup",J);aa(f.scroller,"drop",J);10>Math.abs(a.clientX-b.clientX)+Math.abs(a.clientY-b.clientY)&&(A(b),F(e.doc,k),N(e))});K&&(f.scroller.draggable=!0);e.state.draggingText=J;f.scroller.dragDrop&&f.scroller.dragDrop();v(document,"mouseup",J);v(f.scroller,"drop",J)}}else(a.target||a.srcElement)==f.scroller&&A(a)}}}function ed(a,b){var c=a.display;try{var d=b.clientX,e=b.clientY}catch(f){return!1}if(d>=Math.floor(y(c.gutters).right))return!1; A(b);if(!ba(a,"gutterClick"))return!0;var g=y(c.lineDiv);if(e>g.bottom)return!0;e-=g.top-c.viewOffset;for(g=0;g<a.options.gutters.length;++g){var h=c.gutters.childNodes[g];if(h&&y(h).right>=d){c=Oa(a.doc,e);M(a,"gutterClick",a,c,a.options.gutters[g],b);break}}return!0}function oe(a){var b=this;if(!(X(b,a)||la(b.display,a)||b.options.onDragEvent&&b.options.onDragEvent(b,Xa(a)))){A(a);B&&(id=+new Date);var c=Za(b,a,!0),d=a.dataTransfer.files;if(c&&!Va(b))if(d&&d.length&&window.FileReader&&window.File){var e= d.length,f=Array(e),g=0;a=function(a,d){var h=new FileReader;h.onload=function(){f[d]=h.result;++g==e&&(c=s(b.doc,c),Ca(b.doc,{from:c,to:c,text:ka(f.join("\n")),origin:"paste"},"around"))};h.readAsText(a)};for(var h=0;h<e;++h)a(d[h],h)}else if(!b.state.draggingText||z(c,b.doc.sel.from)||z(b.doc.sel.to,c))try{if(f=a.dataTransfer.getData("Text")){var h=b.doc.sel.from,k=b.doc.sel.to;ea(b.doc,c,c);b.state.draggingText&&fa(b.doc,"",h,k,"paste");b.replaceSelection(f,null,"paste");N(b);ha(b)}}catch(l){}else b.state.draggingText(a), setTimeout(O(N,b),20)}}function $a(a,b){2>Math.abs(a.doc.scrollTop-b)||(a.doc.scrollTop=b,Da||ob(a,[],b),a.display.scroller.scrollTop!=b&&(a.display.scroller.scrollTop=b),a.display.scrollbarV.scrollTop!=b&&(a.display.scrollbarV.scrollTop=b),Da&&ob(a,[]),Ka(a,100))}function Ba(a,b,c){(c?b==a.doc.scrollLeft:2>Math.abs(a.doc.scrollLeft-b))||(b=Math.min(b,a.display.scroller.scrollWidth-a.display.scroller.clientWidth),a.doc.scrollLeft=b,Yb(a),a.display.scroller.scrollLeft!=b&&(a.display.scroller.scrollLeft= b),a.display.scrollbarH.scrollLeft!=b&&(a.display.scrollbarH.scrollLeft=b))}function gd(a,b){var c=b.wheelDeltaX,d=b.wheelDeltaY;null==c&&b.detail&&b.axis==b.HORIZONTAL_AXIS&&(c=b.detail);null==d&&b.detail&&b.axis==b.VERTICAL_AXIS?d=b.detail:null==d&&(d=b.wheelDelta);var e=a.display,f=e.scroller;if(c&&f.scrollWidth>f.clientWidth||d&&f.scrollHeight>f.clientHeight){if(d&&va&&K)for(var g=b.target;g!=f;g=g.parentNode)if(g.lineObj){a.display.currentWheelTarget=g;break}if(!c||Da||S||null==T){if(d&&null!= T){var g=d*T,h=a.doc.scrollTop,k=h+e.wrapper.clientHeight;0>g?h=Math.max(0,h+g-50):k=Math.min(a.doc.height,k+g+50);ob(a,[],{top:h,bottom:k})}20>Cb&&(null==e.wheelStartX?(e.wheelStartX=f.scrollLeft,e.wheelStartY=f.scrollTop,e.wheelDX=c,e.wheelDY=d,setTimeout(function(){if(null!=e.wheelStartX){var a=f.scrollLeft-e.wheelStartX,b=f.scrollTop-e.wheelStartY,a=b&&e.wheelDY&&b/e.wheelDY||a&&e.wheelDX&&a/e.wheelDX;e.wheelStartX=e.wheelStartY=null;a&&(T=(T*Cb+a)/(Cb+1),++Cb)}},200)):(e.wheelDX+=c,e.wheelDY+= d))}else d&&$a(a,Math.max(0,Math.min(f.scrollTop+d*T,f.scrollHeight-f.clientHeight))),Ba(a,Math.max(0,Math.min(f.scrollLeft+c*T,f.scrollWidth-f.clientWidth))),A(b),e.wheelStartX=null}}function Db(a,b,c){if("string"==typeof b&&(b=vc[b],!b))return!1;a.display.pollingFast&&rc(a)&&(a.display.pollingFast=!1);var d=a.doc,e=d.sel.shift,f=!1;try{Va(a)&&(a.state.suppressEdits=!0),c&&(d.sel.shift=!1),f=b(a)!=kd}finally{d.sel.shift=e,a.state.suppressEdits=!1}return f}function ld(a){var b=a.state.keyMaps.slice(0); a.options.extraKeys&&b.push(a.options.extraKeys);b.push(a.options.keyMap);return b}function md(a,b){var c=wc(a.options.keyMap),d=c.auto;clearTimeout(nd);d&&!od(b)&&(nd=setTimeout(function(){wc(a.options.keyMap)==c&&(a.options.keyMap=d.call?d.call(null,a):d,Uc(a))},50));var e=pd(b,!0),f=!1;if(!e)return!1;f=ld(a);if(f=b.shiftKey?ab("Shift-"+e,f,function(b){return Db(a,b,!0)})||ab(e,f,function(b){if("string"==typeof b?/^go[A-Z]/.test(b):b.motion)return Db(a,b)}):ab(e,f,function(b){return Db(a,b)}))A(b), sb(a),Q&&(b.oldKeyCode=b.keyCode,b.keyCode=0),M(a,"keyHandled",a,e,b);return f}function re(a,b,c){var d=ab("'"+c+"'",ld(a),function(b){return Db(a,b,!0)});d&&(A(b),sb(a),M(a,"keyHandled",a,"'"+c+"'",b));return d}function hd(a){this.state.focused||ha(this);if(!(X(this,a)||this.options.onKeyEvent&&this.options.onKeyEvent(this,Xa(a)))){B&&27==a.keyCode&&(a.returnValue=!1);var b=a.keyCode;this.doc.sel.shift=16==b||a.shiftKey;var c=md(this,a);S&&(xc=c?b:null,!c&&88==b&&!cd&&(va?a.metaKey:a.ctrlKey)&&this.replaceSelection(""))}} function ne(a){var b=this;if(!(X(b,a)||b.options.onKeyEvent&&b.options.onKeyEvent(b,Xa(a)))){var c=a.keyCode,d=a.charCode;S&&c==xc?(xc=null,A(a)):(S&&(!a.which||10>a.which)||Xb)&&md(b,a)||(c=String.fromCharCode(null==d?c:d),this.options.electricChars&&this.doc.mode.electricChars&&this.options.smartIndent&&!Va(this)&&-1<this.doc.mode.electricChars.indexOf(c)&&setTimeout(t(b,function(){Eb(b,b.doc.sel.to.line,"smart")}),75),re(b,a,c)||(B&&!Q&&(b.display.inputHasSelection=null),Ua(b)))}}function ha(a){"nocursor"!= a.options.readOnly&&(a.state.focused||(J(a,"focus",a),a.state.focused=!0,-1==a.display.wrapper.className.search(/\bCodeMirror-focused\b/)&&(a.display.wrapper.className+=" CodeMirror-focused"),a.curOp||(Y(a,!0),K&&setTimeout(O(Y,a,!0),0))),zb(a),sb(a))}function Vb(a){a.state.focused&&(J(a,"blur",a),a.state.focused=!1,a.display.wrapper.className=a.display.wrapper.className.replace(" CodeMirror-focused",""));clearInterval(a.display.blinker);setTimeout(function(){a.state.focused||(a.doc.sel.shift=!1)}, 150)}function fd(a,b){function c(){if(null!=e.input.selectionStart){var a=e.input.value=" "+(x(f.from,f.to)?"":e.input.value);e.prevInput=" ";e.input.selectionStart=1;e.input.selectionEnd=a.length}}function d(){e.inputDiv.style.position="relative";e.input.style.cssText=k;Q&&(e.scrollbarV.scrollTop=e.scroller.scrollTop=h);zb(a);if(null!=e.input.selectionStart){B&&!Q||c();clearTimeout(yc);var b=0,d=function(){" "==e.prevInput&&0==e.input.selectionStart?t(a,vc.selectAll)(a):10>b++?yc=setTimeout(d,500): Y(a)};yc=setTimeout(d,200)}}if(!X(a,b,"contextmenu")){var e=a.display,f=a.doc.sel;if(!la(e,b)){var g=Za(a,b),h=e.scroller.scrollTop;if(g&&!S){(x(f.from,f.to)||z(g,f.from)||!z(g,f.to))&&t(a,ea)(a.doc,g,g);var k=e.input.style.cssText;e.inputDiv.style.position="absolute";e.input.style.cssText="position: fixed; width: 30px; height: 30px; top: "+(b.clientY-5)+"px; left: "+(b.clientX-5)+"px; z-index: 1000; background: white; outline: none;border-width: 0; outline: none; overflow: hidden; opacity: .05; -ms-opacity: .05; filter: alpha(opacity=5);"; N(a);Y(a,!0);x(f.from,f.to)&&(e.input.value=e.prevInput=" ");B&&!Q&&c();if(tc){Ya(b);var l=function(){aa(window,"mouseup",l);setTimeout(d,20)};v(window,"mouseup",l)}else setTimeout(d,50)}}}}function qd(a,b,c){if(!z(b.from,c))return s(a,c);var d=b.text.length-1-(b.to.line-b.from.line);if(c.line>b.to.line+d)return b=c.line-d,d=a.first+a.size-1,b>d?r(d,u(a,d).text.length):Fb(c,u(a,b).text.length);if(c.line==b.to.line+d)return Fb(c,L(b.text).length+(1==b.text.length?b.from.ch:0)+u(a,b.to.line).text.length- b.to.ch);a=c.line-b.from.line;return Fb(c,b.text[a].length+(a?0:b.from.ch))}function zc(a,b,c){if(c&&"object"==typeof c)return{anchor:qd(a,b,c.anchor),head:qd(a,b,c.head)};if("start"==c)return{anchor:b.from,head:b.from};var d=Ac(b);if("around"==c)return{anchor:b.from,head:d};if("end"==c)return{anchor:d,head:d};c=function(a){if(z(a,b.from))return a;if(!z(b.to,a))return d;var c=a.line+b.text.length-(b.to.line-b.from.line)-1,g=a.ch;a.line==b.to.line&&(g+=d.ch-b.to.ch);return r(c,g)};return{anchor:c(a.sel.anchor), head:c(a.sel.head)}}function rd(a,b,c){b={canceled:!1,from:b.from,to:b.to,text:b.text,origin:b.origin,cancel:function(){this.canceled=!0}};c&&(b.update=function(b,c,f,g){b&&(this.from=s(a,b));c&&(this.to=s(a,c));f&&(this.text=f);void 0!==g&&(this.origin=g)});J(a,"beforeChange",a,b);a.cm&&J(a.cm,"beforeChange",a.cm,b);return b.canceled?null:{from:b.from,to:b.to,text:b.text,origin:b.origin}}function Ca(a,b,c,d){if(a.cm){if(!a.cm.curOp)return t(a.cm,Ca)(a,b,c,d);if(a.cm.state.suppressEdits)return}if(ba(a, "beforeChange")||a.cm&&ba(a.cm,"beforeChange"))if(b=rd(a,b,!0),!b)return;if(d=sd&&!d&&se(a,b.from,b.to)){for(var e=d.length-1;1<=e;--e)Bc(a,{from:d[e].from,to:d[e].to,text:[""]});d.length&&Bc(a,{from:d[0].from,to:d[0].to,text:b.text},c)}else Bc(a,b,c)}function Bc(a,b,c){c=zc(a,b,c);td(a,b,c,a.cm?a.cm.curOp.id:NaN);bb(a,b,c,Cc(a,b));var d=[];Ea(a,function(a,c){c||-1!=ca(d,a.history)||(ud(a.history,b),d.push(a.history));bb(a,b,null,Cc(a,b))})}function vd(a,b){if(!a.cm||!a.cm.state.suppressEdits){var c= a.history,d=("undo"==b?c.done:c.undone).pop();if(d){var e={changes:[],anchorBefore:d.anchorAfter,headBefore:d.headAfter,anchorAfter:d.anchorBefore,headAfter:d.headBefore,generation:c.generation};("undo"==b?c.undone:c.done).push(e);c.generation=d.generation||++c.maxGeneration;for(var f=ba(a,"beforeChange")||a.cm&&ba(a.cm,"beforeChange"),g=d.changes.length-1;0<=g;--g){var h=d.changes[g];h.origin=b;if(f&&!rd(a,h,!1)){("undo"==b?c.done:c.undone).length=0;break}e.changes.push(Dc(a,h));var k=g?zc(a,h,null): {anchor:d.anchorBefore,head:d.headBefore};bb(a,h,k,wd(a,h));var l=[];Ea(a,function(a,b){b||-1!=ca(l,a.history)||(ud(a.history,h),l.push(a.history));bb(a,h,null,wd(a,h))})}}}}function xd(a,b){function c(a){return r(a.line+b,a.ch)}a.first+=b;a.cm&&D(a.cm,a.first,a.first,b);a.sel.head=c(a.sel.head);a.sel.anchor=c(a.sel.anchor);a.sel.from=c(a.sel.from);a.sel.to=c(a.sel.to)}function bb(a,b,c,d){if(a.cm&&!a.cm.curOp)return t(a.cm,bb)(a,b,c,d);if(b.to.line<a.first)xd(a,b.text.length-1-(b.to.line-b.from.line)); else if(!(b.from.line>a.lastLine())){if(b.from.line<a.first){var e=b.text.length-1-(a.first-b.from.line);xd(a,e);b={from:r(a.first,0),to:r(b.to.line+e,b.to.ch),text:[L(b.text)],origin:b.origin}}e=a.lastLine();b.to.line>e&&(b={from:b.from,to:r(e,u(a,e).text.length),text:[b.text[0]],origin:b.origin});b.removed=Ec(a,b.from,b.to);c||(c=zc(a,b,null));a.cm?te(a.cm,b,d,c):Fc(a,b,d,c)}}function te(a,b,c,d){var e=a.doc,f=a.display,g=b.from,h=b.to,k=!1,l=g.line;a.options.lineWrapping||(l=P($(e,u(e,g.line))), e.iter(l,h.line+1,function(a){if(a==f.maxLine)return k=!0}));z(e.sel.head,b.from)||z(b.to,e.sel.head)||(a.curOp.cursorActivity=!0);Fc(e,b,c,d,Rc(a));a.options.lineWrapping||(e.iter(l,g.line+b.text.length,function(a){var b=mb(e,a);b>f.maxLineLength&&(f.maxLine=a,f.maxLineLength=b,f.maxLineChanged=!0,k=!1)}),k&&(a.curOp.updateMaxLine=!0));e.frontier=Math.min(e.frontier,g.line);Ka(a,400);D(a,g.line,h.line+1,b.text.length-(h.line-g.line)-1);if(ba(a,"change"))if(b={from:g,to:h,text:b.text,removed:b.removed, origin:b.origin},a.curOp.textChanged){for(a=a.curOp.textChanged;a.next;a=a.next);a.next=b}else a.curOp.textChanged=b}function fa(a,b,c,d,e){d||(d=c);if(z(d,c)){var f=d;d=c;c=f}"string"==typeof b&&(b=ka(b));Ca(a,{from:c,to:d,text:b,origin:e},null)}function r(a,b){if(!(this instanceof r))return new r(a,b);this.line=a;this.ch=b}function x(a,b){return a.line==b.line&&a.ch==b.ch}function z(a,b){return a.line<b.line||a.line==b.line&&a.ch<b.ch}function ma(a){return r(a.line,a.ch)}function s(a,b){if(b.line< a.first)return r(a.first,0);var c=a.first+a.size-1;return b.line>c?r(c,u(a,c).text.length):Fb(b,u(a,b.line).text.length)}function Fb(a,b){var c=a.ch;return null==c||c>b?r(a.line,b):0>c?r(a.line,0):a}function Fa(a,b){return b>=a.first&&b<a.first+a.size}function F(a,b,c,d){if(a.sel.shift||a.sel.extend){var e=a.sel.anchor;if(c){var f=z(b,e);f!=z(c,e)?(e=b,b=c):f!=z(b,c)&&(b=c)}ea(a,e,b,d)}else ea(a,b,c||b,d);a.cm&&(a.cm.curOp.userSelChange=!0)}function ea(a,b,c,d,e){if(!e&&ba(a,"beforeSelectionChange")|| a.cm&&ba(a.cm,"beforeSelectionChange"))b={anchor:b,head:c},J(a,"beforeSelectionChange",a,b),a.cm&&J(a.cm,"beforeSelectionChange",a.cm,b),b.anchor=s(a,b.anchor),b.head=s(a,b.head),c=b.head,b=b.anchor;var f=a.sel;f.goalColumn=null;if(e||!x(b,f.anchor))b=Gb(a,b,d,"push"!=e);if(e||!x(c,f.head))c=Gb(a,c,d,"push"!=e);x(f.anchor,b)&&x(f.head,c)||(f.anchor=b,f.head=c,d=z(c,b),f.from=d?c:b,f.to=d?b:c,a.cm&&(a.cm.curOp.updateInput=a.cm.curOp.selectionChanged=a.cm.curOp.cursorActivity=!0),M(a,"cursorActivity", a))}function yd(a){ea(a.doc,a.doc.sel.from,a.doc.sel.to,null,"push")}function Gb(a,b,c,d){var e=!1,f=b,g=c||1;a.cantEdit=!1;a:for(;;){var h=u(a,f.line);if(h.markedSpans)for(var k=0;k<h.markedSpans.length;++k){var l=h.markedSpans[k],n=l.marker;if((null==l.from||(n.inclusiveLeft?l.from<=f.ch:l.from<f.ch))&&(null==l.to||(n.inclusiveRight?l.to>=f.ch:l.to>f.ch))){if(d&&(J(n,"beforeCursorEnter"),n.explicitlyCleared))if(h.markedSpans){--k;continue}else break;if(n.atomic){k=n.find()[0>g?"from":"to"];if(x(k, f)&&(k.ch+=g,0>k.ch?k=k.line>a.first?s(a,r(k.line-1)):null:k.ch>h.text.length&&(k=k.line<a.first+a.size-1?r(k.line+1,0):null),!k)){if(e){if(!d)return Gb(a,b,c,!0);a.cantEdit=!0;return r(a.first,0)}e=!0;k=b;g=-g}f=k;continue a}}}return f}}function bd(a,b,c){for(null==c&&(c=0);;){var d=!1,e=U(a,b),f=yb(a,e.left,e.top-c,e.left,e.bottom+c),g=a.doc.scrollTop,h=a.doc.scrollLeft;null!=f.scrollTop&&($a(a,f.scrollTop),1<Math.abs(a.doc.scrollTop-g)&&(d=!0));null!=f.scrollLeft&&(Ba(a,f.scrollLeft),1<Math.abs(a.doc.scrollLeft- h)&&(d=!0));if(!d)return e}}function yb(a,b,c,d,e){var f=a.display,g=sa(a.display);0>c&&(c=0);var h=f.scroller.clientHeight-qa,k=f.scroller.scrollTop,l={};a=a.doc.height+(f.mover.offsetHeight-f.lineSpace.offsetHeight);var n=c<g,g=e>a-g;c<k?l.scrollTop=n?0:c:e>k+h&&(c=Math.min(c,(g?a:e)-h),c!=k&&(l.scrollTop=c));k=f.scroller.clientWidth-qa;c=f.scroller.scrollLeft;b+=f.gutters.offsetWidth;d+=f.gutters.offsetWidth;f=f.gutters.offsetWidth;e=b<f+10;b<c+f||e?(e&&(b=0),l.scrollLeft=Math.max(0,b-10-f)):d> k+c-3&&(l.scrollLeft=d+10-k);return l}function Hb(a,b,c){a.curOp.updateScrollPos={scrollLeft:null==b?a.doc.scrollLeft:b,scrollTop:null==c?a.doc.scrollTop:c}}function Gc(a,b,c){var d=a.curOp.updateScrollPos||(a.curOp.updateScrollPos={scrollLeft:a.doc.scrollLeft,scrollTop:a.doc.scrollTop});a=a.display.scroller;d.scrollTop=Math.max(0,Math.min(a.scrollHeight-a.clientHeight,d.scrollTop+c));d.scrollLeft=Math.max(0,Math.min(a.scrollWidth-a.clientWidth,d.scrollLeft+b))}function Eb(a,b,c,d){var e=a.doc;null== c&&(c="add");if("smart"==c)if(a.doc.mode.indent)var f=Ra(a,b);else c="prev";var g=a.options.tabSize,h=u(e,b),k=xa(h.text,null,g),l=h.text.match(/^\s*/)[0],n;if("smart"==c&&(n=a.doc.mode.indent(f,h.text.slice(l.length),h.text),n==kd)){if(!d)return;c="prev"}"prev"==c?n=b>e.first?xa(u(e,b-1).text,null,g):0:"add"==c?n=k+a.options.indentUnit:"subtract"==c?n=k-a.options.indentUnit:"number"==typeof c&&(n=k+c);n=Math.max(0,n);c="";d=0;if(a.options.indentWithTabs)for(e=Math.floor(n/g);e;--e)d+=g,c+="\t";d< n&&(c+=zd(n-d));c!=l&&fa(a.doc,c,r(b,0),r(b,l.length),"+input");h.stateAfter=null}function Ib(a,b,c){var d=b,e=b,f=a.doc;"number"==typeof b?e=u(f,Math.max(f.first,Math.min(b,f.first+f.size-1))):d=P(b);if(null!=d&&c(e,d))D(a,d,d+1);else return null;return e}function Hc(a,b,c,d,e){function f(b){var d=(e?oc:Ad)(k,h,c,!0);if(null==d){if(b=!b)b=g+c,b<a.first||b>=a.first+a.size?b=l=!1:(g=b,b=k=u(a,b));if(b)h=e?(0>c?wb:vb)(k):0>c?k.text.length:0;else return l=!1}else h=d;return!0}var g=b.line,h=b.ch;b=c; var k=u(a,g),l=!0;if("char"==d)f();else if("column"==d)f(!0);else if("word"==d||"group"==d){var n=null;d="group"==d;for(var E=!0;!(0>c)||f(!E);E=!1){var q=k.text.charAt(h)||"\n",q=cb(q)?"w":d?/\s/.test(q)?null:"p":null;if(n&&n!=q){0>c&&(c=1,f());break}q&&(n=q);if(0<c&&!f(!E))break}}b=Gb(a,r(g,h),b,!0);l||(b.hitSide=!0);return b}function Bd(a,b,c,d){var e=a.doc,f=b.left,g;"page"==d?(d=Math.min(a.display.wrapper.clientHeight,window.innerHeight||document.documentElement.clientHeight),g=b.top+c*(d-(0> c?1.5:0.5)*sa(a.display))):"line"==d&&(g=0<c?b.bottom+3:b.top-3);for(;;){var h=nc(a,f,g);if(!h.outside)break;if(0>c?0>=g:g>=e.height){h.hitSide=!0;break}g+=5*c}return h}function sc(a,b){var c=b.ch,d=b.ch;if(a){(0>b.xRel||d==a.length)&&c?--c:++d;for(var e=a.charAt(c),e=cb(e)?cb:/\s/.test(e)?function(a){return/\s/.test(a)}:function(a){return!/\s/.test(a)&&!cb(a)};0<c&&e(a.charAt(c-1));)--c;for(;d<a.length&&e(a.charAt(d));)++d}return{from:r(b.line,c),to:r(b.line,d)}}function pe(a,b){F(a.doc,r(b,0),s(a.doc, r(b+1,0)))}function w(a,b,c,d){m.defaults[a]=b;c&&(pa[a]=d?function(a,b,d){d!=Qc&&c(a,b,d)}:c)}function wa(a,b){if(!0===b)return b;if(a.copyState)return a.copyState(b);var c={},d;for(d in b){var e=b[d];e instanceof Array&&(e=e.concat([]));c[d]=e}return c}function Zc(a,b,c){return a.startState?a.startState(b,c):!0}function wc(a){return"string"==typeof a?Z[a]:a}function ab(a,b,c){function d(b){b=wc(b);var e=b[a];if(!1===e)return"stop";if(null!=e&&c(e))return!0;if(b.nofallthrough)return"stop";b=b.fallthrough; if(null==b)return!1;if("[object Array]"!=Object.prototype.toString.call(b))return d(b);for(var e=0,f=b.length;e<f;++e){var l=d(b[e]);if(l)return l}return!1}for(var e=0;e<b.length;++e){var f=d(b[e]);if(f)return"stop"!=f}}function od(a){a=na[a.keyCode];return"Ctrl"==a||"Alt"==a||"Shift"==a||"Mod"==a}function pd(a,b){if(S&&34==a.keyCode&&a["char"])return!1;var c=na[a.keyCode];if(null==c||a.altGraphKey)return!1;a.altKey&&(c="Alt-"+c);if(Cd?a.metaKey:a.ctrlKey)c="Ctrl-"+c;if(Cd?a.ctrlKey:a.metaKey)c="Cmd-"+ c;!b&&a.shiftKey&&(c="Shift-"+c);return c}function db(a,b){this.pos=this.start=0;this.string=a;this.tabSize=b||8;this.lastColumnPos=this.lastColumnValue=0}function ga(a,b){this.lines=[];this.type=b;this.doc=a}function eb(a,b,c,d,e){if(d&&d.shared)return ue(a,b,c,d,e);if(a.cm&&!a.cm.curOp)return t(a.cm,eb)(a,b,c,d,e);var f=new ga(a,e);if("range"==e&&!z(b,c))return f;d&&Jb(d,f);f.replacedWith&&(f.collapsed=!0,f.replacedWith=p("span",[f.replacedWith],"CodeMirror-widget"),d.handleMouseEvents||(f.replacedWith.ignoreEvents= !0));f.collapsed&&(Pa=!0);f.addToHistory&&td(a,{from:b,to:c,origin:"markText"},{head:a.sel.head,anchor:a.sel.anchor},NaN);var g=b.line,h=0,k,l,n=a.cm,E;a.iter(g,c.line+1,function(d){n&&f.collapsed&&!n.options.lineWrapping&&$(a,d)==n.display.maxLine&&(E=!0);var e={from:null,to:null,marker:f};h+=d.text.length;g==b.line&&(e.from=b.ch,h-=b.ch);g==c.line&&(e.to=c.ch,h-=d.text.length-c.ch);f.collapsed&&(g==c.line&&(l=ua(d,c.ch)),g==b.line?k=ua(d,b.ch):R(d,0));d.markedSpans=d.markedSpans?d.markedSpans.concat([e]): [e];e.marker.attachLine(d);++g});f.collapsed&&a.iter(b.line,c.line+1,function(b){ia(a,b)&&R(b,0)});f.clearOnEnter&&v(f,"beforeCursorEnter",function(){f.clear()});f.readOnly&&(sd=!0,(a.history.done.length||a.history.undone.length)&&a.clearHistory());if(f.collapsed){if(k!=l)throw Error("Inserting collapsed marker overlapping an existing one");f.size=h;f.atomic=!0}n&&(E&&(n.curOp.updateMaxLine=!0),(f.className||f.title||f.startStyle||f.endStyle||f.collapsed)&&D(n,b.line,c.line+1),f.atomic&&yd(n));return f} function fb(a,b){this.markers=a;this.primary=b;for(var c=0,d=this;c<a.length;++c)a[c].parent=this,v(a[c],"clear",function(){d.clear()})}function ue(a,b,c,d,e){d=Jb(d);d.shared=!1;var f=[eb(a,b,c,d,e)],g=f[0],h=d.replacedWith;Ea(a,function(a){h&&(d.replacedWith=h.cloneNode(!0));f.push(eb(a,s(a,b),s(a,c),d,e));for(var l=0;l<a.linked.length;++l)if(a.linked[l].isParent)return;g=L(f)});return new fb(f,g)}function gb(a,b){if(a)for(var c=0;c<a.length;++c){var d=a[c];if(d.marker==b)return d}}function Cc(a, b){var c=Fa(a,b.from.line)&&u(a,b.from.line).markedSpans,d=Fa(a,b.to.line)&&u(a,b.to.line).markedSpans;if(!c&&!d)return null;var e=b.from.ch,f=b.to.ch,g=x(b.from,b.to);if(c)for(var h=0,k;h<c.length;++h){var l=c[h],n=l.marker;if(null==l.from||(n.inclusiveLeft?l.from<=e:l.from<e)||"bookmark"==n.type&&!(l.from!=e||g&&l.marker.insertLeft)){var E=null==l.to||(n.inclusiveRight?l.to>=e:l.to>e);(k||(k=[])).push({from:l.from,to:E?null:l.to,marker:n})}}c=k;if(d)for(var h=0,m;h<d.length;++h)if(k=d[h],l=k.marker, null==k.to||(l.inclusiveRight?k.to>=f:k.to>f)||"bookmark"==l.type&&k.from==f&&(!g||k.marker.insertLeft))n=null==k.from||(l.inclusiveLeft?k.from<=f:k.from<f),(m||(m=[])).push({from:n?null:k.from-f,to:null==k.to?null:k.to-f,marker:l});d=m;g=1==b.text.length;m=L(b.text).length+(g?e:0);if(c)for(f=0;f<c.length;++f)if(h=c[f],null==h.to)(k=gb(d,h.marker),k)?g&&(h.to=null==k.to?null:k.to+m):h.to=e;if(d)for(f=0;f<d.length;++f)h=d[f],null!=h.to&&(h.to+=m),null==h.from?(k=gb(c,h.marker),k||(h.from=m,g&&(c|| (c=[])).push(h))):(h.from+=m,g&&(c||(c=[])).push(h));if(g&&c){for(f=0;f<c.length;++f)null!=c[f].from&&c[f].from==c[f].to&&"bookmark"!=c[f].marker.type&&c.splice(f--,1);c.length||(c=null)}e=[c];if(!g){var g=b.text.length-2,p;if(0<g&&c)for(f=0;f<c.length;++f)null==c[f].to&&(p||(p=[])).push({from:null,to:null,marker:c[f].marker});for(f=0;f<g;++f)e.push(p);e.push(d)}return e}function wd(a,b){var c;if(c=b["spans_"+a.id]){for(var d=0,e=[];d<b.text.length;++d)e.push(ve(c[d]));c=e}else c=null;d=Cc(a,b);if(!c)return d; if(!d)return c;for(e=0;e<c.length;++e){var f=c[e],g=d[e];if(f&&g){var h=0;a:for(;h<g.length;++h){for(var k=g[h],l=0;l<f.length;++l)if(f[l].marker==k.marker)continue a;f.push(k)}}else g&&(c[e]=g)}return c}function se(a,b,c){var d=null;a.iter(b.line,c.line+1,function(a){if(a.markedSpans)for(var b=0;b<a.markedSpans.length;++b){var c=a.markedSpans[b].marker;!c.readOnly||d&&-1!=ca(d,c)||(d||(d=[])).push(c)}});if(!d)return null;a=[{from:b,to:c}];for(b=0;b<d.length;++b){c=d[b];for(var e=c.find(),f=0;f<a.length;++f){var g= a[f];if(!z(g.to,e.from)&&!z(e.to,g.from)){var h=[f,1];(z(g.from,e.from)||!c.inclusiveLeft&&x(g.from,e.from))&&h.push({from:g.from,to:e.from});(z(e.to,g.to)||!c.inclusiveRight&&x(g.to,e.to))&&h.push({from:e.to,to:g.to});a.splice.apply(a,h);f+=h.length-1}}}return a}function ua(a,b){var c=Pa&&a.markedSpans,d;if(c)for(var e,f=0;f<c.length;++f)e=c[f],e.marker.collapsed&&(null==e.from||e.from<b)&&(null==e.to||e.to>b)&&(!d||d.width<e.marker.width)&&(d=e.marker);return d}function nb(a){return ua(a,a.text.length+ 1)}function $(a,b){for(var c;c=ua(b,-1);)b=u(a,c.find().from.line);return b}function ia(a,b){var c=Pa&&b.markedSpans;if(c)for(var d,e=0;e<c.length;++e)if(d=c[e],d.marker.collapsed&&(null==d.from||!d.marker.replacedWith&&0==d.from&&d.marker.inclusiveLeft&&Ic(a,b,d)))return!0}function Ic(a,b,c){if(null==c.to)return b=c.marker.find().to,b=u(a,b.line),Ic(a,b,gb(b.markedSpans,c.marker));if(c.marker.inclusiveRight&&c.to==b.text.length)return!0;for(var d,e=0;e<b.markedSpans.length;++e)if(d=b.markedSpans[e], d.marker.collapsed&&!d.marker.replacedWith&&d.from==c.to&&(d.marker.inclusiveLeft||c.marker.inclusiveRight)&&Ic(a,b,d))return!0}function Dd(a){var b=a.markedSpans;if(b){for(var c=0;c<b.length;++c)b[c].marker.detachLine(a);a.markedSpans=null}}function Ed(a,b){if(b){for(var c=0;c<b.length;++c)b[c].marker.attachLine(a);a.markedSpans=b}}function Fd(a){return function(){var b=!this.cm.curOp;b&&za(this.cm);try{var c=a.apply(this,arguments)}finally{b&&Aa(this.cm)}return c}}function tb(a){if(null!=a.height)return a.height; a.node.parentNode&&1==a.node.parentNode.nodeType||W(a.cm.display.measure,p("div",[a.node],null,"position: relative"));return a.height=a.node.offsetHeight}function we(a,b,c,d){var e=new Kb(a,c,d);e.noHScroll&&(a.display.alignWidgets=!0);Ib(a,b,function(b){var c=b.widgets||(b.widgets=[]);null==e.insertAt?c.push(e):c.splice(Math.min(c.length-1,Math.max(0,e.insertAt)),0,e);e.line=b;if(!ia(a.doc,b)||e.showIfHidden)c=Qa(a,b)<a.doc.scrollTop,R(b,b.height+tb(e)),c&&Gc(a,0,e.height);return!0});return e}function Gd(a, b,c,d,e){var f=c.flattenSpans;null==f&&(f=a.options.flattenSpans);var g=0,h=null,k=new db(b,a.options.tabSize),l;for(""==b&&c.blankLine&&c.blankLine(d);!k.eol();)k.pos>a.options.maxHighlightLength?(f=!1,k.pos=Math.min(b.length,k.start+5E4),l=null):l=c.token(k,d),f&&h==l||(g<k.start&&e(k.start,h),g=k.start,h=l),k.start=k.pos;g<k.pos&&e(k.pos,h)}function Xc(a,b,c){var d=[a.state.modeGen];Gd(a,b.text,a.doc.mode,c,function(a,b){d.push(a,b)});for(c=0;c<a.state.overlays.length;++c){var e=a.state.overlays[c], f=1,g=0;Gd(a,b.text,e.mode,!0,function(a,b){for(var c=f;g<a;){var n=d[f];n>a&&d.splice(f,1,a,d[f+1],n);f+=2;g=Math.min(a,n)}if(b)if(e.opaque)d.splice(c,f-c,a,b),f=c+2;else for(;c<f;c+=2)n=d[c+1],d[c+1]=n?n+" "+b:b})}return d}function Hd(a,b){b.styles&&b.styles[0]==a.state.modeGen||(b.styles=Xc(a,b,b.stateAfter=Ra(a,P(b))));return b.styles}function Yc(a,b,c){var d=a.doc.mode,e=new db(b.text,a.options.tabSize);for(""==b.text&&d.blankLine&&d.blankLine(c);!e.eol()&&e.pos<=a.options.maxHighlightLength;)d.token(e, c),e.start=e.pos}function Id(a){return a?Jd[a]||(Jd[a]="cm-"+a.replace(/ +/g," cm-")):null}function fc(a,b,c,d){for(var e,f=b,g=!0;e=ua(f,-1);)f=u(a.doc,e.find().from.line);d={pre:p("pre"),col:0,pos:0,measure:null,measuredSomething:!1,cm:a,copyWidgets:d};f.textClass&&(d.pre.className=f.textClass);do{f.text&&(g=!1);d.measure=f==b&&c;d.pos=0;d.addToken=d.measure?xe:Kd;(B||K)&&a.getOption("lineWrapping")&&(d.addToken=ye(d.addToken));a:{e=d;var h=Hd(a,f),k=f.markedSpans,l=f.text,n=0;if(k)for(var m=l.length, q=0,r=1,s="",t=void 0,v=0,C=void 0,w=void 0,x=void 0,y=void 0,G=void 0;;){if(v==q){for(var C=w=x=y="",G=null,v=Infinity,z=[],D=0;D<k.length;++D){var A=k[D],F=A.marker;A.from<=q&&(null==A.to||A.to>q)?(null!=A.to&&v>A.to&&(v=A.to,w=""),F.className&&(C+=" "+F.className),F.startStyle&&A.from==q&&(x+=" "+F.startStyle),F.endStyle&&A.to==v&&(w+=" "+F.endStyle),F.title&&!y&&(y=F.title),F.collapsed&&(!G||G.marker.size<F.size)&&(G=A)):A.from>q&&v>A.from&&(v=A.from);"bookmark"==F.type&&A.from==q&&F.replacedWith&& z.push(F)}if(G&&(G.from||0)==q&&(Ld(e,(null==G.to?m:G.to)-q,G.marker,null==G.from),null==G.to)){e=G.marker.find();break a}if(!G&&z.length)for(D=0;D<z.length;++D)Ld(e,0,z[D])}if(q>=m)break;for(z=Math.min(m,v);;){if(s){D=q+s.length;G||(A=D>z?s.slice(0,z-q):s,e.addToken(e,A,t?t+C:C,x,q+A.length==v?w:"",y));if(D>=z){s=s.slice(z-q);q=z;break}q=D;x=""}s=l.slice(n,n=h[r++]);t=Id(h[r++])}}else for(var r=1;r<h.length;r+=2)e.addToken(e,l.slice(n,n=h[r]),Id(h[r+1]));e=void 0}c&&f==b&&!d.measuredSomething&&(c[0]= d.pre.appendChild(Sa(a.display.measure)),d.measuredSomething=!0);e&&(f=u(a.doc,e.to.line))}while(e);!c||d.measuredSomething||c[0]||(c[0]=d.pre.appendChild(g?p("span","\u00a0"):Sa(a.display.measure)));d.pre.firstChild||ia(a.doc,b)||d.pre.appendChild(document.createTextNode("\u00a0"));var I;c&&B&&(I=V(f))&&(g=I.length-1,I[g].from==I[g].to&&--g,f=I[g],I=I[g-1],f.from+1==f.to&&I&&f.level<I.level&&(c=c[d.pos-1])&&c.parentNode.insertBefore(c.measureRight=Sa(a.display.measure),c.nextSibling));J(a,"renderLine", a,b,d.pre);return d.pre}function Kd(a,b,c,d,e,f){if(b){if(Jc.test(b))for(var g=document.createDocumentFragment(),h=0;;){Jc.lastIndex=h;var k=Jc.exec(b),l=k?k.index-h:b.length-h;l&&(g.appendChild(document.createTextNode(b.slice(h,h+l))),a.col+=l);if(!k)break;h+=l+1;"\t"==k[0]?(k=a.cm.options.tabSize,k-=a.col%k,g.appendChild(p("span",zd(k),"cm-tab")),a.col+=k):(l=p("span","\u2022","cm-invalidchar"),l.title="\\u"+k[0].charCodeAt(0).toString(16),g.appendChild(l),a.col+=1)}else{a.col+=b.length;var g=document.createTextNode(b)}if(c|| d||e||a.measure)return b=c||"",d&&(b+=d),e&&(b+=e),l=p("span",[g],b),f&&(l.title=f),a.pre.appendChild(l);a.pre.appendChild(g)}}function xe(a,b,c,d,e){for(var f=a.cm.options.lineWrapping,g=0;g<b.length;++g){var h=b.charAt(g),k=0==g;"\ud800"<=h&&"\udbff">h&&g<b.length-1?(h=b.slice(g,g+2),++g):g&&f&&Lb(b,g)&&a.pre.appendChild(p("wbr"));var l=a.measure[a.pos],k=a.measure[a.pos]=Kd(a,h,c,k&&d,g==b.length-1&&e);l&&(k.leftSide=l.leftSide||l);B&&f&&" "==h&&g&&!/\s/.test(b.charAt(g-1))&&g<b.length-1&&!/\s/.test(b.charAt(g+ 1))&&(k.style.whiteSpace="normal");a.pos+=h.length}b.length&&(a.measuredSomething=!0)}function ye(a){function b(a){for(var b=" ",e=0;e<a.length-2;++e)b+=e%2?" ":"\u00a0";return b+" "}return function(c,d,e,f,g,h){return a(c,d.replace(/ {3,}/,b),e,f,g,h)}}function Ld(a,b,c,d){if(d=!d&&c.replacedWith)if(a.copyWidgets&&(d=d.cloneNode(!0)),a.pre.appendChild(d),a.measure){if(b)a.measure[a.pos]=d;else{var e=Sa(a.cm.display.measure);if("bookmark"!=c.type||c.insertLeft){if(a.measure[a.pos])return;a.measure[a.pos]= a.pre.insertBefore(e,d)}else a.measure[a.pos]=a.pre.appendChild(e)}a.measuredSomething=!0}a.pos+=b}function Fc(a,b,c,d,e){function f(a,c,d){var f=e;a.text=c;a.stateAfter&&(a.stateAfter=null);a.styles&&(a.styles=null);null!=a.order&&(a.order=null);Dd(a);Ed(a,d);c=f?f(a):1;c!=a.height&&R(a,c);M(a,"change",a,b)}var g=b.from,h=b.to,k=b.text,l=u(a,g.line),n=u(a,h.line),m=L(k),q=c?c[k.length-1]:null,r=h.line-g.line;if(0==g.ch&&0==h.ch&&""==m){for(var p=0,s=k.length-1,t=[];p<s;++p)t.push(new Ga(k[p],c?c[p]: null,e));f(n,n.text,q);r&&a.remove(g.line,r);t.length&&a.insert(g.line,t)}else if(l==n)if(1==k.length)f(l,l.text.slice(0,g.ch)+m+l.text.slice(h.ch),q);else{t=[];p=1;for(s=k.length-1;p<s;++p)t.push(new Ga(k[p],c?c[p]:null,e));t.push(new Ga(m+l.text.slice(h.ch),q,e));f(l,l.text.slice(0,g.ch)+k[0],c?c[0]:null);a.insert(g.line+1,t)}else if(1==k.length)f(l,l.text.slice(0,g.ch)+k[0]+n.text.slice(h.ch),c?c[0]:null),a.remove(g.line+1,r);else{f(l,l.text.slice(0,g.ch)+k[0],c?c[0]:null);f(n,m+n.text.slice(h.ch), q);p=1;s=k.length-1;for(t=[];p<s;++p)t.push(new Ga(k[p],c?c[p]:null,e));1<r&&a.remove(g.line+1,r-1);a.insert(g.line+1,t)}M(a,"change",a,b);ea(a,d.anchor,d.head,null,!0)}function Mb(a){this.lines=a;this.parent=null;for(var b=0,c=a.length,d=0;b<c;++b)a[b].parent=this,d+=a[b].height;this.height=d}function hb(a){this.children=a;for(var b=0,c=0,d=0,e=a.length;d<e;++d){var f=a[d],b=b+f.chunkSize(),c=c+f.height;f.parent=this}this.size=b;this.height=c;this.parent=null}function Ea(a,b,c){function d(a,f,g){if(a.linked)for(var h= 0;h<a.linked.length;++h){var k=a.linked[h];if(k.doc!=f){var l=g&&k.sharedHist;if(!c||l)b(k.doc,l),d(k.doc,a,l)}}}d(a,null,!0)}function Pc(a,b){if(b.cm)throw Error("This document is already in use.");a.doc=b;b.cm=a;Tc(a);Ja(a);a.options.lineWrapping||Zb(a);a.options.mode=b.modeOption;D(a)}function u(a,b){for(b-=a.first;!a.lines;)for(var c=0;;++c){var d=a.children[c],e=d.chunkSize();if(b<e){a=d;break}b-=e}return a.lines[b]}function Ec(a,b,c){var d=[],e=b.line;a.iter(b.line,c.line+1,function(a){a=a.text; e==c.line&&(a=a.slice(0,c.ch));e==b.line&&(a=a.slice(b.ch));d.push(a);++e});return d}function Kc(a,b,c){var d=[];a.iter(b,c,function(a){d.push(a.text)});return d}function R(a,b){for(var c=b-a.height,d=a;d;d=d.parent)d.height+=c}function P(a){if(null==a.parent)return null;var b=a.parent;a=ca(b.lines,a);for(var c=b.parent;c;b=c,c=c.parent)for(var d=0;c.children[d]!=b;++d)a+=c.children[d].chunkSize();return a+b.first}function Oa(a,b){var c=a.first;a:do{for(var d=0,e=a.children.length;d<e;++d){var f= a.children[d],g=f.height;if(b<g){a=f;continue a}b-=g;c+=f.chunkSize()}return c}while(!a.lines);d=0;for(e=a.lines.length;d<e;++d){f=a.lines[d].height;if(b<f)break;b-=f}return c+d}function Qa(a,b){b=$(a.doc,b);for(var c=0,d=b.parent,e=0;e<d.lines.length;++e){var f=d.lines[e];if(f==b)break;else c+=f.height}for(f=d.parent;f;d=f,f=d.parent)for(e=0;e<f.children.length;++e){var g=f.children[e];if(g==d)break;else c+=g.height}return c}function V(a){var b=a.order;null==b&&(b=a.order=ze(a.text));return b}function Nb(a){return{done:[], undone:[],undoDepth:Infinity,lastTime:0,lastOp:null,lastOrigin:null,generation:a||1,maxGeneration:a||1}}function Md(a,b,c,d){var e=b["spans_"+a.id],f=0;a.iter(Math.max(a.first,c),Math.min(a.first+a.size,d),function(c){c.markedSpans&&((e||(e=b["spans_"+a.id]={}))[f]=c.markedSpans);++f})}function Dc(a,b){var c={from:{line:b.from.line,ch:b.from.ch},to:Ac(b),text:Ec(a,b.from,b.to)};Md(a,c,b.from.line,b.to.line+1);Ea(a,function(a){Md(a,c,b.from.line,b.to.line+1)},!0);return c}function td(a,b,c,d){var e= a.history;e.undone.length=0;var f=+new Date,g=L(e.done);if(g&&(e.lastOp==d||e.lastOrigin==b.origin&&b.origin&&("+"==b.origin.charAt(0)&&a.cm&&e.lastTime>f-a.cm.options.historyEventDelay||"*"==b.origin.charAt(0)))){var h=L(g.changes);x(b.from,b.to)&&x(b.from,h.to)?h.to=Ac(b):g.changes.push(Dc(a,b));g.anchorAfter=c.anchor;g.headAfter=c.head}else for(g={changes:[Dc(a,b)],generation:e.generation,anchorBefore:a.sel.anchor,headBefore:a.sel.head,anchorAfter:c.anchor,headAfter:c.head},e.done.push(g),e.generation= ++e.maxGeneration;e.done.length>e.undoDepth;)e.done.shift();e.lastTime=f;e.lastOp=d;e.lastOrigin=b.origin}function ve(a){if(!a)return null;for(var b=0,c;b<a.length;++b)a[b].marker.explicitlyCleared?c||(c=a.slice(0,b)):c&&c.push(a[b]);return c?c.length?c:null:a}function Ob(a,b){for(var c=0,d=[];c<a.length;++c){var e=a[c],f=e.changes,g=[];d.push({changes:g,anchorBefore:e.anchorBefore,headBefore:e.headBefore,anchorAfter:e.anchorAfter,headAfter:e.headAfter});for(e=0;e<f.length;++e){var h=f[e],k;g.push({from:h.from, to:h.to,text:h.text});if(b)for(var l in h)(k=l.match(/^spans_(\d+)$/))&&-1<ca(b,Number(k[1]))&&(L(g)[l]=h[l],delete h[l])}}return d}function Pb(a,b,c,d){c<a.line?a.line+=d:b<a.line&&(a.line=b,a.ch=0)}function Nd(a,b,c,d){for(var e=0;e<a.length;++e){for(var f=a[e],g=!0,h=0;h<f.changes.length;++h){var k=f.changes[h];f.copied||(k.from=ma(k.from),k.to=ma(k.to));if(c<k.from.line)k.from.line+=d,k.to.line+=d;else if(b<=k.to.line){g=!1;break}}f.copied||(f.anchorBefore=ma(f.anchorBefore),f.headBefore=ma(f.headBefore), f.anchorAfter=ma(f.anchorAfter),f.readAfter=ma(f.headAfter),f.copied=!0);g?(Pb(f.anchorBefore),Pb(f.headBefore),Pb(f.anchorAfter),Pb(f.headAfter)):(a.splice(0,e+1),e=0)}}function ud(a,b){var c=b.from.line,d=b.to.line,e=b.text.length-(d-c)-1;Nd(a.done,c,d,e);Nd(a.undone,c,d,e)}function Ae(){Ya(this)}function Xa(a){a.stop||(a.stop=Ae);return a}function A(a){a.preventDefault?a.preventDefault():a.returnValue=!1}function Od(a){a.stopPropagation?a.stopPropagation():a.cancelBubble=!0}function Ya(a){A(a); Od(a)}function jd(a){var b=a.which;null==b&&(a.button&1?b=1:a.button&2?b=3:a.button&4&&(b=2));va&&a.ctrlKey&&1==b&&(b=3);return b}function v(a,b,c){a.addEventListener?a.addEventListener(b,c,!1):a.attachEvent?a.attachEvent("on"+b,c):(a=a._handlers||(a._handlers={}),(a[b]||(a[b]=[])).push(c))}function aa(a,b,c){if(a.removeEventListener)a.removeEventListener(b,c,!1);else if(a.detachEvent)a.detachEvent("on"+b,c);else if(a=a._handlers&&a._handlers[b])for(b=0;b<a.length;++b)if(a[b]==c){a.splice(b,1);break}} function J(a,b){var c=a._handlers&&a._handlers[b];if(c)for(var d=Array.prototype.slice.call(arguments,2),e=0;e<c.length;++e)c[e].apply(null,d)}function M(a,b){function c(a){return function(){a.apply(null,e)}}var d=a._handlers&&a._handlers[b];if(d){var e=Array.prototype.slice.call(arguments,2);da||(++xb,da=[],setTimeout(Be,0));for(var f=0;f<d.length;++f)da.push(c(d[f]))}}function X(a,b,c){J(a,c||b.type,a,b);return(null!=b.defaultPrevented?b.defaultPrevented:!1==b.returnValue)||b.codemirrorIgnore}function Be(){--xb; var a=da;da=null;for(var b=0;b<a.length;++b)a[b]()}function ba(a,b){var c=a._handlers&&a._handlers[b];return c&&0<c.length}function Ha(a){a.prototype.on=function(a,c){v(this,a,c)};a.prototype.off=function(a,c){aa(this,a,c)}}function Ub(){this.id=null}function xa(a,b,c,d,e){null==b&&(b=a.search(/[^\s\u00a0]/),-1==b&&(b=a.length));d=d||0;for(e=e||0;d<b;++d)"\t"==a.charAt(d)?e+=c-e%c:++e;return e}function zd(a){for(;Qb.length<=a;)Qb.push(L(Qb)+" ");return Qb[a]}function L(a){return a[a.length-1]}function dd(a){if(Ia)a.selectionStart= 0,a.selectionEnd=a.value.length;else try{a.select()}catch(b){}}function ca(a,b){if(a.indexOf)return a.indexOf(b);for(var c=0,d=a.length;c<d;++c)if(a[c]==b)return c;return-1}function Pd(a,b){function c(){}c.prototype=a;var d=new c;b&&Jb(b,d);return d}function Jb(a,b){b||(b={});for(var c in a)a.hasOwnProperty(c)&&(b[c]=a[c]);return b}function $c(a){for(var b=[],c=0;c<a;++c)b.push(void 0);return b}function O(a){var b=Array.prototype.slice.call(arguments,1);return function(){return a.apply(null,b)}}function cb(a){return/\w/.test(a)|| "\u0080"<a&&(a.toUpperCase()!=a.toLowerCase()||Ce.test(a))}function Qd(a){for(var b in a)if(a.hasOwnProperty(b)&&a[b])return!1;return!0}function p(a,b,c,d){a=document.createElement(a);c&&(a.className=c);d&&(a.style.cssText=d);if("string"==typeof b)Wc(a,b);else if(b)for(c=0;c<b.length;++c)a.appendChild(b[c]);return a}function Ma(a){for(var b=a.childNodes.length;0<b;--b)a.removeChild(a.firstChild);return a}function W(a,b){return Ma(a).appendChild(b)}function Wc(a,b){Q?(a.innerHTML="",a.appendChild(document.createTextNode(b))): a.textContent=b}function y(a){return a.getBoundingClientRect()}function Lb(){return!1}function Na(a){if(null!=Wa)return Wa;var b=p("div",null,null,"width: 50px; height: 50px; overflow-x: scroll");W(a,b);b.offsetWidth&&(Wa=b.offsetHeight-b.clientHeight);return Wa||0}function Sa(a){if(null==Lc){var b=p("span","\u200b");W(a,p("span",[b,document.createTextNode("x")]));0!=a.firstChild.offsetHeight&&(Lc=1>=b.offsetWidth&&2<b.offsetHeight&&!ra)}return Lc?p("span","\u200b"):p("span","\u00a0",null,"display: inline-block; width: 1px; margin-right: -1px")} function de(a,b,c,d){if(!a)return d(b,c,"ltr");for(var e=!1,f=0;f<a.length;++f){var g=a[f];if(g.from<c&&g.to>b||b==c&&g.to==b)d(Math.max(g.from,b),Math.min(g.to,c),1==g.level?"rtl":"ltr"),e=!0}e||d(b,c,"ltr")}function kc(a){return a.level%2?a.to:a.from}function lc(a){return a.level%2?a.from:a.to}function vb(a){return(a=V(a))?kc(a[0]):0}function wb(a){var b=V(a);return b?lc(L(b)):a.text.length}function Rd(a,b){var c=u(a.doc,b),d=$(a.doc,c);d!=c&&(b=P(d));d=(c=V(d))?c[0].level%2?wb(d):vb(d):0;return r(b, d)}function De(a,b){for(var c,d;c=nb(d=u(a.doc,b));)b=c.find().to.line;d=(c=V(d))?c[0].level%2?vb(d):wb(d):d.text.length;return r(b,d)}function mc(a,b){for(var c=0,d;c<a.length;++c){var e=a[c];if(e.from<b&&e.to>b)return ya=null,c;if(e.from==b||e.to==b)if(null==d)d=c;else{var e=e.level,f=a[d].level,g=a[0].level,e=e==g?!0:f==g?!1:e<f;if(e)return ya=d,c;ya=c;return d}}ya=null;return d}function Mc(a,b,c,d){if(!d)return b+c;do b+=c;while(0<b&&pc.test(a.text.charAt(b)));return b}function oc(a,b,c,d){var e= V(a);if(!e)return Ad(a,b,c,d);var f=mc(e,b),g=e[f];for(b=Mc(a,b,g.level%2?-c:c,d);;){if(b>g.from&&b<g.to)return b;if(b==g.from||b==g.to){if(mc(e,b)==f)return b;g=e[f+c];return 0<c==g.level%2?g.to:g.from}g=e[f+=c];if(!g)return null;b=0<c==g.level%2?Mc(a,g.to,-1,d):Mc(a,g.from,1,d)}}function Ad(a,b,c,d){b+=c;if(d)for(;0<b&&pc.test(a.text.charAt(b));)b+=c;return 0>b||b>a.text.length?null:b}var Da=/gecko\/\d/i.test(navigator.userAgent),B=/MSIE \d/.test(navigator.userAgent),ra=B&&(null==document.documentMode|| 8>document.documentMode),Q=B&&(null==document.documentMode||9>document.documentMode),K=/WebKit\//.test(navigator.userAgent),Ee=K&&/Qt\/\d+\.\d+/.test(navigator.userAgent),Fe=/Chrome\//.test(navigator.userAgent),S=/Opera\//.test(navigator.userAgent),uc=/Apple Computer/.test(navigator.vendor),Xb=/KHTML\//.test(navigator.userAgent),Vd=/Mac OS X 1\d\D([7-9]|\d\d)\D/.test(navigator.userAgent),Wd=/Mac OS X 1\d\D([8-9]|\d\d)\D/.test(navigator.userAgent),ke=/PhantomJS/.test(navigator.userAgent),Ia=/AppleWebKit/.test(navigator.userAgent)&& /Mobile\/\w+/.test(navigator.userAgent),Tb=Ia||/Android|webOS|BlackBerry|Opera Mini|Opera Mobi|IEMobile/i.test(navigator.userAgent),va=Ia||/Mac/.test(navigator.platform),Ge=/win/i.test(navigator.platform),oa=S&&navigator.userAgent.match(/Version\/(\d*\.\d*)/);oa&&(oa=Number(oa[1]));oa&&15<=oa&&(S=!1,K=!0);var Cd=va&&(Ee||S&&(null==oa||12.11>oa)),tc=Da||B&&!Q,sd=!1,Pa=!1,ja,je=0,Bb,Ab,id=0,Cb=0,T=null;B?T=-0.53:Da?T=15:Fe?T=-0.7:uc&&(T=-1/3);var nd,xc=null,yc,Ac=m.changeEnd=function(a){return a.text? r(a.from.line+a.text.length-1,L(a.text).length+(1==a.text.length?a.from.ch:0)):a.to};m.Pos=r;m.prototype={constructor:m,focus:function(){window.focus();N(this);ha(this);Ua(this)},setOption:function(a,b){var c=this.options,d=c[a];if(c[a]!=b||"mode"==a)c[a]=b,pa.hasOwnProperty(a)&&t(this,pa[a])(this,b,d)},getOption:function(a){return this.options[a]},getDoc:function(){return this.doc},addKeyMap:function(a,b){this.state.keyMaps[b?"push":"unshift"](a)},removeKeyMap:function(a){for(var b=this.state.keyMaps, c=0;c<b.length;++c)if(b[c]==a||"string"!=typeof b[c]&&b[c].name==a)return b.splice(c,1),!0},addOverlay:t(null,function(a,b){var c=a.token?a:m.getMode(this.options,a);if(c.startState)throw Error("Overlays may not be stateful.");this.state.overlays.push({mode:c,modeSpec:a,opaque:b&&b.opaque});this.state.modeGen++;D(this)}),removeOverlay:t(null,function(a){for(var b=this.state.overlays,c=0;c<b.length;++c){var d=b[c].modeSpec;if(d==a||"string"==typeof a&&d.name==a){b.splice(c,1);this.state.modeGen++; D(this);break}}}),indentLine:t(null,function(a,b,c){"string"!=typeof b&&"number"!=typeof b&&(b=null==b?this.options.smartIndent?"smart":"prev":b?"add":"subtract");Fa(this.doc,a)&&Eb(this,a,b,c)}),indentSelection:t(null,function(a){var b=this.doc.sel;if(x(b.from,b.to))return Eb(this,b.from.line,a);for(var c=b.to.line-(b.to.ch?0:1),b=b.from.line;b<=c;++b)Eb(this,b,a)}),getTokenAt:function(a,b){var c=this.doc;a=s(c,a);for(var d=Ra(this,a.line,b),e=this.doc.mode,c=u(c,a.line),c=new db(c.text,this.options.tabSize);c.pos< a.ch&&!c.eol();){c.start=c.pos;var f=e.token(c,d)}return{start:c.start,end:c.pos,string:c.current(),className:f||null,type:f||null,state:d}},getTokenTypeAt:function(a){a=s(this.doc,a);var b=Hd(this,u(this.doc,a.line)),c=0,d=(b.length-1)/2;a=a.ch;if(0==a)return b[2];for(;;){var e=c+d>>1;if((e?b[2*e-1]:0)>=a)d=e;else if(b[2*e+1]<a)c=e+1;else return b[2*e+2]}},getModeAt:function(a){var b=this.doc.mode;return b.innerMode?m.innerMode(b,this.getTokenAt(a).state).mode:b},getHelper:function(a,b){if(ib.hasOwnProperty(b)){var c= ib[b],d=this.getModeAt(a);return d[b]&&c[d[b]]||d.helperType&&c[d.helperType]||c[d.name]}},getStateAfter:function(a,b){var c=this.doc;a=Math.max(c.first,Math.min(null==a?c.first+c.size-1:a,c.first+c.size-1));return Ra(this,a+1,b)},cursorCoords:function(a,b){var c;c=this.doc.sel;c=null==a?c.head:"object"==typeof a?s(this.doc,a):a?c.from:c.to;return U(this,c,b||"page")},charCoords:function(a,b){return rb(this,s(this.doc,a),b||"page")},coordsChar:function(a,b){a=ad(this,a,b||"page");return nc(this,a.left, a.top)},lineAtHeight:function(a,b){a=ad(this,{top:a,left:0},b||"page").top;return Oa(this.doc,a+this.display.viewOffset)},heightAtLine:function(a,b){var c=!1,d=this.doc.first+this.doc.size-1;a<this.doc.first?a=this.doc.first:a>d&&(a=d,c=!0);d=u(this.doc,a);return jc(this,u(this.doc,a),{top:0,left:0},b||"page").top+(c?d.height:0)},defaultTextHeight:function(){return sa(this.display)},defaultCharWidth:function(){return Sc(this.display)},setGutterMarker:t(null,function(a,b,c){return Ib(this,a,function(a){var e= a.gutterMarkers||(a.gutterMarkers={});e[b]=c;!c&&Qd(e)&&(a.gutterMarkers=null);return!0})}),clearGutter:t(null,function(a){var b=this,c=b.doc,d=c.first;c.iter(function(c){c.gutterMarkers&&c.gutterMarkers[a]&&(c.gutterMarkers[a]=null,D(b,d,d+1),Qd(c.gutterMarkers)&&(c.gutterMarkers=null));++d})}),addLineClass:t(null,function(a,b,c){return Ib(this,a,function(a){var e="text"==b?"textClass":"background"==b?"bgClass":"wrapClass";if(a[e]){if(RegExp("(?:^|\\s)"+c+"(?:$|\\s)").test(a[e]))return!1;a[e]+=" "+ c}else a[e]=c;return!0})}),removeLineClass:t(null,function(a,b,c){return Ib(this,a,function(a){var e="text"==b?"textClass":"background"==b?"bgClass":"wrapClass",f=a[e];if(f)if(null==c)a[e]=null;else{var g=f.match(RegExp("(?:^|\\s+)"+c+"(?:$|\\s+)"));if(!g)return!1;var h=g.index+g[0].length;a[e]=f.slice(0,g.index)+(g.index&&h!=f.length?" ":"")+f.slice(h)||null}else return!1;return!0})}),addLineWidget:t(null,function(a,b,c){return we(this,a,b,c)}),removeLineWidget:function(a){a.clear()},lineInfo:function(a){if("number"== typeof a){if(!Fa(this.doc,a))return null;var b=a;a=u(this.doc,a);if(!a)return null}else if(b=P(a),null==b)return null;return{line:b,handle:a,text:a.text,gutterMarkers:a.gutterMarkers,textClass:a.textClass,bgClass:a.bgClass,wrapClass:a.wrapClass,widgets:a.widgets}},getViewport:function(){return{from:this.display.showingFrom,to:this.display.showingTo}},addWidget:function(a,b,c,d,e){var f=this.display;a=U(this,s(this.doc,a));var g=a.bottom,h=a.left;b.style.position="absolute";f.sizer.appendChild(b); if("over"==d)g=a.top;else if("above"==d||"near"==d){var k=Math.max(f.wrapper.clientHeight,this.doc.height),l=Math.max(f.sizer.clientWidth,f.lineSpace.clientWidth);("above"==d||a.bottom+b.offsetHeight>k)&&a.top>b.offsetHeight?g=a.top-b.offsetHeight:a.bottom+b.offsetHeight<=k&&(g=a.bottom);h+b.offsetWidth>l&&(h=l-b.offsetWidth)}b.style.top=g+"px";b.style.left=b.style.right="";"right"==e?(h=f.sizer.clientWidth-b.offsetWidth,b.style.right="0px"):("left"==e?h=0:"middle"==e&&(h=(f.sizer.clientWidth-b.offsetWidth)/ 2),b.style.left=h+"px");c&&(a=yb(this,h,g,h+b.offsetWidth,g+b.offsetHeight),null!=a.scrollTop&&$a(this,a.scrollTop),null!=a.scrollLeft&&Ba(this,a.scrollLeft))},triggerOnKeyDown:t(null,hd),execCommand:function(a){return vc[a](this)},findPosH:function(a,b,c,d){var e=1;0>b&&(e=-1,b=-b);var f=0;for(a=s(this.doc,a);f<b&&(a=Hc(this.doc,a,e,c,d),!a.hitSide);++f);return a},moveH:t(null,function(a,b){var c=this.doc.sel,c=c.shift||c.extend||x(c.from,c.to)?Hc(this.doc,c.head,a,b,this.options.rtlMoveVisually): 0>a?c.from:c.to;F(this.doc,c,c,a)}),deleteH:t(null,function(a,b){var c=this.doc.sel;x(c.from,c.to)?fa(this.doc,"",c.from,Hc(this.doc,c.head,a,b,!1),"+delete"):fa(this.doc,"",c.from,c.to,"+delete");this.curOp.userSelChange=!0}),findPosV:function(a,b,c,d){var e=1;0>b&&(e=-1,b=-b);var f=0;for(a=s(this.doc,a);f<b&&(a=U(this,a,"div"),null==d?d=a.left:a.left=d,a=Bd(this,a,e,c),!a.hitSide);++f);return a},moveV:t(null,function(a,b){var c=this.doc.sel,d=U(this,c.head,"div");null!=c.goalColumn&&(d.left=c.goalColumn); var e=Bd(this,d,a,b);"page"==b&&Gc(this,0,rb(this,e,"div").top-d.top);F(this.doc,e,e,a);c.goalColumn=d.left}),toggleOverwrite:function(a){if(null==a||a!=this.state.overwrite)(this.state.overwrite=!this.state.overwrite)?this.display.cursor.className+=" CodeMirror-overwrite":this.display.cursor.className=this.display.cursor.className.replace(" CodeMirror-overwrite","")},hasFocus:function(){return this.state.focused},scrollTo:t(null,function(a,b){Hb(this,a,b)}),getScrollInfo:function(){var a=this.display.scroller, b=qa;return{left:a.scrollLeft,top:a.scrollTop,height:a.scrollHeight-b,width:a.scrollWidth-b,clientHeight:a.clientHeight-b,clientWidth:a.clientWidth-b}},scrollIntoView:t(null,function(a,b){"number"==typeof a&&(a=r(a,0));b||(b=0);var c=a;a&&null==a.line||(this.curOp.scrollToPos=a?s(this.doc,a):this.doc.sel.head,this.curOp.scrollToPosMargin=b,c=U(this,this.curOp.scrollToPos));c=yb(this,c.left,c.top-b,c.right,c.bottom+b);Hb(this,c.scrollLeft,c.scrollTop)}),setSize:t(null,function(a,b){function c(a){return"number"== typeof a||/^\d+$/.test(String(a))?a+"px":a}null!=a&&(this.display.wrapper.style.width=c(a));null!=b&&(this.display.wrapper.style.height=c(b));this.options.lineWrapping&&(this.display.measureLineCache.length=this.display.measureLineCachePos=0);this.curOp.forceUpdate=!0}),operation:function(a){return qc(this,a)},refresh:t(null,function(){ta(this);Hb(this,this.doc.scrollLeft,this.doc.scrollTop);D(this)}),swapDoc:t(null,function(a){var b=this.doc;b.cm=null;Pc(this,a);ta(this);Y(this,!0);Hb(this,a.scrollLeft, a.scrollTop);return b}),getInputField:function(){return this.display.input},getWrapperElement:function(){return this.display.wrapper},getScrollerElement:function(){return this.display.scroller},getGutterElement:function(){return this.display.gutters}};Ha(m);var pa=m.optionHandlers={},Rb=m.defaults={},Qc=m.Init={toString:function(){return"CodeMirror.Init"}};w("value","",function(a,b){a.setValue(b)},!0);w("mode",null,function(a,b){a.doc.modeOption=b;Ja(a)},!0);w("indentUnit",2,Ja,!0);w("indentWithTabs", !1);w("smartIndent",!0);w("tabSize",4,function(a){Ja(a);ta(a);D(a)},!0);w("electricChars",!0);w("rtlMoveVisually",!Ge);w("theme","default",function(a){Oc(a);La(a)},!0);w("keyMap","default",Uc);w("extraKeys",null);w("onKeyEvent",null);w("onDragEvent",null);w("lineWrapping",!1,function(a){a.options.lineWrapping?(a.display.wrapper.className+=" CodeMirror-wrap",a.display.sizer.style.minWidth=""):(a.display.wrapper.className=a.display.wrapper.className.replace(" CodeMirror-wrap",""),Zb(a));Tc(a);D(a); ta(a);setTimeout(function(){$b(a)},100)},!0);w("gutters",[],function(a){Sb(a.options);La(a)},!0);w("fixedGutter",!0,function(a,b){a.display.gutters.style.left=b?bc(a.display)+"px":"0";a.refresh()},!0);w("coverGutterNextToScrollbar",!1,$b,!0);w("lineNumbers",!1,function(a){Sb(a.options);La(a)},!0);w("firstLineNumber",1,La,!0);w("lineNumberFormatter",function(a){return a},La,!0);w("showCursorWhenSelecting",!1,dc,!0);w("readOnly",!1,function(a,b){"nocursor"==b?(Vb(a),a.display.input.blur()):b||Y(a,!0)}); w("dragDrop",!0);w("cursorBlinkRate",530);w("cursorScrollMargin",0);w("cursorHeight",1);w("workTime",100);w("workDelay",100);w("flattenSpans",!0);w("pollInterval",100);w("undoDepth",40,function(a,b){a.doc.history.undoDepth=b});w("historyEventDelay",500);w("viewportMargin",10,function(a){a.refresh()},!0);w("maxHighlightLength",1E4,function(a){Ja(a);a.refresh()},!0);w("moveInputWithCursor",!0,function(a,b){b||(a.display.inputDiv.style.top=a.display.inputDiv.style.left=0)});w("tabindex",null,function(a, b){a.display.input.tabIndex=b||""});w("autofocus",null);var Sd=m.modes={},jb=m.mimeModes={};m.defineMode=function(a,b){m.defaults.mode||"null"==a||(m.defaults.mode=a);if(2<arguments.length){b.dependencies=[];for(var c=2;c<arguments.length;++c)b.dependencies.push(arguments[c])}Sd[a]=b};m.defineMIME=function(a,b){jb[a]=b};m.resolveMode=function(a){if("string"==typeof a&&jb.hasOwnProperty(a))a=jb[a];else if(a&&"string"==typeof a.name&&jb.hasOwnProperty(a.name)){var b=jb[a.name];a=Pd(b,a);a.name=b.name}else if("string"== typeof a&&/^[\w\-]+\/[\w\-]+\+xml$/.test(a))return m.resolveMode("application/xml");return"string"==typeof a?{name:a}:a||{name:"null"}};m.getMode=function(a,b){b=m.resolveMode(b);var c=Sd[b.name];if(!c)return m.getMode(a,"text/plain");c=c(a,b);if(kb.hasOwnProperty(b.name)){var d=kb[b.name],e;for(e in d)d.hasOwnProperty(e)&&(c.hasOwnProperty(e)&&(c["_"+e]=c[e]),c[e]=d[e])}c.name=b.name;return c};m.defineMode("null",function(){return{token:function(a){a.skipToEnd()}}});m.defineMIME("text/plain","null"); var kb=m.modeExtensions={};m.extendMode=function(a,b){var c=kb.hasOwnProperty(a)?kb[a]:kb[a]={};Jb(b,c)};m.defineExtension=function(a,b){m.prototype[a]=b};m.defineDocExtension=function(a,b){I.prototype[a]=b};m.defineOption=w;var Wb=[];m.defineInitHook=function(a){Wb.push(a)};var ib=m.helpers={};m.registerHelper=function(a,b,c){ib.hasOwnProperty(a)||(ib[a]=m[a]={});ib[a][b]=c};m.isWordChar=cb;m.copyState=wa;m.startState=Zc;m.innerMode=function(a,b){for(;a.innerMode;){var c=a.innerMode(b);if(!c||c.mode== a)break;b=c.state;a=c.mode}return c||{mode:a,state:b}};var vc=m.commands={selectAll:function(a){a.setSelection(r(a.firstLine(),0),r(a.lastLine()))},killLine:function(a){var b=a.getCursor(!0),c=a.getCursor(!1),d=!x(b,c);d||a.getLine(b.line).length!=b.ch?a.replaceRange("",b,d?c:r(b.line),"+delete"):a.replaceRange("",b,r(b.line+1,0),"+delete")},deleteLine:function(a){var b=a.getCursor().line;a.replaceRange("",r(b,0),r(b),"+delete")},delLineLeft:function(a){var b=a.getCursor();a.replaceRange("",r(b.line, 0),b,"+delete")},undo:function(a){a.undo()},redo:function(a){a.redo()},goDocStart:function(a){a.extendSelection(r(a.firstLine(),0))},goDocEnd:function(a){a.extendSelection(r(a.lastLine()))},goLineStart:function(a){a.extendSelection(Rd(a,a.getCursor().line))},goLineStartSmart:function(a){var b=a.getCursor(),c=Rd(a,b.line),d=a.getLineHandle(c.line),e=V(d);e&&0!=e[0].level?a.extendSelection(c):(d=Math.max(0,d.text.search(/\S/)),a.extendSelection(r(c.line,b.line==c.line&&b.ch<=d&&b.ch?0:d)))},goLineEnd:function(a){a.extendSelection(De(a, a.getCursor().line))},goLineRight:function(a){var b=a.charCoords(a.getCursor(),"div").top+5;a.extendSelection(a.coordsChar({left:a.display.lineDiv.offsetWidth+100,top:b},"div"))},goLineLeft:function(a){var b=a.charCoords(a.getCursor(),"div").top+5;a.extendSelection(a.coordsChar({left:0,top:b},"div"))},goLineUp:function(a){a.moveV(-1,"line")},goLineDown:function(a){a.moveV(1,"line")},goPageUp:function(a){a.moveV(-1,"page")},goPageDown:function(a){a.moveV(1,"page")},goCharLeft:function(a){a.moveH(-1, "char")},goCharRight:function(a){a.moveH(1,"char")},goColumnLeft:function(a){a.moveH(-1,"column")},goColumnRight:function(a){a.moveH(1,"column")},goWordLeft:function(a){a.moveH(-1,"word")},goGroupRight:function(a){a.moveH(1,"group")},goGroupLeft:function(a){a.moveH(-1,"group")},goWordRight:function(a){a.moveH(1,"word")},delCharBefore:function(a){a.deleteH(-1,"char")},delCharAfter:function(a){a.deleteH(1,"char")},delWordBefore:function(a){a.deleteH(-1,"word")},delWordAfter:function(a){a.deleteH(1, "word")},delGroupBefore:function(a){a.deleteH(-1,"group")},delGroupAfter:function(a){a.deleteH(1,"group")},indentAuto:function(a){a.indentSelection("smart")},indentMore:function(a){a.indentSelection("add")},indentLess:function(a){a.indentSelection("subtract")},insertTab:function(a){a.replaceSelection("\t","end","+input")},defaultTab:function(a){a.somethingSelected()?a.indentSelection("add"):a.replaceSelection("\t","end","+input")},transposeChars:function(a){var b=a.getCursor(),c=a.getLine(b.line); 0<b.ch&&b.ch<c.length-1&&a.replaceRange(c.charAt(b.ch)+c.charAt(b.ch-1),r(b.line,b.ch-1),r(b.line,b.ch+1))},newlineAndIndent:function(a){t(a,function(){a.replaceSelection("\n","end","+input");a.indentLine(a.getCursor().line,null,!0)})()},toggleOverwrite:function(a){a.toggleOverwrite()}},Z=m.keyMap={};Z.basic={Left:"goCharLeft",Right:"goCharRight",Up:"goLineUp",Down:"goLineDown",End:"goLineEnd",Home:"goLineStartSmart",PageUp:"goPageUp",PageDown:"goPageDown",Delete:"delCharAfter",Backspace:"delCharBefore", Tab:"defaultTab","Shift-Tab":"indentAuto",Enter:"newlineAndIndent",Insert:"toggleOverwrite"};Z.pcDefault={"Ctrl-A":"selectAll","Ctrl-D":"deleteLine","Ctrl-Z":"undo","Shift-Ctrl-Z":"redo","Ctrl-Y":"redo","Ctrl-Home":"goDocStart","Alt-Up":"goDocStart","Ctrl-End":"goDocEnd","Ctrl-Down":"goDocEnd","Ctrl-Left":"goGroupLeft","Ctrl-Right":"goGroupRight","Alt-Left":"goLineStart","Alt-Right":"goLineEnd","Ctrl-Backspace":"delGroupBefore","Ctrl-Delete":"delGroupAfter","Ctrl-S":"save","Ctrl-F":"find","Ctrl-G":"findNext", "Shift-Ctrl-G":"findPrev","Shift-Ctrl-F":"replace","Shift-Ctrl-R":"replaceAll","Ctrl-[":"indentLess","Ctrl-]":"indentMore",fallthrough:"basic"};Z.macDefault={"Cmd-A":"selectAll","Cmd-D":"deleteLine","Cmd-Z":"undo","Shift-Cmd-Z":"redo","Cmd-Y":"redo","Cmd-Up":"goDocStart","Cmd-End":"goDocEnd","Cmd-Down":"goDocEnd","Alt-Left":"goGroupLeft","Alt-Right":"goGroupRight","Cmd-Left":"goLineStart","Cmd-Right":"goLineEnd","Alt-Backspace":"delGroupBefore","Ctrl-Alt-Backspace":"delGroupAfter","Alt-Delete":"delGroupAfter", "Cmd-S":"save","Cmd-F":"find","Cmd-G":"findNext","Shift-Cmd-G":"findPrev","Cmd-Alt-F":"replace","Shift-Cmd-Alt-F":"replaceAll","Cmd-[":"indentLess","Cmd-]":"indentMore","Cmd-Backspace":"delLineLeft",fallthrough:["basic","emacsy"]};Z["default"]=va?Z.macDefault:Z.pcDefault;Z.emacsy={"Ctrl-F":"goCharRight","Ctrl-B":"goCharLeft","Ctrl-P":"goLineUp","Ctrl-N":"goLineDown","Alt-F":"goWordRight","Alt-B":"goWordLeft","Ctrl-A":"goLineStart","Ctrl-E":"goLineEnd","Ctrl-V":"goPageDown","Shift-Ctrl-V":"goPageUp", "Ctrl-D":"delCharAfter","Ctrl-H":"delCharBefore","Alt-D":"delWordAfter","Alt-Backspace":"delWordBefore","Ctrl-K":"killLine","Ctrl-T":"transposeChars"};m.lookupKey=ab;m.isModifierKey=od;m.keyName=pd;m.fromTextArea=function(a,b){function c(){a.value=l.getValue()}b||(b={});b.value=a.value;!b.tabindex&&a.tabindex&&(b.tabindex=a.tabindex);!b.placeholder&&a.placeholder&&(b.placeholder=a.placeholder);if(null==b.autofocus){var d=document.body;try{d=document.activeElement}catch(e){}b.autofocus=d==a||null!= a.getAttribute("autofocus")&&d==document.body}if(a.form&&(v(a.form,"submit",c),!b.leaveSubmitMethodAlone)){var f=a.form,g=f.submit;try{var h=f.submit=function(){c();f.submit=g;f.submit();f.submit=h}}catch(k){}}a.style.display="none";var l=m(function(b){a.parentNode.insertBefore(b,a.nextSibling)},b);l.save=c;l.getTextArea=function(){return a};l.toTextArea=function(){c();a.parentNode.removeChild(l.getWrapperElement());a.style.display="";a.form&&(aa(a.form,"submit",c),"function"==typeof a.form.submit&& (a.form.submit=g))};return l};db.prototype={eol:function(){return this.pos>=this.string.length},sol:function(){return 0==this.pos},peek:function(){return this.string.charAt(this.pos)||void 0},next:function(){if(this.pos<this.string.length)return this.string.charAt(this.pos++)},eat:function(a){var b=this.string.charAt(this.pos);if("string"==typeof a?b==a:b&&(a.test?a.test(b):a(b)))return++this.pos,b},eatWhile:function(a){for(var b=this.pos;this.eat(a););return this.pos>b},eatSpace:function(){for(var a= this.pos;/[\s\u00a0]/.test(this.string.charAt(this.pos));)++this.pos;return this.pos>a},skipToEnd:function(){this.pos=this.string.length},skipTo:function(a){a=this.string.indexOf(a,this.pos);if(-1<a)return this.pos=a,!0},backUp:function(a){this.pos-=a},column:function(){this.lastColumnPos<this.start&&(this.lastColumnValue=xa(this.string,this.start,this.tabSize,this.lastColumnPos,this.lastColumnValue),this.lastColumnPos=this.start);return this.lastColumnValue},indentation:function(){return xa(this.string, null,this.tabSize)},match:function(a,b,c){if("string"==typeof a){var d=function(a){return c?a.toLowerCase():a},e=this.string.substr(this.pos,a.length);if(d(e)==d(a))return!1!==b&&(this.pos+=a.length),!0}else{if((a=this.string.slice(this.pos).match(a))&&0<a.index)return null;a&&!1!==b&&(this.pos+=a[0].length);return a}},current:function(){return this.string.slice(this.start,this.pos)}};m.StringStream=db;m.TextMarker=ga;Ha(ga);ga.prototype.clear=function(){if(!this.explicitlyCleared){var a=this.doc.cm, b=a&&!a.curOp;b&&za(a);if(ba(this,"clear")){var c=this.find();c&&M(this,"clear",c.from,c.to)}for(var d=c=null,e=0;e<this.lines.length;++e){var f=this.lines[e],g=gb(f.markedSpans,this);null!=g.to&&(d=P(f));for(var h=f,k=f.markedSpans,l=g,n=void 0,m=0;m<k.length;++m)k[m]!=l&&(n||(n=[])).push(k[m]);h.markedSpans=n;null!=g.from?c=P(f):this.collapsed&&!ia(this.doc,f)&&a&&R(f,sa(a.display))}if(a&&this.collapsed&&!a.options.lineWrapping)for(e=0;e<this.lines.length;++e)f=$(a.doc,this.lines[e]),g=mb(a.doc, f),g>a.display.maxLineLength&&(a.display.maxLine=f,a.display.maxLineLength=g,a.display.maxLineChanged=!0);null!=c&&a&&D(a,c,d+1);this.lines.length=0;this.explicitlyCleared=!0;this.atomic&&this.doc.cantEdit&&(this.doc.cantEdit=!1,a&&yd(a));b&&Aa(a)}};ga.prototype.find=function(){for(var a,b,c=0;c<this.lines.length;++c){var d=this.lines[c],e=gb(d.markedSpans,this);if(null!=e.from||null!=e.to)d=P(d),null!=e.from&&(a=r(d,e.from)),null!=e.to&&(b=r(d,e.to))}return"bookmark"==this.type?a:a&&{from:a,to:b}}; ga.prototype.changed=function(){var a=this.find(),b=this.doc.cm;if(a&&b){"bookmark"!=this.type&&(a=a.from);var c=u(this.doc,a.line);ge(b,c);if(a.line>=b.display.showingFrom&&a.line<b.display.showingTo){for(a=b.display.lineDiv.firstChild;a;a=a.nextSibling)if(a.lineObj==c){a.offsetHeight!=c.height&&R(c,a.offsetHeight);break}qc(b,function(){b.curOp.selectionChanged=b.curOp.forceUpdate=b.curOp.updateMaxLine=!0})}}};ga.prototype.attachLine=function(a){if(!this.lines.length&&this.doc.cm){var b=this.doc.cm.curOp; b.maybeHiddenMarkers&&-1!=ca(b.maybeHiddenMarkers,this)||(b.maybeUnhiddenMarkers||(b.maybeUnhiddenMarkers=[])).push(this)}this.lines.push(a)};ga.prototype.detachLine=function(a){this.lines.splice(ca(this.lines,a),1);!this.lines.length&&this.doc.cm&&(a=this.doc.cm.curOp,(a.maybeHiddenMarkers||(a.maybeHiddenMarkers=[])).push(this))};m.SharedTextMarker=fb;Ha(fb);fb.prototype.clear=function(){if(!this.explicitlyCleared){this.explicitlyCleared=!0;for(var a=0;a<this.markers.length;++a)this.markers[a].clear(); M(this,"clear")}};fb.prototype.find=function(){return this.primary.find()};var Kb=m.LineWidget=function(a,b,c){if(c)for(var d in c)c.hasOwnProperty(d)&&(this[d]=c[d]);this.cm=a;this.node=b};Ha(Kb);Kb.prototype.clear=Fd(function(){var a=this.line.widgets,b=P(this.line);if(null!=b&&a){for(var c=0;c<a.length;++c)a[c]==this&&a.splice(c--,1);a.length||(this.line.widgets=null);a=Qa(this.cm,this.line)<this.cm.doc.scrollTop;R(this.line,Math.max(0,this.line.height-tb(this)));a&&Gc(this.cm,0,-this.height); D(this.cm,b,b+1)}});Kb.prototype.changed=Fd(function(){var a=this.height;this.height=null;if(a=tb(this)-a)R(this.line,this.line.height+a),a=P(this.line),D(this.cm,a,a+1)});var Ga=m.Line=function(a,b,c){this.text=a;Ed(this,b);this.height=c?c(this):1};Ha(Ga);var Jd={},Jc=/[\t\u0000-\u0019\u00ad\u200b\u2028\u2029\uFEFF]/g;Mb.prototype={chunkSize:function(){return this.lines.length},removeInner:function(a,b){for(var c=a,d=a+b;c<d;++c){var e=this.lines[c];this.height-=e.height;var f=e;f.parent=null;Dd(f); M(e,"delete")}this.lines.splice(a,b)},collapse:function(a){a.splice.apply(a,[a.length,0].concat(this.lines))},insertInner:function(a,b,c){this.height+=c;this.lines=this.lines.slice(0,a).concat(b).concat(this.lines.slice(a));a=0;for(c=b.length;a<c;++a)b[a].parent=this},iterN:function(a,b,c){for(b=a+b;a<b;++a)if(c(this.lines[a]))return!0}};hb.prototype={chunkSize:function(){return this.size},removeInner:function(a,b){this.size-=b;for(var c=0;c<this.children.length;++c){var d=this.children[c],e=d.chunkSize(); if(a<e){var f=Math.min(b,e-a),g=d.height;d.removeInner(a,f);this.height-=g-d.height;e==f&&(this.children.splice(c--,1),d.parent=null);if(0==(b-=f))break;a=0}else a-=e}25>this.size-b&&(c=[],this.collapse(c),this.children=[new Mb(c)],this.children[0].parent=this)},collapse:function(a){for(var b=0,c=this.children.length;b<c;++b)this.children[b].collapse(a)},insertInner:function(a,b,c){this.size+=b.length;this.height+=c;for(var d=0,e=this.children.length;d<e;++d){var f=this.children[d],g=f.chunkSize(); if(a<=g){f.insertInner(a,b,c);if(f.lines&&50<f.lines.length){for(;50<f.lines.length;)a=f.lines.splice(f.lines.length-25,25),a=new Mb(a),f.height-=a.height,this.children.splice(d+1,0,a),a.parent=this;this.maybeSpill()}break}a-=g}},maybeSpill:function(){if(!(10>=this.children.length)){var a=this;do{var b=a.children.splice(a.children.length-5,5),b=new hb(b);if(a.parent){a.size-=b.size;a.height-=b.height;var c=ca(a.parent.children,a);a.parent.children.splice(c+1,0,b)}else c=new hb(a.children),c.parent= a,a.children=[c,b],a=c;b.parent=a.parent}while(10<a.children.length);a.parent.maybeSpill()}},iterN:function(a,b,c){for(var d=0,e=this.children.length;d<e;++d){var f=this.children[d],g=f.chunkSize();if(a<g){g=Math.min(b,g-a);if(f.iterN(a,g,c))return!0;if(0==(b-=g))break;a=0}else a-=g}}};var He=0,I=m.Doc=function(a,b,c){if(!(this instanceof I))return new I(a,b,c);null==c&&(c=0);hb.call(this,[new Mb([new Ga("",null)])]);this.first=c;this.scrollTop=this.scrollLeft=0;this.cantEdit=!1;this.history=Nb(); this.cleanGeneration=1;this.frontier=c;c=r(c,0);this.sel={from:c,to:c,head:c,anchor:c,shift:!1,extend:!1,goalColumn:null};this.id=++He;this.modeOption=b;"string"==typeof a&&(a=ka(a));Fc(this,{from:c,to:c,text:a},null,{head:c,anchor:c})};I.prototype=Pd(hb.prototype,{constructor:I,iter:function(a,b,c){c?this.iterN(a-this.first,b-a,c):this.iterN(this.first,this.first+this.size,a)},insert:function(a,b){for(var c=0,d=0,e=b.length;d<e;++d)c+=b[d].height;this.insertInner(a-this.first,b,c)},remove:function(a, b){this.removeInner(a-this.first,b)},getValue:function(a){var b=Kc(this,this.first,this.first+this.size);return!1===a?b:b.join(a||"\n")},setValue:function(a){var b=r(this.first,0),c=this.first+this.size-1;Ca(this,{from:b,to:r(c,u(this,c).text.length),text:ka(a),origin:"setValue"},{head:b,anchor:b},!0)},replaceRange:function(a,b,c,d){b=s(this,b);c=c?s(this,c):b;fa(this,a,b,c,d)},getRange:function(a,b,c){a=Ec(this,s(this,a),s(this,b));return!1===c?a:a.join(c||"\n")},getLine:function(a){return(a=this.getLineHandle(a))&& a.text},setLine:function(a,b){Fa(this,a)&&fa(this,b,r(a,0),s(this,r(a)))},removeLine:function(a){a?fa(this,"",s(this,r(a-1)),s(this,r(a))):fa(this,"",r(0,0),s(this,r(1,0)))},getLineHandle:function(a){if(Fa(this,a))return u(this,a)},getLineNumber:function(a){return P(a)},getLineHandleVisualStart:function(a){"number"==typeof a&&(a=u(this,a));return $(this,a)},lineCount:function(){return this.size},firstLine:function(){return this.first},lastLine:function(){return this.first+this.size-1},clipPos:function(a){return s(this, a)},getCursor:function(a){var b=this.sel;return ma(null==a||"head"==a?b.head:"anchor"==a?b.anchor:"end"==a||!1===a?b.to:b.from)},somethingSelected:function(){return!x(this.sel.head,this.sel.anchor)},setCursor:Ta(function(a,b,c){a=s(this,"number"==typeof a?r(a,b||0):a);c?F(this,a):ea(this,a,a)}),setSelection:Ta(function(a,b,c){ea(this,s(this,a),s(this,b||a),c)}),extendSelection:Ta(function(a,b,c){F(this,s(this,a),b&&s(this,b),c)}),getSelection:function(a){return this.getRange(this.sel.from,this.sel.to, a)},replaceSelection:function(a,b,c){Ca(this,{from:this.sel.from,to:this.sel.to,text:ka(a),origin:c},b||"around")},undo:Ta(function(){vd(this,"undo")}),redo:Ta(function(){vd(this,"redo")}),setExtending:function(a){this.sel.extend=a},historySize:function(){var a=this.history;return{undo:a.done.length,redo:a.undone.length}},clearHistory:function(){this.history=Nb(this.history.maxGeneration)},markClean:function(){this.cleanGeneration=this.changeGeneration()},changeGeneration:function(){this.history.lastOp= this.history.lastOrigin=null;return this.history.generation},isClean:function(a){return this.history.generation==(a||this.cleanGeneration)},getHistory:function(){return{done:Ob(this.history.done),undone:Ob(this.history.undone)}},setHistory:function(a){var b=this.history=Nb(this.history.maxGeneration);b.done=a.done.slice(0);b.undone=a.undone.slice(0)},markText:function(a,b,c){return eb(this,s(this,a),s(this,b),c,"range")},setBookmark:function(a,b){var c={replacedWith:b&&(null==b.nodeType?b.widget: b),insertLeft:b&&b.insertLeft};a=s(this,a);return eb(this,a,a,c,"bookmark")},findMarksAt:function(a){a=s(this,a);var b=[],c=u(this,a.line).markedSpans;if(c)for(var d=0;d<c.length;++d){var e=c[d];(null==e.from||e.from<=a.ch)&&(null==e.to||e.to>=a.ch)&&b.push(e.marker.parent||e.marker)}return b},getAllMarks:function(){var a=[];this.iter(function(b){if(b=b.markedSpans)for(var c=0;c<b.length;++c)null!=b[c].from&&a.push(b[c].marker)});return a},posFromIndex:function(a){var b,c=this.first;this.iter(function(d){d= d.text.length+1;if(d>a)return b=a,!0;a-=d;++c});return s(this,r(c,b))},indexFromPos:function(a){a=s(this,a);var b=a.ch;if(a.line<this.first||0>a.ch)return 0;this.iter(this.first,a.line,function(a){b+=a.text.length+1});return b},copy:function(a){var b=new I(Kc(this,this.first,this.first+this.size),this.modeOption,this.first);b.scrollTop=this.scrollTop;b.scrollLeft=this.scrollLeft;b.sel={from:this.sel.from,to:this.sel.to,head:this.sel.head,anchor:this.sel.anchor,shift:this.sel.shift,extend:!1,goalColumn:this.sel.goalColumn}; a&&(b.history.undoDepth=this.history.undoDepth,b.setHistory(this.getHistory()));return b},linkedDoc:function(a){a||(a={});var b=this.first,c=this.first+this.size;null!=a.from&&a.from>b&&(b=a.from);null!=a.to&&a.to<c&&(c=a.to);b=new I(Kc(this,b,c),a.mode||this.modeOption,b);a.sharedHist&&(b.history=this.history);(this.linked||(this.linked=[])).push({doc:b,sharedHist:a.sharedHist});b.linked=[{doc:this,isParent:!0,sharedHist:a.sharedHist}];return b},unlinkDoc:function(a){a instanceof m&&(a=a.doc);if(this.linked)for(var b= 0;b<this.linked.length;++b)if(this.linked[b].doc==a){this.linked.splice(b,1);a.unlinkDoc(this);break}if(a.history==this.history){var c=[a.id];Ea(a,function(a){c.push(a.id)},!0);a.history=Nb();a.history.done=Ob(this.history.done,c);a.history.undone=Ob(this.history.undone,c)}},iterLinkedDocs:function(a){Ea(this,a)},getMode:function(){return this.mode},getEditor:function(){return this.cm}});I.prototype.eachLine=I.prototype.iter;var Ie=["iter","insert","remove","copy","getEditor"],lb;for(lb in I.prototype)I.prototype.hasOwnProperty(lb)&& 0>ca(Ie,lb)&&(m.prototype[lb]=function(a){return function(){return a.apply(this.doc,arguments)}}(I.prototype[lb]));Ha(I);m.e_stop=Ya;m.e_preventDefault=A;m.e_stopPropagation=Od;var da,xb=0;m.on=v;m.off=aa;m.signal=J;var qa=30,kd=m.Pass={toString:function(){return"CodeMirror.Pass"}};Ub.prototype={set:function(a,b){clearTimeout(this.id);this.id=setTimeout(b,a)}};m.countColumn=xa;var Qb=[""],Ce=/[\u3040-\u309f\u30a0-\u30ff\u3400-\u4db5\u4e00-\u9fcc\uac00-\ud7af]/,pc=/[\u0300-\u036F\u0483-\u0487\u0488-\u0489\u0591-\u05BD\u05BF\u05C1-\u05C2\u05C4-\u05C5\u05C7\u0610-\u061A\u064B-\u065F\u0670\u06D6-\u06DC\u06DF-\u06E4\u06E7-\u06E8\u06EA-\u06ED\uA66F\uA670-\uA672\uA674-\uA67D\uA69F\udc00-\udfff]/; m.replaceGetRect=function(a){y=a};var qe=function(){if(Q)return!1;var a=p("div");return"draggable"in a||"dragDrop"in a}();Da?Lb=function(a,b){return 36==a.charCodeAt(b-1)&&39==a.charCodeAt(b)}:uc&&!/Version\/([6-9]|\d\d)\b/.test(navigator.userAgent)?Lb=function(a,b){return/\-[^ \-?]|\?[^ !\'\"\),.\-\/:;\?\]\}]/.test(a.slice(b-1,b+1))}:K&&!/Chrome\/(?:29|[3-9]\d|\d\d\d)\./.test(navigator.userAgent)&&(Lb=function(a,b){if(1<b&&45==a.charCodeAt(b-1)){if(/\w/.test(a.charAt(b-2))&&/[^\-?\.]/.test(a.charAt(b)))return!0; if(2<b&&/[\d\.,]/.test(a.charAt(b-2))&&/[\d\.,]/.test(a.charAt(b)))return!1}return/[~!#%&*)=+}\]|\"\.>,:;][({[<]|-[^\-?\.\u2010-\u201f\u2026]|\?[\w~`@#$%\^&*(_=+{[|><]|\u2026[\w~`@#$%\^&*(_=+{[><]/.test(a.slice(b-1,b+1))});var Wa,Lc,ka=3!="\n\nb".split(/\n/).length?function(a){for(var b=0,c=[],d=a.length;b<=d;){var e=a.indexOf("\n",b);-1==e&&(e=a.length);var f=a.slice(b,"\r"==a.charAt(e-1)?e-1:e),g=f.indexOf("\r");-1!=g?(c.push(f.slice(0,g)),b+=g+1):(c.push(f),b=e+1)}return c}:function(a){return a.split(/\r\n?|\n/)}; m.splitLines=ka;var le=window.getSelection?function(a){try{return a.selectionStart!=a.selectionEnd}catch(b){return!1}}:function(a){try{var b=a.ownerDocument.selection.createRange()}catch(c){}return b&&b.parentElement()==a?0!=b.compareEndPoints("StartToEnd",b):!1},cd=function(){var a=p("div");if("oncopy"in a)return!0;a.setAttribute("oncopy","return;");return"function"==typeof a.oncopy}(),na={3:"Enter",8:"Backspace",9:"Tab",13:"Enter",16:"Shift",17:"Ctrl",18:"Alt",19:"Pause",20:"CapsLock",27:"Esc", 32:"Space",33:"PageUp",34:"PageDown",35:"End",36:"Home",37:"Left",38:"Up",39:"Right",40:"Down",44:"PrintScrn",45:"Insert",46:"Delete",59:";",91:"Mod",92:"Mod",93:"Mod",109:"-",107:"=",127:"Delete",186:";",187:"=",188:",",189:"-",190:".",191:"/",192:"`",219:"[",220:"\\",221:"]",222:"'",63276:"PageUp",63277:"PageDown",63275:"End",63273:"Home",63234:"Left",63232:"Up",63235:"Right",63233:"Down",63302:"Insert",63272:"Delete"};m.keyNames=na;(function(){for(var a=0;10>a;a++)na[a+48]=String(a);for(a=65;90>= a;a++)na[a]=String.fromCharCode(a);for(a=1;12>=a;a++)na[a+111]=na[a+63235]="F"+a})();var ya,ze=function(){function a(a){return 255>=a?b.charAt(a):1424<=a&&1524>=a?"R":1536<=a&&1791>=a?c.charAt(a-1536):1792<=a&&2220>=a?"r":"L"}var b="bbbbbbbbbtstwsbbbbbbbbbbbbbbssstwNN%%%NNNNNN,N,N1111111111NNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNNNLLLLLLLLLLLLLLLLLLLLLLLLLLNNNNbbbbbbsbbbbbbbbbbbbbbbbbbbbbbbbbb,N%%%%NNNNLNNNNN%%11NLNNN1LNNNNNLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLNLLLLLLLL",c="rrrrrrrrrrrr,rNNmmmmmmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmrrrrrrrnnnnnnnnnn%nnrrrmrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrmmmmmmmmmmmmmmmmmmmNmmmmrrrrrrrrrrrrrrrrrr", d=/[\u0590-\u05f4\u0600-\u06ff\u0700-\u08ac]/,e=/[stwN]/,f=/[LRr]/,g=/[Lb1n]/,h=/[1n]/;return function(b){if(!d.test(b))return!1;for(var c=b.length,n=[],m=0,q;m<c;++m)n.push(a(b.charCodeAt(m)));for(var m=0,p="L";m<c;++m)q=n[m],"m"==q?n[m]=p:p=q;m=0;for(p="L";m<c;++m)q=n[m],"1"==q&&"r"==p?n[m]="n":f.test(q)&&(p=q,"r"==q&&(n[m]="R"));m=1;for(p=n[0];m<c-1;++m)q=n[m],"+"==q&&"1"==p&&"1"==n[m+1]?n[m]="1":","!=q||p!=n[m+1]||"1"!=p&&"n"!=p||(n[m]=p),p=q;for(m=0;m<c;++m)if(q=n[m],","==q)n[m]="N";else if("%"== q){for(p=m+1;p<c&&"%"==n[p];++p);var r=m&&"!"==n[m-1]||p<c-1&&"1"==n[p]?"1":"N";for(q=m;q<p;++q)n[q]=r;m=p-1}m=0;for(p="L";m<c;++m)q=n[m],"L"==p&&"1"==q?n[m]="L":f.test(q)&&(p=q);for(m=0;m<c;++m)if(e.test(n[m])){for(p=m+1;p<c&&e.test(n[p]);++p);q="L"==(p<c-1?n[p]:"L");r="L"==(m?n[m-1]:"L")||q?"L":"R";for(q=m;q<p;++q)n[q]=r;m=p-1}for(var p=[],s,m=0;m<c;)if(g.test(n[m])){q=m;for(++m;m<c&&g.test(n[m]);++m);p.push({from:q,to:m,level:0})}else{var t=m,r=p.length;for(++m;m<c&&"L"!=n[m];++m);for(q=t;q<m;)if(h.test(n[q])){t< q&&p.splice(r,0,{from:t,to:q,level:1});t=q;for(++q;q<m&&h.test(n[q]);++q);p.splice(r,0,{from:t,to:q,level:2});t=q}else++q;t<m&&p.splice(r,0,{from:t,to:m,level:1})}1==p[0].level&&(s=b.match(/^\s+/))&&(p[0].from=s[0].length,p.unshift({from:0,to:s[0].length,level:0}));1==L(p).level&&(s=b.match(/\s+$/))&&(L(p).to-=s[0].length,p.push({from:c-s[0].length,to:c,level:0}));p[0].level!=L(p).level&&p.push({from:c,to:c,level:p[0].level});return p}}();m.version="3.16.0";return m}();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
readme.txt CHANGED
@@ -3,7 +3,7 @@ Contributors: vasyl_m
3
  Tags: access manager, access, access control, comments, capability, widget, filter menu, role manager, user access, user control, user
4
  Requires at least: 3.4.2
5
  Tested up to: 3.8
6
- Stable tag: 2.0
7
 
8
  Graphic interface to manage User Access to your Front-end and Back-end
9
 
@@ -30,7 +30,8 @@ The AAM support also next languages:
30
  * English
31
  * German (by Kolja www.Reggae-Party.de)
32
  * Spanish (by Etruel www.netmdp.com)
33
-
 
34
 
35
  == Installation ==
36
 
@@ -58,10 +59,24 @@ the list of additional metaboxes can be picked by AAM.
58
 
59
  == Changelog ==
60
 
 
 
 
 
 
 
 
 
 
 
 
 
 
61
  = 2.0 =
62
  * New UI
63
  * Robust and completely new core functionality
64
  * Over 3 dozen of bug fixed and improvement during 3 alpha & beta versions
 
65
 
66
  = 1.9.1 =
67
  * Fixed bug with empty event list
3
  Tags: access manager, access, access control, comments, capability, widget, filter menu, role manager, user access, user control, user
4
  Requires at least: 3.4.2
5
  Tested up to: 3.8
6
+ Stable tag: 2.1
7
 
8
  Graphic interface to manage User Access to your Front-end and Back-end
9
 
30
  * English
31
  * German (by Kolja www.Reggae-Party.de)
32
  * Spanish (by Etruel www.netmdp.com)
33
+ * Polish (by Gustaw Lasek www.servitium.pl)
34
+ * French (by Moskito7)
35
 
36
  == Installation ==
37
 
59
 
60
  == Changelog ==
61
 
62
+ = 2.1 =
63
+ * Fixed issue with Admin Menu restrictions (thanks to MikeB2B)
64
+ * Added Polish Translation
65
+ * Fixed issue with Widgets restriction
66
+ * Improved internal User & Role handling
67
+ * Implemented caching mechanism
68
+ * Extended Update mechanism (remove the AAM cache after update)
69
+ * Added New ConfigPress setting aam.caching (by default is FALSE)
70
+ * Improved Metabox & Widgets filtering mechanism
71
+ * Added French Translation (by Moskito7)
72
+ * Added "My Feature" Tab
73
+ * Regenerated .pot file
74
+
75
  = 2.0 =
76
  * New UI
77
  * Robust and completely new core functionality
78
  * Over 3 dozen of bug fixed and improvement during 3 alpha & beta versions
79
+ * Improved Update mechanism
80
 
81
  = 1.9.1 =
82
  * Fixed bug with empty event list