Skip to content
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.

Need Wiki/Doc about WGXPath #51

Open
oliezekat opened this issue Oct 26, 2016 · 3 comments
Open

Need Wiki/Doc about WGXPath #51

oliezekat opened this issue Oct 26, 2016 · 3 comments

Comments

@oliezekat
Copy link

Hi,

I create a framework which use Evaluate, I know how to detect if this method is available but I would like to detect if wgxpath.install.js is loaded, an if wgxpath.install() is executed, and at last, if wgxpath.install() failed or not in both case my framework call it or browser did it before to initialize my framework.

A Wiki or documentation about these issues could be fine.

@oliezekat
Copy link
Author

Up

Please give me your advices.

@nedjs
Copy link
Contributor

nedjs commented Jun 5, 2017

detect if wgxpath.install.js is loaded - Did you include the script or not? Also console.log(window.wgxpath?'wgxpath is loaded':'wgxpath is not loaded');

wgxpath.install() is executed - You can call it multiple times, im pretty sure invoking it a 2nd time wont cause any harm. Could also just do the check yourself if(!window.document.evaluate) wgxpath.install();

if wgxpath.install() failed - I cant imagine why it would fail but maybe just a try catch? I dont think catastrophic failure inside the install method is really handled

You can test if wgxpath is installed instead of the browser version by checking if the document.evaluate is native code or not.

if( /\{\s+\[native code\]/.test( Function.prototype.toString.call( document.evaluate ) ) ) { console.log("document.evaluate is native!"); }

IMO wgxpath is designed with the intent to be a fallback to document.evaluate, you should continue that design pattern by simply checking if the evaluate method exists at any point. If it does then do you really care where its coming from? As long as the xpath functions work, right?

@oliezekat
Copy link
Author

Thank @nedjs

I submit wgxpath's object include public property (or method) which give its state. As example return 0 if install() is not executed, 2 if executed, 3 if installed fine, 5 if failed

Other submit: purpose callback function as argument of install()

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants