mirror of
https://github.com/Hopiu/jquery-mobile.git
synced 2026-04-20 22:30:59 +00:00
Added AJAX loader.
This commit is contained in:
parent
5cbcc55ef9
commit
d721600566
4 changed files with 91 additions and 2 deletions
|
|
@ -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');
|
||||
42
docs/pages/ajaxinclude.html
Normal file
42
docs/pages/ajaxinclude.html
Normal 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>
|
||||
|
|
@ -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'
|
||||
);
|
||||
|
||||
|
|
|
|||
47
js/jquery.mobile.ajaxinclude.js
Normal file
47
js/jquery.mobile.ajaxinclude.js
Normal 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);
|
||||
Loading…
Reference in a new issue