Page scroll to id - Version 1.6.0

Version Description

  • Fixed contextual help shortcut links in plugin settings page.
  • Added new option 'Enable for all targets' for 'Scroll to location hash'.
  • Added new option 'Delay' for 'Scroll to location hash'.
  • Fixed an issue regarding invalid selectors with location hash.
  • Updated readme.txt.
  • Updated help.
Download this release

Release Info

Developer malihu
Plugin Icon 128x128 Page scroll to id
Version 1.6.0
Comparing to
See all releases

Code changes from version 1.5.9 to 1.6.0

includes/help/plugin-settings.inc CHANGED
@@ -87,7 +87,9 @@ $help_plugin_settings_text=<<<EOD
87
  <p>
88
  <strong>Scroll to location hash</strong> -
89
  Scrolls to target id (e.g. <code>&lt;div id="id" /&gt;</code>) based on location hash (e.g. <code>mysite.com/mypage#id</code>) on page load. <br />
90
- Enable when you need to scroll to an id in another page.
 
 
91
  </p>
92
 
93
  <p>
87
  <p>
88
  <strong>Scroll to location hash</strong> -
89
  Scrolls to target id (e.g. <code>&lt;div id="id" /&gt;</code>) based on location hash (e.g. <code>mysite.com/mypage#id</code>) on page load. <br />
90
+ Enable when you need to scroll to an id in another page. <br />
91
+ By default, this option will only work for target elements that are handled by the plugin (e.g. are connected to a link which scrolls the page via "Page scroll to id"). To enable the option for all targets (even for elements that are not handled by the plugin) check "Enable for all targets". <br />
92
+ To set an animation delay for "Scroll to location hash", use the "Delay" field and set a value which represents milliseconds (default value is 0 meaning no delay). For example, a value of <code>500</code> will delay page scrolling by half a second after the page has loaded.
93
  </p>
94
 
95
  <p>
includes/help/shortcodes.inc CHANGED
@@ -26,7 +26,7 @@ $help_shortcodes_text=<<<EOD
26
  </ul>
27
 
28
  <p>
29
- <strong>Create target</strong> - <code>[ps2id id='id' target='']</code>
30
  </p>
31
 
32
  <p>
@@ -37,18 +37,18 @@ $help_shortcodes_text=<<<EOD
37
  <li>
38
  <code>id</code> - target element id <br />
39
  Examples: <br />
40
- <code>[ps2id id='some-id']</code>
41
  </li>
42
  <li>
43
  <code>target</code> - the element that will be considered as the actual target (useful when you need proper highlighting with targets that have zero dimensions) <br />
44
  Examples: <br />
45
- <code>[ps2id id='some-id' target='#id + div']</code> - set the target as the next div from the #some-id element <br />
46
- <code>[ps2id id='some-id' target='#another-id']</code> - set the target as the element with id: another-id
47
  </li>
48
  </ul>
49
 
50
  <p>
51
- <strong>Create target wrapper</strong> - <code>[ps2id_wrap id='id']content[/ps2id_wrap]</code>
52
  </p>
53
 
54
  <p>
26
  </ul>
27
 
28
  <p>
29
+ <strong>Create target</strong> - <code>[ps2id id='id' target=''/]</code>
30
  </p>
31
 
32
  <p>
37
  <li>
38
  <code>id</code> - target element id <br />
39
  Examples: <br />
40
+ <code>[ps2id id='some-id'/]</code>
41
  </li>
42
  <li>
43
  <code>target</code> - the element that will be considered as the actual target (useful when you need proper highlighting with targets that have zero dimensions) <br />
44
  Examples: <br />
45
+ <code>[ps2id id='some-id' target='#id + div'/]</code> - set the target as the next div from the #some-id element <br />
46
+ <code>[ps2id id='some-id' target='#another-id'/]</code> - set the target as the element with id: another-id
47
  </li>
48
  </ul>
49
 
50
  <p>
51
+ <strong>Create target wrapper</strong> - <code>[ps2id_wrap id='id'] content... [/ps2id_wrap]</code>
52
  </p>
53
 
54
  <p>
js/admin.js CHANGED
@@ -187,7 +187,7 @@
187
  $("a[href='#tab-panel-page-scroll-to-id"+tab+"']").trigger("click");
188
  }else{
189
  if(!$("#contextual-help-wrap").is(":visible")){
190
- $("a#contextual-help-link").trigger("click");
191
  }
192
  }
193
  }else{
187
  $("a[href='#tab-panel-page-scroll-to-id"+tab+"']").trigger("click");
188
  }else{
189
  if(!$("#contextual-help-wrap").is(":visible")){
190
+ setTimeout(function(){ $("#contextual-help-link").trigger("click"); },60);
191
  }
192
  }
