Widgetfactory’d the fetchlink plugin; continued tinkering.

This commit is contained in:
Mat Marquis 2011-11-30 18:20:08 -05:00 committed by scottjehl
parent efb95e5589
commit c37d5dc522
5 changed files with 4 additions and 125 deletions

View file

@ -1,75 +0,0 @@
<!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>A <a href="dialog.html" data-target=".quote">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 href="dialog.html" data-target=".quote" data-method="append">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-target=".quote" data-fragment="#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 a what 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-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>
<a data-include="replace" data-fragment=".bq" data-target=".quote" href="#" data-breakpoint="800" rel="external">Link</a>
<div class="quote">
<p>To be replaced.</p>
</div>
</div>
</div>
</body>
</html>

View file

@ -13,6 +13,7 @@
</head>
<body>
<div data-role="page">
<div data-role="header" data-theme="d">
@ -20,7 +21,7 @@
</div>
<div data-role="content" data-theme="c">
<div data-role="content" data-theme="c" class="test">
<h1>Delete page?</h1>
<p>This is a regular page, styled as a dialog. To create a dialog, just link to a normal page and include a transition and <code>data-rel="dialog"</code> attribute.</p>
<a href="docs-dialogs.html" data-role="button" data-rel="back" data-theme="b">Sounds good</a>

View file

@ -36,7 +36,7 @@ $files = array(
'jquery.mobile.links.js',
'jquery.mobile.fixHeaderFooter.js',
'jquery.mobile.fixHeaderFooter.native.js',
'jquery.mobile.ajaxinclude.js',
'jquery.mobile.fetchlink.js',
'jquery.mobile.popup.js',
'jquery.mobile.init.js'
);

View file

@ -1,47 +0,0 @@
( function( $, undefined ) {
$.fn.ajaxInclude = function( e ) {
return this.each(function() {
var el = $( this ),
url = el.attr( 'href' ),
target = el.data( "target" ),
targetEl = target && $( target ) || el,
load = el.data( "fragment" ),
threshold = screen.width > parseInt( el.data( "breakpoint" ) || 0 ),
methods = [ "append", "prepend", "replace", "before", "after" ],
method = "replace",
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 ),
eTarget = method === "replaceWith" || !method ? responseEl : el;
$( load ).remove();
targetEl[ method ]( responseEl )
eTarget.trigger( "ajaxInclude", [eTarget, data] );
});
}
}
});
};
$( function(){
$("[data-include]").ajaxInclude();
});
})(jQuery);

View file

@ -111,7 +111,7 @@ $.widget( "mobile.collapsible", $.mobile.widget, {
});
//auto self-init widgets
$( document ).bind( "pagecreate create", function( e ){
$( document ).bind( "pagecreate create", function( e ){
$( $.mobile.collapsible.prototype.options.initSelector, e.target ).collapsible();
});