docs/playground/js/require-iframe.js
function complete2() {
            //reset any calls to document.write
            resetLog();
            //reinstate alert
            window.alert = originalAlert;
            var originalFn = parent.makerjs.exporter.toSVG;
            var captureExportedModel;
            parent.makerjs.exporter.toSVG = function (itemToExport, options) {
                if (parent.makerjs.isModel(itemToExport)) {
                    captureExportedModel = itemToExport;
                }
                else if (Array.isArray(itemToExport)) {
                    captureExportedModel = {};
                    itemToExport.forEach(function (x, i) {
                        if (makerjs.isModel(x)) {
                            captureExportedModel.models = captureExportedModel.models || {};
                            captureExportedModel.models[i] = x;
                        }
                        if (makerjs.isPath(x)) {
                            captureExportedModel.paths = captureExportedModel.paths || {};
                            captureExportedModel.paths[i] = x;
                        }
                    });
                }
                else if (parent.makerjs.isPath(itemToExport)) {
                    captureExportedModel = { paths: { "0": itemToExport } };
                }
                return originalFn(itemToExport, options);
            };
            //when all requirements are collected, run the code again, using its requirements
            runCodeGlobal(javaScript);
            parent.makerjs.exporter.toSVG = originalFn;
            if (errorReported)
                return;
            //yield thread for the script tag to execute
            setTimeout(function () {
                var model;
                if (captureExportedModel) {
                    model = captureExportedModel;
                }
                else {
                    //restore properties from the "this" keyword
                    model = {};
                    var props = ['layer', 'models', 'notes', 'origin', 'paths', 'type', 'units', 'caption', 'exporterOptions'];
                    var hasProps = false;
                    for (var i = 0; i < props.length; i++) {
                        var prop = props[i];
                        if (prop in window) {
                            model[prop] = window[prop];
                            hasProps = true;
                        }
                    }
                    if (!hasProps) {
                        model = null;
                    }
                }
                var orderedDependencies = [];
                var scripts = head.getElementsByTagName('script');
                for (var i = 0; i < scripts.length; i++) {
                    if (scripts[i].hasAttribute('id')) {
                        orderedDependencies.push(scripts[i].id);
                    }
                }
                //send results back to parent window
                parent.MakerJsPlayground.processResult({ html: getHtml(), result: window.module.exports || model, orderedDependencies: orderedDependencies, paramValues: window.paramValues });
            }, 0);
        }
function complete2() {
            //reset any calls to document.write
            resetLog();
            //reinstate alert
            window.alert = originalAlert;
            var originalFn = parent.makerjs.exporter.toSVG;
            var captureExportedModel;
            parent.makerjs.exporter.toSVG = function (itemToExport, options) {
                if (parent.makerjs.isModel(itemToExport)) {
                    captureExportedModel = itemToExport;
                }
                else if (Array.isArray(itemToExport)) {
                    captureExportedModel = {};
                    itemToExport.forEach(function (x, i) {
                        if (makerjs.isModel(x)) {
                            captureExportedModel.models = captureExportedModel.models || {};
                            captureExportedModel.models[i] = x;
                        }
                        if (makerjs.isPath(x)) {
                            captureExportedModel.paths = captureExportedModel.paths || {};
                            captureExportedModel.paths[i] = x;
                        }
                    });
                }
                else if (parent.makerjs.isPath(itemToExport)) {
                    captureExportedModel = { paths: { "0": itemToExport } };
                }
                return originalFn(itemToExport, options);
            };
            //when all requirements are collected, run the code again, using its requirements
            runCodeGlobal(javaScript);
            parent.makerjs.exporter.toSVG = originalFn;
            if (errorReported)
                return;
            //yield thread for the script tag to execute
            setTimeout(function () {
                var model;
                if (captureExportedModel) {
                    model = captureExportedModel;
                }
                else {
                    //restore properties from the "this" keyword
                    model = {};
                    var props = ['layer', 'models', 'notes', 'origin', 'paths', 'type', 'units', 'caption', 'exporterOptions'];
                    var hasProps = false;
                    for (var i = 0; i < props.length; i++) {
                        var prop = props[i];
                        if (prop in window) {
                            model[prop] = window[prop];
                            hasProps = true;
                        }
                    }
                    if (!hasProps) {
                        model = null;
                    }
                }
                var orderedDependencies = [];
                var scripts = head.getElementsByTagName('script');
                for (var i = 0; i < scripts.length; i++) {
                    if (scripts[i].hasAttribute('id')) {
                        orderedDependencies.push(scripts[i].id);
                    }
                }
                //send results back to parent window
                parent.MakerJsPlayground.processResult({ html: getHtml(), result: window.module.exports || model, orderedDependencies: orderedDependencies, paramValues: window.paramValues });
            }, 0);
        }
function complete2 ( ) { //reset any calls to document.write resetLog ( ) ; //reinstate alert window . alert = originalAlert ; var originalFn = parent . makerjs . exporter . toSVG ; var captureExportedModel ; parent . makerjs . exporter . toSVG = function ( itemToExport , options ) { if ( parent . makerjs . isModel ( itemToExport ) ) { captureExportedModel = itemToExport ; } else if ( Array . isArray ( itemToExport ) ) { captureExportedModel = { } ; itemToExport . forEach ( function ( x , i ) { if ( makerjs . isModel ( x ) ) { captureExportedModel . models = captureExportedModel . models || { } ; captureExportedModel . models [ i ] = x ; } if ( makerjs . isPath ( x ) ) { captureExportedModel . paths = captureExportedModel . paths || { } ; captureExportedModel . paths [ i ] = x ; } } ) ; } else if ( parent . makerjs . isPath ( itemToExport ) ) { captureExportedModel = { paths : { "0" : itemToExport } } ; } return originalFn ( itemToExport , options ) ; } ; //when all requirements are collected, run the code again, using its requirements runCodeGlobal ( javaScript ) ; parent . makerjs . exporter . toSVG = originalFn ; if ( errorReported ) return ; //yield thread for the script tag to execute setTimeout ( function ( ) { var model ; if ( captureExportedModel ) { model = captureExportedModel ; } else { //restore properties from the "this" keyword model = { } ; var props = [ 'layer' , 'models' , 'notes' , 'origin' , 'paths' , 'type' , 'units' , 'caption' , 'exporterOptions' ] ; var hasProps = false ; for ( var i = 0 ; i < props . length ; i ++ ) { var prop = props [ i ] ; if ( prop in window ) { model [ prop ] = window [ prop ] ; hasProps = true ; } } if ( ! hasProps ) { model = null ; } } var orderedDependencies = [ ] ; var scripts = head . getElementsByTagName ( 'script' ) ; for ( var i = 0 ; i < scripts . length ; i ++ ) { if ( scripts [ i ] . hasAttribute ( 'id' ) ) { orderedDependencies . push ( scripts [ i ] . id ) ; } } //send results back to parent window parent . MakerJsPlayground . processResult ( { html : getHtml ( ) , result : window . module . exports || model , orderedDependencies : orderedDependencies , paramValues : window . paramValues } ) ; } , 0 ) ; }
run the code in 2 passes, first - to cache all required libraries, secondly the actual execution
run the code in 2 passes first - to cache all required libraries secondly the actual execution