mirror of https://github.com/vitalif/phantomjs
Merge branch 'master' of https://github.com/ariya/phantomjs
commit
99473110df
|
@ -1,65 +1,73 @@
|
||||||
// This allows creating a new web page using the construct "new WebPage",
|
// This allows creating a new web page using the construct "new WebPage",
|
||||||
// which feels more natural than "phantom.createWebPage()".
|
// which feels more natural than "phantom.createWebPage()".
|
||||||
window.WebPage = function() {
|
window.WebPage = function() {
|
||||||
var page = phantom.createWebPage();
|
var page = phantom.createWebPage(),
|
||||||
|
handlers = {};
|
||||||
|
|
||||||
// deep copy
|
// deep copy
|
||||||
page.settings = JSON.parse(JSON.stringify(phantom.defaultPageSettings));
|
page.settings = JSON.parse(JSON.stringify(phantom.defaultPageSettings));
|
||||||
|
|
||||||
// private, don't touch this
|
|
||||||
page._handlers = {};
|
|
||||||
|
|
||||||
page.__defineSetter__("onLoadStarted", function(f) {
|
page.__defineSetter__("onLoadStarted", function(f) {
|
||||||
if (this._handlers && typeof this._handlers.loadStarted === 'function') {
|
if (handlers && typeof handlers.loadStarted === 'function') {
|
||||||
try {
|
try {
|
||||||
this.loadStarted.disconnect(this._handlers.loadStarted);
|
this.loadStarted.disconnect(handlers.loadStarted);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
this._handlers.loadStarted = f;
|
handlers.loadStarted = f;
|
||||||
this.loadStarted.connect(this._handlers.loadStarted);
|
this.loadStarted.connect(handlers.loadStarted);
|
||||||
});
|
});
|
||||||
|
|
||||||
page.__defineSetter__("onLoadFinished", function(f) {
|
page.__defineSetter__("onLoadFinished", function(f) {
|
||||||
if (this._handlers && typeof this._handlers.loadFinished === 'function') {
|
if (handlers && typeof handlers.loadFinished === 'function') {
|
||||||
try {
|
try {
|
||||||
this.loadFinished.disconnect(this._handlers.loadFinished);
|
this.loadFinished.disconnect(handlers.loadFinished);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
this._handlers.loadFinished = f;
|
handlers.loadFinished = f;
|
||||||
this.loadFinished.connect(this._handlers.loadFinished);
|
this.loadFinished.connect(handlers.loadFinished);
|
||||||
});
|
});
|
||||||
|
|
||||||
page.__defineSetter__("onResourceRequested", function(f) {
|
page.__defineSetter__("onResourceRequested", function(f) {
|
||||||
if (this._handlers && typeof this._handlers.resourceRequested === 'function') {
|
if (handlers && typeof handlers.resourceRequested === 'function') {
|
||||||
try {
|
try {
|
||||||
this.resourceRequested.disconnect(this._handlers.resourceRequested);
|
this.resourceRequested.disconnect(handlers.resourceRequested);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
this._handlers.resourceRequested = f;
|
handlers.resourceRequested = f;
|
||||||
this.resourceRequested.connect(this._handlers.resourceRequested);
|
this.resourceRequested.connect(handlers.resourceRequested);
|
||||||
});
|
});
|
||||||
|
|
||||||
page.__defineSetter__("onResourceReceived", function(f) {
|
page.__defineSetter__("onResourceReceived", function(f) {
|
||||||
if (this._handlers && typeof this._handlers.resourceReceived === 'function') {
|
if (handlers && typeof handlers.resourceReceived === 'function') {
|
||||||
try {
|
try {
|
||||||
this.resourceReceived.disconnect(this._handlers.resourceReceived);
|
this.resourceReceived.disconnect(handlers.resourceReceived);
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}
|
}
|
||||||
this._handlers.resourceReceived = f;
|
handlers.resourceReceived = f;
|
||||||
this.resourceReceived.connect(this._handlers.resourceReceived);
|
this.resourceReceived.connect(handlers.resourceReceived);
|
||||||
});
|
});
|
||||||
|
|
||||||
page.onAlert = function (msg) {};
|
page.__defineSetter__("onAlert", function(f) {
|
||||||
|
if (handlers && typeof handlers.javaScriptAlertSent === 'function') {
|
||||||
|
try {
|
||||||
|
this.javaScriptAlertSent.disconnect(handlers.javaScriptAlertSent);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
handlers.javaScriptAlertSent = f;
|
||||||
|
this.javaScriptAlertSent.connect(handlers.javaScriptAlertSent);
|
||||||
|
});
|
||||||
|
|
||||||
page.onConsoleMessage = function (msg) {};
|
page.__defineSetter__("onConsoleMessage", function(f) {
|
||||||
|
if (handlers && typeof handlers.javaScriptConsoleMessageSent === 'function') {
|
||||||
|
try {
|
||||||
|
this.javaScriptConsoleMessageSent.disconnect(handlers.javaScriptConsoleMessageSent);
|
||||||
|
} catch (e) {}
|
||||||
|
}
|
||||||
|
handlers.javaScriptConsoleMessageSent = f;
|
||||||
|
this.javaScriptConsoleMessageSent.connect(handlers.javaScriptConsoleMessageSent);
|
||||||
|
});
|
||||||
|
|
||||||
page.open = function () {
|
page.open = function () {
|
||||||
if (typeof this.onAlert === 'function') {
|
|
||||||
this.javaScriptAlertSent.connect(this.onAlert);
|
|
||||||
}
|
|
||||||
if (typeof this.onConsoleMessage === 'function') {
|
|
||||||
this.javaScriptConsoleMessageSent.connect(this.onConsoleMessage);
|
|
||||||
}
|
|
||||||
if (arguments.length === 1) {
|
if (arguments.length === 1) {
|
||||||
this.openUrl(arguments[0], 'get', this.settings);
|
this.openUrl(arguments[0], 'get', this.settings);
|
||||||
return;
|
return;
|
||||||
|
|
Loading…
Reference in New Issue