Giter VIP home page Giter VIP logo

Comments (19)

nbubna avatar nbubna commented on August 24, 2024

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.

nbubna avatar nbubna commented on August 24, 2024

Oh, and i should ask. What's not working? What errors are you getting?

from html.

jtenner avatar jtenner commented on August 24, 2024

@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.

jtenner avatar jtenner commented on August 24, 2024

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.

nbubna avatar nbubna commented on August 24, 2024

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.

jtenner avatar jtenner commented on August 24, 2024

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.

jtenner avatar jtenner commented on August 24, 2024

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.

jtenner avatar jtenner commented on August 24, 2024

nwjs/nw.js#1188 (comment)

from html.

jtenner avatar jtenner commented on August 24, 2024

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.

nbubna avatar nbubna commented on August 24, 2024

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.

jtenner avatar jtenner commented on August 24, 2024

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.

jtenner avatar jtenner commented on August 24, 2024

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.

jtenner avatar jtenner commented on August 24, 2024

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.

nbubna avatar nbubna commented on August 24, 2024

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.

reinpk avatar reinpk commented on August 24, 2024

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.

jtenner avatar jtenner commented on August 24, 2024

That's brilliant! Thank you so much!

from html.

jtenner avatar jtenner commented on August 24, 2024

@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.

reinpk avatar reinpk commented on August 24, 2024

haven't had a chance to play with multi windowed apps, sorry!

from html.

jtenner avatar jtenner commented on August 24, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.