Version Description
- Fixed invalid foreach statement for WP 3.4 in Theme editor
- Fixed invalid URL for images in root directory of themes
- Updated editor to keep line position when saving files
- Removed tab characters in all code and replaced with spaces
- Updated contextual help in the code editor pages
- Added ability to upload files in Theme/Plugin Editor
Download this release
Release Info
Developer | benjaminprojas |
Plugin | WP Editor |
Version | 1.0.2 |
Comparing to | |
See all releases |
Version 1.0.2
- classes/WPEditor.php +247 -0
- classes/WPEditorAdmin.php +86 -0
- classes/WPEditorAjax.php +119 -0
- classes/WPEditorBrowser.php +331 -0
- classes/WPEditorException.php +23 -0
- classes/WPEditorLog.php +61 -0
- classes/WPEditorPlugins.php +110 -0
- classes/WPEditorSetting.php +47 -0
- classes/WPEditorThemes.php +157 -0
- extensions/codemirror/codemirror.css +116 -0
- extensions/codemirror/dialog.css +23 -0
- extensions/codemirror/js/clike.js +249 -0
- extensions/codemirror/js/codemirror.js +2761 -0
- extensions/codemirror/js/css.js +124 -0
- extensions/codemirror/js/dialog.js +63 -0
- extensions/codemirror/js/foldcode.js +66 -0
- extensions/codemirror/js/htmlembedded.js +68 -0
- extensions/codemirror/js/htmlmixed.js +83 -0
- extensions/codemirror/js/javascript.js +360 -0
- extensions/codemirror/js/php.js +120 -0
- extensions/codemirror/js/search.js +114 -0
- extensions/codemirror/js/searchcursor.js +117 -0
- extensions/codemirror/js/xml.js +252 -0
- extensions/codemirror/theme/cobalt.css +18 -0
- extensions/codemirror/theme/eclipse.css +25 -0
- extensions/codemirror/theme/elegant.css +10 -0
- extensions/codemirror/theme/monokai.css +28 -0
- extensions/codemirror/theme/neat.css +9 -0
- extensions/codemirror/theme/night.css +21 -0
- extensions/codemirror/theme/rubyblue.css +21 -0
- extensions/codemirror/themes/cobalt.css +18 -0
- extensions/codemirror/themes/eclipse.css +25 -0
- extensions/codemirror/themes/elegant.css +10 -0
- extensions/codemirror/themes/monokai.css +28 -0
- extensions/codemirror/themes/neat.css +9 -0
- extensions/codemirror/themes/night.css +21 -0
- extensions/codemirror/themes/rubyblue.css +21 -0
- extensions/fancybox/images/blank.gif +0 -0
- extensions/fancybox/images/fancy_close.png +0 -0
- extensions/fancybox/images/fancy_loading.png +0 -0
- extensions/fancybox/images/fancy_nav_left.png +0 -0
- extensions/fancybox/images/fancy_nav_right.png +0 -0
- extensions/fancybox/images/fancy_shadow_e.png +0 -0
- extensions/fancybox/images/fancy_shadow_n.png +0 -0
- extensions/fancybox/images/fancy_shadow_ne.png +0 -0
- extensions/fancybox/images/fancy_shadow_nw.png +0 -0
- extensions/fancybox/images/fancy_shadow_s.png +0 -0
- extensions/fancybox/images/fancy_shadow_se.png +0 -0
- extensions/fancybox/images/fancy_shadow_sw.png +0 -0
- extensions/fancybox/images/fancy_shadow_w.png +0 -0
- extensions/fancybox/images/fancy_title_left.png +0 -0
- extensions/fancybox/images/fancy_title_main.png +0 -0
- extensions/fancybox/images/fancy_title_over.png +0 -0
- extensions/fancybox/images/fancy_title_right.png +0 -0
- extensions/fancybox/images/fancybox-x.png +0 -0
- extensions/fancybox/images/fancybox-y.png +0 -0
- extensions/fancybox/images/fancybox.png +0 -0
- extensions/fancybox/jquery.fancybox-1.3.4.css +359 -0
- extensions/fancybox/js/jquery.fancybox-1.3.4.pack.js +46 -0
- images/css.png +0 -0
- images/folder.png +0 -0
- images/gif.png +0 -0
- images/htm.png +0 -0
- images/html.png +0 -0
- images/jpeg.png +0 -0
- images/jpg.png +0 -0
- images/js.png +0 -0
- images/loader.gif +0 -0
- images/php.png +0 -0
- images/png.png +0 -0
- images/po.png +0 -0
- images/pot.png +0 -0
- images/sql.png +0 -0
- images/txt.png +0 -0
- images/wpeditor_logo_16.png +0 -0
- images/wpeditor_logo_32.png +0 -0
- js/wpeditor.js +345 -0
- log.txt +0 -0
- readme.txt +49 -0
- sql/database.sql +5 -0
- sql/uninstall.sql +1 -0
- uninstall.php +21 -0
- views/plugin-editor.php +225 -0
- views/settings.php +542 -0
- views/theme-editor.php +233 -0
- wpeditor.css +290 -0
- wpeditor.php +86 -0
classes/WPEditor.php
ADDED
@@ -0,0 +1,247 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPEditor {
|
3 |
+
|
4 |
+
public function install() {
|
5 |
+
|
6 |
+
global $wpdb;
|
7 |
+
$prefix = $this->getTablePrefix();
|
8 |
+
$sqlFile = WPEDITOR_PATH . 'sql/database.sql';
|
9 |
+
$sql = str_replace('[prefix]', $prefix, file_get_contents($sqlFile));
|
10 |
+
$queries = explode(";\n", $sql);
|
11 |
+
$wpdb->hide_errors();
|
12 |
+
foreach($queries as $sql) {
|
13 |
+
if(strlen($sql) > 5) {
|
14 |
+
$wpdb->query($sql);
|
15 |
+
}
|
16 |
+
}
|
17 |
+
|
18 |
+
// Set the version number for this version of WPEditor
|
19 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorSetting.php');
|
20 |
+
WPEditorSetting::setValue('version', WPEDITOR_VERSION_NUMBER);
|
21 |
+
|
22 |
+
if(!WPEditorSetting::getValue('upgrade')) {
|
23 |
+
$this->firstInstall();
|
24 |
+
}
|
25 |
+
|
26 |
+
}
|
27 |
+
|
28 |
+
public function firstInstall() {
|
29 |
+
|
30 |
+
// Set the database to upgrade instead of first time install
|
31 |
+
WPEditorSetting::setValue('upgrade', 1);
|
32 |
+
|
33 |
+
// Check if the plugin and theme editors have been hidden before and hide them if not
|
34 |
+
if(!WPEditorSetting::getValue('hide_default_plugin_editor')) {
|
35 |
+
WPEditorSetting::setValue('hide_default_plugin_editor', 1);
|
36 |
+
}
|
37 |
+
if(!WPEditorSetting::getValue('hide_default_theme_editor')) {
|
38 |
+
WPEditorSetting::setValue('hide_default_theme_editor', 1);
|
39 |
+
}
|
40 |
+
|
41 |
+
// Check if the edit link for plugins has been hidden before and hide if not
|
42 |
+
if(!WPEditorSetting::getValue('replace_plugin_edit_links')) {
|
43 |
+
WPEditorSetting::setValue('replace_plugin_edit_links', 1);
|
44 |
+
}
|
45 |
+
|
46 |
+
// Check if the plugin line numbers have been disabled and enable if not
|
47 |
+
if(!WPEditorSetting::getValue('enable_plugin_line_numbers')) {
|
48 |
+
WPEditorSetting::setValue('enable_plugin_line_numbers', 1);
|
49 |
+
}
|
50 |
+
|
51 |
+
// Check if the theme line numbers have been disabled and enable if not
|
52 |
+
if(!WPEditorSetting::getValue('enable_theme_line_numbers')) {
|
53 |
+
WPEditorSetting::setValue('enable_theme_line_numbers', 1);
|
54 |
+
}
|
55 |
+
|
56 |
+
// Check if plugin line wrapping has been disabled and enable if not
|
57 |
+
if(!WPEditorSetting::getValue('enable_plugin_line_wrapping')) {
|
58 |
+
WPEditorSetting::setValue('enable_plugin_line_wrapping', 1);
|
59 |
+
}
|
60 |
+
|
61 |
+
// Check if theme line wrapping has been disabled and enable if not
|
62 |
+
if(!WPEditorSetting::getValue('enable_theme_line_wrapping')) {
|
63 |
+
WPEditorSetting::setValue('enable_theme_line_wrapping', 1);
|
64 |
+
}
|
65 |
+
|
66 |
+
// Check if plugin active line highlighting has been disabled and enable if not
|
67 |
+
if(!WPEditorSetting::getValue('enable_plugin_active_line')) {
|
68 |
+
WPEditorSetting::setValue('enable_plugin_active_line', 1);
|
69 |
+
}
|
70 |
+
|
71 |
+
// Check if theme active line highlighting has been disabled and enable if not
|
72 |
+
if(!WPEditorSetting::getValue('enable_theme_active_line')) {
|
73 |
+
WPEditorSetting::setValue('enable_theme_active_line', 1);
|
74 |
+
}
|
75 |
+
|
76 |
+
// Check if the default allowed extensions for the plugin editor have been set and set if not
|
77 |
+
if(!WPEditorSetting::getValue('plugin_editor_allowed_extensions')) {
|
78 |
+
WPEditorSetting::setValue('plugin_editor_allowed_extensions', 'php~js~css~txt~htm~html~jpg~jpeg~png~gif~sql~po');
|
79 |
+
}
|
80 |
+
|
81 |
+
// Check if the default allowed extensions for the theme editor have been set and set if not
|
82 |
+
if(!WPEditorSetting::getValue('theme_editor_allowed_extensions')) {
|
83 |
+
WPEditorSetting::setValue('theme_editor_allowed_extensions', 'php~js~css~txt~htm~html~jpg~jpeg~png~gif~sql~po');
|
84 |
+
}
|
85 |
+
|
86 |
+
// Check if the upload plugin file option has been set and set if not
|
87 |
+
if(!WPEditorSetting::getValue('plugin_file_upload')) {
|
88 |
+
WPEditorSetting::setValue('plugin_file_upload', 1);
|
89 |
+
}
|
90 |
+
|
91 |
+
// Check if the upload theme file option has been set and set if not
|
92 |
+
if(!WPEditorSetting::getValue('theme_file_upload')) {
|
93 |
+
WPEditorSetting::setValue('theme_file_upload', 1);
|
94 |
+
}
|
95 |
+
|
96 |
+
}
|
97 |
+
|
98 |
+
public function init() {
|
99 |
+
// Load all additional required classes
|
100 |
+
$this->loadCoreModels();
|
101 |
+
|
102 |
+
// Verify that upgrade has been run
|
103 |
+
if(IS_ADMIN) {
|
104 |
+
if(version_compare(WPEDITOR_VERSION_NUMBER, WPEditorSetting::getValue('version'))) {
|
105 |
+
$this->install();
|
106 |
+
}
|
107 |
+
}
|
108 |
+
|
109 |
+
// Define debugging and testing info
|
110 |
+
$wpeditor_logging = WPEditorSetting::getValue('wpeditor_logging') ? true : false;
|
111 |
+
define('WPEDITOR_DEBUG', $wpeditor_logging);
|
112 |
+
|
113 |
+
$default_wpeditor_roles = array(
|
114 |
+
'settings' => 'manage_options',
|
115 |
+
'theme-editor' => 'edit_themes',
|
116 |
+
'plugin-editor' => 'edit_plugins'
|
117 |
+
);
|
118 |
+
// Set default admin page roles if there isn't any
|
119 |
+
$wpeditor_roles = WPEditorSetting::getValue('admin_page_roles');
|
120 |
+
if(empty($wpeditor_roles)){
|
121 |
+
WPEditorSetting::setValue('admin_page_roles',serialize($default_wpeditor_roles));
|
122 |
+
}
|
123 |
+
// Ensure that all admin page roles have been set.
|
124 |
+
else {
|
125 |
+
$update_roles = false;
|
126 |
+
$wpeditor_roles = unserialize($wpeditor_roles);
|
127 |
+
foreach($default_wpeditor_roles as $key => $value) {
|
128 |
+
if(!array_key_exists($key, $wpeditor_roles)) {
|
129 |
+
$wpeditor_roles[$key] = $value;
|
130 |
+
$update_roles = true;
|
131 |
+
}
|
132 |
+
}
|
133 |
+
if($update_roles) {
|
134 |
+
WPEditorSetting::setValue('admin_page_roles',serialize($wpeditor_roles));
|
135 |
+
}
|
136 |
+
$wpeditor_roles = serialize($wpeditor_roles);
|
137 |
+
}
|
138 |
+
|
139 |
+
if(IS_ADMIN) {
|
140 |
+
// Load default stylesheet
|
141 |
+
add_action('admin_init', array($this, 'registerDefaultStylesheet'));
|
142 |
+
// Load default script
|
143 |
+
add_action('admin_init', array($this, 'registerDefaultScript'));
|
144 |
+
|
145 |
+
// Remove default editor submenus
|
146 |
+
add_action('admin_menu', array('WPEditorAdmin', 'removeDefaultEditorMenus'));
|
147 |
+
// Add WP Editor Settings Page
|
148 |
+
add_action('admin_menu', array('WPEditorAdmin', 'buildAdminMenu'));
|
149 |
+
|
150 |
+
// Add Plugin Editor Page
|
151 |
+
add_action('admin_menu', array('WPEditorAdmin', 'addPluginsPage'));
|
152 |
+
// Add Theme Editor Page
|
153 |
+
add_action('admin_menu', array('WPEditorAdmin', 'addThemesPage'));
|
154 |
+
|
155 |
+
// Ajax request to save settings
|
156 |
+
add_action('wp_ajax_save_wpeditor_settings', array('WPEditorAjax', 'saveSettings'));
|
157 |
+
|
158 |
+
// Ajax request to save files
|
159 |
+
add_action('wp_ajax_save_files', array('WPEditorAjax', 'saveFile'));
|
160 |
+
|
161 |
+
// Ajax request to upload files
|
162 |
+
add_action('wp_ajax_upload_files', array('WPEditorAjax', 'uploadFile'));
|
163 |
+
|
164 |
+
// Ajax request to retrieve files and folders
|
165 |
+
add_action('wp_ajax_ajax_folders', array('WPEditorAjax', 'ajaxFolders'));
|
166 |
+
|
167 |
+
// Replace default plugin edit links
|
168 |
+
add_filter('plugin_action_links', array($this, 'replacePluginEditLinks'),9,1);
|
169 |
+
|
170 |
+
}
|
171 |
+
}
|
172 |
+
|
173 |
+
public function loadCoreModels() {
|
174 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorAdmin.php');
|
175 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorAjax.php');
|
176 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorBrowser.php');
|
177 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorException.php');
|
178 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorLog.php');
|
179 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorPlugins.php');
|
180 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorSetting.php');
|
181 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorThemes.php');
|
182 |
+
}
|
183 |
+
|
184 |
+
public function registerDefaultStylesheet() {
|
185 |
+
wp_register_style('wpeditor', WPEDITOR_URL . '/wpeditor.css');
|
186 |
+
wp_register_style('fancybox', WPEDITOR_URL . '/extensions/fancybox/jquery.fancybox-1.3.4.css');
|
187 |
+
wp_register_style('codemirror', WPEDITOR_URL . '/extensions/codemirror/codemirror.css');
|
188 |
+
wp_register_style('codemirror_dialog', WPEDITOR_URL . '/extensions/codemirror/dialog.css');
|
189 |
+
wp_register_style('codemirror_theme_cobalt', WPEDITOR_URL . '/extensions/codemirror/themes/cobalt.css');
|
190 |
+
wp_register_style('codemirror_theme_eclipse', WPEDITOR_URL . '/extensions/codemirror/themes/eclipse.css');
|
191 |
+
wp_register_style('codemirror_theme_elegant', WPEDITOR_URL . '/extensions/codemirror/themes/elegant.css');
|
192 |
+
wp_register_style('codemirror_theme_monokai', WPEDITOR_URL . '/extensions/codemirror/themes/monokai.css');
|
193 |
+
wp_register_style('codemirror_theme_neat', WPEDITOR_URL . '/extensions/codemirror/themes/neat.css');
|
194 |
+
wp_register_style('codemirror_theme_night', WPEDITOR_URL . '/extensions/codemirror/themes/night.css');
|
195 |
+
wp_register_style('codemirror_theme_rubyblue', WPEDITOR_URL . '/extensions/codemirror/themes/rubyblue.css');
|
196 |
+
}
|
197 |
+
|
198 |
+
public function registerDefaultScript() {
|
199 |
+
wp_register_script('wpeditor', WPEDITOR_URL . '/js/wpeditor.js');
|
200 |
+
wp_register_script('fancybox', WPEDITOR_URL . '/extensions/fancybox/js/jquery.fancybox-1.3.4.pack.js');
|
201 |
+
wp_register_script('codemirror', WPEDITOR_URL . '/extensions/codemirror/js/codemirror.js');
|
202 |
+
wp_register_script('codemirror_php', WPEDITOR_URL . '/extensions/codemirror/js/php.js');
|
203 |
+
wp_register_script('codemirror_javascript', WPEDITOR_URL . '/extensions/codemirror/js/javascript.js');
|
204 |
+
wp_register_script('codemirror_css', WPEDITOR_URL . '/extensions/codemirror/js/css.js');
|
205 |
+
wp_register_script('codemirror_xml', WPEDITOR_URL . '/extensions/codemirror/js/xml.js');
|
206 |
+
wp_register_script('codemirror_clike', WPEDITOR_URL . '/extensions/codemirror/js/clike.js');
|
207 |
+
wp_register_script('codemirror_dialog', WPEDITOR_URL . '/extensions/codemirror/js/dialog.js');
|
208 |
+
wp_register_script('codemirror_search', WPEDITOR_URL . '/extensions/codemirror/js/search.js');
|
209 |
+
wp_register_script('codemirror_searchcursor', WPEDITOR_URL . '/extensions/codemirror/js/searchcursor.js');
|
210 |
+
//wp_register_script('codemirror_foldcode', WPEDITOR_URL . '/extensions/codemirror/js/foldcode.js');
|
211 |
+
}
|
212 |
+
|
213 |
+
public static function getView($filename, $data=null) {
|
214 |
+
$filename = WPEDITOR_PATH . "/$filename";
|
215 |
+
ob_start();
|
216 |
+
include $filename;
|
217 |
+
$contents = ob_get_contents();
|
218 |
+
ob_end_clean();
|
219 |
+
return $contents;
|
220 |
+
}
|
221 |
+
|
222 |
+
public static function getTableName($name){
|
223 |
+
return WPEditor::getTablePrefix() . $name;
|
224 |
+
}
|
225 |
+
|
226 |
+
public static function getTablePrefix(){
|
227 |
+
global $wpdb;
|
228 |
+
return $wpdb->prefix . 'wpeditor_';
|
229 |
+
}
|
230 |
+
|
231 |
+
public static function replacePluginEditLinks($links) {
|
232 |
+
$data = '';
|
233 |
+
if(WPEditorSetting::getValue('replace_plugin_edit_links') == 1) {
|
234 |
+
foreach($links as $key => $value) {
|
235 |
+
if($key === 'edit') {
|
236 |
+
$value = str_replace('plugin-editor.php?', 'plugins.php?page=wpeditor_plugin&', $value);
|
237 |
+
}
|
238 |
+
$data[$key] = $value;
|
239 |
+
}
|
240 |
+
}
|
241 |
+
else {
|
242 |
+
$data = $links;
|
243 |
+
}
|
244 |
+
return $data;
|
245 |
+
}
|
246 |
+
|
247 |
+
}
|
classes/WPEditorAdmin.php
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPEditorAdmin {
|
3 |
+
|
4 |
+
public function buildAdminMenu() {
|
5 |
+
$icon = WPEDITOR_URL . '/images/wpeditor_logo_16.png';
|
6 |
+
$page_roles = WPEditorSetting::getValue('admin_page_roles');
|
7 |
+
$page_roles = unserialize($page_roles);
|
8 |
+
|
9 |
+
$settings = add_menu_page(__('WP Editor Settings', 'wpeditor'), __('WP Editor', 'wpeditor'), $page_roles['settings'], 'wpeditor_admin', array('WPEditorAdmin', 'addSettingsPage'), $icon);
|
10 |
+
//add_submenu_page('wpeditor_admin', __('Sub Menu', 'wpeditor'), __('Orders', 'wpeditor'), $page_roles['orders'], 'wpeditor_admin', array('WPEditorAdmin', 'subMenuPage'));
|
11 |
+
add_action('admin_print_styles-' . $settings, array('WPEditorAdmin', 'defaultStylesheetAndScript'));
|
12 |
+
}
|
13 |
+
|
14 |
+
public static function addPluginsPage() {
|
15 |
+
global $wpeditor_plugin;
|
16 |
+
|
17 |
+
$page_title = __('Plugin Editor', 'wpeditor');
|
18 |
+
$menu_title = __('Plugin Editor', 'wpeditor');
|
19 |
+
$capability = 'edit_plugins';
|
20 |
+
$menu_slug = 'wpeditor_plugin';
|
21 |
+
$wpeditor_plugin = add_plugins_page($page_title, $menu_title, $capability, $menu_slug, array('WPEditorPlugins', 'addPluginsPage'));
|
22 |
+
add_action("load-$wpeditor_plugin", array('WPEditorPlugins', 'pluginsHelpTab'));
|
23 |
+
add_action('admin_print_styles', array('WPEditorAdmin', 'editorStylesheetAndScripts'));
|
24 |
+
}
|
25 |
+
|
26 |
+
public function addThemesPage() {
|
27 |
+
global $wpeditor_themes;
|
28 |
+
|
29 |
+
$page_title = __('Theme Editor', 'wpeditor');
|
30 |
+
$menu_title = __('Theme Editor', 'wpeditor');
|
31 |
+
$capability = 'edit_themes';
|
32 |
+
$menu_slug = 'wpeditor_themes';
|
33 |
+
$wpeditor_themes = add_theme_page($page_title, $menu_title, $capability, $menu_slug, array('WPEditorThemes', 'addThemesPage'));
|
34 |
+
|
35 |
+
add_action("load-$wpeditor_themes", array('WPEditorThemes', 'themesHelpTab'));
|
36 |
+
add_action('admin_print_styles', array('WPEditorAdmin', 'editorStylesheetAndScripts'));
|
37 |
+
}
|
38 |
+
|
39 |
+
public function addSettingsPage() {
|
40 |
+
$view = WPEditor::getView('views/settings.php');
|
41 |
+
echo $view;
|
42 |
+
}
|
43 |
+
|
44 |
+
public function editorStylesheetAndScripts() {
|
45 |
+
wp_enqueue_style('wpeditor');
|
46 |
+
wp_enqueue_script('wpeditor');
|
47 |
+
wp_enqueue_style('fancybox');
|
48 |
+
wp_enqueue_script('fancybox');
|
49 |
+
wp_enqueue_style('codemirror');
|
50 |
+
wp_enqueue_style('codemirror_dialog');
|
51 |
+
wp_enqueue_style('codemirror_theme_cobalt');
|
52 |
+
wp_enqueue_style('codemirror_theme_eclipse');
|
53 |
+
wp_enqueue_style('codemirror_theme_elegant');
|
54 |
+
wp_enqueue_style('codemirror_theme_monokai');
|
55 |
+
wp_enqueue_style('codemirror_theme_neat');
|
56 |
+
wp_enqueue_style('codemirror_theme_night');
|
57 |
+
wp_enqueue_style('codemirror_theme_rubyblue');
|
58 |
+
wp_enqueue_script('codemirror');
|
59 |
+
wp_enqueue_script('codemirror_php');
|
60 |
+
wp_enqueue_script('codemirror_javascript');
|
61 |
+
wp_enqueue_script('codemirror_css');
|
62 |
+
wp_enqueue_script('codemirror_xml');
|
63 |
+
wp_enqueue_script('codemirror_clike');
|
64 |
+
wp_enqueue_script('codemirror_dialog');
|
65 |
+
wp_enqueue_script('codemirror_search');
|
66 |
+
wp_enqueue_script('codemirror_searchcursor');
|
67 |
+
}
|
68 |
+
|
69 |
+
public function defaultStylesheetAndScript() {
|
70 |
+
wp_enqueue_style('wpeditor');
|
71 |
+
wp_enqueue_script('wpeditor');
|
72 |
+
}
|
73 |
+
|
74 |
+
public function removeDefaultEditorMenus() {
|
75 |
+
// Remove default plugin editor
|
76 |
+
if(WPEditorSetting::getValue('hide_default_plugin_editor') == 1) {
|
77 |
+
global $submenu;
|
78 |
+
unset($submenu['plugins.php'][15]);
|
79 |
+
}
|
80 |
+
if(WPEditorSetting::getValue('hide_default_theme_editor') == 1) {
|
81 |
+
// Remove default themes editor
|
82 |
+
remove_action('admin_menu', '_add_themes_utility_last', 101);
|
83 |
+
}
|
84 |
+
}
|
85 |
+
|
86 |
+
}
|
classes/WPEditorAjax.php
ADDED
@@ -0,0 +1,119 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPEditorAjax {
|
3 |
+
|
4 |
+
public static function saveSettings() {
|
5 |
+
$error = '';
|
6 |
+
|
7 |
+
foreach($_REQUEST as $key => $value) {
|
8 |
+
if($key[0] != '_' && $key != 'action' && $key != 'submit') {
|
9 |
+
if(is_array($value)) {
|
10 |
+
$value = implode('~', $value);
|
11 |
+
}
|
12 |
+
if($key == 'wpeditor_logging' && $value == '1') {
|
13 |
+
try {
|
14 |
+
WPEditorLog::createLogFile();
|
15 |
+
}
|
16 |
+
catch(WPEditorException $e) {
|
17 |
+
$error = $e->getMessage();
|
18 |
+
WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Caught WPEditor exception: " . $e->getMessage());
|
19 |
+
}
|
20 |
+
}
|
21 |
+
WPEditorSetting::setValue($key, trim(stripslashes($value)));
|
22 |
+
}
|
23 |
+
}
|
24 |
+
|
25 |
+
if(isset($_REQUEST['_tab'])) {
|
26 |
+
WPEditorSetting::setValue('settings_tab', $_REQUEST['_tab']);
|
27 |
+
}
|
28 |
+
|
29 |
+
if($error) {
|
30 |
+
$result[0] = 'WPEditorAjaxError';
|
31 |
+
$result[1] = '<h3>' . __('Warning','wpeditor') . "</h3><p>$error</p>";
|
32 |
+
}
|
33 |
+
else {
|
34 |
+
$result[0] = 'WPEditorAjaxSuccess';
|
35 |
+
$result[1] = '<h3>' . __('Success', 'wpeditor') . '</h3><p>' . $_REQUEST['_success'] . '</p>';
|
36 |
+
}
|
37 |
+
|
38 |
+
$out = json_encode($result);
|
39 |
+
echo $out;
|
40 |
+
die();
|
41 |
+
}
|
42 |
+
|
43 |
+
public static function uploadFile() {
|
44 |
+
$upload = '';
|
45 |
+
if(isset($_POST['current_theme_root'])){
|
46 |
+
$upload = WPEditorBrowser::uploadThemeFiles();
|
47 |
+
}
|
48 |
+
elseif(isset($_POST['current_plugin_root'])) {
|
49 |
+
$upload = WPEditorBrowser::uploadPluginFiles();
|
50 |
+
}
|
51 |
+
echo json_encode($upload);
|
52 |
+
die();
|
53 |
+
}
|
54 |
+
|
55 |
+
public static function saveFile() {
|
56 |
+
$error = '';
|
57 |
+
try {
|
58 |
+
if(isset($_POST['new_content']) && isset($_POST['real_file'])) {
|
59 |
+
$real_file = $_POST['real_file'];
|
60 |
+
if(file_exists($real_file) && is_writeable($real_file)) {
|
61 |
+
$new_content = stripslashes($_POST['new_content']);
|
62 |
+
if(file_get_contents($real_file) === $new_content) {
|
63 |
+
WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Contents are the same");
|
64 |
+
}
|
65 |
+
else {
|
66 |
+
$f = fopen($real_file, 'w+');
|
67 |
+
fwrite($f, $new_content);
|
68 |
+
fclose($f);
|
69 |
+
WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] just wrote to $real_file");
|
70 |
+
}
|
71 |
+
}
|
72 |
+
}
|
73 |
+
else {
|
74 |
+
$error = 'Invalid Content';
|
75 |
+
}
|
76 |
+
}
|
77 |
+
catch(WPEditorException $e) {
|
78 |
+
$error = $e->getMessage();
|
79 |
+
WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Caught WPEditor exception: " . $e->getMessage());
|
80 |
+
}
|
81 |
+
|
82 |
+
if($error) {
|
83 |
+
$result[0] = 'WPEditorAjaxError';
|
84 |
+
$result[1] = '<h3>' . __('Warning','wpeditor') . "</h3><p>$error</p>";
|
85 |
+
}
|
86 |
+
else {
|
87 |
+
$result[0] = 'WPEditorAjaxSuccess';
|
88 |
+
$result[1] = '<h3>' . __('Success', 'wpeditor') . '</h3><p>' . $_REQUEST['_success'] . '</p>';
|
89 |
+
}
|
90 |
+
|
91 |
+
if(isset($_POST['extension'])) {
|
92 |
+
$result[2] = $_POST['extension'];
|
93 |
+
}
|
94 |
+
|
95 |
+
$out = json_encode($result);
|
96 |
+
echo $out;
|
97 |
+
die();
|
98 |
+
}
|
99 |
+
|
100 |
+
public static function ajaxFolders() {
|
101 |
+
|
102 |
+
$dir = urldecode($_REQUEST['dir']);
|
103 |
+
|
104 |
+
if(isset($_REQUEST['contents'])) {
|
105 |
+
$contents = $_REQUEST['contents'];
|
106 |
+
}
|
107 |
+
else {
|
108 |
+
$contents = 0;
|
109 |
+
}
|
110 |
+
$type = null;
|
111 |
+
if(isset($_REQUEST['type'])) {
|
112 |
+
$type = $_REQUEST['type'];
|
113 |
+
}
|
114 |
+
$out = json_encode(WPEditorBrowser::getFilesAndFolders($dir, $contents, $type));
|
115 |
+
echo $out;
|
116 |
+
die();
|
117 |
+
}
|
118 |
+
|
119 |
+
}
|
classes/WPEditorBrowser.php
ADDED
@@ -0,0 +1,331 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPEditorBrowser {
|
3 |
+
|
4 |
+
public static function getFilesAndFolders($dir, $contents, $type) {
|
5 |
+
$slash = '/';
|
6 |
+
if(WPWINDOWS) {
|
7 |
+
$slash = '\\';
|
8 |
+
}
|
9 |
+
$output = array();
|
10 |
+
if(is_dir($dir)) {
|
11 |
+
if($handle = opendir($dir)) {
|
12 |
+
$size_document_root = strlen($_SERVER['DOCUMENT_ROOT']);
|
13 |
+
$pos = strrpos($dir, $slash);
|
14 |
+
$topdir = substr($dir, 0, $pos + 1);
|
15 |
+
$i = 0;
|
16 |
+
while(false !== ($file = readdir($handle))) {
|
17 |
+
if($file != '.' && $file != '..' && substr($file, 0, 1) != '.' && WPEditorBrowser::allowedFiles($dir, $file)) {
|
18 |
+
$rows[$i]['data'] = $file;
|
19 |
+
$rows[$i]['dir'] = is_dir($dir . $slash . $file);
|
20 |
+
$i++;
|
21 |
+
}
|
22 |
+
}
|
23 |
+
closedir($handle);
|
24 |
+
}
|
25 |
+
|
26 |
+
if(isset($rows)) {
|
27 |
+
$size = count($rows);
|
28 |
+
$rows = self::sortRows($rows);
|
29 |
+
for($i = 0; $i < $size; ++$i) {
|
30 |
+
$topdir = $dir . $slash . $rows[$i]['data'];
|
31 |
+
$output[$i]['name'] = $rows[$i]['data'];
|
32 |
+
$output[$i]['path'] = $topdir;
|
33 |
+
if($rows[$i]['dir']) {
|
34 |
+
$output[$i]['filetype'] = 'folder';
|
35 |
+
$output[$i]['extension'] = 'folder';
|
36 |
+
$output[$i]['filesize'] = '';
|
37 |
+
}
|
38 |
+
else {
|
39 |
+
$output[$i]['filetype'] = 'file';
|
40 |
+
$path = pathinfo($output[$i]['name']);
|
41 |
+
if(isset($path['extension'])) {
|
42 |
+
$output[$i]['extension'] = $path['extension'];
|
43 |
+
}
|
44 |
+
$output[$i]['filesize'] = '(' . round(filesize($topdir) * .0009765625, 2) . ' KB)';
|
45 |
+
if($type == 'theme') {
|
46 |
+
$output[$i]['file'] = str_replace(realpath(get_theme_root()) . $slash, '', $output[$i]['path']);
|
47 |
+
$output[$i]['url'] = get_theme_root_uri() . $slash . $output[$i]['file'];
|
48 |
+
}
|
49 |
+
else {
|
50 |
+
$output[$i]['file'] = str_replace(realpath(WP_PLUGIN_DIR) . $slash, '', $output[$i]['path']);
|
51 |
+
$output[$i]['url'] = plugins_url() . $slash . $output[$i]['file'];
|
52 |
+
}
|
53 |
+
}
|
54 |
+
}
|
55 |
+
}
|
56 |
+
else {
|
57 |
+
$output[-1] = 'this folder has no contents';
|
58 |
+
}
|
59 |
+
}
|
60 |
+
elseif(is_file($dir)) {
|
61 |
+
if(isset($contents) && $contents == 1) {
|
62 |
+
$output['name'] = basename($dir);
|
63 |
+
$output['path'] = $dir;
|
64 |
+
$output['filetype'] = 'file';
|
65 |
+
$path = pathinfo($output['name']);
|
66 |
+
if(isset($path['extension'])) {
|
67 |
+
$output['extension'] = $path['extension'];
|
68 |
+
}
|
69 |
+
$output['content'] = file_get_contents($dir);
|
70 |
+
if($type == 'theme') {
|
71 |
+
$output['file'] = str_replace(realpath(get_theme_root()) . $slash, '', $output['path']);
|
72 |
+
$output['url'] = get_theme_root_uri() . $slash . $output['file'];
|
73 |
+
}
|
74 |
+
else {
|
75 |
+
$output['file'] = str_replace(realpath(WP_PLUGIN_DIR) . $slash, '', $output['path']);
|
76 |
+
$output['url'] = plugins_url() . $slash . $output['file'];
|
77 |
+
}
|
78 |
+
}
|
79 |
+
else {
|
80 |
+
$pos = strrpos($dir, $slash);
|
81 |
+
$newdir = substr($dir, 0, $pos);
|
82 |
+
if($handle = opendir($newdir)) {
|
83 |
+
$size_document_root = strlen($_SERVER['DOCUMENT_ROOT']);
|
84 |
+
$pos = strrpos($newdir, $slash);
|
85 |
+
$topdir = substr($newdir, 0, $pos + 1);
|
86 |
+
$i = 0;
|
87 |
+
while(false !== ($file = readdir($handle))) {
|
88 |
+
if($file != '.' && $file != '..' && substr($file, 0, 1) != '.' && WPEditorBrowser::allowedFiles($newdir, $file)) {
|
89 |
+
$rows[$i]['data'] = $file;
|
90 |
+
$rows[$i]['dir'] = is_dir($newdir . $slash . $file);
|
91 |
+
$i++;
|
92 |
+
}
|
93 |
+
}
|
94 |
+
closedir($handle);
|
95 |
+
}
|
96 |
+
|
97 |
+
if(isset($rows)) {
|
98 |
+
$size = count($rows);
|
99 |
+
$rows = self::sortRows($rows);
|
100 |
+
for($i = 0; $i < $size; ++$i) {
|
101 |
+
$topdir = $newdir . $slash . $rows[$i]['data'];
|
102 |
+
$output[$i]['name'] = $rows[$i]['data'];
|
103 |
+
$output[$i]['path'] = $topdir;
|
104 |
+
if($rows[$i]['dir']) {
|
105 |
+
$output[$i]['filetype'] = 'folder';
|
106 |
+
$output[$i]['extension'] = 'folder';
|
107 |
+
$output[$i]['filesize'] = '';
|
108 |
+
}
|
109 |
+
else {
|
110 |
+
$output[$i]['filetype'] = 'file';
|
111 |
+
$path = pathinfo($rows[$i]['data']);
|
112 |
+
if(isset($path['extension'])) {
|
113 |
+
$output[$i]['extension'] = $path['extension'];
|
114 |
+
}
|
115 |
+
$output[$i]['filesize'] = '(' . round(filesize($topdir) * .0009765625, 2) . ' KB)';
|
116 |
+
}
|
117 |
+
if($output[$i]['path'] == $dir) {
|
118 |
+
$output[$i]['content'] = file_get_contents($dir);
|
119 |
+
}
|
120 |
+
if($type == 'theme') {
|
121 |
+
$output[$i]['file'] = str_replace(realpath(get_theme_root()) . $slash, '', $output[$i]['path']);
|
122 |
+
$output[$i]['url'] = get_theme_root_uri() . $slash . $output[$i]['file'];
|
123 |
+
}
|
124 |
+
else {
|
125 |
+
$output[$i]['file'] = str_replace(realpath(WP_PLUGIN_DIR) . $slash, '', $output[$i]['path']);
|
126 |
+
$output[$i]['url'] = plugins_url() . $slash . $output[$i]['file'];
|
127 |
+
}
|
128 |
+
}
|
129 |
+
}
|
130 |
+
else {
|
131 |
+
$output[-1] = 'bad file or unable to open';
|
132 |
+
}
|
133 |
+
}
|
134 |
+
}
|
135 |
+
else {
|
136 |
+
$output[-1] = 'bad file or unable to open';
|
137 |
+
}
|
138 |
+
return $output;
|
139 |
+
}
|
140 |
+
|
141 |
+
public static function sortRows($data) {
|
142 |
+
$size = count($data);
|
143 |
+
|
144 |
+
for($i = 0; $i < $size; ++$i) {
|
145 |
+
$row_num = self::findSmallest($i, $size, $data);
|
146 |
+
$tmp = $data[$row_num];
|
147 |
+
$data[$row_num] = $data[$i];
|
148 |
+
$data[$i] = $tmp;
|
149 |
+
}
|
150 |
+
|
151 |
+
return $data;
|
152 |
+
}
|
153 |
+
|
154 |
+
public static function findSmallest($i, $end, $data) {
|
155 |
+
$min['pos'] = $i;
|
156 |
+
$min['value'] = $data[$i]['data'];
|
157 |
+
$min['dir'] = $data[$i]['dir'];
|
158 |
+
for(; $i < $end; ++$i) {
|
159 |
+
if($data[$i]['dir']) {
|
160 |
+
if($min['dir']) {
|
161 |
+
if($data[$i]['data'] < $min['value']) {
|
162 |
+
$min['value'] = $data[$i]['data'];
|
163 |
+
$min['dir'] = $data[$i]['dir'];
|
164 |
+
$min['pos'] = $i;
|
165 |
+
}
|
166 |
+
}
|
167 |
+
else {
|
168 |
+
$min['value'] = $data[$i]['data'];
|
169 |
+
$min['dir'] = $data[$i]['dir'];
|
170 |
+
$min['pos'] = $i;
|
171 |
+
}
|
172 |
+
}
|
173 |
+
else {
|
174 |
+
if(!$min['dir'] && $data[$i]['data'] < $min['value']) {
|
175 |
+
$min['value'] = $data[$i]['data'];
|
176 |
+
$min['dir'] = $data[$i]['dir'];
|
177 |
+
$min['pos'] = $i;
|
178 |
+
}
|
179 |
+
}
|
180 |
+
}
|
181 |
+
return $min['pos'];
|
182 |
+
}
|
183 |
+
|
184 |
+
public static function allowedFiles($dir, $file) {
|
185 |
+
$slash = '/';
|
186 |
+
if(WPWINDOWS) {
|
187 |
+
$slash = '\\';
|
188 |
+
}
|
189 |
+
$output = true;
|
190 |
+
$allowed_extensions = explode('~', WPEditorSetting::getValue('plugin_editor_allowed_extensions'));
|
191 |
+
|
192 |
+
if(is_dir($dir . $slash . $file)) {
|
193 |
+
$output = true;
|
194 |
+
}
|
195 |
+
else {
|
196 |
+
$file = pathinfo($file);
|
197 |
+
if(isset($file['extension']) && in_array($file['extension'], $allowed_extensions)) {
|
198 |
+
$output = true;
|
199 |
+
}
|
200 |
+
else {
|
201 |
+
$output = false;
|
202 |
+
}
|
203 |
+
}
|
204 |
+
return $output;
|
205 |
+
}
|
206 |
+
|
207 |
+
public static function uploadThemeFiles() {
|
208 |
+
// Theme file upload
|
209 |
+
$slash = '/';
|
210 |
+
if(WPWINDOWS) {
|
211 |
+
$slash = '\\';
|
212 |
+
}
|
213 |
+
if(isset($_FILES["file-0"]) && isset($_POST['current_theme_root'])) {
|
214 |
+
$error = $_FILES["file-0"]["error"];
|
215 |
+
$error_message = __('No Errors', 'wpeditor');
|
216 |
+
$success = __('Unsuccessful', 'wpeditor');
|
217 |
+
$current_theme_root = $_POST['current_theme_root'];
|
218 |
+
$directory = '';
|
219 |
+
if(isset($_POST['directory'])) {
|
220 |
+
$directory = $_POST['directory'];
|
221 |
+
$dir = substr($directory, -1);
|
222 |
+
if($dir != $slash) {
|
223 |
+
$directory = $directory . $slash;
|
224 |
+
}
|
225 |
+
$dir = substr($directory, 0, 1);
|
226 |
+
if($dir == $slash) {
|
227 |
+
$directory = substr($directory, 1);
|
228 |
+
}
|
229 |
+
}
|
230 |
+
$complete_directory = $current_theme_root . $directory;
|
231 |
+
if(!is_dir($complete_directory)) {
|
232 |
+
mkdir($complete_directory, 0777, true);
|
233 |
+
}
|
234 |
+
|
235 |
+
if($_FILES["file-0"]["error"] > 0) {
|
236 |
+
$error_message = __('Return Code', 'wpeditor') . ": " . $_FILES["file-0"]["error"];
|
237 |
+
}
|
238 |
+
else {
|
239 |
+
//$result = "Upload: " . $_FILES["file-0"]["name"] . "<br />";
|
240 |
+
//$result .= "Type: " . $_FILES["file-0"]["type"] . "<br />";
|
241 |
+
//$result .= "Size: " . ($_FILES["file-0"]["size"] / 1024) . " Kb<br />";
|
242 |
+
//$result .= "Temp file: " . $_FILES["file-0"]["tmp_name"] . "<br />";
|
243 |
+
|
244 |
+
if(file_exists($complete_directory . $_FILES["file-0"]["name"])) {
|
245 |
+
$error = -1;
|
246 |
+
$error_message = $_FILES["file-0"]["name"] . __(' already exists', 'wpeditor');
|
247 |
+
}
|
248 |
+
else {
|
249 |
+
move_uploaded_file($_FILES["file-0"]["tmp_name"], $current_theme_root . $directory . $_FILES["file-0"]["name"]);
|
250 |
+
$success = "Stored in: " . basename($complete_directory) . $slash . $_FILES["file-0"]["name"];
|
251 |
+
}
|
252 |
+
}
|
253 |
+
}
|
254 |
+
else {
|
255 |
+
$error = -2;
|
256 |
+
$error_message = __('No File Selected', 'wpeditor');
|
257 |
+
$success = __('Unsuccessful', 'wpeditor');
|
258 |
+
}
|
259 |
+
$result = array(
|
260 |
+
'error' => array(
|
261 |
+
$error,
|
262 |
+
$error_message
|
263 |
+
),
|
264 |
+
'success' => $success
|
265 |
+
);
|
266 |
+
return $result;
|
267 |
+
}
|
268 |
+
|
269 |
+
public static function uploadPluginFiles() {
|
270 |
+
// Plugin file upload
|
271 |
+
$slash = '/';
|
272 |
+
if(WPWINDOWS) {
|
273 |
+
$slash = '\\';
|
274 |
+
}
|
275 |
+
if(isset($_FILES["file-0"]) && isset($_POST['current_plugin_root'])) {
|
276 |
+
$error = $_FILES["file-0"]["error"];
|
277 |
+
$error_message = __('No Errors', 'wpeditor');
|
278 |
+
$success = __('Unsuccessful', 'wpeditor');
|
279 |
+
$current_plugin_root = $_POST['current_plugin_root'];
|
280 |
+
$directory = '';
|
281 |
+
if(isset($_POST['directory'])) {
|
282 |
+
$directory = $_POST['directory'];
|
283 |
+
$dir = substr($directory, -1);
|
284 |
+
if($dir != $slash) {
|
285 |
+
$directory = $directory . $slash;
|
286 |
+
}
|
287 |
+
$dir = substr($directory, 0, 1);
|
288 |
+
if($dir == $slash) {
|
289 |
+
$directory = substr($directory, 1);
|
290 |
+
}
|
291 |
+
}
|
292 |
+
$complete_directory = $current_plugin_root . $slash . $directory;
|
293 |
+
if(!is_dir($complete_directory)) {
|
294 |
+
mkdir($complete_directory, 0777, true);
|
295 |
+
}
|
296 |
+
|
297 |
+
if($_FILES["file-0"]["error"] > 0) {
|
298 |
+
$error_message = __('Return Code', 'wpeditor') . ": " . $_FILES["file-0"]["error"];
|
299 |
+
}
|
300 |
+
else {
|
301 |
+
//$result = "Upload: " . $_FILES["file-0"]["name"] . "<br />";
|
302 |
+
//$result .= "Type: " . $_FILES["file-0"]["type"] . "<br />";
|
303 |
+
//$result .= "Size: " . ($_FILES["file-0"]["size"] / 1024) . " Kb<br />";
|
304 |
+
//$result .= "Temp file: " . $_FILES["file-0"]["tmp_name"] . "<br />";
|
305 |
+
|
306 |
+
if(file_exists($complete_directory . $_FILES["file-0"]["name"])) {
|
307 |
+
$error = -1;
|
308 |
+
$error_message = $_FILES["file-0"]["name"] . __(' already exists', 'wpeditor');
|
309 |
+
}
|
310 |
+
else {
|
311 |
+
move_uploaded_file($_FILES["file-0"]["tmp_name"], $complete_directory . $_FILES["file-0"]["name"]);
|
312 |
+
$success = "Stored in: " . basename($complete_directory) . $slash . $_FILES["file-0"]["name"];
|
313 |
+
}
|
314 |
+
}
|
315 |
+
}
|
316 |
+
else {
|
317 |
+
$error = -2;
|
318 |
+
$error_message = __('No File Selected', 'wpeditor');
|
319 |
+
$success = __('Unsuccessful', 'wpeditor');
|
320 |
+
}
|
321 |
+
$result = array(
|
322 |
+
'error' => array(
|
323 |
+
$error,
|
324 |
+
$error_message
|
325 |
+
),
|
326 |
+
'success' => $success
|
327 |
+
);
|
328 |
+
return $result;
|
329 |
+
}
|
330 |
+
|
331 |
+
}
|
classes/WPEditorException.php
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/**
|
3 |
+
* Exception error codes
|
4 |
+
* 701 - Could not create Log File
|
5 |
+
*/
|
6 |
+
class WPEditorException extends Exception {
|
7 |
+
|
8 |
+
public static function exceptionMessages($errorCode, $errorMessage, $reasons=null) {
|
9 |
+
$exception = array(
|
10 |
+
'errorCode' => $errorCode,
|
11 |
+
'errorMessage' => $errorMessage
|
12 |
+
);
|
13 |
+
switch ($errorCode) {
|
14 |
+
case 701;
|
15 |
+
$exception['exception'] = __('WPEditor was unable to create the log file. It looks like file permissions are not currently enabled on your site.','wpeditor');
|
16 |
+
break;
|
17 |
+
default;
|
18 |
+
$exception['exception'] = __("Unfortunately there has been an error with the WPEditor Plugin. Please contact the site Administrator for more information.<br />Error Code: $errorCode $errorMessage",'wpeditor');
|
19 |
+
break;
|
20 |
+
}
|
21 |
+
return $exception;
|
22 |
+
}
|
23 |
+
}
|
classes/WPEditorLog.php
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPEditorLog {
|
3 |
+
|
4 |
+
public static function log($data) {
|
5 |
+
if(defined('WPEDITOR_DEBUG') && WPEDITOR_DEBUG) {
|
6 |
+
$tz = '- Server time zone ' . date('T');
|
7 |
+
$date = date('m/d/Y g:i:s a', self::localTs());
|
8 |
+
$header = strpos($_SERVER['REQUEST_URI'], 'wp-admin') ? "\n\n======= ADMIN REQUEST =======\n[LOG DATE: $date $tz]\n" : "\n\n[LOG DATE: $date $tz]\n";
|
9 |
+
$filename = WPEDITOR_PATH . '/log.txt';
|
10 |
+
if(file_exists($filename) && is_writable($filename)) {
|
11 |
+
file_put_contents($filename, $header . $data, FILE_APPEND);
|
12 |
+
}
|
13 |
+
}
|
14 |
+
}
|
15 |
+
|
16 |
+
public static function localTs($timestamp=null) {
|
17 |
+
$timestamp = isset($timestamp) ? $timestamp : time();
|
18 |
+
if(date('T') == 'UTC') {
|
19 |
+
$timestamp += (get_option('gmt_offset') * 3600);
|
20 |
+
}
|
21 |
+
return $timestamp;
|
22 |
+
}
|
23 |
+
|
24 |
+
public static function createLogFile() {
|
25 |
+
$log_dir_path = WPEDITOR_PATH;
|
26 |
+
$log_file_path = self::getLogFilePath();
|
27 |
+
|
28 |
+
if(file_exists($log_dir_path)) {
|
29 |
+
if(is_writable($log_dir_path)) {
|
30 |
+
@fclose(fopen($log_file_path, 'a'));
|
31 |
+
if(!is_writable($log_file_path)) {
|
32 |
+
throw new WPEditorException("Unable to create log file. $log_file_path", 701);
|
33 |
+
}
|
34 |
+
}
|
35 |
+
else {
|
36 |
+
throw new WPEditorException("Log file directory is not writable. $log_dir_path", 702);
|
37 |
+
}
|
38 |
+
}
|
39 |
+
else {
|
40 |
+
throw new WPEditorException("Log file directory does not exist. $log_dir_path", 703);
|
41 |
+
}
|
42 |
+
|
43 |
+
|
44 |
+
return $log_file_path;
|
45 |
+
}
|
46 |
+
|
47 |
+
public static function getLogFilePath() {
|
48 |
+
$log_file_path = WPEDITOR_PATH . '/log.txt';
|
49 |
+
return $log_file_path;
|
50 |
+
}
|
51 |
+
|
52 |
+
public static function exists() {
|
53 |
+
$exists = false;
|
54 |
+
$log_file_path = self::getLogFilePath();
|
55 |
+
if(file_exists($log_file_path) && filesize($log_file_path) > 0) {
|
56 |
+
$exists = true;
|
57 |
+
}
|
58 |
+
return $exists;
|
59 |
+
}
|
60 |
+
|
61 |
+
}
|
classes/WPEditorPlugins.php
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPEditorPlugins {
|
3 |
+
|
4 |
+
public static function addPluginsPage() {
|
5 |
+
if(!current_user_can('edit_plugins')) {
|
6 |
+
wp_die('<p>' . __('You do not have sufficient permissions to edit plugins for this site.', 'wpeditor') . '</p>');
|
7 |
+
}
|
8 |
+
|
9 |
+
$plugins = get_plugins();
|
10 |
+
|
11 |
+
if(empty($plugins)) {
|
12 |
+
wp_die('<p>' . __('There are no plugins installed on this site.', 'wpeditor') . '</p>');
|
13 |
+
}
|
14 |
+
|
15 |
+
if(isset($_REQUEST['plugin'])) {
|
16 |
+
$plugin = stripslashes($_REQUEST['plugin']);
|
17 |
+
}
|
18 |
+
if(isset($_REQUEST['file'])) {
|
19 |
+
$file = stripslashes($_REQUEST['file']);
|
20 |
+
}
|
21 |
+
|
22 |
+
if(empty($plugin)) {
|
23 |
+
$plugin = array_keys($plugins);
|
24 |
+
$plugin = $plugin[0];
|
25 |
+
}
|
26 |
+
$plugin_files[] = $plugin;
|
27 |
+
|
28 |
+
if(empty($file)) {
|
29 |
+
$file = $plugin_files[0];
|
30 |
+
}
|
31 |
+
else {
|
32 |
+
$file = stripslashes($file);
|
33 |
+
}
|
34 |
+
|
35 |
+
$pf = WPEditorBrowser::getFilesAndFolders((WPWINDOWS) ? str_replace("/", "\\", WP_PLUGIN_DIR . '/' . $file) : WP_PLUGIN_DIR . '/' . $file, 0, 'plugin');
|
36 |
+
foreach($pf as $plugin_file) {
|
37 |
+
foreach($plugin_file as $k => $p) {
|
38 |
+
if($k == 'file') {
|
39 |
+
$plugin_files[] = $p;
|
40 |
+
}
|
41 |
+
}
|
42 |
+
}
|
43 |
+
|
44 |
+
$file = validate_file_to_edit((WPWINDOWS) ? str_replace("/", "\\", $file) : $file, $plugin_files);
|
45 |
+
$current_plugin_root = WP_PLUGIN_DIR . '/' . dirname($file);
|
46 |
+
$real_file = WP_PLUGIN_DIR . '/' . $plugin;
|
47 |
+
|
48 |
+
if(isset($_POST['new-content']) && file_exists($real_file) && is_writeable($real_file)) {
|
49 |
+
$new_content = stripslashes($_POST['new-content']);
|
50 |
+
if(file_get_contents($real_file) === $new_content) {
|
51 |
+
WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Contents are the same");
|
52 |
+
}
|
53 |
+
else {
|
54 |
+
$f = fopen($real_file, 'w+');
|
55 |
+
fwrite($f, $new_content);
|
56 |
+
fclose($f);
|
57 |
+
WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] just wrote to $real_file");
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
$content = file_get_contents($real_file);
|
62 |
+
|
63 |
+
$content = esc_textarea($content);
|
64 |
+
|
65 |
+
$scroll_to = isset($_REQUEST['scroll_to']) ? (int) $_REQUEST['scroll_to'] : 0;
|
66 |
+
|
67 |
+
$data = array(
|
68 |
+
'plugins' => $plugins,
|
69 |
+
'plugin' => $plugin,
|
70 |
+
'plugin_files' => $plugin_files,
|
71 |
+
'current_plugin_root' => $current_plugin_root,
|
72 |
+
'real_file' => $real_file,
|
73 |
+
'content' => $content,
|
74 |
+
'scroll_to' => $scroll_to,
|
75 |
+
'file' => $file,
|
76 |
+
'content-type' => 'plugin'
|
77 |
+
);
|
78 |
+
echo WPEditor::getView('views/plugin-editor.php', $data);
|
79 |
+
}
|
80 |
+
|
81 |
+
public function pluginsHelpTab() {
|
82 |
+
global $wpeditor_plugin;
|
83 |
+
$screen = get_current_screen();
|
84 |
+
if(function_exists('add_help_tab')) {
|
85 |
+
$screen->add_help_tab(array(
|
86 |
+
'id' => 'overview',
|
87 |
+
'title' => __('Overview'),
|
88 |
+
'content' => '<p>' . __('You can use the editor to make changes to any of your plugins’ individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.', 'wpeditor') . '</p>' . '<p>' . __('Choose a plugin to edit from the menu in the upper right and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don’t forget to save your changes (Update File) when you’re finished.', 'wpeditor') . '</p>' . '<p>' . __('The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Lookup takes you to a web page about that particular function.', 'wpeditor') . '</p>' . '<p>' . __('If you want to make changes but don’t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.', 'wpeditor') . '</p>' . (is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.', 'wpeditor') . '</p>' : '' )
|
89 |
+
));
|
90 |
+
$screen->set_help_sidebar(
|
91 |
+
'<p><strong>' . __('For more information:', 'wpeditor') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Plugins_Editor_Screen" target="_blank">Documentation on Editing Plugins</a>', 'wpeditor') . '</p>' . '<p>' . __('<a href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">Documentation on Writing Plugins</a>', 'wpeditor') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>', 'wpeditor') . '</p>'
|
92 |
+
);
|
93 |
+
}
|
94 |
+
elseif(version_compare(get_bloginfo('version'), '3.3', '<')) {
|
95 |
+
$help = '<p>' . __('You can use the editor to make changes to any of your plugins’ individual PHP files. Be aware that if you make changes, plugins updates will overwrite your customizations.') . '</p>';
|
96 |
+
$help .= '<p>' . __('Choose a plugin to edit from the menu in the upper right and click the Select button. Click once on any file name to load it in the editor, and make your changes. Don’t forget to save your changes (Update File) when you’re finished.') . '</p>';
|
97 |
+
$help .= '<p>' . __('The Documentation menu below the editor lists the PHP functions recognized in the plugin file. Clicking Lookup takes you to a web page about that particular function.') . '</p>';
|
98 |
+
$help .= '<p>' . __('If you want to make changes but don’t want them to be overwritten when the plugin is updated, you may be ready to think about writing your own plugin. For information on how to edit plugins, write your own from scratch, or just better understand their anatomy, check out the links below.') . '</p>';
|
99 |
+
if(is_network_admin()) {
|
100 |
+
$help .= '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>';
|
101 |
+
}
|
102 |
+
$help .= '<p><strong>' . __('For more information:') . '</strong></p>';
|
103 |
+
$help .= '<p>' . __('<a href="http://codex.wordpress.org/Plugins_Editor_Screen" target="_blank">Documentation on Editing Plugins</a>') . '</p>';
|
104 |
+
$help .= '<p>' . __('<a href="http://codex.wordpress.org/Writing_a_Plugin" target="_blank">Documentation on Writing Plugins</a>') . '</p>';
|
105 |
+
$help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
|
106 |
+
add_contextual_help($screen, $help);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
}
|
classes/WPEditorSetting.php
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPEditorSetting {
|
3 |
+
|
4 |
+
public static function setValue($key, $value) {
|
5 |
+
global $wpdb;
|
6 |
+
$settingsTable = WPEditor::getTableName('settings');
|
7 |
+
|
8 |
+
if(!empty($key)) {
|
9 |
+
$dbKey = $wpdb->get_var("SELECT `key` from $settingsTable where `key`='$key'");
|
10 |
+
if($dbKey) {
|
11 |
+
if(!empty($value)) {
|
12 |
+
$wpdb->update($settingsTable,
|
13 |
+
array('key'=>$key, 'value'=>$value),
|
14 |
+
array('key'=>$key),
|
15 |
+
array('%s', '%s'),
|
16 |
+
array('%s')
|
17 |
+
);
|
18 |
+
}
|
19 |
+
else {
|
20 |
+
$wpdb->query("DELETE from $settingsTable where `key`='$key'");
|
21 |
+
}
|
22 |
+
}
|
23 |
+
else {
|
24 |
+
if(!empty($value)) {
|
25 |
+
$wpdb->insert($settingsTable,
|
26 |
+
array('key'=>$key, 'value'=>$value),
|
27 |
+
array('%s', '%s')
|
28 |
+
);
|
29 |
+
}
|
30 |
+
}
|
31 |
+
}
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
public static function getValue($key, $entities=false) {
|
36 |
+
global $wpdb;
|
37 |
+
$settingsTable = WPEditor::getTableName('settings');
|
38 |
+
$value = $wpdb->get_var("SELECT `value` from $settingsTable where `key`='$key'");
|
39 |
+
|
40 |
+
if(!empty($value) && $entities) {
|
41 |
+
$value = htmlentities($value);
|
42 |
+
}
|
43 |
+
|
44 |
+
return empty($value) ? false : $value;
|
45 |
+
}
|
46 |
+
|
47 |
+
}
|
classes/WPEditorThemes.php
ADDED
@@ -0,0 +1,157 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
class WPEditorThemes {
|
3 |
+
|
4 |
+
public static function addThemesPage() {
|
5 |
+
if(!current_user_can('edit_themes')) {
|
6 |
+
wp_die('<p>' . __('You do not have sufficient permissions to edit templates for this site.', 'wpeditor') . '</p>');
|
7 |
+
}
|
8 |
+
|
9 |
+
if(WP_34) {
|
10 |
+
$themes = wp_get_themes();
|
11 |
+
}
|
12 |
+
else {
|
13 |
+
$themes = get_themes();
|
14 |
+
}
|
15 |
+
|
16 |
+
if(empty($themes)) {
|
17 |
+
wp_die('<p>' . __('There are no themes installed on this site.', 'wpeditor') . '</p>');
|
18 |
+
}
|
19 |
+
|
20 |
+
if(isset($_REQUEST['theme'])) {
|
21 |
+
$theme = stripslashes($_REQUEST['theme']);
|
22 |
+
}
|
23 |
+
if(isset($_REQUEST['file'])) {
|
24 |
+
$file = stripslashes($_REQUEST['file']);
|
25 |
+
}
|
26 |
+
|
27 |
+
if(empty($theme)) {
|
28 |
+
if(WP_34) {
|
29 |
+
$theme = wp_get_theme();
|
30 |
+
}
|
31 |
+
else {
|
32 |
+
$theme = get_current_theme();
|
33 |
+
}
|
34 |
+
}
|
35 |
+
|
36 |
+
$stylesheet = '';
|
37 |
+
if($theme && WP_34) {
|
38 |
+
$stylesheet = urldecode($theme);
|
39 |
+
if(is_object($theme)) {
|
40 |
+
$stylesheet = urldecode($theme->stylesheet);
|
41 |
+
}
|
42 |
+
}
|
43 |
+
elseif(WP_34) {
|
44 |
+
$stylesheet = get_stylesheet();
|
45 |
+
}
|
46 |
+
|
47 |
+
if(WP_34) {
|
48 |
+
$wp_theme = wp_get_theme($stylesheet);
|
49 |
+
}
|
50 |
+
else {
|
51 |
+
$wp_theme = '';
|
52 |
+
}
|
53 |
+
|
54 |
+
if(empty($file)) {
|
55 |
+
if(WP_34) {
|
56 |
+
$file = basename($wp_theme['Stylesheet Dir']) . '/style.css';
|
57 |
+
}
|
58 |
+
else {
|
59 |
+
$file = basename($themes[$theme]['Stylesheet Dir']) . '/style.css';
|
60 |
+
}
|
61 |
+
}
|
62 |
+
else {
|
63 |
+
$file = stripslashes($file);
|
64 |
+
}
|
65 |
+
|
66 |
+
if(WP_34) {
|
67 |
+
$tf = WPEditorBrowser::getFilesAndFolders((WPWINDOWS) ? str_replace("/", "\\", $wp_theme['Theme Root'] . '/' . $file) : $wp_theme['Theme Root'] . '/' . $file, 0, 'theme');
|
68 |
+
}
|
69 |
+
else {
|
70 |
+
$tf = WPEditorBrowser::getFilesAndFolders((WPWINDOWS) ? str_replace("/", "\\", $themes[$theme]['Theme Root'] . '/' . $file) : $themes[$theme]['Theme Root'] . '/' . $file, 0, 'theme');
|
71 |
+
}
|
72 |
+
|
73 |
+
foreach($tf as $theme_file) {
|
74 |
+
foreach($theme_file as $k => $t) {
|
75 |
+
if($k == 'file') {
|
76 |
+
$theme_files[] = $t;
|
77 |
+
}
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
$file = validate_file_to_edit((WPWINDOWS) ? str_replace("/", "\\", $file) : $file, $theme_files);
|
82 |
+
if(WP_34) {
|
83 |
+
$current_theme_root = $wp_theme['Theme Root'] . '/' . dirname($file) . '/';
|
84 |
+
}
|
85 |
+
else {
|
86 |
+
$current_theme_root = $themes[$theme]['Theme Root'] . '/' . dirname($file);
|
87 |
+
}
|
88 |
+
$real_file = $current_theme_root . basename($file);
|
89 |
+
|
90 |
+
if(isset($_POST['new-content']) && file_exists($real_file) && is_writeable($real_file)) {
|
91 |
+
$new_content = stripslashes($_POST['new-content']);
|
92 |
+
if(file_get_contents($real_file) === $new_content) {
|
93 |
+
WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] Contents are the same");
|
94 |
+
}
|
95 |
+
else {
|
96 |
+
$f = fopen($real_file, 'w+');
|
97 |
+
fwrite($f, $new_content);
|
98 |
+
fclose($f);
|
99 |
+
WPEditorLog::log('[' . basename(__FILE__) . ' - line ' . __LINE__ . "] just wrote to $real_file");
|
100 |
+
}
|
101 |
+
}
|
102 |
+
|
103 |
+
$content = file_get_contents($real_file);
|
104 |
+
|
105 |
+
$content = esc_textarea($content);
|
106 |
+
|
107 |
+
$scroll_to = isset($_REQUEST['scroll_to']) ? (int) $_REQUEST['scroll_to'] : 0;
|
108 |
+
|
109 |
+
$data = array(
|
110 |
+
'themes' => $themes,
|
111 |
+
'theme' => $theme,
|
112 |
+
'wp_theme' => $wp_theme,
|
113 |
+
'stylesheet' => $stylesheet,
|
114 |
+
'theme_files' => $theme_files,
|
115 |
+
'current_theme_root' => $current_theme_root,
|
116 |
+
'real_file' => $real_file,
|
117 |
+
'content' => $content,
|
118 |
+
'scroll_to' => $scroll_to,
|
119 |
+
'file' => $file,
|
120 |
+
'content-type' => 'theme'
|
121 |
+
);
|
122 |
+
echo WPEditor::getView('views/theme-editor.php', $data);
|
123 |
+
}
|
124 |
+
|
125 |
+
public function themesHelpTab() {
|
126 |
+
global $wpeditor_themes;
|
127 |
+
$screen = get_current_screen();
|
128 |
+
if(function_exists('add_help_tab') && function_exists('set_help_sidebar')) {
|
129 |
+
$screen->add_help_tab(array(
|
130 |
+
'id' => 'overview',
|
131 |
+
'title' => __('Overview', 'wpeditor'),
|
132 |
+
'content' => '<p>' . __('You can use the Theme Editor to edit the individual files which make up your theme.', 'wpeditor') . '</p>' . '<p>' . __('Begin by choosing a theme to edit from the dropdown menu and clicking Select. A list then appears of all the template files. Clicking once on any file name causes the file to appear in the large Editor box.', 'wpeditor') . '</p>' . '<p>' . __('After typing in your edits, click Update File.', 'wpeditor') . '</p>' . '<p>' . __('<strong>Advice:</strong> think very carefully about your site crashing if you are live-editing the theme currently in use.', 'wpeditor') . '</p>' . '<p>' . __('Upgrading to a newer version of the same theme will override changes made here. To avoid this, consider creating a <a href="http://codex.wordpress.org/Child_Themes" target="_blank">child theme</a> instead.', 'wpeditor') . '</p>' . (is_network_admin() ? '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.', 'wpeditor') . '</p>' : '')
|
133 |
+
));
|
134 |
+
$screen->set_help_sidebar(
|
135 |
+
'<p><strong>' . __('For more information:', 'wpeditor') . '</strong></p>' . '<p>' . __('<a href="http://codex.wordpress.org/Theme_Development" target="_blank">Documentation on Theme Development</a>', 'wpeditor') . '</p>' . '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>', 'wpeditor') . '</p>' . '<p>' . __('<a href="http://codex.wordpress.org/Editing_Files" target="_blank">Documentation on Editing Files</a>', 'wpeditor') . '</p>' . '<p>' . __('<a href="http://codex.wordpress.org/Template_Tags" target="_blank">Documentation on Template Tags</a>', 'wpeditor') . '</p>' . '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>', 'wpeditor') . '</p>'
|
136 |
+
);
|
137 |
+
}
|
138 |
+
elseif(version_compare(get_bloginfo('version'), '3.3', '<')) {
|
139 |
+
$help = '<p>' . __('You can use the Theme Editor to edit the individual files which make up your theme.') . '</p>';
|
140 |
+
$help .= '<p>' . __('Begin by choosing a theme to edit from the dropdown menu and clicking Select. A list then appears of all the template files. Clicking once on any file name causes the file to appear in the large Editor box.') . '</p>';
|
141 |
+
$help .= '<p>' . __('After typing in your edits, click Update File.') . '</p>';
|
142 |
+
$help .= '<p>' . __('<strong>Advice:</strong> think very carefully about your site crashing if you are live-editing the theme currently in use.') . '</p>';
|
143 |
+
$help .= '<p>' . __('Upgrading to a newer version of the same theme will override changes made here. To avoid this, consider creating a <a href="http://codex.wordpress.org/Child_Themes" target="_blank">child theme</a> instead.') . '</p>';
|
144 |
+
if(is_network_admin()) {
|
145 |
+
$help .= '<p>' . __('Any edits to files from this screen will be reflected on all sites in the network.') . '</p>';
|
146 |
+
}
|
147 |
+
$help .= '<p><strong>' . __('For more information:') . '</strong></p>';
|
148 |
+
$help .= '<p>' . __('<a href="http://codex.wordpress.org/Theme_Development" target="_blank">Documentation on Theme Development</a>') . '</p>';
|
149 |
+
$help .= '<p>' . __('<a href="http://codex.wordpress.org/Using_Themes" target="_blank">Documentation on Using Themes</a>') . '</p>';
|
150 |
+
$help .= '<p>' . __('<a href="http://codex.wordpress.org/Editing_Files" target="_blank">Documentation on Editing Files</a>') . '</p>';
|
151 |
+
$help .= '<p>' . __('<a href="http://codex.wordpress.org/Template_Tags" target="_blank">Documentation on Template Tags</a>') . '</p>';
|
152 |
+
$help .= '<p>' . __('<a href="http://wordpress.org/support/" target="_blank">Support Forums</a>') . '</p>';
|
153 |
+
add_contextual_help($screen, $help);
|
154 |
+
}
|
155 |
+
}
|
156 |
+
|
157 |
+
}
|
extensions/codemirror/codemirror.css
ADDED
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.CodeMirror {
|
2 |
+
line-height: 1em;
|
3 |
+
font-family: monospace;
|
4 |
+
}
|
5 |
+
|
6 |
+
.CodeMirror-scroll {
|
7 |
+
overflow: auto;
|
8 |
+
/* This is needed to prevent an IE[67] bug where the scrolled content
|
9 |
+
is visible outside of the scrolling box. */
|
10 |
+
position: relative;
|
11 |
+
}
|
12 |
+
.CodeMirror-fullscreen {
|
13 |
+
display:block;
|
14 |
+
position:fixed !important;
|
15 |
+
top:0;
|
16 |
+
left:0;
|
17 |
+
width:100%;
|
18 |
+
height:100%;
|
19 |
+
z-index:9999999;
|
20 |
+
margin:0;
|
21 |
+
padding:0;
|
22 |
+
border:0px solid #BBBBBB;
|
23 |
+
opacity:1;
|
24 |
+
background:#FFF;
|
25 |
+
}
|
26 |
+
.CodeMirror-gutter {
|
27 |
+
position: absolute; left: 0; top: 0;
|
28 |
+
z-index: 10;
|
29 |
+
background-color: #f7f7f7;
|
30 |
+
border-right: 1px solid #eee;
|
31 |
+
min-width: 2em;
|
32 |
+
height: 100%;
|
33 |
+
}
|
34 |
+
.CodeMirror-gutter-text {
|
35 |
+
color: #aaa;
|
36 |
+
text-align: right;
|
37 |
+
padding: .4em .2em .4em .4em;
|
38 |
+
white-space: pre !important;
|
39 |
+
}
|
40 |
+
.CodeMirror-lines {
|
41 |
+
padding: .4em;
|
42 |
+
}
|
43 |
+
|
44 |
+
.CodeMirror pre {
|
45 |
+
-moz-border-radius: 0;
|
46 |
+
-webkit-border-radius: 0;
|
47 |
+
-o-border-radius: 0;
|
48 |
+
border-radius: 0;
|
49 |
+
border-width: 0; margin: 0; padding: 0; background: transparent;
|
50 |
+
font-family: inherit;
|
51 |
+
font-size: inherit;
|
52 |
+
padding: 0; margin: 0;
|
53 |
+
white-space: pre;
|
54 |
+
word-wrap: normal;
|
55 |
+
}
|
56 |
+
|
57 |
+
.CodeMirror-wrap pre {
|
58 |
+
word-wrap: break-word;
|
59 |
+
white-space: pre-wrap;
|
60 |
+
}
|
61 |
+
.CodeMirror-wrap .CodeMirror-scroll {
|
62 |
+
overflow-x: hidden;
|
63 |
+
}
|
64 |
+
|
65 |
+
.CodeMirror textarea {
|
66 |
+
outline: none !important;
|
67 |
+
}
|
68 |
+
|
69 |
+
.CodeMirror pre.CodeMirror-cursor {
|
70 |
+
z-index: 10;
|
71 |
+
position: absolute;
|
72 |
+
visibility: hidden;
|
73 |
+
border-left: 1px solid black;
|
74 |
+
}
|
75 |
+
.CodeMirror-focused pre.CodeMirror-cursor {
|
76 |
+
visibility: visible;
|
77 |
+
}
|
78 |
+
|
79 |
+
span.CodeMirror-selected { background: #d9d9d9; }
|
80 |
+
.CodeMirror-focused span.CodeMirror-selected { background: #d2dcf8; }
|
81 |
+
|
82 |
+
.CodeMirror-searching {background: #ffa;}
|
83 |
+
|
84 |
+
/* Default theme */
|
85 |
+
|
86 |
+
.cm-s-default span.cm-keyword {color: #708;}
|
87 |
+
.cm-s-default span.cm-atom {color: #219;}
|
88 |
+
.cm-s-default span.cm-number {color: #164;}
|
89 |
+
.cm-s-default span.cm-def {color: #00f;}
|
90 |
+
.cm-s-default span.cm-variable {color: black;}
|
91 |
+
.cm-s-default span.cm-variable-2 {color: #05a;}
|
92 |
+
.cm-s-default span.cm-variable-3 {color: #085;}
|
93 |
+
.cm-s-default span.cm-property {color: black;}
|
94 |
+
.cm-s-default span.cm-operator {color: black;}
|
95 |
+
.cm-s-default span.cm-comment {color: #a50;}
|
96 |
+
.cm-s-default span.cm-string {color: #a11;}
|
97 |
+
.cm-s-default span.cm-string-2 {color: #f50;}
|
98 |
+
.cm-s-default span.cm-meta {color: #555;}
|
99 |
+
.cm-s-default span.cm-error {color: #f00;}
|
100 |
+
.cm-s-default span.cm-qualifier {color: #555;}
|
101 |
+
.cm-s-default span.cm-builtin {color: #30a;}
|
102 |
+
.cm-s-default span.cm-bracket {color: #cc7;}
|
103 |
+
.cm-s-default span.cm-tag {color: #170;}
|
104 |
+
.cm-s-default span.cm-attribute {color: #00c;}
|
105 |
+
.cm-s-default span.cm-header {color: #a0a;}
|
106 |
+
.cm-s-default span.cm-quote {color: #090;}
|
107 |
+
.cm-s-default span.cm-hr {color: #999;}
|
108 |
+
.cm-s-default span.cm-link {color: #00c;}
|
109 |
+
|
110 |
+
span.cm-header, span.cm-strong {font-weight: bold;}
|
111 |
+
span.cm-em {font-style: italic;}
|
112 |
+
span.cm-emstrong {font-style: italic; font-weight: bold;}
|
113 |
+
span.cm-link {text-decoration: underline;}
|
114 |
+
|
115 |
+
div.CodeMirror span.CodeMirror-matchingbracket {color: #0f0;}
|
116 |
+
div.CodeMirror span.CodeMirror-nonmatchingbracket {color: #f22;}
|
extensions/codemirror/dialog.css
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.CodeMirror-dialog {
|
2 |
+
position: relative;
|
3 |
+
}
|
4 |
+
|
5 |
+
.CodeMirror-dialog > div {
|
6 |
+
position: absolute;
|
7 |
+
top: 0; left: 0; right: 0;
|
8 |
+
background: white;
|
9 |
+
border-bottom: 1px solid #eee;
|
10 |
+
z-index: 15;
|
11 |
+
padding: .1em .8em;
|
12 |
+
overflow: hidden;
|
13 |
+
color: #333;
|
14 |
+
}
|
15 |
+
|
16 |
+
.CodeMirror-dialog input {
|
17 |
+
border: none;
|
18 |
+
outline: none;
|
19 |
+
background: transparent;
|
20 |
+
width: 20em;
|
21 |
+
color: inherit;
|
22 |
+
font-family: monospace;
|
23 |
+
}
|
extensions/codemirror/js/clike.js
ADDED
@@ -0,0 +1,249 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("clike", function(config, parserConfig) {
|
2 |
+
var indentUnit = config.indentUnit,
|
3 |
+
keywords = parserConfig.keywords || {},
|
4 |
+
blockKeywords = parserConfig.blockKeywords || {},
|
5 |
+
atoms = parserConfig.atoms || {},
|
6 |
+
hooks = parserConfig.hooks || {},
|
7 |
+
multiLineStrings = parserConfig.multiLineStrings;
|
8 |
+
var isOperatorChar = /[+\-*&%=<>!?|\/]/;
|
9 |
+
|
10 |
+
var curPunc;
|
11 |
+
|
12 |
+
function tokenBase(stream, state) {
|
13 |
+
var ch = stream.next();
|
14 |
+
if (hooks[ch]) {
|
15 |
+
var result = hooks[ch](stream, state);
|
16 |
+
if (result !== false) return result;
|
17 |
+
}
|
18 |
+
if (ch == '"' || ch == "'") {
|
19 |
+
state.tokenize = tokenString(ch);
|
20 |
+
return state.tokenize(stream, state);
|
21 |
+
}
|
22 |
+
if (/[\[\]{}\(\),;\:\.]/.test(ch)) {
|
23 |
+
curPunc = ch;
|
24 |
+
return null
|
25 |
+
}
|
26 |
+
if (/\d/.test(ch)) {
|
27 |
+
stream.eatWhile(/[\w\.]/);
|
28 |
+
return "number";
|
29 |
+
}
|
30 |
+
if (ch == "/") {
|
31 |
+
if (stream.eat("*")) {
|
32 |
+
state.tokenize = tokenComment;
|
33 |
+
return tokenComment(stream, state);
|
34 |
+
}
|
35 |
+
if (stream.eat("/")) {
|
36 |
+
stream.skipToEnd();
|
37 |
+
return "comment";
|
38 |
+
}
|
39 |
+
}
|
40 |
+
if (isOperatorChar.test(ch)) {
|
41 |
+
stream.eatWhile(isOperatorChar);
|
42 |
+
return "operator";
|
43 |
+
}
|
44 |
+
stream.eatWhile(/[\w\$_]/);
|
45 |
+
var cur = stream.current();
|
46 |
+
if (keywords.propertyIsEnumerable(cur)) {
|
47 |
+
if (blockKeywords.propertyIsEnumerable(cur)) curPunc = "newstatement";
|
48 |
+
return "keyword";
|
49 |
+
}
|
50 |
+
if (atoms.propertyIsEnumerable(cur)) return "atom";
|
51 |
+
return "word";
|
52 |
+
}
|
53 |
+
|
54 |
+
function tokenString(quote) {
|
55 |
+
return function(stream, state) {
|
56 |
+
var escaped = false, next, end = false;
|
57 |
+
while ((next = stream.next()) != null) {
|
58 |
+
if (next == quote && !escaped) {end = true; break;}
|
59 |
+
escaped = !escaped && next == "\\";
|
60 |
+
}
|
61 |
+
if (end || !(escaped || multiLineStrings))
|
62 |
+
state.tokenize = tokenBase;
|
63 |
+
return "string";
|
64 |
+
};
|
65 |
+
}
|
66 |
+
|
67 |
+
function tokenComment(stream, state) {
|
68 |
+
var maybeEnd = false, ch;
|
69 |
+
while (ch = stream.next()) {
|
70 |
+
if (ch == "/" && maybeEnd) {
|
71 |
+
state.tokenize = tokenBase;
|
72 |
+
break;
|
73 |
+
}
|
74 |
+
maybeEnd = (ch == "*");
|
75 |
+
}
|
76 |
+
return "comment";
|
77 |
+
}
|
78 |
+
|
79 |
+
function Context(indented, column, type, align, prev) {
|
80 |
+
this.indented = indented;
|
81 |
+
this.column = column;
|
82 |
+
this.type = type;
|
83 |
+
this.align = align;
|
84 |
+
this.prev = prev;
|
85 |
+
}
|
86 |
+
function pushContext(state, col, type) {
|
87 |
+
return state.context = new Context(state.indented, col, type, null, state.context);
|
88 |
+
}
|
89 |
+
function popContext(state) {
|
90 |
+
var t = state.context.type;
|
91 |
+
if (t == ")" || t == "]" || t == "}")
|
92 |
+
state.indented = state.context.indented;
|
93 |
+
return state.context = state.context.prev;
|
94 |
+
}
|
95 |
+
|
96 |
+
// Interface
|
97 |
+
|
98 |
+
return {
|
99 |
+
startState: function(basecolumn) {
|
100 |
+
return {
|
101 |
+
tokenize: null,
|
102 |
+
context: new Context((basecolumn || 0) - indentUnit, 0, "top", false),
|
103 |
+
indented: 0,
|
104 |
+
startOfLine: true
|
105 |
+
};
|
106 |
+
},
|
107 |
+
|
108 |
+
token: function(stream, state) {
|
109 |
+
var ctx = state.context;
|
110 |
+
if (stream.sol()) {
|
111 |
+
if (ctx.align == null) ctx.align = false;
|
112 |
+
state.indented = stream.indentation();
|
113 |
+
state.startOfLine = true;
|
114 |
+
}
|
115 |
+
if (stream.eatSpace()) return null;
|
116 |
+
curPunc = null;
|
117 |
+
var style = (state.tokenize || tokenBase)(stream, state);
|
118 |
+
if (style == "comment" || style == "meta") return style;
|
119 |
+
if (ctx.align == null) ctx.align = true;
|
120 |
+
|
121 |
+
if ((curPunc == ";" || curPunc == ":") && ctx.type == "statement") popContext(state);
|
122 |
+
else if (curPunc == "{") pushContext(state, stream.column(), "}");
|
123 |
+
else if (curPunc == "[") pushContext(state, stream.column(), "]");
|
124 |
+
else if (curPunc == "(") pushContext(state, stream.column(), ")");
|
125 |
+
else if (curPunc == "}") {
|
126 |
+
while (ctx.type == "statement") ctx = popContext(state);
|
127 |
+
if (ctx.type == "}") ctx = popContext(state);
|
128 |
+
while (ctx.type == "statement") ctx = popContext(state);
|
129 |
+
}
|
130 |
+
else if (curPunc == ctx.type) popContext(state);
|
131 |
+
else if (ctx.type == "}" || ctx.type == "top" || (ctx.type == "statement" && curPunc == "newstatement"))
|
132 |
+
pushContext(state, stream.column(), "statement");
|
133 |
+
state.startOfLine = false;
|
134 |
+
return style;
|
135 |
+
},
|
136 |
+
|
137 |
+
indent: function(state, textAfter) {
|
138 |
+
if (state.tokenize != tokenBase && state.tokenize != null) return 0;
|
139 |
+
var ctx = state.context, firstChar = textAfter && textAfter.charAt(0);
|
140 |
+
if (ctx.type == "statement" && firstChar == "}") ctx = ctx.prev;
|
141 |
+
var closing = firstChar == ctx.type;
|
142 |
+
if (ctx.type == "statement") return ctx.indented + (firstChar == "{" ? 0 : indentUnit);
|
143 |
+
else if (ctx.align) return ctx.column + (closing ? 0 : 1);
|
144 |
+
else return ctx.indented + (closing ? 0 : indentUnit);
|
145 |
+
},
|
146 |
+
|
147 |
+
electricChars: "{}"
|
148 |
+
};
|
149 |
+
});
|
150 |
+
|
151 |
+
(function() {
|
152 |
+
function words(str) {
|
153 |
+
var obj = {}, words = str.split(" ");
|
154 |
+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
155 |
+
return obj;
|
156 |
+
}
|
157 |
+
var cKeywords = "auto if break int case long char register continue return default short do sizeof " +
|
158 |
+
"double static else struct entry switch extern typedef float union for unsigned " +
|
159 |
+
"goto while enum void const signed volatile";
|
160 |
+
|
161 |
+
function cppHook(stream, state) {
|
162 |
+
if (!state.startOfLine) return false;
|
163 |
+
stream.skipToEnd();
|
164 |
+
return "meta";
|
165 |
+
}
|
166 |
+
|
167 |
+
// C#-style strings where "" escapes a quote.
|
168 |
+
function tokenAtString(stream, state) {
|
169 |
+
var next;
|
170 |
+
while ((next = stream.next()) != null) {
|
171 |
+
if (next == '"' && !stream.eat('"')) {
|
172 |
+
state.tokenize = null;
|
173 |
+
break;
|
174 |
+
}
|
175 |
+
}
|
176 |
+
return "string";
|
177 |
+
}
|
178 |
+
|
179 |
+
CodeMirror.defineMIME("text/x-csrc", {
|
180 |
+
name: "clike",
|
181 |
+
keywords: words(cKeywords),
|
182 |
+
blockKeywords: words("case do else for if switch while struct"),
|
183 |
+
atoms: words("null"),
|
184 |
+
hooks: {"#": cppHook}
|
185 |
+
});
|
186 |
+
CodeMirror.defineMIME("text/x-c++src", {
|
187 |
+
name: "clike",
|
188 |
+
keywords: words(cKeywords + " asm dynamic_cast namespace reinterpret_cast try bool explicit new " +
|
189 |
+
"static_cast typeid catch operator template typename class friend private " +
|
190 |
+
"this using const_cast inline public throw virtual delete mutable protected " +
|
191 |
+
"wchar_t"),
|
192 |
+
blockKeywords: words("catch class do else finally for if struct switch try while"),
|
193 |
+
atoms: words("true false null"),
|
194 |
+
hooks: {"#": cppHook}
|
195 |
+
});
|
196 |
+
CodeMirror.defineMIME("text/x-java", {
|
197 |
+
name: "clike",
|
198 |
+
keywords: words("abstract assert boolean break byte case catch char class const continue default " +
|
199 |
+
"do double else enum extends final finally float for goto if implements import " +
|
200 |
+
"instanceof int interface long native new package private protected public " +
|
201 |
+
"return short static strictfp super switch synchronized this throw throws transient " +
|
202 |
+
"try void volatile while"),
|
203 |
+
blockKeywords: words("catch class do else finally for if switch try while"),
|
204 |
+
atoms: words("true false null"),
|
205 |
+
hooks: {
|
206 |
+
"@": function(stream, state) {
|
207 |
+
stream.eatWhile(/[\w\$_]/);
|
208 |
+
return "meta";
|
209 |
+
}
|
210 |
+
}
|
211 |
+
});
|
212 |
+
CodeMirror.defineMIME("text/x-csharp", {
|
213 |
+
name: "clike",
|
214 |
+
keywords: words("abstract as base bool break byte case catch char checked class const continue decimal" +
|
215 |
+
" default delegate do double else enum event explicit extern finally fixed float for" +
|
216 |
+
" foreach goto if implicit in int interface internal is lock long namespace new object" +
|
217 |
+
" operator out override params private protected public readonly ref return sbyte sealed short" +
|
218 |
+
" sizeof stackalloc static string struct switch this throw try typeof uint ulong unchecked" +
|
219 |
+
" unsafe ushort using virtual void volatile while add alias ascending descending dynamic from get" +
|
220 |
+
" global group into join let orderby partial remove select set value var yield"),
|
221 |
+
blockKeywords: words("catch class do else finally for foreach if struct switch try while"),
|
222 |
+
atoms: words("true false null"),
|
223 |
+
hooks: {
|
224 |
+
"@": function(stream, state) {
|
225 |
+
if (stream.eat('"')) {
|
226 |
+
state.tokenize = tokenAtString;
|
227 |
+
return tokenAtString(stream, state);
|
228 |
+
}
|
229 |
+
stream.eatWhile(/[\w\$_]/);
|
230 |
+
return "meta";
|
231 |
+
}
|
232 |
+
}
|
233 |
+
});
|
234 |
+
CodeMirror.defineMIME("text/x-groovy", {
|
235 |
+
name: "clike",
|
236 |
+
keywords: words("abstract as assert boolean break byte case catch char class const continue def default " +
|
237 |
+
"do double else enum extends final finally float for goto if implements import " +
|
238 |
+
"in instanceof int interface long native new package property private protected public " +
|
239 |
+
"return short static strictfp super switch synchronized this throw throws transient " +
|
240 |
+
"try void volatile while"),
|
241 |
+
atoms: words("true false null"),
|
242 |
+
hooks: {
|
243 |
+
"@": function(stream, state) {
|
244 |
+
stream.eatWhile(/[\w\$_]/);
|
245 |
+
return "meta";
|
246 |
+
}
|
247 |
+
}
|
248 |
+
});
|
249 |
+
}());
|
extensions/codemirror/js/codemirror.js
ADDED
@@ -0,0 +1,2761 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// CodeMirror version 2.2
|
2 |
+
//
|
3 |
+
// All functions that need access to the editor's state live inside
|
4 |
+
// the CodeMirror function. Below that, at the bottom of the file,
|
5 |
+
// some utilities are defined.
|
6 |
+
|
7 |
+
// CodeMirror is the only global var we claim
|
8 |
+
var CodeMirror = (function() {
|
9 |
+
// This is the function that produces an editor instance. It's
|
10 |
+
// closure is used to store the editor state.
|
11 |
+
function CodeMirror(place, givenOptions) {
|
12 |
+
// Determine effective options based on given values and defaults.
|
13 |
+
var options = {}, defaults = CodeMirror.defaults;
|
14 |
+
for (var opt in defaults)
|
15 |
+
if (defaults.hasOwnProperty(opt))
|
16 |
+
options[opt] = (givenOptions && givenOptions.hasOwnProperty(opt) ? givenOptions : defaults)[opt];
|
17 |
+
|
18 |
+
var targetDocument = options["document"];
|
19 |
+
// The element in which the editor lives.
|
20 |
+
var wrapper = targetDocument.createElement("div");
|
21 |
+
wrapper.className = "CodeMirror" + (options.lineWrapping ? " CodeMirror-wrap" : "");
|
22 |
+
// This mess creates the base DOM structure for the editor.
|
23 |
+
wrapper.innerHTML =
|
24 |
+
'<div style="overflow: hidden; position: relative; width: 3px; height: 0px;">' + // Wraps and hides input textarea
|
25 |
+
'<textarea style="position: absolute; padding: 0; width: 1px;" wrap="off" ' +
|
26 |
+
'autocorrect="off" autocapitalize="off"></textarea></div>' +
|
27 |
+
'<div class="CodeMirror-scroll" tabindex="-1">' +
|
28 |
+
'<div style="position: relative">' + // Set to the height of the text, causes scrolling
|
29 |
+
'<div style="position: relative">' + // Moved around its parent to cover visible view
|
30 |
+
'<div class="CodeMirror-gutter"><div class="CodeMirror-gutter-text"></div></div>' +
|
31 |
+
// Provides positioning relative to (visible) text origin
|
32 |
+
'<div class="CodeMirror-lines"><div style="position: relative">' +
|
33 |
+
'<div style="position: absolute; width: 100%; height: 0; overflow: hidden; visibility: hidden"></div>' +
|
34 |
+
'<pre class="CodeMirror-cursor"> </pre>' + // Absolutely positioned blinky cursor
|
35 |
+
'<div></div>' + // This DIV contains the actual code
|
36 |
+
'</div></div></div></div></div>';
|
37 |
+
if (place.appendChild) place.appendChild(wrapper); else place(wrapper);
|
38 |
+
// I've never seen more elegant code in my life.
|
39 |
+
var inputDiv = wrapper.firstChild, input = inputDiv.firstChild,
|
40 |
+
scroller = wrapper.lastChild, code = scroller.firstChild,
|
41 |
+
mover = code.firstChild, gutter = mover.firstChild, gutterText = gutter.firstChild,
|
42 |
+
lineSpace = gutter.nextSibling.firstChild, measure = lineSpace.firstChild,
|
43 |
+
cursor = measure.nextSibling, lineDiv = cursor.nextSibling;
|
44 |
+
themeChanged();
|
45 |
+
// Needed to hide big blue blinking cursor on Mobile Safari
|
46 |
+
if (/AppleWebKit/.test(navigator.userAgent) && /Mobile\/\w+/.test(navigator.userAgent)) input.style.width = "0px";
|
47 |
+
if (!webkit) lineSpace.draggable = true;
|
48 |
+
if (options.tabindex != null) input.tabIndex = options.tabindex;
|
49 |
+
if (!options.gutter && !options.lineNumbers) gutter.style.display = "none";
|
50 |
+
|
51 |
+
// Check for problem with IE innerHTML not working when we have a
|
52 |
+
// P (or similar) parent node.
|
53 |
+
try { stringWidth("x"); }
|
54 |
+
catch (e) {
|
55 |
+
if (e.message.match(/runtime/i))
|
56 |
+
e = new Error("A CodeMirror inside a P-style element does not work in Internet Explorer. (innerHTML bug)");
|
57 |
+
throw e;
|
58 |
+
}
|
59 |
+
|
60 |
+
// Delayed object wrap timeouts, making sure only one is active. blinker holds an interval.
|
61 |
+
var poll = new Delayed(), highlight = new Delayed(), blinker;
|
62 |
+
|
63 |
+
// mode holds a mode API object. doc is the tree of Line objects,
|
64 |
+
// work an array of lines that should be parsed, and history the
|
65 |
+
// undo history (instance of History constructor).
|
66 |
+
var mode, doc = new BranchChunk([new LeafChunk([new Line("")])]), work, focused;
|
67 |
+
loadMode();
|
68 |
+
// The selection. These are always maintained to point at valid
|
69 |
+
// positions. Inverted is used to remember that the user is
|
70 |
+
// selecting bottom-to-top.
|
71 |
+
var sel = {from: {line: 0, ch: 0}, to: {line: 0, ch: 0}, inverted: false};
|
72 |
+
// Selection-related flags. shiftSelecting obviously tracks
|
73 |
+
// whether the user is holding shift.
|
74 |
+
var shiftSelecting, lastClick, lastDoubleClick, draggingText, overwrite = false;
|
75 |
+
// Variables used by startOperation/endOperation to track what
|
76 |
+
// happened during the operation.
|
77 |
+
var updateInput, userSelChange, changes, textChanged, selectionChanged, leaveInputAlone,
|
78 |
+
gutterDirty, callbacks;
|
79 |
+
// Current visible range (may be bigger than the view window).
|
80 |
+
var displayOffset = 0, showingFrom = 0, showingTo = 0, lastSizeC = 0;
|
81 |
+
// bracketHighlighted is used to remember that a backet has been
|
82 |
+
// marked.
|
83 |
+
var bracketHighlighted;
|
84 |
+
// Tracks the maximum line length so that the horizontal scrollbar
|
85 |
+
// can be kept static when scrolling.
|
86 |
+
var maxLine = "", maxWidth, tabText = computeTabText();
|
87 |
+
|
88 |
+
// Initialize the content.
|
89 |
+
operation(function(){setValue(options.value || ""); updateInput = false;})();
|
90 |
+
var history = new History();
|
91 |
+
|
92 |
+
// Register our event handlers.
|
93 |
+
connect(scroller, "mousedown", operation(onMouseDown));
|
94 |
+
connect(scroller, "dblclick", operation(onDoubleClick));
|
95 |
+
connect(lineSpace, "dragstart", onDragStart);
|
96 |
+
connect(lineSpace, "selectstart", e_preventDefault);
|
97 |
+
// Gecko browsers fire contextmenu *after* opening the menu, at
|
98 |
+
// which point we can't mess with it anymore. Context menu is
|
99 |
+
// handled in onMouseDown for Gecko.
|
100 |
+
if (!gecko) connect(scroller, "contextmenu", onContextMenu);
|
101 |
+
connect(scroller, "scroll", function() {
|
102 |
+
updateDisplay([]);
|
103 |
+
if (options.fixedGutter) gutter.style.left = scroller.scrollLeft + "px";
|
104 |
+
if (options.onScroll) options.onScroll(instance);
|
105 |
+
});
|
106 |
+
connect(window, "resize", function() {updateDisplay(true);});
|
107 |
+
connect(input, "keyup", operation(onKeyUp));
|
108 |
+
connect(input, "input", fastPoll);
|
109 |
+
connect(input, "keydown", operation(onKeyDown));
|
110 |
+
connect(input, "keypress", operation(onKeyPress));
|
111 |
+
connect(input, "focus", onFocus);
|
112 |
+
connect(input, "blur", onBlur);
|
113 |
+
|
114 |
+
connect(scroller, "dragenter", e_stop);
|
115 |
+
connect(scroller, "dragover", e_stop);
|
116 |
+
connect(scroller, "drop", operation(onDrop));
|
117 |
+
connect(scroller, "paste", function(){focusInput(); fastPoll();});
|
118 |
+
connect(input, "paste", fastPoll);
|
119 |
+
connect(input, "cut", operation(function(){replaceSelection("");}));
|
120 |
+
|
121 |
+
// IE throws unspecified error in certain cases, when
|
122 |
+
// trying to access activeElement before onload
|
123 |
+
var hasFocus; try { hasFocus = (targetDocument.activeElement == input); } catch(e) { }
|
124 |
+
if (hasFocus) setTimeout(onFocus, 20);
|
125 |
+
else onBlur();
|
126 |
+
|
127 |
+
function isLine(l) {return l >= 0 && l < doc.size;}
|
128 |
+
// The instance object that we'll return. Mostly calls out to
|
129 |
+
// local functions in the CodeMirror function. Some do some extra
|
130 |
+
// range checking and/or clipping. operation is used to wrap the
|
131 |
+
// call so that changes it makes are tracked, and the display is
|
132 |
+
// updated afterwards.
|
133 |
+
var instance = wrapper.CodeMirror = {
|
134 |
+
getValue: getValue,
|
135 |
+
setValue: operation(setValue),
|
136 |
+
getSelection: getSelection,
|
137 |
+
replaceSelection: operation(replaceSelection),
|
138 |
+
focus: function(){focusInput(); onFocus(); fastPoll();},
|
139 |
+
setOption: function(option, value) {
|
140 |
+
var oldVal = options[option];
|
141 |
+
options[option] = value;
|
142 |
+
if (option == "mode" || option == "indentUnit") loadMode();
|
143 |
+
else if (option == "readOnly" && value) {onBlur(); input.blur();}
|
144 |
+
else if (option == "theme") themeChanged();
|
145 |
+
else if (option == "lineWrapping" && oldVal != value) operation(wrappingChanged)();
|
146 |
+
else if (option == "tabSize") operation(tabsChanged)();
|
147 |
+
if (option == "lineNumbers" || option == "gutter" || option == "firstLineNumber" || option == "theme")
|
148 |
+
operation(gutterChanged)();
|
149 |
+
},
|
150 |
+
getOption: function(option) {return options[option];},
|
151 |
+
undo: operation(undo),
|
152 |
+
redo: operation(redo),
|
153 |
+
indentLine: operation(function(n, dir) {
|
154 |
+
if (isLine(n)) indentLine(n, dir == null ? "smart" : dir ? "add" : "subtract");
|
155 |
+
}),
|
156 |
+
indentSelection: operation(indentSelected),
|
157 |
+
historySize: function() {return {undo: history.done.length, redo: history.undone.length};},
|
158 |
+
clearHistory: function() {history = new History();},
|
159 |
+
matchBrackets: operation(function(){matchBrackets(true);}),
|
160 |
+
getTokenAt: operation(function(pos) {
|
161 |
+
pos = clipPos(pos);
|
162 |
+
return getLine(pos.line).getTokenAt(mode, getStateBefore(pos.line), pos.ch);
|
163 |
+
}),
|
164 |
+
getStateAfter: function(line) {
|
165 |
+
line = clipLine(line == null ? doc.size - 1: line);
|
166 |
+
return getStateBefore(line + 1);
|
167 |
+
},
|
168 |
+
cursorCoords: function(start){
|
169 |
+
if (start == null) start = sel.inverted;
|
170 |
+
return pageCoords(start ? sel.from : sel.to);
|
171 |
+
},
|
172 |
+
charCoords: function(pos){return pageCoords(clipPos(pos));},
|
173 |
+
coordsChar: function(coords) {
|
174 |
+
var off = eltOffset(lineSpace);
|
175 |
+
return coordsChar(coords.x - off.left, coords.y - off.top);
|
176 |
+
},
|
177 |
+
markText: operation(markText),
|
178 |
+
setBookmark: setBookmark,
|
179 |
+
setMarker: operation(addGutterMarker),
|
180 |
+
clearMarker: operation(removeGutterMarker),
|
181 |
+
setLineClass: operation(setLineClass),
|
182 |
+
hideLine: operation(function(h) {return setLineHidden(h, true);}),
|
183 |
+
showLine: operation(function(h) {return setLineHidden(h, false);}),
|
184 |
+
onDeleteLine: function(line, f) {
|
185 |
+
if (typeof line == "number") {
|
186 |
+
if (!isLine(line)) return null;
|
187 |
+
line = getLine(line);
|
188 |
+
}
|
189 |
+
(line.handlers || (line.handlers = [])).push(f);
|
190 |
+
return line;
|
191 |
+
},
|
192 |
+
lineInfo: lineInfo,
|
193 |
+
addWidget: function(pos, node, scroll, vert, horiz) {
|
194 |
+
pos = localCoords(clipPos(pos));
|
195 |
+
var top = pos.yBot, left = pos.x;
|
196 |
+
node.style.position = "absolute";
|
197 |
+
code.appendChild(node);
|
198 |
+
if (vert == "over") top = pos.y;
|
199 |
+
else if (vert == "near") {
|
200 |
+
var vspace = Math.max(scroller.offsetHeight, doc.height * textHeight()),
|
201 |
+
hspace = Math.max(code.clientWidth, lineSpace.clientWidth) - paddingLeft();
|
202 |
+
if (pos.yBot + node.offsetHeight > vspace && pos.y > node.offsetHeight)
|
203 |
+
top = pos.y - node.offsetHeight;
|
204 |
+
if (left + node.offsetWidth > hspace)
|
205 |
+
left = hspace - node.offsetWidth;
|
206 |
+
}
|
207 |
+
node.style.top = (top + paddingTop()) + "px";
|
208 |
+
node.style.left = node.style.right = "";
|
209 |
+
if (horiz == "right") {
|
210 |
+
left = code.clientWidth - node.offsetWidth;
|
211 |
+
node.style.right = "0px";
|
212 |
+
} else {
|
213 |
+
if (horiz == "left") left = 0;
|
214 |
+
else if (horiz == "middle") left = (code.clientWidth - node.offsetWidth) / 2;
|
215 |
+
node.style.left = (left + paddingLeft()) + "px";
|
216 |
+
}
|
217 |
+
if (scroll)
|
218 |
+
scrollIntoView(left, top, left + node.offsetWidth, top + node.offsetHeight);
|
219 |
+
},
|
220 |
+
|
221 |
+
lineCount: function() {return doc.size;},
|
222 |
+
clipPos: clipPos,
|
223 |
+
getCursor: function(start) {
|
224 |
+
if (start == null) start = sel.inverted;
|
225 |
+
return copyPos(start ? sel.from : sel.to);
|
226 |
+
},
|
227 |
+
somethingSelected: function() {return !posEq(sel.from, sel.to);},
|
228 |
+
setCursor: operation(function(line, ch, user) {
|
229 |
+
if (ch == null && typeof line.line == "number") setCursor(line.line, line.ch, user);
|
230 |
+
else setCursor(line, ch, user);
|
231 |
+
}),
|
232 |
+
setSelection: operation(function(from, to, user) {
|
233 |
+
(user ? setSelectionUser : setSelection)(clipPos(from), clipPos(to || from));
|
234 |
+
}),
|
235 |
+
getLine: function(line) {if (isLine(line)) return getLine(line).text;},
|
236 |
+
getLineHandle: function(line) {if (isLine(line)) return getLine(line);},
|
237 |
+
setLine: operation(function(line, text) {
|
238 |
+
if (isLine(line)) replaceRange(text, {line: line, ch: 0}, {line: line, ch: getLine(line).text.length});
|
239 |
+
}),
|
240 |
+
removeLine: operation(function(line) {
|
241 |
+
if (isLine(line)) replaceRange("", {line: line, ch: 0}, clipPos({line: line+1, ch: 0}));
|
242 |
+
}),
|
243 |
+
replaceRange: operation(replaceRange),
|
244 |
+
getRange: function(from, to) {return getRange(clipPos(from), clipPos(to));},
|
245 |
+
|
246 |
+
execCommand: function(cmd) {return commands[cmd](instance);},
|
247 |
+
// Stuff used by commands, probably not much use to outside code.
|
248 |
+
moveH: operation(moveH),
|
249 |
+
deleteH: operation(deleteH),
|
250 |
+
moveV: operation(moveV),
|
251 |
+
toggleOverwrite: function() {overwrite = !overwrite;},
|
252 |
+
|
253 |
+
posFromIndex: function(off) {
|
254 |
+
var lineNo = 0, ch;
|
255 |
+
doc.iter(0, doc.size, function(line) {
|
256 |
+
var sz = line.text.length + 1;
|
257 |
+
if (sz > off) { ch = off; return true; }
|
258 |
+
off -= sz;
|
259 |
+
++lineNo;
|
260 |
+
});
|
261 |
+
return clipPos({line: lineNo, ch: ch});
|
262 |
+
},
|
263 |
+
indexFromPos: function (coords) {
|
264 |
+
if (coords.line < 0 || coords.ch < 0) return 0;
|
265 |
+
var index = coords.ch;
|
266 |
+
doc.iter(0, coords.line, function (line) {
|
267 |
+
index += line.text.length + 1;
|
268 |
+
});
|
269 |
+
return index;
|
270 |
+
},
|
271 |
+
|
272 |
+
operation: function(f){return operation(f)();},
|
273 |
+
refresh: function(){updateDisplay(true);},
|
274 |
+
getInputField: function(){return input;},
|
275 |
+
getWrapperElement: function(){return wrapper;},
|
276 |
+
getScrollerElement: function(){return scroller;},
|
277 |
+
getGutterElement: function(){return gutter;}
|
278 |
+
};
|
279 |
+
|
280 |
+
function getLine(n) { return getLineAt(doc, n); }
|
281 |
+
function updateLineHeight(line, height) {
|
282 |
+
gutterDirty = true;
|
283 |
+
var diff = height - line.height;
|
284 |
+
for (var n = line; n; n = n.parent) n.height += diff;
|
285 |
+
}
|
286 |
+
|
287 |
+
function setValue(code) {
|
288 |
+
var top = {line: 0, ch: 0};
|
289 |
+
updateLines(top, {line: doc.size - 1, ch: getLine(doc.size-1).text.length},
|
290 |
+
splitLines(code), top, top);
|
291 |
+
updateInput = true;
|
292 |
+
}
|
293 |
+
function getValue(code) {
|
294 |
+
var text = [];
|
295 |
+
doc.iter(0, doc.size, function(line) { text.push(line.text); });
|
296 |
+
return text.join("\n");
|
297 |
+
}
|
298 |
+
|
299 |
+
function onMouseDown(e) {
|
300 |
+
setShift(e.shiftKey);
|
301 |
+
// Check whether this is a click in a widget
|
302 |
+
for (var n = e_target(e); n != wrapper; n = n.parentNode)
|
303 |
+
if (n.parentNode == code && n != mover) return;
|
304 |
+
|
305 |
+
// See if this is a click in the gutter
|
306 |
+
for (var n = e_target(e); n != wrapper; n = n.parentNode)
|
307 |
+
if (n.parentNode == gutterText) {
|
308 |
+
if (options.onGutterClick)
|
309 |
+
options.onGutterClick(instance, indexOf(gutterText.childNodes, n) + showingFrom, e);
|
310 |
+
return e_preventDefault(e);
|
311 |
+
}
|
312 |
+
|
313 |
+
var start = posFromMouse(e);
|
314 |
+
|
315 |
+
switch (e_button(e)) {
|
316 |
+
case 3:
|
317 |
+
if (gecko && !mac) onContextMenu(e);
|
318 |
+
return;
|
319 |
+
case 2:
|
320 |
+
if (start) setCursor(start.line, start.ch, true);
|
321 |
+
return;
|
322 |
+
}
|
323 |
+
// For button 1, if it was clicked inside the editor
|
324 |
+
// (posFromMouse returning non-null), we have to adjust the
|
325 |
+
// selection.
|
326 |
+
if (!start) {if (e_target(e) == scroller) e_preventDefault(e); return;}
|
327 |
+
|
328 |
+
if (!focused) onFocus();
|
329 |
+
|
330 |
+
var now = +new Date;
|
331 |
+
if (lastDoubleClick && lastDoubleClick.time > now - 400 && posEq(lastDoubleClick.pos, start)) {
|
332 |
+
e_preventDefault(e);
|
333 |
+
setTimeout(focusInput, 20);
|
334 |
+
return selectLine(start.line);
|
335 |
+
} else if (lastClick && lastClick.time > now - 400 && posEq(lastClick.pos, start)) {
|
336 |
+
lastDoubleClick = {time: now, pos: start};
|
337 |
+
e_preventDefault(e);
|
338 |
+
return selectWordAt(start);
|
339 |
+
} else { lastClick = {time: now, pos: start}; }
|
340 |
+
|
341 |
+
var last = start, going;
|
342 |
+
if (dragAndDrop && !posEq(sel.from, sel.to) &&
|
343 |
+
!posLess(start, sel.from) && !posLess(sel.to, start)) {
|
344 |
+
// Let the drag handler handle this.
|
345 |
+
if (webkit) lineSpace.draggable = true;
|
346 |
+
var up = connect(targetDocument, "mouseup", operation(function(e2) {
|
347 |
+
if (webkit) lineSpace.draggable = false;
|
348 |
+
draggingText = false;
|
349 |
+
up();
|
350 |
+
if (Math.abs(e.clientX - e2.clientX) + Math.abs(e.clientY - e2.clientY) < 10) {
|
351 |
+
e_preventDefault(e2);
|
352 |
+
setCursor(start.line, start.ch, true);
|
353 |
+
focusInput();
|
354 |
+
}
|
355 |
+
}), true);
|
356 |
+
draggingText = true;
|
357 |
+
return;
|
358 |
+
}
|
359 |
+
e_preventDefault(e);
|
360 |
+
setCursor(start.line, start.ch, true);
|
361 |
+
|
362 |
+
function extend(e) {
|
363 |
+
var cur = posFromMouse(e, true);
|
364 |
+
if (cur && !posEq(cur, last)) {
|
365 |
+
if (!focused) onFocus();
|
366 |
+
last = cur;
|
367 |
+
setSelectionUser(start, cur);
|
368 |
+
updateInput = false;
|
369 |
+
var visible = visibleLines();
|
370 |
+
if (cur.line >= visible.to || cur.line < visible.from)
|
371 |
+
going = setTimeout(operation(function(){extend(e);}), 150);
|
372 |
+
}
|
373 |
+
}
|
374 |
+
|
375 |
+
var move = connect(targetDocument, "mousemove", operation(function(e) {
|
376 |
+
clearTimeout(going);
|
377 |
+
e_preventDefault(e);
|
378 |
+
extend(e);
|
379 |
+
}), true);
|
380 |
+
var up = connect(targetDocument, "mouseup", operation(function(e) {
|
381 |
+
clearTimeout(going);
|
382 |
+
var cur = posFromMouse(e);
|
383 |
+
if (cur) setSelectionUser(start, cur);
|
384 |
+
e_preventDefault(e);
|
385 |
+
focusInput();
|
386 |
+
updateInput = true;
|
387 |
+
move(); up();
|
388 |
+
}), true);
|
389 |
+
}
|
390 |
+
function onDoubleClick(e) {
|
391 |
+
for (var n = e_target(e); n != wrapper; n = n.parentNode)
|
392 |
+
if (n.parentNode == gutterText) return e_preventDefault(e);
|
393 |
+
var start = posFromMouse(e);
|
394 |
+
if (!start) return;
|
395 |
+
lastDoubleClick = {time: +new Date, pos: start};
|
396 |
+
e_preventDefault(e);
|
397 |
+
selectWordAt(start);
|
398 |
+
}
|
399 |
+
function onDrop(e) {
|
400 |
+
e.preventDefault();
|
401 |
+
var pos = posFromMouse(e, true), files = e.dataTransfer.files;
|
402 |
+
if (!pos || options.readOnly) return;
|
403 |
+
if (files && files.length && window.FileReader && window.File) {
|
404 |
+
function loadFile(file, i) {
|
405 |
+
var reader = new FileReader;
|
406 |
+
reader.onload = function() {
|
407 |
+
text[i] = reader.result;
|
408 |
+
if (++read == n) {
|
409 |
+
pos = clipPos(pos);
|
410 |
+
operation(function() {
|
411 |
+
var end = replaceRange(text.join(""), pos, pos);
|
412 |
+
setSelectionUser(pos, end);
|
413 |
+
})();
|
414 |
+
}
|
415 |
+
};
|
416 |
+
reader.readAsText(file);
|
417 |
+
}
|
418 |
+
var n = files.length, text = Array(n), read = 0;
|
419 |
+
for (var i = 0; i < n; ++i) loadFile(files[i], i);
|
420 |
+
}
|
421 |
+
else {
|
422 |
+
try {
|
423 |
+
var text = e.dataTransfer.getData("Text");
|
424 |
+
if (text) {
|
425 |
+
var end = replaceRange(text, pos, pos);
|
426 |
+
var curFrom = sel.from, curTo = sel.to;
|
427 |
+
setSelectionUser(pos, end);
|
428 |
+
if (draggingText) replaceRange("", curFrom, curTo);
|
429 |
+
focusInput();
|
430 |
+
}
|
431 |
+
}
|
432 |
+
catch(e){}
|
433 |
+
}
|
434 |
+
}
|
435 |
+
function onDragStart(e) {
|
436 |
+
var txt = getSelection();
|
437 |
+
// This will reset escapeElement
|
438 |
+
htmlEscape(txt);
|
439 |
+
e.dataTransfer.setDragImage(escapeElement, 0, 0);
|
440 |
+
e.dataTransfer.setData("Text", txt);
|
441 |
+
}
|
442 |
+
function handleKeyBinding(e) {
|
443 |
+
var name = keyNames[e.keyCode], next = keyMap[options.keyMap].auto, bound, dropShift;
|
444 |
+
if (name == null || e.altGraphKey) {
|
445 |
+
if (next) options.keyMap = next;
|
446 |
+
return null;
|
447 |
+
}
|
448 |
+
if (e.altKey) name = "Alt-" + name;
|
449 |
+
if (e.ctrlKey) name = "Ctrl-" + name;
|
450 |
+
if (e.metaKey) name = "Cmd-" + name;
|
451 |
+
if (e.shiftKey && (bound = lookupKey("Shift-" + name, options.extraKeys, options.keyMap))) {
|
452 |
+
dropShift = true;
|
453 |
+
} else {
|
454 |
+
bound = lookupKey(name, options.extraKeys, options.keyMap);
|
455 |
+
}
|
456 |
+
if (typeof bound == "string") {
|
457 |
+
if (commands.propertyIsEnumerable(bound)) bound = commands[bound];
|
458 |
+
else bound = null;
|
459 |
+
}
|
460 |
+
if (next && (bound || !isModifierKey(e))) options.keyMap = next;
|
461 |
+
if (!bound) return false;
|
462 |
+
if (dropShift) {
|
463 |
+
var prevShift = shiftSelecting;
|
464 |
+
shiftSelecting = null;
|
465 |
+
bound(instance);
|
466 |
+
shiftSelecting = prevShift;
|
467 |
+
} else bound(instance);
|
468 |
+
e_preventDefault(e);
|
469 |
+
return true;
|
470 |
+
}
|
471 |
+
var lastStoppedKey = null;
|
472 |
+
function onKeyDown(e) {
|
473 |
+
if (!focused) onFocus();
|
474 |
+
var code = e.keyCode;
|
475 |
+
// IE does strange things with escape.
|
476 |
+
if (ie && code == 27) { e.returnValue = false; }
|
477 |
+
setShift(code == 16 || e.shiftKey);
|
478 |
+
// First give onKeyEvent option a chance to handle this.
|
479 |
+
if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
|
480 |
+
var handled = handleKeyBinding(e);
|
481 |
+
if (window.opera) {
|
482 |
+
lastStoppedKey = handled ? e.keyCode : null;
|
483 |
+
// Opera has no cut event... we try to at least catch the key combo
|
484 |
+
if (!handled && (mac ? e.metaKey : e.ctrlKey) && e.keyCode == 88)
|
485 |
+
replaceSelection("");
|
486 |
+
}
|
487 |
+
}
|
488 |
+
function onKeyPress(e) {
|
489 |
+
if (window.opera && e.keyCode == lastStoppedKey) {lastStoppedKey = null; e_preventDefault(e); return;}
|
490 |
+
if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
|
491 |
+
if (window.opera && !e.which && handleKeyBinding(e)) return;
|
492 |
+
if (options.electricChars && mode.electricChars) {
|
493 |
+
var ch = String.fromCharCode(e.charCode == null ? e.keyCode : e.charCode);
|
494 |
+
if (mode.electricChars.indexOf(ch) > -1)
|
495 |
+
setTimeout(operation(function() {indentLine(sel.to.line, "smart");}), 75);
|
496 |
+
}
|
497 |
+
fastPoll();
|
498 |
+
}
|
499 |
+
function onKeyUp(e) {
|
500 |
+
if (options.onKeyEvent && options.onKeyEvent(instance, addStop(e))) return;
|
501 |
+
if (e.keyCode == 16) shiftSelecting = null;
|
502 |
+
}
|
503 |
+
|
504 |
+
function onFocus() {
|
505 |
+
if (options.readOnly) return;
|
506 |
+
if (!focused) {
|
507 |
+
if (options.onFocus) options.onFocus(instance);
|
508 |
+
focused = true;
|
509 |
+
if (wrapper.className.search(/\bCodeMirror-focused\b/) == -1)
|
510 |
+
wrapper.className += " CodeMirror-focused";
|
511 |
+
if (!leaveInputAlone) resetInput(true);
|
512 |
+
}
|
513 |
+
slowPoll();
|
514 |
+
restartBlink();
|
515 |
+
}
|
516 |
+
function onBlur() {
|
517 |
+
if (focused) {
|
518 |
+
if (options.onBlur) options.onBlur(instance);
|
519 |
+
focused = false;
|
520 |
+
wrapper.className = wrapper.className.replace(" CodeMirror-focused", "");
|
521 |
+
}
|
522 |
+
clearInterval(blinker);
|
523 |
+
setTimeout(function() {if (!focused) shiftSelecting = null;}, 150);
|
524 |
+
}
|
525 |
+
|
526 |
+
// Replace the range from from to to by the strings in newText.
|
527 |
+
// Afterwards, set the selection to selFrom, selTo.
|
528 |
+
function updateLines(from, to, newText, selFrom, selTo) {
|
529 |
+
if (history) {
|
530 |
+
var old = [];
|
531 |
+
doc.iter(from.line, to.line + 1, function(line) { old.push(line.text); });
|
532 |
+
history.addChange(from.line, newText.length, old);
|
533 |
+
while (history.done.length > options.undoDepth) history.done.shift();
|
534 |
+
}
|
535 |
+
updateLinesNoUndo(from, to, newText, selFrom, selTo);
|
536 |
+
}
|
537 |
+
function unredoHelper(from, to) {
|
538 |
+
var change = from.pop();
|
539 |
+
if (change) {
|
540 |
+
var replaced = [], end = change.start + change.added;
|
541 |
+
doc.iter(change.start, end, function(line) { replaced.push(line.text); });
|
542 |
+
to.push({start: change.start, added: change.old.length, old: replaced});
|
543 |
+
var pos = clipPos({line: change.start + change.old.length - 1,
|
544 |
+
ch: editEnd(replaced[replaced.length-1], change.old[change.old.length-1])});
|
545 |
+
updateLinesNoUndo({line: change.start, ch: 0}, {line: end - 1, ch: getLine(end-1).text.length}, change.old, pos, pos);
|
546 |
+
updateInput = true;
|
547 |
+
}
|
548 |
+
}
|
549 |
+
function undo() {unredoHelper(history.done, history.undone);}
|
550 |
+
function redo() {unredoHelper(history.undone, history.done);}
|
551 |
+
|
552 |
+
function updateLinesNoUndo(from, to, newText, selFrom, selTo) {
|
553 |
+
var recomputeMaxLength = false, maxLineLength = maxLine.length;
|
554 |
+
if (!options.lineWrapping)
|
555 |
+
doc.iter(from.line, to.line, function(line) {
|
556 |
+
if (line.text.length == maxLineLength) {recomputeMaxLength = true; return true;}
|
557 |
+
});
|
558 |
+
if (from.line != to.line || newText.length > 1) gutterDirty = true;
|
559 |
+
|
560 |
+
var nlines = to.line - from.line, firstLine = getLine(from.line), lastLine = getLine(to.line);
|
561 |
+
// First adjust the line structure, taking some care to leave highlighting intact.
|
562 |
+
if (from.ch == 0 && to.ch == 0 && newText[newText.length - 1] == "") {
|
563 |
+
// This is a whole-line replace. Treated specially to make
|
564 |
+
// sure line objects move the way they are supposed to.
|
565 |
+
var added = [], prevLine = null;
|
566 |
+
if (from.line) {
|
567 |
+
prevLine = getLine(from.line - 1);
|
568 |
+
prevLine.fixMarkEnds(lastLine);
|
569 |
+
} else lastLine.fixMarkStarts();
|
570 |
+
for (var i = 0, e = newText.length - 1; i < e; ++i)
|
571 |
+
added.push(Line.inheritMarks(newText[i], prevLine));
|
572 |
+
if (nlines) doc.remove(from.line, nlines, callbacks);
|
573 |
+
if (added.length) doc.insert(from.line, added);
|
574 |
+
} else if (firstLine == lastLine) {
|
575 |
+
if (newText.length == 1)
|
576 |
+
firstLine.replace(from.ch, to.ch, newText[0]);
|
577 |
+
else {
|
578 |
+
lastLine = firstLine.split(to.ch, newText[newText.length-1]);
|
579 |
+
firstLine.replace(from.ch, null, newText[0]);
|
580 |
+
firstLine.fixMarkEnds(lastLine);
|
581 |
+
var added = [];
|
582 |
+
for (var i = 1, e = newText.length - 1; i < e; ++i)
|
583 |
+
added.push(Line.inheritMarks(newText[i], firstLine));
|
584 |
+
added.push(lastLine);
|
585 |
+
doc.insert(from.line + 1, added);
|
586 |
+
}
|
587 |
+
} else if (newText.length == 1) {
|
588 |
+
firstLine.replace(from.ch, null, newText[0]);
|
589 |
+
lastLine.replace(null, to.ch, "");
|
590 |
+
firstLine.append(lastLine);
|
591 |
+
doc.remove(from.line + 1, nlines, callbacks);
|
592 |
+
} else {
|
593 |
+
var added = [];
|
594 |
+
firstLine.replace(from.ch, null, newText[0]);
|
595 |
+
lastLine.replace(null, to.ch, newText[newText.length-1]);
|
596 |
+
firstLine.fixMarkEnds(lastLine);
|
597 |
+
for (var i = 1, e = newText.length - 1; i < e; ++i)
|
598 |
+
added.push(Line.inheritMarks(newText[i], firstLine));
|
599 |
+
if (nlines > 1) doc.remove(from.line + 1, nlines - 1, callbacks);
|
600 |
+
doc.insert(from.line + 1, added);
|
601 |
+
}
|
602 |
+
if (options.lineWrapping) {
|
603 |
+
var perLine = scroller.clientWidth / charWidth() - 3;
|
604 |
+
doc.iter(from.line, from.line + newText.length, function(line) {
|
605 |
+
if (line.hidden) return;
|
606 |
+
var guess = Math.ceil(line.text.length / perLine) || 1;
|
607 |
+
if (guess != line.height) updateLineHeight(line, guess);
|
608 |
+
});
|
609 |
+
} else {
|
610 |
+
doc.iter(from.line, i + newText.length, function(line) {
|
611 |
+
var l = line.text;
|
612 |
+
if (l.length > maxLineLength) {
|
613 |
+
maxLine = l; maxLineLength = l.length; maxWidth = null;
|
614 |
+
recomputeMaxLength = false;
|
615 |
+
}
|
616 |
+
});
|
617 |
+
if (recomputeMaxLength) {
|
618 |
+
maxLineLength = 0; maxLine = ""; maxWidth = null;
|
619 |
+
doc.iter(0, doc.size, function(line) {
|
620 |
+
var l = line.text;
|
621 |
+
if (l.length > maxLineLength) {
|
622 |
+
maxLineLength = l.length; maxLine = l;
|
623 |
+
}
|
624 |
+
});
|
625 |
+
}
|
626 |
+
}
|
627 |
+
|
628 |
+
// Add these lines to the work array, so that they will be
|
629 |
+
// highlighted. Adjust work lines if lines were added/removed.
|
630 |
+
var newWork = [], lendiff = newText.length - nlines - 1;
|
631 |
+
for (var i = 0, l = work.length; i < l; ++i) {
|
632 |
+
var task = work[i];
|
633 |
+
if (task < from.line) newWork.push(task);
|
634 |
+
else if (task > to.line) newWork.push(task + lendiff);
|
635 |
+
}
|
636 |
+
var hlEnd = from.line + Math.min(newText.length, 500);
|
637 |
+
highlightLines(from.line, hlEnd);
|
638 |
+
newWork.push(hlEnd);
|
639 |
+
work = newWork;
|
640 |
+
startWorker(100);
|
641 |
+
// Remember that these lines changed, for updating the display
|
642 |
+
changes.push({from: from.line, to: to.line + 1, diff: lendiff});
|
643 |
+
var changeObj = {from: from, to: to, text: newText};
|
644 |
+
if (textChanged) {
|
645 |
+
for (var cur = textChanged; cur.next; cur = cur.next) {}
|
646 |
+
cur.next = changeObj;
|
647 |
+
} else textChanged = changeObj;
|
648 |
+
|
649 |
+
// Update the selection
|
650 |
+
function updateLine(n) {return n <= Math.min(to.line, to.line + lendiff) ? n : n + lendiff;}
|
651 |
+
setSelection(selFrom, selTo, updateLine(sel.from.line), updateLine(sel.to.line));
|
652 |
+
|
653 |
+
// Make sure the scroll-size div has the correct height.
|
654 |
+
code.style.height = (doc.height * textHeight() + 2 * paddingTop()) + "px";
|
655 |
+
}
|
656 |
+
|
657 |
+
function replaceRange(code, from, to) {
|
658 |
+
from = clipPos(from);
|
659 |
+
if (!to) to = from; else to = clipPos(to);
|
660 |
+
code = splitLines(code);
|
661 |
+
function adjustPos(pos) {
|
662 |
+
if (posLess(pos, from)) return pos;
|
663 |
+
if (!posLess(to, pos)) return end;
|
664 |
+
var line = pos.line + code.length - (to.line - from.line) - 1;
|
665 |
+
var ch = pos.ch;
|
666 |
+
if (pos.line == to.line)
|
667 |
+
ch += code[code.length-1].length - (to.ch - (to.line == from.line ? from.ch : 0));
|
668 |
+
return {line: line, ch: ch};
|
669 |
+
}
|
670 |
+
var end;
|
671 |
+
replaceRange1(code, from, to, function(end1) {
|
672 |
+
end = end1;
|
673 |
+
return {from: adjustPos(sel.from), to: adjustPos(sel.to)};
|
674 |
+
});
|
675 |
+
return end;
|
676 |
+
}
|
677 |
+
function replaceSelection(code, collapse) {
|
678 |
+
replaceRange1(splitLines(code), sel.from, sel.to, function(end) {
|
679 |
+
if (collapse == "end") return {from: end, to: end};
|
680 |
+
else if (collapse == "start") return {from: sel.from, to: sel.from};
|
681 |
+
else return {from: sel.from, to: end};
|
682 |
+
});
|
683 |
+
}
|
684 |
+
function replaceRange1(code, from, to, computeSel) {
|
685 |
+
var endch = code.length == 1 ? code[0].length + from.ch : code[code.length-1].length;
|
686 |
+
var newSel = computeSel({line: from.line + code.length - 1, ch: endch});
|
687 |
+
updateLines(from, to, code, newSel.from, newSel.to);
|
688 |
+
}
|
689 |
+
|
690 |
+
function getRange(from, to) {
|
691 |
+
var l1 = from.line, l2 = to.line;
|
692 |
+
if (l1 == l2) return getLine(l1).text.slice(from.ch, to.ch);
|
693 |
+
var code = [getLine(l1).text.slice(from.ch)];
|
694 |
+
doc.iter(l1 + 1, l2, function(line) { code.push(line.text); });
|
695 |
+
code.push(getLine(l2).text.slice(0, to.ch));
|
696 |
+
return code.join("\n");
|
697 |
+
}
|
698 |
+
function getSelection() {
|
699 |
+
return getRange(sel.from, sel.to);
|
700 |
+
}
|
701 |
+
|
702 |
+
var pollingFast = false; // Ensures slowPoll doesn't cancel fastPoll
|
703 |
+
function slowPoll() {
|
704 |
+
if (pollingFast) return;
|
705 |
+
poll.set(options.pollInterval, function() {
|
706 |
+
startOperation();
|
707 |
+
readInput();
|
708 |
+
if (focused) slowPoll();
|
709 |
+
endOperation();
|
710 |
+
});
|
711 |
+
}
|
712 |
+
function fastPoll() {
|
713 |
+
var missed = false;
|
714 |
+
pollingFast = true;
|
715 |
+
function p() {
|
716 |
+
startOperation();
|
717 |
+
var changed = readInput();
|
718 |
+
if (!changed && !missed) {missed = true; poll.set(60, p);}
|
719 |
+
else {pollingFast = false; slowPoll();}
|
720 |
+
endOperation();
|
721 |
+
}
|
722 |
+
poll.set(20, p);
|
723 |
+
}
|
724 |
+
|
725 |
+
// Previnput is a hack to work with IME. If we reset the textarea
|
726 |
+
// on every change, that breaks IME. So we look for changes
|
727 |
+
// compared to the previous content instead. (Modern browsers have
|
728 |
+
// events that indicate IME taking place, but these are not widely
|
729 |
+
// supported or compatible enough yet to rely on.)
|
730 |
+
var prevInput = "";
|
731 |
+
function readInput() {
|
732 |
+
if (leaveInputAlone || !focused || hasSelection(input)) return false;
|
733 |
+
var text = input.value;
|
734 |
+
if (text == prevInput) return false;
|
735 |
+
shiftSelecting = null;
|
736 |
+
var same = 0, l = Math.min(prevInput.length, text.length);
|
737 |
+
while (same < l && prevInput[same] == text[same]) ++same;
|
738 |
+
if (same < prevInput.length)
|
739 |
+
sel.from = {line: sel.from.line, ch: sel.from.ch - (prevInput.length - same)};
|
740 |
+
else if (overwrite && posEq(sel.from, sel.to))
|
741 |
+
sel.to = {line: sel.to.line, ch: Math.min(getLine(sel.to.line).text.length, sel.to.ch + (text.length - same))};
|
742 |
+
replaceSelection(text.slice(same), "end");
|
743 |
+
prevInput = text;
|
744 |
+
return true;
|
745 |
+
}
|
746 |
+
function resetInput(user) {
|
747 |
+
if (!posEq(sel.from, sel.to)) {
|
748 |
+
prevInput = "";
|
749 |
+
input.value = getSelection();
|
750 |
+
input.select();
|
751 |
+
} else if (user) prevInput = input.value = "";
|
752 |
+
}
|
753 |
+
|
754 |
+
function focusInput() {
|
755 |
+
if (!options.readOnly) input.focus();
|
756 |
+
}
|
757 |
+
|
758 |
+
function scrollEditorIntoView() {
|
759 |
+
if (!cursor.getBoundingClientRect) return;
|
760 |
+
var rect = cursor.getBoundingClientRect();
|
761 |
+
// IE returns bogus coordinates when the instance sits inside of an iframe and the cursor is hidden
|
762 |
+
if (ie && rect.top == rect.bottom) return;
|
763 |
+
var winH = window.innerHeight || Math.max(document.body.offsetHeight, document.documentElement.offsetHeight);
|
764 |
+
if (rect.top < 0 || rect.bottom > winH) cursor.scrollIntoView();
|
765 |
+
}
|
766 |
+
function scrollCursorIntoView() {
|
767 |
+
var cursor = localCoords(sel.inverted ? sel.from : sel.to);
|
768 |
+
var x = options.lineWrapping ? Math.min(cursor.x, lineSpace.offsetWidth) : cursor.x;
|
769 |
+
return scrollIntoView(x, cursor.y, x, cursor.yBot);
|
770 |
+
}
|
771 |
+
function scrollIntoView(x1, y1, x2, y2) {
|
772 |
+
var pl = paddingLeft(), pt = paddingTop(), lh = textHeight();
|
773 |
+
y1 += pt; y2 += pt; x1 += pl; x2 += pl;
|
774 |
+
var screen = scroller.clientHeight, screentop = scroller.scrollTop, scrolled = false, result = true;
|
775 |
+
if (y1 < screentop) {scroller.scrollTop = Math.max(0, y1 - 2*lh); scrolled = true;}
|
776 |
+
else if (y2 > screentop + screen) {scroller.scrollTop = y2 + lh - screen; scrolled = true;}
|
777 |
+
|
778 |
+
var screenw = scroller.clientWidth, screenleft = scroller.scrollLeft;
|
779 |
+
var gutterw = options.fixedGutter ? gutter.clientWidth : 0;
|
780 |
+
if (x1 < screenleft + gutterw) {
|
781 |
+
if (x1 < 50) x1 = 0;
|
782 |
+
scroller.scrollLeft = Math.max(0, x1 - 10 - gutterw);
|
783 |
+
scrolled = true;
|
784 |
+
}
|
785 |
+
else if (x2 > screenw + screenleft - 3) {
|
786 |
+
scroller.scrollLeft = x2 + 10 - screenw;
|
787 |
+
scrolled = true;
|
788 |
+
if (x2 > code.clientWidth) result = false;
|
789 |
+
}
|
790 |
+
if (scrolled && options.onScroll) options.onScroll(instance);
|
791 |
+
return result;
|
792 |
+
}
|
793 |
+
|
794 |
+
function visibleLines() {
|
795 |
+
var lh = textHeight(), top = scroller.scrollTop - paddingTop();
|
796 |
+
var from_height = Math.max(0, Math.floor(top / lh));
|
797 |
+
var to_height = Math.ceil((top + scroller.clientHeight) / lh);
|
798 |
+
return {from: lineAtHeight(doc, from_height),
|
799 |
+
to: lineAtHeight(doc, to_height)};
|
800 |
+
}
|
801 |
+
// Uses a set of changes plus the current scroll position to
|
802 |
+
// determine which DOM updates have to be made, and makes the
|
803 |
+
// updates.
|
804 |
+
function updateDisplay(changes, suppressCallback) {
|
805 |
+
if (!scroller.clientWidth) {
|
806 |
+
showingFrom = showingTo = displayOffset = 0;
|
807 |
+
return;
|
808 |
+
}
|
809 |
+
// Compute the new visible window
|
810 |
+
var visible = visibleLines();
|
811 |
+
// Bail out if the visible area is already rendered and nothing changed.
|
812 |
+
if (changes !== true && changes.length == 0 && visible.from >= showingFrom && visible.to <= showingTo) return;
|
813 |
+
var from = Math.max(visible.from - 100, 0), to = Math.min(doc.size, visible.to + 100);
|
814 |
+
if (showingFrom < from && from - showingFrom < 20) from = showingFrom;
|
815 |
+
if (showingTo > to && showingTo - to < 20) to = Math.min(doc.size, showingTo);
|
816 |
+
|
817 |
+
// Create a range of theoretically intact lines, and punch holes
|
818 |
+
// in that using the change info.
|
819 |
+
var intact = changes === true ? [] :
|
820 |
+
computeIntact([{from: showingFrom, to: showingTo, domStart: 0}], changes);
|
821 |
+
// Clip off the parts that won't be visible
|
822 |
+
var intactLines = 0;
|
823 |
+
for (var i = 0; i < intact.length; ++i) {
|
824 |
+
var range = intact[i];
|
825 |
+
if (range.from < from) {range.domStart += (from - range.from); range.from = from;}
|
826 |
+
if (range.to > to) range.to = to;
|
827 |
+
if (range.from >= range.to) intact.splice(i--, 1);
|
828 |
+
else intactLines += range.to - range.from;
|
829 |
+
}
|
830 |
+
if (intactLines == to - from) return;
|
831 |
+
intact.sort(function(a, b) {return a.domStart - b.domStart;});
|
832 |
+
|
833 |
+
var th = textHeight(), gutterDisplay = gutter.style.display;
|
834 |
+
lineDiv.style.display = gutter.style.display = "none";
|
835 |
+
patchDisplay(from, to, intact);
|
836 |
+
lineDiv.style.display = "";
|
837 |
+
|
838 |
+
// Position the mover div to align with the lines it's supposed
|
839 |
+
// to be showing (which will cover the visible display)
|
840 |
+
var different = from != showingFrom || to != showingTo || lastSizeC != scroller.clientHeight + th;
|
841 |
+
// This is just a bogus formula that detects when the editor is
|
842 |
+
// resized or the font size changes.
|
843 |
+
if (different) lastSizeC = scroller.clientHeight + th;
|
844 |
+
showingFrom = from; showingTo = to;
|
845 |
+
displayOffset = heightAtLine(doc, from);
|
846 |
+
mover.style.top = (displayOffset * th) + "px";
|
847 |
+
code.style.height = (doc.height * th + 2 * paddingTop()) + "px";
|
848 |
+
|
849 |
+
// Since this is all rather error prone, it is honoured with the
|
850 |
+
// only assertion in the whole file.
|
851 |
+
if (lineDiv.childNodes.length != showingTo - showingFrom)
|
852 |
+
throw new Error("BAD PATCH! " + JSON.stringify(intact) + " size=" + (showingTo - showingFrom) +
|
853 |
+
" nodes=" + lineDiv.childNodes.length);
|
854 |
+
|
855 |
+
if (options.lineWrapping) {
|
856 |
+
maxWidth = scroller.clientWidth;
|
857 |
+
var curNode = lineDiv.firstChild;
|
858 |
+
doc.iter(showingFrom, showingTo, function(line) {
|
859 |
+
if (!line.hidden) {
|
860 |
+
var height = Math.round(curNode.offsetHeight / th) || 1;
|
861 |
+
if (line.height != height) {updateLineHeight(line, height); gutterDirty = true;}
|
862 |
+
}
|
863 |
+
curNode = curNode.nextSibling;
|
864 |
+
});
|
865 |
+
} else {
|
866 |
+
if (maxWidth == null) maxWidth = stringWidth(maxLine);
|
867 |
+
if (maxWidth > scroller.clientWidth) {
|
868 |
+
lineSpace.style.width = maxWidth + "px";
|
869 |
+
// Needed to prevent odd wrapping/hiding of widgets placed in here.
|
870 |
+
code.style.width = "";
|
871 |
+
code.style.width = scroller.scrollWidth + "px";
|
872 |
+
} else {
|
873 |
+
lineSpace.style.width = code.style.width = "";
|
874 |
+
}
|
875 |
+
}
|
876 |
+
gutter.style.display = gutterDisplay;
|
877 |
+
if (different || gutterDirty) updateGutter();
|
878 |
+
updateCursor();
|
879 |
+
if (!suppressCallback && options.onUpdate) options.onUpdate(instance);
|
880 |
+
return true;
|
881 |
+
}
|
882 |
+
|
883 |
+
function computeIntact(intact, changes) {
|
884 |
+
for (var i = 0, l = changes.length || 0; i < l; ++i) {
|
885 |
+
var change = changes[i], intact2 = [], diff = change.diff || 0;
|
886 |
+
for (var j = 0, l2 = intact.length; j < l2; ++j) {
|
887 |
+
var range = intact[j];
|
888 |
+
if (change.to <= range.from && change.diff)
|
889 |
+
intact2.push({from: range.from + diff, to: range.to + diff,
|
890 |
+
domStart: range.domStart});
|
891 |
+
else if (change.to <= range.from || change.from >= range.to)
|
892 |
+
intact2.push(range);
|
893 |
+
else {
|
894 |
+
if (change.from > range.from)
|
895 |
+
intact2.push({from: range.from, to: change.from, domStart: range.domStart});
|
896 |
+
if (change.to < range.to)
|
897 |
+
intact2.push({from: change.to + diff, to: range.to + diff,
|
898 |
+
domStart: range.domStart + (change.to - range.from)});
|
899 |
+
}
|
900 |
+
}
|
901 |
+
intact = intact2;
|
902 |
+
}
|
903 |
+
return intact;
|
904 |
+
}
|
905 |
+
|
906 |
+
function patchDisplay(from, to, intact) {
|
907 |
+
// The first pass removes the DOM nodes that aren't intact.
|
908 |
+
if (!intact.length) lineDiv.innerHTML = "";
|
909 |
+
else {
|
910 |
+
function killNode(node) {
|
911 |
+
var tmp = node.nextSibling;
|
912 |
+
node.parentNode.removeChild(node);
|
913 |
+
return tmp;
|
914 |
+
}
|
915 |
+
var domPos = 0, curNode = lineDiv.firstChild, n;
|
916 |
+
for (var i = 0; i < intact.length; ++i) {
|
917 |
+
var cur = intact[i];
|
918 |
+
while (cur.domStart > domPos) {curNode = killNode(curNode); domPos++;}
|
919 |
+
for (var j = 0, e = cur.to - cur.from; j < e; ++j) {curNode = curNode.nextSibling; domPos++;}
|
920 |
+
}
|
921 |
+
while (curNode) curNode = killNode(curNode);
|
922 |
+
}
|
923 |
+
// This pass fills in the lines that actually changed.
|
924 |
+
var nextIntact = intact.shift(), curNode = lineDiv.firstChild, j = from;
|
925 |
+
var sfrom = sel.from.line, sto = sel.to.line, inSel = sfrom < from && sto >= from;
|
926 |
+
var scratch = targetDocument.createElement("div"), newElt;
|
927 |
+
doc.iter(from, to, function(line) {
|
928 |
+
var ch1 = null, ch2 = null;
|
929 |
+
if (inSel) {
|
930 |
+
ch1 = 0;
|
931 |
+
if (sto == j) {inSel = false; ch2 = sel.to.ch;}
|
932 |
+
} else if (sfrom == j) {
|
933 |
+
if (sto == j) {ch1 = sel.from.ch; ch2 = sel.to.ch;}
|
934 |
+
else {inSel = true; ch1 = sel.from.ch;}
|
935 |
+
}
|
936 |
+
if (nextIntact && nextIntact.to == j) nextIntact = intact.shift();
|
937 |
+
if (!nextIntact || nextIntact.from > j) {
|
938 |
+
if (line.hidden) scratch.innerHTML = "<pre></pre>";
|
939 |
+
else scratch.innerHTML = line.getHTML(ch1, ch2, true, tabText);
|
940 |
+
lineDiv.insertBefore(scratch.firstChild, curNode);
|
941 |
+
} else {
|
942 |
+
curNode = curNode.nextSibling;
|
943 |
+
}
|
944 |
+
++j;
|
945 |
+
});
|
946 |
+
}
|
947 |
+
|
948 |
+
function updateGutter() {
|
949 |
+
if (!options.gutter && !options.lineNumbers) return;
|
950 |
+
var hText = mover.offsetHeight, hEditor = scroller.clientHeight;
|
951 |
+
gutter.style.height = (hText - hEditor < 2 ? hEditor : hText) + "px";
|
952 |
+
var html = [], i = showingFrom;
|
953 |
+
doc.iter(showingFrom, Math.max(showingTo, showingFrom + 1), function(line) {
|
954 |
+
if (line.hidden) {
|
955 |
+
html.push("<pre></pre>");
|
956 |
+
} else {
|
957 |
+
var marker = line.gutterMarker;
|
958 |
+
var text = options.lineNumbers ? i + options.firstLineNumber : null;
|
959 |
+
if (marker && marker.text)
|
960 |
+
text = marker.text.replace("%N%", text != null ? text : "");
|
961 |
+
else if (text == null)
|
962 |
+
text = "\u00a0";
|
963 |
+
html.push((marker && marker.style ? '<pre class="' + marker.style + '">' : "<pre>"), text);
|
964 |
+
for (var j = 1; j < line.height; ++j) html.push("<br/> ");
|
965 |
+
html.push("</pre>");
|
966 |
+
}
|
967 |
+
++i;
|
968 |
+
});
|
969 |
+
gutter.style.display = "none";
|
970 |
+
gutterText.innerHTML = html.join("");
|
971 |
+
var minwidth = String(doc.size).length, firstNode = gutterText.firstChild, val = eltText(firstNode), pad = "";
|
972 |
+
while (val.length + pad.length < minwidth) pad += "\u00a0";
|
973 |
+
if (pad) firstNode.insertBefore(targetDocument.createTextNode(pad), firstNode.firstChild);
|
974 |
+
gutter.style.display = "";
|
975 |
+
lineSpace.style.marginLeft = gutter.offsetWidth + "px";
|
976 |
+
gutterDirty = false;
|
977 |
+
}
|
978 |
+
function updateCursor() {
|
979 |
+
var head = sel.inverted ? sel.from : sel.to, lh = textHeight();
|
980 |
+
var pos = localCoords(head, true);
|
981 |
+
var wrapOff = eltOffset(wrapper), lineOff = eltOffset(lineDiv);
|
982 |
+
inputDiv.style.top = (pos.y + lineOff.top - wrapOff.top) + "px";
|
983 |
+
inputDiv.style.left = (pos.x + lineOff.left - wrapOff.left) + "px";
|
984 |
+
if (posEq(sel.from, sel.to)) {
|
985 |
+
cursor.style.top = pos.y + "px";
|
986 |
+
cursor.style.left = (options.lineWrapping ? Math.min(pos.x, lineSpace.offsetWidth) : pos.x) + "px";
|
987 |
+
cursor.style.display = "";
|
988 |
+
}
|
989 |
+
else cursor.style.display = "none";
|
990 |
+
}
|
991 |
+
|
992 |
+
function setShift(val) {
|
993 |
+
if (val) shiftSelecting = shiftSelecting || (sel.inverted ? sel.to : sel.from);
|
994 |
+
else shiftSelecting = null;
|
995 |
+
}
|
996 |
+
function setSelectionUser(from, to) {
|
997 |
+
var sh = shiftSelecting && clipPos(shiftSelecting);
|
998 |
+
if (sh) {
|
999 |
+
if (posLess(sh, from)) from = sh;
|
1000 |
+
else if (posLess(to, sh)) to = sh;
|
1001 |
+
}
|
1002 |
+
setSelection(from, to);
|
1003 |
+
userSelChange = true;
|
1004 |
+
}
|
1005 |
+
// Update the selection. Last two args are only used by
|
1006 |
+
// updateLines, since they have to be expressed in the line
|
1007 |
+
// numbers before the update.
|
1008 |
+
function setSelection(from, to, oldFrom, oldTo) {
|
1009 |
+
goalColumn = null;
|
1010 |
+
if (oldFrom == null) {oldFrom = sel.from.line; oldTo = sel.to.line;}
|
1011 |
+
if (posEq(sel.from, from) && posEq(sel.to, to)) return;
|
1012 |
+
if (posLess(to, from)) {var tmp = to; to = from; from = tmp;}
|
1013 |
+
|
1014 |
+
// Skip over hidden lines.
|
1015 |
+
if (from.line != oldFrom) from = skipHidden(from, oldFrom, sel.from.ch);
|
1016 |
+
if (to.line != oldTo) to = skipHidden(to, oldTo, sel.to.ch);
|
1017 |
+
|
1018 |
+
if (posEq(from, to)) sel.inverted = false;
|
1019 |
+
else if (posEq(from, sel.to)) sel.inverted = false;
|
1020 |
+
else if (posEq(to, sel.from)) sel.inverted = true;
|
1021 |
+
|
1022 |
+
// Some ugly logic used to only mark the lines that actually did
|
1023 |
+
// see a change in selection as changed, rather than the whole
|
1024 |
+
// selected range.
|
1025 |
+
if (posEq(from, to)) {
|
1026 |
+
if (!posEq(sel.from, sel.to))
|
1027 |
+
changes.push({from: oldFrom, to: oldTo + 1});
|
1028 |
+
}
|
1029 |
+
else if (posEq(sel.from, sel.to)) {
|
1030 |
+
changes.push({from: from.line, to: to.line + 1});
|
1031 |
+
}
|
1032 |
+
else {
|
1033 |
+
if (!posEq(from, sel.from)) {
|
1034 |
+
if (from.line < oldFrom)
|
1035 |
+
changes.push({from: from.line, to: Math.min(to.line, oldFrom) + 1});
|
1036 |
+
else
|
1037 |
+
changes.push({from: oldFrom, to: Math.min(oldTo, from.line) + 1});
|
1038 |
+
}
|
1039 |
+
if (!posEq(to, sel.to)) {
|
1040 |
+
if (to.line < oldTo)
|
1041 |
+
changes.push({from: Math.max(oldFrom, from.line), to: oldTo + 1});
|
1042 |
+
else
|
1043 |
+
changes.push({from: Math.max(from.line, oldTo), to: to.line + 1});
|
1044 |
+
}
|
1045 |
+
}
|
1046 |
+
sel.from = from; sel.to = to;
|
1047 |
+
selectionChanged = true;
|
1048 |
+
}
|
1049 |
+
function skipHidden(pos, oldLine, oldCh) {
|
1050 |
+
function getNonHidden(dir) {
|
1051 |
+
var lNo = pos.line + dir, end = dir == 1 ? doc.size : -1;
|
1052 |
+
while (lNo != end) {
|
1053 |
+
var line = getLine(lNo);
|
1054 |
+
if (!line.hidden) {
|
1055 |
+
var ch = pos.ch;
|
1056 |
+
if (ch > oldCh || ch > line.text.length) ch = line.text.length;
|
1057 |
+
return {line: lNo, ch: ch};
|
1058 |
+
}
|
1059 |
+
lNo += dir;
|
1060 |
+
}
|
1061 |
+
}
|
1062 |
+
var line = getLine(pos.line);
|
1063 |
+
if (!line.hidden) return pos;
|
1064 |
+
if (pos.line >= oldLine) return getNonHidden(1) || getNonHidden(-1);
|
1065 |
+
else return getNonHidden(-1) || getNonHidden(1);
|
1066 |
+
}
|
1067 |
+
function setCursor(line, ch, user) {
|
1068 |
+
var pos = clipPos({line: line, ch: ch || 0});
|
1069 |
+
(user ? setSelectionUser : setSelection)(pos, pos);
|
1070 |
+
}
|
1071 |
+
|
1072 |
+
function clipLine(n) {return Math.max(0, Math.min(n, doc.size-1));}
|
1073 |
+
function clipPos(pos) {
|
1074 |
+
if (pos.line < 0) return {line: 0, ch: 0};
|
1075 |
+
if (pos.line >= doc.size) return {line: doc.size-1, ch: getLine(doc.size-1).text.length};
|
1076 |
+
var ch = pos.ch, linelen = getLine(pos.line).text.length;
|
1077 |
+
if (ch == null || ch > linelen) return {line: pos.line, ch: linelen};
|
1078 |
+
else if (ch < 0) return {line: pos.line, ch: 0};
|
1079 |
+
else return pos;
|
1080 |
+
}
|
1081 |
+
|
1082 |
+
function findPosH(dir, unit) {
|
1083 |
+
var end = sel.inverted ? sel.from : sel.to, line = end.line, ch = end.ch;
|
1084 |
+
var lineObj = getLine(line);
|
1085 |
+
function findNextLine() {
|
1086 |
+
for (var l = line + dir, e = dir < 0 ? -1 : doc.size; l != e; l += dir) {
|
1087 |
+
var lo = getLine(l);
|
1088 |
+
if (!lo.hidden) { line = l; lineObj = lo; return true; }
|
1089 |
+
}
|
1090 |
+
}
|
1091 |
+
function moveOnce(boundToLine) {
|
1092 |
+
if (ch == (dir < 0 ? 0 : lineObj.text.length)) {
|
1093 |
+
if (!boundToLine && findNextLine()) ch = dir < 0 ? lineObj.text.length : 0;
|
1094 |
+
else return false;
|
1095 |
+
} else ch += dir;
|
1096 |
+
return true;
|
1097 |
+
}
|
1098 |
+
if (unit == "char") moveOnce();
|
1099 |
+
else if (unit == "column") moveOnce(true);
|
1100 |
+
else if (unit == "word") {
|
1101 |
+
var sawWord = false;
|
1102 |
+
for (;;) {
|
1103 |
+
if (dir < 0) if (!moveOnce()) break;
|
1104 |
+
if (isWordChar(lineObj.text.charAt(ch))) sawWord = true;
|
1105 |
+
else if (sawWord) {if (dir < 0) {dir = 1; moveOnce();} break;}
|
1106 |
+
if (dir > 0) if (!moveOnce()) break;
|
1107 |
+
}
|
1108 |
+
}
|
1109 |
+
return {line: line, ch: ch};
|
1110 |
+
}
|
1111 |
+
function moveH(dir, unit) {
|
1112 |
+
var pos = dir < 0 ? sel.from : sel.to;
|
1113 |
+
if (shiftSelecting || posEq(sel.from, sel.to)) pos = findPosH(dir, unit);
|
1114 |
+
setCursor(pos.line, pos.ch, true);
|
1115 |
+
}
|
1116 |
+
function deleteH(dir, unit) {
|
1117 |
+
if (!posEq(sel.from, sel.to)) replaceRange("", sel.from, sel.to);
|
1118 |
+
else if (dir < 0) replaceRange("", findPosH(dir, unit), sel.to);
|
1119 |
+
else replaceRange("", sel.from, findPosH(dir, unit));
|
1120 |
+
userSelChange = true;
|
1121 |
+
}
|
1122 |
+
var goalColumn = null;
|
1123 |
+
function moveV(dir, unit) {
|
1124 |
+
var dist = 0, pos = localCoords(sel.inverted ? sel.from : sel.to, true);
|
1125 |
+
if (goalColumn != null) pos.x = goalColumn;
|
1126 |
+
if (unit == "page") dist = scroller.clientHeight;
|
1127 |
+
else if (unit == "line") dist = textHeight();
|
1128 |
+
var target = coordsChar(pos.x, pos.y + dist * dir + 2);
|
1129 |
+
setCursor(target.line, target.ch, true);
|
1130 |
+
goalColumn = pos.x;
|
1131 |
+
}
|
1132 |
+
|
1133 |
+
function selectWordAt(pos) {
|
1134 |
+
var line = getLine(pos.line).text;
|
1135 |
+
var start = pos.ch, end = pos.ch;
|
1136 |
+
while (start > 0 && isWordChar(line.charAt(start - 1))) --start;
|
1137 |
+
while (end < line.length && isWordChar(line.charAt(end))) ++end;
|
1138 |
+
setSelectionUser({line: pos.line, ch: start}, {line: pos.line, ch: end});
|
1139 |
+
}
|
1140 |
+
function selectLine(line) {
|
1141 |
+
setSelectionUser({line: line, ch: 0}, {line: line, ch: getLine(line).text.length});
|
1142 |
+
}
|
1143 |
+
function indentSelected(mode) {
|
1144 |
+
if (posEq(sel.from, sel.to)) return indentLine(sel.from.line, mode);
|
1145 |
+
var e = sel.to.line - (sel.to.ch ? 0 : 1);
|
1146 |
+
for (var i = sel.from.line; i <= e; ++i) indentLine(i, mode);
|
1147 |
+
}
|
1148 |
+
|
1149 |
+
function indentLine(n, how) {
|
1150 |
+
if (!how) how = "add";
|
1151 |
+
if (how == "smart") {
|
1152 |
+
if (!mode.indent) how = "prev";
|
1153 |
+
else var state = getStateBefore(n);
|
1154 |
+
}
|
1155 |
+
|
1156 |
+
var line = getLine(n), curSpace = line.indentation(options.tabSize),
|
1157 |
+
curSpaceString = line.text.match(/^\s*/)[0], indentation;
|
1158 |
+
if (how == "prev") {
|
1159 |
+
if (n) indentation = getLine(n-1).indentation(options.tabSize);
|
1160 |
+
else indentation = 0;
|
1161 |
+
}
|
1162 |
+
else if (how == "smart") indentation = mode.indent(state, line.text.slice(curSpaceString.length), line.text);
|
1163 |
+
else if (how == "add") indentation = curSpace + options.indentUnit;
|
1164 |
+
else if (how == "subtract") indentation = curSpace - options.indentUnit;
|
1165 |
+
indentation = Math.max(0, indentation);
|
1166 |
+
var diff = indentation - curSpace;
|
1167 |
+
|
1168 |
+
if (!diff) {
|
1169 |
+
if (sel.from.line != n && sel.to.line != n) return;
|
1170 |
+
var indentString = curSpaceString;
|
1171 |
+
}
|
1172 |
+
else {
|
1173 |
+
var indentString = "", pos = 0;
|
1174 |
+
if (options.indentWithTabs)
|
1175 |
+
for (var i = Math.floor(indentation / options.tabSize); i; --i) {pos += options.tabSize; indentString += "\t";}
|
1176 |
+
while (pos < indentation) {++pos; indentString += " ";}
|
1177 |
+
}
|
1178 |
+
|
1179 |
+
replaceRange(indentString, {line: n, ch: 0}, {line: n, ch: curSpaceString.length});
|
1180 |
+
}
|
1181 |
+
|
1182 |
+
function loadMode() {
|
1183 |
+
mode = CodeMirror.getMode(options, options.mode);
|
1184 |
+
doc.iter(0, doc.size, function(line) { line.stateAfter = null; });
|
1185 |
+
work = [0];
|
1186 |
+
startWorker();
|
1187 |
+
}
|
1188 |
+
function gutterChanged() {
|
1189 |
+
var visible = options.gutter || options.lineNumbers;
|
1190 |
+
gutter.style.display = visible ? "" : "none";
|
1191 |
+
if (visible) gutterDirty = true;
|
1192 |
+
else lineDiv.parentNode.style.marginLeft = 0;
|
1193 |
+
}
|
1194 |
+
function wrappingChanged(from, to) {
|
1195 |
+
if (options.lineWrapping) {
|
1196 |
+
wrapper.className += " CodeMirror-wrap";
|
1197 |
+
var perLine = scroller.clientWidth / charWidth() - 3;
|
1198 |
+
doc.iter(0, doc.size, function(line) {
|
1199 |
+
if (line.hidden) return;
|
1200 |
+
var guess = Math.ceil(line.text.length / perLine) || 1;
|
1201 |
+
if (guess != 1) updateLineHeight(line, guess);
|
1202 |
+
});
|
1203 |
+
lineSpace.style.width = code.style.width = "";
|
1204 |
+
} else {
|
1205 |
+
wrapper.className = wrapper.className.replace(" CodeMirror-wrap", "");
|
1206 |
+
maxWidth = null; maxLine = "";
|
1207 |
+
doc.iter(0, doc.size, function(line) {
|
1208 |
+
if (line.height != 1 && !line.hidden) updateLineHeight(line, 1);
|
1209 |
+
if (line.text.length > maxLine.length) maxLine = line.text;
|
1210 |
+
});
|
1211 |
+
}
|
1212 |
+
changes.push({from: 0, to: doc.size});
|
1213 |
+
}
|
1214 |
+
function computeTabText() {
|
1215 |
+
for (var str = '<span class="cm-tab">', i = 0; i < options.tabSize; ++i) str += " ";
|
1216 |
+
return str + "</span>";
|
1217 |
+
}
|
1218 |
+
function tabsChanged() {
|
1219 |
+
tabText = computeTabText();
|
1220 |
+
updateDisplay(true);
|
1221 |
+
}
|
1222 |
+
function themeChanged() {
|
1223 |
+
scroller.className = scroller.className.replace(/\s*cm-s-\w+/g, "") +
|
1224 |
+
options.theme.replace(/(^|\s)\s*/g, " cm-s-");
|
1225 |
+
}
|
1226 |
+
|
1227 |
+
function TextMarker() { this.set = []; }
|
1228 |
+
TextMarker.prototype.clear = operation(function() {
|
1229 |
+
var min = Infinity, max = -Infinity;
|
1230 |
+
for (var i = 0, e = this.set.length; i < e; ++i) {
|
1231 |
+
var line = this.set[i], mk = line.marked;
|
1232 |
+
if (!mk || !line.parent) continue;
|
1233 |
+
var lineN = lineNo(line);
|
1234 |
+
min = Math.min(min, lineN); max = Math.max(max, lineN);
|
1235 |
+
for (var j = 0; j < mk.length; ++j)
|
1236 |
+
if (mk[j].set == this.set) mk.splice(j--, 1);
|
1237 |
+
}
|
1238 |
+
if (min != Infinity)
|
1239 |
+
changes.push({from: min, to: max + 1});
|
1240 |
+
});
|
1241 |
+
TextMarker.prototype.find = function() {
|
1242 |
+
var from, to;
|
1243 |
+
for (var i = 0, e = this.set.length; i < e; ++i) {
|
1244 |
+
var line = this.set[i], mk = line.marked;
|
1245 |
+
for (var j = 0; j < mk.length; ++j) {
|
1246 |
+
var mark = mk[j];
|
1247 |
+
if (mark.set == this.set) {
|
1248 |
+
if (mark.from != null || mark.to != null) {
|
1249 |
+
var found = lineNo(line);
|
1250 |
+
if (found != null) {
|
1251 |
+
if (mark.from != null) from = {line: found, ch: mark.from};
|
1252 |
+
if (mark.to != null) to = {line: found, ch: mark.to};
|
1253 |
+
}
|
1254 |
+
}
|
1255 |
+
}
|
1256 |
+
}
|
1257 |
+
}
|
1258 |
+
return {from: from, to: to};
|
1259 |
+
};
|
1260 |
+
|
1261 |
+
function markText(from, to, className) {
|
1262 |
+
from = clipPos(from); to = clipPos(to);
|
1263 |
+
var tm = new TextMarker();
|
1264 |
+
function add(line, from, to, className) {
|
1265 |
+
getLine(line).addMark(new MarkedText(from, to, className, tm.set));
|
1266 |
+
}
|
1267 |
+
if (from.line == to.line) add(from.line, from.ch, to.ch, className);
|
1268 |
+
else {
|
1269 |
+
add(from.line, from.ch, null, className);
|
1270 |
+
for (var i = from.line + 1, e = to.line; i < e; ++i)
|
1271 |
+
add(i, null, null, className);
|
1272 |
+
add(to.line, null, to.ch, className);
|
1273 |
+
}
|
1274 |
+
changes.push({from: from.line, to: to.line + 1});
|
1275 |
+
return tm;
|
1276 |
+
}
|
1277 |
+
|
1278 |
+
function setBookmark(pos) {
|
1279 |
+
pos = clipPos(pos);
|
1280 |
+
var bm = new Bookmark(pos.ch);
|
1281 |
+
getLine(pos.line).addMark(bm);
|
1282 |
+
return bm;
|
1283 |
+
}
|
1284 |
+
|
1285 |
+
function addGutterMarker(line, text, className) {
|
1286 |
+
if (typeof line == "number") line = getLine(clipLine(line));
|
1287 |
+
line.gutterMarker = {text: text, style: className};
|
1288 |
+
gutterDirty = true;
|
1289 |
+
return line;
|
1290 |
+
}
|
1291 |
+
function removeGutterMarker(line) {
|
1292 |
+
if (typeof line == "number") line = getLine(clipLine(line));
|
1293 |
+
line.gutterMarker = null;
|
1294 |
+
gutterDirty = true;
|
1295 |
+
}
|
1296 |
+
|
1297 |
+
function changeLine(handle, op) {
|
1298 |
+
var no = handle, line = handle;
|
1299 |
+
if (typeof handle == "number") line = getLine(clipLine(handle));
|
1300 |
+
else no = lineNo(handle);
|
1301 |
+
if (no == null) return null;
|
1302 |
+
if (op(line, no)) changes.push({from: no, to: no + 1});
|
1303 |
+
else return null;
|
1304 |
+
return line;
|
1305 |
+
}
|
1306 |
+
function setLineClass(handle, className) {
|
1307 |
+
return changeLine(handle, function(line) {
|
1308 |
+
if (line.className != className) {
|
1309 |
+
line.className = className;
|
1310 |
+
return true;
|
1311 |
+
}
|
1312 |
+
});
|
1313 |
+
}
|
1314 |
+
function setLineHidden(handle, hidden) {
|
1315 |
+
return changeLine(handle, function(line, no) {
|
1316 |
+
if (line.hidden != hidden) {
|
1317 |
+
line.hidden = hidden;
|
1318 |
+
updateLineHeight(line, hidden ? 0 : 1);
|
1319 |
+
if (hidden && (sel.from.line == no || sel.to.line == no))
|
1320 |
+
setSelection(skipHidden(sel.from, sel.from.line, sel.from.ch),
|
1321 |
+
skipHidden(sel.to, sel.to.line, sel.to.ch));
|
1322 |
+
return (gutterDirty = true);
|
1323 |
+
}
|
1324 |
+
});
|
1325 |
+
}
|
1326 |
+
|
1327 |
+
function lineInfo(line) {
|
1328 |
+
if (typeof line == "number") {
|
1329 |
+
if (!isLine(line)) return null;
|
1330 |
+
var n = line;
|
1331 |
+
line = getLine(line);
|
1332 |
+
if (!line) return null;
|
1333 |
+
}
|
1334 |
+
else {
|
1335 |
+
var n = lineNo(line);
|
1336 |
+
if (n == null) return null;
|
1337 |
+
}
|
1338 |
+
var marker = line.gutterMarker;
|
1339 |
+
return {line: n, handle: line, text: line.text, markerText: marker && marker.text,
|
1340 |
+
markerClass: marker && marker.style, lineClass: line.className};
|
1341 |
+
}
|
1342 |
+
|
1343 |
+
function stringWidth(str) {
|
1344 |
+
measure.innerHTML = "<pre><span>x</span></pre>";
|
1345 |
+
measure.firstChild.firstChild.firstChild.nodeValue = str;
|
1346 |
+
return measure.firstChild.firstChild.offsetWidth || 10;
|
1347 |
+
}
|
1348 |
+
// These are used to go from pixel positions to character
|
1349 |
+
// positions, taking varying character widths into account.
|
1350 |
+
function charFromX(line, x) {
|
1351 |
+
if (x <= 0) return 0;
|
1352 |
+
var lineObj = getLine(line), text = lineObj.text;
|
1353 |
+
function getX(len) {
|
1354 |
+
measure.innerHTML = "<pre><span>" + lineObj.getHTML(null, null, false, tabText, len) + "</span></pre>";
|
1355 |
+
return measure.firstChild.firstChild.offsetWidth;
|
1356 |
+
}
|
1357 |
+
var from = 0, fromX = 0, to = text.length, toX;
|
1358 |
+
// Guess a suitable upper bound for our search.
|
1359 |
+
var estimated = Math.min(to, Math.ceil(x / charWidth()));
|
1360 |
+
for (;;) {
|
1361 |
+
var estX = getX(estimated);
|
1362 |
+
if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
|
1363 |
+
else {toX = estX; to = estimated; break;}
|
1364 |
+
}
|
1365 |
+
if (x > toX) return to;
|
1366 |
+
// Try to guess a suitable lower bound as well.
|
1367 |
+
estimated = Math.floor(to * 0.8); estX = getX(estimated);
|
1368 |
+
if (estX < x) {from = estimated; fromX = estX;}
|
1369 |
+
// Do a binary search between these bounds.
|
1370 |
+
for (;;) {
|
1371 |
+
if (to - from <= 1) return (toX - x > x - fromX) ? from : to;
|
1372 |
+
var middle = Math.ceil((from + to) / 2), middleX = getX(middle);
|
1373 |
+
if (middleX > x) {to = middle; toX = middleX;}
|
1374 |
+
else {from = middle; fromX = middleX;}
|
1375 |
+
}
|
1376 |
+
}
|
1377 |
+
|
1378 |
+
var tempId = Math.floor(Math.random() * 0xffffff).toString(16);
|
1379 |
+
function measureLine(line, ch) {
|
1380 |
+
var extra = "";
|
1381 |
+
// Include extra text at the end to make sure the measured line is wrapped in the right way.
|
1382 |
+
if (options.lineWrapping) {
|
1383 |
+
var end = line.text.indexOf(" ", ch + 2);
|
1384 |
+
extra = htmlEscape(line.text.slice(ch + 1, end < 0 ? line.text.length : end + (ie ? 5 : 0)));
|
1385 |
+
}
|
1386 |
+
measure.innerHTML = "<pre>" + line.getHTML(null, null, false, tabText, ch) +
|
1387 |
+
'<span id="CodeMirror-temp-' + tempId + '">' + htmlEscape(line.text.charAt(ch) || " ") + "</span>" +
|
1388 |
+
extra + "</pre>";
|
1389 |
+
var elt = document.getElementById("CodeMirror-temp-" + tempId);
|
1390 |
+
var top = elt.offsetTop, left = elt.offsetLeft;
|
1391 |
+
// Older IEs report zero offsets for spans directly after a wrap
|
1392 |
+
if (ie && ch && top == 0 && left == 0) {
|
1393 |
+
var backup = document.createElement("span");
|
1394 |
+
backup.innerHTML = "x";
|
1395 |
+
elt.parentNode.insertBefore(backup, elt.nextSibling);
|
1396 |
+
top = backup.offsetTop;
|
1397 |
+
}
|
1398 |
+
return {top: top, left: left};
|
1399 |
+
}
|
1400 |
+
function localCoords(pos, inLineWrap) {
|
1401 |
+
var x, lh = textHeight(), y = lh * (heightAtLine(doc, pos.line) - (inLineWrap ? displayOffset : 0));
|
1402 |
+
if (pos.ch == 0) x = 0;
|
1403 |
+
else {
|
1404 |
+
var sp = measureLine(getLine(pos.line), pos.ch);
|
1405 |
+
x = sp.left;
|
1406 |
+
if (options.lineWrapping) y += Math.max(0, sp.top);
|
1407 |
+
}
|
1408 |
+
return {x: x, y: y, yBot: y + lh};
|
1409 |
+
}
|
1410 |
+
// Coords must be lineSpace-local
|
1411 |
+
function coordsChar(x, y) {
|
1412 |
+
if (y < 0) y = 0;
|
1413 |
+
var th = textHeight(), cw = charWidth(), heightPos = displayOffset + Math.floor(y / th);
|
1414 |
+
var lineNo = lineAtHeight(doc, heightPos);
|
1415 |
+
if (lineNo >= doc.size) return {line: doc.size - 1, ch: getLine(doc.size - 1).text.length};
|
1416 |
+
var lineObj = getLine(lineNo), text = lineObj.text;
|
1417 |
+
var tw = options.lineWrapping, innerOff = tw ? heightPos - heightAtLine(doc, lineNo) : 0;
|
1418 |
+
if (x <= 0 && innerOff == 0) return {line: lineNo, ch: 0};
|
1419 |
+
function getX(len) {
|
1420 |
+
var sp = measureLine(lineObj, len);
|
1421 |
+
if (tw) {
|
1422 |
+
var off = Math.round(sp.top / th);
|
1423 |
+
return Math.max(0, sp.left + (off - innerOff) * scroller.clientWidth);
|
1424 |
+
}
|
1425 |
+
return sp.left;
|
1426 |
+
}
|
1427 |
+
var from = 0, fromX = 0, to = text.length, toX;
|
1428 |
+
// Guess a suitable upper bound for our search.
|
1429 |
+
var estimated = Math.min(to, Math.ceil((x + innerOff * scroller.clientWidth * .9) / cw));
|
1430 |
+
for (;;) {
|
1431 |
+
var estX = getX(estimated);
|
1432 |
+
if (estX <= x && estimated < to) estimated = Math.min(to, Math.ceil(estimated * 1.2));
|
1433 |
+
else {toX = estX; to = estimated; break;}
|
1434 |
+
}
|
1435 |
+
if (x > toX) return {line: lineNo, ch: to};
|
1436 |
+
// Try to guess a suitable lower bound as well.
|
1437 |
+
estimated = Math.floor(to * 0.8); estX = getX(estimated);
|
1438 |
+
if (estX < x) {from = estimated; fromX = estX;}
|
1439 |
+
// Do a binary search between these bounds.
|
1440 |
+
for (;;) {
|
1441 |
+
if (to - from <= 1) return {line: lineNo, ch: (toX - x > x - fromX) ? from : to};
|
1442 |
+
var middle = Math.ceil((from + to) / 2), middleX = getX(middle);
|
1443 |
+
if (middleX > x) {to = middle; toX = middleX;}
|
1444 |
+
else {from = middle; fromX = middleX;}
|
1445 |
+
}
|
1446 |
+
}
|
1447 |
+
function pageCoords(pos) {
|
1448 |
+
var local = localCoords(pos, true), off = eltOffset(lineSpace);
|
1449 |
+
return {x: off.left + local.x, y: off.top + local.y, yBot: off.top + local.yBot};
|
1450 |
+
}
|
1451 |
+
|
1452 |
+
var cachedHeight, cachedHeightFor, measureText;
|
1453 |
+
function textHeight() {
|
1454 |
+
if (measureText == null) {
|
1455 |
+
measureText = "<pre>";
|
1456 |
+
for (var i = 0; i < 49; ++i) measureText += "x<br/>";
|
1457 |
+
measureText += "x</pre>";
|
1458 |
+
}
|
1459 |
+
var offsetHeight = lineDiv.clientHeight;
|
1460 |
+
if (offsetHeight == cachedHeightFor) return cachedHeight;
|
1461 |
+
cachedHeightFor = offsetHeight;
|
1462 |
+
measure.innerHTML = measureText;
|
1463 |
+
cachedHeight = measure.firstChild.offsetHeight / 50 || 1;
|
1464 |
+
measure.innerHTML = "";
|
1465 |
+
return cachedHeight;
|
1466 |
+
}
|
1467 |
+
var cachedWidth, cachedWidthFor = 0;
|
1468 |
+
function charWidth() {
|
1469 |
+
if (scroller.clientWidth == cachedWidthFor) return cachedWidth;
|
1470 |
+
cachedWidthFor = scroller.clientWidth;
|
1471 |
+
return (cachedWidth = stringWidth("x"));
|
1472 |
+
}
|
1473 |
+
function paddingTop() {return lineSpace.offsetTop;}
|
1474 |
+
function paddingLeft() {return lineSpace.offsetLeft;}
|
1475 |
+
|
1476 |
+
function posFromMouse(e, liberal) {
|
1477 |
+
var offW = eltOffset(scroller, true), x, y;
|
1478 |
+
// Fails unpredictably on IE[67] when mouse is dragged around quickly.
|
1479 |
+
try { x = e.clientX; y = e.clientY; } catch (e) { return null; }
|
1480 |
+
// This is a mess of a heuristic to try and determine whether a
|
1481 |
+
// scroll-bar was clicked or not, and to return null if one was
|
1482 |
+
// (and !liberal).
|
1483 |
+
if (!liberal && (x - offW.left > scroller.clientWidth || y - offW.top > scroller.clientHeight))
|
1484 |
+
return null;
|
1485 |
+
var offL = eltOffset(lineSpace, true);
|
1486 |
+
return coordsChar(x - offL.left, y - offL.top);
|
1487 |
+
}
|
1488 |
+
function onContextMenu(e) {
|
1489 |
+
var pos = posFromMouse(e);
|
1490 |
+
if (!pos || window.opera) return; // Opera is difficult.
|
1491 |
+
if (posEq(sel.from, sel.to) || posLess(pos, sel.from) || !posLess(pos, sel.to))
|
1492 |
+
operation(setCursor)(pos.line, pos.ch);
|
1493 |
+
|
1494 |
+
var oldCSS = input.style.cssText;
|
1495 |
+
inputDiv.style.position = "absolute";
|
1496 |
+
input.style.cssText = "position: fixed; width: 30px; height: 30px; top: " + (e.clientY - 5) +
|
1497 |
+
"px; left: " + (e.clientX - 5) + "px; z-index: 1000; background: white; " +
|
1498 |
+
"border-width: 0; outline: none; overflow: hidden; opacity: .05; filter: alpha(opacity=5);";
|
1499 |
+
leaveInputAlone = true;
|
1500 |
+
var val = input.value = getSelection();
|
1501 |
+
focusInput();
|
1502 |
+
input.select();
|
1503 |
+
function rehide() {
|
1504 |
+
var newVal = splitLines(input.value).join("\n");
|
1505 |
+
if (newVal != val) operation(replaceSelection)(newVal, "end");
|
1506 |
+
inputDiv.style.position = "relative";
|
1507 |
+
input.style.cssText = oldCSS;
|
1508 |
+
leaveInputAlone = false;
|
1509 |
+
resetInput(true);
|
1510 |
+
slowPoll();
|
1511 |
+
}
|
1512 |
+
|
1513 |
+
if (gecko) {
|
1514 |
+
e_stop(e);
|
1515 |
+
var mouseup = connect(window, "mouseup", function() {
|
1516 |
+
mouseup();
|
1517 |
+
setTimeout(rehide, 20);
|
1518 |
+
}, true);
|
1519 |
+
}
|
1520 |
+
else {
|
1521 |
+
setTimeout(rehide, 50);
|
1522 |
+
}
|
1523 |
+
}
|
1524 |
+
|
1525 |
+
// Cursor-blinking
|
1526 |
+
function restartBlink() {
|
1527 |
+
clearInterval(blinker);
|
1528 |
+
var on = true;
|
1529 |
+
cursor.style.visibility = "";
|
1530 |
+
blinker = setInterval(function() {
|
1531 |
+
cursor.style.visibility = (on = !on) ? "" : "hidden";
|
1532 |
+
}, 650);
|
1533 |
+
}
|
1534 |
+
|
1535 |
+
var matching = {"(": ")>", ")": "(<", "[": "]>", "]": "[<", "{": "}>", "}": "{<"};
|
1536 |
+
function matchBrackets(autoclear) {
|
1537 |
+
var head = sel.inverted ? sel.from : sel.to, line = getLine(head.line), pos = head.ch - 1;
|
1538 |
+
var match = (pos >= 0 && matching[line.text.charAt(pos)]) || matching[line.text.charAt(++pos)];
|
1539 |
+
if (!match) return;
|
1540 |
+
var ch = match.charAt(0), forward = match.charAt(1) == ">", d = forward ? 1 : -1, st = line.styles;
|
1541 |
+
for (var off = pos + 1, i = 0, e = st.length; i < e; i+=2)
|
1542 |
+
if ((off -= st[i].length) <= 0) {var style = st[i+1]; break;}
|
1543 |
+
|
1544 |
+
var stack = [line.text.charAt(pos)], re = /[(){}[\]]/;
|
1545 |
+
function scan(line, from, to) {
|
1546 |
+
if (!line.text) return;
|
1547 |
+
var st = line.styles, pos = forward ? 0 : line.text.length - 1, cur;
|
1548 |
+
for (var i = forward ? 0 : st.length - 2, e = forward ? st.length : -2; i != e; i += 2*d) {
|
1549 |
+
var text = st[i];
|
1550 |
+
if (st[i+1] != null && st[i+1] != style) {pos += d * text.length; continue;}
|
1551 |
+
for (var j = forward ? 0 : text.length - 1, te = forward ? text.length : -1; j != te; j += d, pos+=d) {
|
1552 |
+
if (pos >= from && pos < to && re.test(cur = text.charAt(j))) {
|
1553 |
+
var match = matching[cur];
|
1554 |
+
if (match.charAt(1) == ">" == forward) stack.push(cur);
|
1555 |
+
else if (stack.pop() != match.charAt(0)) return {pos: pos, match: false};
|
1556 |
+
else if (!stack.length) return {pos: pos, match: true};
|
1557 |
+
}
|
1558 |
+
}
|
1559 |
+
}
|
1560 |
+
}
|
1561 |
+
for (var i = head.line, e = forward ? Math.min(i + 100, doc.size) : Math.max(-1, i - 100); i != e; i+=d) {
|
1562 |
+
var line = getLine(i), first = i == head.line;
|
1563 |
+
var found = scan(line, first && forward ? pos + 1 : 0, first && !forward ? pos : line.text.length);
|
1564 |
+
if (found) break;
|
1565 |
+
}
|
1566 |
+
if (!found) found = {pos: null, match: false};
|
1567 |
+
var style = found.match ? "CodeMirror-matchingbracket" : "CodeMirror-nonmatchingbracket";
|
1568 |
+
var one = markText({line: head.line, ch: pos}, {line: head.line, ch: pos+1}, style),
|
1569 |
+
two = found.pos != null && markText({line: i, ch: found.pos}, {line: i, ch: found.pos + 1}, style);
|
1570 |
+
var clear = operation(function(){one.clear(); two && two.clear();});
|
1571 |
+
if (autoclear) setTimeout(clear, 800);
|
1572 |
+
else bracketHighlighted = clear;
|
1573 |
+
}
|
1574 |
+
|
1575 |
+
// Finds the line to start with when starting a parse. Tries to
|
1576 |
+
// find a line with a stateAfter, so that it can start with a
|
1577 |
+
// valid state. If that fails, it returns the line with the
|
1578 |
+
// smallest indentation, which tends to need the least context to
|
1579 |
+
// parse correctly.
|
1580 |
+
function findStartLine(n) {
|
1581 |
+
var minindent, minline;
|
1582 |
+
for (var search = n, lim = n - 40; search > lim; --search) {
|
1583 |
+
if (search == 0) return 0;
|
1584 |
+
var line = getLine(search-1);
|
1585 |
+
if (line.stateAfter) return search;
|
1586 |
+
var indented = line.indentation(options.tabSize);
|
1587 |
+
if (minline == null || minindent > indented) {
|
1588 |
+
minline = search - 1;
|
1589 |
+
minindent = indented;
|
1590 |
+
}
|
1591 |
+
}
|
1592 |
+
return minline;
|
1593 |
+
}
|
1594 |
+
function getStateBefore(n) {
|
1595 |
+
var start = findStartLine(n), state = start && getLine(start-1).stateAfter;
|
1596 |
+
if (!state) state = startState(mode);
|
1597 |
+
else state = copyState(mode, state);
|
1598 |
+
doc.iter(start, n, function(line) {
|
1599 |
+
line.highlight(mode, state, options.tabSize);
|
1600 |
+
line.stateAfter = copyState(mode, state);
|
1601 |
+
});
|
1602 |
+
if (start < n) changes.push({from: start, to: n});
|
1603 |
+
if (n < doc.size && !getLine(n).stateAfter) work.push(n);
|
1604 |
+
return state;
|
1605 |
+
}
|
1606 |
+
function highlightLines(start, end) {
|
1607 |
+
var state = getStateBefore(start);
|
1608 |
+
doc.iter(start, end, function(line) {
|
1609 |
+
line.highlight(mode, state, options.tabSize);
|
1610 |
+
line.stateAfter = copyState(mode, state);
|
1611 |
+
});
|
1612 |
+
}
|
1613 |
+
function highlightWorker() {
|
1614 |
+
var end = +new Date + options.workTime;
|
1615 |
+
var foundWork = work.length;
|
1616 |
+
while (work.length) {
|
1617 |
+
if (!getLine(showingFrom).stateAfter) var task = showingFrom;
|
1618 |
+
else var task = work.pop();
|
1619 |
+
if (task >= doc.size) continue;
|
1620 |
+
var start = findStartLine(task), state = start && getLine(start-1).stateAfter;
|
1621 |
+
if (state) state = copyState(mode, state);
|
1622 |
+
else state = startState(mode);
|
1623 |
+
|
1624 |
+
var unchanged = 0, compare = mode.compareStates, realChange = false,
|
1625 |
+
i = start, bail = false;
|
1626 |
+
doc.iter(i, doc.size, function(line) {
|
1627 |
+
var hadState = line.stateAfter;
|
1628 |
+
if (+new Date > end) {
|
1629 |
+
work.push(i);
|
1630 |
+
startWorker(options.workDelay);
|
1631 |
+
if (realChange) changes.push({from: task, to: i + 1});
|
1632 |
+
return (bail = true);
|
1633 |
+
}
|
1634 |
+
var changed = line.highlight(mode, state, options.tabSize);
|
1635 |
+
if (changed) realChange = true;
|
1636 |
+
line.stateAfter = copyState(mode, state);
|
1637 |
+
if (compare) {
|
1638 |
+
if (hadState && compare(hadState, state)) return true;
|
1639 |
+
} else {
|
1640 |
+
if (changed !== false || !hadState) unchanged = 0;
|
1641 |
+
else if (++unchanged > 3 && (!mode.indent || mode.indent(hadState, "") == mode.indent(state, "")))
|
1642 |
+
return true;
|
1643 |
+
}
|
1644 |
+
++i;
|
1645 |
+
});
|
1646 |
+
if (bail) return;
|
1647 |
+
if (realChange) changes.push({from: task, to: i + 1});
|
1648 |
+
}
|
1649 |
+
if (foundWork && options.onHighlightComplete)
|
1650 |
+
options.onHighlightComplete(instance);
|
1651 |
+
}
|
1652 |
+
function startWorker(time) {
|
1653 |
+
if (!work.length) return;
|
1654 |
+
highlight.set(time, operation(highlightWorker));
|
1655 |
+
}
|
1656 |
+
|
1657 |
+
// Operations are used to wrap changes in such a way that each
|
1658 |
+
// change won't have to update the cursor and display (which would
|
1659 |
+
// be awkward, slow, and error-prone), but instead updates are
|
1660 |
+
// batched and then all combined and executed at once.
|
1661 |
+
function startOperation() {
|
1662 |
+
updateInput = userSelChange = textChanged = null;
|
1663 |
+
changes = []; selectionChanged = false; callbacks = [];
|
1664 |
+
}
|
1665 |
+
function endOperation() {
|
1666 |
+
var reScroll = false, updated;
|
1667 |
+
if (selectionChanged) reScroll = !scrollCursorIntoView();
|
1668 |
+
if (changes.length) updated = updateDisplay(changes, true);
|
1669 |
+
else {
|
1670 |
+
if (selectionChanged) updateCursor();
|
1671 |
+
if (gutterDirty) updateGutter();
|
1672 |
+
}
|
1673 |
+
if (reScroll) scrollCursorIntoView();
|
1674 |
+
if (selectionChanged) {scrollEditorIntoView(); restartBlink();}
|
1675 |
+
|
1676 |
+
if (focused && !leaveInputAlone &&
|
1677 |
+
(updateInput === true || (updateInput !== false && selectionChanged)))
|
1678 |
+
resetInput(userSelChange);
|
1679 |
+
|
1680 |
+
if (selectionChanged && options.matchBrackets)
|
1681 |
+
setTimeout(operation(function() {
|
1682 |
+
if (bracketHighlighted) {bracketHighlighted(); bracketHighlighted = null;}
|
1683 |
+
if (posEq(sel.from, sel.to)) matchBrackets(false);
|
1684 |
+
}), 20);
|
1685 |
+
var tc = textChanged, cbs = callbacks; // these can be reset by callbacks
|
1686 |
+
if (selectionChanged && options.onCursorActivity)
|
1687 |
+
options.onCursorActivity(instance);
|
1688 |
+
if (tc && options.onChange && instance)
|
1689 |
+
options.onChange(instance, tc);
|
1690 |
+
for (var i = 0; i < cbs.length; ++i) cbs[i](instance);
|
1691 |
+
if (updated && options.onUpdate) options.onUpdate(instance);
|
1692 |
+
}
|
1693 |
+
var nestedOperation = 0;
|
1694 |
+
function operation(f) {
|
1695 |
+
return function() {
|
1696 |
+
if (!nestedOperation++) startOperation();
|
1697 |
+
try {var result = f.apply(this, arguments);}
|
1698 |
+
finally {if (!--nestedOperation) endOperation();}
|
1699 |
+
return result;
|
1700 |
+
};
|
1701 |
+
}
|
1702 |
+
|
1703 |
+
for (var ext in extensions)
|
1704 |
+
if (extensions.propertyIsEnumerable(ext) &&
|
1705 |
+
!instance.propertyIsEnumerable(ext))
|
1706 |
+
instance[ext] = extensions[ext];
|
1707 |
+
return instance;
|
1708 |
+
} // (end of function CodeMirror)
|
1709 |
+
|
1710 |
+
// The default configuration options.
|
1711 |
+
CodeMirror.defaults = {
|
1712 |
+
value: "",
|
1713 |
+
mode: null,
|
1714 |
+
theme: "default",
|
1715 |
+
indentUnit: 2,
|
1716 |
+
indentWithTabs: false,
|
1717 |
+
tabSize: 4,
|
1718 |
+
keyMap: "default",
|
1719 |
+
extraKeys: null,
|
1720 |
+
electricChars: true,
|
1721 |
+
onKeyEvent: null,
|
1722 |
+
lineWrapping: false,
|
1723 |
+
lineNumbers: false,
|
1724 |
+
gutter: false,
|
1725 |
+
fixedGutter: false,
|
1726 |
+
firstLineNumber: 1,
|
1727 |
+
readOnly: false,
|
1728 |
+
onChange: null,
|
1729 |
+
onCursorActivity: null,
|
1730 |
+
onGutterClick: null,
|
1731 |
+
onHighlightComplete: null,
|
1732 |
+
onUpdate: null,
|
1733 |
+
onFocus: null, onBlur: null, onScroll: null,
|
1734 |
+
matchBrackets: false,
|
1735 |
+
workTime: 100,
|
1736 |
+
workDelay: 200,
|
1737 |
+
pollInterval: 100,
|
1738 |
+
undoDepth: 40,
|
1739 |
+
tabindex: null,
|
1740 |
+
document: window.document
|
1741 |
+
};
|
1742 |
+
|
1743 |
+
var mac = /Mac/.test(navigator.platform);
|
1744 |
+
var win = /Win/.test(navigator.platform);
|
1745 |
+
|
1746 |
+
// Known modes, by name and by MIME
|
1747 |
+
var modes = {}, mimeModes = {};
|
1748 |
+
CodeMirror.defineMode = function(name, mode) {
|
1749 |
+
if (!CodeMirror.defaults.mode && name != "null") CodeMirror.defaults.mode = name;
|
1750 |
+
modes[name] = mode;
|
1751 |
+
};
|
1752 |
+
CodeMirror.defineMIME = function(mime, spec) {
|
1753 |
+
mimeModes[mime] = spec;
|
1754 |
+
};
|
1755 |
+
CodeMirror.getMode = function(options, spec) {
|
1756 |
+
if (typeof spec == "string" && mimeModes.hasOwnProperty(spec))
|
1757 |
+
spec = mimeModes[spec];
|
1758 |
+
if (typeof spec == "string")
|
1759 |
+
var mname = spec, config = {};
|
1760 |
+
else if (spec != null)
|
1761 |
+
var mname = spec.name, config = spec;
|
1762 |
+
var mfactory = modes[mname];
|
1763 |
+
if (!mfactory) {
|
1764 |
+
if (window.console) console.warn("No mode " + mname + " found, falling back to plain text.");
|
1765 |
+
return CodeMirror.getMode(options, "text/plain");
|
1766 |
+
}
|
1767 |
+
return mfactory(options, config || {});
|
1768 |
+
};
|
1769 |
+
CodeMirror.listModes = function() {
|
1770 |
+
var list = [];
|
1771 |
+
for (var m in modes)
|
1772 |
+
if (modes.propertyIsEnumerable(m)) list.push(m);
|
1773 |
+
return list;
|
1774 |
+
};
|
1775 |
+
CodeMirror.listMIMEs = function() {
|
1776 |
+
var list = [];
|
1777 |
+
for (var m in mimeModes)
|
1778 |
+
if (mimeModes.propertyIsEnumerable(m)) list.push({mime: m, mode: mimeModes[m]});
|
1779 |
+
return list;
|
1780 |
+
};
|
1781 |
+
|
1782 |
+
var extensions = CodeMirror.extensions = {};
|
1783 |
+
CodeMirror.defineExtension = function(name, func) {
|
1784 |
+
extensions[name] = func;
|
1785 |
+
};
|
1786 |
+
|
1787 |
+
var commands = CodeMirror.commands = {
|
1788 |
+
selectAll: function(cm) {cm.setSelection({line: 0, ch: 0}, {line: cm.lineCount() - 1});},
|
1789 |
+
killLine: function(cm) {
|
1790 |
+
var from = cm.getCursor(true), to = cm.getCursor(false), sel = !posEq(from, to);
|
1791 |
+
if (!sel && cm.getLine(from.line).length == from.ch) cm.replaceRange("", from, {line: from.line + 1, ch: 0});
|
1792 |
+
else cm.replaceRange("", from, sel ? to : {line: from.line});
|
1793 |
+
},
|
1794 |
+
deleteLine: function(cm) {var l = cm.getCursor().line; cm.replaceRange("", {line: l, ch: 0}, {line: l});},
|
1795 |
+
undo: function(cm) {cm.undo();},
|
1796 |
+
redo: function(cm) {cm.redo();},
|
1797 |
+
goDocStart: function(cm) {cm.setCursor(0, 0, true);},
|
1798 |
+
goDocEnd: function(cm) {cm.setSelection({line: cm.lineCount() - 1}, null, true);},
|
1799 |
+
goLineStart: function(cm) {cm.setCursor(cm.getCursor().line, 0, true);},
|
1800 |
+
goLineStartSmart: function(cm) {
|
1801 |
+
var cur = cm.getCursor();
|
1802 |
+
var text = cm.getLine(cur.line), firstNonWS = Math.max(0, text.search(/\S/));
|
1803 |
+
cm.setCursor(cur.line, cur.ch <= firstNonWS && cur.ch ? 0 : firstNonWS, true);
|
1804 |
+
},
|
1805 |
+
goLineEnd: function(cm) {cm.setSelection({line: cm.getCursor().line}, null, true);},
|
1806 |
+
goLineUp: function(cm) {cm.moveV(-1, "line");},
|
1807 |
+
goLineDown: function(cm) {cm.moveV(1, "line");},
|
1808 |
+
goPageUp: function(cm) {cm.moveV(-1, "page");},
|
1809 |
+
goPageDown: function(cm) {cm.moveV(1, "page");},
|
1810 |
+
goCharLeft: function(cm) {cm.moveH(-1, "char");},
|
1811 |
+
goCharRight: function(cm) {cm.moveH(1, "char");},
|
1812 |
+
goColumnLeft: function(cm) {cm.moveH(-1, "column");},
|
1813 |
+
goColumnRight: function(cm) {cm.moveH(1, "column");},
|
1814 |
+
goWordLeft: function(cm) {cm.moveH(-1, "word");},
|
1815 |
+
goWordRight: function(cm) {cm.moveH(1, "word");},
|
1816 |
+
delCharLeft: function(cm) {cm.deleteH(-1, "char");},
|
1817 |
+
delCharRight: function(cm) {cm.deleteH(1, "char");},
|
1818 |
+
delWordLeft: function(cm) {cm.deleteH(-1, "word");},
|
1819 |
+
delWordRight: function(cm) {cm.deleteH(1, "word");},
|
1820 |
+
indentAuto: function(cm) {cm.indentSelection("smart");},
|
1821 |
+
indentMore: function(cm) {cm.indentSelection("add");},
|
1822 |
+
indentLess: function(cm) {cm.indentSelection("subtract");},
|
1823 |
+
insertTab: function(cm) {cm.replaceSelection("\t", "end");},
|
1824 |
+
transposeChars: function(cm) {
|
1825 |
+
var cur = cm.getCursor(), line = cm.getLine(cur.line);
|
1826 |
+
if (cur.ch > 0 && cur.ch < line.length - 1)
|
1827 |
+
cm.replaceRange(line.charAt(cur.ch) + line.charAt(cur.ch - 1),
|
1828 |
+
{line: cur.line, ch: cur.ch - 1}, {line: cur.line, ch: cur.ch + 1});
|
1829 |
+
},
|
1830 |
+
newlineAndIndent: function(cm) {
|
1831 |
+
cm.replaceSelection("\n", "end");
|
1832 |
+
cm.indentLine(cm.getCursor().line);
|
1833 |
+
},
|
1834 |
+
toggleOverwrite: function(cm) {cm.toggleOverwrite();}
|
1835 |
+
};
|
1836 |
+
|
1837 |
+
var keyMap = CodeMirror.keyMap = {};
|
1838 |
+
keyMap.basic = {
|
1839 |
+
"Left": "goCharLeft", "Right": "goCharRight", "Up": "goLineUp", "Down": "goLineDown",
|
1840 |
+
"End": "goLineEnd", "Home": "goLineStartSmart", "PageUp": "goPageUp", "PageDown": "goPageDown",
|
1841 |
+
"Delete": "delCharRight", "Backspace": "delCharLeft", "Tab": "indentMore", "Shift-Tab": "indentLess",
|
1842 |
+
"Enter": "newlineAndIndent", "Insert": "toggleOverwrite"
|
1843 |
+
};
|
1844 |
+
// Note that the save and find-related commands aren't defined by
|
1845 |
+
// default. Unknown commands are simply ignored.
|
1846 |
+
keyMap.pcDefault = {
|
1847 |
+
"Ctrl-A": "selectAll", "Ctrl-D": "deleteLine", "Ctrl-Z": "undo", "Shift-Ctrl-Z": "redo", "Ctrl-Y": "redo",
|
1848 |
+
"Ctrl-Home": "goDocStart", "Alt-Up": "goDocStart", "Ctrl-End": "goDocEnd", "Ctrl-Down": "goDocEnd",
|
1849 |
+
"Ctrl-Left": "goWordLeft", "Ctrl-Right": "goWordRight", "Alt-Left": "goLineStart", "Alt-Right": "goLineEnd",
|
1850 |
+
"Ctrl-Backspace": "delWordLeft", "Ctrl-Delete": "delWordRight", "Ctrl-S": "save", "Ctrl-F": "find",
|
1851 |
+
"Ctrl-G": "findNext", "Shift-Ctrl-G": "findPrev", "Shift-Ctrl-F": "replace", "Shift-Ctrl-R": "replaceAll",
|
1852 |
+
fallthrough: "basic"
|
1853 |
+
};
|
1854 |
+
keyMap.macDefault = {
|
1855 |
+
"Cmd-A": "selectAll", "Cmd-D": "deleteLine", "Cmd-Z": "undo", "Shift-Cmd-Z": "redo", "Cmd-Y": "redo",
|
1856 |
+
"Cmd-Up": "goDocStart", "Cmd-End": "goDocEnd", "Cmd-Down": "goDocEnd", "Alt-Left": "goWordLeft",
|
1857 |
+
"Alt-Right": "goWordRight", "Cmd-Left": "goLineStart", "Cmd-Right": "goLineEnd", "Alt-Backspace": "delWordLeft",
|
1858 |
+
"Ctrl-Alt-Backspace": "delWordRight", "Alt-Delete": "delWordRight", "Cmd-S": "save", "Cmd-F": "find",
|
1859 |
+
"Cmd-G": "findNext", "Shift-Cmd-G": "findPrev", "Cmd-Alt-F": "replace", "Shift-Cmd-Alt-F": "replaceAll",
|
1860 |
+
fallthrough: ["basic", "emacsy"]
|
1861 |
+
};
|
1862 |
+
keyMap["default"] = mac ? keyMap.macDefault : keyMap.pcDefault;
|
1863 |
+
keyMap.emacsy = {
|
1864 |
+
"Ctrl-F": "goCharRight", "Ctrl-B": "goCharLeft", "Ctrl-P": "goLineUp", "Ctrl-N": "goLineDown",
|
1865 |
+
"Alt-F": "goWordRight", "Alt-B": "goWordLeft", "Ctrl-A": "goLineStart", "Ctrl-E": "goLineEnd",
|
1866 |
+
"Ctrl-V": "goPageUp", "Shift-Ctrl-V": "goPageDown", "Ctrl-D": "delCharRight", "Ctrl-H": "delCharLeft",
|
1867 |
+
"Alt-D": "delWordRight", "Alt-Backspace": "delWordLeft", "Ctrl-K": "killLine", "Ctrl-T": "transposeChars"
|
1868 |
+
};
|
1869 |
+
|
1870 |
+
function lookupKey(name, extraMap, map) {
|
1871 |
+
function lookup(name, map, ft) {
|
1872 |
+
var found = map[name];
|
1873 |
+
if (found != null) return found;
|
1874 |
+
if (ft == null) ft = map.fallthrough;
|
1875 |
+
if (ft == null) return map.catchall;
|
1876 |
+
if (typeof ft == "string") return lookup(name, keyMap[ft]);
|
1877 |
+
for (var i = 0, e = ft.length; i < e; ++i) {
|
1878 |
+
found = lookup(name, keyMap[ft[i]]);
|
1879 |
+
if (found != null) return found;
|
1880 |
+
}
|
1881 |
+
return null;
|
1882 |
+
}
|
1883 |
+
return extraMap ? lookup(name, extraMap, map) : lookup(name, keyMap[map]);
|
1884 |
+
}
|
1885 |
+
function isModifierKey(event) {
|
1886 |
+
var name = keyNames[event.keyCode];
|
1887 |
+
return name == "Ctrl" || name == "Alt" || name == "Shift" || name == "Mod";
|
1888 |
+
}
|
1889 |
+
|
1890 |
+
CodeMirror.fromTextArea = function(textarea, options) {
|
1891 |
+
if (!options) options = {};
|
1892 |
+
options.value = textarea.value;
|
1893 |
+
if (!options.tabindex && textarea.tabindex)
|
1894 |
+
options.tabindex = textarea.tabindex;
|
1895 |
+
|
1896 |
+
function save() {textarea.value = instance.getValue();}
|
1897 |
+
if (textarea.form) {
|
1898 |
+
// Deplorable hack to make the submit method do the right thing.
|
1899 |
+
var rmSubmit = connect(textarea.form, "submit", save, true);
|
1900 |
+
if (typeof textarea.form.submit == "function") {
|
1901 |
+
var realSubmit = textarea.form.submit;
|
1902 |
+
function wrappedSubmit() {
|
1903 |
+
save();
|
1904 |
+
textarea.form.submit = realSubmit;
|
1905 |
+
textarea.form.submit();
|
1906 |
+
textarea.form.submit = wrappedSubmit;
|
1907 |
+
}
|
1908 |
+
textarea.form.submit = wrappedSubmit;
|
1909 |
+
}
|
1910 |
+
}
|
1911 |
+
|
1912 |
+
textarea.style.display = "none";
|
1913 |
+
var instance = CodeMirror(function(node) {
|
1914 |
+
textarea.parentNode.insertBefore(node, textarea.nextSibling);
|
1915 |
+
}, options);
|
1916 |
+
instance.save = save;
|
1917 |
+
instance.getTextArea = function() { return textarea; };
|
1918 |
+
instance.toTextArea = function() {
|
1919 |
+
save();
|
1920 |
+
textarea.parentNode.removeChild(instance.getWrapperElement());
|
1921 |
+
textarea.style.display = "";
|
1922 |
+
if (textarea.form) {
|
1923 |
+
rmSubmit();
|
1924 |
+
if (typeof textarea.form.submit == "function")
|
1925 |
+
textarea.form.submit = realSubmit;
|
1926 |
+
}
|
1927 |
+
};
|
1928 |
+
return instance;
|
1929 |
+
};
|
1930 |
+
|
1931 |
+
// Utility functions for working with state. Exported because modes
|
1932 |
+
// sometimes need to do this.
|
1933 |
+
function copyState(mode, state) {
|
1934 |
+
if (state === true) return state;
|
1935 |
+
if (mode.copyState) return mode.copyState(state);
|
1936 |
+
var nstate = {};
|
1937 |
+
for (var n in state) {
|
1938 |
+
var val = state[n];
|
1939 |
+
if (val instanceof Array) val = val.concat([]);
|
1940 |
+
nstate[n] = val;
|
1941 |
+
}
|
1942 |
+
return nstate;
|
1943 |
+
}
|
1944 |
+
CodeMirror.copyState = copyState;
|
1945 |
+
function startState(mode, a1, a2) {
|
1946 |
+
return mode.startState ? mode.startState(a1, a2) : true;
|
1947 |
+
}
|
1948 |
+
CodeMirror.startState = startState;
|
1949 |
+
|
1950 |
+
// The character stream used by a mode's parser.
|
1951 |
+
function StringStream(string, tabSize) {
|
1952 |
+
this.pos = this.start = 0;
|
1953 |
+
this.string = string;
|
1954 |
+
this.tabSize = tabSize || 8;
|
1955 |
+
}
|
1956 |
+
StringStream.prototype = {
|
1957 |
+
eol: function() {return this.pos >= this.string.length;},
|
1958 |
+
sol: function() {return this.pos == 0;},
|
1959 |
+
peek: function() {return this.string.charAt(this.pos);},
|
1960 |
+
next: function() {
|
1961 |
+
if (this.pos < this.string.length)
|
1962 |
+
return this.string.charAt(this.pos++);
|
1963 |
+
},
|
1964 |
+
eat: function(match) {
|
1965 |
+
var ch = this.string.charAt(this.pos);
|
1966 |
+
if (typeof match == "string") var ok = ch == match;
|
1967 |
+
else var ok = ch && (match.test ? match.test(ch) : match(ch));
|
1968 |
+
if (ok) {++this.pos; return ch;}
|
1969 |
+
},
|
1970 |
+
eatWhile: function(match) {
|
1971 |
+
var start = this.pos;
|
1972 |
+
while (this.eat(match)){}
|
1973 |
+
return this.pos > start;
|
1974 |
+
},
|
1975 |
+
eatSpace: function() {
|
1976 |
+
var start = this.pos;
|
1977 |
+
while (/[\s\u00a0]/.test(this.string.charAt(this.pos))) ++this.pos;
|
1978 |
+
return this.pos > start;
|
1979 |
+
},
|
1980 |
+
skipToEnd: function() {this.pos = this.string.length;},
|
1981 |
+
skipTo: function(ch) {
|
1982 |
+
var found = this.string.indexOf(ch, this.pos);
|
1983 |
+
if (found > -1) {this.pos = found; return true;}
|
1984 |
+
},
|
1985 |
+
backUp: function(n) {this.pos -= n;},
|
1986 |
+
column: function() {return countColumn(this.string, this.start, this.tabSize);},
|
1987 |
+
indentation: function() {return countColumn(this.string, null, this.tabSize);},
|
1988 |
+
match: function(pattern, consume, caseInsensitive) {
|
1989 |
+
if (typeof pattern == "string") {
|
1990 |
+
function cased(str) {return caseInsensitive ? str.toLowerCase() : str;}
|
1991 |
+
if (cased(this.string).indexOf(cased(pattern), this.pos) == this.pos) {
|
1992 |
+
if (consume !== false) this.pos += pattern.length;
|
1993 |
+
return true;
|
1994 |
+
}
|
1995 |
+
}
|
1996 |
+
else {
|
1997 |
+
var match = this.string.slice(this.pos).match(pattern);
|
1998 |
+
if (match && consume !== false) this.pos += match[0].length;
|
1999 |
+
return match;
|
2000 |
+
}
|
2001 |
+
},
|
2002 |
+
current: function(){return this.string.slice(this.start, this.pos);}
|
2003 |
+
};
|
2004 |
+
CodeMirror.StringStream = StringStream;
|
2005 |
+
|
2006 |
+
function MarkedText(from, to, className, set) {
|
2007 |
+
this.from = from; this.to = to; this.style = className; this.set = set;
|
2008 |
+
}
|
2009 |
+
MarkedText.prototype = {
|
2010 |
+
attach: function(line) { this.set.push(line); },
|
2011 |
+
detach: function(line) {
|
2012 |
+
var ix = indexOf(this.set, line);
|
2013 |
+
if (ix > -1) this.set.splice(ix, 1);
|
2014 |
+
},
|
2015 |
+
split: function(pos, lenBefore) {
|
2016 |
+
if (this.to <= pos && this.to != null) return null;
|
2017 |
+
var from = this.from < pos || this.from == null ? null : this.from - pos + lenBefore;
|
2018 |
+
var to = this.to == null ? null : this.to - pos + lenBefore;
|
2019 |
+
return new MarkedText(from, to, this.style, this.set);
|
2020 |
+
},
|
2021 |
+
dup: function() { return new MarkedText(null, null, this.style, this.set); },
|
2022 |
+
clipTo: function(fromOpen, from, toOpen, to, diff) {
|
2023 |
+
if (this.from != null && this.from >= from)
|
2024 |
+
this.from = Math.max(to, this.from) + diff;
|
2025 |
+
if (this.to != null && this.to > from)
|
2026 |
+
this.to = to < this.to ? this.to + diff : from;
|
2027 |
+
if (fromOpen && to > this.from && (to < this.to || this.to == null))
|
2028 |
+
this.from = null;
|
2029 |
+
if (toOpen && (from < this.to || this.to == null) && (from > this.from || this.from == null))
|
2030 |
+
this.to = null;
|
2031 |
+
},
|
2032 |
+
isDead: function() { return this.from != null && this.to != null && this.from >= this.to; },
|
2033 |
+
sameSet: function(x) { return this.set == x.set; }
|
2034 |
+
};
|
2035 |
+
|
2036 |
+
function Bookmark(pos) {
|
2037 |
+
this.from = pos; this.to = pos; this.line = null;
|
2038 |
+
}
|
2039 |
+
Bookmark.prototype = {
|
2040 |
+
attach: function(line) { this.line = line; },
|
2041 |
+
detach: function(line) { if (this.line == line) this.line = null; },
|
2042 |
+
split: function(pos, lenBefore) {
|
2043 |
+
if (pos < this.from) {
|
2044 |
+
this.from = this.to = (this.from - pos) + lenBefore;
|
2045 |
+
return this;
|
2046 |
+
}
|
2047 |
+
},
|
2048 |
+
isDead: function() { return this.from > this.to; },
|
2049 |
+
clipTo: function(fromOpen, from, toOpen, to, diff) {
|
2050 |
+
if ((fromOpen || from < this.from) && (toOpen || to > this.to)) {
|
2051 |
+
this.from = 0; this.to = -1;
|
2052 |
+
} else if (this.from > from) {
|
2053 |
+
this.from = this.to = Math.max(to, this.from) + diff;
|
2054 |
+
}
|
2055 |
+
},
|
2056 |
+
sameSet: function(x) { return false; },
|
2057 |
+
find: function() {
|
2058 |
+
if (!this.line || !this.line.parent) return null;
|
2059 |
+
return {line: lineNo(this.line), ch: this.from};
|
2060 |
+
},
|
2061 |
+
clear: function() {
|
2062 |
+
if (this.line) {
|
2063 |
+
var found = indexOf(this.line.marked, this);
|
2064 |
+
if (found != -1) this.line.marked.splice(found, 1);
|
2065 |
+
this.line = null;
|
2066 |
+
}
|
2067 |
+
}
|
2068 |
+
};
|
2069 |
+
|
2070 |
+
// Line objects. These hold state related to a line, including
|
2071 |
+
// highlighting info (the styles array).
|
2072 |
+
function Line(text, styles) {
|
2073 |
+
this.styles = styles || [text, null];
|
2074 |
+
this.text = text;
|
2075 |
+
this.height = 1;
|
2076 |
+
this.marked = this.gutterMarker = this.className = this.handlers = null;
|
2077 |
+
this.stateAfter = this.parent = this.hidden = null;
|
2078 |
+
}
|
2079 |
+
Line.inheritMarks = function(text, orig) {
|
2080 |
+
var ln = new Line(text), mk = orig && orig.marked;
|
2081 |
+
if (mk) {
|
2082 |
+
for (var i = 0; i < mk.length; ++i) {
|
2083 |
+
if (mk[i].to == null && mk[i].style) {
|
2084 |
+
var newmk = ln.marked || (ln.marked = []), mark = mk[i];
|
2085 |
+
var nmark = mark.dup(); newmk.push(nmark); nmark.attach(ln);
|
2086 |
+
}
|
2087 |
+
}
|
2088 |
+
}
|
2089 |
+
return ln;
|
2090 |
+
}
|
2091 |
+
Line.prototype = {
|
2092 |
+
// Replace a piece of a line, keeping the styles around it intact.
|
2093 |
+
replace: function(from, to_, text) {
|
2094 |
+
var st = [], mk = this.marked, to = to_ == null ? this.text.length : to_;
|
2095 |
+
copyStyles(0, from, this.styles, st);
|
2096 |
+
if (text) st.push(text, null);
|
2097 |
+
copyStyles(to, this.text.length, this.styles, st);
|
2098 |
+
this.styles = st;
|
2099 |
+
this.text = this.text.slice(0, from) + text + this.text.slice(to);
|
2100 |
+
this.stateAfter = null;
|
2101 |
+
if (mk) {
|
2102 |
+
var diff = text.length - (to - from);
|
2103 |
+
for (var i = 0, mark = mk[i]; i < mk.length; ++i) {
|
2104 |
+
mark.clipTo(from == null, from || 0, to_ == null, to, diff);
|
2105 |
+
if (mark.isDead()) {mark.detach(this); mk.splice(i--, 1);}
|
2106 |
+
}
|
2107 |
+
}
|
2108 |
+
},
|
2109 |
+
// Split a part off a line, keeping styles and markers intact.
|
2110 |
+
split: function(pos, textBefore) {
|
2111 |
+
var st = [textBefore, null], mk = this.marked;
|
2112 |
+
copyStyles(pos, this.text.length, this.styles, st);
|
2113 |
+
var taken = new Line(textBefore + this.text.slice(pos), st);
|
2114 |
+
if (mk) {
|
2115 |
+
for (var i = 0; i < mk.length; ++i) {
|
2116 |
+
var mark = mk[i];
|
2117 |
+
var newmark = mark.split(pos, textBefore.length);
|
2118 |
+
if (newmark) {
|
2119 |
+
if (!taken.marked) taken.marked = [];
|
2120 |
+
taken.marked.push(newmark); newmark.attach(taken);
|
2121 |
+
}
|
2122 |
+
}
|
2123 |
+
}
|
2124 |
+
return taken;
|
2125 |
+
},
|
2126 |
+
append: function(line) {
|
2127 |
+
var mylen = this.text.length, mk = line.marked, mymk = this.marked;
|
2128 |
+
this.text += line.text;
|
2129 |
+
copyStyles(0, line.text.length, line.styles, this.styles);
|
2130 |
+
if (mymk) {
|
2131 |
+
for (var i = 0; i < mymk.length; ++i)
|
2132 |
+
if (mymk[i].to == null) mymk[i].to = mylen;
|
2133 |
+
}
|
2134 |
+
if (mk && mk.length) {
|
2135 |
+
if (!mymk) this.marked = mymk = [];
|
2136 |
+
outer: for (var i = 0; i < mk.length; ++i) {
|
2137 |
+
var mark = mk[i];
|
2138 |
+
if (!mark.from) {
|
2139 |
+
for (var j = 0; j < mymk.length; ++j) {
|
2140 |
+
var mymark = mymk[j];
|
2141 |
+
if (mymark.to == mylen && mymark.sameSet(mark)) {
|
2142 |
+
mymark.to = mark.to == null ? null : mark.to + mylen;
|
2143 |
+
if (mymark.isDead()) {
|
2144 |
+
mymark.detach(this);
|
2145 |
+
mk.splice(i--, 1);
|
2146 |
+
}
|
2147 |
+
continue outer;
|
2148 |
+
}
|
2149 |
+
}
|
2150 |
+
}
|
2151 |
+
mymk.push(mark);
|
2152 |
+
mark.attach(this);
|
2153 |
+
mark.from += mylen;
|
2154 |
+
if (mark.to != null) mark.to += mylen;
|
2155 |
+
}
|
2156 |
+
}
|
2157 |
+
},
|
2158 |
+
fixMarkEnds: function(other) {
|
2159 |
+
var mk = this.marked, omk = other.marked;
|
2160 |
+
if (!mk) return;
|
2161 |
+
for (var i = 0; i < mk.length; ++i) {
|
2162 |
+
var mark = mk[i], close = mark.to == null;
|
2163 |
+
if (close && omk) {
|
2164 |
+
for (var j = 0; j < omk.length; ++j)
|
2165 |
+
if (omk[j].sameSet(mark)) {close = false; break;}
|
2166 |
+
}
|
2167 |
+
if (close) mark.to = this.text.length;
|
2168 |
+
}
|
2169 |
+
},
|
2170 |
+
fixMarkStarts: function() {
|
2171 |
+
var mk = this.marked;
|
2172 |
+
if (!mk) return;
|
2173 |
+
for (var i = 0; i < mk.length; ++i)
|
2174 |
+
if (mk[i].from == null) mk[i].from = 0;
|
2175 |
+
},
|
2176 |
+
addMark: function(mark) {
|
2177 |
+
mark.attach(this);
|
2178 |
+
if (this.marked == null) this.marked = [];
|
2179 |
+
this.marked.push(mark);
|
2180 |
+
this.marked.sort(function(a, b){return (a.from || 0) - (b.from || 0);});
|
2181 |
+
},
|
2182 |
+
// Run the given mode's parser over a line, update the styles
|
2183 |
+
// array, which contains alternating fragments of text and CSS
|
2184 |
+
// classes.
|
2185 |
+
highlight: function(mode, state, tabSize) {
|
2186 |
+
var stream = new StringStream(this.text, tabSize), st = this.styles, pos = 0;
|
2187 |
+
var changed = false, curWord = st[0], prevWord;
|
2188 |
+
if (this.text == "" && mode.blankLine) mode.blankLine(state);
|
2189 |
+
while (!stream.eol()) {
|
2190 |
+
var style = mode.token(stream, state);
|
2191 |
+
var substr = this.text.slice(stream.start, stream.pos);
|
2192 |
+
stream.start = stream.pos;
|
2193 |
+
if (pos && st[pos-1] == style)
|
2194 |
+
st[pos-2] += substr;
|
2195 |
+
else if (substr) {
|
2196 |
+
if (!changed && (st[pos+1] != style || (pos && st[pos-2] != prevWord))) changed = true;
|
2197 |
+
st[pos++] = substr; st[pos++] = style;
|
2198 |
+
prevWord = curWord; curWord = st[pos];
|
2199 |
+
}
|
2200 |
+
// Give up when line is ridiculously long
|
2201 |
+
if (stream.pos > 5000) {
|
2202 |
+
st[pos++] = this.text.slice(stream.pos); st[pos++] = null;
|
2203 |
+
break;
|
2204 |
+
}
|
2205 |
+
}
|
2206 |
+
if (st.length != pos) {st.length = pos; changed = true;}
|
2207 |
+
if (pos && st[pos-2] != prevWord) changed = true;
|
2208 |
+
// Short lines with simple highlights return null, and are
|
2209 |
+
// counted as changed by the driver because they are likely to
|
2210 |
+
// highlight the same way in various contexts.
|
2211 |
+
return changed || (st.length < 5 && this.text.length < 10 ? null : false);
|
2212 |
+
},
|
2213 |
+
// Fetch the parser token for a given character. Useful for hacks
|
2214 |
+
// that want to inspect the mode state (say, for completion).
|
2215 |
+
getTokenAt: function(mode, state, ch) {
|
2216 |
+
var txt = this.text, stream = new StringStream(txt);
|
2217 |
+
while (stream.pos < ch && !stream.eol()) {
|
2218 |
+
stream.start = stream.pos;
|
2219 |
+
var style = mode.token(stream, state);
|
2220 |
+
}
|
2221 |
+
return {start: stream.start,
|
2222 |
+
end: stream.pos,
|
2223 |
+
string: stream.current(),
|
2224 |
+
className: style || null,
|
2225 |
+
state: state};
|
2226 |
+
},
|
2227 |
+
indentation: function(tabSize) {return countColumn(this.text, null, tabSize);},
|
2228 |
+
// Produces an HTML fragment for the line, taking selection,
|
2229 |
+
// marking, and highlighting into account.
|
2230 |
+
getHTML: function(sfrom, sto, includePre, tabText, endAt) {
|
2231 |
+
var html = [], first = true;
|
2232 |
+
if (includePre)
|
2233 |
+
html.push(this.className ? '<pre class="' + this.className + '">': "<pre>");
|
2234 |
+
function span(text, style) {
|
2235 |
+
if (!text) return;
|
2236 |
+
// Work around a bug where, in some compat modes, IE ignores leading spaces
|
2237 |
+
if (first && ie && text.charAt(0) == " ") text = "\u00a0" + text.slice(1);
|
2238 |
+
first = false;
|
2239 |
+
if (style) html.push('<span class="', style, '">', htmlEscape(text).replace(/\t/g, tabText), "</span>");
|
2240 |
+
else html.push(htmlEscape(text).replace(/\t/g, tabText));
|
2241 |
+
}
|
2242 |
+
var st = this.styles, allText = this.text, marked = this.marked;
|
2243 |
+
if (sfrom == sto) sfrom = null;
|
2244 |
+
var len = allText.length;
|
2245 |
+
if (endAt != null) len = Math.min(endAt, len);
|
2246 |
+
|
2247 |
+
if (!allText && endAt == null)
|
2248 |
+
span(" ", sfrom != null && sto == null ? "CodeMirror-selected" : null);
|
2249 |
+
else if (!marked && sfrom == null)
|
2250 |
+
for (var i = 0, ch = 0; ch < len; i+=2) {
|
2251 |
+
var str = st[i], style = st[i+1], l = str.length;
|
2252 |
+
if (ch + l > len) str = str.slice(0, len - ch);
|
2253 |
+
ch += l;
|
2254 |
+
span(str, style && "cm-" + style);
|
2255 |
+
}
|
2256 |
+
else {
|
2257 |
+
var pos = 0, i = 0, text = "", style, sg = 0;
|
2258 |
+
var markpos = -1, mark = null;
|
2259 |
+
function nextMark() {
|
2260 |
+
if (marked) {
|
2261 |
+
markpos += 1;
|
2262 |
+
mark = (markpos < marked.length) ? marked[markpos] : null;
|
2263 |
+
}
|
2264 |
+
}
|
2265 |
+
nextMark();
|
2266 |
+
while (pos < len) {
|
2267 |
+
var upto = len;
|
2268 |
+
var extraStyle = "";
|
2269 |
+
if (sfrom != null) {
|
2270 |
+
if (sfrom > pos) upto = sfrom;
|
2271 |
+
else if (sto == null || sto > pos) {
|
2272 |
+
extraStyle = " CodeMirror-selected";
|
2273 |
+
if (sto != null) upto = Math.min(upto, sto);
|
2274 |
+
}
|
2275 |
+
}
|
2276 |
+
while (mark && mark.to != null && mark.to <= pos) nextMark();
|
2277 |
+
if (mark) {
|
2278 |
+
if (mark.from > pos) upto = Math.min(upto, mark.from);
|
2279 |
+
else {
|
2280 |
+
extraStyle += " " + mark.style;
|
2281 |
+
if (mark.to != null) upto = Math.min(upto, mark.to);
|
2282 |
+
}
|
2283 |
+
}
|
2284 |
+
for (;;) {
|
2285 |
+
var end = pos + text.length;
|
2286 |
+
var appliedStyle = style;
|
2287 |
+
if (extraStyle) appliedStyle = style ? style + extraStyle : extraStyle;
|
2288 |
+
span(end > upto ? text.slice(0, upto - pos) : text, appliedStyle);
|
2289 |
+
if (end >= upto) {text = text.slice(upto - pos); pos = upto; break;}
|
2290 |
+
pos = end;
|
2291 |
+
text = st[i++]; style = "cm-" + st[i++];
|
2292 |
+
}
|
2293 |
+
}
|
2294 |
+
if (sfrom != null && sto == null) span(" ", "CodeMirror-selected");
|
2295 |
+
}
|
2296 |
+
if (includePre) html.push("</pre>");
|
2297 |
+
return html.join("");
|
2298 |
+
},
|
2299 |
+
cleanUp: function() {
|
2300 |
+
this.parent = null;
|
2301 |
+
if (this.marked)
|
2302 |
+
for (var i = 0, e = this.marked.length; i < e; ++i) this.marked[i].detach(this);
|
2303 |
+
}
|
2304 |
+
};
|
2305 |
+
// Utility used by replace and split above
|
2306 |
+
function copyStyles(from, to, source, dest) {
|
2307 |
+
for (var i = 0, pos = 0, state = 0; pos < to; i+=2) {
|
2308 |
+
var part = source[i], end = pos + part.length;
|
2309 |
+
if (state == 0) {
|
2310 |
+
if (end > from) dest.push(part.slice(from - pos, Math.min(part.length, to - pos)), source[i+1]);
|
2311 |
+
if (end >= from) state = 1;
|
2312 |
+
}
|
2313 |
+
else if (state == 1) {
|
2314 |
+
if (end > to) dest.push(part.slice(0, to - pos), source[i+1]);
|
2315 |
+
else dest.push(part, source[i+1]);
|
2316 |
+
}
|
2317 |
+
pos = end;
|
2318 |
+
}
|
2319 |
+
}
|
2320 |
+
|
2321 |
+
// Data structure that holds the sequence of lines.
|
2322 |
+
function LeafChunk(lines) {
|
2323 |
+
this.lines = lines;
|
2324 |
+
this.parent = null;
|
2325 |
+
for (var i = 0, e = lines.length, height = 0; i < e; ++i) {
|
2326 |
+
lines[i].parent = this;
|
2327 |
+
height += lines[i].height;
|
2328 |
+
}
|
2329 |
+
this.height = height;
|
2330 |
+
}
|
2331 |
+
LeafChunk.prototype = {
|
2332 |
+
chunkSize: function() { return this.lines.length; },
|
2333 |
+
remove: function(at, n, callbacks) {
|
2334 |
+
for (var i = at, e = at + n; i < e; ++i) {
|
2335 |
+
var line = this.lines[i];
|
2336 |
+
this.height -= line.height;
|
2337 |
+
line.cleanUp();
|
2338 |
+
if (line.handlers)
|
2339 |
+
for (var j = 0; j < line.handlers.length; ++j) callbacks.push(line.handlers[j]);
|
2340 |
+
}
|
2341 |
+
this.lines.splice(at, n);
|
2342 |
+
},
|
2343 |
+
collapse: function(lines) {
|
2344 |
+
lines.splice.apply(lines, [lines.length, 0].concat(this.lines));
|
2345 |
+
},
|
2346 |
+
insertHeight: function(at, lines, height) {
|
2347 |
+
this.height += height;
|
2348 |
+
this.lines.splice.apply(this.lines, [at, 0].concat(lines));
|
2349 |
+
for (var i = 0, e = lines.length; i < e; ++i) lines[i].parent = this;
|
2350 |
+
},
|
2351 |
+
iterN: function(at, n, op) {
|
2352 |
+
for (var e = at + n; at < e; ++at)
|
2353 |
+
if (op(this.lines[at])) return true;
|
2354 |
+
}
|
2355 |
+
};
|
2356 |
+
function BranchChunk(children) {
|
2357 |
+
this.children = children;
|
2358 |
+
var size = 0, height = 0;
|
2359 |
+
for (var i = 0, e = children.length; i < e; ++i) {
|
2360 |
+
var ch = children[i];
|
2361 |
+
size += ch.chunkSize(); height += ch.height;
|
2362 |
+
ch.parent = this;
|
2363 |
+
}
|
2364 |
+
this.size = size;
|
2365 |
+
this.height = height;
|
2366 |
+
this.parent = null;
|
2367 |
+
}
|
2368 |
+
BranchChunk.prototype = {
|
2369 |
+
chunkSize: function() { return this.size; },
|
2370 |
+
remove: function(at, n, callbacks) {
|
2371 |
+
this.size -= n;
|
2372 |
+
for (var i = 0; i < this.children.length; ++i) {
|
2373 |
+
var child = this.children[i], sz = child.chunkSize();
|
2374 |
+
if (at < sz) {
|
2375 |
+
var rm = Math.min(n, sz - at), oldHeight = child.height;
|
2376 |
+
child.remove(at, rm, callbacks);
|
2377 |
+
this.height -= oldHeight - child.height;
|
2378 |
+
if (sz == rm) { this.children.splice(i--, 1); child.parent = null; }
|
2379 |
+
if ((n -= rm) == 0) break;
|
2380 |
+
at = 0;
|
2381 |
+
} else at -= sz;
|
2382 |
+
}
|
2383 |
+
if (this.size - n < 25) {
|
2384 |
+
var lines = [];
|
2385 |
+
this.collapse(lines);
|
2386 |
+
this.children = [new LeafChunk(lines)];
|
2387 |
+
}
|
2388 |
+
},
|
2389 |
+
collapse: function(lines) {
|
2390 |
+
for (var i = 0, e = this.children.length; i < e; ++i) this.children[i].collapse(lines);
|
2391 |
+
},
|
2392 |
+
insert: function(at, lines) {
|
2393 |
+
var height = 0;
|
2394 |
+
for (var i = 0, e = lines.length; i < e; ++i) height += lines[i].height;
|
2395 |
+
this.insertHeight(at, lines, height);
|
2396 |
+
},
|
2397 |
+
insertHeight: function(at, lines, height) {
|
2398 |
+
this.size += lines.length;
|
2399 |
+
this.height += height;
|
2400 |
+
for (var i = 0, e = this.children.length; i < e; ++i) {
|
2401 |
+
var child = this.children[i], sz = child.chunkSize();
|
2402 |
+
if (at <= sz) {
|
2403 |
+
child.insertHeight(at, lines, height);
|
2404 |
+
if (child.lines && child.lines.length > 50) {
|
2405 |
+
while (child.lines.length > 50) {
|
2406 |
+
var spilled = child.lines.splice(child.lines.length - 25, 25);
|
2407 |
+
var newleaf = new LeafChunk(spilled);
|
2408 |
+
child.height -= newleaf.height;
|
2409 |
+
this.children.splice(i + 1, 0, newleaf);
|
2410 |
+
newleaf.parent = this;
|
2411 |
+
}
|
2412 |
+
this.maybeSpill();
|
2413 |
+
}
|
2414 |
+
break;
|
2415 |
+
}
|
2416 |
+
at -= sz;
|
2417 |
+
}
|
2418 |
+
},
|
2419 |
+
maybeSpill: function() {
|
2420 |
+
if (this.children.length <= 10) return;
|
2421 |
+
var me = this;
|
2422 |
+
do {
|
2423 |
+
var spilled = me.children.splice(me.children.length - 5, 5);
|
2424 |
+
var sibling = new BranchChunk(spilled);
|
2425 |
+
if (!me.parent) { // Become the parent node
|
2426 |
+
var copy = new BranchChunk(me.children);
|
2427 |
+
copy.parent = me;
|
2428 |
+
me.children = [copy, sibling];
|
2429 |
+
me = copy;
|
2430 |
+
} else {
|
2431 |
+
me.size -= sibling.size;
|
2432 |
+
me.height -= sibling.height;
|
2433 |
+
var myIndex = indexOf(me.parent.children, me);
|
2434 |
+
me.parent.children.splice(myIndex + 1, 0, sibling);
|
2435 |
+
}
|
2436 |
+
sibling.parent = me.parent;
|
2437 |
+
} while (me.children.length > 10);
|
2438 |
+
me.parent.maybeSpill();
|
2439 |
+
},
|
2440 |
+
iter: function(from, to, op) { this.iterN(from, to - from, op); },
|
2441 |
+
iterN: function(at, n, op) {
|
2442 |
+
for (var i = 0, e = this.children.length; i < e; ++i) {
|
2443 |
+
var child = this.children[i], sz = child.chunkSize();
|
2444 |
+
if (at < sz) {
|
2445 |
+
var used = Math.min(n, sz - at);
|
2446 |
+
if (child.iterN(at, used, op)) return true;
|
2447 |
+
if ((n -= used) == 0) break;
|
2448 |
+
at = 0;
|
2449 |
+
} else at -= sz;
|
2450 |
+
}
|
2451 |
+
}
|
2452 |
+
};
|
2453 |
+
|
2454 |
+
function getLineAt(chunk, n) {
|
2455 |
+
while (!chunk.lines) {
|
2456 |
+
for (var i = 0;; ++i) {
|
2457 |
+
var child = chunk.children[i], sz = child.chunkSize();
|
2458 |
+
if (n < sz) { chunk = child; break; }
|
2459 |
+
n -= sz;
|
2460 |
+
}
|
2461 |
+
}
|
2462 |
+
return chunk.lines[n];
|
2463 |
+
}
|
2464 |
+
function lineNo(line) {
|
2465 |
+
if (line.parent == null) return null;
|
2466 |
+
var cur = line.parent, no = indexOf(cur.lines, line);
|
2467 |
+
for (var chunk = cur.parent; chunk; cur = chunk, chunk = chunk.parent) {
|
2468 |
+
for (var i = 0, e = chunk.children.length; ; ++i) {
|
2469 |
+
if (chunk.children[i] == cur) break;
|
2470 |
+
no += chunk.children[i].chunkSize();
|
2471 |
+
}
|
2472 |
+
}
|
2473 |
+
return no;
|
2474 |
+
}
|
2475 |
+
function lineAtHeight(chunk, h) {
|
2476 |
+
var n = 0;
|
2477 |
+
outer: do {
|
2478 |
+
for (var i = 0, e = chunk.children.length; i < e; ++i) {
|
2479 |
+
var child = chunk.children[i], ch = child.height;
|
2480 |
+
if (h < ch) { chunk = child; continue outer; }
|
2481 |
+
h -= ch;
|
2482 |
+
n += child.chunkSize();
|
2483 |
+
}
|
2484 |
+
return n;
|
2485 |
+
} while (!chunk.lines);
|
2486 |
+
for (var i = 0, e = chunk.lines.length; i < e; ++i) {
|
2487 |
+
var line = chunk.lines[i], lh = line.height;
|
2488 |
+
if (h < lh) break;
|
2489 |
+
h -= lh;
|
2490 |
+
}
|
2491 |
+
return n + i;
|
2492 |
+
}
|
2493 |
+
function heightAtLine(chunk, n) {
|
2494 |
+
var h = 0;
|
2495 |
+
outer: do {
|
2496 |
+
for (var i = 0, e = chunk.children.length; i < e; ++i) {
|
2497 |
+
var child = chunk.children[i], sz = child.chunkSize();
|
2498 |
+
if (n < sz) { chunk = child; continue outer; }
|
2499 |
+
n -= sz;
|
2500 |
+
h += child.height;
|
2501 |
+
}
|
2502 |
+
return h;
|
2503 |
+
} while (!chunk.lines);
|
2504 |
+
for (var i = 0; i < n; ++i) h += chunk.lines[i].height;
|
2505 |
+
return h;
|
2506 |
+
}
|
2507 |
+
|
2508 |
+
// The history object 'chunks' changes that are made close together
|
2509 |
+
// and at almost the same time into bigger undoable units.
|
2510 |
+
function History() {
|
2511 |
+
this.time = 0;
|
2512 |
+
this.done = []; this.undone = [];
|
2513 |
+
}
|
2514 |
+
History.prototype = {
|
2515 |
+
addChange: function(start, added, old) {
|
2516 |
+
this.undone.length = 0;
|
2517 |
+
var time = +new Date, last = this.done[this.done.length - 1];
|
2518 |
+
if (time - this.time > 400 || !last ||
|
2519 |
+
last.start > start + added || last.start + last.added < start - last.added + last.old.length)
|
2520 |
+
this.done.push({start: start, added: added, old: old});
|
2521 |
+
else {
|
2522 |
+
var oldoff = 0;
|
2523 |
+
if (start < last.start) {
|
2524 |
+
for (var i = last.start - start - 1; i >= 0; --i)
|
2525 |
+
last.old.unshift(old[i]);
|
2526 |
+
last.added += last.start - start;
|
2527 |
+
last.start = start;
|
2528 |
+
}
|
2529 |
+
else if (last.start < start) {
|
2530 |
+
oldoff = start - last.start;
|
2531 |
+
added += oldoff;
|
2532 |
+
}
|
2533 |
+
for (var i = last.added - oldoff, e = old.length; i < e; ++i)
|
2534 |
+
last.old.push(old[i]);
|
2535 |
+
if (last.added < added) last.added = added;
|
2536 |
+
}
|
2537 |
+
this.time = time;
|
2538 |
+
}
|
2539 |
+
};
|
2540 |
+
|
2541 |
+
function stopMethod() {e_stop(this);}
|
2542 |
+
// Ensure an event has a stop method.
|
2543 |
+
function addStop(event) {
|
2544 |
+
if (!event.stop) event.stop = stopMethod;
|
2545 |
+
return event;
|
2546 |
+
}
|
2547 |
+
|
2548 |
+
function e_preventDefault(e) {
|
2549 |
+
if (e.preventDefault) e.preventDefault();
|
2550 |
+
else e.returnValue = false;
|
2551 |
+
}
|
2552 |
+
function e_stopPropagation(e) {
|
2553 |
+
if (e.stopPropagation) e.stopPropagation();
|
2554 |
+
else e.cancelBubble = true;
|
2555 |
+
}
|
2556 |
+
function e_stop(e) {e_preventDefault(e); e_stopPropagation(e);}
|
2557 |
+
CodeMirror.e_stop = e_stop;
|
2558 |
+
CodeMirror.e_preventDefault = e_preventDefault;
|
2559 |
+
CodeMirror.e_stopPropagation = e_stopPropagation;
|
2560 |
+
|
2561 |
+
function e_target(e) {return e.target || e.srcElement;}
|
2562 |
+
function e_button(e) {
|
2563 |
+
if (e.which) return e.which;
|
2564 |
+
else if (e.button & 1) return 1;
|
2565 |
+
else if (e.button & 2) return 3;
|
2566 |
+
else if (e.button & 4) return 2;
|
2567 |
+
}
|
2568 |
+
|
2569 |
+
// Event handler registration. If disconnect is true, it'll return a
|
2570 |
+
// function that unregisters the handler.
|
2571 |
+
function connect(node, type, handler, disconnect) {
|
2572 |
+
if (typeof node.addEventListener == "function") {
|
2573 |
+
node.addEventListener(type, handler, false);
|
2574 |
+
if (disconnect) return function() {node.removeEventListener(type, handler, false);};
|
2575 |
+
}
|
2576 |
+
else {
|
2577 |
+
var wrapHandler = function(event) {handler(event || window.event);};
|
2578 |
+
node.attachEvent("on" + type, wrapHandler);
|
2579 |
+
if (disconnect) return function() {node.detachEvent("on" + type, wrapHandler);};
|
2580 |
+
}
|
2581 |
+
}
|
2582 |
+
CodeMirror.connect = connect;
|
2583 |
+
|
2584 |
+
function Delayed() {this.id = null;}
|
2585 |
+
Delayed.prototype = {set: function(ms, f) {clearTimeout(this.id); this.id = setTimeout(f, ms);}};
|
2586 |
+
|
2587 |
+
// Detect drag-and-drop
|
2588 |
+
var dragAndDrop = function() {
|
2589 |
+
// IE8 has ondragstart and ondrop properties, but doesn't seem to
|
2590 |
+
// actually support ondragstart the way it's supposed to work.
|
2591 |
+
if (/MSIE [1-8]\b/.test(navigator.userAgent)) return false;
|
2592 |
+
var div = document.createElement('div');
|
2593 |
+
return "draggable" in div;
|
2594 |
+
}();
|
2595 |
+
|
2596 |
+
var gecko = /gecko\/\d{7}/i.test(navigator.userAgent);
|
2597 |
+
var ie = /MSIE \d/.test(navigator.userAgent);
|
2598 |
+
var webkit = /WebKit\//.test(navigator.userAgent);
|
2599 |
+
|
2600 |
+
var lineSep = "\n";
|
2601 |
+
// Feature-detect whether newlines in textareas are converted to \r\n
|
2602 |
+
(function () {
|
2603 |
+
var te = document.createElement("textarea");
|
2604 |
+
te.value = "foo\nbar";
|
2605 |
+
if (te.value.indexOf("\r") > -1) lineSep = "\r\n";
|
2606 |
+
}());
|
2607 |
+
|
2608 |
+
// Counts the column offset in a string, taking tabs into account.
|
2609 |
+
// Used mostly to find indentation.
|
2610 |
+
function countColumn(string, end, tabSize) {
|
2611 |
+
if (end == null) {
|
2612 |
+
end = string.search(/[^\s\u00a0]/);
|
2613 |
+
if (end == -1) end = string.length;
|
2614 |
+
}
|
2615 |
+
for (var i = 0, n = 0; i < end; ++i) {
|
2616 |
+
if (string.charAt(i) == "\t") n += tabSize - (n % tabSize);
|
2617 |
+
else ++n;
|
2618 |
+
}
|
2619 |
+
return n;
|
2620 |
+
}
|
2621 |
+
|
2622 |
+
function computedStyle(elt) {
|
2623 |
+
if (elt.currentStyle) return elt.currentStyle;
|
2624 |
+
return window.getComputedStyle(elt, null);
|
2625 |
+
}
|
2626 |
+
|
2627 |
+
// Find the position of an element by following the offsetParent chain.
|
2628 |
+
// If screen==true, it returns screen (rather than page) coordinates.
|
2629 |
+
function eltOffset(node, screen) {
|
2630 |
+
var bod = node.ownerDocument.body;
|
2631 |
+
var x = 0, y = 0, skipBody = false;
|
2632 |
+
for (var n = node; n; n = n.offsetParent) {
|
2633 |
+
var ol = n.offsetLeft, ot = n.offsetTop;
|
2634 |
+
// Firefox reports weird inverted offsets when the body has a border.
|
2635 |
+
if (n == bod) { x += Math.abs(ol); y += Math.abs(ot); }
|
2636 |
+
else { x += ol, y += ot; }
|
2637 |
+
if (screen && computedStyle(n).position == "fixed")
|
2638 |
+
skipBody = true;
|
2639 |
+
}
|
2640 |
+
var e = screen && !skipBody ? null : bod;
|
2641 |
+
for (var n = node.parentNode; n != e; n = n.parentNode)
|
2642 |
+
if (n.scrollLeft != null) { x -= n.scrollLeft; y -= n.scrollTop;}
|
2643 |
+
return {left: x, top: y};
|
2644 |
+
}
|
2645 |
+
// Use the faster and saner getBoundingClientRect method when possible.
|
2646 |
+
if (document.documentElement.getBoundingClientRect != null) eltOffset = function(node, screen) {
|
2647 |
+
// Take the parts of bounding client rect that we are interested in so we are able to edit if need be,
|
2648 |
+
// since the returned value cannot be changed externally (they are kept in sync as the element moves within the page)
|
2649 |
+
try { var box = node.getBoundingClientRect(); box = { top: box.top, left: box.left }; }
|
2650 |
+
catch(e) { box = {top: 0, left: 0}; }
|
2651 |
+
if (!screen) {
|
2652 |
+
// Get the toplevel scroll, working around browser differences.
|
2653 |
+
if (window.pageYOffset == null) {
|
2654 |
+
var t = document.documentElement || document.body.parentNode;
|
2655 |
+
if (t.scrollTop == null) t = document.body;
|
2656 |
+
box.top += t.scrollTop; box.left += t.scrollLeft;
|
2657 |
+
} else {
|
2658 |
+
box.top += window.pageYOffset; box.left += window.pageXOffset;
|
2659 |
+
}
|
2660 |
+
}
|
2661 |
+
return box;
|
2662 |
+
};
|
2663 |
+
|
2664 |
+
// Get a node's text content.
|
2665 |
+
function eltText(node) {
|
2666 |
+
return node.textContent || node.innerText || node.nodeValue || "";
|
2667 |
+
}
|
2668 |
+
|
2669 |
+
// Operations on {line, ch} objects.
|
2670 |
+
function posEq(a, b) {return a.line == b.line && a.ch == b.ch;}
|
2671 |
+
function posLess(a, b) {return a.line < b.line || (a.line == b.line && a.ch < b.ch);}
|
2672 |
+
function copyPos(x) {return {line: x.line, ch: x.ch};}
|
2673 |
+
|
2674 |
+
var escapeElement = document.createElement("pre");
|
2675 |
+
function htmlEscape(str) {
|
2676 |
+
escapeElement.textContent = str;
|
2677 |
+
return escapeElement.innerHTML;
|
2678 |
+
}
|
2679 |
+
// Recent (late 2011) Opera betas insert bogus newlines at the start
|
2680 |
+
// of the textContent, so we strip those.
|
2681 |
+
if (htmlEscape("a") == "\na")
|
2682 |
+
htmlEscape = function(str) {
|
2683 |
+
escapeElement.textContent = str;
|
2684 |
+
return escapeElement.innerHTML.slice(1);
|
2685 |
+
};
|
2686 |
+
// Some IEs don't preserve tabs through innerHTML
|
2687 |
+
else if (htmlEscape("\t") != "\t")
|
2688 |
+
htmlEscape = function(str) {
|
2689 |
+
escapeElement.innerHTML = "";
|
2690 |
+
escapeElement.appendChild(document.createTextNode(str));
|
2691 |
+
return escapeElement.innerHTML;
|
2692 |
+
};
|
2693 |
+
CodeMirror.htmlEscape = htmlEscape;
|
2694 |
+
|
2695 |
+
// Used to position the cursor after an undo/redo by finding the
|
2696 |
+
// last edited character.
|
2697 |
+
function editEnd(from, to) {
|
2698 |
+
if (!to) return from ? from.length : 0;
|
2699 |
+
if (!from) return to.length;
|
2700 |
+
for (var i = from.length, j = to.length; i >= 0 && j >= 0; --i, --j)
|
2701 |
+
if (from.charAt(i) != to.charAt(j)) break;
|
2702 |
+
return j + 1;
|
2703 |
+
}
|
2704 |
+
|
2705 |
+
function indexOf(collection, elt) {
|
2706 |
+
if (collection.indexOf) return collection.indexOf(elt);
|
2707 |
+
for (var i = 0, e = collection.length; i < e; ++i)
|
2708 |
+
if (collection[i] == elt) return i;
|
2709 |
+
return -1;
|
2710 |
+
}
|
2711 |
+
function isWordChar(ch) {
|
2712 |
+
return /\w/.test(ch) || ch.toUpperCase() != ch.toLowerCase();
|
2713 |
+
}
|
2714 |
+
|
2715 |
+
// See if "".split is the broken IE version, if so, provide an
|
2716 |
+
// alternative way to split lines.
|
2717 |
+
var splitLines = "\n\nb".split(/\n/).length != 3 ? function(string) {
|
2718 |
+
var pos = 0, nl, result = [];
|
2719 |
+
while ((nl = string.indexOf("\n", pos)) > -1) {
|
2720 |
+
result.push(string.slice(pos, string.charAt(nl-1) == "\r" ? nl - 1 : nl));
|
2721 |
+
pos = nl + 1;
|
2722 |
+
}
|
2723 |
+
result.push(string.slice(pos));
|
2724 |
+
return result;
|
2725 |
+
} : function(string){return string.split(/\r?\n/);};
|
2726 |
+
CodeMirror.splitLines = splitLines;
|
2727 |
+
|
2728 |
+
var hasSelection = window.getSelection ? function(te) {
|
2729 |
+
try { return te.selectionStart != te.selectionEnd; }
|
2730 |
+
catch(e) { return false; }
|
2731 |
+
} : function(te) {
|
2732 |
+
try {var range = te.ownerDocument.selection.createRange();}
|
2733 |
+
catch(e) {}
|
2734 |
+
if (!range || range.parentElement() != te) return false;
|
2735 |
+
return range.compareEndPoints("StartToEnd", range) != 0;
|
2736 |
+
};
|
2737 |
+
|
2738 |
+
CodeMirror.defineMode("null", function() {
|
2739 |
+
return {token: function(stream) {stream.skipToEnd();}};
|
2740 |
+
});
|
2741 |
+
CodeMirror.defineMIME("text/plain", "null");
|
2742 |
+
|
2743 |
+
var keyNames = {3: "Enter", 8: "Backspace", 9: "Tab", 13: "Enter", 16: "Shift", 17: "Ctrl", 18: "Alt",
|
2744 |
+
19: "Pause", 20: "CapsLock", 27: "Esc", 32: "Space", 33: "PageUp", 34: "PageDown", 35: "End",
|
2745 |
+
36: "Home", 37: "Left", 38: "Up", 39: "Right", 40: "Down", 44: "PrintScrn", 45: "Insert",
|
2746 |
+
46: "Delete", 59: ";", 91: "Mod", 92: "Mod", 93: "Mod", 186: ";", 187: "=", 188: ",",
|
2747 |
+
189: "-", 190: ".", 191: "/", 192: "`", 219: "[", 220: "\\", 221: "]", 222: "'", 63276: "PageUp",
|
2748 |
+
63277: "PageDown", 63275: "End", 63273: "Home", 63234: "Left", 63232: "Up", 63235: "Right",
|
2749 |
+
63233: "Down", 63302: "Insert", 63272: "Delete"};
|
2750 |
+
CodeMirror.keyNames = keyNames;
|
2751 |
+
(function() {
|
2752 |
+
// Number keys
|
2753 |
+
for (var i = 0; i < 10; i++) keyNames[i + 48] = String(i);
|
2754 |
+
// Alphabetic keys
|
2755 |
+
for (var i = 65; i <= 90; i++) keyNames[i] = String.fromCharCode(i);
|
2756 |
+
// Function keys
|
2757 |
+
for (var i = 1; i <= 12; i++) keyNames[i + 111] = keyNames[i + 63235] = "F" + i;
|
2758 |
+
})();
|
2759 |
+
|
2760 |
+
return CodeMirror;
|
2761 |
+
})();
|
extensions/codemirror/js/css.js
ADDED
@@ -0,0 +1,124 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("css", function(config) {
|
2 |
+
var indentUnit = config.indentUnit, type;
|
3 |
+
function ret(style, tp) {type = tp; return style;}
|
4 |
+
|
5 |
+
function tokenBase(stream, state) {
|
6 |
+
var ch = stream.next();
|
7 |
+
if (ch == "@") {stream.eatWhile(/[\w\\\-]/); return ret("meta", stream.current());}
|
8 |
+
else if (ch == "/" && stream.eat("*")) {
|
9 |
+
state.tokenize = tokenCComment;
|
10 |
+
return tokenCComment(stream, state);
|
11 |
+
}
|
12 |
+
else if (ch == "<" && stream.eat("!")) {
|
13 |
+
state.tokenize = tokenSGMLComment;
|
14 |
+
return tokenSGMLComment(stream, state);
|
15 |
+
}
|
16 |
+
else if (ch == "=") ret(null, "compare");
|
17 |
+
else if ((ch == "~" || ch == "|") && stream.eat("=")) return ret(null, "compare");
|
18 |
+
else if (ch == "\"" || ch == "'") {
|
19 |
+
state.tokenize = tokenString(ch);
|
20 |
+
return state.tokenize(stream, state);
|
21 |
+
}
|
22 |
+
else if (ch == "#") {
|
23 |
+
stream.eatWhile(/[\w\\\-]/);
|
24 |
+
return ret("atom", "hash");
|
25 |
+
}
|
26 |
+
else if (ch == "!") {
|
27 |
+
stream.match(/^\s*\w*/);
|
28 |
+
return ret("keyword", "important");
|
29 |
+
}
|
30 |
+
else if (/\d/.test(ch)) {
|
31 |
+
stream.eatWhile(/[\w.%]/);
|
32 |
+
return ret("number", "unit");
|
33 |
+
}
|
34 |
+
else if (/[,.+>*\/]/.test(ch)) {
|
35 |
+
return ret(null, "select-op");
|
36 |
+
}
|
37 |
+
else if (/[;{}:\[\]]/.test(ch)) {
|
38 |
+
return ret(null, ch);
|
39 |
+
}
|
40 |
+
else {
|
41 |
+
stream.eatWhile(/[\w\\\-]/);
|
42 |
+
return ret("variable", "variable");
|
43 |
+
}
|
44 |
+
}
|
45 |
+
|
46 |
+
function tokenCComment(stream, state) {
|
47 |
+
var maybeEnd = false, ch;
|
48 |
+
while ((ch = stream.next()) != null) {
|
49 |
+
if (maybeEnd && ch == "/") {
|
50 |
+
state.tokenize = tokenBase;
|
51 |
+
break;
|
52 |
+
}
|
53 |
+
maybeEnd = (ch == "*");
|
54 |
+
}
|
55 |
+
return ret("comment", "comment");
|
56 |
+
}
|
57 |
+
|
58 |
+
function tokenSGMLComment(stream, state) {
|
59 |
+
var dashes = 0, ch;
|
60 |
+
while ((ch = stream.next()) != null) {
|
61 |
+
if (dashes >= 2 && ch == ">") {
|
62 |
+
state.tokenize = tokenBase;
|
63 |
+
break;
|
64 |
+
}
|
65 |
+
dashes = (ch == "-") ? dashes + 1 : 0;
|
66 |
+
}
|
67 |
+
return ret("comment", "comment");
|
68 |
+
}
|
69 |
+
|
70 |
+
function tokenString(quote) {
|
71 |
+
return function(stream, state) {
|
72 |
+
var escaped = false, ch;
|
73 |
+
while ((ch = stream.next()) != null) {
|
74 |
+
if (ch == quote && !escaped)
|
75 |
+
break;
|
76 |
+
escaped = !escaped && ch == "\\";
|
77 |
+
}
|
78 |
+
if (!escaped) state.tokenize = tokenBase;
|
79 |
+
return ret("string", "string");
|
80 |
+
};
|
81 |
+
}
|
82 |
+
|
83 |
+
return {
|
84 |
+
startState: function(base) {
|
85 |
+
return {tokenize: tokenBase,
|
86 |
+
baseIndent: base || 0,
|
87 |
+
stack: []};
|
88 |
+
},
|
89 |
+
|
90 |
+
token: function(stream, state) {
|
91 |
+
if (stream.eatSpace()) return null;
|
92 |
+
var style = state.tokenize(stream, state);
|
93 |
+
|
94 |
+
var context = state.stack[state.stack.length-1];
|
95 |
+
if (type == "hash" && context == "rule") style = "atom";
|
96 |
+
else if (style == "variable") {
|
97 |
+
if (context == "rule") style = "number";
|
98 |
+
else if (!context || context == "@media{") style = "tag";
|
99 |
+
}
|
100 |
+
|
101 |
+
if (context == "rule" && /^[\{\};]$/.test(type))
|
102 |
+
state.stack.pop();
|
103 |
+
if (type == "{") {
|
104 |
+
if (context == "@media") state.stack[state.stack.length-1] = "@media{";
|
105 |
+
else state.stack.push("{");
|
106 |
+
}
|
107 |
+
else if (type == "}") state.stack.pop();
|
108 |
+
else if (type == "@media") state.stack.push("@media");
|
109 |
+
else if (context == "{" && type != "comment") state.stack.push("rule");
|
110 |
+
return style;
|
111 |
+
},
|
112 |
+
|
113 |
+
indent: function(state, textAfter) {
|
114 |
+
var n = state.stack.length;
|
115 |
+
if (/^\}/.test(textAfter))
|
116 |
+
n -= state.stack[state.stack.length-1] == "rule" ? 2 : 1;
|
117 |
+
return state.baseIndent + n * indentUnit;
|
118 |
+
},
|
119 |
+
|
120 |
+
electricChars: "}"
|
121 |
+
};
|
122 |
+
});
|
123 |
+
|
124 |
+
CodeMirror.defineMIME("text/css", "css");
|
extensions/codemirror/js/dialog.js
ADDED
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Open simple dialogs on top of an editor. Relies on dialog.css.
|
2 |
+
|
3 |
+
(function() {
|
4 |
+
function dialogDiv(cm, template) {
|
5 |
+
var wrap = cm.getWrapperElement();
|
6 |
+
var dialog = wrap.insertBefore(document.createElement("div"), wrap.firstChild);
|
7 |
+
dialog.className = "CodeMirror-dialog";
|
8 |
+
dialog.innerHTML = '<div>' + template + '</div>';
|
9 |
+
return dialog;
|
10 |
+
}
|
11 |
+
|
12 |
+
CodeMirror.defineExtension("openDialog", function(template, callback) {
|
13 |
+
var dialog = dialogDiv(this, template);
|
14 |
+
var closed = false, me = this;
|
15 |
+
function close() {
|
16 |
+
if (closed) return;
|
17 |
+
closed = true;
|
18 |
+
dialog.parentNode.removeChild(dialog);
|
19 |
+
}
|
20 |
+
var inp = dialog.getElementsByTagName("input")[0];
|
21 |
+
if (inp) {
|
22 |
+
CodeMirror.connect(inp, "keydown", function(e) {
|
23 |
+
if (e.keyCode == 13 || e.keyCode == 27) {
|
24 |
+
CodeMirror.e_stop(e);
|
25 |
+
close();
|
26 |
+
me.focus();
|
27 |
+
if (e.keyCode == 13) callback(inp.value);
|
28 |
+
}
|
29 |
+
});
|
30 |
+
inp.focus();
|
31 |
+
CodeMirror.connect(inp, "blur", close);
|
32 |
+
}
|
33 |
+
return close;
|
34 |
+
});
|
35 |
+
|
36 |
+
CodeMirror.defineExtension("openConfirm", function(template, callbacks) {
|
37 |
+
var dialog = dialogDiv(this, template);
|
38 |
+
var buttons = dialog.getElementsByTagName("button");
|
39 |
+
var closed = false, me = this, blurring = 1;
|
40 |
+
function close() {
|
41 |
+
if (closed) return;
|
42 |
+
closed = true;
|
43 |
+
dialog.parentNode.removeChild(dialog);
|
44 |
+
me.focus();
|
45 |
+
}
|
46 |
+
buttons[0].focus();
|
47 |
+
for (var i = 0; i < buttons.length; ++i) {
|
48 |
+
var b = buttons[i];
|
49 |
+
(function(callback) {
|
50 |
+
CodeMirror.connect(b, "click", function(e) {
|
51 |
+
CodeMirror.e_preventDefault(e);
|
52 |
+
close();
|
53 |
+
if (callback) callback(me);
|
54 |
+
});
|
55 |
+
})(callbacks[i]);
|
56 |
+
CodeMirror.connect(b, "blur", function() {
|
57 |
+
--blurring;
|
58 |
+
setTimeout(function() { if (blurring <= 0) close(); }, 200);
|
59 |
+
});
|
60 |
+
CodeMirror.connect(b, "focus", function() { ++blurring; });
|
61 |
+
}
|
62 |
+
});
|
63 |
+
})();
|
extensions/codemirror/js/foldcode.js
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.braceRangeFinder = function(cm, line) {
|
2 |
+
var lineText = cm.getLine(line);
|
3 |
+
var startChar = lineText.lastIndexOf("{");
|
4 |
+
if (startChar < 0 || lineText.lastIndexOf("}") > startChar) return;
|
5 |
+
var tokenType = cm.getTokenAt({line: line, ch: startChar}).className;
|
6 |
+
var count = 1, lastLine = cm.lineCount(), end;
|
7 |
+
outer: for (var i = line + 1; i < lastLine; ++i) {
|
8 |
+
var text = cm.getLine(i), pos = 0;
|
9 |
+
for (;;) {
|
10 |
+
var nextOpen = text.indexOf("{", pos), nextClose = text.indexOf("}", pos);
|
11 |
+
if (nextOpen < 0) nextOpen = text.length;
|
12 |
+
if (nextClose < 0) nextClose = text.length;
|
13 |
+
pos = Math.min(nextOpen, nextClose);
|
14 |
+
if (pos == text.length) break;
|
15 |
+
if (cm.getTokenAt({line: i, ch: pos + 1}).className == tokenType) {
|
16 |
+
if (pos == nextOpen) ++count;
|
17 |
+
else if (!--count) { end = i; break outer; }
|
18 |
+
}
|
19 |
+
++pos;
|
20 |
+
}
|
21 |
+
}
|
22 |
+
if (end == null || end == line + 1) return;
|
23 |
+
return end;
|
24 |
+
};
|
25 |
+
|
26 |
+
|
27 |
+
CodeMirror.newFoldFunction = function(rangeFinder, markText) {
|
28 |
+
var folded = [];
|
29 |
+
if (markText == null) markText = '<div style="position: absolute; left: 2px; color:#600">▼</div>%N%';
|
30 |
+
|
31 |
+
function isFolded(cm, n) {
|
32 |
+
for (var i = 0; i < folded.length; ++i) {
|
33 |
+
var start = cm.lineInfo(folded[i].start);
|
34 |
+
if (!start) folded.splice(i--, 1);
|
35 |
+
else if (start.line == n) return {pos: i, region: folded[i]};
|
36 |
+
}
|
37 |
+
}
|
38 |
+
|
39 |
+
function expand(cm, region) {
|
40 |
+
cm.clearMarker(region.start);
|
41 |
+
for (var i = 0; i < region.hidden.length; ++i)
|
42 |
+
cm.showLine(region.hidden[i]);
|
43 |
+
}
|
44 |
+
|
45 |
+
return function(cm, line) {
|
46 |
+
cm.operation(function() {
|
47 |
+
var known = isFolded(cm, line);
|
48 |
+
if (known) {
|
49 |
+
folded.splice(known.pos, 1);
|
50 |
+
expand(cm, known.region);
|
51 |
+
} else {
|
52 |
+
var end = rangeFinder(cm, line);
|
53 |
+
if (end == null) return;
|
54 |
+
var hidden = [];
|
55 |
+
for (var i = line + 1; i < end; ++i) {
|
56 |
+
var handle = cm.hideLine(i);
|
57 |
+
if (handle) hidden.push(handle);
|
58 |
+
}
|
59 |
+
var first = cm.setMarker(line, markText);
|
60 |
+
var region = {start: first, hidden: hidden};
|
61 |
+
cm.onDeleteLine(first, function() { expand(cm, region); });
|
62 |
+
folded.push(region);
|
63 |
+
}
|
64 |
+
});
|
65 |
+
};
|
66 |
+
};
|
extensions/codemirror/js/htmlembedded.js
ADDED
@@ -0,0 +1,68 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("htmlembedded", function(config, parserConfig) {
|
2 |
+
|
3 |
+
//config settings
|
4 |
+
var scriptStartRegex = parserConfig.scriptStartRegex || /^<%/i,
|
5 |
+
scriptEndRegex = parserConfig.scriptEndRegex || /^%>/i;
|
6 |
+
|
7 |
+
//inner modes
|
8 |
+
var scriptingMode, htmlMixedMode;
|
9 |
+
|
10 |
+
//tokenizer when in html mode
|
11 |
+
function htmlDispatch(stream, state) {
|
12 |
+
if (stream.match(scriptStartRegex, false)) {
|
13 |
+
state.token=scriptingDispatch;
|
14 |
+
return scriptingMode.token(stream, state.scriptState);
|
15 |
+
}
|
16 |
+
else
|
17 |
+
return htmlMixedMode.token(stream, state.htmlState);
|
18 |
+
}
|
19 |
+
|
20 |
+
//tokenizer when in scripting mode
|
21 |
+
function scriptingDispatch(stream, state) {
|
22 |
+
if (stream.match(scriptEndRegex, false)) {
|
23 |
+
state.token=htmlDispatch;
|
24 |
+
return htmlMixedMode.token(stream, state.htmlState);
|
25 |
+
}
|
26 |
+
else
|
27 |
+
return scriptingMode.token(stream, state.scriptState);
|
28 |
+
}
|
29 |
+
|
30 |
+
|
31 |
+
return {
|
32 |
+
startState: function() {
|
33 |
+
scriptingMode = scriptingMode || CodeMirror.getMode(config, parserConfig.scriptingModeSpec);
|
34 |
+
htmlMixedMode = htmlMixedMode || CodeMirror.getMode(config, "htmlmixed");
|
35 |
+
return {
|
36 |
+
token : parserConfig.startOpen ? scriptingDispatch : htmlDispatch,
|
37 |
+
htmlState : htmlMixedMode.startState(),
|
38 |
+
scriptState : scriptingMode.startState()
|
39 |
+
}
|
40 |
+
},
|
41 |
+
|
42 |
+
token: function(stream, state) {
|
43 |
+
return state.token(stream, state);
|
44 |
+
},
|
45 |
+
|
46 |
+
indent: function(state, textAfter) {
|
47 |
+
if (state.token == htmlDispatch)
|
48 |
+
return htmlMixedMode.indent(state.htmlState, textAfter);
|
49 |
+
else
|
50 |
+
return scriptingMode.indent(state.scriptState, textAfter);
|
51 |
+
},
|
52 |
+
|
53 |
+
copyState: function(state) {
|
54 |
+
return {
|
55 |
+
token : state.token,
|
56 |
+
htmlState : CodeMirror.copyState(htmlMixedMode, state.htmlState),
|
57 |
+
scriptState : CodeMirror.copyState(scriptingMode, state.scriptState)
|
58 |
+
}
|
59 |
+
},
|
60 |
+
|
61 |
+
|
62 |
+
electricChars: "/{}:"
|
63 |
+
}
|
64 |
+
});
|
65 |
+
|
66 |
+
CodeMirror.defineMIME("application/x-ejs", { name: "htmlembedded", scriptingModeSpec:"javascript"});
|
67 |
+
CodeMirror.defineMIME("application/x-aspx", { name: "htmlembedded", scriptingModeSpec:"text/x-csharp"});
|
68 |
+
CodeMirror.defineMIME("application/x-jsp", { name: "htmlembedded", scriptingModeSpec:"text/x-java"});
|
extensions/codemirror/js/htmlmixed.js
ADDED
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("htmlmixed", function(config, parserConfig) {
|
2 |
+
var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
|
3 |
+
var jsMode = CodeMirror.getMode(config, "javascript");
|
4 |
+
var cssMode = CodeMirror.getMode(config, "css");
|
5 |
+
|
6 |
+
function html(stream, state) {
|
7 |
+
var style = htmlMode.token(stream, state.htmlState);
|
8 |
+
if (style == "tag" && stream.current() == ">" && state.htmlState.context) {
|
9 |
+
if (/^script$/i.test(state.htmlState.context.tagName)) {
|
10 |
+
state.token = javascript;
|
11 |
+
state.localState = jsMode.startState(htmlMode.indent(state.htmlState, ""));
|
12 |
+
state.mode = "javascript";
|
13 |
+
}
|
14 |
+
else if (/^style$/i.test(state.htmlState.context.tagName)) {
|
15 |
+
state.token = css;
|
16 |
+
state.localState = cssMode.startState(htmlMode.indent(state.htmlState, ""));
|
17 |
+
state.mode = "css";
|
18 |
+
}
|
19 |
+
}
|
20 |
+
return style;
|
21 |
+
}
|
22 |
+
function maybeBackup(stream, pat, style) {
|
23 |
+
var cur = stream.current();
|
24 |
+
var close = cur.search(pat);
|
25 |
+
if (close > -1) stream.backUp(cur.length - close);
|
26 |
+
return style;
|
27 |
+
}
|
28 |
+
function javascript(stream, state) {
|
29 |
+
if (stream.match(/^<\/\s*script\s*>/i, false)) {
|
30 |
+
state.token = html;
|
31 |
+
state.curState = null;
|
32 |
+
state.mode = "html";
|
33 |
+
return html(stream, state);
|
34 |
+
}
|
35 |
+
return maybeBackup(stream, /<\/\s*script\s*>/,
|
36 |
+
jsMode.token(stream, state.localState));
|
37 |
+
}
|
38 |
+
function css(stream, state) {
|
39 |
+
if (stream.match(/^<\/\s*style\s*>/i, false)) {
|
40 |
+
state.token = html;
|
41 |
+
state.localState = null;
|
42 |
+
state.mode = "html";
|
43 |
+
return html(stream, state);
|
44 |
+
}
|
45 |
+
return maybeBackup(stream, /<\/\s*style\s*>/,
|
46 |
+
cssMode.token(stream, state.localState));
|
47 |
+
}
|
48 |
+
|
49 |
+
return {
|
50 |
+
startState: function() {
|
51 |
+
var state = htmlMode.startState();
|
52 |
+
return {token: html, localState: null, mode: "html", htmlState: state};
|
53 |
+
},
|
54 |
+
|
55 |
+
copyState: function(state) {
|
56 |
+
if (state.localState)
|
57 |
+
var local = CodeMirror.copyState(state.token == css ? cssMode : jsMode, state.localState);
|
58 |
+
return {token: state.token, localState: local, mode: state.mode,
|
59 |
+
htmlState: CodeMirror.copyState(htmlMode, state.htmlState)};
|
60 |
+
},
|
61 |
+
|
62 |
+
token: function(stream, state) {
|
63 |
+
return state.token(stream, state);
|
64 |
+
},
|
65 |
+
|
66 |
+
indent: function(state, textAfter) {
|
67 |
+
if (state.token == html || /^\s*<\//.test(textAfter))
|
68 |
+
return htmlMode.indent(state.htmlState, textAfter);
|
69 |
+
else if (state.token == javascript)
|
70 |
+
return jsMode.indent(state.localState, textAfter);
|
71 |
+
else
|
72 |
+
return cssMode.indent(state.localState, textAfter);
|
73 |
+
},
|
74 |
+
|
75 |
+
compareStates: function(a, b) {
|
76 |
+
return htmlMode.compareStates(a.htmlState, b.htmlState);
|
77 |
+
},
|
78 |
+
|
79 |
+
electricChars: "/{}:"
|
80 |
+
}
|
81 |
+
});
|
82 |
+
|
83 |
+
CodeMirror.defineMIME("text/html", "htmlmixed");
|
extensions/codemirror/js/javascript.js
ADDED
@@ -0,0 +1,360 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("javascript", function(config, parserConfig) {
|
2 |
+
var indentUnit = config.indentUnit;
|
3 |
+
var jsonMode = parserConfig.json;
|
4 |
+
|
5 |
+
// Tokenizer
|
6 |
+
|
7 |
+
var keywords = function(){
|
8 |
+
function kw(type) {return {type: type, style: "keyword"};}
|
9 |
+
var A = kw("keyword a"), B = kw("keyword b"), C = kw("keyword c");
|
10 |
+
var operator = kw("operator"), atom = {type: "atom", style: "atom"};
|
11 |
+
return {
|
12 |
+
"if": A, "while": A, "with": A, "else": B, "do": B, "try": B, "finally": B,
|
13 |
+
"return": C, "break": C, "continue": C, "new": C, "delete": C, "throw": C,
|
14 |
+
"var": kw("var"), "const": kw("var"), "let": kw("var"),
|
15 |
+
"function": kw("function"), "catch": kw("catch"),
|
16 |
+
"for": kw("for"), "switch": kw("switch"), "case": kw("case"), "default": kw("default"),
|
17 |
+
"in": operator, "typeof": operator, "instanceof": operator,
|
18 |
+
"true": atom, "false": atom, "null": atom, "undefined": atom, "NaN": atom, "Infinity": atom
|
19 |
+
};
|
20 |
+
}();
|
21 |
+
|
22 |
+
var isOperatorChar = /[+\-*&%=<>!?|]/;
|
23 |
+
|
24 |
+
function chain(stream, state, f) {
|
25 |
+
state.tokenize = f;
|
26 |
+
return f(stream, state);
|
27 |
+
}
|
28 |
+
|
29 |
+
function nextUntilUnescaped(stream, end) {
|
30 |
+
var escaped = false, next;
|
31 |
+
while ((next = stream.next()) != null) {
|
32 |
+
if (next == end && !escaped)
|
33 |
+
return false;
|
34 |
+
escaped = !escaped && next == "\\";
|
35 |
+
}
|
36 |
+
return escaped;
|
37 |
+
}
|
38 |
+
|
39 |
+
// Used as scratch variables to communicate multiple values without
|
40 |
+
// consing up tons of objects.
|
41 |
+
var type, content;
|
42 |
+
function ret(tp, style, cont) {
|
43 |
+
type = tp; content = cont;
|
44 |
+
return style;
|
45 |
+
}
|
46 |
+
|
47 |
+
function jsTokenBase(stream, state) {
|
48 |
+
var ch = stream.next();
|
49 |
+
if (ch == '"' || ch == "'")
|
50 |
+
return chain(stream, state, jsTokenString(ch));
|
51 |
+
else if (/[\[\]{}\(\),;\:\.]/.test(ch))
|
52 |
+
return ret(ch);
|
53 |
+
else if (ch == "0" && stream.eat(/x/i)) {
|
54 |
+
stream.eatWhile(/[\da-f]/i);
|
55 |
+
return ret("number", "number");
|
56 |
+
}
|
57 |
+
else if (/\d/.test(ch)) {
|
58 |
+
stream.match(/^\d*(?:\.\d*)?(?:[eE][+\-]?\d+)?/);
|
59 |
+
return ret("number", "number");
|
60 |
+
}
|
61 |
+
else if (ch == "/") {
|
62 |
+
if (stream.eat("*")) {
|
63 |
+
return chain(stream, state, jsTokenComment);
|
64 |
+
}
|
65 |
+
else if (stream.eat("/")) {
|
66 |
+
stream.skipToEnd();
|
67 |
+
return ret("comment", "comment");
|
68 |
+
}
|
69 |
+
else if (state.reAllowed) {
|
70 |
+
nextUntilUnescaped(stream, "/");
|
71 |
+
stream.eatWhile(/[gimy]/); // 'y' is "sticky" option in Mozilla
|
72 |
+
return ret("regexp", "string");
|
73 |
+
}
|
74 |
+
else {
|
75 |
+
stream.eatWhile(isOperatorChar);
|
76 |
+
return ret("operator", null, stream.current());
|
77 |
+
}
|
78 |
+
}
|
79 |
+
else if (ch == "#") {
|
80 |
+
stream.skipToEnd();
|
81 |
+
return ret("error", "error");
|
82 |
+
}
|
83 |
+
else if (isOperatorChar.test(ch)) {
|
84 |
+
stream.eatWhile(isOperatorChar);
|
85 |
+
return ret("operator", null, stream.current());
|
86 |
+
}
|
87 |
+
else {
|
88 |
+
stream.eatWhile(/[\w\$_]/);
|
89 |
+
var word = stream.current(), known = keywords.propertyIsEnumerable(word) && keywords[word];
|
90 |
+
return (known && state.kwAllowed) ? ret(known.type, known.style, word) :
|
91 |
+
ret("variable", "variable", word);
|
92 |
+
}
|
93 |
+
}
|
94 |
+
|
95 |
+
function jsTokenString(quote) {
|
96 |
+
return function(stream, state) {
|
97 |
+
if (!nextUntilUnescaped(stream, quote))
|
98 |
+
state.tokenize = jsTokenBase;
|
99 |
+
return ret("string", "string");
|
100 |
+
};
|
101 |
+
}
|
102 |
+
|
103 |
+
function jsTokenComment(stream, state) {
|
104 |
+
var maybeEnd = false, ch;
|
105 |
+
while (ch = stream.next()) {
|
106 |
+
if (ch == "/" && maybeEnd) {
|
107 |
+
state.tokenize = jsTokenBase;
|
108 |
+
break;
|
109 |
+
}
|
110 |
+
maybeEnd = (ch == "*");
|
111 |
+
}
|
112 |
+
return ret("comment", "comment");
|
113 |
+
}
|
114 |
+
|
115 |
+
// Parser
|
116 |
+
|
117 |
+
var atomicTypes = {"atom": true, "number": true, "variable": true, "string": true, "regexp": true};
|
118 |
+
|
119 |
+
function JSLexical(indented, column, type, align, prev, info) {
|
120 |
+
this.indented = indented;
|
121 |
+
this.column = column;
|
122 |
+
this.type = type;
|
123 |
+
this.prev = prev;
|
124 |
+
this.info = info;
|
125 |
+
if (align != null) this.align = align;
|
126 |
+
}
|
127 |
+
|
128 |
+
function inScope(state, varname) {
|
129 |
+
for (var v = state.localVars; v; v = v.next)
|
130 |
+
if (v.name == varname) return true;
|
131 |
+
}
|
132 |
+
|
133 |
+
function parseJS(state, style, type, content, stream) {
|
134 |
+
var cc = state.cc;
|
135 |
+
// Communicate our context to the combinators.
|
136 |
+
// (Less wasteful than consing up a hundred closures on every call.)
|
137 |
+
cx.state = state; cx.stream = stream; cx.marked = null, cx.cc = cc;
|
138 |
+
|
139 |
+
if (!state.lexical.hasOwnProperty("align"))
|
140 |
+
state.lexical.align = true;
|
141 |
+
|
142 |
+
while(true) {
|
143 |
+
var combinator = cc.length ? cc.pop() : jsonMode ? expression : statement;
|
144 |
+
if (combinator(type, content)) {
|
145 |
+
while(cc.length && cc[cc.length - 1].lex)
|
146 |
+
cc.pop()();
|
147 |
+
if (cx.marked) return cx.marked;
|
148 |
+
if (type == "variable" && inScope(state, content)) return "variable-2";
|
149 |
+
return style;
|
150 |
+
}
|
151 |
+
}
|
152 |
+
}
|
153 |
+
|
154 |
+
// Combinator utils
|
155 |
+
|
156 |
+
var cx = {state: null, column: null, marked: null, cc: null};
|
157 |
+
function pass() {
|
158 |
+
for (var i = arguments.length - 1; i >= 0; i--) cx.cc.push(arguments[i]);
|
159 |
+
}
|
160 |
+
function cont() {
|
161 |
+
pass.apply(null, arguments);
|
162 |
+
return true;
|
163 |
+
}
|
164 |
+
function register(varname) {
|
165 |
+
var state = cx.state;
|
166 |
+
if (state.context) {
|
167 |
+
cx.marked = "def";
|
168 |
+
for (var v = state.localVars; v; v = v.next)
|
169 |
+
if (v.name == varname) return;
|
170 |
+
state.localVars = {name: varname, next: state.localVars};
|
171 |
+
}
|
172 |
+
}
|
173 |
+
|
174 |
+
// Combinators
|
175 |
+
|
176 |
+
var defaultVars = {name: "this", next: {name: "arguments"}};
|
177 |
+
function pushcontext() {
|
178 |
+
if (!cx.state.context) cx.state.localVars = defaultVars;
|
179 |
+
cx.state.context = {prev: cx.state.context, vars: cx.state.localVars};
|
180 |
+
}
|
181 |
+
function popcontext() {
|
182 |
+
cx.state.localVars = cx.state.context.vars;
|
183 |
+
cx.state.context = cx.state.context.prev;
|
184 |
+
}
|
185 |
+
function pushlex(type, info) {
|
186 |
+
var result = function() {
|
187 |
+
var state = cx.state;
|
188 |
+
state.lexical = new JSLexical(state.indented, cx.stream.column(), type, null, state.lexical, info)
|
189 |
+
};
|
190 |
+
result.lex = true;
|
191 |
+
return result;
|
192 |
+
}
|
193 |
+
function poplex() {
|
194 |
+
var state = cx.state;
|
195 |
+
if (state.lexical.prev) {
|
196 |
+
if (state.lexical.type == ")")
|
197 |
+
state.indented = state.lexical.indented;
|
198 |
+
state.lexical = state.lexical.prev;
|
199 |
+
}
|
200 |
+
}
|
201 |
+
poplex.lex = true;
|
202 |
+
|
203 |
+
function expect(wanted) {
|
204 |
+
return function expecting(type) {
|
205 |
+
if (type == wanted) return cont();
|
206 |
+
else if (wanted == ";") return pass();
|
207 |
+
else return cont(arguments.callee);
|
208 |
+
};
|
209 |
+
}
|
210 |
+
|
211 |
+
function statement(type) {
|
212 |
+
if (type == "var") return cont(pushlex("vardef"), vardef1, expect(";"), poplex);
|
213 |
+
if (type == "keyword a") return cont(pushlex("form"), expression, statement, poplex);
|
214 |
+
if (type == "keyword b") return cont(pushlex("form"), statement, poplex);
|
215 |
+
if (type == "{") return cont(pushlex("}"), block, poplex);
|
216 |
+
if (type == ";") return cont();
|
217 |
+
if (type == "function") return cont(functiondef);
|
218 |
+
if (type == "for") return cont(pushlex("form"), expect("("), pushlex(")"), forspec1, expect(")"),
|
219 |
+
poplex, statement, poplex);
|
220 |
+
if (type == "variable") return cont(pushlex("stat"), maybelabel);
|
221 |
+
if (type == "switch") return cont(pushlex("form"), expression, pushlex("}", "switch"), expect("{"),
|
222 |
+
block, poplex, poplex);
|
223 |
+
if (type == "case") return cont(expression, expect(":"));
|
224 |
+
if (type == "default") return cont(expect(":"));
|
225 |
+
if (type == "catch") return cont(pushlex("form"), pushcontext, expect("("), funarg, expect(")"),
|
226 |
+
statement, poplex, popcontext);
|
227 |
+
return pass(pushlex("stat"), expression, expect(";"), poplex);
|
228 |
+
}
|
229 |
+
function expression(type) {
|
230 |
+
if (atomicTypes.hasOwnProperty(type)) return cont(maybeoperator);
|
231 |
+
if (type == "function") return cont(functiondef);
|
232 |
+
if (type == "keyword c") return cont(maybeexpression);
|
233 |
+
if (type == "(") return cont(pushlex(")"), expression, expect(")"), poplex, maybeoperator);
|
234 |
+
if (type == "operator") return cont(expression);
|
235 |
+
if (type == "[") return cont(pushlex("]"), commasep(expression, "]"), poplex, maybeoperator);
|
236 |
+
if (type == "{") return cont(pushlex("}"), commasep(objprop, "}"), poplex, maybeoperator);
|
237 |
+
return cont();
|
238 |
+
}
|
239 |
+
function maybeexpression(type) {
|
240 |
+
if (type.match(/[;\}\)\],]/)) return pass();
|
241 |
+
return pass(expression);
|
242 |
+
}
|
243 |
+
|
244 |
+
function maybeoperator(type, value) {
|
245 |
+
if (type == "operator" && /\+\+|--/.test(value)) return cont(maybeoperator);
|
246 |
+
if (type == "operator") return cont(expression);
|
247 |
+
if (type == ";") return;
|
248 |
+
if (type == "(") return cont(pushlex(")"), commasep(expression, ")"), poplex, maybeoperator);
|
249 |
+
if (type == ".") return cont(property, maybeoperator);
|
250 |
+
if (type == "[") return cont(pushlex("]"), expression, expect("]"), poplex, maybeoperator);
|
251 |
+
}
|
252 |
+
function maybelabel(type) {
|
253 |
+
if (type == ":") return cont(poplex, statement);
|
254 |
+
return pass(maybeoperator, expect(";"), poplex);
|
255 |
+
}
|
256 |
+
function property(type) {
|
257 |
+
if (type == "variable") {cx.marked = "property"; return cont();}
|
258 |
+
}
|
259 |
+
function objprop(type) {
|
260 |
+
if (type == "variable") cx.marked = "property";
|
261 |
+
if (atomicTypes.hasOwnProperty(type)) return cont(expect(":"), expression);
|
262 |
+
}
|
263 |
+
function commasep(what, end) {
|
264 |
+
function proceed(type) {
|
265 |
+
if (type == ",") return cont(what, proceed);
|
266 |
+
if (type == end) return cont();
|
267 |
+
return cont(expect(end));
|
268 |
+
}
|
269 |
+
return function commaSeparated(type) {
|
270 |
+
if (type == end) return cont();
|
271 |
+
else return pass(what, proceed);
|
272 |
+
};
|
273 |
+
}
|
274 |
+
function block(type) {
|
275 |
+
if (type == "}") return cont();
|
276 |
+
return pass(statement, block);
|
277 |
+
}
|
278 |
+
function vardef1(type, value) {
|
279 |
+
if (type == "variable"){register(value); return cont(vardef2);}
|
280 |
+
return cont();
|
281 |
+
}
|
282 |
+
function vardef2(type, value) {
|
283 |
+
if (value == "=") return cont(expression, vardef2);
|
284 |
+
if (type == ",") return cont(vardef1);
|
285 |
+
}
|
286 |
+
function forspec1(type) {
|
287 |
+
if (type == "var") return cont(vardef1, forspec2);
|
288 |
+
if (type == ";") return pass(forspec2);
|
289 |
+
if (type == "variable") return cont(formaybein);
|
290 |
+
return pass(forspec2);
|
291 |
+
}
|
292 |
+
function formaybein(type, value) {
|
293 |
+
if (value == "in") return cont(expression);
|
294 |
+
return cont(maybeoperator, forspec2);
|
295 |
+
}
|
296 |
+
function forspec2(type, value) {
|
297 |
+
if (type == ";") return cont(forspec3);
|
298 |
+
if (value == "in") return cont(expression);
|
299 |
+
return cont(expression, expect(";"), forspec3);
|
300 |
+
}
|
301 |
+
function forspec3(type) {
|
302 |
+
if (type != ")") cont(expression);
|
303 |
+
}
|
304 |
+
function functiondef(type, value) {
|
305 |
+
if (type == "variable") {register(value); return cont(functiondef);}
|
306 |
+
if (type == "(") return cont(pushlex(")"), pushcontext, commasep(funarg, ")"), poplex, statement, popcontext);
|
307 |
+
}
|
308 |
+
function funarg(type, value) {
|
309 |
+
if (type == "variable") {register(value); return cont();}
|
310 |
+
}
|
311 |
+
|
312 |
+
// Interface
|
313 |
+
|
314 |
+
return {
|
315 |
+
startState: function(basecolumn) {
|
316 |
+
return {
|
317 |
+
tokenize: jsTokenBase,
|
318 |
+
reAllowed: true,
|
319 |
+
kwAllowed: true,
|
320 |
+
cc: [],
|
321 |
+
lexical: new JSLexical((basecolumn || 0) - indentUnit, 0, "block", false),
|
322 |
+
localVars: null,
|
323 |
+
context: null,
|
324 |
+
indented: 0
|
325 |
+
};
|
326 |
+
},
|
327 |
+
|
328 |
+
token: function(stream, state) {
|
329 |
+
if (stream.sol()) {
|
330 |
+
if (!state.lexical.hasOwnProperty("align"))
|
331 |
+
state.lexical.align = false;
|
332 |
+
state.indented = stream.indentation();
|
333 |
+
}
|
334 |
+
if (stream.eatSpace()) return null;
|
335 |
+
var style = state.tokenize(stream, state);
|
336 |
+
if (type == "comment") return style;
|
337 |
+
state.reAllowed = type == "operator" || type == "keyword c" || type.match(/^[\[{}\(,;:]$/);
|
338 |
+
state.kwAllowed = type != '.';
|
339 |
+
return parseJS(state, style, type, content, stream);
|
340 |
+
},
|
341 |
+
|
342 |
+
indent: function(state, textAfter) {
|
343 |
+
if (state.tokenize != jsTokenBase) return 0;
|
344 |
+
var firstChar = textAfter && textAfter.charAt(0), lexical = state.lexical,
|
345 |
+
type = lexical.type, closing = firstChar == type;
|
346 |
+
if (type == "vardef") return lexical.indented + 4;
|
347 |
+
else if (type == "form" && firstChar == "{") return lexical.indented;
|
348 |
+
else if (type == "stat" || type == "form") return lexical.indented + indentUnit;
|
349 |
+
else if (lexical.info == "switch" && !closing)
|
350 |
+
return lexical.indented + (/^(?:case|default)\b/.test(textAfter) ? indentUnit : 2 * indentUnit);
|
351 |
+
else if (lexical.align) return lexical.column + (closing ? 0 : 1);
|
352 |
+
else return lexical.indented + (closing ? 0 : indentUnit);
|
353 |
+
},
|
354 |
+
|
355 |
+
electricChars: ":{}"
|
356 |
+
};
|
357 |
+
});
|
358 |
+
|
359 |
+
CodeMirror.defineMIME("text/javascript", "javascript");
|
360 |
+
CodeMirror.defineMIME("application/json", {name: "javascript", json: true});
|
extensions/codemirror/js/php.js
ADDED
@@ -0,0 +1,120 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function() {
|
2 |
+
function keywords(str) {
|
3 |
+
var obj = {}, words = str.split(" ");
|
4 |
+
for (var i = 0; i < words.length; ++i) obj[words[i]] = true;
|
5 |
+
return obj;
|
6 |
+
}
|
7 |
+
function heredoc(delim) {
|
8 |
+
return function(stream, state) {
|
9 |
+
if (stream.match(delim)) state.tokenize = null;
|
10 |
+
else stream.skipToEnd();
|
11 |
+
return "string";
|
12 |
+
}
|
13 |
+
}
|
14 |
+
var phpConfig = {
|
15 |
+
name: "clike",
|
16 |
+
keywords: keywords("abstract and array as break case catch cfunction class clone const continue declare " +
|
17 |
+
"default do else elseif enddeclare endfor endforeach endif endswitch endwhile extends " +
|
18 |
+
"final for foreach function global goto if implements interface instanceof namespace " +
|
19 |
+
"new or private protected public static switch throw try use var while xor return" +
|
20 |
+
"die echo empty exit eval include include_once isset list require require_once print unset"),
|
21 |
+
blockKeywords: keywords("catch do else elseif for foreach if switch try while"),
|
22 |
+
atoms: keywords("true false null TRUE FALSE NULL"),
|
23 |
+
multiLineStrings: true,
|
24 |
+
hooks: {
|
25 |
+
"$": function(stream, state) {
|
26 |
+
stream.eatWhile(/[\w\$_]/);
|
27 |
+
return "variable-2";
|
28 |
+
},
|
29 |
+
"<": function(stream, state) {
|
30 |
+
if (stream.match(/<</)) {
|
31 |
+
stream.eatWhile(/[\w\.]/);
|
32 |
+
state.tokenize = heredoc(stream.current().slice(3));
|
33 |
+
return state.tokenize(stream, state);
|
34 |
+
}
|
35 |
+
return false;
|
36 |
+
},
|
37 |
+
"#": function(stream, state) {
|
38 |
+
stream.skipToEnd();
|
39 |
+
return "comment";
|
40 |
+
}
|
41 |
+
}
|
42 |
+
};
|
43 |
+
|
44 |
+
CodeMirror.defineMode("php", function(config, parserConfig) {
|
45 |
+
var htmlMode = CodeMirror.getMode(config, {name: "xml", htmlMode: true});
|
46 |
+
var jsMode = CodeMirror.getMode(config, "javascript");
|
47 |
+
var cssMode = CodeMirror.getMode(config, "css");
|
48 |
+
var phpMode = CodeMirror.getMode(config, phpConfig);
|
49 |
+
|
50 |
+
function dispatch(stream, state) { // TODO open PHP inside text/css
|
51 |
+
if (state.curMode == htmlMode) {
|
52 |
+
var style = htmlMode.token(stream, state.curState);
|
53 |
+
if (style == "meta" && /^<\?/.test(stream.current())) {
|
54 |
+
state.curMode = phpMode;
|
55 |
+
state.curState = state.php;
|
56 |
+
state.curClose = /^\?>/;
|
57 |
+
state.mode = 'php';
|
58 |
+
}
|
59 |
+
else if (style == "tag" && stream.current() == ">" && state.curState.context) {
|
60 |
+
if (/^script$/i.test(state.curState.context.tagName)) {
|
61 |
+
state.curMode = jsMode;
|
62 |
+
state.curState = jsMode.startState(htmlMode.indent(state.curState, ""));
|
63 |
+
state.curClose = /^<\/\s*script\s*>/i;
|
64 |
+
state.mode = 'javascript';
|
65 |
+
}
|
66 |
+
else if (/^style$/i.test(state.curState.context.tagName)) {
|
67 |
+
state.curMode = cssMode;
|
68 |
+
state.curState = cssMode.startState(htmlMode.indent(state.curState, ""));
|
69 |
+
state.curClose = /^<\/\s*style\s*>/i;
|
70 |
+
state.mode = 'css';
|
71 |
+
}
|
72 |
+
}
|
73 |
+
return style;
|
74 |
+
}
|
75 |
+
else if (stream.match(state.curClose, false)) {
|
76 |
+
state.curMode = htmlMode;
|
77 |
+
state.curState = state.html;
|
78 |
+
state.curClose = null;
|
79 |
+
state.mode = 'html';
|
80 |
+
return dispatch(stream, state);
|
81 |
+
}
|
82 |
+
else return state.curMode.token(stream, state.curState);
|
83 |
+
}
|
84 |
+
|
85 |
+
return {
|
86 |
+
startState: function() {
|
87 |
+
var html = htmlMode.startState();
|
88 |
+
return {html: html,
|
89 |
+
php: phpMode.startState(),
|
90 |
+
curMode: parserConfig.startOpen ? phpMode : htmlMode,
|
91 |
+
curState: parserConfig.startOpen ? phpMode.startState() : html,
|
92 |
+
curClose: parserConfig.startOpen ? /^\?>/ : null,
|
93 |
+
mode: parserConfig.startOpen ? 'php' : 'html'}
|
94 |
+
},
|
95 |
+
|
96 |
+
copyState: function(state) {
|
97 |
+
var html = state.html, htmlNew = CodeMirror.copyState(htmlMode, html),
|
98 |
+
php = state.php, phpNew = CodeMirror.copyState(phpMode, php), cur;
|
99 |
+
if (state.curState == html) cur = htmlNew;
|
100 |
+
else if (state.curState == php) cur = phpNew;
|
101 |
+
else cur = CodeMirror.copyState(state.curMode, state.curState);
|
102 |
+
return {html: htmlNew, php: phpNew, curMode: state.curMode, curState: cur, curClose: state.curClose};
|
103 |
+
},
|
104 |
+
|
105 |
+
token: dispatch,
|
106 |
+
|
107 |
+
indent: function(state, textAfter) {
|
108 |
+
if ((state.curMode != phpMode && /^\s*<\//.test(textAfter)) ||
|
109 |
+
(state.curMode == phpMode && /^\?>/.test(textAfter)))
|
110 |
+
return htmlMode.indent(state.html, textAfter);
|
111 |
+
return state.curMode.indent(state.curState, textAfter);
|
112 |
+
},
|
113 |
+
|
114 |
+
electricChars: "/{}:"
|
115 |
+
}
|
116 |
+
});
|
117 |
+
CodeMirror.defineMIME("application/x-httpd-php", "php");
|
118 |
+
CodeMirror.defineMIME("application/x-httpd-php-open", {name: "php", startOpen: true});
|
119 |
+
CodeMirror.defineMIME("text/x-php", phpConfig);
|
120 |
+
})();
|
extensions/codemirror/js/search.js
ADDED
@@ -0,0 +1,114 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
// Define search commands. Depends on dialog.js or another
|
2 |
+
// implementation of the openDialog method.
|
3 |
+
|
4 |
+
// Replace works a little oddly -- it will do the replace on the next
|
5 |
+
// Ctrl-G (or whatever is bound to findNext) press. You prevent a
|
6 |
+
// replace by making sure the match is no longer selected when hitting
|
7 |
+
// Ctrl-G.
|
8 |
+
|
9 |
+
(function() {
|
10 |
+
function SearchState() {
|
11 |
+
this.posFrom = this.posTo = this.query = null;
|
12 |
+
this.marked = [];
|
13 |
+
}
|
14 |
+
function getSearchState(cm) {
|
15 |
+
return cm._searchState || (cm._searchState = new SearchState());
|
16 |
+
}
|
17 |
+
function dialog(cm, text, shortText, f) {
|
18 |
+
if (cm.openDialog) cm.openDialog(text, f);
|
19 |
+
else f(prompt(shortText, ""));
|
20 |
+
}
|
21 |
+
function confirmDialog(cm, text, shortText, fs) {
|
22 |
+
if (cm.openConfirm) cm.openConfirm(text, fs);
|
23 |
+
else if (confirm(shortText)) fs[0]();
|
24 |
+
}
|
25 |
+
function parseQuery(query) {
|
26 |
+
var isRE = query.match(/^\/(.*)\/$/);
|
27 |
+
return isRE ? new RegExp(isRE[1]) : query;
|
28 |
+
}
|
29 |
+
var queryDialog =
|
30 |
+
'Search: <input type="text" style="width: 10em"> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
|
31 |
+
function doSearch(cm, rev) {
|
32 |
+
var state = getSearchState(cm);
|
33 |
+
if (state.query) return findNext(cm, rev);
|
34 |
+
dialog(cm, queryDialog, "Search for:", function(query) {
|
35 |
+
cm.operation(function() {
|
36 |
+
if (!query || state.query) return;
|
37 |
+
state.query = parseQuery(query);
|
38 |
+
if (cm.lineCount() < 2000) { // This is too expensive on big documents.
|
39 |
+
for (var cursor = cm.getSearchCursor(query); cursor.findNext();)
|
40 |
+
state.marked.push(cm.markText(cursor.from(), cursor.to(), "CodeMirror-searching"));
|
41 |
+
}
|
42 |
+
state.posFrom = state.posTo = cm.getCursor();
|
43 |
+
findNext(cm, rev);
|
44 |
+
});
|
45 |
+
});
|
46 |
+
}
|
47 |
+
function findNext(cm, rev) {cm.operation(function() {
|
48 |
+
var state = getSearchState(cm);
|
49 |
+
var cursor = cm.getSearchCursor(state.query, rev ? state.posFrom : state.posTo);
|
50 |
+
if (!cursor.find(rev)) {
|
51 |
+
cursor = cm.getSearchCursor(state.query, rev ? {line: cm.lineCount() - 1} : {line: 0, ch: 0});
|
52 |
+
if (!cursor.find(rev)) return;
|
53 |
+
}
|
54 |
+
cm.setSelection(cursor.from(), cursor.to());
|
55 |
+
state.posFrom = cursor.from(); state.posTo = cursor.to();
|
56 |
+
})}
|
57 |
+
function clearSearch(cm) {cm.operation(function() {
|
58 |
+
var state = getSearchState(cm);
|
59 |
+
if (!state.query) return;
|
60 |
+
state.query = null;
|
61 |
+
for (var i = 0; i < state.marked.length; ++i) state.marked[i].clear();
|
62 |
+
state.marked.length = 0;
|
63 |
+
})}
|
64 |
+
|
65 |
+
var replaceQueryDialog =
|
66 |
+
'Replace: <input type="text" style="width: 10em"> <span style="color: #888">(Use /re/ syntax for regexp search)</span>';
|
67 |
+
var replacementQueryDialog = 'With: <input type="text" style="width: 10em">';
|
68 |
+
var doReplaceConfirm = "Replace? <button>Yes</button> <button>No</button> <button>Stop</button>";
|
69 |
+
function replace(cm, all) {
|
70 |
+
dialog(cm, replaceQueryDialog, "Replace:", function(query) {
|
71 |
+
if (!query) return;
|
72 |
+
query = parseQuery(query);
|
73 |
+
dialog(cm, replacementQueryDialog, "Replace with:", function(text) {
|
74 |
+
if (all) {
|
75 |
+
cm.operation(function() {
|
76 |
+
for (var cursor = cm.getSearchCursor(query); cursor.findNext();) {
|
77 |
+
if (typeof query != "string") {
|
78 |
+
var match = cm.getRange(cursor.from(), cursor.to()).match(query);
|
79 |
+
cursor.replace(text.replace(/\$(\d)/, function(w, i) {return match[i];}));
|
80 |
+
} else cursor.replace(text);
|
81 |
+
}
|
82 |
+
});
|
83 |
+
} else {
|
84 |
+
clearSearch(cm);
|
85 |
+
var cursor = cm.getSearchCursor(query, cm.getCursor());
|
86 |
+
function advance() {
|
87 |
+
var start = cursor.from(), match;
|
88 |
+
if (!(match = cursor.findNext())) {
|
89 |
+
cursor = cm.getSearchCursor(query);
|
90 |
+
if (!(match = cursor.findNext()) ||
|
91 |
+
(cursor.from().line == start.line && cursor.from().ch == start.ch)) return;
|
92 |
+
}
|
93 |
+
cm.setSelection(cursor.from(), cursor.to());
|
94 |
+
confirmDialog(cm, doReplaceConfirm, "Replace?",
|
95 |
+
[function() {doReplace(match);}, advance]);
|
96 |
+
}
|
97 |
+
function doReplace(match) {
|
98 |
+
cursor.replace(typeof query == "string" ? text :
|
99 |
+
text.replace(/\$(\d)/, function(w, i) {return match[i];}));
|
100 |
+
advance();
|
101 |
+
}
|
102 |
+
advance();
|
103 |
+
}
|
104 |
+
});
|
105 |
+
});
|
106 |
+
}
|
107 |
+
|
108 |
+
CodeMirror.commands.find = function(cm) {clearSearch(cm); doSearch(cm);};
|
109 |
+
CodeMirror.commands.findNext = doSearch;
|
110 |
+
CodeMirror.commands.findPrev = function(cm) {doSearch(cm, true);};
|
111 |
+
CodeMirror.commands.clearSearch = clearSearch;
|
112 |
+
CodeMirror.commands.replace = replace;
|
113 |
+
CodeMirror.commands.replaceAll = function(cm) {replace(cm, true);};
|
114 |
+
})();
|
extensions/codemirror/js/searchcursor.js
ADDED
@@ -0,0 +1,117 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function(){
|
2 |
+
function SearchCursor(cm, query, pos, caseFold) {
|
3 |
+
this.atOccurrence = false; this.cm = cm;
|
4 |
+
if (caseFold == null) caseFold = typeof query == "string" && query == query.toLowerCase();
|
5 |
+
|
6 |
+
pos = pos ? cm.clipPos(pos) : {line: 0, ch: 0};
|
7 |
+
this.pos = {from: pos, to: pos};
|
8 |
+
|
9 |
+
// The matches method is filled in based on the type of query.
|
10 |
+
// It takes a position and a direction, and returns an object
|
11 |
+
// describing the next occurrence of the query, or null if no
|
12 |
+
// more matches were found.
|
13 |
+
if (typeof query != "string") // Regexp match
|
14 |
+
this.matches = function(reverse, pos) {
|
15 |
+
if (reverse) {
|
16 |
+
var line = cm.getLine(pos.line).slice(0, pos.ch), match = line.match(query), start = 0;
|
17 |
+
while (match) {
|
18 |
+
var ind = line.indexOf(match[0]);
|
19 |
+
start += ind;
|
20 |
+
line = line.slice(ind + 1);
|
21 |
+
var newmatch = line.match(query);
|
22 |
+
if (newmatch) match = newmatch;
|
23 |
+
else break;
|
24 |
+
start++;
|
25 |
+
}
|
26 |
+
}
|
27 |
+
else {
|
28 |
+
var line = cm.getLine(pos.line).slice(pos.ch), match = line.match(query),
|
29 |
+
start = match && pos.ch + line.indexOf(match[0]);
|
30 |
+
}
|
31 |
+
if (match)
|
32 |
+
return {from: {line: pos.line, ch: start},
|
33 |
+
to: {line: pos.line, ch: start + match[0].length},
|
34 |
+
match: match};
|
35 |
+
};
|
36 |
+
else { // String query
|
37 |
+
if (caseFold) query = query.toLowerCase();
|
38 |
+
var fold = caseFold ? function(str){return str.toLowerCase();} : function(str){return str;};
|
39 |
+
var target = query.split("\n");
|
40 |
+
// Different methods for single-line and multi-line queries
|
41 |
+
if (target.length == 1)
|
42 |
+
this.matches = function(reverse, pos) {
|
43 |
+
var line = fold(cm.getLine(pos.line)), len = query.length, match;
|
44 |
+
if (reverse ? (pos.ch >= len && (match = line.lastIndexOf(query, pos.ch - len)) != -1)
|
45 |
+
: (match = line.indexOf(query, pos.ch)) != -1)
|
46 |
+
return {from: {line: pos.line, ch: match},
|
47 |
+
to: {line: pos.line, ch: match + len}};
|
48 |
+
};
|
49 |
+
else
|
50 |
+
this.matches = function(reverse, pos) {
|
51 |
+
var ln = pos.line, idx = (reverse ? target.length - 1 : 0), match = target[idx], line = fold(cm.getLine(ln));
|
52 |
+
var offsetA = (reverse ? line.indexOf(match) + match.length : line.lastIndexOf(match));
|
53 |
+
if (reverse ? offsetA >= pos.ch || offsetA != match.length
|
54 |
+
: offsetA <= pos.ch || offsetA != line.length - match.length)
|
55 |
+
return;
|
56 |
+
for (;;) {
|
57 |
+
if (reverse ? !ln : ln == cm.lineCount() - 1) return;
|
58 |
+
line = fold(cm.getLine(ln += reverse ? -1 : 1));
|
59 |
+
match = target[reverse ? --idx : ++idx];
|
60 |
+
if (idx > 0 && idx < target.length - 1) {
|
61 |
+
if (line != match) return;
|
62 |
+
else continue;
|
63 |
+
}
|
64 |
+
var offsetB = (reverse ? line.lastIndexOf(match) : line.indexOf(match) + match.length);
|
65 |
+
if (reverse ? offsetB != line.length - match.length : offsetB != match.length)
|
66 |
+
return;
|
67 |
+
var start = {line: pos.line, ch: offsetA}, end = {line: ln, ch: offsetB};
|
68 |
+
return {from: reverse ? end : start, to: reverse ? start : end};
|
69 |
+
}
|
70 |
+
};
|
71 |
+
}
|
72 |
+
}
|
73 |
+
|
74 |
+
SearchCursor.prototype = {
|
75 |
+
findNext: function() {return this.find(false);},
|
76 |
+
findPrevious: function() {return this.find(true);},
|
77 |
+
|
78 |
+
find: function(reverse) {
|
79 |
+
var self = this, pos = this.cm.clipPos(reverse ? this.pos.from : this.pos.to);
|
80 |
+
function savePosAndFail(line) {
|
81 |
+
var pos = {line: line, ch: 0};
|
82 |
+
self.pos = {from: pos, to: pos};
|
83 |
+
self.atOccurrence = false;
|
84 |
+
return false;
|
85 |
+
}
|
86 |
+
|
87 |
+
for (;;) {
|
88 |
+
if (this.pos = this.matches(reverse, pos)) {
|
89 |
+
this.atOccurrence = true;
|
90 |
+
return this.pos.match || true;
|
91 |
+
}
|
92 |
+
if (reverse) {
|
93 |
+
if (!pos.line) return savePosAndFail(0);
|
94 |
+
pos = {line: pos.line-1, ch: this.cm.getLine(pos.line-1).length};
|
95 |
+
}
|
96 |
+
else {
|
97 |
+
var maxLine = this.cm.lineCount();
|
98 |
+
if (pos.line == maxLine - 1) return savePosAndFail(maxLine);
|
99 |
+
pos = {line: pos.line+1, ch: 0};
|
100 |
+
}
|
101 |
+
}
|
102 |
+
},
|
103 |
+
|
104 |
+
from: function() {if (this.atOccurrence) return this.pos.from;},
|
105 |
+
to: function() {if (this.atOccurrence) return this.pos.to;},
|
106 |
+
|
107 |
+
replace: function(newText) {
|
108 |
+
var self = this;
|
109 |
+
if (this.atOccurrence)
|
110 |
+
self.pos.to = this.cm.replaceRange(newText, self.pos.from, self.pos.to);
|
111 |
+
}
|
112 |
+
};
|
113 |
+
|
114 |
+
CodeMirror.defineExtension("getSearchCursor", function(query, pos, caseFold) {
|
115 |
+
return new SearchCursor(this, query, pos, caseFold);
|
116 |
+
});
|
117 |
+
})();
|
extensions/codemirror/js/xml.js
ADDED
@@ -0,0 +1,252 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
CodeMirror.defineMode("xml", function(config, parserConfig) {
|
2 |
+
var indentUnit = config.indentUnit;
|
3 |
+
var Kludges = parserConfig.htmlMode ? {
|
4 |
+
autoSelfClosers: {"br": true, "img": true, "hr": true, "link": true, "input": true,
|
5 |
+
"meta": true, "col": true, "frame": true, "base": true, "area": true},
|
6 |
+
doNotIndent: {"pre": true},
|
7 |
+
allowUnquoted: true
|
8 |
+
} : {autoSelfClosers: {}, doNotIndent: {}, allowUnquoted: false};
|
9 |
+
var alignCDATA = parserConfig.alignCDATA;
|
10 |
+
|
11 |
+
// Return variables for tokenizers
|
12 |
+
var tagName, type;
|
13 |
+
|
14 |
+
function inText(stream, state) {
|
15 |
+
function chain(parser) {
|
16 |
+
state.tokenize = parser;
|
17 |
+
return parser(stream, state);
|
18 |
+
}
|
19 |
+
|
20 |
+
var ch = stream.next();
|
21 |
+
if (ch == "<") {
|
22 |
+
if (stream.eat("!")) {
|
23 |
+
if (stream.eat("[")) {
|
24 |
+
if (stream.match("CDATA[")) return chain(inBlock("atom", "]]>"));
|
25 |
+
else return null;
|
26 |
+
}
|
27 |
+
else if (stream.match("--")) return chain(inBlock("comment", "-->"));
|
28 |
+
else if (stream.match("DOCTYPE", true, true)) {
|
29 |
+
stream.eatWhile(/[\w\._\-]/);
|
30 |
+
return chain(doctype(1));
|
31 |
+
}
|
32 |
+
else return null;
|
33 |
+
}
|
34 |
+
else if (stream.eat("?")) {
|
35 |
+
stream.eatWhile(/[\w\._\-]/);
|
36 |
+
state.tokenize = inBlock("meta", "?>");
|
37 |
+
return "meta";
|
38 |
+
}
|
39 |
+
else {
|
40 |
+
type = stream.eat("/") ? "closeTag" : "openTag";
|
41 |
+
stream.eatSpace();
|
42 |
+
tagName = "";
|
43 |
+
var c;
|
44 |
+
while ((c = stream.eat(/[^\s\u00a0=<>\"\'\/?]/))) tagName += c;
|
45 |
+
state.tokenize = inTag;
|
46 |
+
return "tag";
|
47 |
+
}
|
48 |
+
}
|
49 |
+
else if (ch == "&") {
|
50 |
+
stream.eatWhile(/[^;]/);
|
51 |
+
stream.eat(";");
|
52 |
+
return "atom";
|
53 |
+
}
|
54 |
+
else {
|
55 |
+
stream.eatWhile(/[^&<]/);
|
56 |
+
return null;
|
57 |
+
}
|
58 |
+
}
|
59 |
+
|
60 |
+
function inTag(stream, state) {
|
61 |
+
var ch = stream.next();
|
62 |
+
if (ch == ">" || (ch == "/" && stream.eat(">"))) {
|
63 |
+
state.tokenize = inText;
|
64 |
+
type = ch == ">" ? "endTag" : "selfcloseTag";
|
65 |
+
return "tag";
|
66 |
+
}
|
67 |
+
else if (ch == "=") {
|
68 |
+
type = "equals";
|
69 |
+
return null;
|
70 |
+
}
|
71 |
+
else if (/[\'\"]/.test(ch)) {
|
72 |
+
state.tokenize = inAttribute(ch);
|
73 |
+
return state.tokenize(stream, state);
|
74 |
+
}
|
75 |
+
else {
|
76 |
+
stream.eatWhile(/[^\s\u00a0=<>\"\'\/?]/);
|
77 |
+
return "word";
|
78 |
+
}
|
79 |
+
}
|
80 |
+
|
81 |
+
function inAttribute(quote) {
|
82 |
+
return function(stream, state) {
|
83 |
+
while (!stream.eol()) {
|
84 |
+
if (stream.next() == quote) {
|
85 |
+
state.tokenize = inTag;
|
86 |
+
break;
|
87 |
+
}
|
88 |
+
}
|
89 |
+
return "string";
|
90 |
+
};
|
91 |
+
}
|
92 |
+
|
93 |
+
function inBlock(style, terminator) {
|
94 |
+
return function(stream, state) {
|
95 |
+
while (!stream.eol()) {
|
96 |
+
if (stream.match(terminator)) {
|
97 |
+
state.tokenize = inText;
|
98 |
+
break;
|
99 |
+
}
|
100 |
+
stream.next();
|
101 |
+
}
|
102 |
+
return style;
|
103 |
+
};
|
104 |
+
}
|
105 |
+
function doctype(depth) {
|
106 |
+
return function(stream, state) {
|
107 |
+
var ch;
|
108 |
+
while ((ch = stream.next()) != null) {
|
109 |
+
if (ch == "<") {
|
110 |
+
state.tokenize = doctype(depth + 1);
|
111 |
+
return state.tokenize(stream, state);
|
112 |
+
} else if (ch == ">") {
|
113 |
+
if (depth == 1) {
|
114 |
+
state.tokenize = inText;
|
115 |
+
break;
|
116 |
+
} else {
|
117 |
+
state.tokenize = doctype(depth - 1);
|
118 |
+
return state.tokenize(stream, state);
|
119 |
+
}
|
120 |
+
}
|
121 |
+
}
|
122 |
+
return "meta";
|
123 |
+
};
|
124 |
+
}
|
125 |
+
|
126 |
+
var curState, setStyle;
|
127 |
+
function pass() {
|
128 |
+
for (var i = arguments.length - 1; i >= 0; i--) curState.cc.push(arguments[i]);
|
129 |
+
}
|
130 |
+
function cont() {
|
131 |
+
pass.apply(null, arguments);
|
132 |
+
return true;
|
133 |
+
}
|
134 |
+
|
135 |
+
function pushContext(tagName, startOfLine) {
|
136 |
+
var noIndent = Kludges.doNotIndent.hasOwnProperty(tagName) || (curState.context && curState.context.noIndent);
|
137 |
+
curState.context = {
|
138 |
+
prev: curState.context,
|
139 |
+
tagName: tagName,
|
140 |
+
indent: curState.indented,
|
141 |
+
startOfLine: startOfLine,
|
142 |
+
noIndent: noIndent
|
143 |
+
};
|
144 |
+
}
|
145 |
+
function popContext() {
|
146 |
+
if (curState.context) curState.context = curState.context.prev;
|
147 |
+
}
|
148 |
+
|
149 |
+
function element(type) {
|
150 |
+
if (type == "openTag") {
|
151 |
+
curState.tagName = tagName;
|
152 |
+
return cont(attributes, endtag(curState.startOfLine));
|
153 |
+
} else if (type == "closeTag") {
|
154 |
+
var err = false;
|
155 |
+
if (curState.context) {
|
156 |
+
err = curState.context.tagName != tagName;
|
157 |
+
} else {
|
158 |
+
err = true;
|
159 |
+
}
|
160 |
+
if (err) setStyle = "error";
|
161 |
+
return cont(endclosetag(err));
|
162 |
+
}
|
163 |
+
return cont();
|
164 |
+
}
|
165 |
+
function endtag(startOfLine) {
|
166 |
+
return function(type) {
|
167 |
+
if (type == "selfcloseTag" ||
|
168 |
+
(type == "endTag" && Kludges.autoSelfClosers.hasOwnProperty(curState.tagName.toLowerCase())))
|
169 |
+
return cont();
|
170 |
+
if (type == "endTag") {pushContext(curState.tagName, startOfLine); return cont();}
|
171 |
+
return cont();
|
172 |
+
};
|
173 |
+
}
|
174 |
+
function endclosetag(err) {
|
175 |
+
return function(type) {
|
176 |
+
if (err) setStyle = "error";
|
177 |
+
if (type == "endTag") { popContext(); return cont(); }
|
178 |
+
setStyle = "error";
|
179 |
+
return cont(arguments.callee);
|
180 |
+
}
|
181 |
+
}
|
182 |
+
|
183 |
+
function attributes(type) {
|
184 |
+
if (type == "word") {setStyle = "attribute"; return cont(attributes);}
|
185 |
+
if (type == "equals") return cont(attvalue, attributes);
|
186 |
+
if (type == "string") {setStyle = "error"; return cont(attributes);}
|
187 |
+
return pass();
|
188 |
+
}
|
189 |
+
function attvalue(type) {
|
190 |
+
if (type == "word" && Kludges.allowUnquoted) {setStyle = "string"; return cont();}
|
191 |
+
if (type == "string") return cont(attvaluemaybe);
|
192 |
+
return pass();
|
193 |
+
}
|
194 |
+
function attvaluemaybe(type) {
|
195 |
+
if (type == "string") return cont(attvaluemaybe);
|
196 |
+
else return pass();
|
197 |
+
}
|
198 |
+
|
199 |
+
return {
|
200 |
+
startState: function() {
|
201 |
+
return {tokenize: inText, cc: [], indented: 0, startOfLine: true, tagName: null, context: null};
|
202 |
+
},
|
203 |
+
|
204 |
+
token: function(stream, state) {
|
205 |
+
if (stream.sol()) {
|
206 |
+
state.startOfLine = true;
|
207 |
+
state.indented = stream.indentation();
|
208 |
+
}
|
209 |
+
if (stream.eatSpace()) return null;
|
210 |
+
|
211 |
+
setStyle = type = tagName = null;
|
212 |
+
var style = state.tokenize(stream, state);
|
213 |
+
state.type = type;
|
214 |
+
if ((style || type) && style != "comment") {
|
215 |
+
curState = state;
|
216 |
+
while (true) {
|
217 |
+
var comb = state.cc.pop() || element;
|
218 |
+
if (comb(type || style)) break;
|
219 |
+
}
|
220 |
+
}
|
221 |
+
state.startOfLine = false;
|
222 |
+
return setStyle || style;
|
223 |
+
},
|
224 |
+
|
225 |
+
indent: function(state, textAfter, fullLine) {
|
226 |
+
var context = state.context;
|
227 |
+
if ((state.tokenize != inTag && state.tokenize != inText) ||
|
228 |
+
context && context.noIndent)
|
229 |
+
return fullLine ? fullLine.match(/^(\s*)/)[0].length : 0;
|
230 |
+
if (alignCDATA && /<!\[CDATA\[/.test(textAfter)) return 0;
|
231 |
+
if (context && /^<\//.test(textAfter))
|
232 |
+
context = context.prev;
|
233 |
+
while (context && !context.startOfLine)
|
234 |
+
context = context.prev;
|
235 |
+
if (context) return context.indent + indentUnit;
|
236 |
+
else return 0;
|
237 |
+
},
|
238 |
+
|
239 |
+
compareStates: function(a, b) {
|
240 |
+
if (a.indented != b.indented || a.tokenize != b.tokenize) return false;
|
241 |
+
for (var ca = a.context, cb = b.context; ; ca = ca.prev, cb = cb.prev) {
|
242 |
+
if (!ca || !cb) return ca == cb;
|
243 |
+
if (ca.tagName != cb.tagName) return false;
|
244 |
+
}
|
245 |
+
},
|
246 |
+
|
247 |
+
electricChars: "/"
|
248 |
+
};
|
249 |
+
});
|
250 |
+
|
251 |
+
CodeMirror.defineMIME("application/xml", "xml");
|
252 |
+
CodeMirror.defineMIME("text/html", {name: "xml", htmlMode: true});
|
extensions/codemirror/theme/cobalt.css
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-cobalt { background: #002240; color: white; }
|
2 |
+
.cm-s-cobalt span.CodeMirror-selected { background: #b36539 !important; }
|
3 |
+
.cm-s-cobalt .CodeMirror-gutter { background: #002240; border-right: 1px solid #aaa; }
|
4 |
+
.cm-s-cobalt .CodeMirror-gutter-text { color: #d0d0d0; }
|
5 |
+
.cm-s-cobalt .CodeMirror-cursor { border-left: 1px solid white !important; }
|
6 |
+
|
7 |
+
.cm-s-cobalt span.cm-comment { color: #08f; }
|
8 |
+
.cm-s-cobalt span.cm-atom { color: #845dc4; }
|
9 |
+
.cm-s-cobalt span.cm-number, .cm-s-cobalt span.cm-attribute { color: #ff80e1; }
|
10 |
+
.cm-s-cobalt span.cm-keyword { color: #ffee80; }
|
11 |
+
.cm-s-cobalt span.cm-string { color: #3ad900; }
|
12 |
+
.cm-s-cobalt span.cm-meta { color: #ff9d00; }
|
13 |
+
.cm-s-cobalt span.cm-variable-2, .cm-s-cobalt span.cm-tag { color: #9effff; }
|
14 |
+
.cm-s-cobalt span.cm-variable-3, .cm-s-cobalt span.cm-def { color: white; }
|
15 |
+
.cm-s-cobalt span.cm-error { color: #9d1e15; }
|
16 |
+
.cm-s-cobalt span.cm-bracket { color: #d8d8d8; }
|
17 |
+
.cm-s-cobalt span.cm-builtin, .cm-s-cobalt span.cm-special { color: #ff9e59; }
|
18 |
+
.cm-s-cobalt span.cm-link { color: #845dc4; }
|
extensions/codemirror/theme/eclipse.css
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-eclipse span.cm-meta {color: #FF1717;}
|
2 |
+
.cm-s-eclipse span.cm-keyword { font-weight: bold; color: #7F0055; }
|
3 |
+
.cm-s-eclipse span.cm-atom {color: #219;}
|
4 |
+
.cm-s-eclipse span.cm-number {color: #164;}
|
5 |
+
.cm-s-eclipse span.cm-def {color: #00f;}
|
6 |
+
.cm-s-eclipse span.cm-variable {color: black;}
|
7 |
+
.cm-s-eclipse span.cm-variable-2 {color: #0000C0;}
|
8 |
+
.cm-s-eclipse span.cm-variable-3 {color: #0000C0;}
|
9 |
+
.cm-s-eclipse span.cm-property {color: black;}
|
10 |
+
.cm-s-eclipse span.cm-operator {color: black;}
|
11 |
+
.cm-s-eclipse span.cm-comment {color: #3F7F5F;}
|
12 |
+
.cm-s-eclipse span.cm-string {color: #2A00FF;}
|
13 |
+
.cm-s-eclipse span.cm-string-2 {color: #f50;}
|
14 |
+
.cm-s-eclipse span.cm-error {color: #f00;}
|
15 |
+
.cm-s-eclipse span.cm-qualifier {color: #555;}
|
16 |
+
.cm-s-eclipse span.cm-builtin {color: #30a;}
|
17 |
+
.cm-s-eclipse span.cm-bracket {color: #cc7;}
|
18 |
+
.cm-s-eclipse span.cm-tag {color: #170;}
|
19 |
+
.cm-s-eclipse span.cm-attribute {color: #00c;}
|
20 |
+
.cm-s-eclipse span.cm-link {color: #219;}
|
21 |
+
|
22 |
+
.cm-s-eclipse .CodeMirror-matchingbracket {
|
23 |
+
border:1px solid grey;
|
24 |
+
color:black !important;;
|
25 |
+
}
|
extensions/codemirror/theme/elegant.css
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
|
2 |
+
.cm-s-elegant span.cm-comment {color: #262;font-style: italic;}
|
3 |
+
.cm-s-elegant span.cm-meta {color: #555;font-style: italic;}
|
4 |
+
.cm-s-elegant span.cm-variable {color: black;}
|
5 |
+
.cm-s-elegant span.cm-variable-2 {color: #b11;}
|
6 |
+
.cm-s-elegant span.cm-qualifier {color: #555;}
|
7 |
+
.cm-s-elegant span.cm-keyword {color: #730;}
|
8 |
+
.cm-s-elegant span.cm-builtin {color: #30a;}
|
9 |
+
.cm-s-elegant span.cm-error {background-color: #fdd;}
|
10 |
+
.cm-s-elegant span.cm-link {color: #762;}
|
extensions/codemirror/theme/monokai.css
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Based on Sublime Text's Monokai theme */
|
2 |
+
|
3 |
+
.cm-s-monokai {background: #272822; color: #f8f8f2;}
|
4 |
+
.cm-s-monokai span.CodeMirror-selected {background: #ffe792 !important;}
|
5 |
+
.cm-s-monokai .CodeMirror-gutter {background: #272822; border-right: 0px;}
|
6 |
+
.cm-s-monokai .CodeMirror-gutter-text {color: #d0d0d0;}
|
7 |
+
.cm-s-monokai .CodeMirror-cursor {border-left: 1px solid #f8f8f0 !important;}
|
8 |
+
|
9 |
+
.cm-s-monokai span.cm-comment {color: #75715e;}
|
10 |
+
.cm-s-monokai span.cm-atom {color: #ae81ff;}
|
11 |
+
.cm-s-monokai span.cm-number {color: #ae81ff;}
|
12 |
+
|
13 |
+
.cm-s-monokai span.cm-property, .cm-s-monokai span.cm-attribute {color: #a6e22e;}
|
14 |
+
.cm-s-monokai span.cm-keyword {color: #f92672;}
|
15 |
+
.cm-s-monokai span.cm-string {color: #e6db74;}
|
16 |
+
|
17 |
+
.cm-s-monokai span.cm-variable {color: #a6e22e;}
|
18 |
+
.cm-s-monokai span.cm-variable-2 {color: #9effff;}
|
19 |
+
.cm-s-monokai span.cm-def {color: #fd971f;}
|
20 |
+
.cm-s-monokai span.cm-error {background: #f92672; color: #f8f8f0;}
|
21 |
+
.cm-s-monokai span.cm-bracket {color: #f8f8f2;}
|
22 |
+
.cm-s-monokai span.cm-tag {color: #f92672;}
|
23 |
+
.cm-s-monokai span.cm-link {color: #ae81ff;}
|
24 |
+
|
25 |
+
.cm-s-monokai .CodeMirror-matchingbracket {
|
26 |
+
text-decoration: underline;
|
27 |
+
color: white !important;
|
28 |
+
}
|
extensions/codemirror/theme/neat.css
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-neat span.cm-comment { color: #a86; }
|
2 |
+
.cm-s-neat span.cm-keyword { font-weight: bold; color: blue; }
|
3 |
+
.cm-s-neat span.cm-string { color: #a22; }
|
4 |
+
.cm-s-neat span.cm-builtin { font-weight: bold; color: #077; }
|
5 |
+
.cm-s-neat span.cm-special { font-weight: bold; color: #0aa; }
|
6 |
+
.cm-s-neat span.cm-variable { color: black; }
|
7 |
+
.cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; }
|
8 |
+
.cm-s-neat span.cm-meta {color: #555;}
|
9 |
+
.cm-s-neat span.cm-link { color: #3a3; }
|
extensions/codemirror/theme/night.css
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Loosely based on the Midnight Textmate theme */
|
2 |
+
|
3 |
+
.cm-s-night { background: #0a001f; color: #f8f8f8; }
|
4 |
+
.cm-s-night span.CodeMirror-selected { background: #a8f !important; }
|
5 |
+
.cm-s-night .CodeMirror-gutter { background: #0a001f; border-right: 1px solid #aaa; }
|
6 |
+
.cm-s-night .CodeMirror-gutter-text { color: #f8f8f8; }
|
7 |
+
.cm-s-night .CodeMirror-cursor { border-left: 1px solid white !important; }
|
8 |
+
|
9 |
+
.cm-s-night span.cm-comment { color: #6900a1; }
|
10 |
+
.cm-s-night span.cm-atom { color: #845dc4; }
|
11 |
+
.cm-s-night span.cm-number, .cm-s-night span.cm-attribute { color: #ffd500; }
|
12 |
+
.cm-s-night span.cm-keyword { color: #599eff; }
|
13 |
+
.cm-s-night span.cm-string { color: #37f14a; }
|
14 |
+
.cm-s-night span.cm-meta { color: #7678e2; }
|
15 |
+
.cm-s-night span.cm-variable-2, .cm-s-night span.cm-tag { color: #99b2ff; }
|
16 |
+
.cm-s-night span.cm-variable-3, .cm-s-night span.cm-def { color: white; }
|
17 |
+
.cm-s-night span.cm-error { color: #9d1e15; }
|
18 |
+
.cm-s-night span.cm-bracket { color: #8da6ce; }
|
19 |
+
.cm-s-night span.cm-comment { color: #6900a1; }
|
20 |
+
.cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; }
|
21 |
+
.cm-s-night span.cm-link { color: #845dc4; }
|
extensions/codemirror/theme/rubyblue.css
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-rubyblue { font:13px/1.4em Trebuchet, Verdana, sans-serif; } /* - customized editor font - */
|
2 |
+
|
3 |
+
.cm-s-rubyblue { background: #112435; color: white; }
|
4 |
+
.cm-s-rubyblue span.CodeMirror-selected { background: #0000FF !important; }
|
5 |
+
.cm-s-rubyblue .CodeMirror-gutter { background: #1F4661; border-right: 7px solid #3E7087; min-width:2.5em; }
|
6 |
+
.cm-s-rubyblue .CodeMirror-gutter-text { color: white; }
|
7 |
+
.cm-s-rubyblue .CodeMirror-cursor { border-left: 1px solid white !important; }
|
8 |
+
|
9 |
+
.cm-s-rubyblue span.cm-comment { color: #999; font-style:italic; }
|
10 |
+
.cm-s-rubyblue span.cm-atom { color: #F4C20B; }
|
11 |
+
.cm-s-rubyblue span.cm-number, .cm-s-rubyblue span.cm-attribute { color: #82C6E0; }
|
12 |
+
.cm-s-rubyblue span.cm-keyword { color: #F0F; }
|
13 |
+
.cm-s-rubyblue span.cm-string { color: #F08047; }
|
14 |
+
.cm-s-rubyblue span.cm-meta { color: #F0F; }
|
15 |
+
.cm-s-rubyblue span.cm-variable-2, .cm-s-rubyblue span.cm-tag { color: #7BD827; }
|
16 |
+
.cm-s-rubyblue span.cm-variable-3, .cm-s-rubyblue span.cm-def { color: white; }
|
17 |
+
.cm-s-rubyblue span.cm-error { color: #AF2018; }
|
18 |
+
.cm-s-rubyblue span.cm-bracket { color: #F0F; }
|
19 |
+
.cm-s-rubyblue span.cm-link { color: #F4C20B; }
|
20 |
+
.cm-s-rubyblue span.CodeMirror-matchingbracket { color:#F0F !important; }
|
21 |
+
.cm-s-rubyblue span.cm-builtin, .cm-s-rubyblue span.cm-special { color: #FF9D00; }
|
extensions/codemirror/themes/cobalt.css
ADDED
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-cobalt { background: #002240; color: white; }
|
2 |
+
.cm-s-cobalt span.CodeMirror-selected { background: #b36539 !important; }
|
3 |
+
.cm-s-cobalt .CodeMirror-gutter { background: #002240; border-right: 1px solid #aaa; }
|
4 |
+
.cm-s-cobalt .CodeMirror-gutter-text { color: #d0d0d0; }
|
5 |
+
.cm-s-cobalt .CodeMirror-cursor { border-left: 1px solid white !important; }
|
6 |
+
|
7 |
+
.cm-s-cobalt span.cm-comment { color: #08f; }
|
8 |
+
.cm-s-cobalt span.cm-atom { color: #845dc4; }
|
9 |
+
.cm-s-cobalt span.cm-number, .cm-s-cobalt span.cm-attribute { color: #ff80e1; }
|
10 |
+
.cm-s-cobalt span.cm-keyword { color: #ffee80; }
|
11 |
+
.cm-s-cobalt span.cm-string { color: #3ad900; }
|
12 |
+
.cm-s-cobalt span.cm-meta { color: #ff9d00; }
|
13 |
+
.cm-s-cobalt span.cm-variable-2, .cm-s-cobalt span.cm-tag { color: #9effff; }
|
14 |
+
.cm-s-cobalt span.cm-variable-3, .cm-s-cobalt span.cm-def { color: white; }
|
15 |
+
.cm-s-cobalt span.cm-error { color: #9d1e15; }
|
16 |
+
.cm-s-cobalt span.cm-bracket { color: #d8d8d8; }
|
17 |
+
.cm-s-cobalt span.cm-builtin, .cm-s-cobalt span.cm-special { color: #ff9e59; }
|
18 |
+
.cm-s-cobalt span.cm-link { color: #845dc4; }
|
extensions/codemirror/themes/eclipse.css
ADDED
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-eclipse span.cm-meta {color: #FF1717;}
|
2 |
+
.cm-s-eclipse span.cm-keyword { font-weight: bold; color: #7F0055; }
|
3 |
+
.cm-s-eclipse span.cm-atom {color: #219;}
|
4 |
+
.cm-s-eclipse span.cm-number {color: #164;}
|
5 |
+
.cm-s-eclipse span.cm-def {color: #00f;}
|
6 |
+
.cm-s-eclipse span.cm-variable {color: black;}
|
7 |
+
.cm-s-eclipse span.cm-variable-2 {color: #0000C0;}
|
8 |
+
.cm-s-eclipse span.cm-variable-3 {color: #0000C0;}
|
9 |
+
.cm-s-eclipse span.cm-property {color: black;}
|
10 |
+
.cm-s-eclipse span.cm-operator {color: black;}
|
11 |
+
.cm-s-eclipse span.cm-comment {color: #3F7F5F;}
|
12 |
+
.cm-s-eclipse span.cm-string {color: #2A00FF;}
|
13 |
+
.cm-s-eclipse span.cm-string-2 {color: #f50;}
|
14 |
+
.cm-s-eclipse span.cm-error {color: #f00;}
|
15 |
+
.cm-s-eclipse span.cm-qualifier {color: #555;}
|
16 |
+
.cm-s-eclipse span.cm-builtin {color: #30a;}
|
17 |
+
.cm-s-eclipse span.cm-bracket {color: #cc7;}
|
18 |
+
.cm-s-eclipse span.cm-tag {color: #170;}
|
19 |
+
.cm-s-eclipse span.cm-attribute {color: #00c;}
|
20 |
+
.cm-s-eclipse span.cm-link {color: #219;}
|
21 |
+
|
22 |
+
.cm-s-eclipse .CodeMirror-matchingbracket {
|
23 |
+
border:1px solid grey;
|
24 |
+
color:black !important;;
|
25 |
+
}
|
extensions/codemirror/themes/elegant.css
ADDED
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-elegant span.cm-number, .cm-s-elegant span.cm-string, .cm-s-elegant span.cm-atom {color: #762;}
|
2 |
+
.cm-s-elegant span.cm-comment {color: #262;font-style: italic;}
|
3 |
+
.cm-s-elegant span.cm-meta {color: #555;font-style: italic;}
|
4 |
+
.cm-s-elegant span.cm-variable {color: black;}
|
5 |
+
.cm-s-elegant span.cm-variable-2 {color: #b11;}
|
6 |
+
.cm-s-elegant span.cm-qualifier {color: #555;}
|
7 |
+
.cm-s-elegant span.cm-keyword {color: #730;}
|
8 |
+
.cm-s-elegant span.cm-builtin {color: #30a;}
|
9 |
+
.cm-s-elegant span.cm-error {background-color: #fdd;}
|
10 |
+
.cm-s-elegant span.cm-link {color: #762;}
|
extensions/codemirror/themes/monokai.css
ADDED
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Based on Sublime Text's Monokai theme */
|
2 |
+
|
3 |
+
.cm-s-monokai {background: #272822; color: #f8f8f2;}
|
4 |
+
.cm-s-monokai span.CodeMirror-selected {background: #ffe792 !important;}
|
5 |
+
.cm-s-monokai .CodeMirror-gutter {background: #272822; border-right: 0px;}
|
6 |
+
.cm-s-monokai .CodeMirror-gutter-text {color: #d0d0d0;}
|
7 |
+
.cm-s-monokai .CodeMirror-cursor {border-left: 1px solid #f8f8f0 !important;}
|
8 |
+
|
9 |
+
.cm-s-monokai span.cm-comment {color: #75715e;}
|
10 |
+
.cm-s-monokai span.cm-atom {color: #ae81ff;}
|
11 |
+
.cm-s-monokai span.cm-number {color: #ae81ff;}
|
12 |
+
|
13 |
+
.cm-s-monokai span.cm-property, .cm-s-monokai span.cm-attribute {color: #a6e22e;}
|
14 |
+
.cm-s-monokai span.cm-keyword {color: #f92672;}
|
15 |
+
.cm-s-monokai span.cm-string {color: #e6db74;}
|
16 |
+
|
17 |
+
.cm-s-monokai span.cm-variable {color: #a6e22e;}
|
18 |
+
.cm-s-monokai span.cm-variable-2 {color: #9effff;}
|
19 |
+
.cm-s-monokai span.cm-def {color: #fd971f;}
|
20 |
+
.cm-s-monokai span.cm-error {background: #f92672; color: #f8f8f0;}
|
21 |
+
.cm-s-monokai span.cm-bracket {color: #f8f8f2;}
|
22 |
+
.cm-s-monokai span.cm-tag {color: #f92672;}
|
23 |
+
.cm-s-monokai span.cm-link {color: #ae81ff;}
|
24 |
+
|
25 |
+
.cm-s-monokai .CodeMirror-matchingbracket {
|
26 |
+
text-decoration: underline;
|
27 |
+
color: white !important;
|
28 |
+
}
|
extensions/codemirror/themes/neat.css
ADDED
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-neat span.cm-comment { color: #a86; }
|
2 |
+
.cm-s-neat span.cm-keyword { font-weight: bold; color: blue; }
|
3 |
+
.cm-s-neat span.cm-string { color: #a22; }
|
4 |
+
.cm-s-neat span.cm-builtin { font-weight: bold; color: #077; }
|
5 |
+
.cm-s-neat span.cm-special { font-weight: bold; color: #0aa; }
|
6 |
+
.cm-s-neat span.cm-variable { color: black; }
|
7 |
+
.cm-s-neat span.cm-number, .cm-s-neat span.cm-atom { color: #3a3; }
|
8 |
+
.cm-s-neat span.cm-meta {color: #555;}
|
9 |
+
.cm-s-neat span.cm-link { color: #3a3; }
|
extensions/codemirror/themes/night.css
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/* Loosely based on the Midnight Textmate theme */
|
2 |
+
|
3 |
+
.cm-s-night { background: #0a001f; color: #f8f8f8; }
|
4 |
+
.cm-s-night span.CodeMirror-selected { background: #a8f !important; }
|
5 |
+
.cm-s-night .CodeMirror-gutter { background: #0a001f; border-right: 1px solid #aaa; }
|
6 |
+
.cm-s-night .CodeMirror-gutter-text { color: #f8f8f8; }
|
7 |
+
.cm-s-night .CodeMirror-cursor { border-left: 1px solid white !important; }
|
8 |
+
|
9 |
+
.cm-s-night span.cm-comment { color: #6900a1; }
|
10 |
+
.cm-s-night span.cm-atom { color: #845dc4; }
|
11 |
+
.cm-s-night span.cm-number, .cm-s-night span.cm-attribute { color: #ffd500; }
|
12 |
+
.cm-s-night span.cm-keyword { color: #599eff; }
|
13 |
+
.cm-s-night span.cm-string { color: #37f14a; }
|
14 |
+
.cm-s-night span.cm-meta { color: #7678e2; }
|
15 |
+
.cm-s-night span.cm-variable-2, .cm-s-night span.cm-tag { color: #99b2ff; }
|
16 |
+
.cm-s-night span.cm-variable-3, .cm-s-night span.cm-def { color: white; }
|
17 |
+
.cm-s-night span.cm-error { color: #9d1e15; }
|
18 |
+
.cm-s-night span.cm-bracket { color: #8da6ce; }
|
19 |
+
.cm-s-night span.cm-comment { color: #6900a1; }
|
20 |
+
.cm-s-night span.cm-builtin, .cm-s-night span.cm-special { color: #ff9e59; }
|
21 |
+
.cm-s-night span.cm-link { color: #845dc4; }
|
extensions/codemirror/themes/rubyblue.css
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.cm-s-rubyblue { font:13px/1.4em Trebuchet, Verdana, sans-serif; } /* - customized editor font - */
|
2 |
+
|
3 |
+
.cm-s-rubyblue { background: #112435; color: white; }
|
4 |
+
.cm-s-rubyblue span.CodeMirror-selected { background: #0000FF !important; }
|
5 |
+
.cm-s-rubyblue .CodeMirror-gutter { background: #1F4661; border-right: 7px solid #3E7087; min-width:2.5em; }
|
6 |
+
.cm-s-rubyblue .CodeMirror-gutter-text { color: white; }
|
7 |
+
.cm-s-rubyblue .CodeMirror-cursor { border-left: 1px solid white !important; }
|
8 |
+
|
9 |
+
.cm-s-rubyblue span.cm-comment { color: #999; font-style:italic; }
|
10 |
+
.cm-s-rubyblue span.cm-atom { color: #F4C20B; }
|
11 |
+
.cm-s-rubyblue span.cm-number, .cm-s-rubyblue span.cm-attribute { color: #82C6E0; }
|
12 |
+
.cm-s-rubyblue span.cm-keyword { color: #F0F; }
|
13 |
+
.cm-s-rubyblue span.cm-string { color: #F08047; }
|
14 |
+
.cm-s-rubyblue span.cm-meta { color: #F0F; }
|
15 |
+
.cm-s-rubyblue span.cm-variable-2, .cm-s-rubyblue span.cm-tag { color: #7BD827; }
|
16 |
+
.cm-s-rubyblue span.cm-variable-3, .cm-s-rubyblue span.cm-def { color: white; }
|
17 |
+
.cm-s-rubyblue span.cm-error { color: #AF2018; }
|
18 |
+
.cm-s-rubyblue span.cm-bracket { color: #F0F; }
|
19 |
+
.cm-s-rubyblue span.cm-link { color: #F4C20B; }
|
20 |
+
.cm-s-rubyblue span.CodeMirror-matchingbracket { color:#F0F !important; }
|
21 |
+
.cm-s-rubyblue span.cm-builtin, .cm-s-rubyblue span.cm-special { color: #FF9D00; }
|
extensions/fancybox/images/blank.gif
ADDED
Binary file
|
extensions/fancybox/images/fancy_close.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_loading.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_nav_left.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_nav_right.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_shadow_e.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_shadow_n.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_shadow_ne.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_shadow_nw.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_shadow_s.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_shadow_se.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_shadow_sw.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_shadow_w.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_title_left.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_title_main.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_title_over.png
ADDED
Binary file
|
extensions/fancybox/images/fancy_title_right.png
ADDED
Binary file
|
extensions/fancybox/images/fancybox-x.png
ADDED
Binary file
|
extensions/fancybox/images/fancybox-y.png
ADDED
Binary file
|
extensions/fancybox/images/fancybox.png
ADDED
Binary file
|
extensions/fancybox/jquery.fancybox-1.3.4.css
ADDED
@@ -0,0 +1,359 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* FancyBox - jQuery Plugin
|
3 |
+
* Simple and fancy lightbox alternative
|
4 |
+
*
|
5 |
+
* Examples and documentation at: http://fancybox.net
|
6 |
+
*
|
7 |
+
* Copyright (c) 2008 - 2010 Janis Skarnelis
|
8 |
+
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
|
9 |
+
*
|
10 |
+
* Version: 1.3.4 (11/11/2010)
|
11 |
+
* Requires: jQuery v1.3+
|
12 |
+
*
|
13 |
+
* Dual licensed under the MIT and GPL licenses:
|
14 |
+
* http://www.opensource.org/licenses/mit-license.php
|
15 |
+
* http://www.gnu.org/licenses/gpl.html
|
16 |
+
*/
|
17 |
+
|
18 |
+
#fancybox-loading {
|
19 |
+
position: fixed;
|
20 |
+
top: 50%;
|
21 |
+
left: 50%;
|
22 |
+
width: 40px;
|
23 |
+
height: 40px;
|
24 |
+
margin-top: -20px;
|
25 |
+
margin-left: -20px;
|
26 |
+
cursor: pointer;
|
27 |
+
overflow: hidden;
|
28 |
+
z-index: 1104;
|
29 |
+
display: none;
|
30 |
+
}
|
31 |
+
|
32 |
+
#fancybox-loading div {
|
33 |
+
position: absolute;
|
34 |
+
top: 0;
|
35 |
+
left: 0;
|
36 |
+
width: 40px;
|
37 |
+
height: 480px;
|
38 |
+
background-image: url('images/fancybox.png');
|
39 |
+
}
|
40 |
+
|
41 |
+
#fancybox-overlay {
|
42 |
+
position: absolute;
|
43 |
+
top: 0;
|
44 |
+
left: 0;
|
45 |
+
width: 100%;
|
46 |
+
z-index: 1100;
|
47 |
+
display: none;
|
48 |
+
}
|
49 |
+
|
50 |
+
#fancybox-tmp {
|
51 |
+
padding: 0;
|
52 |
+
margin: 0;
|
53 |
+
border: 0;
|
54 |
+
overflow: auto;
|
55 |
+
display: none;
|
56 |
+
}
|
57 |
+
|
58 |
+
#fancybox-wrap {
|
59 |
+
position: absolute;
|
60 |
+
top: 0;
|
61 |
+
left: 0;
|
62 |
+
padding: 20px;
|
63 |
+
z-index: 1101;
|
64 |
+
outline: none;
|
65 |
+
display: none;
|
66 |
+
}
|
67 |
+
|
68 |
+
#fancybox-outer {
|
69 |
+
position: relative;
|
70 |
+
width: 100%;
|
71 |
+
height: 100%;
|
72 |
+
background: #fff;
|
73 |
+
}
|
74 |
+
|
75 |
+
#fancybox-content {
|
76 |
+
width: 0;
|
77 |
+
height: 0;
|
78 |
+
padding: 0;
|
79 |
+
outline: none;
|
80 |
+
position: relative;
|
81 |
+
overflow: hidden;
|
82 |
+
z-index: 1102;
|
83 |
+
border: 0px solid #fff;
|
84 |
+
}
|
85 |
+
|
86 |
+
#fancybox-hide-sel-frame {
|
87 |
+
position: absolute;
|
88 |
+
top: 0;
|
89 |
+
left: 0;
|
90 |
+
width: 100%;
|
91 |
+
height: 100%;
|
92 |
+
background: transparent;
|
93 |
+
z-index: 1101;
|
94 |
+
}
|
95 |
+
|
96 |
+
#fancybox-close {
|
97 |
+
position: absolute;
|
98 |
+
top: -15px;
|
99 |
+
right: -15px;
|
100 |
+
width: 30px;
|
101 |
+
height: 30px;
|
102 |
+
background: transparent url('images/fancybox.png') -40px 0px;
|
103 |
+
cursor: pointer;
|
104 |
+
z-index: 1103;
|
105 |
+
display: none;
|
106 |
+
}
|
107 |
+
|
108 |
+
#fancybox-error {
|
109 |
+
color: #444;
|
110 |
+
font: normal 12px/20px Arial;
|
111 |
+
padding: 14px;
|
112 |
+
margin: 0;
|
113 |
+
}
|
114 |
+
|
115 |
+
#fancybox-img {
|
116 |
+
width: 100%;
|
117 |
+
height: 100%;
|
118 |
+
padding: 0;
|
119 |
+
margin: 0;
|
120 |
+
border: none;
|
121 |
+
outline: none;
|
122 |
+
line-height: 0;
|
123 |
+
vertical-align: top;
|
124 |
+
}
|
125 |
+
|
126 |
+
#fancybox-frame {
|
127 |
+
width: 100%;
|
128 |
+
height: 100%;
|
129 |
+
border: none;
|
130 |
+
display: block;
|
131 |
+
}
|
132 |
+
|
133 |
+
#fancybox-left, #fancybox-right {
|
134 |
+
position: absolute;
|
135 |
+
bottom: 0px;
|
136 |
+
height: 100%;
|
137 |
+
width: 35%;
|
138 |
+
cursor: pointer;
|
139 |
+
outline: none;
|
140 |
+
background: transparent url('images/blank.gif');
|
141 |
+
z-index: 1102;
|
142 |
+
display: none;
|
143 |
+
}
|
144 |
+
|
145 |
+
#fancybox-left {
|
146 |
+
left: 0px;
|
147 |
+
}
|
148 |
+
|
149 |
+
#fancybox-right {
|
150 |
+
right: 0px;
|
151 |
+
}
|
152 |
+
|
153 |
+
#fancybox-left-ico, #fancybox-right-ico {
|
154 |
+
position: absolute;
|
155 |
+
top: 50%;
|
156 |
+
left: -9999px;
|
157 |
+
width: 30px;
|
158 |
+
height: 30px;
|
159 |
+
margin-top: -15px;
|
160 |
+
cursor: pointer;
|
161 |
+
z-index: 1102;
|
162 |
+
display: block;
|
163 |
+
}
|
164 |
+
|
165 |
+
#fancybox-left-ico {
|
166 |
+
background-image: url('images/fancybox.png');
|
167 |
+
background-position: -40px -30px;
|
168 |
+
}
|
169 |
+
|
170 |
+
#fancybox-right-ico {
|
171 |
+
background-image: url('images/fancybox.png');
|
172 |
+
background-position: -40px -60px;
|
173 |
+
}
|
174 |
+
|
175 |
+
#fancybox-left:hover, #fancybox-right:hover {
|
176 |
+
visibility: visible; /* IE6 */
|
177 |
+
}
|
178 |
+
|
179 |
+
#fancybox-left:hover span {
|
180 |
+
left: 20px;
|
181 |
+
}
|
182 |
+
|
183 |
+
#fancybox-right:hover span {
|
184 |
+
left: auto;
|
185 |
+
right: 20px;
|
186 |
+
}
|
187 |
+
|
188 |
+
.fancybox-bg {
|
189 |
+
position: absolute;
|
190 |
+
padding: 0;
|
191 |
+
margin: 0;
|
192 |
+
border: 0;
|
193 |
+
width: 20px;
|
194 |
+
height: 20px;
|
195 |
+
z-index: 1001;
|
196 |
+
}
|
197 |
+
|
198 |
+
#fancybox-bg-n {
|
199 |
+
top: -20px;
|
200 |
+
left: 0;
|
201 |
+
width: 100%;
|
202 |
+
background-image: url('images/fancybox-x.png');
|
203 |
+
}
|
204 |
+
|
205 |
+
#fancybox-bg-ne {
|
206 |
+
top: -20px;
|
207 |
+
right: -20px;
|
208 |
+
background-image: url('images/fancybox.png');
|
209 |
+
background-position: -40px -162px;
|
210 |
+
}
|
211 |
+
|
212 |
+
#fancybox-bg-e {
|
213 |
+
top: 0;
|
214 |
+
right: -20px;
|
215 |
+
height: 100%;
|
216 |
+
background-image: url('images/fancybox-y.png');
|
217 |
+
background-position: -20px 0px;
|
218 |
+
}
|
219 |
+
|
220 |
+
#fancybox-bg-se {
|
221 |
+
bottom: -20px;
|
222 |
+
right: -20px;
|
223 |
+
background-image: url('images/fancybox.png');
|
224 |
+
background-position: -40px -182px;
|
225 |
+
}
|
226 |
+
|
227 |
+
#fancybox-bg-s {
|
228 |
+
bottom: -20px;
|
229 |
+
left: 0;
|
230 |
+
width: 100%;
|
231 |
+
background-image: url('images/fancybox-x.png');
|
232 |
+
background-position: 0px -20px;
|
233 |
+
}
|
234 |
+
|
235 |
+
#fancybox-bg-sw {
|
236 |
+
bottom: -20px;
|
237 |
+
left: -20px;
|
238 |
+
background-image: url('images/fancybox.png');
|
239 |
+
background-position: -40px -142px;
|
240 |
+
}
|
241 |
+
|
242 |
+
#fancybox-bg-w {
|
243 |
+
top: 0;
|
244 |
+
left: -20px;
|
245 |
+
height: 100%;
|
246 |
+
background-image: url('images/fancybox-y.png');
|
247 |
+
}
|
248 |
+
|
249 |
+
#fancybox-bg-nw {
|
250 |
+
top: -20px;
|
251 |
+
left: -20px;
|
252 |
+
background-image: url('images/fancybox.png');
|
253 |
+
background-position: -40px -122px;
|
254 |
+
}
|
255 |
+
|
256 |
+
#fancybox-title {
|
257 |
+
font-family: Helvetica;
|
258 |
+
font-size: 12px;
|
259 |
+
z-index: 1102;
|
260 |
+
}
|
261 |
+
|
262 |
+
.fancybox-title-inside {
|
263 |
+
padding-bottom: 10px;
|
264 |
+
text-align: center;
|
265 |
+
color: #333;
|
266 |
+
background: #fff;
|
267 |
+
position: relative;
|
268 |
+
}
|
269 |
+
|
270 |
+
.fancybox-title-outside {
|
271 |
+
padding-top: 10px;
|
272 |
+
color: #fff;
|
273 |
+
}
|
274 |
+
|
275 |
+
.fancybox-title-over {
|
276 |
+
position: absolute;
|
277 |
+
bottom: 0;
|
278 |
+
left: 0;
|
279 |
+
color: #FFF;
|
280 |
+
text-align: left;
|
281 |
+
}
|
282 |
+
|
283 |
+
#fancybox-title-over {
|
284 |
+
padding: 10px;
|
285 |
+
background-image: url('images/fancy_title_over.png');
|
286 |
+
display: block;
|
287 |
+
}
|
288 |
+
|
289 |
+
.fancybox-title-float {
|
290 |
+
position: absolute;
|
291 |
+
left: 0;
|
292 |
+
bottom: -20px;
|
293 |
+
height: 32px;
|
294 |
+
}
|
295 |
+
|
296 |
+
#fancybox-title-float-wrap {
|
297 |
+
border: none;
|
298 |
+
border-collapse: collapse;
|
299 |
+
width: auto;
|
300 |
+
}
|
301 |
+
|
302 |
+
#fancybox-title-float-wrap td {
|
303 |
+
border: none;
|
304 |
+
white-space: nowrap;
|
305 |
+
}
|
306 |
+
|
307 |
+
#fancybox-title-float-left {
|
308 |
+
padding: 0 0 0 15px;
|
309 |
+
background: url('images/fancybox.png') -40px -90px no-repeat;
|
310 |
+
}
|
311 |
+
|
312 |
+
#fancybox-title-float-main {
|
313 |
+
color: #FFF;
|
314 |
+
line-height: 29px;
|
315 |
+
font-weight: bold;
|
316 |
+
padding: 0 0 3px 0;
|
317 |
+
background: url('images/fancybox-x.png') 0px -40px;
|
318 |
+
}
|
319 |
+
|
320 |
+
#fancybox-title-float-right {
|
321 |
+
padding: 0 0 0 15px;
|
322 |
+
background: url('images/fancybox.png') -55px -90px no-repeat;
|
323 |
+
}
|
324 |
+
|
325 |
+
/* IE6 */
|
326 |
+
|
327 |
+
.fancybox-ie6 #fancybox-close { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_close.png', sizingMethod='scale'); }
|
328 |
+
|
329 |
+
.fancybox-ie6 #fancybox-left-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_nav_left.png', sizingMethod='scale'); }
|
330 |
+
.fancybox-ie6 #fancybox-right-ico { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_nav_right.png', sizingMethod='scale'); }
|
331 |
+
|
332 |
+
.fancybox-ie6 #fancybox-title-over { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_title_over.png', sizingMethod='scale'); zoom: 1; }
|
333 |
+
.fancybox-ie6 #fancybox-title-float-left { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_title_left.png', sizingMethod='scale'); }
|
334 |
+
.fancybox-ie6 #fancybox-title-float-main { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_title_main.png', sizingMethod='scale'); }
|
335 |
+
.fancybox-ie6 #fancybox-title-float-right { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_title_right.png', sizingMethod='scale'); }
|
336 |
+
|
337 |
+
.fancybox-ie6 #fancybox-bg-w, .fancybox-ie6 #fancybox-bg-e, .fancybox-ie6 #fancybox-left, .fancybox-ie6 #fancybox-right, #fancybox-hide-sel-frame {
|
338 |
+
height: expression(this.parentNode.clientHeight + "px");
|
339 |
+
}
|
340 |
+
|
341 |
+
#fancybox-loading.fancybox-ie6 {
|
342 |
+
position: absolute; margin-top: 0;
|
343 |
+
top: expression( (-20 + (document.documentElement.clientHeight ? document.documentElement.clientHeight/2 : document.body.clientHeight/2 ) + ( ignoreMe = document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop )) + 'px');
|
344 |
+
}
|
345 |
+
|
346 |
+
#fancybox-loading.fancybox-ie6 div { background: transparent; filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_loading.png', sizingMethod='scale'); }
|
347 |
+
|
348 |
+
/* IE6, IE7, IE8 */
|
349 |
+
|
350 |
+
.fancybox-ie .fancybox-bg { background: transparent !important; }
|
351 |
+
|
352 |
+
.fancybox-ie #fancybox-bg-n { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_shadow_n.png', sizingMethod='scale'); }
|
353 |
+
.fancybox-ie #fancybox-bg-ne { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_shadow_ne.png', sizingMethod='scale'); }
|
354 |
+
.fancybox-ie #fancybox-bg-e { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_shadow_e.png', sizingMethod='scale'); }
|
355 |
+
.fancybox-ie #fancybox-bg-se { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_shadow_se.png', sizingMethod='scale'); }
|
356 |
+
.fancybox-ie #fancybox-bg-s { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_shadow_s.png', sizingMethod='scale'); }
|
357 |
+
.fancybox-ie #fancybox-bg-sw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_shadow_sw.png', sizingMethod='scale'); }
|
358 |
+
.fancybox-ie #fancybox-bg-w { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_shadow_w.png', sizingMethod='scale'); }
|
359 |
+
.fancybox-ie #fancybox-bg-nw { filter: progid:DXImageTransform.Microsoft.AlphaImageLoader(src='images/fancy_shadow_nw.png', sizingMethod='scale'); }
|
extensions/fancybox/js/jquery.fancybox-1.3.4.pack.js
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
/*
|
2 |
+
* FancyBox - jQuery Plugin
|
3 |
+
* Simple and fancy lightbox alternative
|
4 |
+
*
|
5 |
+
* Examples and documentation at: http://fancybox.net
|
6 |
+
*
|
7 |
+
* Copyright (c) 2008 - 2010 Janis Skarnelis
|
8 |
+
* That said, it is hardly a one-person project. Many people have submitted bugs, code, and offered their advice freely. Their support is greatly appreciated.
|
9 |
+
*
|
10 |
+
* Version: 1.3.4 (11/11/2010)
|
11 |
+
* Requires: jQuery v1.3+
|
12 |
+
*
|
13 |
+
* Dual licensed under the MIT and GPL licenses:
|
14 |
+
* http://www.opensource.org/licenses/mit-license.php
|
15 |
+
* http://www.gnu.org/licenses/gpl.html
|
16 |
+
*/
|
17 |
+
|
18 |
+
;(function(b){var m,t,u,f,D,j,E,n,z,A,q=0,e={},o=[],p=0,d={},l=[],G=null,v=new Image,J=/\.(jpg|gif|png|bmp|jpeg)(.*)?$/i,W=/[^\.]\.(swf)\s*$/i,K,L=1,y=0,s="",r,i,h=false,B=b.extend(b("<div/>")[0],{prop:0}),M=b.browser.msie&&b.browser.version<7&&!window.XMLHttpRequest,N=function(){t.hide();v.onerror=v.onload=null;G&&G.abort();m.empty()},O=function(){if(false===e.onError(o,q,e)){t.hide();h=false}else{e.titleShow=false;e.width="auto";e.height="auto";m.html('<p id="fancybox-error">The requested content cannot be loaded.<br />Please try again later.</p>');
|
19 |
+
F()}},I=function(){var a=o[q],c,g,k,C,P,w;N();e=b.extend({},b.fn.fancybox.defaults,typeof b(a).data("fancybox")=="undefined"?e:b(a).data("fancybox"));w=e.onStart(o,q,e);if(w===false)h=false;else{if(typeof w=="object")e=b.extend(e,w);k=e.title||(a.nodeName?b(a).attr("title"):a.title)||"";if(a.nodeName&&!e.orig)e.orig=b(a).children("img:first").length?b(a).children("img:first"):b(a);if(k===""&&e.orig&&e.titleFromAlt)k=e.orig.attr("alt");c=e.href||(a.nodeName?b(a).attr("href"):a.href)||null;if(/^(?:javascript)/i.test(c)||
|
20 |
+
c=="#")c=null;if(e.type){g=e.type;if(!c)c=e.content}else if(e.content)g="html";else if(c)g=c.match(J)?"image":c.match(W)?"swf":b(a).hasClass("iframe")?"iframe":c.indexOf("#")===0?"inline":"ajax";if(g){if(g=="inline"){a=c.substr(c.indexOf("#"));g=b(a).length>0?"inline":"ajax"}e.type=g;e.href=c;e.title=k;if(e.autoDimensions)if(e.type=="html"||e.type=="inline"||e.type=="ajax"){e.width="auto";e.height="auto"}else e.autoDimensions=false;if(e.modal){e.overlayShow=true;e.hideOnOverlayClick=false;e.hideOnContentClick=
|
21 |
+
false;e.enableEscapeButton=false;e.showCloseButton=false}e.padding=parseInt(e.padding,10);e.margin=parseInt(e.margin,10);m.css("padding",e.padding+e.margin);b(".fancybox-inline-tmp").unbind("fancybox-cancel").bind("fancybox-change",function(){b(this).replaceWith(j.children())});switch(g){case "html":m.html(e.content);F();break;case "inline":if(b(a).parent().is("#fancybox-content")===true){h=false;break}b('<div class="fancybox-inline-tmp" />').hide().insertBefore(b(a)).bind("fancybox-cleanup",function(){b(this).replaceWith(j.children())}).bind("fancybox-cancel",
|
22 |
+
function(){b(this).replaceWith(m.children())});b(a).appendTo(m);F();break;case "image":h=false;b.fancybox.showActivity();v=new Image;v.onerror=function(){O()};v.onload=function(){h=true;v.onerror=v.onload=null;e.width=v.width;e.height=v.height;b("<img />").attr({id:"fancybox-img",src:v.src,alt:e.title}).appendTo(m);Q()};v.src=c;break;case "swf":e.scrolling="no";C='<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="'+e.width+'" height="'+e.height+'"><param name="movie" value="'+c+
|
23 |
+
'"></param>';P="";b.each(e.swf,function(x,H){C+='<param name="'+x+'" value="'+H+'"></param>';P+=" "+x+'="'+H+'"'});C+='<embed src="'+c+'" type="application/x-shockwave-flash" width="'+e.width+'" height="'+e.height+'"'+P+"></embed></object>";m.html(C);F();break;case "ajax":h=false;b.fancybox.showActivity();e.ajax.win=e.ajax.success;G=b.ajax(b.extend({},e.ajax,{url:c,data:e.ajax.data||{},error:function(x){x.status>0&&O()},success:function(x,H,R){if((typeof R=="object"?R:G).status==200){if(typeof e.ajax.win==
|
24 |
+
"function"){w=e.ajax.win(c,x,H,R);if(w===false){t.hide();return}else if(typeof w=="string"||typeof w=="object")x=w}m.html(x);F()}}}));break;case "iframe":Q()}}else O()}},F=function(){var a=e.width,c=e.height;a=a.toString().indexOf("%")>-1?parseInt((b(window).width()-e.margin*2)*parseFloat(a)/100,10)+"px":a=="auto"?"auto":a+"px";c=c.toString().indexOf("%")>-1?parseInt((b(window).height()-e.margin*2)*parseFloat(c)/100,10)+"px":c=="auto"?"auto":c+"px";m.wrapInner('<div style="width:'+a+";height:"+c+
|
25 |
+
";overflow: "+(e.scrolling=="auto"?"auto":e.scrolling=="yes"?"scroll":"hidden")+';position:relative;"></div>');e.width=m.width();e.height=m.height();Q()},Q=function(){var a,c;t.hide();if(f.is(":visible")&&false===d.onCleanup(l,p,d)){b.event.trigger("fancybox-cancel");h=false}else{h=true;b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");f.is(":visible")&&d.titlePosition!=="outside"&&f.css("height",f.height());l=o;p=q;d=e;if(d.overlayShow){u.css({"background-color":d.overlayColor,
|
26 |
+
opacity:d.overlayOpacity,cursor:d.hideOnOverlayClick?"pointer":"auto",height:b(document).height()});if(!u.is(":visible")){M&&b("select:not(#fancybox-tmp select)").filter(function(){return this.style.visibility!=="hidden"}).css({visibility:"hidden"}).one("fancybox-cleanup",function(){this.style.visibility="inherit"});u.show()}}else u.hide();i=X();s=d.title||"";y=0;n.empty().removeAttr("style").removeClass();if(d.titleShow!==false){if(b.isFunction(d.titleFormat))a=d.titleFormat(s,l,p,d);else a=s&&s.length?
|
27 |
+
d.titlePosition=="float"?'<table id="fancybox-title-float-wrap" cellpadding="0" cellspacing="0"><tr><td id="fancybox-title-float-left"></td><td id="fancybox-title-float-main">'+s+'</td><td id="fancybox-title-float-right"></td></tr></table>':'<div id="fancybox-title-'+d.titlePosition+'">'+s+"</div>":false;s=a;if(!(!s||s==="")){n.addClass("fancybox-title-"+d.titlePosition).html(s).appendTo("body").show();switch(d.titlePosition){case "inside":n.css({width:i.width-d.padding*2,marginLeft:d.padding,marginRight:d.padding});
|
28 |
+
y=n.outerHeight(true);n.appendTo(D);i.height+=y;break;case "over":n.css({marginLeft:d.padding,width:i.width-d.padding*2,bottom:d.padding}).appendTo(D);break;case "float":n.css("left",parseInt((n.width()-i.width-40)/2,10)*-1).appendTo(f);break;default:n.css({width:i.width-d.padding*2,paddingLeft:d.padding,paddingRight:d.padding}).appendTo(f)}}}n.hide();if(f.is(":visible")){b(E.add(z).add(A)).hide();a=f.position();r={top:a.top,left:a.left,width:f.width(),height:f.height()};c=r.width==i.width&&r.height==
|
29 |
+
i.height;j.fadeTo(d.changeFade,0.3,function(){var g=function(){j.html(m.contents()).fadeTo(d.changeFade,1,S)};b.event.trigger("fancybox-change");j.empty().removeAttr("filter").css({"border-width":d.padding,width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2});if(c)g();else{B.prop=0;b(B).animate({prop:1},{duration:d.changeSpeed,easing:d.easingChange,step:T,complete:g})}})}else{f.removeAttr("style");j.css("border-width",d.padding);if(d.transitionIn=="elastic"){r=V();j.html(m.contents());
|
30 |
+
f.show();if(d.opacity)i.opacity=0;B.prop=0;b(B).animate({prop:1},{duration:d.speedIn,easing:d.easingIn,step:T,complete:S})}else{d.titlePosition=="inside"&&y>0&&n.show();j.css({width:i.width-d.padding*2,height:e.autoDimensions?"auto":i.height-y-d.padding*2}).html(m.contents());f.css(i).fadeIn(d.transitionIn=="none"?0:d.speedIn,S)}}}},Y=function(){if(d.enableEscapeButton||d.enableKeyboardNav)b(document).bind("keydown.fb",function(a){if(a.keyCode==27&&d.enableEscapeButton){a.preventDefault();b.fancybox.close()}else if((a.keyCode==
|
31 |
+
37||a.keyCode==39)&&d.enableKeyboardNav&&a.target.tagName!=="INPUT"&&a.target.tagName!=="TEXTAREA"&&a.target.tagName!=="SELECT"){a.preventDefault();b.fancybox[a.keyCode==37?"prev":"next"]()}});if(d.showNavArrows){if(d.cyclic&&l.length>1||p!==0)z.show();if(d.cyclic&&l.length>1||p!=l.length-1)A.show()}else{z.hide();A.hide()}},S=function(){if(!b.support.opacity){j.get(0).style.removeAttribute("filter");f.get(0).style.removeAttribute("filter")}e.autoDimensions&&j.css("height","auto");f.css("height","auto");
|
32 |
+
s&&s.length&&n.show();d.showCloseButton&&E.show();Y();d.hideOnContentClick&&j.bind("click",b.fancybox.close);d.hideOnOverlayClick&&u.bind("click",b.fancybox.close);b(window).bind("resize.fb",b.fancybox.resize);d.centerOnScroll&&b(window).bind("scroll.fb",b.fancybox.center);if(d.type=="iframe")b('<iframe id="fancybox-frame" name="fancybox-frame'+(new Date).getTime()+'" frameborder="0" hspace="0" '+(b.browser.msie?'allowtransparency="true""':"")+' scrolling="'+e.scrolling+'" src="'+d.href+'"></iframe>').appendTo(j);
|
33 |
+
f.show();h=false;b.fancybox.center();d.onComplete(l,p,d);var a,c;if(l.length-1>p){a=l[p+1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}if(p>0){a=l[p-1].href;if(typeof a!=="undefined"&&a.match(J)){c=new Image;c.src=a}}},T=function(a){var c={width:parseInt(r.width+(i.width-r.width)*a,10),height:parseInt(r.height+(i.height-r.height)*a,10),top:parseInt(r.top+(i.top-r.top)*a,10),left:parseInt(r.left+(i.left-r.left)*a,10)};if(typeof i.opacity!=="undefined")c.opacity=a<0.5?0.5:a;f.css(c);
|
34 |
+
j.css({width:c.width-d.padding*2,height:c.height-y*a-d.padding*2})},U=function(){return[b(window).width()-d.margin*2,b(window).height()-d.margin*2,b(document).scrollLeft()+d.margin,b(document).scrollTop()+d.margin]},X=function(){var a=U(),c={},g=d.autoScale,k=d.padding*2;c.width=d.width.toString().indexOf("%")>-1?parseInt(a[0]*parseFloat(d.width)/100,10):d.width+k;c.height=d.height.toString().indexOf("%")>-1?parseInt(a[1]*parseFloat(d.height)/100,10):d.height+k;if(g&&(c.width>a[0]||c.height>a[1]))if(e.type==
|
35 |
+
"image"||e.type=="swf"){g=d.width/d.height;if(c.width>a[0]){c.width=a[0];c.height=parseInt((c.width-k)/g+k,10)}if(c.height>a[1]){c.height=a[1];c.width=parseInt((c.height-k)*g+k,10)}}else{c.width=Math.min(c.width,a[0]);c.height=Math.min(c.height,a[1])}c.top=parseInt(Math.max(a[3]-20,a[3]+(a[1]-c.height-40)*0.5),10);c.left=parseInt(Math.max(a[2]-20,a[2]+(a[0]-c.width-40)*0.5),10);return c},V=function(){var a=e.orig?b(e.orig):false,c={};if(a&&a.length){c=a.offset();c.top+=parseInt(a.css("paddingTop"),
|
36 |
+
10)||0;c.left+=parseInt(a.css("paddingLeft"),10)||0;c.top+=parseInt(a.css("border-top-width"),10)||0;c.left+=parseInt(a.css("border-left-width"),10)||0;c.width=a.width();c.height=a.height();c={width:c.width+d.padding*2,height:c.height+d.padding*2,top:c.top-d.padding-20,left:c.left-d.padding-20}}else{a=U();c={width:d.padding*2,height:d.padding*2,top:parseInt(a[3]+a[1]*0.5,10),left:parseInt(a[2]+a[0]*0.5,10)}}return c},Z=function(){if(t.is(":visible")){b("div",t).css("top",L*-40+"px");L=(L+1)%12}else clearInterval(K)};
|
37 |
+
b.fn.fancybox=function(a){if(!b(this).length)return this;b(this).data("fancybox",b.extend({},a,b.metadata?b(this).metadata():{})).unbind("click.fb").bind("click.fb",function(c){c.preventDefault();if(!h){h=true;b(this).blur();o=[];q=0;c=b(this).attr("rel")||"";if(!c||c==""||c==="nofollow")o.push(this);else{o=b("a[rel="+c+"], area[rel="+c+"]");q=o.index(this)}I()}});return this};b.fancybox=function(a,c){var g;if(!h){h=true;g=typeof c!=="undefined"?c:{};o=[];q=parseInt(g.index,10)||0;if(b.isArray(a)){for(var k=
|
38 |
+
0,C=a.length;k<C;k++)if(typeof a[k]=="object")b(a[k]).data("fancybox",b.extend({},g,a[k]));else a[k]=b({}).data("fancybox",b.extend({content:a[k]},g));o=jQuery.merge(o,a)}else{if(typeof a=="object")b(a).data("fancybox",b.extend({},g,a));else a=b({}).data("fancybox",b.extend({content:a},g));o.push(a)}if(q>o.length||q<0)q=0;I()}};b.fancybox.showActivity=function(){clearInterval(K);t.show();K=setInterval(Z,66)};b.fancybox.hideActivity=function(){t.hide()};b.fancybox.next=function(){return b.fancybox.pos(p+
|
39 |
+
1)};b.fancybox.prev=function(){return b.fancybox.pos(p-1)};b.fancybox.pos=function(a){if(!h){a=parseInt(a);o=l;if(a>-1&&a<l.length){q=a;I()}else if(d.cyclic&&l.length>1){q=a>=l.length?0:l.length-1;I()}}};b.fancybox.cancel=function(){if(!h){h=true;b.event.trigger("fancybox-cancel");N();e.onCancel(o,q,e);h=false}};b.fancybox.close=function(){function a(){u.fadeOut("fast");n.empty().hide();f.hide();b.event.trigger("fancybox-cleanup");j.empty();d.onClosed(l,p,d);l=e=[];p=q=0;d=e={};h=false}if(!(h||f.is(":hidden"))){h=
|
40 |
+
true;if(d&&false===d.onCleanup(l,p,d))h=false;else{N();b(E.add(z).add(A)).hide();b(j.add(u)).unbind();b(window).unbind("resize.fb scroll.fb");b(document).unbind("keydown.fb");j.find("iframe").attr("src",M&&/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank");d.titlePosition!=="inside"&&n.empty();f.stop();if(d.transitionOut=="elastic"){r=V();var c=f.position();i={top:c.top,left:c.left,width:f.width(),height:f.height()};if(d.opacity)i.opacity=1;n.empty().hide();B.prop=1;
|
41 |
+
b(B).animate({prop:0},{duration:d.speedOut,easing:d.easingOut,step:T,complete:a})}else f.fadeOut(d.transitionOut=="none"?0:d.speedOut,a)}}};b.fancybox.resize=function(){u.is(":visible")&&u.css("height",b(document).height());b.fancybox.center(true)};b.fancybox.center=function(a){var c,g;if(!h){g=a===true?1:0;c=U();!g&&(f.width()>c[0]||f.height()>c[1])||f.stop().animate({top:parseInt(Math.max(c[3]-20,c[3]+(c[1]-j.height()-40)*0.5-d.padding)),left:parseInt(Math.max(c[2]-20,c[2]+(c[0]-j.width()-40)*0.5-
|
42 |
+
d.padding))},typeof a=="number"?a:200)}};b.fancybox.init=function(){if(!b("#fancybox-wrap").length){b("body").append(m=b('<div id="fancybox-tmp"></div>'),t=b('<div id="fancybox-loading"><div></div></div>'),u=b('<div id="fancybox-overlay"></div>'),f=b('<div id="fancybox-wrap"></div>'));D=b('<div id="fancybox-outer"></div>').append('<div class="fancybox-bg" id="fancybox-bg-n"></div><div class="fancybox-bg" id="fancybox-bg-ne"></div><div class="fancybox-bg" id="fancybox-bg-e"></div><div class="fancybox-bg" id="fancybox-bg-se"></div><div class="fancybox-bg" id="fancybox-bg-s"></div><div class="fancybox-bg" id="fancybox-bg-sw"></div><div class="fancybox-bg" id="fancybox-bg-w"></div><div class="fancybox-bg" id="fancybox-bg-nw"></div>').appendTo(f);
|
43 |
+
D.append(j=b('<div id="fancybox-content"></div>'),E=b('<a id="fancybox-close"></a>'),n=b('<div id="fancybox-title"></div>'),z=b('<a href="javascript:;" id="fancybox-left"><span class="fancy-ico" id="fancybox-left-ico"></span></a>'),A=b('<a href="javascript:;" id="fancybox-right"><span class="fancy-ico" id="fancybox-right-ico"></span></a>'));E.click(b.fancybox.close);t.click(b.fancybox.cancel);z.click(function(a){a.preventDefault();b.fancybox.prev()});A.click(function(a){a.preventDefault();b.fancybox.next()});
|
44 |
+
b.fn.mousewheel&&f.bind("mousewheel.fb",function(a,c){if(h)a.preventDefault();else if(b(a.target).get(0).clientHeight==0||b(a.target).get(0).scrollHeight===b(a.target).get(0).clientHeight){a.preventDefault();b.fancybox[c>0?"prev":"next"]()}});b.support.opacity||f.addClass("fancybox-ie");if(M){t.addClass("fancybox-ie6");f.addClass("fancybox-ie6");b('<iframe id="fancybox-hide-sel-frame" src="'+(/^https/i.test(window.location.href||"")?"javascript:void(false)":"about:blank")+'" scrolling="no" border="0" frameborder="0" tabindex="-1"></iframe>').prependTo(D)}}};
|
45 |
+
b.fn.fancybox.defaults={padding:10,margin:40,opacity:false,modal:false,cyclic:false,scrolling:"auto",width:560,height:340,autoScale:true,autoDimensions:true,centerOnScroll:false,ajax:{},swf:{wmode:"transparent"},hideOnOverlayClick:true,hideOnContentClick:false,overlayShow:true,overlayOpacity:0.7,overlayColor:"#777",titleShow:true,titlePosition:"float",titleFormat:null,titleFromAlt:false,transitionIn:"fade",transitionOut:"fade",speedIn:300,speedOut:300,changeSpeed:300,changeFade:"fast",easingIn:"swing",
|
46 |
+
easingOut:"swing",showCloseButton:true,showNavArrows:true,enableEscapeButton:true,enableKeyboardNav:true,onStart:function(){},onCancel:function(){},onComplete:function(){},onCleanup:function(){},onClosed:function(){},onError:function(){}};b(document).ready(function(){b.fancybox.init()})})(jQuery);
|
images/css.png
ADDED
Binary file
|
images/folder.png
ADDED
Binary file
|
images/gif.png
ADDED
Binary file
|
images/htm.png
ADDED
Binary file
|
images/html.png
ADDED
Binary file
|
images/jpeg.png
ADDED
Binary file
|
images/jpg.png
ADDED
Binary file
|
images/js.png
ADDED
Binary file
|
images/loader.gif
ADDED
Binary file
|
images/php.png
ADDED
Binary file
|
images/png.png
ADDED
Binary file
|
images/po.png
ADDED
Binary file
|
images/pot.png
ADDED
Binary file
|
images/sql.png
ADDED
Binary file
|
images/txt.png
ADDED
Binary file
|
images/wpeditor_logo_16.png
ADDED
Binary file
|
images/wpeditor_logo_32.png
ADDED
Binary file
|
js/wpeditor.js
ADDED
@@ -0,0 +1,345 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
editor = new Object();
|
2 |
+
var changed = false;
|
3 |
+
function changeTrue() {
|
4 |
+
changed = true;
|
5 |
+
}
|
6 |
+
|
7 |
+
function changeReset() {
|
8 |
+
changed = false;
|
9 |
+
}
|
10 |
+
|
11 |
+
function hasChanged() {
|
12 |
+
return changed;
|
13 |
+
}
|
14 |
+
|
15 |
+
function checkChanged() {
|
16 |
+
if(hasChanged()) {
|
17 |
+
if(confirm('You have unsaved changes on this page. Are you sure you want to load a new document?')) {
|
18 |
+
changed = false;
|
19 |
+
}
|
20 |
+
else {
|
21 |
+
changed = true;
|
22 |
+
}
|
23 |
+
}
|
24 |
+
return changed;
|
25 |
+
}
|
26 |
+
function checkExtension(extension) {
|
27 |
+
var ext = false;
|
28 |
+
var exts = [
|
29 |
+
'gif',
|
30 |
+
'png',
|
31 |
+
'jpg',
|
32 |
+
'jpeg'
|
33 |
+
];
|
34 |
+
if(jQuery.inArray(extension, exts) >= 0) {
|
35 |
+
ext = true;
|
36 |
+
}
|
37 |
+
return ext;
|
38 |
+
}
|
39 |
+
function toggleFullscreenEditing() {
|
40 |
+
$jq = jQuery.noConflict();
|
41 |
+
var editorDiv = $jq('.CodeMirror');
|
42 |
+
if(!editorDiv.hasClass('CodeMirror-fullscreen')) {
|
43 |
+
toggleFullscreenEditing.beforeFullscreen = {
|
44 |
+
height: editorDiv.height(),
|
45 |
+
width: editorDiv.width()
|
46 |
+
}
|
47 |
+
editorDiv.addClass('CodeMirror-fullscreen');
|
48 |
+
editorDiv.height('100%');
|
49 |
+
$jq('.CodeMirror-scroll').height('100%');
|
50 |
+
editorDiv.width('100%');
|
51 |
+
editor.refresh();
|
52 |
+
}
|
53 |
+
else {
|
54 |
+
editorDiv.removeClass('CodeMirror-fullscreen');
|
55 |
+
editorDiv.height(toggleFullscreenEditing.beforeFullscreen.height);
|
56 |
+
$jq('.CodeMirror-scroll').height('450px');
|
57 |
+
editorDiv.width('97%');
|
58 |
+
editor.refresh();
|
59 |
+
}
|
60 |
+
}
|
61 |
+
|
62 |
+
(function($){
|
63 |
+
var c = function(){
|
64 |
+
|
65 |
+
};
|
66 |
+
$.extend(c.prototype, {
|
67 |
+
name:'folders',initialize:function(element, handler){
|
68 |
+
function ajaxFolders(handler){
|
69 |
+
if(!checkChanged()) {
|
70 |
+
handler.preventDefault();
|
71 |
+
var newElement = $(this).closest('li', element);
|
72 |
+
newElement.length || (newElement = element);
|
73 |
+
if(newElement.hasClass(ajaxObject.options.open) && !newElement.hasClass('file')) {
|
74 |
+
newElement.removeClass(ajaxObject.options.open).children('ul').slideUp();
|
75 |
+
}
|
76 |
+
else if(!newElement.hasClass(ajaxObject.options.open) && newElement.hasClass('file')) {
|
77 |
+
// Removed in 1.0.2 to fix issues with reloading a version that was not correct.
|
78 |
+
//if(newElement.data('content') != null) {
|
79 |
+
// editor.toTextArea();
|
80 |
+
// $('#new-content').val(newElement.data('content'));
|
81 |
+
// $('#file').val(newElement.data('file'));
|
82 |
+
// $('#path').val(newElement.data('path'));
|
83 |
+
// $('#extension').val(newElement.data('extension'));
|
84 |
+
// $('.current_file').html(newElement.data('file'));
|
85 |
+
// console.log(newElement.data('file'))
|
86 |
+
// runCodeMirror(newElement.data('extension'));
|
87 |
+
//}
|
88 |
+
if(checkExtension(newElement.data('extension'))) {
|
89 |
+
$.fancybox(this);
|
90 |
+
}
|
91 |
+
else {
|
92 |
+
var type = $('#content-type').val();
|
93 |
+
runAjaxRequest(newElement, ajaxObject, 'file', type);
|
94 |
+
}
|
95 |
+
}
|
96 |
+
else {
|
97 |
+
var type = $('#content-type').val();
|
98 |
+
runAjaxRequest(newElement, ajaxObject, null, type);
|
99 |
+
}
|
100 |
+
}
|
101 |
+
else {
|
102 |
+
return false;
|
103 |
+
}
|
104 |
+
}
|
105 |
+
function runAjaxRequest(newElement, ajaxObject, contentType, type) {
|
106 |
+
if(contentType === 'file'){
|
107 |
+
var contents = 1;
|
108 |
+
}
|
109 |
+
else {
|
110 |
+
var contents = 0;
|
111 |
+
}
|
112 |
+
if(newElement.data('encoded') === 1) {
|
113 |
+
var path = newElement.data('path');
|
114 |
+
}
|
115 |
+
else {
|
116 |
+
var path = encodeURI(newElement.data('path'));
|
117 |
+
}
|
118 |
+
newElement.addClass(ajaxObject.options.loading),
|
119 |
+
$.post(
|
120 |
+
ajaxObject.options.url, {
|
121 |
+
action: 'ajax_folders',
|
122 |
+
dir: path,
|
123 |
+
contents: contents,
|
124 |
+
type: type
|
125 |
+
}, function(result){
|
126 |
+
if(contentType === 'file'){
|
127 |
+
newElement.removeClass(ajaxObject.options.loading);
|
128 |
+
if(result.content == null) {
|
129 |
+
$('#save-result').html('<div id="save-message" class="WPEditorAjaxError"></div>');
|
130 |
+
$('#save-message').append('<h3>Warning</h3><p>An error occured while trying to open this file</p>');
|
131 |
+
$('#save-result').fadeIn(1000).delay(3000).fadeOut(300);
|
132 |
+
}
|
133 |
+
else {
|
134 |
+
editor.toTextArea();
|
135 |
+
$('#new-content').val(result.content);
|
136 |
+
$('#file').val(result.file);
|
137 |
+
$('#path').val(result.path);
|
138 |
+
$('#extension').val(result.extension);
|
139 |
+
$('.current_file').html(result.file);
|
140 |
+
runCodeMirror(result.extension);
|
141 |
+
}
|
142 |
+
}
|
143 |
+
else {
|
144 |
+
newElement.removeClass(ajaxObject.options.loading).addClass(ajaxObject.options.open);
|
145 |
+
result.length && (
|
146 |
+
newElement.children().remove('ul'),
|
147 |
+
newElement.append('<ul>').children('ul').hide(),
|
148 |
+
$.each(result, function(index, value){
|
149 |
+
if(checkExtension(value.extension)) {
|
150 |
+
newElement.children('ul').append(
|
151 |
+
$('<li><a href="' + value.url + '" class="fancybox ' + value.filetype + '">' + value.name + ' <span class="tiny">' + value.filesize + '</span></a></li>').addClass(
|
152 |
+
value.extension + ' ' + value.filetype
|
153 |
+
).data({
|
154 |
+
'path': value.path,
|
155 |
+
'content': value.content,
|
156 |
+
'filesize': value.filesize,
|
157 |
+
'file': value.file,
|
158 |
+
'extension': value.extension,
|
159 |
+
'url': value.url
|
160 |
+
}
|
161 |
+
))
|
162 |
+
}
|
163 |
+
else {
|
164 |
+
newElement.children('ul').append(
|
165 |
+
$('<li><a href="#" class="' + value.filetype + '">' + value.name + ' <span class="tiny">' + value.filesize + '</span></a></li>').addClass(
|
166 |
+
value.extension + ' ' + value.filetype
|
167 |
+
).data({
|
168 |
+
'path': value.path,
|
169 |
+
'content': value.content,
|
170 |
+
'filesize': value.filesize,
|
171 |
+
'file': value.file,
|
172 |
+
'extension': value.extension,
|
173 |
+
'url': value.url
|
174 |
+
}
|
175 |
+
))
|
176 |
+
}
|
177 |
+
}),
|
178 |
+
newElement.find('ul a').bind('click', ajaxFolders),
|
179 |
+
newElement.children('ul').slideDown()
|
180 |
+
)
|
181 |
+
}
|
182 |
+
}, 'json')
|
183 |
+
}
|
184 |
+
var ajaxObject = this;
|
185 |
+
this.options = $.extend({
|
186 |
+
url: '',
|
187 |
+
path: '',
|
188 |
+
url: '',
|
189 |
+
encoded: '',
|
190 |
+
content: '',
|
191 |
+
filesize: '',
|
192 |
+
file: '',
|
193 |
+
extension: '',
|
194 |
+
open: 'opened',
|
195 |
+
loading: 'loading'
|
196 |
+
}, handler);
|
197 |
+
element.data({
|
198 |
+
'path': this.options.path,
|
199 |
+
'encoded': this.options.encoded,
|
200 |
+
'content': this.options.content,
|
201 |
+
'filesize': this.options.filesize,
|
202 |
+
'file': this.options.file,
|
203 |
+
'extension': this.options.extension,
|
204 |
+
'url': this.options.url
|
205 |
+
}).bind('retrieve:finder', ajaxFolders).trigger('retrieve:finder')
|
206 |
+
}
|
207 |
+
});
|
208 |
+
$.fn[c.prototype.name] = function(){
|
209 |
+
var b = arguments
|
210 |
+
var g = b[0] ? b[0] : null;
|
211 |
+
return this.each(function(){
|
212 |
+
var f = $(this);
|
213 |
+
if(c.prototype[g] && f.data(c.prototype.name) && g != 'initialize'){
|
214 |
+
f.data(c.prototype.name)[g].apply(
|
215 |
+
f.data(c.prototype.name),
|
216 |
+
Array.prototype.slice.call(b, 1)
|
217 |
+
);
|
218 |
+
}
|
219 |
+
else if(!g || $.isPlainObject(g)){
|
220 |
+
var e = new c;
|
221 |
+
c.prototype.initialize && e.initialize.apply(e, $.merge([f], b));
|
222 |
+
f.data(c.prototype.name, e)
|
223 |
+
}
|
224 |
+
else {
|
225 |
+
$.error('Method ' + g + ' does not exist on jQuery.' + c.name)
|
226 |
+
}
|
227 |
+
})
|
228 |
+
}
|
229 |
+
})(jQuery);
|
230 |
+
(function($){
|
231 |
+
$(document).ready(function(){
|
232 |
+
|
233 |
+
$('#new-content').change(function() {
|
234 |
+
changeTrue();
|
235 |
+
});
|
236 |
+
|
237 |
+
$('#save-result').click(function() {
|
238 |
+
$(this).hide();
|
239 |
+
});
|
240 |
+
$('.ajax-settings-form').submit(function() {
|
241 |
+
var data = getFormData($(this).attr('id'));
|
242 |
+
$.ajax({
|
243 |
+
type: "POST",
|
244 |
+
url: ajaxurl,
|
245 |
+
data: data,
|
246 |
+
dataType: 'json',
|
247 |
+
success: function(result) {
|
248 |
+
$('#save-result').html("<div id='save-message' class='" + result[0] + "'></div>");
|
249 |
+
$('#save-message').append(result[1]);
|
250 |
+
$('#save-result').fadeIn(1000).delay(3000).fadeOut(300);
|
251 |
+
}
|
252 |
+
});
|
253 |
+
return false;
|
254 |
+
});
|
255 |
+
|
256 |
+
$('.ajax-editor-update').submit(function() {
|
257 |
+
editor.save(); // Implemented .save() in 1.0.2 instead of .toTextArea() to fix issues with not maintaining line numbers
|
258 |
+
var data = {
|
259 |
+
action: 'save_files',
|
260 |
+
real_file: $('#path').val(),
|
261 |
+
new_content: $('#new-content').val(),
|
262 |
+
file: $('#file').val(),
|
263 |
+
plugin: $('#plugin-dirname').val(),
|
264 |
+
extension: $('#extension').val(),
|
265 |
+
_success: $('#_success').val()
|
266 |
+
}
|
267 |
+
// Removed in 1.0.2
|
268 |
+
//runCodeMirror($('#extension').val());
|
269 |
+
$.ajax({
|
270 |
+
type: "POST",
|
271 |
+
url: ajaxurl,
|
272 |
+
data: data,
|
273 |
+
dataType: 'json',
|
274 |
+
success: function(result) {
|
275 |
+
// Removed in 1.0.2
|
276 |
+
//editor.save();
|
277 |
+
$('#save-result').html("<div id='save-message' class='" + result[0] + "'></div>");
|
278 |
+
$('#save-message').append(result[1]);
|
279 |
+
$('#save-result').fadeIn(1000).delay(3000).fadeOut(300);
|
280 |
+
changeReset();
|
281 |
+
// Removed in 1.0.2
|
282 |
+
//runCodeMirror(result[2]);
|
283 |
+
}
|
284 |
+
});
|
285 |
+
return false;
|
286 |
+
});
|
287 |
+
$(window).bind('beforeunload', function() {
|
288 |
+
if(hasChanged()) {
|
289 |
+
return 'Leaving this page will undo all changes you have made.';
|
290 |
+
}
|
291 |
+
});
|
292 |
+
});
|
293 |
+
})(jQuery);
|
294 |
+
function enableThemeAjaxBrowser(path) {
|
295 |
+
$jq = jQuery.noConflict();
|
296 |
+
var c;
|
297 |
+
var url = ajaxurl;
|
298 |
+
$jq('#theme-folders').folders({
|
299 |
+
url: url,
|
300 |
+
path: path,
|
301 |
+
encoded: 1
|
302 |
+
}).delegate('a','click',function() {
|
303 |
+
$jq('#theme-folders li').removeClass('selected');
|
304 |
+
c = $jq(this).parent().addClass('selected').data('path')
|
305 |
+
});
|
306 |
+
}
|
307 |
+
function enablePluginAjaxBrowser(path) {
|
308 |
+
$jq = jQuery.noConflict();
|
309 |
+
var c;
|
310 |
+
var url = ajaxurl;
|
311 |
+
$jq('#plugin-folders').folders({
|
312 |
+
url: url,
|
313 |
+
path: path,
|
314 |
+
encoded: 1
|
315 |
+
}).delegate('a','click',function() {
|
316 |
+
$jq('#plugin-folders li').removeClass('selected');
|
317 |
+
c = $jq(this).parent().addClass('selected').data('path')
|
318 |
+
});
|
319 |
+
}
|
320 |
+
function getFormData(formId) {
|
321 |
+
$jq = jQuery.noConflict();
|
322 |
+
var theForm = $jq('#' + formId);
|
323 |
+
var str = '';
|
324 |
+
$jq('input:not([type=checkbox], :radio), input[type=checkbox]:checked, input:radio:checked, select, textarea', theForm).each(
|
325 |
+
function() {
|
326 |
+
var name = $jq(this).attr('name');
|
327 |
+
var val = encodeURIComponent($jq(this).val());
|
328 |
+
str += name + '=' + val + '&';
|
329 |
+
}
|
330 |
+
);
|
331 |
+
return str.substring(0, str.length-1);
|
332 |
+
}
|
333 |
+
function settingsTabs(tab) {
|
334 |
+
$jq = jQuery.noConflict();
|
335 |
+
$jq('#settings-' + tab).show();
|
336 |
+
$jq('#settings-loading').hide();
|
337 |
+
$jq('#settings-' + tab + '-tab a').addClass('active');
|
338 |
+
$jq('div.settings-tabs ul li a').click(function(){
|
339 |
+
var thisClass = $jq(this).attr('id').replace('settings-link-','');
|
340 |
+
$jq('div.settings-body').hide();
|
341 |
+
$jq('#settings-' + thisClass).fadeIn(300);
|
342 |
+
$jq('div.settings-tabs ul li a').removeClass('active');
|
343 |
+
$jq('#settings-link-' + thisClass).addClass('active');
|
344 |
+
});
|
345 |
+
}
|
log.txt
ADDED
File without changes
|
readme.txt
ADDED
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
=== WP Editor ===
|
2 |
+
Contributors: benjaminprojas
|
3 |
+
Donate link: http://wpeditor.net/
|
4 |
+
Tags: plugin editor, theme editor, codemirror, plugins, themes, editor, fancybox
|
5 |
+
Requires at least: 3.0
|
6 |
+
Tested up to: 3.3.1
|
7 |
+
Stable tag: 1.0 BETA
|
8 |
+
|
9 |
+
WP Editor is a plugin for WordPress that replaces the default plugin and theme editors.
|
10 |
+
|
11 |
+
== Description ==
|
12 |
+
|
13 |
+
WP Editor is a plugin for WordPress that replaces the default plugin and theme editors. Using integrations with CodeMirror and FancyBox to create a feature rich environment, WP Editor completely reworks the default WordPress file editing capabilities. Using Asynchronous Javascript and XML (AJAX) to retrieve files and folders, WP Editor sets a new standard for speed and reliability in a web-based editing atmosphere.
|
14 |
+
|
15 |
+
= Features: =
|
16 |
+
* CodeMirror
|
17 |
+
* Active Line Highlighting
|
18 |
+
* Line Numbers
|
19 |
+
* Line Wrapping
|
20 |
+
* Eight Editor Themes with Syntax Highlighting
|
21 |
+
* Fullscreen Editing (ESC, F11)
|
22 |
+
* Text Search (CMD + F, CTRL + F)
|
23 |
+
* Individual Settings for Each Editor
|
24 |
+
* FancyBox for image viewing
|
25 |
+
* AJAX File Browser
|
26 |
+
* Allowed Extensions List
|
27 |
+
* Easy to use Settings Section
|
28 |
+
|
29 |
+
== Installation ==
|
30 |
+
|
31 |
+
1. Upload the `wp-editor.zip` to the `/wp-content/plugins/` directory
|
32 |
+
2. Activate the plugin through the 'Plugins' menu in WordPress
|
33 |
+
|
34 |
+
== Changelog ==
|
35 |
+
|
36 |
+
= 1.0.2 =
|
37 |
+
* Fixed invalid foreach statement for WP 3.4 in Theme editor
|
38 |
+
* Fixed invalid URL for images in root directory of themes
|
39 |
+
* Updated editor to keep line position when saving files
|
40 |
+
* Removed tab characters in all code and replaced with spaces
|
41 |
+
* Updated contextual help in the code editor pages
|
42 |
+
* Added ability to upload files in Theme/Plugin Editor
|
43 |
+
|
44 |
+
= 1.0.1 =
|
45 |
+
* Updated WP Editor to work with WordPress 3.4+
|
46 |
+
* Added HTML and HTM icons
|
47 |
+
|
48 |
+
= 1.0 BETA =
|
49 |
+
* Initial release of WP Editor
|
sql/database.sql
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
create table if not exists `[prefix]settings` (
|
2 |
+
`key` varchar(50) not null,
|
3 |
+
`value` text not null,
|
4 |
+
primary key(`key`)
|
5 |
+
);
|
sql/uninstall.sql
ADDED
@@ -0,0 +1 @@
|
|
|
1 |
+
drop table if exists `[prefix]settings`;
|
uninstall.php
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
if(!defined('ABSPATH') && !defined('WP_UNINSTALL_PLUGIN')) {
|
3 |
+
exit();
|
4 |
+
}
|
5 |
+
|
6 |
+
define('WPEDITOR_PATH', plugin_dir_path( __FILE__ )); // e.g. /var/www/example.com/wordpress/wp-content/plugins/wpeditor
|
7 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditor.php');
|
8 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditorSetting.php');
|
9 |
+
|
10 |
+
//if(WPEditorSetting::getValue('uninstall_db')) {
|
11 |
+
global $wpdb;
|
12 |
+
$prefix = WPEditor::getTablePrefix();
|
13 |
+
$sqlFile = WPEDITOR_PATH . 'sql/uninstall.sql';
|
14 |
+
$sql = str_replace('[prefix]', $prefix, file_get_contents($sqlFile));
|
15 |
+
$queries = explode(";\n", $sql);
|
16 |
+
foreach($queries as $sql) {
|
17 |
+
if(strlen($sql) > 5) {
|
18 |
+
$wpdb->query($sql);
|
19 |
+
}
|
20 |
+
}
|
21 |
+
//}
|
views/plugin-editor.php
ADDED
@@ -0,0 +1,225 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="save-result"></div>
|
2 |
+
<div class="wrap">
|
3 |
+
<?php screen_icon(); ?>
|
4 |
+
<h2><?php _e('Edit Plugins', 'wpeditor'); ?></h2>
|
5 |
+
<?php if(in_array($data['file'], (array) get_option('active_plugins', array()))) { ?>
|
6 |
+
<div class="updated">
|
7 |
+
<p><?php _e('<strong>This plugin is currently activated!<br />Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.', 'wpeditor'); ?></p>
|
8 |
+
</div>
|
9 |
+
<?php } ?>
|
10 |
+
<div class="fileedit-sub">
|
11 |
+
<div class="alignleft">
|
12 |
+
<h3>
|
13 |
+
<?php
|
14 |
+
if(is_plugin_active($data['plugin'])) {
|
15 |
+
if(is_writeable($data['real_file'])) {
|
16 |
+
echo __('Editing <span class="current_file">', 'wpeditor') . $data['file'] . __('</span> (active)', 'wpeditor');
|
17 |
+
}
|
18 |
+
else {
|
19 |
+
echo __('Browsing <span class="current_file">', 'wpeditor') . $data['file'] . __('</span> (active)', 'wpeditor');
|
20 |
+
}
|
21 |
+
} else {
|
22 |
+
if (is_writeable($data['real_file'])) {
|
23 |
+
echo __('Editing <span class="current_file">', 'wpeditor') . $data['file'] . __('</span> (inactive)', 'wpeditor');
|
24 |
+
}
|
25 |
+
else {
|
26 |
+
echo __('Browsing <span class="current_file">', 'wpeditor') . $data['file'] . __('</span> (inactive)', 'wpeditor');
|
27 |
+
}
|
28 |
+
}
|
29 |
+
?>
|
30 |
+
</h3>
|
31 |
+
</div>
|
32 |
+
<div class="alignright">
|
33 |
+
<form action="plugins.php?page=wpeditor_plugin" method="post">
|
34 |
+
<strong><label for="plugin"><?php _e('Select plugin to edit:', 'wpeditor'); ?></label></strong>
|
35 |
+
<select name="plugin" id="plugin">
|
36 |
+
<?php
|
37 |
+
foreach($data['plugins'] as $plugin_key => $a_plugin) {
|
38 |
+
$plugin_name = $a_plugin['Name'];
|
39 |
+
if($plugin_key == $data['plugin']) {
|
40 |
+
$selected = ' selected="selected"';
|
41 |
+
}
|
42 |
+
else {
|
43 |
+
$selected = '';
|
44 |
+
}
|
45 |
+
$plugin_name = esc_attr($plugin_name);
|
46 |
+
$plugin_key = esc_attr($plugin_key); ?>
|
47 |
+
<option value="<?php echo $plugin_key; ?>" <?php echo $selected; ?>><?php echo $plugin_name; ?></option>
|
48 |
+
<?php
|
49 |
+
}
|
50 |
+
?>
|
51 |
+
</select>
|
52 |
+
<input type='submit' name='submit' class="button-secondary" value="<?php _e('Select', 'wpeditor'); ?>" />
|
53 |
+
</form>
|
54 |
+
</div>
|
55 |
+
<br class="clear" />
|
56 |
+
</div>
|
57 |
+
|
58 |
+
<div id="templateside">
|
59 |
+
<?php if(WPEditorSetting::getValue('plugin_file_upload')): ?>
|
60 |
+
<h3><?php _e('Upload Files', 'wpeditor'); ?></h3>
|
61 |
+
<div id="plugin-upload-files">
|
62 |
+
<?php if(is_writeable($data['real_file'])): ?>
|
63 |
+
<form enctype="multipart/form-data" id="plugin_upload_form" method="POST">
|
64 |
+
<!-- MAX_FILE_SIZE must precede the file input field -->
|
65 |
+
<!--input type="hidden" name="MAX_FILE_SIZE" value="30000" /-->
|
66 |
+
<p class="description">
|
67 |
+
<?php _e('To', 'wpeditor'); ?>: <?php echo basename(dirname($data['current_plugin_root'])) . '/' . basename($data['current_plugin_root']) . '/'; ?>
|
68 |
+
</p>
|
69 |
+
<input type="hidden" name="current_plugin_root" value="<?php echo $data['current_plugin_root']; ?>" id="current_plugin_root" />
|
70 |
+
<input type="text" name="directory" id="file_directory" style="width:190px" placeholder="<?php _e('Optional: Sub-Directory', 'wpeditor'); ?>" />
|
71 |
+
<!-- Name of input element determines name in $_FILES array -->
|
72 |
+
<input name="file" type="file" id="file" style="width:180px" />
|
73 |
+
<div class="ajax-button-loader">
|
74 |
+
<?php submit_button(__('Upload File', 'wpeditor'), 'primary', 'submit', false); ?>
|
75 |
+
<div class="ajax-loader"></div>
|
76 |
+
</div>
|
77 |
+
</form>
|
78 |
+
<?php else: ?>
|
79 |
+
<p>
|
80 |
+
<em><?php _e('You need to make this folder writable before you can upload any files. See <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">the Codex</a> for more information.'); ?></em>
|
81 |
+
</p>
|
82 |
+
<?php endif; ?>
|
83 |
+
</div>
|
84 |
+
<div id="upload_message"></div>
|
85 |
+
<?php endif; ?>
|
86 |
+
|
87 |
+
<h3><?php _e('Plugin Files', 'wpeditor'); ?></h3>
|
88 |
+
<div id="plugin-editor-files">
|
89 |
+
<ul id="plugin-folders" class="plugin-folders"></ul>
|
90 |
+
</div>
|
91 |
+
</div>
|
92 |
+
|
93 |
+
<form name="template" id="template_form" action="" method="post" class="ajax-editor-update">
|
94 |
+
<?php wp_nonce_field('edit-plugin_' . $data['real_file']); ?>
|
95 |
+
<div>
|
96 |
+
<textarea cols="70" rows="25" name="new-content" id="new-content" tabindex="1"><?php echo $data['content'] ?></textarea>
|
97 |
+
<input type="hidden" name="action" value="save_files" />
|
98 |
+
<input type="hidden" name="_success" id="_success" value="<?php _e('The file has been updated successfully.', 'wpeditor'); ?>" />
|
99 |
+
<input type="hidden" id="file" name="file" value="<?php echo esc_attr($data['file']); ?>" />
|
100 |
+
<input type="hidden" id="plugin-dirname" name="plugin" value="<?php echo esc_attr($data['plugin']); ?>" />
|
101 |
+
<input type="hidden" id="path" name="path" value="<?php echo esc_attr($data['real_file']); ?>" />
|
102 |
+
<input type="hidden" name="scroll_to" id="scroll_to" value="<?php echo $data['scroll_to']; ?>" />
|
103 |
+
<input type="hidden" name="content-type" id="content-type" value="<?php echo $data['content-type']; ?>" />
|
104 |
+
<?php
|
105 |
+
$pathinfo = pathinfo($data['plugin']);
|
106 |
+
?>
|
107 |
+
<input type="hidden" name="extension" id="extension" value="<?php echo $pathinfo['extension']; ?>" />
|
108 |
+
</div>
|
109 |
+
<?php if(is_writeable($data['real_file'])): ?>
|
110 |
+
<p class="submit">
|
111 |
+
<?php
|
112 |
+
if(isset($_GET['phperror'])) {
|
113 |
+
echo '<input type="hidden" name="phperror" value="1" />'; ?>
|
114 |
+
<input type="submit" name="submit" class="button-primary" value="<?php _e('Update File and Attempt to Reactivate', 'wpeditor'); ?>" />
|
115 |
+
<?php } else { ?>
|
116 |
+
<input type="submit" name='submit' class="button-primary" value="<?php _e('Update File', 'wpeditor'); ?>" />
|
117 |
+
<?php
|
118 |
+
}
|
119 |
+
?>
|
120 |
+
</p>
|
121 |
+
<?php else: ?>
|
122 |
+
<p>
|
123 |
+
<em><?php _e('You need to make this file writable before you can save your changes. See <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">the Codex</a> for more information.'); ?></em>
|
124 |
+
</p>
|
125 |
+
<?php endif; ?>
|
126 |
+
</form>
|
127 |
+
<script type="text/javascript">
|
128 |
+
(function($){
|
129 |
+
$(document).ready(function(){
|
130 |
+
$('#template_form').submit(function(){
|
131 |
+
$('#scroll-to').val( $('#new-content').scrollTop() );
|
132 |
+
});
|
133 |
+
$('#new-content').scrollTop($('#scroll-to').val());
|
134 |
+
enablePluginAjaxBrowser('<?php echo urlencode((WPWINDOWS) ? str_replace("/", "\\", $data["real_file"]) : $data["real_file"]); ?>');
|
135 |
+
runCodeMirror('<?php echo $pathinfo["extension"]; ?>');
|
136 |
+
$('.ajax-loader').hide();
|
137 |
+
$('#plugin_upload_form').submit(function() {
|
138 |
+
$('.ajax-loader').show();
|
139 |
+
var directory = $('#file_directory').val();
|
140 |
+
var current_plugin_root = $('#current_plugin_root').val();
|
141 |
+
var data = new FormData();
|
142 |
+
$.each($('input[type=file]')[0].files, function(i, file) {
|
143 |
+
data.append('file-'+i, file);
|
144 |
+
});
|
145 |
+
data.append('action', 'upload_files');
|
146 |
+
data.append('current_plugin_root', current_plugin_root);
|
147 |
+
data.append('directory', directory);
|
148 |
+
$.ajax({
|
149 |
+
type: "POST",
|
150 |
+
url: ajaxurl,
|
151 |
+
data: data,
|
152 |
+
contentType: false,
|
153 |
+
processData: false,
|
154 |
+
dataType: 'json',
|
155 |
+
success: function(result) {
|
156 |
+
if(result.error[0] === 0) {
|
157 |
+
enablePluginAjaxBrowser('<?php echo urlencode((WPWINDOWS) ? str_replace("/", "\\", $data["real_file"]) : $data["real_file"]); ?>');
|
158 |
+
$('#upload_message').html('<p class="WPEditorAjaxSuccess" style="padding:5px;">' + result.success + '</p>');
|
159 |
+
}
|
160 |
+
if(result.error[0] === -2) {
|
161 |
+
$('#upload_message').html('<p class="WPEditorAjaxError" style="padding:5px;">' + result.error[1] + '</p>');
|
162 |
+
}
|
163 |
+
else if(result.error[0] === -1) {
|
164 |
+
$('#upload_message').html('<p class="WPEditorAjaxError" style="padding:5px;">' + result.error[1] + '</p>');
|
165 |
+
}
|
166 |
+
$('.ajax-loader').hide();
|
167 |
+
}
|
168 |
+
});
|
169 |
+
return false;
|
170 |
+
});
|
171 |
+
})
|
172 |
+
})(jQuery);
|
173 |
+
function runCodeMirror(extension) {
|
174 |
+
if(extension === 'php') {
|
175 |
+
var mode = 'application/x-httpd-php';
|
176 |
+
}
|
177 |
+
else if(extension === 'css') {
|
178 |
+
var mode = 'css';
|
179 |
+
}
|
180 |
+
else if(extension === 'js') {
|
181 |
+
var mode = 'javascript';
|
182 |
+
}
|
183 |
+
else if(extension === 'html' || extension === 'htm') {
|
184 |
+
var mode = 'text/html';
|
185 |
+
}
|
186 |
+
else if(extension === 'xml') {
|
187 |
+
var mode = 'application/xml';
|
188 |
+
}
|
189 |
+
<?php
|
190 |
+
if(WPEditorSetting::getValue('plugin_editor_theme')) { ?>
|
191 |
+
var theme = '<?php echo WPEditorSetting::getValue("plugin_editor_theme"); ?>';
|
192 |
+
<?php }
|
193 |
+
else { ?>
|
194 |
+
var theme = 'default';
|
195 |
+
<?php }
|
196 |
+
if(WPEditorSetting::getValue('enable_plugin_active_line')) { ?>
|
197 |
+
var activeLine = 'activeline-' + theme;
|
198 |
+
<?php } ?>
|
199 |
+
editor = CodeMirror.fromTextArea(document.getElementById('new-content'), {
|
200 |
+
mode: mode,
|
201 |
+
theme: theme,
|
202 |
+
<?php
|
203 |
+
if(WPEditorSetting::getValue('enable_plugin_line_numbers')) { ?>
|
204 |
+
lineNumbers: true,
|
205 |
+
<?php } ?>
|
206 |
+
lineWrapping: true, // set line wrapping here
|
207 |
+
onCursorActivity: function() {
|
208 |
+
editor.setLineClass(hlLine, null);
|
209 |
+
hlLine = editor.setLineClass(editor.getCursor().line, activeLine);
|
210 |
+
},
|
211 |
+
onChange: function() {
|
212 |
+
changeTrue();
|
213 |
+
},
|
214 |
+
extraKeys: {
|
215 |
+
'F11': toggleFullscreenEditing,
|
216 |
+
'Esc': toggleFullscreenEditing
|
217 |
+
} // set fullscreen options here
|
218 |
+
});
|
219 |
+
var hlLine = editor.setLineClass(0, activeLine);
|
220 |
+
}
|
221 |
+
</script>
|
222 |
+
</div>
|
223 |
+
<div class="alignright">
|
224 |
+
</div>
|
225 |
+
<br class="clear" />
|
views/settings.php
ADDED
@@ -0,0 +1,542 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
$tab = 'overview';
|
3 |
+
if(WPEditorSetting::getValue('settings_tab')) {
|
4 |
+
$tab = WPEditorSetting::getValue('settings_tab');
|
5 |
+
}
|
6 |
+
if(!WPEditorSetting::getValue('run_overview')) {
|
7 |
+
$tab = 'overview';
|
8 |
+
}
|
9 |
+
WPEditorSetting::setValue('run_overview', 1);
|
10 |
+
$success_message = '';
|
11 |
+
?>
|
12 |
+
|
13 |
+
<div class="wrap">
|
14 |
+
<div id="icon-wpeditor" class="icon32"></div>
|
15 |
+
<h2><?php _e('WP Editor Settings', 'wpeditor'); ?></h2>
|
16 |
+
<div id="settings-main">
|
17 |
+
<div id="settings-main-wrap">
|
18 |
+
<div id="settings-back"></div>
|
19 |
+
<div id="save-result"></div>
|
20 |
+
<div id="settings-columns">
|
21 |
+
<div class="settings-tabs">
|
22 |
+
<ul>
|
23 |
+
<li id="settings-main-settings-tab"><a id="settings-link-main-settings" href="javascript:void(0)"><?php _e('Main Settings', 'wpeditor'); ?></a></li>
|
24 |
+
<li id="settings-themes-tab"><a id="settings-link-themes" href="javascript:void(0)"><?php _e('Theme Editor', 'wpeditor'); ?></a></li>
|
25 |
+
<li id="settings-plugins-tab"><a id="settings-link-plugins" href="javascript:void(0)"><?php _e('Plugin Editor', 'wpeditor'); ?></a></li>
|
26 |
+
<li id="settings-overview-tab"><a id="settings-link-overview" href="javascript:void(0)"><?php _e('Overview', 'wpeditor'); ?></a></li>
|
27 |
+
</ul>
|
28 |
+
</div>
|
29 |
+
<div id="settings-loading">
|
30 |
+
<h2><?php _e('loading...', 'wpeditor'); ?></h2>
|
31 |
+
</div>
|
32 |
+
<div id="settings-main-settings" class="settings-body">
|
33 |
+
<form action="" method="post" class="ajax-settings-form" id="settings-form">
|
34 |
+
<input type="hidden" name="action" value="save_wpeditor_settings" />
|
35 |
+
<input type="hidden" name="_success" value="Your main settings have been saved." />
|
36 |
+
<input type="hidden" name="_tab" value="main-settings" />
|
37 |
+
<div id="replace-plugin-edit-links" class="section">
|
38 |
+
<div class="section-header">
|
39 |
+
<h3><?php _e('Plugin Edit Links', 'wpeditor'); ?></h3>
|
40 |
+
</div>
|
41 |
+
<div class="section-body">
|
42 |
+
<ul>
|
43 |
+
<li>
|
44 |
+
<label for="replace_plugin_edit_links"><?php _e('Replace Default Plugin Edit Links:', 'wpeditor'); ?></label>
|
45 |
+
</li>
|
46 |
+
<li class="indent">
|
47 |
+
<input type="radio" name="replace_plugin_edit_links" value="1" <?php echo (WPEditorSetting::getValue('replace_plugin_edit_links') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
48 |
+
<input type="radio" name="replace_plugin_edit_links" value="0" <?php echo (WPEditorSetting::getValue('replace_plugin_edit_links') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
49 |
+
</li>
|
50 |
+
<li class="indent description">
|
51 |
+
<p><?php _e("This will replace the default edit links on the Installed Plugins page with WP Editor links.<br />Default: Yes", 'wpeditor'); ?></p>
|
52 |
+
</li>
|
53 |
+
</ul>
|
54 |
+
</div>
|
55 |
+
</div>
|
56 |
+
<div id="hide-default-editors" class="section">
|
57 |
+
<div class="section-header">
|
58 |
+
<h3><?php _e('Hide Default Editors', 'wpeditor'); ?></h3>
|
59 |
+
</div>
|
60 |
+
<div class="section-body">
|
61 |
+
<ul>
|
62 |
+
<li>
|
63 |
+
<label for="hide_default_plugin_editor"><?php _e('Hide Default Plugin Editor:', 'wpeditor'); ?></label>
|
64 |
+
</li>
|
65 |
+
<li class="indent">
|
66 |
+
<input type="radio" name="hide_default_plugin_editor" value="1" <?php echo (WPEditorSetting::getValue('hide_default_plugin_editor') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
67 |
+
<input type="radio" name="hide_default_plugin_editor" value="0" <?php echo (WPEditorSetting::getValue('hide_default_plugin_editor') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
68 |
+
</li>
|
69 |
+
<li class="indent description">
|
70 |
+
<p><?php _e("This will hide the default Edit submenu for the plugins page.<br />Default: Yes", 'wpeditor'); ?></p>
|
71 |
+
</li>
|
72 |
+
<li>
|
73 |
+
<label for="hide_default_theme_editor"><?php _e('Hide Default Theme Editor:', 'wpeditor'); ?></label>
|
74 |
+
</li>
|
75 |
+
<li class="indent">
|
76 |
+
<input type="radio" name="hide_default_theme_editor" value="1" <?php echo (WPEditorSetting::getValue('hide_default_theme_editor') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
77 |
+
<input type="radio" name="hide_default_theme_editor" value="0" <?php echo (WPEditorSetting::getValue('hide_default_theme_editor') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
78 |
+
</li>
|
79 |
+
<li class="indent description">
|
80 |
+
<p><?php _e("This will hide the default Edit submenu for the themes page.<br />Default: Yes", 'wpeditor'); ?></p>
|
81 |
+
</li>
|
82 |
+
</ul>
|
83 |
+
</div>
|
84 |
+
</div>
|
85 |
+
<div id="logging" class="section">
|
86 |
+
<div class="section-header">
|
87 |
+
<h3><?php _e('Logging', 'wpeditor'); ?></h3>
|
88 |
+
</div>
|
89 |
+
<div class="section-body">
|
90 |
+
<ul>
|
91 |
+
<li>
|
92 |
+
<label for="wpeditor_logging"><?php _e('Enable Logging:', 'wpeditor'); ?></label>
|
93 |
+
</li>
|
94 |
+
<li class="indent">
|
95 |
+
<input type="radio" name="wpeditor_logging" value="1" <?php echo (WPEditorSetting::getValue('wpeditor_logging') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
96 |
+
<input type="radio" name="wpeditor_logging" value="0" <?php echo (WPEditorSetting::getValue('wpeditor_logging') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
97 |
+
</li>
|
98 |
+
<li class="indent description">
|
99 |
+
<p><?php _e("This will enable diagnostic logging on the site. WARNING: This file grows quickly so please only enable if you are troubleshooting.<br />Default: No", 'wpeditor'); ?></p>
|
100 |
+
</li>
|
101 |
+
</ul>
|
102 |
+
</div>
|
103 |
+
</div>
|
104 |
+
<div id="save-settings">
|
105 |
+
<ul>
|
106 |
+
<li>
|
107 |
+
<input type='submit' name='submit' class="button-primary" value="<?php _e('Save Settings', 'wpeditor'); ?>" />
|
108 |
+
</li>
|
109 |
+
</ul>
|
110 |
+
</div>
|
111 |
+
</form>
|
112 |
+
</div>
|
113 |
+
<div id="settings-themes" class="settings-body">
|
114 |
+
<form action="" method="post" class="ajax-settings-form" id="theme-settings-form">
|
115 |
+
<input type="hidden" name="action" value="save_wpeditor_settings" />
|
116 |
+
<input type="hidden" name="_success" value="Your theme settings have been saved." />
|
117 |
+
<input type="hidden" name="_tab" value="themes" />
|
118 |
+
<div id="theme-editor-theme" class="section">
|
119 |
+
<div class="section-header">
|
120 |
+
<h3><?php _e('Editor Theme', 'wpeditor'); ?></h3>
|
121 |
+
</div>
|
122 |
+
<div class="section-body">
|
123 |
+
<ul>
|
124 |
+
<li>
|
125 |
+
<label for="theme_editor_theme"><?php _e('Theme:', 'wpeditor'); ?></label>
|
126 |
+
<select id="theme_editor_theme" name="theme_editor_theme">
|
127 |
+
<?php
|
128 |
+
$theme = 'default';
|
129 |
+
if(WPEditorSetting::getValue('theme_editor_theme')) {
|
130 |
+
$theme = WPEditorSetting::getValue('theme_editor_theme');
|
131 |
+
}
|
132 |
+
?>
|
133 |
+
<option value="default" <?php echo ($theme == 'default') ? 'selected="selected"' : '' ?>><?php _e('Default', 'wpeditor'); ?></option>
|
134 |
+
<option value="cobalt" <?php echo ($theme == 'cobalt') ? 'selected="selected"' : '' ?>><?php _e('Cobalt', 'wpeditor'); ?></option>
|
135 |
+
<option value="eclipse" <?php echo ($theme == 'eclipse') ? 'selected="selected"' : '' ?>><?php _e('Eclipse', 'wpeditor'); ?></option>
|
136 |
+
<option value="elegant" <?php echo ($theme == 'elegant') ? 'selected="selected"' : '' ?>><?php _e('Elegant', 'wpeditor'); ?></option>
|
137 |
+
<option value="monokai" <?php echo ($theme == 'monokai') ? 'selected="selected"' : '' ?>><?php _e('Monokai', 'wpeditor'); ?></option>
|
138 |
+
<option value="neat" <?php echo ($theme == 'neat') ? 'selected="selected"' : '' ?>><?php _e('Neat', 'wpeditor'); ?></option>
|
139 |
+
<option value="night" <?php echo ($theme == 'night') ? 'selected="selected"' : '' ?>><?php _e('Night', 'wpeditor'); ?></option>
|
140 |
+
<option value="rubyblue" <?php echo ($theme == 'rubyblue') ? 'selected="selected"' : '' ?>><?php _e('Ruby Blue', 'wpeditor'); ?></option>
|
141 |
+
</select>
|
142 |
+
</li>
|
143 |
+
<li class="indent description">
|
144 |
+
<p><?php _e("This allows you to select the theme for the theme editor.<br />Default: Default", 'wpeditor'); ?></p>
|
145 |
+
</li>
|
146 |
+
</ul>
|
147 |
+
</div>
|
148 |
+
</div>
|
149 |
+
<div id="theme-editor-extensions" class="section">
|
150 |
+
<div class="section-header">
|
151 |
+
<h3><?php _e('Extensions', 'wpeditor'); ?></h3>
|
152 |
+
</div>
|
153 |
+
<div class="section-body">
|
154 |
+
<ul>
|
155 |
+
<li>
|
156 |
+
<label for="theme_editor_allowed_extensions"><?php _e('Allowed Extensions:', 'wpeditor'); ?></label>
|
157 |
+
</li>
|
158 |
+
<li class="indent">
|
159 |
+
<?php
|
160 |
+
$allowed_extensions = WPEditorSetting::getValue('theme_editor_allowed_extensions');
|
161 |
+
if($allowed_extensions) {
|
162 |
+
$allowed_extensions = explode('~', $allowed_extensions);
|
163 |
+
}
|
164 |
+
else {
|
165 |
+
$allowed_extensions = array();
|
166 |
+
}
|
167 |
+
?>
|
168 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="php" <?php echo in_array('php', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
169 |
+
<label class="checkbox_label"><?php _e('.php', 'wpeditor'); ?></label>
|
170 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="js" <?php echo in_array('js', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
171 |
+
<label class="checkbox_label"><?php _e('.js', 'wpeditor'); ?></label>
|
172 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="css" <?php echo in_array('css', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
173 |
+
<label class="checkbox_label"><?php _e('.css', 'wpeditor'); ?></label>
|
174 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="txt" <?php echo in_array('txt', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
175 |
+
<label class="checkbox_label"><?php _e('.txt', 'wpeditor'); ?></label>
|
176 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="htm" <?php echo in_array('htm', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
177 |
+
<label class="checkbox_label"><?php _e('.htm', 'wpeditor'); ?></label>
|
178 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="html" <?php echo in_array('html', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
179 |
+
<label class="checkbox_label"><?php _e('.html', 'wpeditor'); ?></label>
|
180 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="jpg" <?php echo in_array('jpg', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
181 |
+
<label class="checkbox_label"><?php _e('.jpg', 'wpeditor'); ?></label>
|
182 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="jpeg" <?php echo in_array('jpeg', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
183 |
+
<label class="checkbox_label"><?php _e('.jpeg', 'wpeditor'); ?></label>
|
184 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="png" <?php echo in_array('png', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
185 |
+
<label class="checkbox_label"><?php _e('.png', 'wpeditor'); ?></label>
|
186 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="gif" <?php echo in_array('gif', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
187 |
+
<label class="checkbox_label"><?php _e('.gif', 'wpeditor'); ?></label>
|
188 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="sql" <?php echo in_array('sql', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
189 |
+
<label class="checkbox_label"><?php _e('.sql', 'wpeditor'); ?></label>
|
190 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="po" <?php echo in_array('po', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
191 |
+
<label class="checkbox_label"><?php _e('.po', 'wpeditor'); ?></label>
|
192 |
+
<input type="checkbox" name="theme_editor_allowed_extensions[]" value="pot" <?php echo in_array('pot', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
193 |
+
<label class="checkbox_label"><?php _e('.pot', 'wpeditor'); ?></label>
|
194 |
+
</li>
|
195 |
+
<li class="indent description">
|
196 |
+
<p><?php _e('Select which extensions you would like the theme editor browser to be able to access.', 'wpeditor'); ?></p>
|
197 |
+
</li>
|
198 |
+
</ul>
|
199 |
+
</div>
|
200 |
+
</div>
|
201 |
+
<div id="enable-theme-line-numbers" class="section">
|
202 |
+
<div class="section-header">
|
203 |
+
<h3><?php _e('Line Numbers', 'wpeditor'); ?></h3>
|
204 |
+
</div>
|
205 |
+
<div class="section-body">
|
206 |
+
<ul>
|
207 |
+
<li>
|
208 |
+
<label for="enable_theme_line_numbers"><?php _e('Enable Line Numbers:', 'wpeditor'); ?></label>
|
209 |
+
</li>
|
210 |
+
<li class="indent">
|
211 |
+
<input type="radio" name="enable_theme_line_numbers" value="1" <?php echo (WPEditorSetting::getValue('enable_theme_line_numbers') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
212 |
+
<input type="radio" name="enable_theme_line_numbers" value="0" <?php echo (WPEditorSetting::getValue('enable_theme_line_numbers') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
213 |
+
</li>
|
214 |
+
<li class="indent description">
|
215 |
+
<p><?php _e("This will enable line numbers for the theme editor.<br />Default: Yes", 'wpeditor'); ?></p>
|
216 |
+
</li>
|
217 |
+
</ul>
|
218 |
+
</div>
|
219 |
+
</div>
|
220 |
+
<div id="enable-theme-line-wrapping" class="section">
|
221 |
+
<div class="section-header">
|
222 |
+
<h3><?php _e('Line Wrapping', 'wpeditor'); ?></h3>
|
223 |
+
</div>
|
224 |
+
<div class="section-body">
|
225 |
+
<ul>
|
226 |
+
<li>
|
227 |
+
<label for="enable_theme_line_wrapping"><?php _e('Enable Line Wrapping:', 'wpeditor'); ?></label>
|
228 |
+
</li>
|
229 |
+
<li class="indent">
|
230 |
+
<input type="radio" name="enable_theme_line_wrapping" value="1" <?php echo (WPEditorSetting::getValue('enable_theme_line_wrapping') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
231 |
+
<input type="radio" name="enable_theme_line_wrapping" value="0" <?php echo (WPEditorSetting::getValue('enable_theme_line_wrapping') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
232 |
+
</li>
|
233 |
+
<li class="indent description">
|
234 |
+
<p><?php _e("This will enable line wrapping for the theme editor.<br />Default: Yes", 'wpeditor'); ?></p>
|
235 |
+
</li>
|
236 |
+
</ul>
|
237 |
+
</div>
|
238 |
+
</div>
|
239 |
+
<div id="enable-theme-active-line" class="section">
|
240 |
+
<div class="section-header">
|
241 |
+
<h3><?php _e('Active Line Highlighting', 'wpeditor'); ?></h3>
|
242 |
+
</div>
|
243 |
+
<div class="section-body">
|
244 |
+
<ul>
|
245 |
+
<li>
|
246 |
+
<label for="enable_theme_active_line"><?php _e('Highlight Active Line:', 'wpeditor'); ?></label>
|
247 |
+
</li>
|
248 |
+
<li class="indent">
|
249 |
+
<input type="radio" name="enable_theme_active_line" value="1" <?php echo (WPEditorSetting::getValue('enable_theme_active_line') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
250 |
+
<input type="radio" name="enable_theme_active_line" value="0" <?php echo (WPEditorSetting::getValue('enable_theme_active_line') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
251 |
+
</li>
|
252 |
+
<li class="indent description">
|
253 |
+
<p><?php _e("This will enable highlighting of the active line for the theme editor.<br />Default: Yes", 'wpeditor'); ?></p>
|
254 |
+
</li>
|
255 |
+
</ul>
|
256 |
+
</div>
|
257 |
+
</div>
|
258 |
+
<div id="enable-theme-file-upload" class="section">
|
259 |
+
<div class="section-header">
|
260 |
+
<h3><?php _e('File Upload', 'wpeditor'); ?></h3>
|
261 |
+
</div>
|
262 |
+
<div class="section-body">
|
263 |
+
<ul>
|
264 |
+
<li>
|
265 |
+
<label for="theme_file_upload"><?php _e('Enable File Upload:', 'wpeditor'); ?></label>
|
266 |
+
</li>
|
267 |
+
<li class="indent">
|
268 |
+
<input type="radio" name="theme_file_upload" value="1" <?php echo (WPEditorSetting::getValue('theme_file_upload') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
269 |
+
<input type="radio" name="theme_file_upload" value="0" <?php echo (WPEditorSetting::getValue('theme_file_upload') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
270 |
+
</li>
|
271 |
+
<li class="indent description">
|
272 |
+
<p><?php _e("This will enable a file upload option for the theme editor.<br />Default: Yes", 'wpeditor'); ?></p>
|
273 |
+
</li>
|
274 |
+
</ul>
|
275 |
+
</div>
|
276 |
+
</div>
|
277 |
+
<div id="save-settings">
|
278 |
+
<ul>
|
279 |
+
<li>
|
280 |
+
<input type='submit' name='submit' class="button-primary" value="<?php _e('Save Settings', 'wpeditor'); ?>" />
|
281 |
+
</li>
|
282 |
+
</ul>
|
283 |
+
</div>
|
284 |
+
</form>
|
285 |
+
</div>
|
286 |
+
<div id="settings-plugins" class="settings-body">
|
287 |
+
<form action="" method="post" class="ajax-settings-form" id="plugin-settings-form">
|
288 |
+
<input type="hidden" name="action" value="save_wpeditor_settings" />
|
289 |
+
<input type="hidden" name="_success" value="Your plugin settings have been saved." />
|
290 |
+
<input type="hidden" name="_tab" value="plugins" />
|
291 |
+
<div id="plugin-editor-theme" class="section">
|
292 |
+
<div class="section-header">
|
293 |
+
<h3><?php _e('Editor Theme', 'wpeditor'); ?></h3>
|
294 |
+
</div>
|
295 |
+
<div class="section-body">
|
296 |
+
<ul>
|
297 |
+
<li>
|
298 |
+
<label for="plugin_editor_theme"><?php _e('Theme:', 'wpeditor'); ?></label>
|
299 |
+
<select id="plugin_editor_theme" name="plugin_editor_theme">
|
300 |
+
<?php
|
301 |
+
$theme = 'default';
|
302 |
+
if(WPEditorSetting::getValue('plugin_editor_theme')) {
|
303 |
+
$theme = WPEditorSetting::getValue('plugin_editor_theme');
|
304 |
+
}
|
305 |
+
?>
|
306 |
+
<option value="default" <?php echo ($theme == 'default') ? 'selected="selected"' : '' ?>><?php _e('Default', 'wpeditor'); ?></option>
|
307 |
+
<option value="cobalt" <?php echo ($theme == 'cobalt') ? 'selected="selected"' : '' ?>><?php _e('Cobalt', 'wpeditor'); ?></option>
|
308 |
+
<option value="eclipse" <?php echo ($theme == 'eclipse') ? 'selected="selected"' : '' ?>><?php _e('Eclipse', 'wpeditor'); ?></option>
|
309 |
+
<option value="elegant" <?php echo ($theme == 'elegant') ? 'selected="selected"' : '' ?>><?php _e('Elegant', 'wpeditor'); ?></option>
|
310 |
+
<option value="monokai" <?php echo ($theme == 'monokai') ? 'selected="selected"' : '' ?>><?php _e('Monokai', 'wpeditor'); ?></option>
|
311 |
+
<option value="neat" <?php echo ($theme == 'neat') ? 'selected="selected"' : '' ?>><?php _e('Neat', 'wpeditor'); ?></option>
|
312 |
+
<option value="night" <?php echo ($theme == 'night') ? 'selected="selected"' : '' ?>><?php _e('Night', 'wpeditor'); ?></option>
|
313 |
+
<option value="rubyblue" <?php echo ($theme == 'rubyblue') ? 'selected="selected"' : '' ?>><?php _e('Ruby Blue', 'wpeditor'); ?></option>
|
314 |
+
</select>
|
315 |
+
</li>
|
316 |
+
<li class="indent description">
|
317 |
+
<p><?php _e("This allows you to select the theme for the plugin editor.<br />Default: Default", 'wpeditor'); ?></p>
|
318 |
+
</li>
|
319 |
+
</ul>
|
320 |
+
</div>
|
321 |
+
</div>
|
322 |
+
<div id="plugin-editor-extensions" class="section">
|
323 |
+
<div class="section-header">
|
324 |
+
<h3><?php _e('Extensions', 'wpeditor'); ?></h3>
|
325 |
+
</div>
|
326 |
+
<div class="section-body">
|
327 |
+
<ul>
|
328 |
+
<li>
|
329 |
+
<label for="plugin_editor_allowed_extensions"><?php _e('Allowed Extensions:', 'wpeditor'); ?></label>
|
330 |
+
</li>
|
331 |
+
<li class="indent">
|
332 |
+
<?php
|
333 |
+
$allowed_extensions = WPEditorSetting::getValue('plugin_editor_allowed_extensions');
|
334 |
+
if($allowed_extensions) {
|
335 |
+
$allowed_extensions = explode('~', $allowed_extensions);
|
336 |
+
}
|
337 |
+
else {
|
338 |
+
$allowed_extensions = array();
|
339 |
+
}
|
340 |
+
?>
|
341 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="php" <?php echo in_array('php', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
342 |
+
<label class="checkbox_label"><?php _e('.php', 'wpeditor'); ?></label>
|
343 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="js" <?php echo in_array('js', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
344 |
+
<label class="checkbox_label"><?php _e('.js', 'wpeditor'); ?></label>
|
345 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="css" <?php echo in_array('css', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
346 |
+
<label class="checkbox_label"><?php _e('.css', 'wpeditor'); ?></label>
|
347 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="txt" <?php echo in_array('txt', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
348 |
+
<label class="checkbox_label"><?php _e('.txt', 'wpeditor'); ?></label>
|
349 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="htm" <?php echo in_array('htm', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
350 |
+
<label class="checkbox_label"><?php _e('.htm', 'wpeditor'); ?></label>
|
351 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="html" <?php echo in_array('html', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
352 |
+
<label class="checkbox_label"><?php _e('.html', 'wpeditor'); ?></label>
|
353 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="jpg" <?php echo in_array('jpg', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
354 |
+
<label class="checkbox_label"><?php _e('.jpg', 'wpeditor'); ?></label>
|
355 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="jpeg" <?php echo in_array('jpeg', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
356 |
+
<label class="checkbox_label"><?php _e('.jpeg', 'wpeditor'); ?></label>
|
357 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="png" <?php echo in_array('png', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
358 |
+
<label class="checkbox_label"><?php _e('.png', 'wpeditor'); ?></label>
|
359 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="gif" <?php echo in_array('gif', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
360 |
+
<label class="checkbox_label"><?php _e('.gif', 'wpeditor'); ?></label>
|
361 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="sql" <?php echo in_array('sql', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
362 |
+
<label class="checkbox_label"><?php _e('.sql', 'wpeditor'); ?></label>
|
363 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="po" <?php echo in_array('po', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
364 |
+
<label class="checkbox_label"><?php _e('.po', 'wpeditor'); ?></label>
|
365 |
+
<input type="checkbox" name="plugin_editor_allowed_extensions[]" value="pot" <?php echo in_array('pot', $allowed_extensions) ? 'checked="checked"' : '' ?>>
|
366 |
+
<label class="checkbox_label"><?php _e('.pot', 'wpeditor'); ?></label>
|
367 |
+
</li>
|
368 |
+
<li class="indent description">
|
369 |
+
<p><?php _e('Select which extensions you would like the plugin editor browser to be able to access.', 'wpeditor'); ?></p>
|
370 |
+
</li>
|
371 |
+
</ul>
|
372 |
+
</div>
|
373 |
+
</div>
|
374 |
+
<div id="enable-plugin-line-numbers" class="section">
|
375 |
+
<div class="section-header">
|
376 |
+
<h3><?php _e('Line Numbers', 'wpeditor'); ?></h3>
|
377 |
+
</div>
|
378 |
+
<div class="section-body">
|
379 |
+
<ul>
|
380 |
+
<li>
|
381 |
+
<label for="enable_plugin_line_numbers"><?php _e('Enable Line Numbers:', 'wpeditor'); ?></label>
|
382 |
+
</li>
|
383 |
+
<li class="indent">
|
384 |
+
<input type="radio" name="enable_plugin_line_numbers" value="1" <?php echo (WPEditorSetting::getValue('enable_plugin_line_numbers') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
385 |
+
<input type="radio" name="enable_plugin_line_numbers" value="0" <?php echo (WPEditorSetting::getValue('enable_plugin_line_numbers') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
386 |
+
</li>
|
387 |
+
<li class="indent description">
|
388 |
+
<p><?php _e("This will enable line numbers for the plugin editor.<br />Default: Yes", 'wpeditor'); ?></p>
|
389 |
+
</li>
|
390 |
+
</ul>
|
391 |
+
</div>
|
392 |
+
</div>
|
393 |
+
<div id="enable-plugin-line-wrapping" class="section">
|
394 |
+
<div class="section-header">
|
395 |
+
<h3><?php _e('Line Wrapping', 'wpeditor'); ?></h3>
|
396 |
+
</div>
|
397 |
+
<div class="section-body">
|
398 |
+
<ul>
|
399 |
+
<li>
|
400 |
+
<label for="enable_plugin_line_wrapping"><?php _e('Enable Line Wrapping:', 'wpeditor'); ?></label>
|
401 |
+
</li>
|
402 |
+
<li class="indent">
|
403 |
+
<input type="radio" name="enable_plugin_line_wrapping" value="1" <?php echo (WPEditorSetting::getValue('enable_plugin_line_wrapping') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
404 |
+
<input type="radio" name="enable_plugin_line_wrapping" value="0" <?php echo (WPEditorSetting::getValue('enable_plugin_line_wrapping') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
405 |
+
</li>
|
406 |
+
<li class="indent description">
|
407 |
+
<p><?php _e("This will enable line wrapping for the plugin editor.<br />Default: Yes", 'wpeditor'); ?></p>
|
408 |
+
</li>
|
409 |
+
</ul>
|
410 |
+
</div>
|
411 |
+
</div>
|
412 |
+
<div id="enable-plugin-active-line" class="section">
|
413 |
+
<div class="section-header">
|
414 |
+
<h3><?php _e('Active Line Highlighting', 'wpeditor'); ?></h3>
|
415 |
+
</div>
|
416 |
+
<div class="section-body">
|
417 |
+
<ul>
|
418 |
+
<li>
|
419 |
+
<label for="enable_plugin_active_line"><?php _e('Highlight Active Line:', 'wpeditor'); ?></label>
|
420 |
+
</li>
|
421 |
+
<li class="indent">
|
422 |
+
<input type="radio" name="enable_plugin_active_line" value="1" <?php echo (WPEditorSetting::getValue('enable_plugin_active_line') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
423 |
+
<input type="radio" name="enable_plugin_active_line" value="0" <?php echo (WPEditorSetting::getValue('enable_plugin_active_line') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
424 |
+
</li>
|
425 |
+
<li class="indent description">
|
426 |
+
<p><?php _e("This will enable highlighting of the active line for the plugin editor.<br />Default: Yes", 'wpeditor'); ?></p>
|
427 |
+
</li>
|
428 |
+
</ul>
|
429 |
+
</div>
|
430 |
+
</div>
|
431 |
+
<div id="enable-plugin-file-upload" class="section">
|
432 |
+
<div class="section-header">
|
433 |
+
<h3><?php _e('File Upload', 'wpeditor'); ?></h3>
|
434 |
+
</div>
|
435 |
+
<div class="section-body">
|
436 |
+
<ul>
|
437 |
+
<li>
|
438 |
+
<label for="plugin_file_upload"><?php _e('Enable File Upload:', 'wpeditor'); ?></label>
|
439 |
+
</li>
|
440 |
+
<li class="indent">
|
441 |
+
<input type="radio" name="plugin_file_upload" value="1" <?php echo (WPEditorSetting::getValue('plugin_file_upload') == 1) ? 'checked="checked"' : ''; ?>> <?php _e('Yes', 'wpeditor'); ?>
|
442 |
+
<input type="radio" name="plugin_file_upload" value="0" <?php echo (WPEditorSetting::getValue('plugin_file_upload') != 1) ? 'checked="checked"' : ''; ?>> <?php _e('No', 'wpeditor'); ?>
|
443 |
+
</li>
|
444 |
+
<li class="indent description">
|
445 |
+
<p><?php _e("This will enable a file upload option for the plugin editor.<br />Default: Yes", 'wpeditor'); ?></p>
|
446 |
+
</li>
|
447 |
+
</ul>
|
448 |
+
</div>
|
449 |
+
</div>
|
450 |
+
<div id="save-settings">
|
451 |
+
<ul>
|
452 |
+
<li>
|
453 |
+
<input type='submit' name='submit' class="button-primary" value="<?php _e('Save Settings', 'wpeditor'); ?>" />
|
454 |
+
</li>
|
455 |
+
</ul>
|
456 |
+
</div>
|
457 |
+
</form>
|
458 |
+
</div>
|
459 |
+
<div id="settings-overview" class="settings-body">
|
460 |
+
<div id="wpeditor-overview" class="section">
|
461 |
+
<div class="section-header">
|
462 |
+
<h3><?php _e('WP Editor Overview', 'wpeditor'); ?></h3>
|
463 |
+
</div>
|
464 |
+
<div class="section-body">
|
465 |
+
<ul>
|
466 |
+
<li>
|
467 |
+
<p><strong><?php _e('What is WP Editor?', 'wpeditor'); ?></strong></p>
|
468 |
+
</li>
|
469 |
+
<li class="indent">
|
470 |
+
<p><?php _e('WP Editor is a plugin for WordPress that replaces the default plugin and theme editors. Using integrations with <a href="http://codemirror.net" target="_blank">CodeMirror</a> and <a href="http://fancybox.net" target="_blank">FancyBox</a> to create a feature rich environment, WP Editor completely reworks the default WordPress file editing capabilities. Using Asynchronous Javascript and XML (AJAX) to retrieve files and folders, WP Editor sets a new standard for speed and reliability in a web-based editing atmosphere.', 'wpeditor'); ?></p>
|
471 |
+
</li>
|
472 |
+
<li>
|
473 |
+
<br />
|
474 |
+
<p><strong><?php _e('Features', 'wpeditor'); ?></strong></p>
|
475 |
+
</li>
|
476 |
+
<li class="indent">
|
477 |
+
<ul class="normal_list">
|
478 |
+
<li><strong><a href="http://codemirror.net" target="_blank"><?php _e('CodeMirror', 'wpeditor'); ?></a></strong></li>
|
479 |
+
<ul class="normal_list">
|
480 |
+
<li><?php _e('Active Line Highlighting', 'wpeditor'); ?></li>
|
481 |
+
<li><?php _e('Line Numbers', 'wpeditor'); ?></li>
|
482 |
+
<li><?php _e('Line Wrapping', 'wpeditor'); ?></li>
|
483 |
+
<li><?php _e('Eight Editor Themes with Syntax Highlighting', 'wpeditor'); ?></li>
|
484 |
+
<li><?php _e('Fullscreen Editing (ESC, F11)', 'wpeditor'); ?></li>
|
485 |
+
<li><?php _e('Text Search (CMD + F, CTRL + F)', 'wpeditor'); ?></li>
|
486 |
+
<li><?php _e('Individual Settings for Each Editor', 'wpeditor'); ?></li>
|
487 |
+
</ul>
|
488 |
+
<li><<?php _e('strong><a href="http://fancybox.net" target="_blank">FancyBox</a> for image viewing', 'wpeditor'); ?></strong></li>
|
489 |
+
<li><strong><?php _e('AJAX File Browser', 'wpeditor'); ?></strong></li>
|
490 |
+
<li><strong><?php _e('Allowed Extensions List', 'wpeditor'); ?></strong></li>
|
491 |
+
<li><strong><?php _e('Easy to use Settings Section', 'wpeditor'); ?></strong></li>
|
492 |
+
</ul>
|
493 |
+
</li>
|
494 |
+
<li>
|
495 |
+
<br />
|
496 |
+
<p><strong><?php _e('The Future of WP Editor', 'wpeditor'); ?></strong></p>
|
497 |
+
</li>
|
498 |
+
<li class="indent">
|
499 |
+
<p><?php _e('WP Editor is brand new! This means that there is a lot more work that will be going into the plugin to make it better. Since it is currently in Beta mode, we would appreciate all the feedback you can give to make this a better product. Please visit <a href="http://wpeditor.net/beta">http://wpeditor.net/beta</a> to give feedback, request features or just to leave a comment for the developers. We would appreciate any input you can give!', 'wpeditor'); ?></p>
|
500 |
+
<p><?php _e('That being said, please be patient with us as we are working on this project in our spare time. While we hope that WP Editor can remain free, it does cost us to continue to develop and maintain it. If you feel so inclined, we would appreciate any donation that you might give to enable us to spend more time developing the plugin and keeping this great product up to date! Use the Donate button below to keep WP Editor free!', 'wpeditor'); ?></p>
|
501 |
+
<p>
|
502 |
+
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DCFRQLH3DMMS4" target="_blank" class="donate">Donate Today!</a>
|
503 |
+
</p>
|
504 |
+
</li>
|
505 |
+
<li>
|
506 |
+
<br />
|
507 |
+
<p><strong><?php _e('Support', 'wpeditor'); ?></strong></p>
|
508 |
+
</li>
|
509 |
+
<li class="indent">
|
510 |
+
<p><?php _e('Support for WP Editor is provided on a first-come, first-serve basis. You can however, get to the top of the queue by paying a per-incident fee based on what you feel your ticket is worth. The more you pay, the faster we will get to your ticket. Following are a few examples:', 'wpeditor'); ?></p>
|
511 |
+
<ul class="normal_list">
|
512 |
+
<li><?php _e('$1.00+ - We will answer your inquiry before we answer anyone who hasn\'t paid yet', 'wpeditor'); ?></li>
|
513 |
+
<li><?php _e('$5.00+ - We will answer your inquiry before the $1.00 inquiries', 'wpeditor'); ?></li>
|
514 |
+
<li><?php _e('$50.00+ - We will answer your inquiry within a 24 hour period', 'wpeditor'); ?></li>
|
515 |
+
<li><?php _e('$100.00+ - We will answer your inquiry within a 12 hour period', 'wpeditor'); ?></li>
|
516 |
+
<li><?php _e('$1000.00+ - We will stop what we are doing to answer your inquiry', 'wpeditor'); ?></li>
|
517 |
+
<li><?php _e('$100,000.00+ - We will consider quitting our day jobs to make sure your issue is resolved', 'wpeditor'); ?></li>
|
518 |
+
</ul>
|
519 |
+
<p><?php _e('To get support, please visit <a href="http://wpeditor.net/support" target="_blank">http://wpeditor.net/support</a>. If you want paid support, create your support request and then click on the button below to make a payment and put the text you entered in the "brief description" into the "Add special instructions to the seller" box of the payment form.', 'wpeditor'); ?></p>
|
520 |
+
<p>
|
521 |
+
<a href="https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=YEPC72BPT73PC" target="_blank" class="support">Pay for Support</a>
|
522 |
+
</p>
|
523 |
+
</li>
|
524 |
+
<li class="indent description">
|
525 |
+
<br />
|
526 |
+
<p><?php _e('To learn more, please visit <a href="http://wpeditor.net" target="_blank">http://wpeditor.net</a>', 'wpeditor'); ?></p>
|
527 |
+
</li>
|
528 |
+
</ul>
|
529 |
+
</div>
|
530 |
+
</div>
|
531 |
+
</div>
|
532 |
+
<br clear="both" />
|
533 |
+
</div>
|
534 |
+
</div>
|
535 |
+
</div>
|
536 |
+
<script type="text/javascript">
|
537 |
+
(function($){
|
538 |
+
$(document).ready(function(){
|
539 |
+
settingsTabs('<?php echo $tab; ?>');
|
540 |
+
})
|
541 |
+
})(jQuery);
|
542 |
+
</script>
|
views/theme-editor.php
ADDED
@@ -0,0 +1,233 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<div id="save-result"></div>
|
2 |
+
<div class="wrap">
|
3 |
+
<?php screen_icon(); ?>
|
4 |
+
<h2><?php _e('Edit Themes', 'wpeditor'); ?></h2>
|
5 |
+
<?php if(in_array($data['file'], (array) get_option('active_plugins', array()))) { ?>
|
6 |
+
<div class="updated">
|
7 |
+
<p><?php _e('<strong>This plugin is currently activated!<br />Warning:</strong> Making changes to active plugins is not recommended. If your changes cause a fatal error, the plugin will be automatically deactivated.', 'wpeditor'); ?></p>
|
8 |
+
</div>
|
9 |
+
<?php } ?>
|
10 |
+
<div class="fileedit-sub">
|
11 |
+
<div class="alignleft">
|
12 |
+
<h3>
|
13 |
+
<?php if(WP_34): ?>
|
14 |
+
<?php echo $data['wp_theme']->display('Name') . ': '; ?>
|
15 |
+
<?php else: ?>
|
16 |
+
<?php echo $data['themes'][$data['theme']]['Name'] . ': '; ?>
|
17 |
+
<?php endif; ?>
|
18 |
+
<?php
|
19 |
+
if(is_writeable($data['real_file'])) {
|
20 |
+
echo __('Editing <span class="current_file">', 'wpeditor') . $data['file'] . __('</span>', 'wpeditor');
|
21 |
+
}
|
22 |
+
else {
|
23 |
+
echo __('Browsing <span class="current_file">', 'wpeditor') . $data['file'] . __('</span>', 'wpeditor');
|
24 |
+
}
|
25 |
+
?>
|
26 |
+
</h3>
|
27 |
+
</div>
|
28 |
+
<div class="alignright">
|
29 |
+
<form action="themes.php?page=wpeditor_themes" method="post">
|
30 |
+
<strong><label for="plugin"><?php _e('Select theme to edit:', 'wpeditor'); ?></label></strong>
|
31 |
+
<select name="theme" id="theme">
|
32 |
+
<?php if(WP_34): ?>
|
33 |
+
<?php
|
34 |
+
foreach(wp_get_themes(array('errors' => null)) as $a_stylesheet => $a_theme) {
|
35 |
+
if($a_theme->errors() && 'theme_no_stylesheet' == $a_theme->errors()->get_error_code()) {
|
36 |
+
continue;
|
37 |
+
}
|
38 |
+
$selected = $a_stylesheet == strtolower($data['stylesheet']) ? ' selected="selected"' : '';
|
39 |
+
echo "\n\t" . '<option value="' . esc_attr($a_stylesheet) . '"' . $selected . '>' . $a_theme->display('Name') . '</option>';
|
40 |
+
}
|
41 |
+
?>
|
42 |
+
<?php else: ?>
|
43 |
+
<?php
|
44 |
+
foreach($data['themes'] as $a_theme) {
|
45 |
+
$theme_name = $a_theme['Name'];
|
46 |
+
if($theme_name == $data['theme']) {
|
47 |
+
$selected = ' selected="selected"';
|
48 |
+
}
|
49 |
+
else {
|
50 |
+
$selected = '';
|
51 |
+
}
|
52 |
+
$theme_name = esc_attr($theme_name); ?>
|
53 |
+
<option value="<?php echo $theme_name; ?>" <?php echo $selected; ?>><?php echo $theme_name; ?></option>
|
54 |
+
<?php
|
55 |
+
}
|
56 |
+
?>
|
57 |
+
<?php endif; ?>
|
58 |
+
</select>
|
59 |
+
<input type='submit' name='submit' class="button-secondary" value="<?php _e('Select', 'wpeditor'); ?>" />
|
60 |
+
</form>
|
61 |
+
</div>
|
62 |
+
<br class="clear" />
|
63 |
+
</div>
|
64 |
+
|
65 |
+
<div id="templateside">
|
66 |
+
<?php if(WPEditorSetting::getValue('theme_file_upload')): ?>
|
67 |
+
<h3><?php _e('Upload Files', 'wpeditor'); ?></h3>
|
68 |
+
<div id="theme-upload-files">
|
69 |
+
<?php if(is_writeable($data['real_file'])): ?>
|
70 |
+
<form enctype="multipart/form-data" id="theme_upload_form" method="POST">
|
71 |
+
<!-- MAX_FILE_SIZE must precede the file input field -->
|
72 |
+
<!--input type="hidden" name="MAX_FILE_SIZE" value="30000" /-->
|
73 |
+
<p class="description">
|
74 |
+
<?php _e('To', 'wpeditor'); ?>: <?php echo basename(dirname($data['current_theme_root'])) . '/' . basename($data['current_theme_root']) . '/'; ?>
|
75 |
+
</p>
|
76 |
+
<input type="hidden" name="current_theme_root" value="<?php echo $data['current_theme_root']; ?>" id="current_theme_root" />
|
77 |
+
<input type="text" name="directory" id="file_directory" style="width:190px" placeholder="<?php _e('Optional: Sub-Directory', 'wpeditor'); ?>" />
|
78 |
+
<!-- Name of input element determines name in $_FILES array -->
|
79 |
+
<input name="file" type="file" id="file" style="width:180px" />
|
80 |
+
<div class="ajax-button-loader">
|
81 |
+
<?php submit_button(__('Upload File', 'wpeditor'), 'primary', 'submit', false); ?>
|
82 |
+
<div class="ajax-loader"></div>
|
83 |
+
</div>
|
84 |
+
</form>
|
85 |
+
<?php else: ?>
|
86 |
+
<p>
|
87 |
+
<em><?php _e('You need to make this folder writable before you can upload any files. See <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">the Codex</a> for more information.'); ?></em>
|
88 |
+
</p>
|
89 |
+
<?php endif; ?>
|
90 |
+
</div>
|
91 |
+
<div id="upload_message"></div>
|
92 |
+
<?php endif; ?>
|
93 |
+
|
94 |
+
<h3><?php _e('Theme Files', 'wpeditor'); ?></h3>
|
95 |
+
<div id="theme-editor-files">
|
96 |
+
<ul id="theme-folders" class="theme-folders"></ul>
|
97 |
+
</div>
|
98 |
+
</div>
|
99 |
+
|
100 |
+
<form name="template" id="template_form" action="" method="post" class="ajax-editor-update">
|
101 |
+
<?php wp_nonce_field('edit-theme_' . $data['real_file']); ?>
|
102 |
+
<div>
|
103 |
+
<textarea cols="70" rows="25" name="new-content" id="new-content" tabindex="1"><?php echo $data['content'] ?></textarea>
|
104 |
+
<input type="hidden" name="action" value="save_files" />
|
105 |
+
<input type="hidden" name="_success" id="_success" value="<?php _e('The file has been updated successfully.', 'wpeditor'); ?>" />
|
106 |
+
<input type="hidden" id="file" name="file" value="<?php echo esc_attr($data['file']); ?>" />
|
107 |
+
<input type="hidden" id="plugin-dirname" name="theme" value="<?php echo esc_attr($data['theme']); ?>" />
|
108 |
+
<input type="hidden" id="path" name="path" value="<?php echo esc_attr($data['real_file']); ?>" />
|
109 |
+
<input type="hidden" name="scroll_to" id="scroll_to" value="<?php echo $data['scroll_to']; ?>" />
|
110 |
+
<input type="hidden" name="content-type" id="content-type" value="<?php echo $data['content-type']; ?>" />
|
111 |
+
<?php
|
112 |
+
$pathinfo = pathinfo($data['file']);
|
113 |
+
?>
|
114 |
+
<input type="hidden" name="extension" id="extension" value="<?php echo $pathinfo['extension']; ?>" />
|
115 |
+
</div>
|
116 |
+
<?php if(is_writeable($data['real_file'])): ?>
|
117 |
+
<p class="submit">
|
118 |
+
<?php
|
119 |
+
if(isset($_GET['phperror'])) {
|
120 |
+
echo '<input type="hidden" name="phperror" value="1" />'; ?>
|
121 |
+
<input type="submit" name="submit" class="button-primary" value="<?php _e('Update File and Attempt to Reactivate', 'wpeditor'); ?>" />
|
122 |
+
<?php } else { ?>
|
123 |
+
<input type="submit" name='submit' class="button-primary" value="<?php _e('Update File', 'wpeditor'); ?>" />
|
124 |
+
<?php
|
125 |
+
}
|
126 |
+
?>
|
127 |
+
</p>
|
128 |
+
<?php else: ?>
|
129 |
+
<p>
|
130 |
+
<em><?php _e('You need to make this file writable before you can save your changes. See <a href="http://codex.wordpress.org/Changing_File_Permissions" target="_blank">the Codex</a> for more information.'); ?></em>
|
131 |
+
</p>
|
132 |
+
<?php endif; ?>
|
133 |
+
</form>
|
134 |
+
<script type="text/javascript">
|
135 |
+
(function($){
|
136 |
+
$(document).ready(function(){
|
137 |
+
$('#template_form').submit(function(){
|
138 |
+
$('#scroll-to').val( $('#new-content').scrollTop() );
|
139 |
+
});
|
140 |
+
$('#new-content').scrollTop($('#scroll-to').val());
|
141 |
+
enableThemeAjaxBrowser('<?php echo urlencode((WPWINDOWS) ? str_replace("/", "\\", $data["real_file"]) : $data["real_file"]); ?>');
|
142 |
+
runCodeMirror('<?php echo $pathinfo["extension"]; ?>');
|
143 |
+
$('.ajax-loader').hide();
|
144 |
+
$('#theme_upload_form').submit(function() {
|
145 |
+
$('.ajax-loader').show();
|
146 |
+
var directory = $('#file_directory').val();
|
147 |
+
var current_theme_root = $('#current_theme_root').val();
|
148 |
+
var data = new FormData();
|
149 |
+
$.each($('input[type=file]')[0].files, function(i, file) {
|
150 |
+
data.append('file-'+i, file);
|
151 |
+
});
|
152 |
+
data.append('action', 'upload_files');
|
153 |
+
data.append('current_theme_root', current_theme_root);
|
154 |
+
data.append('directory', directory);
|
155 |
+
$.ajax({
|
156 |
+
type: "POST",
|
157 |
+
url: ajaxurl,
|
158 |
+
data: data,
|
159 |
+
contentType: false,
|
160 |
+
processData: false,
|
161 |
+
dataType: 'json',
|
162 |
+
success: function(result) {
|
163 |
+
if(result.error[0] === 0) {
|
164 |
+
enableThemeAjaxBrowser('<?php echo urlencode((WPWINDOWS) ? str_replace("/", "\\", $data["real_file"]) : $data["real_file"]); ?>');
|
165 |
+
$('#upload_message').html('<p class="WPEditorAjaxSuccess" style="padding:5px;">' + result.success + '</p>');
|
166 |
+
}
|
167 |
+
if(result.error[0] === -2) {
|
168 |
+
$('#upload_message').html('<p class="WPEditorAjaxError" style="padding:5px;">' + result.error[1] + '</p>');
|
169 |
+
}
|
170 |
+
else if(result.error[0] === -1) {
|
171 |
+
$('#upload_message').html('<p class="WPEditorAjaxError" style="padding:5px;">' + result.error[1] + '</p>');
|
172 |
+
}
|
173 |
+
$('.ajax-loader').hide();
|
174 |
+
}
|
175 |
+
});
|
176 |
+
return false;
|
177 |
+
});
|
178 |
+
|
179 |
+
})
|
180 |
+
})(jQuery);
|
181 |
+
function runCodeMirror(extension) {
|
182 |
+
if(extension === 'php') {
|
183 |
+
var mode = 'application/x-httpd-php';
|
184 |
+
}
|
185 |
+
else if(extension === 'css') {
|
186 |
+
var mode = 'css';
|
187 |
+
}
|
188 |
+
else if(extension === 'js') {
|
189 |
+
var mode = 'javascript';
|
190 |
+
}
|
191 |
+
else if(extension === 'html' || extension === 'htm') {
|
192 |
+
var mode = 'text/html';
|
193 |
+
}
|
194 |
+
else if(extension === 'xml') {
|
195 |
+
var mode = 'application/xml';
|
196 |
+
}
|
197 |
+
<?php
|
198 |
+
if(WPEditorSetting::getValue('theme_editor_theme')) { ?>
|
199 |
+
var theme = '<?php echo WPEditorSetting::getValue("theme_editor_theme"); ?>';
|
200 |
+
<?php }
|
201 |
+
else { ?>
|
202 |
+
var theme = 'default';
|
203 |
+
<?php }
|
204 |
+
if(WPEditorSetting::getValue('enable_theme_active_line')) { ?>
|
205 |
+
var activeLine = 'activeline-' + theme;
|
206 |
+
<?php } ?>
|
207 |
+
editor = CodeMirror.fromTextArea(document.getElementById('new-content'), {
|
208 |
+
mode: mode,
|
209 |
+
theme: theme,
|
210 |
+
<?php
|
211 |
+
if(WPEditorSetting::getValue('enable_theme_line_numbers')) { ?>
|
212 |
+
lineNumbers: true,
|
213 |
+
<?php } ?>
|
214 |
+
lineWrapping: true, // set line wrapping here
|
215 |
+
onCursorActivity: function() {
|
216 |
+
editor.setLineClass(hlLine, null);
|
217 |
+
hlLine = editor.setLineClass(editor.getCursor().line, activeLine);
|
218 |
+
},
|
219 |
+
onChange: function() {
|
220 |
+
changeTrue();
|
221 |
+
},
|
222 |
+
extraKeys: {
|
223 |
+
'F11': toggleFullscreenEditing,
|
224 |
+
'Esc': toggleFullscreenEditing
|
225 |
+
} // set fullscreen options here
|
226 |
+
});
|
227 |
+
var hlLine = editor.setLineClass(0, activeLine);
|
228 |
+
}
|
229 |
+
</script>
|
230 |
+
</div>
|
231 |
+
<div class="alignright">
|
232 |
+
</div>
|
233 |
+
<br class="clear" />
|
wpeditor.css
ADDED
@@ -0,0 +1,290 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#icon-wpeditor {
|
2 |
+
background:url('images/wpeditor_logo_32.png');
|
3 |
+
height:32px;
|
4 |
+
width:32px;
|
5 |
+
}
|
6 |
+
#settings-main {
|
7 |
+
background-color:#F1F1F1;
|
8 |
+
border-color:#CCC;
|
9 |
+
-webkit-box-shadow:0 1px 3px rgba(0,0,0,0.05);
|
10 |
+
box-shadow:0 1px 3px rgba(0,0,0,0.05);
|
11 |
+
position:relative;
|
12 |
+
margin:15px 15px 0 5px;
|
13 |
+
border-width:1px;
|
14 |
+
border-style:solid;
|
15 |
+
-webkit-border-radius:3px;
|
16 |
+
-moz-border-radius:3px;
|
17 |
+
border-radius:3px;
|
18 |
+
}
|
19 |
+
#settings-wrap {
|
20 |
+
padding:0;
|
21 |
+
margin-left:-4px;
|
22 |
+
margin:0;
|
23 |
+
position:relative;
|
24 |
+
overflow:visible;
|
25 |
+
}
|
26 |
+
#settings-back, .settings-tabs .active {
|
27 |
+
border-color:#CCC;
|
28 |
+
}
|
29 |
+
#settings-back {
|
30 |
+
background:#FFF;
|
31 |
+
position:absolute;
|
32 |
+
top:0;
|
33 |
+
bottom:0;
|
34 |
+
left:120px;
|
35 |
+
right:-1px;
|
36 |
+
border-width:0 1px;
|
37 |
+
border-style:solid;
|
38 |
+
-webkit-border-top-right-radius:3px;
|
39 |
+
-moz-border-top-right-radius:3px;
|
40 |
+
border-top-right-radius:3px;
|
41 |
+
-webkit-border-bottom-right-radius:3px;
|
42 |
+
-moz-border-bottom-right-radius:3px;
|
43 |
+
border-bottom-right-radius:3px;
|
44 |
+
}
|
45 |
+
#settings-columns {
|
46 |
+
position:relative;
|
47 |
+
}
|
48 |
+
.settings-tabs {
|
49 |
+
float:left;
|
50 |
+
width:120px;
|
51 |
+
margin:0;
|
52 |
+
}
|
53 |
+
.settings-tabs ul {
|
54 |
+
margin:1em 0;
|
55 |
+
}
|
56 |
+
.settings-tabs .active, .settings-tabs .active a, .settings-tabs .active a:hover {
|
57 |
+
background:#FFF;
|
58 |
+
color:#000;
|
59 |
+
}
|
60 |
+
.settings-tabs .active {
|
61 |
+
padding:5px 5px 5px 16px;
|
62 |
+
margin:-1px -1px -1px -5px;
|
63 |
+
border-width:1px 0 1px 1px;
|
64 |
+
border-style:solid;
|
65 |
+
}
|
66 |
+
.settings-tabs li {
|
67 |
+
margin:0;
|
68 |
+
list-style-type:none;
|
69 |
+
border-style:solid;
|
70 |
+
border-width:1px 0;
|
71 |
+
border-color:transparent;
|
72 |
+
}
|
73 |
+
.settings-tabs a {
|
74 |
+
display:block;
|
75 |
+
padding:5px 5px 5px 12px;
|
76 |
+
line-height:18px;
|
77 |
+
text-decoration:none;
|
78 |
+
}
|
79 |
+
.settings-body {
|
80 |
+
padding:10px;
|
81 |
+
overflow:auto;
|
82 |
+
display:none;
|
83 |
+
margin-bottom:-15px;
|
84 |
+
}
|
85 |
+
.settings-body h3 {
|
86 |
+
margin:0 0 5px;
|
87 |
+
padding:0 0 5px;
|
88 |
+
border-bottom:1px solid #E6E6E6;
|
89 |
+
}
|
90 |
+
#settings-loading {
|
91 |
+
padding:10px;
|
92 |
+
overflow:auto;
|
93 |
+
height:200px;
|
94 |
+
}
|
95 |
+
#settings-loading h2 {
|
96 |
+
padding-left:10px;
|
97 |
+
}
|
98 |
+
li.indent {
|
99 |
+
padding-left:10px;
|
100 |
+
}
|
101 |
+
.description p {
|
102 |
+
font-style:italic;
|
103 |
+
color:#999;
|
104 |
+
margin-top:0;
|
105 |
+
}
|
106 |
+
#save-message {
|
107 |
+
display:block;
|
108 |
+
position:fixed;
|
109 |
+
top:45%;
|
110 |
+
left:25%;
|
111 |
+
width:300px;
|
112 |
+
height:auto;
|
113 |
+
padding:5px 20px;
|
114 |
+
z-index:1002;
|
115 |
+
overflow:auto;
|
116 |
+
border-radius:6px;
|
117 |
+
-moz-border-radius:6px;
|
118 |
+
-webkit-border-radius:6px;
|
119 |
+
-moz-box-shadow:3px 3px 6px #cfcfcf;
|
120 |
+
-webkit-box-shadow:3px 3px 6px #cfcfcf;
|
121 |
+
}
|
122 |
+
.WPEditorAjaxSuccess {
|
123 |
+
background-color:#1F8FEE;
|
124 |
+
color:#FFF;
|
125 |
+
}
|
126 |
+
.WPEditorAjaxSuccess p, .WPEditorAjaxError p {
|
127 |
+
font-size:14px;
|
128 |
+
font-weight:bold;
|
129 |
+
}
|
130 |
+
.WPEditorAjaxError {
|
131 |
+
background-color:#E51F1F;
|
132 |
+
color:#FFF;
|
133 |
+
}
|
134 |
+
#plugin-editor-files, #theme-editor-files {
|
135 |
+
margin-top:5px;
|
136 |
+
}
|
137 |
+
#plugin-editor-files .plugin-folders, #theme-editor-files .theme-folders {
|
138 |
+
overflow:hidden;
|
139 |
+
padding-left:10px;
|
140 |
+
}
|
141 |
+
#plugin-editor-files .plugin-folders ul, #theme-editor-files .theme-folders ul {
|
142 |
+
margin:0 0 0 -10px;
|
143 |
+
padding:0px;
|
144 |
+
font-size:13px;
|
145 |
+
}
|
146 |
+
#plugin-editor-files .plugin-folders ul li, #theme-editor-files .theme-folders ul li {
|
147 |
+
list-style:none;
|
148 |
+
margin:0px;
|
149 |
+
padding-left:20px;
|
150 |
+
white-space:nowrap;
|
151 |
+
line-height:18px;
|
152 |
+
}
|
153 |
+
#plugin-editor-files .plugin-folders ul a, #theme-editor-files .theme-folders ul a {
|
154 |
+
display:block;
|
155 |
+
padding:0 2px;
|
156 |
+
-moz-border-radius:3px;
|
157 |
+
-webkit-border-radius:3px;
|
158 |
+
border-radius:3px;
|
159 |
+
color:#333;
|
160 |
+
text-decoration:none;
|
161 |
+
}
|
162 |
+
#plugin-editor-files .plugin-folders ul a:hover, #plugin-editor-files .plugin-folders ul .selected > a:hover, #theme-editor-files .theme-folders ul a:hover, #theme-editor-files .theme-folders ul .selected > a:hover {
|
163 |
+
background:#DDD;
|
164 |
+
}
|
165 |
+
|
166 |
+
#plugin-editor-files .plugin-folders ul .selected > a, #theme-editor-files .theme-folders ul .selected > a {
|
167 |
+
color:#21759B;
|
168 |
+
font-weight:bold;
|
169 |
+
background:#EDEDED;
|
170 |
+
}
|
171 |
+
.ajax-button-loader {
|
172 |
+
margin:5px 0;
|
173 |
+
padding:5px;
|
174 |
+
}
|
175 |
+
.ajax-loader {
|
176 |
+
background:url('images/loader.gif') 0px 0px no-repeat;
|
177 |
+
height:16px;
|
178 |
+
width:16px;
|
179 |
+
position:relative;
|
180 |
+
top:4px;
|
181 |
+
display:inline-block;
|
182 |
+
}
|
183 |
+
#plugin-editor-files .plugin-folders ul li.folder, #theme-editor-files .theme-folders ul li.folder {
|
184 |
+
background:url('images/folder.png') 0px 0px no-repeat;
|
185 |
+
}
|
186 |
+
#plugin-editor-files .plugin-folders ul li.folder.opened, #theme-editor-files .theme-folders ul li.folder.opened {
|
187 |
+
background:url('images/folder.png') 0px 0px no-repeat;
|
188 |
+
}
|
189 |
+
#plugin-editor-files .plugin-folders ul li.loading, #theme-editor-files .theme-folders ul li.loading {
|
190 |
+
background:url('images/loader.gif') 0px 0px no-repeat;
|
191 |
+
}
|
192 |
+
#plugin-editor-files .plugin-folders ul li.php, #theme-editor-files .theme-folders ul li.php {
|
193 |
+
background:url('images/php.png') 0px 0px no-repeat;
|
194 |
+
}
|
195 |
+
#plugin-editor-files .plugin-folders ul li.css, #theme-editor-files .theme-folders ul li.css {
|
196 |
+
background:url('images/css.png') 0px 0px no-repeat;
|
197 |
+
}
|
198 |
+
#plugin-editor-files .plugin-folders ul li.txt, #theme-editor-files .theme-folders ul li.txt {
|
199 |
+
background:url('images/txt.png') 0px 0px no-repeat;
|
200 |
+
}
|
201 |
+
#plugin-editor-files .plugin-folders ul li.js, #theme-editor-files .theme-folders ul li.js {
|
202 |
+
background:url('images/js.png') 0px 0px no-repeat;
|
203 |
+
}
|
204 |
+
#plugin-editor-files .plugin-folders ul li.sql, #theme-editor-files .theme-folders ul li.sql {
|
205 |
+
background:url('images/sql.png') 0px 0px no-repeat;
|
206 |
+
}
|
207 |
+
#plugin-editor-files .plugin-folders ul li.po, #theme-editor-files .theme-folders ul li.po {
|
208 |
+
background:url('images/po.png') 0px 0px no-repeat;
|
209 |
+
}
|
210 |
+
#plugin-editor-files .plugin-folders ul li.pot, #theme-editor-files .theme-folders ul li.pot {
|
211 |
+
background:url('images/pot.png') 0px 0px no-repeat;
|
212 |
+
}
|
213 |
+
#plugin-editor-files .plugin-folders ul li.png, #theme-editor-files .theme-folders ul li.png {
|
214 |
+
background:url('images/png.png') 0px 0px no-repeat;
|
215 |
+
}
|
216 |
+
#plugin-editor-files .plugin-folders ul li.gif, #theme-editor-files .theme-folders ul li.gif {
|
217 |
+
background:url('images/gif.png') 0px 0px no-repeat;
|
218 |
+
}
|
219 |
+
#plugin-editor-files .plugin-folders ul li.jpg, #theme-editor-files .theme-folders ul li.jpg {
|
220 |
+
background:url('images/jpg.png') 0px 0px no-repeat;
|
221 |
+
}
|
222 |
+
#plugin-editor-files .plugin-folders ul li.jpeg, #theme-editor-files .theme-folders ul li.jpeg {
|
223 |
+
background:url('images/jpg.png') 0px 0px no-repeat;
|
224 |
+
}
|
225 |
+
#plugin-editor-files .plugin-folders ul li.htm, #theme-editor-files .theme-folders ul li.htm {
|
226 |
+
background:url('images/htm.png') 0px 0px no-repeat;
|
227 |
+
}
|
228 |
+
#plugin-editor-files .plugin-folders ul li.html, #theme-editor-files .theme-folders ul li.html {
|
229 |
+
background:url('images/html.png') 0px 0px no-repeat;
|
230 |
+
}
|
231 |
+
span.tiny {
|
232 |
+
font-size:10px;
|
233 |
+
}
|
234 |
+
.CodeMirror {
|
235 |
+
height:450px;
|
236 |
+
width:97%;
|
237 |
+
}
|
238 |
+
.CodeMirror-scroll {
|
239 |
+
height:450px;
|
240 |
+
}
|
241 |
+
#templateside {
|
242 |
+
margin-left:20px;
|
243 |
+
float:right;
|
244 |
+
}
|
245 |
+
.activeline-elegant, .activeline-eclipse, .activeline-default, .activeline-neat {
|
246 |
+
background:#F0FCFF !important;
|
247 |
+
}
|
248 |
+
.activeline-cobalt {
|
249 |
+
background:#B36539 !important;
|
250 |
+
}
|
251 |
+
.activeline-night {
|
252 |
+
background:#A8F !important;
|
253 |
+
}
|
254 |
+
.activeline-monokai {
|
255 |
+
background:#FFE792 !important;
|
256 |
+
}
|
257 |
+
.activeline-rubyblue {
|
258 |
+
background:#00F !important;
|
259 |
+
}
|
260 |
+
.checkbox_label {
|
261 |
+
margin:0 5px 0 0;
|
262 |
+
padding:0;
|
263 |
+
}
|
264 |
+
.current_file {
|
265 |
+
font-weight:bold;
|
266 |
+
}
|
267 |
+
.normal_list {
|
268 |
+
list-style-type:disc;
|
269 |
+
padding-left:15px;
|
270 |
+
}
|
271 |
+
.normal_list li {
|
272 |
+
margin:2px;
|
273 |
+
}
|
274 |
+
a.donate, a.support {
|
275 |
+
font-family:"Droid Sans", "Helvetica Neue", Helvetica, Arial, sans-serif;
|
276 |
+
font-size: 14px;
|
277 |
+
font-weight:bold;
|
278 |
+
color: #ffffff;
|
279 |
+
text-decoration:none;
|
280 |
+
padding:5px 30px;
|
281 |
+
background:-moz-linear-gradient(top, #a10e0e 0%, #600606);
|
282 |
+
background:-webkit-gradient(linear, left top, left bottom, from(#a10e0e), to(#600606));
|
283 |
+
border-radius:3px;
|
284 |
+
-moz-border-radius:3px;
|
285 |
+
-webkit-border-radius:3px;
|
286 |
+
border:1px solid #500a0a;
|
287 |
+
-moz-box-shadow:0px 1px 3px rgba(000,000,000,0.5);
|
288 |
+
-webkit-box-shadow:0px 1px 3px rgba(000,000,000,0.5);
|
289 |
+
text-shadow:1px 1px 2px rgba(000,000,000,.8);
|
290 |
+
}
|
wpeditor.php
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<?php
|
2 |
+
/*
|
3 |
+
Plugin Name: WP Editor
|
4 |
+
Plugin URI: http://wpeditor.net
|
5 |
+
Description: This plugin modifies the default behavior of the WordPress plugin and theme editors.
|
6 |
+
Version: 1.0.2
|
7 |
+
Author: Benjamin Rojas
|
8 |
+
Author URI: http://benjaminrojas.net
|
9 |
+
Text Domain: wpeditor
|
10 |
+
Domain Path: /languages/
|
11 |
+
------------------------------------------------------------------------
|
12 |
+
WP Editor Plugin
|
13 |
+
Copyright 2012 Benjamin Rojas
|
14 |
+
|
15 |
+
This program is free software: you can redistribute it and/or modify
|
16 |
+
it under the terms of the GNU General Public License as published by
|
17 |
+
the Free Software Foundation, either version 3 of the License, or
|
18 |
+
(at your option) any later version.
|
19 |
+
|
20 |
+
This program is distributed in the hope that it will be useful,
|
21 |
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
22 |
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
23 |
+
GNU General Public License for more details.
|
24 |
+
|
25 |
+
You should have received a copy of the GNU General Public License
|
26 |
+
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
27 |
+
*/
|
28 |
+
|
29 |
+
if(!class_exists('WPEditor')) {
|
30 |
+
|
31 |
+
ob_start();
|
32 |
+
|
33 |
+
// Define the WP Editor version number
|
34 |
+
define('WPEDITOR_VERSION_NUMBER', '1.0.2');
|
35 |
+
|
36 |
+
$wp_34 = false;
|
37 |
+
if(version_compare(get_bloginfo('version'), '3.4', '>=')) {
|
38 |
+
$wp_34 = true;
|
39 |
+
}
|
40 |
+
define('WP_34', $wp_34);
|
41 |
+
|
42 |
+
// Define the default path and URL for the WP Editor plugin
|
43 |
+
define('WPEDITOR_PATH', plugin_dir_path( __FILE__ ));
|
44 |
+
define('WPEDITOR_URL', plugins_url() . '/' . basename(dirname(__FILE__)));
|
45 |
+
|
46 |
+
// IS_ADMIN is true when the dashboard or the administration panels are displayed
|
47 |
+
if(!defined('IS_ADMIN')) {
|
48 |
+
define('IS_ADMIN', is_admin());
|
49 |
+
}
|
50 |
+
|
51 |
+
$windows = false;
|
52 |
+
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
|
53 |
+
$windows = true;
|
54 |
+
}
|
55 |
+
|
56 |
+
define('WPWINDOWS', $windows);
|
57 |
+
|
58 |
+
load_plugin_textdomain('wpeditor', false, '/' . basename(dirname(__FILE__)) . '/languages/');
|
59 |
+
|
60 |
+
// Load the main WP Editor class
|
61 |
+
require_once(WPEDITOR_PATH . 'classes/WPEditor.php');
|
62 |
+
$wpedit = new WPEditor();
|
63 |
+
|
64 |
+
// Register activation hook to install WP Editor database tables and system code
|
65 |
+
register_activation_hook(__FILE__, array($wpedit, 'install'));
|
66 |
+
|
67 |
+
// Check for WordPress 3.1 auto-upgrades
|
68 |
+
if(function_exists('register_update_hook')) {
|
69 |
+
register_update_hook(__FILE__, array($wpedit, 'install'));
|
70 |
+
}
|
71 |
+
|
72 |
+
// Initialize the main WP Editor Class
|
73 |
+
add_action('init', array($wpedit, 'init'));
|
74 |
+
|
75 |
+
// Add settings link to plugin page
|
76 |
+
add_filter('plugin_action_links', 'wpEditorSettingsLink',10,2);
|
77 |
+
}
|
78 |
+
|
79 |
+
function wpEditorSettingsLink($links, $file) {
|
80 |
+
$thisFile = plugin_basename(__FILE__);
|
81 |
+
if($file == $thisFile) {
|
82 |
+
$settings = '<a href="' . admin_url('admin.php?page=wpeditor_admin') . '" title="' . __('Open the settings page for this plugin', 'wpeditor') . '">' . __('Settings', 'wpeditor') . '</a>';
|
83 |
+
array_unshift($links, $settings);
|
84 |
+
}
|
85 |
+
return $links;
|
86 |
+
}
|