Вот вам скрипт:
(function($) {
$.fn.includeVirtual = function(path) {
$.holdReady(true);
var $element = this;
$.get(path, function(data) {
$element.replaceWith(data);
$.holdReady(false);
});
$element.ajaxError(function() {
$.holdReady(false);
});
};
})(jQuery);
Вот holdReady на случай, если как у меня, используется старая версия jQuery:
(function($) {
$.extend({
// Is the DOM ready to be used? Set to true once it occurs.
isReady: false,
// A counter to track how many items to wait for before
// the ready event fires. See #6781
readyWait: 1,
// Hold (or release) the ready event
holdReady: function( hold ) {
if ( hold ) {
jQuery.readyWait++;
} else {
jQuery.ready( true );
}
},
// Handle when the DOM is ready
ready: function( wait ) {
// A third-party is pushing the ready event forwards
if ( wait === true ) {
jQuery.readyWait--;
}
// Make sure that the DOM is not already loaded
if ( !jQuery.readyWait || (wait !== true && !jQuery.isReady) ) {
// Make sure body exists, at least, in case IE gets a little overzealous (ticket #5443).
if ( !document.body ) {
return setTimeout( jQuery.ready, 1 );
}
// Remember that the DOM is ready
jQuery.isReady = true;
// If a normal DOM Ready event fired, decrement, and wait if need be
if ( wait !== true && --jQuery.readyWait > 0 ) {
return;
}
// If there are functions bound, to execute
if ( this.readyList ) {
// Execute all of them
var fn,
i = 0,
ready = this.readyList;
// Reset the list of functions
this.readyList = null;
while ( (fn = ready[ i++ ]) ) {
fn.call( document, jQuery );
}
// Trigger any bound ready events
if ( jQuery.fn.trigger ) {
jQuery( document ).trigger( "ready" ).unbind( "ready" );
}
}
}
}
});
А вот использование:
<script id="selector">$('#selector').includeVirtual('/your/path/to/content');</script>