|
470 | 470 | els.sourceCodeContentHd.show(); |
471 | 471 | els.sourceCodeContent.removeClass('prettyprinted').text(''); |
472 | 472 | if (data && data.code) { |
473 | | - els.sourceCodeContentHd.hide(); |
474 | | - els.sourceCodeContent.text(data.code); |
475 | | - setTimeout(function () { |
476 | | - PR.prettyPrint(renderHighlightVariableKeyword); |
477 | | - }, 100); |
| 473 | + renderSourceCodeByWorker(function(){ |
| 474 | + els.sourceCodeContentHd.hide(); |
| 475 | + els.sourceCodeContent.text(data.code); |
| 476 | + setTimeout(function(){ |
| 477 | + PR.prettyPrint(renderHighlightVariableKeyword); |
| 478 | + }, 100); |
| 479 | + }); |
478 | 480 | renderAnalytics('vc&q=' + els.lastInputVal); |
479 | 481 | } |
480 | 482 | } |
481 | 483 |
|
| 484 | + function renderSourceCodeByWorker(callback){ |
| 485 | + if(Util.InlineWebWorker.ready){ |
| 486 | + if(!els.prettifyWorker){ |
| 487 | + els.prettifyWorker = els.prettifyWorker || Util.InlineWebWorker.create('#worker_prettify'); |
| 488 | + els.prettifyWorker.onmessage = function(e){ |
| 489 | + if(e.data=='after'){ |
| 490 | + callback && callback(); |
| 491 | + } |
| 492 | + } |
| 493 | + } |
| 494 | + els.prettifyWorker.postMessage('before'); |
| 495 | + }else{ |
| 496 | + callback && callback(); |
| 497 | + } |
| 498 | + } |
| 499 | + |
482 | 500 | function renderHighlightVariableKeyword(){ |
483 | 501 | els.sourceCodeContent.unhighlight(); |
484 | 502 | setTimeout(function(){ |
|
491 | 509 | },800); |
492 | 510 | } |
493 | 511 |
|
494 | | - function renderSourceCodeByWorker(){ |
495 | | - var blob = new Blob([document.querySelector('#worker1').textContent]); |
496 | | - var worker = new Worker(window.URL.createObjectURL(blob)); |
497 | | - worker.onmessage = function(e) { |
498 | | - log("Received: " + e.data); |
499 | | - } |
500 | | - worker.postMessage(); |
501 | | - } |
502 | | - |
503 | 512 | function renderRelatedProperty(name) { |
504 | 513 | var htm = [], |
505 | 514 | prop = getRelatedProperty(name); |
|
850 | 859 | return false; |
851 | 860 | } |
852 | 861 |
|
| 862 | + exports.InlineWebWorker = { |
| 863 | + ready: window.Blob && window.Worker && window.URL, |
| 864 | + create: function create(selector){ |
| 865 | + return new Worker(window.URL.createObjectURL(new Blob([document.querySelector(selector).textContent]))); |
| 866 | + } |
| 867 | + } |
| 868 | + |
853 | 869 |
|
854 | 870 | /***/ }, |
855 | 871 | /* 3 */ |
|
0 commit comments