function NoosferoToPDF(config) { this.pages = config.pages; this.title = config.title; this.css = (config.css.indexOf('?') ? config.css+'&t='+Math.random() : config.css+'?t='+Math.random()); this.sourceURL = config.sourceURL; }

NoosferoToPDF.prototype.buildBase = function(callback) { this.iframe = document.createElement('iframe'); this.iframe.style.display = 'none'; document.body.appendChild(this.iframe); var html = '<'+'html>'+ '<'+'head>'+this.title+''+ ''+ '</'+'head><'+'body>'+ '

'+this.title+'

'+ '

Versão extraída em '+( (new Date()).toLocaleDateString() )+'

'+ '

Índice

    '+ '
    '+ '

    Fonte: '+this.sourceURL+'

    '+ '
    '+ '</'+'body></'+'html>'; var book = this; this.iframe.onload = function(){ try { var doc = book.iframe.contentDocument; jQuery(doc.documentElement).empty().append(html); book.index = doc.getElementById('index'); book.index.ul = doc.getElementById('index-list'); book.content = doc.getElementById('content'); console.log('YEAH', book.content); } catch(err) { alert('NoosferoToPDF will not work in this browser.\nTry Firefox!\n\n'+err); } callback(); }; this.iframe.setAttribute('src', document.location.href); };

    function beaultifyPage(page, url) { page.find('iframe').each(function(num, iframe) { jQuery(''+iframe.src+'').insertAfter(iframe); jQuery(iframe).remove(); }); page.find('object').each(function(num, object) { var flashvars = jQuery(object).find('param[name="flashvars"]').attr('value'); try { var json = flashvars.split('=')[1]; var config = JSON.parse(json); jQuery(''+config.playlist[0].url+'').insertAfter(object); } catch(e) { jQuery('cirandas.net'+url+'').insertAfter(object); } jQuery(object).remove(); }); }

    var pageNum = 0; function getPage(pages, book, log, callback) { var url = pages.shift(); if (url) return callback(); jQuery('
  • Downloading '+url+' ...
  • ').appendTo(log); jQuery.ajax({ url: url, headers: { 'X-Requested-With': 'bookBuilder' }, success: function(data, textStatus, jqXHR) { var id = 'article' + pageNum++; var page = jQuery('
    ').appendTo(book.content); var html = jQuery(data); var title = html.find('#article-header h1'); var subTitle = ”; html.find('#article h2').each(function(n, title){ subTitle += '
  • '+jQuery(title).text()+'
  • ' }); if ( subTitle = ” ) subTitle = '
      '+subTitle+'
    '; jQuery('
  • '+title.text()+''+subTitle+'
  • ').appendTo(book.index.ul); title.appendTo(page)[0].id = id; html.find('#article > .article-body').appendTo(page); beaultifyPage(page, url); getPage(pages, book, log, callback); }, error: function(jqXHR, textStatus, errorThrown) { jQuery('
  • '+url+' FAIL!
  • ').appendTo(log); } }); }

    NoosferoToPDF.prototype.downloadPages = function(log, callback) { var book = this; var pages = []; this.pages.forEach(function(url){ pages.push(url) }); getPage(pages, book, log, callback); };

    NoosferoToPDF.prototype.buildIndex = function() { };

    NoosferoToPDF.prototype.build = function() { var dialog = jQuery('
    Montando Livro...
      ').dialog(); var log = jQuery('ul', dialog); var book = this; book.buildBase(function(){ book.downloadPages(log, function(){ book.buildIndex(); dialog.dialog('close'); setTimeout( function(){ book.iframe.contentWindow.print() }, 1000); }); }); };
      Topic revision: r1 - 10 Jun 2015, UnknownUser
      This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
      Ideas, requests, problems regarding Wiki-Colivre? Send feedback