Permalink
Browse files

scrollto: updateing docs with example usage

  • Loading branch information...
arschmitz committed Dec 4, 2012
1 parent be7ff25 commit 5a5c94bcac5b5d98eddcbc99ed89c08b5c29c734
Showing with 62 additions and 37 deletions.
  1. +40 −15 docs/_assets/js/jqm-docs.js
  2. +16 −16 docs/forms/slider/index.html
  3. +6 −6 docs/forms/slider/options.html
@@ -1,27 +1,52 @@
//collapse page navs after use
$(function(){
- $( document ).bind('pageshow',function(){
- var match,
- pos,
- urlParams = {},
- pl = /\+/g, // Regex for replacing addition symbol with a space
- search = /([^&=]+)=?([^&]*)/g,
- decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
- query = window.location.search.substring(1);
-
+ //this is to allow deeplinks to id's from external pages and from same page links
+ //this will not currently work for multi-page documents if this is needed in the
+ //future it can be added at that time.
+ $.widget( "mobile.scrollto", $.mobile.widget, {
+ options: {
+ initSelector: ":jqmData(scrollto='true')"
+ },
+ _create: function(){
+ this.element.attr('data-ajax',false);
+ this._on({
+ "click":function(event){
+ var id = this.element.attr('href'),
+ pos = (id === "top")? this.element.closest(".ui-page-active").offset().top:$(id).offset().top;
+ $.mobile.silentScroll( pos );
+ return false;
+ }
+ });
+ },
+ _destroy:function(){
+ this.element.removeAttr("data-ajax");
+ }
+ });
+
+ //auto self-init widget
+ $( document ).bind( "pagecreate create", function( e ) {
+ $.mobile.scrollto.prototype.enhanceWithin( e.target );
+ });
+ $( document ).bind( "pageshow", function(){
+ var match, pos,
+ urlParams = {},
+ pl = /\+/g, // Regex for replacing addition symbol with a space
+ search = /([^&=]+)=?([^&]*)/g,
+ decode = function (s) { return decodeURIComponent(s.replace( pl, " " )); },
+ query = window.location.search.substring(1);
+
while (match = search.exec(query)){
urlParams[decode(match[1])] = decode(match[2]);
}
- if(typeof urlParams.scrollTo !== "undefined"){
+ if( typeof urlParams.scrollto !== "undefined" ){
- pos = $("#"+urlParams.scrollTo).offset().top;
- console.log(pos);
- setTimeout(function(){
+ pos = $("#"+urlParams.scrollto).offset().top;
+ setTimeout( function() {
$.mobile.silentScroll( pos );
- },100);
+ }, 0);
}
- });
+ });
$('body').delegate('.content-secondary .ui-collapsible-content', 'click', function(){
$(this).trigger("collapse");
});
@@ -35,13 +35,12 @@ <h2>Slider</h2>
</ul>
<div>
Jump To:
- <a href="#step-increment" data-scrolllink="true" >Step Increment</a>,
- <a href="#fill-highlight" data-scrolllink="true" >Fill Highlight</a>,
- <a href="#mini-version" data-scrolllink="true" >Mini version</a>,
- <a href="#field-containers" data-scrolllink="true" >Field Containers</a>,
- <a href="#calling-slider" data-scrolllink="true" >Calling the slider</a>,
- <a href="#theme-slider" data-scrolllink="true" >Theming the slider</a>,
- <a href="#field-containers" data-scrolllink="true" >Field Containers</a>,
+ <a href="#step-increment" data-scrollto="true" >Step Increment</a>,
+ <a href="#fill-highlight" data-scrollto="true" >Fill Highlight</a>,
+ <a href="#mini-version" data-scrollto="true" >Mini version</a>,
+ <a href="#field-containers" data-scrollto="true" >Field Containers</a>,
+ <a href="#calling-slider" data-scrollto="true" >Calling the slider</a>,
+ <a href="#theme-slider" data-scrollto="true" >Theming the slider</a>
</div>
<p>To add a slider widget to your page, use a standard <code>input</code> with the <code>type="range"</code> attribute. The input's <code>value</code> is used to configure the starting position of the handle and the value is populated in the text input. Specify <code>min</code> and <code>max</code> attribute values to set the slider's range. If you want to constrain input to specific increments, add the <code>step</code> attribute. Set the <code>value</code> attribute to define the initial value. The framework will parse these attributes to configure the slider widget. View the <a href="../../api/data-attributes.html">data- attribute reference</a> to see all the possible attributes you can add to sliders.</p>
@@ -58,7 +57,7 @@ <h2>Slider</h2>
<p>The default slider with these settings is displayed like this:</p>
<label for="slider-1">Input slider:</label>
<input type="range" name="slider-1" id="slider-1" value="60" min="0" max="100" />
-
+ <br/><br/><a href="top" data-scrollto="true">return to top</a>
<h2 id="step-increment">Step increment</h2>
<p>To force the slider to snap to a specific increment, add the <code>step</code> attribute to the input. By default, the step is 1, but in this example, the step is 50 and the maximum value is 500.</p>
@@ -72,10 +71,10 @@ <h2 id="step-increment">Step increment</h2>
<label for="slider-step">Input slider:</label>
<input type="range" name="slider-step" id="slider-step" value="150" min="0" max="500" step="50" />
-
+ <br/><br/><a href="top" data-scrollto="true">return to top</a>
<h2 id="fill-highlight">Fill highlight</h2>
- <p>To have a highlight fill on the track up to the slider handle position, add the <code>data-highlight="true"</code> attribute to the input. The fill uses the active state swatch. </p>
+ <p>To have a highlight fill on the track up to the slider handle position, add the <a href="options.html?scrollto=option-highlight"><code>data-highlight="true"</code></a> attribute to the input. The fill uses the active state swatch. </p>
<pre><code>
&lt;label for=&quot;slider-fill&quot;&gt;Input slider:&lt;/label&gt;
@@ -85,10 +84,10 @@ <h2 id="fill-highlight">Fill highlight</h2>
<label for="slider-fill">Input slider:</label>
<input type="range" name="slider-fill" id="slider-fill" value="60" min="0" max="100" data-highlight="true" />
-
+ <br/><br/><a href="top" data-scrollto="true">return to top</a>
<h2 id="mini-version">Mini version</h2>
- <p>For a more compact version that is useful in toolbars and tight spaces, add the <code>data-mini="true"</code> attribute to the element to create a <a href="../forms-all-mini.html">mini version</a>. </p>
+ <p>For a more compact version that is useful in toolbars and tight spaces, add the <a href="options.html?scrollto=option-mini"><code>data-mini="true"</code></a> attribute to the element to create a <a href="../forms-all-mini.html">mini version</a>. </p>
<pre><code>
&lt;label for=&quot;slider-mini&quot;&gt;Input slider:&lt;/label&gt;
@@ -98,7 +97,7 @@ <h2 id="mini-version">Mini version</h2>
<p>This will produce a slider and its corresponding input that are not as tall as the standard version. The input also has a smaller text size.</p>
<label for="slider-mini">Input slider:</label>
<input type="range" name="slider-mini" id="slider-mini" value="25" min="0" max="100" data-highlight="true" data-mini="true" />
-
+ <br/><br/><a href="top" data-scrollto="true">return to top</a>
<h2 id="field-containers">Field containers</h2>
<p>Optionally wrap the slider markup in a container with the <code>data-role="fieldcontain"</code> attribute to help visually group it in a longer form. In this example, the <code>step</code> attribute is omitted to allow any whole number value to be selected.</p>
@@ -119,17 +118,17 @@ <h2 id="field-containers">Field containers</h2>
<p>Sliders also respond to key commands. Right Arrow, Up Arrow and Page Up keys increase the value; Left Arrow, Down Arrow and Page Down keys decrease it. To move the slider to its minimum or maximum value, use the Home or End key, respectively.</p>
-
+ <br/><br/><a href="top" data-scrollto="true">return to top</a>
<h2 id="calling-slider">Calling the slider plugin</h2>
<p>This plugin will auto initialize on any page that contains a text <code>input</code> with the <code>type="range"</code> attribute. However, if needed you can directly call the <code>slider</code> plugin on any selector, just like any jQuery plugin:</p>
<pre><code>
$('input').slider();
</code></pre>
-
+ <br/><br/><a href="top" data-scrollto="true">return to top</a>
<h2 id="theme-slider">Theming the slider</h2>
- <p>To set the theme swatch for the slider, add a <code>data-theme</code> attribute to the <code>input</code> which will apply the theme to both the input, handle and track. The track swatch can be set separately by adding the <code>data-track-theme</code> attribute to apply the down state version of the selected button swatch.</p>
+ <p>To set the theme swatch for the slider, add a <a href="options.html?scrollto=option-theme"><code>data-theme</code></a> attribute to the <code>input</code> which will apply the theme to both the input, handle and track. The track swatch can be set separately by adding the <a href="options.html?scrollto=option-track-theme"><code>data-track-theme</code></a> attribute to apply the down state version of the selected button swatch.</p>
<pre><code>
&lt;div data-role=&quot;fieldcontain&quot;&gt;
@@ -143,6 +142,7 @@ <h2 id="theme-slider">Theming the slider</h2>
<label for="slider-3">Input slider:</label>
<input type="range" name="slider-3" id="slider-3" value="25" min="0" max="100" data-theme="a" data-track-theme="b" />
</div>
+ <br/><br/><a href="top" data-scrollto="true">return to top</a>
</form>
</div><!--/content-primary -->
@@ -38,21 +38,21 @@ <h2>Slider</h2>
<p>The slider plugin has the following options:</p>
<dl>
- <dt><code>disabled</code> <em>boolean</em></dt>
+ <dt id="option-disabled"><code>disabled</code> <em>boolean</em></dt>
<dd>
<p class="default">default: false</p>
<p>Sets the default state of the slider to disabled when "true".</p>
<pre><code>$('.selector').slider(<strong>{ disabled: true }</strong>);</code></pre>
</dd>
- <dt><code>highlight</code> <em>boolean</em></dt>
+ <dt id="option-highlight"><code>highlight</code> <em>boolean</em></dt>
<dd>
<p class="default">default: false</p>
<p>Sets an active state fill on the track from the left edge to the slider handle when set to "true".</p>
<pre><code>$('.selector').slider(<strong>{ highlight: true }</strong>);</code></pre>
</dd>
- <dt><code>initSelector</code> <em>CSS selector string</em></dt>
+ <dt id="option-initselector"><code>initSelector</code> <em>CSS selector string</em></dt>
<dd>
<p class="default">default: "input[type='range'], :jqmData(type='range'), :jqmData(role='slider')"</p>
<p>This is used to define the selectors (element types, data roles, etc.) that will automatically be initialized as sliders. To change which elements are initialized, bind this option to the <a href="../../api/globalconfig.html">mobileinit event</a>:</p>
@@ -62,21 +62,21 @@ <h2>Slider</h2>
</code></pre>
</dd>
- <dt><code>mini</code> <em>boolean</em></dt>
+ <dt id="option-mini"><code>mini</code> <em>boolean</em></dt>
<dd>
<p class="default">default: false</p>
<p>Sets the size of the element to a more compact, <a href="../forms-all-mini.html">mini version</a>. This option is also exposed as a data attribute: <code>data-mini=&quot;true&quot;</code></p>
<pre><code>$('.selector').slider(<strong>{ mini: true }</strong>);</code></pre>
</dd>
- <dt><code>theme</code> <em>string</em></dt>
+ <dt id="option-theme"><code>theme</code> <em>string</em></dt>
<dd>
<p class="default">default: null, inherited from parent</p>
<p>Sets the color scheme (swatch) for all instances of this widget. It accepts a single letter from a-z that maps to one of the swatches included in your theme. By default, it will inherit the same swatch color as its parent container if not explicitly set. This option is also exposed as a data attribute: <code>data-theme=&quot;a&quot;</code></p>
<pre><code>$('.selector').slider(<strong>{ theme: "a" }</strong>);</code></pre>
</dd>
- <dt><code>trackTheme</code> <em>string</em></dt>
+ <dt id="option-track-theme"><code>trackTheme</code> <em>string</em></dt>
<dd>
<p class="default">default: null, inherited from parent</p>
<p>Sets the color scheme (swatch) for the slider's track, specifically. It accepts a single letter from a-z that maps to one of the swatches included in your theme.</p>

0 comments on commit 5a5c94b

Please sign in to comment.