jquery-mobile/docs/_assets/js/_viewsource.js

42 lines
1.6 KiB
JavaScript
Raw Permalink Normal View History

2010-10-15 21:09:53 +00:00
//quick view source in new window links
$.fn.addSourceLink = function(style){
return $(this).each(function(){
2011-03-10 02:34:03 +00:00
var link = $('<a href="#" data-'+ $.mobile.ns +'inline="true">View Source</a>'),
2010-10-15 21:09:53 +00:00
src = src = $('<div></div>').append( $(this).clone() ).html(),
2011-03-10 02:34:03 +00:00
page = $( "<div data-"+ $.mobile.ns +"role='dialog' data-"+ $.mobile.ns +"theme='a'>" +
"<div data-"+ $.mobile.ns +"role='header' data-"+ $.mobile.ns +"theme='b'>" +
"<a href='#' class='ui-btn-left' data-"+ $.mobile.ns +"icon='delete' data-"+ $.mobile.ns +"iconpos='notext'>Close</a>"+
2010-10-15 21:09:53 +00:00
"<div class='ui-title'>jQuery Mobile Source Excerpt</div>"+
"</div>"+
2011-03-10 02:34:03 +00:00
"<div data-"+ $.mobile.ns +"role='content'></div>"+
2010-10-15 21:09:53 +00:00
"</div>" )
.appendTo( "body" )
.page();
$('<a href="#">View Source</a>')
.buttonMarkup({
icon: 'arrow-u',
iconpos: 'notext'
})
.click(function(){
var codeblock = $('<pre><code></code></pre>');
2011-03-10 02:34:03 +00:00
src = src.replace(/&/gmi, '&amp;').replace(/"/gmi, '&quot;').replace(/>/gmi, '&gt;').replace(/</gmi, '&lt;').replace('data-'+ $.mobile.ns +'source="true"','');
2010-10-15 21:09:53 +00:00
codeblock.find('code').append(src);
var activePage = $(this).parents('.ui-page-active');
page.find('.ui-content').append(codeblock);
$.changePage(page, 'slideup',false);
2010-10-15 21:09:53 +00:00
page.find('.ui-btn-left').click(function(){
$.changePage(activepage, 'slideup',true);
2010-10-15 21:09:53 +00:00
return false;
});
})
.insertAfter(this);
});
};
//set up view source links
$('div').live('pagebeforecreate',function(){
2011-03-10 02:34:03 +00:00
$(this).find('[data-'+ $.mobile.ns +'source="true"]').addSourceLink();
2010-10-15 21:09:53 +00:00
});