Added AJAX loader.

This commit is contained in:
Mat Marquis 2011-11-29 18:18:50 -05:00 committed by scottjehl
parent 5cbcc55ef9
commit d721600566
4 changed files with 91 additions and 2 deletions

View file

@ -18,5 +18,4 @@ $files = array_merge($files, array(
'../../structure/jquery.mobile.forms.slider.css'
));
require_once($base.'/../../../combine.php');
require_once($base.'/../../../combine.php');

View file

@ -0,0 +1,42 @@
<!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">
<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

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

View file

@ -0,0 +1,47 @@
( 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);