Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ERIC.js #1279

Merged
merged 2 commits into from Apr 5, 2017

Conversation

Projects
None yet
3 participants
@zuphilip
Copy link
Collaborator

zuphilip commented Mar 16, 2017

I tried out some querySelector here as @dstillman suggested in #1277 (comment) .

ERIC.js Outdated
var hasTitle = doc.querySelector("meta[name=citation_title]");
var type = doc.querySelector("meta[name=source][content]");
if (hasTitle) {
if (type && type.content.indexOf("Non-Journal")!=-1) {

This comment has been minimized.

Copy link
@dstillman

dstillman Mar 16, 2017

Member

I think you meant textContent here.

This comment has been minimized.

Copy link
@zuphilip

zuphilip Mar 16, 2017

Author Collaborator

No, it is something like

<meta name="source" content="Non-Journal"/>

This comment has been minimized.

Copy link
@dstillman

dstillman Mar 16, 2017

Member

Then you meant getAttribute('content'), no? type is just a DOM element at this point.

This comment has been minimized.

Copy link
@dstillman

dstillman Mar 16, 2017

Member

Ah, never mind, I guess .content works on meta elements.

ERIC.js Outdated

function detectWeb(doc, url) {
var hasTitle = doc.querySelector("meta[name=citation_title]");
var type = doc.querySelector("meta[name=source][content]");

This comment has been minimized.

Copy link
@dstillman

dstillman Mar 16, 2017

Member

I know you're just porting, but this should go within theif (hasTitle) block so that it doesn't run unnecessarily.

This comment has been minimized.

Copy link
@zuphilip

zuphilip Mar 17, 2017

Author Collaborator

Done

@adam3smith adam3smith merged commit 1d56b98 into zotero:master Apr 5, 2017

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@adam3smith

This comment has been minimized.

Copy link
Collaborator

adam3smith commented Apr 5, 2017

Thanks. @zuphilip any thoughts on querySelector vs. xpath? It is significantly more efficient, from the looks of it: https://jsperf.com/getelementbyid-vs-queryselector/89
Should we push ahead with trying to encourage it?

@zuphilip zuphilip deleted the zuphilip:eric branch Apr 5, 2017

@zuphilip

This comment has been minimized.

Copy link
Collaborator Author

zuphilip commented Apr 5, 2017

@adam3smith The querySelector can already been use as an alternative for ZU.xpath, but for ZU.xpathText this becomes more complicated, because one has to check first if there exists any element before accessing to the textContent. As @dstillman pointed out, this is not an argument against switching, but maybe the question is more when to do this and what should be done before. (BTW changing is maybe also not that the easy because people, including me, are used to use these ZU.xpath functions.)

@zuphilip

This comment has been minimized.

Copy link
Collaborator Author

zuphilip commented Apr 5, 2017

Maybe, we should start simply by trying it out more on every occasion we have...

zuphilip added a commit to zuphilip/translators that referenced this pull request Mar 28, 2018

zuphilip added a commit to zuphilip/translators that referenced this pull request Mar 28, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.