Load jquery from a script tag in iframe
This commit is contained in:
		| @@ -9,7 +9,6 @@ window.common = (function(global) { | |||||||
|   // context to that of the iframe. |   // context to that of the iframe. | ||||||
|   var libraryIncludes = ` |   var libraryIncludes = ` | ||||||
| <script> | <script> | ||||||
|   window.$ = parent.$.proxy(parent.$.fn.find, parent.$(document)); |  | ||||||
|   window.loopProtect = parent.loopProtect; |   window.loopProtect = parent.loopProtect; | ||||||
|   window.__err = null; |   window.__err = null; | ||||||
|   window.loopProtect.hit = function(line) { |   window.loopProtect.hit = function(line) { | ||||||
| @@ -38,6 +37,9 @@ window.common = (function(global) { | |||||||
|  |  | ||||||
|   const iFrameScript$ = |   const iFrameScript$ = | ||||||
|     common.getScriptContent$('/js/iFrameScripts.js').shareReplay(); |     common.getScriptContent$('/js/iFrameScripts.js').shareReplay(); | ||||||
|  |   const jQueryScript$ = common.getScriptContent$( | ||||||
|  |     '/bower_components/jquery/dist/jquery.js' | ||||||
|  |   ).shareReplay(); | ||||||
|  |  | ||||||
|   // behavior subject allways remembers the last value |   // behavior subject allways remembers the last value | ||||||
|   // we use this to determine if runPreviewTest$ is defined |   // we use this to determine if runPreviewTest$ is defined | ||||||
| @@ -55,14 +57,27 @@ window.common = (function(global) { | |||||||
|   common.updatePreview$ = function updatePreview$(code = '') { |   common.updatePreview$ = function updatePreview$(code = '') { | ||||||
|     const preview = common.getIframe('preview'); |     const preview = common.getIframe('preview'); | ||||||
|  |  | ||||||
|     return iFrameScript$ |     return Observable.combineLatest( | ||||||
|       .map(script => `<script>${script}</script>`) |       iFrameScript$, | ||||||
|       .flatMap(script => { |       jQueryScript$, | ||||||
|  |       (iframe, jQuery) => ({ | ||||||
|  |         iframeScript: `<script>${iframe}</script>`, | ||||||
|  |         jQuery: `<script>${jQuery}</script>` | ||||||
|  |       }) | ||||||
|  |     ) | ||||||
|  |       .first() | ||||||
|  |       .flatMap(({ iframeScript, jQuery }) => { | ||||||
|         // we make sure to override the last value in the |         // we make sure to override the last value in the | ||||||
|         // subject to false here. |         // subject to false here. | ||||||
|         common.previewReady$.onNext(false); |         common.previewReady$.onNext(false); | ||||||
|         preview.open(); |         preview.open(); | ||||||
|         preview.write(libraryIncludes + code + '<!-- -->' + script); |         preview.write( | ||||||
|  |           libraryIncludes + | ||||||
|  |           jQuery + | ||||||
|  |           code + | ||||||
|  |           '<!-- -->' + | ||||||
|  |           iframeScript | ||||||
|  |         ); | ||||||
|         preview.close(); |         preview.close(); | ||||||
|         // now we filter false values and wait for the first true |         // now we filter false values and wait for the first true | ||||||
|         return common.previewReady$ |         return common.previewReady$ | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user