Tizen 2.1 base
[platform/framework/web/web-ui-fw.git] / libs / js / jquery-mobile-1.0.1pre / docs / _assets / js / _viewsource.js
1 //quick view source in new window links
2 $.fn.addSourceLink = function(style){
3
4         return $(this).each(function(){
5                 var link = $('<a href="#" data-'+ $.mobile.ns +'inline="true">View Source</a>'),
6                         src = src = $('<div></div>').append( $(this).clone() ).html(),
7                         page = $( "<div data-"+ $.mobile.ns +"role='dialog' data-"+ $.mobile.ns +"theme='a'>" +
8                                         "<div data-"+ $.mobile.ns +"role='header' data-"+ $.mobile.ns +"theme='b'>" +
9                                                 "<a href='#' class='ui-btn-left' data-"+ $.mobile.ns +"icon='delete' data-"+ $.mobile.ns +"iconpos='notext'>Close</a>"+
10                                                 "<div class='ui-title'>jQuery Mobile Source Excerpt</div>"+
11                                         "</div>"+
12                                         "<div data-"+ $.mobile.ns +"role='content'></div>"+
13                                 "</div>" )
14                                 .appendTo( "body" )
15                                 .page();
16                                 
17                 $('<a href="#">View Source</a>')
18                         .buttonMarkup({
19                                 icon: 'arrow-u',
20                                 iconpos: 'notext'
21                         })
22                         .click(function(){
23                                 var codeblock = $('<pre><code></code></pre>');
24                                 src = src.replace(/&/gmi, '&amp;').replace(/"/gmi, '&quot;').replace(/>/gmi, '&gt;').replace(/</gmi, '&lt;').replace('data-'+ $.mobile.ns +'source="true"','');
25                                 codeblock.find('code').append(src);
26
27                                 var activePage = $(this).parents('.ui-page-active');
28                                 page.find('.ui-content').append(codeblock);
29                                 $.changePage(page, 'slideup',false);
30                                 page.find('.ui-btn-left').click(function(){
31                                         $.changePage(activepage, 'slideup',true);
32                                         return false;
33                                 });                                             
34                         })      
35                         .insertAfter(this);
36                 });     
37 };
38
39 //set up view source links
40 $('div').live('pagebeforecreate',function(){
41         $(this).find('[data-'+ $.mobile.ns +'source="true"]').addSourceLink();
42 });