Page scroll to id - Version 1.5.5

Version Description

  • Fixed contextual help links in plugin settings page.
  • Updated Offset field to accept comma separated values for defining different offsets for vertical and horizontal layout (e.g. 100,50).
  • Added 'Scroll to location hash' option. When enabled, the plugin will scroll to target id (e.g. <div id="id" />) based on location hash (e.g. mysite.com/mypage#id) on page load.
  • Updated readme.txt.
  • Updated help.
Download this release

Release Info

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

Code changes from version 1.5.4 to 1.5.5

includes/admin.php CHANGED
@@ -18,7 +18,7 @@ $toggle_instance_title=__('Click to toggle', $this->plugin_slug);
18
  <p class="plugin-info"><?php echo $plugin_info; ?></p>
19
  <p class="plugin-version">Version <?php echo $this->version; ?></p>
20
 
21
- <?php if(get_bloginfo('version') < '3.6') : ?>
22
  <div class="oldwp-plugin-help">
23
  <!-- --edit-- -->
24
  <div class="oldwp-plugin-help-section oldwp-plugin-help-section-overview">
18
  <p class="plugin-info"><?php echo $plugin_info; ?></p>
19
  <p class="plugin-version">Version <?php echo $this->version; ?></p>
20
 
21
+ <?php if(version_compare(get_bloginfo('version'), '3.6', '<')) : ?>
22
  <div class="oldwp-plugin-help">
23
  <!-- --edit-- -->
24
  <div class="oldwp-plugin-help-section oldwp-plugin-help-section-overview">
includes/help/plugin-settings.inc CHANGED
@@ -35,6 +35,7 @@ $help_plugin_settings_text=<<<EOD
35
  <strong>Offset</strong> -
36
  Defines the amount of pixels to offset the scroll-to position. The value can a be a positive or negative number, or a matching element in your html. For example, setting Offset to 50 will stop page scrolling 50 pixels before reaching the target. <br />
37
  If you need to offset scroll-to position accoring to the height or width of some element (e.g. accoring to a responsive, fixed-positioned navigation menu), insert its selector in the Offset field. For example, if you have a fixed menu with id <code>navigation-menu</code>, set Offset to <code>#navigation-menu</code> in order to stop page scrolling below it and avoid overlapping your content. <br />
 
38
  You may also define link specific offsets by using the <code>ps2id</code> shortcode in your content, e.g. <code>[ps2id url='#id' offset='100']link[/ps2id]</code>.
39
  </p>
40
 
@@ -60,6 +61,12 @@ $help_plugin_settings_text=<<<EOD
60
  By checking "Force single highlight", only one highlighted element is allowed at a time.
61
  </p>
62
 
 
 
 
 
 
 
63
  EOD;
64
  ?>
65
 
35
  <strong>Offset</strong> -
36
  Defines the amount of pixels to offset the scroll-to position. The value can a be a positive or negative number, or a matching element in your html. For example, setting Offset to 50 will stop page scrolling 50 pixels before reaching the target. <br />
37
  If you need to offset scroll-to position accoring to the height or width of some element (e.g. accoring to a responsive, fixed-positioned navigation menu), insert its selector in the Offset field. For example, if you have a fixed menu with id <code>navigation-menu</code>, set Offset to <code>#navigation-menu</code> in order to stop page scrolling below it and avoid overlapping your content. <br />
38
+ To set different vertical and horizontal offsets (e.g. when Layout is set to auto), add comma seperated values in Offset field, e.g. <code>100,50</code> (vertical offset 100, horizontal offset 50). <br />
39
  You may also define link specific offsets by using the <code>ps2id</code> shortcode in your content, e.g. <code>[ps2id url='#id' offset='100']link[/ps2id]</code>.
40
  </p>
41
 
61
  By checking "Force single highlight", only one highlighted element is allowed at a time.
62
  </p>
63
 
64
+ <p>
65
+ <strong>Scroll to location hash</strong> -
66
+ 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 />
67
+ Enable when you need to scroll to an id in another page.
68
+ </p>
69
+
70
  EOD;
71
  ?>
72
 
js/admin.js CHANGED
@@ -182,7 +182,7 @@
182
  });
183
 