193
  }else{
js/jquery.malihu.PageScroll2id-init.js CHANGED
@@ -3,8 +3,9 @@
3
  _o=mPS2id_params,
4
  shortcodeClass=_o.shortcode_class, //shortcode without suffix
5
  _hash=location.hash || null,
6
- _validateLocHash=function(val){
7
- return $(val).length && $("a[href*='"+val+"']").filter(function(){return $(this).data(_p+"Element")==true}).length;
 
8
  },
9
  _offset=function(val){
10
  if(val.indexOf(",")!==-1){
@@ -29,7 +30,7 @@
29
  $(_o.instances[_p+"_instance_"+k]["selector"]["value"]+",."+shortcodeClass).each(function(){
30
  $(this).data(_p+"Element",true);
31
  });
32
- if(_validateLocHash(_hash)){
33
  var href=window.location.href.replace(/#.*$/,"#"),
34
  layout=_o.instances[_p+"_instance_"+k]["layout"]["value"];
35
  if(layout!=="horizontal"){
@@ -68,13 +69,15 @@
68
  });
69
  //scroll to location hash on page load
70
  if(_o.instances[_p+"_instance_"+i]["scrollToHash"]["value"]==="true" && _hash){
71
- if(_validateLocHash(_hash)){
72
- $.mPageScroll2id("scrollTo",_hash);
73
- if(window.history && window.history.pushState){
74
- window.history.pushState("","",_hash);
75
- }else{
76
- window.location.hash=_hash;
77
- }
 
 
78
  }
79
  }
80
  }
3
  _o=mPS2id_params,
4
  shortcodeClass=_o.shortcode_class, //shortcode without suffix
5
  _hash=location.hash || null,
6
+ _validateLocHash=function(val,forAll){
7
+ try{ var $val=$(val); }catch(error){ return false; } //avoid js errors on invalid selectors
8
+ return $(val).length && (forAll || $("a[href*='"+val+"']").filter(function(){return $(this).data(_p+"Element")==true}).length);
9
  },
10
  _offset=function(val){
11
  if(val.indexOf(",")!==-1){
30
  $(_o.instances[_p+"_instance_"+k]["selector"]["value"]+",."+shortcodeClass).each(function(){
31
  $(this).data(_p+"Element",true);
32
  });
33
+ if(_validateLocHash(_hash,_o.instances[_p+"_instance_"+k]["scrollToHashForAll"]["value"]==="true")){
34
  var href=window.location.href.replace(/#.*$/,"#"),
35
  layout=_o.instances[_p+"_instance_"+k]["layout"]["value"];
36
  if(layout!=="horizontal"){
69
  });
70
  //scroll to location hash on page load
71
  if(_o.instances[_p+"_instance_"+i]["scrollToHash"]["value"]==="true" && _hash){
72
+ if(_validateLocHash(_hash,_o.instances[_p+"_instance_"+i]["scrollToHashForAll"]["value"]==="true")){
73
+ setTimeout(function(){
74
+ $.mPageScroll2id("scrollTo",_hash);
75
+ if(window.history && window.history.pushState){
76
+ window.history.pushState("","",_hash);
77
+ }else{
78
+ window.location.hash=_hash;
79
+ }
80
+ },_o.instances[_p+"_instance_"+i]["scrollToHashDelay"]["value"]);
81
  }
82
  }
83
  }
malihu-pagescroll2id.php CHANGED
@@ -3,10 +3,12 @@
3
  Plugin Name: Page scroll to id
4
  Plugin URI: http://manos.malihu.gr/page-scroll-to-id
5
  Description: Page scroll to id is an easy-to-use jQuery plugin that enables animated page scrolling to specific id within the document.
6
- Version: 1.5.9
7
  Author: malihu
8
  Author URI: http://manos.malihu.gr
9
  License: MIT License (MIT)
 
 
10
  */
11
 
12
  /*
@@ -45,7 +47,7 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
45
 
46
  class malihuPageScroll2id{ // --edit--
47
 
48
- protected $version='1.5.9'; // Plugin version --edit--
49
  protected $update_option=null;
50
 
51
  protected $plugin_name='Page scroll to id'; // Plugin name --edit--
@@ -524,6 +526,8 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
524
  $d14='false';
525
  $d16='false';
526
  $d13='false';
 
 
527
  $d15=0;
528
  // Values
529
  switch($action){
@@ -544,6 +548,8 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
544
  $v14=(isset($_POST[$this->db_prefix.$i.'_keepHighlightUntilNext'])) ? 'true' : 'false';
545
  $v16=(isset($_POST[$this->db_prefix.$i.'_highlightByNextTarget'])) ? 'true' : 'false';
546
  $v13=(isset($_POST[$this->db_prefix.$i.'_scrollToHash'])) ? 'true' : 'false';
 
 
547
  $v15=$this->sanitize_input('text', $_POST[$this->db_prefix.$i.'_disablePluginBelow'], $d15);
548
  break;
549
  case 'upgrade':
@@ -573,6 +579,8 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
573
  $v14=(isset($j['keepHighlightUntilNext'])) ? $j['keepHighlightUntilNext']['value'] : $d14;
574
  $v16=(isset($j['highlightByNextTarget'])) ? $j['highlightByNextTarget']['value'] : $d16;
575
  $v13=(isset($j['scrollToHash'])) ? $j['scrollToHash']['value'] : $d13;
 
 
576
  $v15=(isset($j['disablePluginBelow'])) ? $j['disablePluginBelow']['value'] : $d15;
577
  break;
578
  default:
@@ -592,6 +600,8 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
592
  $v14=$d14;
593
  $v16=$d16;
594
  $v13=$d13;
 
 
595
  $v15=$d15;
596
  }
597
  // Options array
@@ -801,6 +811,30 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
801
  'description' => 'Scroll to target id (e.g. <code>&lt;div id="id" /&gt;</code>) based on location hash (e.g. <code>mysite.com/mypage#id</code>) on page load',
802
  'wrapper' => 'fieldset'
803
  ),
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
804
  'disablePluginBelow' => array(
805
  'value' => $v15,
806
  'values' => null,
3
  Plugin Name: Page scroll to id
4
  Plugin URI: http://manos.malihu.gr/page-scroll-to-id
5
  Description: Page scroll to id is an easy-to-use jQuery plugin that enables animated page scrolling to specific id within the document.
6
+ Version: 1.6.0
7
  Author: malihu
8
  Author URI: http://manos.malihu.gr
9
  License: MIT License (MIT)
10
+ Text Domain: page-scroll-to-id
11
+ Domain Path: /languages
12
  */
13
 
14
  /*
47
 
48
  class malihuPageScroll2id{ // --edit--
49
 
50
+ protected $version='1.6.0'; // Plugin version --edit--
51
  protected $update_option=null;
52
 
53
  protected $plugin_name='Page scroll to id'; // Plugin name --edit--
526
  $d14='false';
527
  $d16='false';
528
  $d13='false';
529
+ $d17='false';
530
+ $d18=0;
531
  $d15=0;
532
  // Values
533
  switch($action){
548
  $v14=(isset($_POST[$this->db_prefix.$i.'_keepHighlightUntilNext'])) ? 'true' : 'false';
549
  $v16=(isset($_POST[$this->db_prefix.$i.'_highlightByNextTarget'])) ? 'true' : 'false';
550
  $v13=(isset($_POST[$this->db_prefix.$i.'_scrollToHash'])) ? 'true' : 'false';
551
+ $v17=(isset($_POST[$this->db_prefix.$i.'_scrollToHashForAll'])) ? 'true' : 'false';
552
+ $v18=$this->sanitize_input('number', $_POST[$this->db_prefix.$i.'_scrollToHashDelay'], $d18);
553
  $v15=$this->sanitize_input('text', $_POST[$this->db_prefix.$i.'_disablePluginBelow'], $d15);
554
  break;
555
  case 'upgrade':
579
  $v14=(isset($j['keepHighlightUntilNext'])) ? $j['keepHighlightUntilNext']['value'] : $d14;
580
  $v16=(isset($j['highlightByNextTarget'])) ? $j['highlightByNextTarget']['value'] : $d16;
581
  $v13=(isset($j['scrollToHash'])) ? $j['scrollToHash']['value'] : $d13;
582
+ $v17=(isset($j['scrollToHashForAll'])) ? $j['scrollToHashForAll']['value'] : $d17;
583
+ $v18=(isset($j['scrollToHashDelay'])) ? $j['scrollToHashDelay']['value'] : $d18;
584
  $v15=(isset($j['disablePluginBelow'])) ? $j['disablePluginBelow']['value'] : $d15;
585
  break;
586
  default:
600
  $v14=$d14;
601
  $v16=$d16;
602
  $v13=$d13;
603
+ $v17=$d17;
604
+ $v18=$d18;
605
  $v15=$d15;
606
  }
607
  // Options array
811
  'description' => 'Scroll to target id (e.g. <code>&lt;div id="id" /&gt;</code>) based on location hash (e.g. <code>mysite.com/mypage#id</code>) on page load',
812
  'wrapper' => 'fieldset'
813
  ),
814
+ 'scrollToHashForAll' => array(
815
+ 'value' => $v17,
816
+ 'values' => null,
817
+ 'id' => $this->db_prefix.$i.'_scrollToHashForAll',
818
+ 'field_type' => 'checkbox',
819
+ 'label' => '',
820
+ 'checkbox_label' => 'Enable for all targets (even for elements that are not handled by the plugin)',
821
+ 'radio_labels' => null,
822
+ 'field_info' => null,
823
+ 'description' => null,
824
+ 'wrapper' => 'fieldset'
825
+ ),
826
+ 'scrollToHashDelay' => array(
827
+ 'value' => $v18,
828
+ 'values' => null,
829
+ 'id' => $this->db_prefix.$i.'_scrollToHashDelay',
830
+ 'field_type' => 'text-integer',
831
+ 'label' => '',
832
+ 'checkbox_label' => null,
833
+ 'radio_labels' => null,
834
+ 'field_info' => 'Delay (milliseconds)',
835
+ 'description' => 'Scroll to location hash animation delay in milliseconds (1000 milliseconds equals 1 second)',
836
+ 'wrapper' => null
837
+ ),
838
  'disablePluginBelow' => array(
839
  'value' => $v15,
840
  'values' => null,
readme.txt CHANGED
@@ -3,8 +3,8 @@ Contributors: malihu
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UYJ5G65M6ZA28
4
  Tags: page scrolling, page animation, navigation, single-page navigation
5
  Requires at least: 3.3
6
- Tested up to: 4.2.2
7
- Stable tag: 1.5.9
8
  License: The MIT License (MIT)
9
  License URI: http://opensource.org/licenses/MIT
10
 
@@ -20,6 +20,7 @@ The plugin replaces the default browser behaviour of "jumping" to page sections
20
  * Links and targets highlighting via ready-to-use classes
21
  * Auto-adjustable scroll-to position
22
  * Advanced scroll-to position offset (by pixels, by element selector, link specific offsets etc.)
 
23
 
24
  = Demo =
25
 
@@ -29,7 +30,7 @@ The plugin replaces the default browser behaviour of "jumping" to page sections
29
 
30
  = Requirements =
31
 
32
- Page scroll to id requires WordPress version **3.3** or higher and jQuery version **1.6.0** or higher. For older installations implement it in your theme manually.
33
 
34
  = Quick usage =
35
 
@@ -144,6 +145,14 @@ Yes but you probably need to implement the plugin in your theme **manually**. Se
144
 
145
  == Changelog ==
146
 
 
 
 
 
 
 
 
 
147
  = 1.5.9 =
148
  * Extended `ps2id` shortcode for creating `div` elements (in addition to anchors).
149
  * Added `ps2id_wrap` shortcode for creating target wrappers in content editor.
@@ -217,6 +226,10 @@ Yes but you probably need to implement the plugin in your theme **manually**. Se
217
 
218
  == Upgrade Notice ==
219
 
 
 
 
 
220
  = 1.5.9 =
221
 
222
  Extended `ps2id` shortcode, added `ps2id_wrap` shortcode, extended offset selector expressions, updated help and readme.txt.
3
  Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=UYJ5G65M6ZA28
4
  Tags: page scrolling, page animation, navigation, single-page navigation
5
  Requires at least: 3.3
6
+ Tested up to: 4.4
7
+ Stable tag: 1.6.0
8
  License: The MIT License (MIT)
9
  License URI: http://opensource.org/licenses/MIT
10
 
20
  * Links and targets highlighting via ready-to-use classes
21
  * Auto-adjustable scroll-to position
22
  * Advanced scroll-to position offset (by pixels, by element selector, link specific offsets etc.)
23
+ * Page scrolling from/to different pages (scrolling to location hash)
24
 
25
  = Demo =
26
 
30
 
31
  = Requirements =
32
 
33
+ Page scroll to id requires WordPress version **3.3** or higher and jQuery version **1.6.0** or higher. For older installations implement it in your theme [manually](http://manos.malihu.gr/page-scroll-to-id/). Your theme **must** (and should) have `wp_head()` and `wp_footer()` functions. In some MS Windows based web servers the plugin might produce an error 500 (depends on server/PHP configuration). To pinpoint the issue [enable debugging](https://codex.wordpress.org/Debugging_in_WordPress) in `wp-config.php` and check `wp-content/debug.log` file for relevant errors.
34
 
35
  = Quick usage =
36
 
145
 
146
  == Changelog ==
147
 
148
+ = 1.6.0 =
149
+ * Fixed contextual help shortcut links in plugin settings page.
150
+ * Added new option 'Enable for all targets' for 'Scroll to location hash'.
151
+ * Added new option 'Delay' for 'Scroll to location hash'.
152
+ * Fixed an issue regarding invalid selectors with location hash.
153
+ * Updated readme.txt.
154
+ * Updated help.
155
+
156
  = 1.5.9 =
157
  * Extended `ps2id` shortcode for creating `div` elements (in addition to anchors).
158
  * Added `ps2id_wrap` shortcode for creating target wrappers in content editor.
226
 
227
  == Upgrade Notice ==
228
 
229
+ = 1.6.0 =
230
+
231
+ Fixed some (minor) issues in admin and front-end, added new options (Enable for all targets' and 'Delay') for 'Scroll to location hash', updated help and readme.txt.
232
+
233
  = 1.5.9 =
234
 
235
  Extended `ps2id` shortcode, added `ps2id_wrap` shortcode, extended offset selector expressions, updated help and readme.txt.