-\r
-function progress(work) {\r
- console.log(work);\r
-}\r
-\r
-/**\r
- * Wait until the test condition is true or a timeout occurs. Useful for waiting\r
- * on a server response or for a ui change (fadeIn, etc.) to occur.\r
- *\r
- * @param testFx javascript condition that evaluates to a boolean,\r
- * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or\r
- * as a callback function.\r
- * @param onReady what to do when testFx condition is fulfilled,\r
- * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or\r
- * as a callback function.\r
- * @param timeOutMillis the max amount of time to wait. If not specified, 5 min is used.\r
- */\r
-function waitFor(testFx, onReady, timeOutMillis) {\r
- var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 300000, //< Default Max Timout is 5 min\r
- start = new Date().getTime(),\r
- condition = false;\r
- var interval = setInterval(function() {\r
- if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {\r
- // If not time-out yet and condition not yet fulfilled\r
- condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code\r
- } else {\r
- if(!condition) {\r
- // timeout\r
- phantom.exit(1);\r
- } else {\r
- // Condition fulfilled (timeout and/or condition is 'true')\r
- typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled\r
- clearInterval(interval); //< Stop this interval\r
- }\r
- }\r
- }, 250); //< repeat check every 250ms\r
-};\r
-\r
-phantom.onError = function(msg, trace) {\r
- var msgStack = ['PHANTOM ERROR: ' + msg];\r
- if (trace && trace.length) {\r
- msgStack.push('TRACE:');\r
- trace.forEach(function(t) {\r
- msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));\r
- });\r
- }\r
- console.error(msgStack.join('\n'));\r
- phantom.exit(1);\r
-};\r
-\r
-var page = require('webpage').create();\r
-\r
-require('system');\r
-\r
-progress('#initialized');\r
-\r
-page.paperSize = {\r
- width: "190mm",\r
- height: "276mm",\r
- orientation: "portrait",\r
- margin: %%margin\r
-};\r
-\r
-page.zoomFactor = 1.57\r
-\r
-page.open('%%url', function (status) {\r
-\r
- page.render('%%file', {quality: '100'});\r
-\r
- progress('#rendered');\r
- \r
- phantom.exit();\r
- \r
+
+function progress(work) {
+ console.log(work);
+}
+
+/**
+ * Wait until the test condition is true or a timeout occurs. Useful for waiting
+ * on a server response or for a ui change (fadeIn, etc.) to occur.
+ *
+ * @param testFx javascript condition that evaluates to a boolean,
+ * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
+ * as a callback function.
+ * @param onReady what to do when testFx condition is fulfilled,
+ * it can be passed in as a string (e.g.: "1 == 1" or "$('#bar').is(':visible')" or
+ * as a callback function.
+ * @param timeOutMillis the max amount of time to wait. If not specified, 5 min is used.
+ */
+function waitFor(testFx, onReady, timeOutMillis) {
+ var maxtimeOutMillis = timeOutMillis ? timeOutMillis : 300000, //< Default Max Timout is 5 min
+ start = new Date().getTime(),
+ condition = false;
+ var interval = setInterval(function() {
+ if ( (new Date().getTime() - start < maxtimeOutMillis) && !condition ) {
+ // If not time-out yet and condition not yet fulfilled
+ condition = (typeof(testFx) === "string" ? eval(testFx) : testFx()); //< defensive code
+ } else {
+ if(!condition) {
+ // timeout
+ phantom.exit(1);
+ } else {
+ // Condition fulfilled (timeout and/or condition is 'true')
+ typeof(onReady) === "string" ? eval(onReady) : onReady(); //< Do what it's supposed to do once the condition is fulfilled
+ clearInterval(interval); //< Stop this interval
+ }
+ }
+ }, 250); //< repeat check every 250ms
+};
+
+phantom.onError = function(msg, trace) {
+ var msgStack = ['PHANTOM ERROR: ' + msg];
+ if (trace && trace.length) {
+ msgStack.push('TRACE:');
+ trace.forEach(function(t) {
+ msgStack.push(' -> ' + (t.file || t.sourceURL) + ': ' + t.line + (t.function ? ' (in function ' + t.function +')' : ''));
+ });
+ }
+ console.error(msgStack.join('\n'));
+ phantom.exit(1);
+};
+
+var page = require('webpage').create();
+
+require('system');
+
+progress('#initialized');
+
+page.paperSize = {
+ width: "190mm",
+ height: "276mm",
+ orientation: "portrait",
+ margin: %%margin
+};
+
+page.zoomFactor = 1.57
+
+page.open('%%url', function (status) {
+
+ page.render('%%file', {quality: '100'});
+
+ progress('#rendered');
+
+ phantom.exit();
+
});
\ No newline at end of file