184
  function openHelp(tab){
185
- if(wpVersion>=3.6){ //WP Contextual Help
186
  if(tab){
187
  $("a[href='#tab-panel-page-scroll-to-id"+tab+"']").trigger("click");
188
  }else{
182
  });
183
 
184
  function openHelp(tab){
185
+ if(parseFloat(wpVersion)>=3.6){ //WP Contextual Help
186
  if(tab){
187
  $("a[href='#tab-panel-page-scroll-to-id"+tab+"']").trigger("click");
188
  }else{
js/jquery.malihu.PageScroll2id-init.js CHANGED
@@ -1,24 +1,71 @@
1
  (function($){
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  $(window).load(function(){
3
- var _p="mPS2id",
4
- _o=mPS2id_params;
5
  for(var i=0; i<_o.total_instances; i++){
6
- var shortcodeClass=_o.shortcode_class; // Shortcode without suffix
7
- //var shortcodeClass=_o.shortcode_class+"_"+(i+1); // Shortcode with suffix
8
  $(_o.instances[_p+"_instance_"+i]["selector"]["value"]+",."+shortcodeClass).mPageScroll2id({
9
  scrollSpeed:_o.instances[_p+"_instance_"+i]["scrollSpeed"]["value"],
10
- autoScrollSpeed:(_o.instances[_p+"_instance_"+i]["autoScrollSpeed"]["value"] === "true") ? true : false,
11
  scrollEasing:_o.instances[_p+"_instance_"+i]["scrollEasing"]["value"],
12
  scrollingEasing:_o.instances[_p+"_instance_"+i]["scrollingEasing"]["value"],
13
- pageEndSmoothScroll:(_o.instances[_p+"_instance_"+i]["pageEndSmoothScroll"]["value"] === "true") ? true : false,
14
  layout:_o.instances[_p+"_instance_"+i]["layout"]["value"],
15
- offset:_o.instances[_p+"_instance_"+i]["offset"]["value"],
16
  highlightSelector:_o.instances[_p+"_instance_"+i]["highlightSelector"]["value"],
17
  clickedClass:_o.instances[_p+"_instance_"+i]["clickedClass"]["value"],
18
  targetClass:_o.instances[_p+"_instance_"+i]["targetClass"]["value"],
19
  highlightClass:_o.instances[_p+"_instance_"+i]["highlightClass"]["value"],
20
- forceSingleHighlight:(_o.instances[_p+"_instance_"+i]["forceSingleHighlight"]["value"] === "true") ? true : false
21
  });
 
 
 
 
 
 
 
 
 
 
 
22
  }
23
  });
24
  })(jQuery);
1
  (function($){
2
+ var _p="mPS2id",
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){
11
+ var arr=val.split(","),y=arr[0] || "0",x=arr[1] || "0";
12
+ return {"y":y,"x":x};
13
+ }else{
14
+ return val;
15
+ }
16
+ };
17
+ $(document).ready(function(){
18
+ for(var k=0; k<_o.total_instances; k++){
19
+ //scroll to location hash on page load
20
+ if(_o.instances[_p+"_instance_"+k]["scrollToHash"]["value"]==="true" && _hash){
21
+ $(_o.instances[_p+"_instance_"+k]["selector"]["value"]+",."+shortcodeClass).each(function(){
22
+ $(this).data(_p+"Element",true);
23
+ });
24
+ if(_validateLocHash(_hash)){
25
+ var href=window.location.href.replace(/#.*$/,"#"),
26
+ layout=_o.instances[_p+"_instance_"+k]["layout"]["value"];
27
+ if(layout!=="horizontal"){
28
+ $(window).scrollTop(0); //stop jump to hash straight away
29
+ }
30
+ if(layout!=="vertical"){
31
+ $(window).scrollLeft(0); //stop jump to hash straight away
32
+ }
33
+ if(window.history && window.history.pushState){
34
+ window.history.pushState("","",href);
35
+ }else{
36
+ window.location.href=href;
37
+ }
38
+ }
39
+ }
40
+ }
41
+ });
42
  $(window).load(function(){
 
 
43
  for(var i=0; i<_o.total_instances; i++){
 
 
44
  $(_o.instances[_p+"_instance_"+i]["selector"]["value"]+",."+shortcodeClass).mPageScroll2id({
45
  scrollSpeed:_o.instances[_p+"_instance_"+i]["scrollSpeed"]["value"],
46
+ autoScrollSpeed:(_o.instances[_p+"_instance_"+i]["autoScrollSpeed"]["value"]==="true") ? true : false,
47
  scrollEasing:_o.instances[_p+"_instance_"+i]["scrollEasing"]["value"],
48
  scrollingEasing:_o.instances[_p+"_instance_"+i]["scrollingEasing"]["value"],
49
+ pageEndSmoothScroll:(_o.instances[_p+"_instance_"+i]["pageEndSmoothScroll"]["value"]==="true") ? true : false,
50
  layout:_o.instances[_p+"_instance_"+i]["layout"]["value"],
51
+ offset:_offset(_o.instances[_p+"_instance_"+i]["offset"]["value"].toString()),
52
  highlightSelector:_o.instances[_p+"_instance_"+i]["highlightSelector"]["value"],
53
  clickedClass:_o.instances[_p+"_instance_"+i]["clickedClass"]["value"],
54
  targetClass:_o.instances[_p+"_instance_"+i]["targetClass"]["value"],
55
  highlightClass:_o.instances[_p+"_instance_"+i]["highlightClass"]["value"],
56
+ forceSingleHighlight:(_o.instances[_p+"_instance_"+i]["forceSingleHighlight"]["value"]==="true") ? true : false
57
  });
58
+ //scroll to location hash on page load
59
+ if(_o.instances[_p+"_instance_"+i]["scrollToHash"]["value"]==="true" && _hash){
60
+ if(_validateLocHash(_hash)){
61
+ $.mPageScroll2id("scrollTo",_hash);
62
+ if(window.history && window.history.pushState){
63
+ window.history.pushState("","",_hash);
64
+ }else{
65
+ window.location.hash=_hash;
66
+ }
67
+ }
68
+ }
69
  }
70
  });
71
  })(jQuery);
malihu-pagescroll2id.php CHANGED
@@ -3,7 +3,7 @@
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.4
7
  Author: malihu
8
  Author URI: http://manos.malihu.gr
9
  License: MIT License (MIT)
@@ -45,7 +45,7 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
45
 
46
  class malihuPageScroll2id{ // --edit--
47
 
48
- protected $version='1.5.4'; // Plugin version --edit--
49
  protected $update_option=null;
50
 
51
  protected $plugin_name='Page scroll to id'; // Plugin name --edit--
@@ -64,8 +64,13 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
64
  protected $plugin_init_script='jquery.malihu.PageScroll2id-init.js'; // Plugin public initialization script --edit--
65
 
66
  private function __construct(){
 
 
 
 
 
67
  // Plugin requires WP version 3.3 or higher
68
- if(get_bloginfo('version') < '3.3'){
69
  add_action('admin_notices', array($this, 'admin_notice_wp_version'));
70
  return;
71
  }
@@ -100,6 +105,11 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
100
  return self::$instance;
101
  }
102
 
 
 
 
 
 
103
  // WP version notice
104
  public function admin_notice_wp_version(){
105
  _e('<div class="error"><p><strong>'.$this->plugin_name.'</strong> requires WordPress version <strong>3.3</strong> or higher. Deactivate the plugin and reactivate when WordPress is updated.</p></div>', $this->plugin_slug);
@@ -485,6 +495,7 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
485
  $d10='mPS2id-target';
486
  $d11='mPS2id-highlight';
487
  $d12='false';
 
488
  // Values
489
  switch($action){
490
  case 'validate':
@@ -501,6 +512,7 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
501
  $v10=$this->sanitize_input('class', $_POST[$this->db_prefix.$i.'_targetClass'], $d10);
502
  $v11=$this->sanitize_input('class', $_POST[$this->db_prefix.$i.'_highlightClass'], $d11);
503
  $v12=(isset($_POST[$this->db_prefix.$i.'_forceSingleHighlight'])) ? 'true' : 'false';
 
504
  break;
505
  case 'upgrade':
506
  if(isset($old)){
@@ -526,6 +538,7 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
526
  $v10=(isset($j['targetClass'])) ? $j['targetClass']['value'] : $d10;
527
  $v11=(isset($j['highlightClass'])) ? $j['highlightClass']['value'] : $d11;
528
  $v12=(isset($j['forceSingleHighlight'])) ? $j['forceSingleHighlight']['value'] : $d12;
 
529
  break;
530
  default:
531
  $v0=$d0;
@@ -541,6 +554,7 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
541
  $v10=$d10;
542
  $v11=$d11;
543
  $v12=$d12;
 
544
  }
545
  // Options array
546
  /*
@@ -712,6 +726,18 @@ if(!class_exists('malihuPageScroll2id')){ // --edit--
712
  'field_info' => null,
713
  'description' => 'Allow only one highlighted element at a time',
714
  'wrapper' => 'fieldset'
 
 
 
 
 
 
 
 
 
 
 
 
715
  )
716
  );
717
  }
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.5
7
  Author: malihu
8
  Author URI: http://manos.malihu.gr
9
  License: MIT License (MIT)
45
 
46
  class malihuPageScroll2id{ // --edit--
47
 
48
+ protected $version='1.5.5'; // Plugin version --edit--
49
  protected $update_option=null;
50
 
51
  protected $plugin_name='Page scroll to id'; // Plugin name --edit--
64
  protected $plugin_init_script='jquery.malihu.PageScroll2id-init.js'; // Plugin public initialization script --edit--
65
 
66
  private function __construct(){
67
+ // Plugin requires PHP version 5.2 or higher
68
+ if(version_compare(PHP_VERSION, '5.2', '<')){
69
+ add_action('admin_notices', array($this, 'admin_notice_php_version'));
70
+ return;
71
+ }
72
  // Plugin requires WP version 3.3 or higher
73
+ if(version_compare(get_bloginfo('version'), '3.3', '<')){
74
  add_action('admin_notices', array($this, 'admin_notice_wp_version'));
75
  return;
76
  }
105
  return self::$instance;
106
  }
107
 
108
+ // PHP version notice
109
+ public function admin_notice_php_version(){
110
+ _e('<div class="error"><p><strong>'.$this->plugin_name.'</strong> requires PHP version <strong>5.2</strong> or higher.</p></div>', $this->plugin_slug);
111
+ }
112
+
113
  // WP version notice
114
  public function admin_notice_wp_version(){
115
  _e('<div class="error"><p><strong>'.$this->plugin_name.'</strong> requires WordPress version <strong>3.3</strong> or higher. Deactivate the plugin and reactivate when WordPress is updated.</p></div>', $this->plugin_slug);
495
  $d10='mPS2id-target';
496
  $d11='mPS2id-highlight';
497
  $d12='false';
498
+ $d13='false';
499
  // Values
500
  switch($action){
501
  case 'validate':
512
  $v10=$this->sanitize_input('class', $_POST[$this->db_prefix.$i.'_targetClass'], $d10);
513
  $v11=$this->sanitize_input('class', $_POST[$this->db_prefix.$i.'_highlightClass'], $d11);
514
  $v12=(isset($_POST[$this->db_prefix.$i.'_forceSingleHighlight'])) ? 'true' : 'false';
515
+ $v13=(isset($_POST[$this->db_prefix.$i.'_scrollToHash'])) ? 'true' : 'false';
516
  break;
517
  case 'upgrade':
518
  if(isset($old)){
538
  $v10=(isset($j['targetClass'])) ? $j['targetClass']['value'] : $d10;
539
  $v11=(isset($j['highlightClass'])) ? $j['highlightClass']['value'] : $d11;
540
  $v12=(isset($j['forceSingleHighlight'])) ? $j['forceSingleHighlight']['value'] : $d12;
541
+ $v13=(isset($j['scrollToHash'])) ? $j['scrollToHash']['value'] : $d13;
542
  break;
543
  default:
544
  $v0=$d0;
554
  $v10=$d10;
555
  $v11=$d11;
556
  $v12=$d12;
557
+ $v13=$d13;
558
  }
559
  // Options array
560
  /*
726
  'field_info' => null,
727
  'description' => 'Allow only one highlighted element at a time',
728
  'wrapper' => 'fieldset'
729
+ ),
730
+ 'scrollToHash' => array(
731
+ 'value' => $v13,
732
+ 'values' => null,
733
+ 'id' => $this->db_prefix.$i.'_scrollToHash',
734
+ 'field_type' => 'checkbox',
735
+ 'label' => 'Scroll to location hash',
736
+ 'checkbox_label' => 'Enable',
737
+ 'radio_labels' => null,
738
+ 'field_info' => null,
739
+ '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',
740
+ 'wrapper' => 'fieldset'
741
  )
742
  );
743
  }
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: 3.8.1
7
- Stable tag: 1.5.4
8
  License: The MIT License (MIT)
9
  License URI: http://opensource.org/licenses/MIT
10
 
@@ -86,7 +86,7 @@ Make sure your link has href value `#` with the id of the section you want to sc
86
 
87
  = How do I make my links work from other/different pages =
88
 
89
- To make your links work from any page, you need to add the full address in your links href (instead of just the hash with the id). For example, you'll need to change `<a href="#id" rel="m_PageScroll2id">link</a>` to something like `<a href="http://mysite.com/some-page/#id" rel="m_PageScroll2id">link</a>`. The same applies for your WP custom menus. You'll need to insert the full address in the `URL` field.
90
 
91
  = The page doesn't scroll exactly where I want =
92
 
@@ -100,6 +100,10 @@ Your target element is probably not at the very top (check its position via your
100
 
101
  Insert your menu selector in the Offset field in plugin settings. For example, if you have a fixed menu with id `navigation-menu`, set Offset to `#navigation-menu` in order to stop page scrolling below it and avoid overlapping your content.
102
 
 
 
 
 
103
  = Can I specify link specific offset values? =
104
 
105
  Yes, by adding the html attribute `data-ps2id-offset` to a link. For example, `<a href="#id" rel="m_PageScroll2id" data-ps2id-offset="100">link</a>` will offset scroll-to position by 100 pixels. You may also use the `ps2id` shortcode to create links with specific offsets, e.g. `[ps2id url='#id' offset='100']link[/ps2id]`.
@@ -124,10 +128,17 @@ Yes but you probably need to implement the plugin in your theme **manually**. Se
124
 
125
  == Changelog ==
126
 
 
 
 
 
 
 
 
127
  = 1.5.4 =
128
  * Fixed a minor bug in jquery.malihu.PageScroll2id-init.js.
129
- * updated screenshots.
130
- * updated readme.txt.
131
 
132
  = 1.5.3 =
133
  * Extended Offset option to accept element selectors in addition to fixed pixels values.
@@ -169,6 +180,10 @@ Yes but you probably need to implement the plugin in your theme **manually**. Se
169
 
170
  == Upgrade Notice ==
171
 
 
 
 
 
172
  = 1.5.4 =
173
 
174
  Fixed a minor bug in jquery.malihu.PageScroll2id-init.js, updated screenshots 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: 3.9
7
+ Stable tag: 1.5.5
8
  License: The MIT License (MIT)
9
  License URI: http://opensource.org/licenses/MIT
10
 
86
 
87
  = How do I make my links work from other/different pages =
88
 
89
+ To make your links work from any page, you need to add the full address in your links href (instead of just the hash with the id). For example, you'll need to change `<a href="#id" rel="m_PageScroll2id">link</a>` to something like `<a href="http://mysite.com/some-page/#id" rel="m_PageScroll2id">link</a>`. The same applies for your WP custom menus. You'll need to insert the full address in the `URL` field. To enable page scrolling to URL location hash on page load, check `Scroll to location hash` in plugin settings.
90
 
91
  = The page doesn't scroll exactly where I want =
92
 
100
 
101
  Insert your menu selector in the Offset field in plugin settings. For example, if you have a fixed menu with id `navigation-menu`, set Offset to `#navigation-menu` in order to stop page scrolling below it and avoid overlapping your content.
102
 
103
+ = Can I set different vertical and horizontal offsets? =
104
+
105
+ Yes, by inserting comma separated values in `Offset` field For example `100,50` will set vertical offset to 100 and horizontal offset to 50 pixels.
106
+
107
  = Can I specify link specific offset values? =
108
 
109
  Yes, by adding the html attribute `data-ps2id-offset` to a link. For example, `<a href="#id" rel="m_PageScroll2id" data-ps2id-offset="100">link</a>` will offset scroll-to position by 100 pixels. You may also use the `ps2id` shortcode to create links with specific offsets, e.g. `[ps2id url='#id' offset='100']link[/ps2id]`.
128
 
129
  == Changelog ==
130
 
131
+ = 1.5.5 =
132
+ * Fixed contextual help links in plugin settings page.
133
+ * Updated Offset field to accept comma separated values for defining different offsets for vertical and horizontal layout (e.g. `100,50`).
134
+ * Added 'Scroll to location hash' option. When enabled, the plugin will scroll to target id (e.g. `<div id="id" />`) based on location hash (e.g. `mysite.com/mypage#id`) on page load.
135
+ * Updated readme.txt.
136
+ * Updated help.
137
+
138
  = 1.5.4 =
139
  * Fixed a minor bug in jquery.malihu.PageScroll2id-init.js.
140
+ * Updated screenshots.
141
+ * Updated readme.txt.
142
 
143
  = 1.5.3 =
144
  * Extended Offset option to accept element selectors in addition to fixed pixels values.
180
 
181
  == Upgrade Notice ==
182
 
183
+ = 1.5.5 =
184
+
185
+ Fixed contextual help links in plugin settings, define different offsets for vertical and horizontal layout, Added 'Scroll to location hash' option, updated readme.txt.
186
+
187
  = 1.5.4 =
188
 
189
  Fixed a minor bug in jquery.malihu.PageScroll2id-init.js, updated screenshots and readme.txt.