]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.document/print.js
Change default "Eclipse Launcher" shell title from workspace launcher
[simantics/platform.git] / bundles / org.simantics.document / print.js
1
2 function progress(work) {
3         console.log(work);
4 }
5
6 /**
7  * Wait until the test condition is true or a timeout occurs. Useful for waiting
8  * on a server response or for a ui change (fadeIn, etc.) to occur.
9  *
10  * @param testFx javascript condition that evaluates to a boolean,
11  * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
12  * as a callback function.
13  * @param onReady what to do when testFx condition is fulfilled,
14  * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
15  * as a callback function.
16  * @param timeOutMillis the max amount of time to wait. If not specified, 5 min is used.
17  */
18 function waitFor(testFx, onReady, timeOutMillis) {
19     var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 300000, //< Default Max Timout is 5 min
20         start = new Date().getTime(),
21         condition = false;
22         var interval = setInterval(function() {
23                 if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
24                 // If not time-out yet and condition not yet fulfilled
25                 condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
26             } else {
27                 if(!condition) {
28                         // timeout
29                         phantom.exit(1);
30                 } else {
31                     // Condition fulfilled (timeout and/or condition is 'true')
32                     typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
33                     clearInterval(interval); //< Stop this interval
34                 }
35             }
36         }, 250); //< repeat check every 250ms
37 };
38
39 phantom.onError = function(msg, trace) {
40   var msgStack = ['PHANTOM ERROR: ' + msg];
41   if (trace && trace.length) {
42     msgStack.push('TRACE:');
43     trace.forEach(function(t) {
44       msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
45     });
46   }
47   console.error(msgStack.join('\n'));
48   phantom.exit(1);
49 };
50
51 var page = require('webpage').create();
52
53 require('system');
54
55 progress('#initialized');
56
57 page.paperSize = {
58   width: "190mm",
59   height: "276mm",
60   orientation: "portrait",
61   margin: %%margin
62 };
63
64 page.zoomFactor = 1.57
65
66 page.open('%%url', function (status) {
67
68         page.render('%%file', {quality: '100'});
69
70         progress('#rendered');
71         
72         phantom.exit();
73         
74 });