CMS Tree Page View - Version 0.10.1

Version Description

  • Fixed popup closing to fast on Firefox.
  • Enable menu item setting by default for hierarchical post types during first install. It was confusing when it was enabled for pages but not for other post types. Consistency!
  • Added link to settings page to plugin listing.
  • Fixed: WPML-stuff now also works on custom post types
Download this release

Release Info

Developer eskapism
Plugin Icon wp plugin CMS Tree Page View
Version 0.10.1
Comparing to
See all releases

Code changes from version 0.10 to 0.10.1

Files changed (4) hide show
  1. functions.php +94 -49
  2. index.php +5 -3
  3. readme.txt +7 -1
  4. scripts/cms_tree_page_view.js +89 -19
functions.php CHANGED
@@ -126,8 +126,28 @@ function cms_tpv_admin_init() {
126
 
127
  load_plugin_textdomain('cms-tree-page-view', WP_CONTENT_DIR . "/plugins/languages", "/cms-tree-page-view/languages");
128
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  }
130
 
 
131
  // save settings
132
  function cms_tpv_save_settings() {
133
  if (isset($_POST["cms_tpv_action"]) && $_POST["cms_tpv_action"] == "save_settings") {
@@ -206,7 +226,9 @@ function cms_tpv_options() {
206
  <?php
207
  $options = cms_tpv_get_options();
208
 
209
- $post_types = get_post_types(array(), "objects");
 
 
210
  $arr_page_options = array();
211
  foreach ($post_types as $one_post_type) {
212
  $name = $one_post_type->name;
@@ -218,22 +240,20 @@ function cms_tpv_options() {
218
  // continue;
219
  }
220
 
221
- if ($one_post_type->show_ui) {
 
 
 
 
 
 
 
 
 
 
 
 
222
 
223
- $arr_page_options[] = "post-type-dashboard-$name";
224
- $arr_page_options[] = "post-type-menu-$name";
225
- echo "<p>";
226
- echo "<strong>".$one_post_type->label."</strong>";
227
-
228
- $checked = (in_array($name, $options["dashboard"])) ? " checked='checked' " : "";
229
- echo "<br />";
230
- echo "<input $checked type='checkbox' name='post-type-dashboard[]' value='$name' id='post-type-dashboard-$name' /> <label for='post-type-dashboard-$name'>" . __("On dashboard", 'cms-tree-page-view') . "</label>";
231
-
232
- $checked = (in_array($name, $options["menu"])) ? " checked='checked' " : "";
233
- echo "<br />";
234
- echo "<input $checked type='checkbox' name='post-type-menu[]' value='$name' id='post-type-menu-$name' /> <label for='post-type-menu-$name'>" . __("In menu", 'cms-tree-page-view') . "</label>";
235
- echo "</p>";
236
- }
237
  }
238
 
239
  ?>
@@ -294,6 +314,8 @@ function cms_tpv_is_post_type_hierarchical($post_type_object) {
294
  */
295
  function cms_tpv_print_common_tree_stuff($post_type = "") {
296
 
 
 
297
  if (!$post_type) {
298
  $post_type = cms_tpv_get_selected_post_type();
299
  }
@@ -303,13 +325,19 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
303
 
304
  $pages = cms_tpv_get_pages($get_pages_args);
305
 
 
306
  $wpml_current_lang = "";
307
- if (defined("ICL_SITEPRESS_VERSION") && $post_type == "page") {
308
- global $sitepress;
309
- $wpml_current_lang = $sitepress->get_current_language();
 
 
 
 
 
 
310
  }
311
 
312
- global $cms_tpv_view;
313
  // output js for the root/top level
314
  // function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $post_type) {
315
  // @todo: make into function since used at other places
@@ -335,9 +363,9 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
335
  <input type="hidden" name="cms_tpv_meta_wpml_language" value="<?php echo $wpml_current_lang ?>" />
336
  <?php
337
 
338
- // check if WPML is activated
339
- // if: show a language-menu
340
- if (defined("ICL_SITEPRESS_VERSION") && $post_type == "page") {
341
  $wpml_langs = icl_get_languages();
342
  $wpml_active_lang = null;
343
  if (sizeof($wpml_langs)>=1) {
@@ -356,22 +384,9 @@ function cms_tpv_print_common_tree_stuff($post_type = "") {
356
  $lang_out .= "</ul>";
357
  echo $lang_out;
358
  }
 
359
  }
360
- /*
361
- Array
362
- (
363
- [en] => Array
364
- (
365
- [id] => 1
366
- [active] => 1
367
- [native_name] => English
368
- [language_code] => en
369
- [translated_name] => English
370
- [url] => http://localhost/wordpress3
371
- [country_flag_url] => http://localhost/wordpress3/wp-content/plugins/sitepress-multilingual-cms/res/flags/en.png
372
- )
373
- */
374
-
375
  if (empty($pages)) {
376
  echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>';
377
  } else {
@@ -734,15 +749,15 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
734
  "data": {
735
  "title": "<?php echo $title ?>",
736
  "attr": {
737
- "href": "<?php echo $editLink ?>",
738
- "xid": "cms-tpv-<?php echo $onePage->ID ?>"
739
- },
740
- "xicon": "<?php echo CMS_TPV_URL . "images/page_white_text.png" ?>"
741
  },
742
  "attr": {
743
- "xhref": "<?php echo $editLink ?>",
744
  "id": "cms-tpv-<?php echo $onePage->ID ?>",
745
- "xtitle": "<?php _e("Click to edit. Drag to move.", 'cms-tree-page-view') ?>",
746
  "class": "<?php echo $user_can_edit_page_css ?>"
747
  },
748
  <?php echo $strState ?>
@@ -764,6 +779,7 @@ function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $po
764
  }
765
  <?php
766
  // if id is in $arrOpenChilds then also output children on this one
 
767
  if ($hasChildren && isset($arrOpenChilds) && in_array($onePage->ID, $arrOpenChilds)) {
768
  ?>, "children": <?php
769
  cms_tpv_print_childs($onePage->ID, $view, $arrOpenChilds, $post_type);
@@ -1123,19 +1139,48 @@ function cms_tpv_install() {
1123
  // after upgrading/re-enabling the plugin, also re-enable the little please-donate-box
1124
  update_option('cms_tpv_show_annoying_little_box', 1);
1125
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1126
  // check and update version
1127
  $version = get_option('cms_tpv_version', 0);
 
 
 
1128
  if ($version <= 0) {
1129
- // first install or pre custom posts version:
1130
- // make sure pages are enabled by default
1131
  $options = array();
 
 
1132
  $options["dashboard"] = array("page");
1133
  $options["menu"] = array("page");
 
 
 
 
 
 
 
 
 
 
 
 
 
1134
  update_option('cms_tpv_options', $options);
1135
  }
1136
-
1137
- // set to current version
1138
- update_option('cms_tpv_version', CMS_TPV_VERSION);
1139
  }
1140
 
1141
  // when plugins are loaded, check if current plugin version is same as stored
126
 
127
  load_plugin_textdomain('cms-tree-page-view', WP_CONTENT_DIR . "/plugins/languages", "/cms-tree-page-view/languages");
128
 
129
+ // add row to plugin page
130
+ add_filter( 'plugin_row_meta', 'cms_tpv_set_plugin_row_meta', 10, 2 );
131
+
132
+ }
133
+
134
+ /**
135
+ * Add settings link to plugin page
136
+ * Hopefully this helps some people to find the settings page quicker
137
+ */
138
+ function cms_tpv_set_plugin_row_meta($links, $file) {
139
+
140
+ if ($file === "cms-tree-page-view/index.php") {
141
+ return array_merge(
142
+ $links,
143
+ array( sprintf( '<a href="options-general.php?page=%s">%s</a>', "cms-tpv-options", __('Settings') ) )
144
+ );
145
+ }
146
+ return $links;
147
+
148
  }
149
 
150
+
151
  // save settings
152
  function cms_tpv_save_settings() {
153
  if (isset($_POST["cms_tpv_action"]) && $_POST["cms_tpv_action"] == "save_settings") {
226
  <?php
227
  $options = cms_tpv_get_options();
228
 
229
+ $post_types = get_post_types(array(
230
+ "show_ui" => TRUE
231
+ ), "objects");
232
  $arr_page_options = array();
233
  foreach ($post_types as $one_post_type) {
234
  $name = $one_post_type->name;
240
  // continue;
241
  }
242
 
243
+ $arr_page_options[] = "post-type-dashboard-$name";
244
+ $arr_page_options[] = "post-type-menu-$name";
245
+ echo "<p>";
246
+ echo "<strong>".$one_post_type->label."</strong>";
247
+
248
+ $checked = (in_array($name, $options["dashboard"])) ? " checked='checked' " : "";
249
+ echo "<br />";
250
+ echo "<input $checked type='checkbox' name='post-type-dashboard[]' value='$name' id='post-type-dashboard-$name' /> <label for='post-type-dashboard-$name'>" . __("On dashboard", 'cms-tree-page-view') . "</label>";
251
+
252
+ $checked = (in_array($name, $options["menu"])) ? " checked='checked' " : "";
253
+ echo "<br />";
254
+ echo "<input $checked type='checkbox' name='post-type-menu[]' value='$name' id='post-type-menu-$name' /> <label for='post-type-menu-$name'>" . __("In menu", 'cms-tree-page-view') . "</label>";
255
+ echo "</p>";
256
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
257
  }
258
 
259
  ?>
314
  */
315
  function cms_tpv_print_common_tree_stuff($post_type = "") {
316
 
317
+ global $sitepress, $cms_tpv_view;
318
+
319
  if (!$post_type) {
320
  $post_type = cms_tpv_get_selected_post_type();
321
  }
325
 
326
  $pages = cms_tpv_get_pages($get_pages_args);
327
 
328
+ // check if wpml is active and if this post type is one of its enabled ones
329
  $wpml_current_lang = "";
330
+ $wmpl_active_for_post = FALSE;
331
+ if (defined("ICL_SITEPRESS_VERSION")) {
332
+
333
+ $wpml_post_types = $sitepress->get_translatable_documents();
334
+ if (array_key_exists($post_type, $wpml_post_types)) {
335
+ $wmpl_active_for_post = TRUE;
336
+ $wpml_current_lang = $sitepress->get_current_language();
337
+ }
338
+
339
  }
340
 
 
341
  // output js for the root/top level
342
  // function cms_tpv_print_childs($pageID, $view = "all", $arrOpenChilds = null, $post_type) {
343
  // @todo: make into function since used at other places
363
  <input type="hidden" name="cms_tpv_meta_wpml_language" value="<?php echo $wpml_current_lang ?>" />
364
  <?php
365
 
366
+ // check if WPML is activated and show a language-menu
367
+ if ($wmpl_active_for_post) {
368
+
369
  $wpml_langs = icl_get_languages();
370
  $wpml_active_lang = null;
371
  if (sizeof($wpml_langs)>=1) {
384
  $lang_out .= "</ul>";
385
  echo $lang_out;
386
  }
387
+
388
  }
389
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
390
  if (empty($pages)) {
391
  echo '<div class="updated fade below-h2"><p>' . __("No posts found.", 'cms-tree-page-view') . '</p></div>';
392
  } else {
749
  "data": {
750
  "title": "<?php echo $title ?>",
751
  "attr": {
752
+ "href": "<?php echo $editLink ?>"
753
+ <?php /* , "xid": "cms-tpv-<?php echo $onePage->ID ?>" */ ?>
754
+ }<?php /*,
755
+ "xicon": "<?php echo CMS_TPV_URL . "images/page_white_text.png" ?>"*/?>
756
  },
757
  "attr": {
758
+ <?php /* "xhref": "<?php echo $editLink ?>", */ ?>
759
  "id": "cms-tpv-<?php echo $onePage->ID ?>",
760
+ <?php /* "xtitle": "<?php _e("Click to edit. Drag to move.", 'cms-tree-page-view') ?>", */ ?>
761
  "class": "<?php echo $user_can_edit_page_css ?>"
762
  },
763
  <?php echo $strState ?>
779
  }
780
  <?php
781
  // if id is in $arrOpenChilds then also output children on this one
782
+ // TODO: if only "a few" (< 100?) pages then load all, but keep closed, so we don't have to do the ajax thingie
783
  if ($hasChildren && isset($arrOpenChilds) && in_array($onePage->ID, $arrOpenChilds)) {
784
  ?>, "children": <?php
785
  cms_tpv_print_childs($onePage->ID, $view, $arrOpenChilds, $post_type);
1139
  // after upgrading/re-enabling the plugin, also re-enable the little please-donate-box
1140
  update_option('cms_tpv_show_annoying_little_box', 1);
1141
 
1142
+ // first install or pre custom posts version:
1143
+ // make sure pages are enabled by default
1144
+ // run on admin_init so most themes and plugins have time to setup their things. late prio too.
1145
+ add_action("admin_init", "cms_tpv_setup_defaults", 999);
1146
+
1147
+ // set to current version
1148
+ update_option('cms_tpv_version', CMS_TPV_VERSION);
1149
+ }
1150
+
1151
+ /**
1152
+ * setup some defaults
1153
+ */
1154
+ function cms_tpv_setup_defaults() {
1155
+
1156
  // check and update version
1157
  $version = get_option('cms_tpv_version', 0);
1158
+
1159
+ //$version = 0;
1160
+
1161
  if ($version <= 0) {
1162
+
 
1163
  $options = array();
1164
+
1165
+ // Add pages to both dashboard and menu
1166
  $options["dashboard"] = array("page");
1167
  $options["menu"] = array("page");
1168
+
1169
+ // since 0.10.1 enable menu for all hierarchical custom post types
1170
+ $post_types = get_post_types(array(
1171
+ "show_ui" => TRUE,
1172
+ "hierarchical" => TRUE
1173
+ ), "objects");
1174
+
1175
+ foreach ($post_types as $one_post_type) {
1176
+ $options["menu"][] = $one_post_type->name;
1177
+ }
1178
+
1179
+ $options["menu"] = array_unique($options["menu"]);
1180
+
1181
  update_option('cms_tpv_options', $options);
1182
  }
1183
+
 
 
1184
  }
1185
 
1186
  // when plugins are loaded, check if current plugin version is same as stored
index.php CHANGED
@@ -3,7 +3,7 @@
3
  Plugin Name: CMS Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/cms-tree-page-view/
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. Use the tree view to edit, view, add pages and search pages (very useful if you have many pages). And with drag and drop you can rearrange the order of your pages. Page management won't get any easier than this!
6
- Version: 0.10
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
@@ -26,11 +26,12 @@ License: GPL2
26
  */
27
 
28
  #require("functions.php");
29
- require(dirname(__FILE__)."/functions.php");
30
 
31
- define( "CMS_TPV_VERSION", "0.10");
32
  define( "CMS_TPV_NAME", "CMS Tree Page View");
33
 
 
 
34
  // Find the plugin directory URL
35
  $aa = __FILE__;
36
  if ( isset( $mu_plugin ) ) {
@@ -46,6 +47,7 @@ $plugin_dir_url = plugin_dir_url(basename($aa)) . 'cms-tree-page-view/';
46
 
47
  // There! Now we should have it.
48
  define( "CMS_TPV_URL", $plugin_dir_url);
 
49
 
50
  // on admin init: add styles and scripts
51
  add_action( 'admin_init', 'cms_tpv_admin_init' );
3
  Plugin Name: CMS Tree Page View
4
  Plugin URI: http://eskapism.se/code-playground/cms-tree-page-view/
5
  Description: Adds a CMS-like tree view of all your pages, like the view often found in a page-focused CMS. Use the tree view to edit, view, add pages and search pages (very useful if you have many pages). And with drag and drop you can rearrange the order of your pages. Page management won't get any easier than this!
6
+ Version: 0.10.1
7
  Author: Pär Thernström
8
  Author URI: http://eskapism.se/
9
  License: GPL2
26
  */
27
 
28
  #require("functions.php");
 
29
 
30
+ define( "CMS_TPV_VERSION", "0.10.1");
31
  define( "CMS_TPV_NAME", "CMS Tree Page View");
32
 
33
+ require(dirname(__FILE__)."/functions.php");
34
+
35
  // Find the plugin directory URL
36
  $aa = __FILE__;
37
  if ( isset( $mu_plugin ) ) {
47
 
48
  // There! Now we should have it.
49
  define( "CMS_TPV_URL", $plugin_dir_url);
50
+ // define( "CMS_TPV_PLUGIN_FOLDERNAME_AND_FILENAME", basename(dirname(__FILE__)) . "/" . basename(__FILE__) );
51
 
52
  // on admin init: add styles and scripts
53
  add_action( 'admin_init', 'cms_tpv_admin_init' );
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://eskapism.se/sida/donate/
4
  Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and-drop, rearrange, management, manage, admin
5
  Requires at least: 3.0
6
  Tested up to: 3.5
7
- Stable tag: 0.10
8
 
9
  Adds a tree of all your pages or custom posts. Use drag & drop to reorder your pages, and edit, view, add, and search your pages.
10
 
@@ -88,6 +88,12 @@ Now the tree with the pages will be visible both on the dashboard and in the men
88
 
89
  == Changelog ==
90
 
 
 
 
 
 
 
91
  = 0.10 =
92
  - Fixed position of action div. Now it's always to the right of the page name.
93
  - Fixed so action div never is below the fold of the browser. Instead it's moved up until it's visible.
4
  Tags: page, pages, posts, custom posts, tree, cms, dashboard, overview, drag-and-drop, rearrange, management, manage, admin
5
  Requires at least: 3.0
6
  Tested up to: 3.5
7
+ Stable tag: 0.10.1
8
 
9
  Adds a tree of all your pages or custom posts. Use drag & drop to reorder your pages, and edit, view, add, and search your pages.
10
 
88
 
89
  == Changelog ==
90
 
91
+ = 0.10.1 =
92
+ - Fixed popup closing to fast on Firefox.
93
+ - Enable menu item setting by default for hierarchical post types during first install. It was confusing when it was enabled for pages but not for other post types. Consistency!
94
+ - Added link to settings page to plugin listing.
95
+ - Fixed: WPML-stuff now also works on custom post types
96
+
97
  = 0.10 =
98
  - Fixed position of action div. Now it's always to the right of the page name.
99
  - Fixed so action div never is below the fold of the browser. Instead it's moved up until it's visible.
scripts/cms_tree_page_view.js CHANGED
@@ -1,4 +1,52 @@
1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  // @todo: add prefix to treeOptions, div_actions
3
  var cms_tpv_tree, treeOptions, div_actions, cms_tpv_current_li_id = null;
4
  jQuery(function($) {
@@ -9,20 +57,22 @@ jQuery(function($) {
9
 
10
  // try to override css
11
  var height = "20", height2 = "18", ins_height = "20";
12
- css_string = '' +
13
- '.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; } ' +
14
- '.jstree li { display:block; min-height:'+height+'px; line-height:'+height+'px; white-space:nowrap; margin-left:18px; min-width:18px; } ' +
15
- '.jstree-rtl li { margin-left:0; margin-right:18px; } ' +
16
- '.jstree > ul > li { margin-left:0px; } ' +
17
- '.jstree-rtl > ul > li { margin-right:0px; } ' +
18
- '.jstree ins { display:inline-block; text-decoration:none; width:18px; height:'+height+'px; margin:0 0 0 0; padding:0; } ' +
19
- '.jstree a { display:inline-block; line-height:'+height2+'px; height:'+height2+'px; color:black; white-space:nowrap; text-decoration:none; padding:1px 2px; margin:0; } ' +
20
- '.jstree a:focus { outline: none; } ' +
21
- '.jstree a > ins { height:'+ins_height+'px; width:16px; } ' +
22
- '.jstree a > .jstree-icon { margin-right:3px; } ' +
23
- '.jstree-rtl a > .jstree-icon { margin-left:3px; margin-right:0; } ' +
24
- 'li.jstree-open > ul { display:block; } ' +
25
- 'li.jstree-closed > ul { display:none; } ';
 
 
26
  $.vakata.css.add_sheet({
27
  str : css_string,
28
  title : "jstree_cms_tpv"
@@ -119,7 +169,6 @@ function cms_tpv_mouseover(e) {
119
 
120
  /**
121
  * When tree is loaded: start hoverindenting stuff
122
- * @todo: this is fireded several times? why not only once?
123
  */
124
  function cms_tpv_tree_loaded(event, data) {
125
 
@@ -128,16 +177,22 @@ function cms_tpv_tree_loaded(event, data) {
128
  // when mouse enters a/link
129
  // start timer and if no other a/link has been moused over since it started it's ok to show this one
130
  jQuery($container).on("mouseenter", "a", function(e) {
 
 
 
131
  var global_timer = $container.data("cmstpv_global_link_timer");
132
 
133
  if (global_timer) {
134
  // global timer exists, so overwrite it with our new one
135
  // stop that timer before setting ours
 
136
  clearTimeout(global_timer);
137
  } else {
138
  // no timer exists, overwrite with ours
139
  }
 
140
  // create new timer, no matter if one exists already
 
141
  var timeoutID = setTimeout(function(e) {
142
  cms_tpv_mouseover_li(e);
143
  }, 500, e);
@@ -147,15 +202,23 @@ function cms_tpv_tree_loaded(event, data) {
147
  });
148
 
149
  /**
150
- * When mouse down then hide the action div
 
151
  */
152
  jQuery($container).on("mousedown", "a", function(e) {
 
 
 
153
  var $target = jQuery(e.target);
154
  var $container = $target.closest("div.cms_tpv_container");
155
  var $wrapper = $container.closest("div.cms_tpv_wrapper");
 
156
  $container.find("li.has-visible-actions").removeClass("has-visible-actions");
157
  $container.find("a.hover").removeClass("hover");
158
  $wrapper.find("div.cms_tpv_page_actions").removeClass("cms_tpv_page_actions_visible");
 
 
 
159
  });
160
 
161
  }
@@ -364,6 +427,8 @@ function cms_tpv_mouseover_li(e) {
364
  * hide actions div after moving mouse out of a page and not moving it on again for...a while
365
  */
366
  jQuery(document).on("mouseleave", "div.cms_tpv_container", function(e) {
 
 
367
 
368
  var $container = jQuery(e.target).closest("div.cms_tpv_container");
369
  var $wrapper = $container.closest("div.cms_tpv_wrapper");
@@ -372,18 +437,23 @@ jQuery(document).on("mouseleave", "div.cms_tpv_container", function(e) {
372
  // reset global timer
373
  var global_timer = $container.data("cmstpv_global_link_timer");
374
  if (global_timer) {
 
375
  clearTimeout(global_timer);
376
  }
377
 
378
  // hide popup after a short while
379
  var hideTimer = setTimeout(function() {
380
 
 
 
381
  // But don't hide if we are inside the popup
382
- var $toElement = jQuery(e.toElement);
383
- if ($toElement.hasClass("cms_tpv_page_actions")) {
384
  // we are over the actions div, so don't hide
 
385
  } else {
386
  // somewhere else, do hide
 
387
  $container.find("li.has-visible-actions").removeClass("has-visible-actions");
388
  $container.find("a.hover").removeClass("hover");
389
  $wrapper.find("div.cms_tpv_page_actions").removeClass("cms_tpv_page_actions_visible");
@@ -391,7 +461,7 @@ jQuery(document).on("mouseleave", "div.cms_tpv_container", function(e) {
391
 
392
  }, 500);
393
 
394
- $container.data("cmstpv_global_hide_timer", hideTimer);
395
 
396
  });
397
 
1
 
2
+ /*
3
+
4
+ Some docs so I remember how things work:
5
+
6
+ Timers:
7
+
8
+ cmstpv_global_link_timer
9
+ set when mouse over link. used to show the actions div.
10
+
11
+ */
12
+
13
+
14
+ /**
15
+ * Should have a module for all instead...
16
+ */
17
+ var cms_tree_page_view = (function () {
18
+
19
+ var my = {},
20
+ privateVariable = 1;
21
+
22
+ function privateMethod() {
23
+ // ...
24
+ }
25
+
26
+ my.moduleProperty = 1;
27
+ my.moduleMethod = function () {
28
+ // ...
29
+ };
30
+
31
+ my.init = function() {
32
+ my.log("init cms tree page view");
33
+ };
34
+
35
+ /**
36
+ * Log, but only if console.log is available
37
+ */
38
+ my.log = function(what) {
39
+ if (typeof(window.console) === "object" && typeof(window.console.log) === "function" ) {
40
+ console.log(what);
41
+ }
42
+ };
43
+
44
+ return my;
45
+ }());
46
+
47
+ cms_tree_page_view.init();
48
+
49
+
50
  // @todo: add prefix to treeOptions, div_actions
51
  var cms_tpv_tree, treeOptions, div_actions, cms_tpv_current_li_id = null;
52
  jQuery(function($) {
57
 
58
  // try to override css
59
  var height = "20", height2 = "18", ins_height = "20";
60
+ css_string = '' +
61
+ '.jstree ul, .jstree li { display:block; margin:0 0 0 0; padding:0 0 0 0; list-style-type:none; } ' +
62
+ '.jstree li { display:block; min-height:'+height+'px; line-height:'+height+'px; white-space:nowrap; margin-left:18px; min-width:18px; } ' +
63
+ '.jstree-rtl li { margin-left:0; margin-right:18px; } ' +
64
+ '.jstree > ul > li { margin-left:0px; } ' +
65
+ '.jstree-rtl > ul > li { margin-right:0px; } ' +
66
+ '.jstree ins { display:inline-block; text-decoration:none; width:18px; height:'+height+'px; margin:0 0 0 0; padding:0; } ' +
67
+ '.jstree a { display:inline-block; line-height:'+height2+'px; height:'+height2+'px; color:black; white-space:nowrap; text-decoration:none; padding:1px 2px; margin:0; } ' +
68
+ '.jstree a:focus { outline: none; } ' +
69
+ '.jstree a > ins { height:'+ins_height+'px; width:16px; } ' +
70
+ '.jstree a > .jstree-icon { margin-right:3px; } ' +
71
+ '.jstree-rtl a > .jstree-icon { margin-left:3px; margin-right:0; } ' +
72
+ 'li.jstree-open > ul { display:block; } ' +
73
+ 'li.jstree-closed > ul { display:none; } ' +
74
+ '#vakata-dragged { background-color: white; };' +
75
+ '';
76
  $.vakata.css.add_sheet({
77
  str : css_string,
78
  title : "jstree_cms_tpv"
169
 
170
  /**
171
  * When tree is loaded: start hoverindenting stuff
 
172
  */
173
  function cms_tpv_tree_loaded(event, data) {
174
 
177
  // when mouse enters a/link
178
  // start timer and if no other a/link has been moused over since it started it's ok to show this one
179
  jQuery($container).on("mouseenter", "a", function(e) {
180
+
181
+ cms_tree_page_view.log("mouseenter container");
182
+
183
  var global_timer = $container.data("cmstpv_global_link_timer");
184
 
185
  if (global_timer) {
186
  // global timer exists, so overwrite it with our new one
187
  // stop that timer before setting ours
188
+ cms_tree_page_view.log("clear global timer");
189
  clearTimeout(global_timer);
190
  } else {
191
  // no timer exists, overwrite with ours
192
  }
193
+
194
  // create new timer, no matter if one exists already
195
+ cms_tree_page_view.log("add timer for mousover on link");
196
  var timeoutID = setTimeout(function(e) {
197
  cms_tpv_mouseover_li(e);
198
  }, 500, e);
202
  });
203
 
204
  /**
205
+ * When mouse down we may want to drag and drop,
206
+ * so hide the action div and cancel the timer
207
  */
208
  jQuery($container).on("mousedown", "a", function(e) {
209
+
210
+ cms_tree_page_view.log("mousedown a");
211
+
212
  var $target = jQuery(e.target);
213
  var $container = $target.closest("div.cms_tpv_container");
214
  var $wrapper = $container.closest("div.cms_tpv_wrapper");
215
+
216
  $container.find("li.has-visible-actions").removeClass("has-visible-actions");
217
  $container.find("a.hover").removeClass("hover");
218
  $wrapper.find("div.cms_tpv_page_actions").removeClass("cms_tpv_page_actions_visible");
219
+
220
+
221
+
222
  });
223
 
224
  }
427
  * hide actions div after moving mouse out of a page and not moving it on again for...a while
428
  */
429
  jQuery(document).on("mouseleave", "div.cms_tpv_container", function(e) {
430
+
431
+ cms_tree_page_view.log("mouseleave container");
432
 
433
  var $container = jQuery(e.target).closest("div.cms_tpv_container");
434
  var $wrapper = $container.closest("div.cms_tpv_wrapper");
437
  // reset global timer
438
  var global_timer = $container.data("cmstpv_global_link_timer");
439
  if (global_timer) {
440
+ cms_tree_page_view.log("clear global timer");
441
  clearTimeout(global_timer);
442
  }
443
 
444
  // hide popup after a short while
445
  var hideTimer = setTimeout(function() {
446
 
447
+ cms_tree_page_view.log("maybe hide popup because outside container");
448
+
449
  // But don't hide if we are inside the popup
450
+ var $relatedTarget = jQuery(e.relatedTarget);
451
+ if ($relatedTarget.hasClass("cms_tpv_page_actions")) {
452
  // we are over the actions div, so don't hide
453
+ cms_tree_page_view.log("cancel hide beacuse over actions div");
454
  } else {
455
  // somewhere else, do hide
456
+ cms_tree_page_view.log("do hide");
457
  $container.find("li.has-visible-actions").removeClass("has-visible-actions");
458
  $container.find("a.hover").removeClass("hover");
459
  $wrapper.find("div.cms_tpv_page_actions").removeClass("cms_tpv_page_actions_visible");
461
 
462
  }, 500);
463
 
464
+ // $container.data("cmstpv_global_hide_timer", hideTimer);
465
 
466
  });
467