Comments (19)
Alas, i haven't tried it on the server either. In fact, i've not written a node server app myself, much less a node-webkit one. I won't have time to dig in and learn until at least the 20th (i'm on a deadline for a big project). :-/
from html.
Oh, and i should ask. What's not working? What errors are you getting?
from html.
@nbubna , after using npm install html.js
, I cannot use require('html')
I think the fix may be simple: I can probably make a pull request for you if you don't mind.
from html.
I lied: the fix isn't simple.
I fixed the ability to "require" it in node by adding an index.js file:
index.js
module.exports = { HTML: require('./dist/HTML.min') }
Then changing package.json
package.json
"main":"index.js"
However, document isn't defined in the context of require and the node environment, so it fails with the following message:
ReferenceError: document is not defined
And thus, the whole statement goes kaput. Looks like it doesn't matter after all.
from html.
But shouldn't document exist in the context of node-webkit? Do require()'d libraries have any means of accessing global vars at the point of execution? It may be fruitful to see how other DOM libraries allow themselves to be require()'d. It may be the approach of HTML (where HTML is the document.documentElement) may need some "init" function to be compatible if there's no way to access document. Such a function would have to be called once document was available and return the ify()'d document.documentElement.
Failing any of those approaches, can't node-webkit load HTML.js through a <script> tag?
from html.
But shouldn't document exist in the context of node-webkit?
Yes.
Do require()'d libraries have any means of accessing global vars at the point of execution?
No. It doesn't exist under the hood when it calls require because require loads sub_dependencies without the context of node-webkit. If this is even an issue, it belongs in node-webkit.
It may be the approach of HTML (where HTML is the document.documentElement) may need some "init" function to be compatible if there's no way to access document.
I like this idea. Potentially desired code snippet: var HTML = require('html').HTML;HTML.ify();
Failing any of those approaches, can't node-webkit load HTML.js through a
I assume you mean script tag. The answer is yes. I already created the issue and it may get thrown under the rug as a "Potential feature addition" at best.
Try checking for typeof document === "object"
to determine if delayed loading is necessary.
from html.
I will let you decide if you want to try and fix this within your library, and allow you to close the "non"-issue I have created here.
Thanks for your time!
from html.
from html.
One last thing: The window object exists, but the document object is not global, because the global object is global
, not window
.
You could try fully qualifying window.document
instead of document
to make it work. I think that should do the trick, and the solution itself is cross-browser. I may do the pull request myself after some testing.
from html.
Yeah, if window.document works, i'd accept that pull request. Note that the extensions (alter.js and emmet.js) would need the same treatment to the document references in their last lines as well.
from html.
I have changed the source files, but grunt isn't cooperating, so you would have to accept the pull request on the source files.
I am currently re-installing node because uglify is giving me a hard time about the node version number.
I will throw a pull request after testing is done.
from html.
And the testing did not work. I replaced all the library calls with document references to call window.document.
If I can find an easy solution to fix the issue, I will re-open the thread and submit a pull request.
In the meantime, an obvious workaround is to include a build of HTML.js as a script and call it via a <script>
.
It may also be a good practice keeping client side javascript separate from node API calls anyway.
Thanks for your help @nbubna , I will keep you posted.
from html.
In order to pursue a fix, I would have to make a structural change to the HTML.core.js
file
Possible solution update in top level of library:
if(typeof module === "object" && module.exports){
module.exports = function(window){
//library inline here
HTML.init(window, window.document);
return HTML;
}
} else {
HTML.init(window, document);
}
Call it like this from node_modules folder: require("html.js")(window)
Are you even interested in something like this? Seems like a lot of work to work around adding a script tag to a screen.
from html.
Yeah, i'm not seeing a lot of value to the adjustment either. I think we can just leave it closed. If a more compelling case emerges, at least we've made good progress on a solution.
from html.
btw, it seems like another fix is to expose document as a global first thing at the top of your main.js in node webkit:
/**
* A fix for client-side components to work via require.
*/
global.document = window.document;
This is working for me so far :)
from html.
That's brilliant! Thank you so much!
from html.
@reinpk does this have any implications for multi windowed applications?
I think I need to "reset" the global.document property to the document loaded in the new window. No?
from html.
haven't had a chance to play with multi windowed apps, sorry!
from html.
For use in Node-Webkit
To install it to your project:
npm install html.js --save
In node webkit:
//set global variables so that the "require" sees the document and Element in question
global.Element = Element;
global.document = window.document;
var HTML = require("html.js");
//or requirejs
require(['html.js'], function(HTML){
});
Edit; Confirmed, global.document needs to be set AGAIN on a different page because it HTMLify's the prior document.
@nbubna This may be good to place in your readme.md
Re-edit:
I cannot get the new require to pick up the set document. It seems like there is a global variable being set that is overriding my attempts to set the next document.
Must use HTML.ify
..to perform inter-document HTMLification (which is exactly what HTML.ify was designed for)
var HTML = global.HTML.ify(document.querySelector('html'));
This is the only good way to get the job done.
Cheers.
from html.
Related Issues (20)
- Deprecating event() HOT 5
- proxy dot-traversal into first element HOT 3
- Library not found at cdnjs HOT 3
- how to use it?
- Adding text nodes HOT 3
- How to use inside node? HOT 2
- Manipulate XML string HOT 3
- no main declared in package.json
- Uncaught TypeError: Failed to execute 'add' on 'HTMLSelectElement': The provided value is not of type '(HTMLOptionElement or HTMLOptGroupElement)' HOT 4
- .textContent not working properly HOT 15
- document is terrible HOT 2
- files hosted on cdnjs HOT 2
- No update? HOT 3
- Voyeur performance issue HOT 8
- Some demo issues HOT 8
- Offer a comparison with dunxrion/voyeur.js HOT 2
- ES6 has Array.prototype.find (conflicts with HTML._.fn.find for element lists) HOT 1
- Component.js Package HOT 10
- Please tag HTML.js releases HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from html.