Adding the files that should’ve been added yesterday.

This commit is contained in:
Mat Marquis 2011-12-01 14:15:16 -05:00 committed by scottjehl
parent c37d5dc522
commit 5a839f0633
2 changed files with 134 additions and 0 deletions

View file

@ -0,0 +1,73 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery Mobile Framework - Dialog Example</title>
<link rel="stylesheet" href="../../css/themes/default/" />
<link rel="stylesheet" href="../_assets/css/jqm-docs.css"/>
<script src="../../js/jquery.js"></script>
<script src="../../experiments/themeswitcher/jquery.mobile.themeswitcher.js"></script>
<script src="../_assets/js/jqm-docs.js"></script>
<script src="../../js/"></script>
</head>
<body>
<div data-role="page">
<div data-role="content">
<h2>AJAX Fetch Links</h2>
<p>A <a href="dialog.html">standard link</a> with a href pointing to a local anchor (#foo) or external page (foo.html) will trigger a full animated page change via the AJAX nav system with the default transition.</p>
<pre><code>&lt;a href=&quot;dialog.html&quot;&gt;Link&lt;/a&gt;
</code></pre>
<p>A <a href="dialog.html" data-rel="dialog">dialog</a> is made by adding <code>data-rel="dialog"</code> to a link to display the page with an inset appearance and the default dialog transition.</p>
<pre><code>&lt;a href=&quot;dialog.html&quot; <strong>data-rel=&quot;dialog&quot;</strong>&gt;Link&lt;/a&gt;
</code></pre>
<p>Note: The below example temporary contains a <code>data-fragment</code> attribute.</p>
<p>A <a data-role="fetchlink" data-target=".quote" href="dialog.html" data-fragment=".test">fetch link</a> is created by adding the <code>data-target</code> attribute to a link. This tells the framework to <strong>not</strong> change pages and instead load the <code>href</code> into the target DOM element on the current page when the link is clicked. The target can be any jQuery selector (or restrict to ID only?). </p>
<pre><code>&lt;a href=&quot;dialog.html&quot; <strong>data-target=&quot;.quote&quot;</strong>&gt;
</code></pre>
<p>The <a data-role="fetchlink" href="dialog.html" data-target=".quote" data-method="before">target method</a> for a link can be specified by adding the <code>data-method</code> attribute to a link. This specifies whether to <code>replace</code>, <code>append</code>, <code>prepend</code>, or insert the content <code>before</code> or <code>after</code> the target element. By default, an external href will replace the target.</p>
<pre><code>&lt;a href=&quot;dialog.html&quot; data-target=&quot;.quote&quot; <strong>data-method=&quot;append&quot;</strong>&gt;
</code></pre>
<p>The <a href="dialog.html" data-role="fetchlink" data-target=".quote" data-fragment="[data-role='content']">content fragment</a> from the loaded page can be specified. By default, the framework will load in the contents of the <code>data-role=&quot;page&quot;</code> container, but it's possible to specify content from the page to pull into the target by adding a <code>data-fragment</code> attribute to the link with any jQuery selector.</p>
<pre><code>&lt;a href=&quot;dialog.html&quot; data-target=&quot;.quote&quot; <strong>data-fragment=&quot;#content&quot;</strong>&gt;
</code></pre>
<p>A <a href="dialog.html" data-role="fetchlink" data-target=".quote" data-breakpoint="500" data-breakpoint="400">breakpoint option</a> will automatically load the fetch link if the screen width is larger than the specified value instead of waiting for the link to be clicked. The <code>data-breakpoint</code> attribute on the link specifies the min-width pixel value to load the link.</p>
<pre><code>&lt;a href=&quot;dialog.html&quot; data-target=&quot;.quote&quot; <strong>data-breakpoint=&quot;500&quot;</strong>&gt;
</code></pre>
<h2>Local Fetch Links</h2>
<p>Similar to above but examples use local hrefs (#foo) and there isn't a need for a <code>data-fragment</code> attribute since we're already specifying that in the href.</p>
<blockquote class="bq">
<p>“You will not apply my precept,” he said, shaking his head. “How often have I said to you that when you have eliminated the impossible, whatever remains, however improbable, must be the truth?”</p>
<address>Arthur Conan Doyle</address>
<cite>Sherlock Holmes: The Sign of the Four</cite>
</blockquote>
<div class="quote" style="border: 2px solid red;">
<p>To be replaced.</p>
</div>
</div>
</div>
</body>
</html>

View file

@ -0,0 +1,61 @@
(function( $, undefined ) {
$.widget( "mobile.fetchlink", $.mobile.widget, {
options: {
initSelector: ":jqmData(role='fetchlink')"
},
_create: function() {
// Prototyping.
// $( this.element.data( 'fragment' ) ).hide();
$( this.element ).click(function() {
var el = $( this ),
url = el.attr( 'href' ),
target = el.data( "target" ),
targetEl = target && $( target ) || el,
load = el.data( "fragment" ) /* Needs a proper default (page, most likely). */,
threshold = screen.width > parseInt( el.data( "breakpoint" ) || 0 ),
methods = [ "append", "prepend", "replace", "before", "after" ],
method = "html",
url;
if ( threshold ) {
for( var ml = methods.length, i=0; i < ml; i++ ){
if( el.is( "[data-include='" + methods[ i ] + "']" ) ){
method = methods[ i ];
}
}
if ( method === "replace" ){
method += "With";
}
if ( url && method ){
$.get( url, function( data ) {
/* Swiped from the jQuery core; $.get() should really be replaced by .load() */
var rscript = /<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,
responseEl = $( load ? $("<div/>").append( data.replace( rscript, "" ) ).find( load ) : data );
/* Do we want to do this? */
$( load ).remove();
targetEl[ method ]( responseEl )
responseEl
.trigger( "create" )
.trigger( "fetchlink", { target : targetEl, data: responseEl } );
});
}
}
return false;
});
}
});
//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){
$( $.mobile.fetchlink.prototype.options.initSelector, e.target ).fetchlink();
});
})( jQuery );