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
EQCSS is not defined #96
Comments
If EQCSS is not defined you can be sure that the JavaScript has not properly or fully loaded. Just typing <script src=https://elementqueries.com/EQCSS.min.js></script>
<script>alert(EQCSS.version)</script> Here's a basic HTML test that should alert the currently loaded EQCSS version number. If this works for you, but not how you're currently loading the plugin, there must be some kind of problem with the way you've loaded the JavaScript, or where you're trying to access it from or something. Do you have an example of the site online anywhere that we could troubleshoot or debug it? |
Hi @tomhodgins . Thanks for the reply :) I slapped your code into my page, and then removed the other section I had to load it via requireJS. When I run the page I now get: I'm afraid the page in question isn't public facing (we have it behind an IP firewall to stop dup content coming up, as its our dev server). If you are happy to email me your IP on andy.newby@gmail.com, then I'm more than happy to add your IP to the firewall so you can see it :) Interestingly it works fine on a fiddle: http://jsfiddle.net/youradds/om60w4zb/ Thanks Andy |
Ah, that makes me wonder if it's something to do with client side 'module' loading! EQCSS is wrapped in a UMD wrapper to attempt to let it be handled by various different module loaders while still working out-of-the-box in the browser if no module loader is found. I believe we used a version of this template -> https://github.com/umdjs/umd/blob/master/templates/amdWebGlobal.js Is it possible to load EQCSS separately from the other module loading, and link it into your HTML before Alternatively, what if you manually 'unwrap' the EQCSS plugin code from its current wrapper, I'm not sure how you're loading the other frontend code, but taking EQCSS out of its wrapper and packaging it up similar to your other code should work, the plugin itself doesn't take advantage of any modular functionality inside the plugin so it should be fine run as a normal global JS plugin :D |
@tomhodgins you star! That was it. I removed the wrapper code for it, and now it correctly prints out the version number as an The other thing I was a bit confused about was how to generate them with SASS. I've seen people talking about it, but I couldn't find any mixin's for it? (I found a reference to some _raw() functions, but that didn't do it for me). If there is a "proper" SASS template functionality I could use, that'd be awesome 👍 Thanks Andy |
Yay! Glad that worked :D I've seen a number of different Sass mixins that kind of quote code to pass through, but I am not sure it makes sense to do extra work in your preprocessor for the purpose of passing through code that will be parsed by something else later. I'd recommend breaking out the EQCSS-powered styles from the Sass and handling them separately. More info about EQCSS + preprocessors here: https://github.com/eqcss/eqcss/wiki/Using-EQCSS-with-CSS-Preprocessors including a link to one of the mixins I've seen floating around for Sass |
Awesome thanks. I think you may be right about taking it out of the SASS stuff. Its a bit of a niche thing I'm needing to do inside a modal (obviously MQ's don't work when you have a fixed size modal that only gets smaller at x pixels) I've added this test code in:
My understanding is that it should make the background red for
+ data + ;
Maybe I need to do it another way for it to work? I'm just heading out for the evening. Thanks for your help so far. Much appreciated! ( I was going round and round in circles with this earlier, trying to figure out what I was doing wrong) Thanks Andy |
It should be okay. If you're wondering what styles EQCSS has successfully parsed and loaded you can peek inside the If this is good, you're golden so far. It doesn't matter what HTML is loaded, EQCSS knows about this rule. Suppose you have markup that doesn't exist on the page at first, but at some point you add more markup. EQCSS will normally apply on Here's a little demo where I store some HTML that your style would apply to in a <template>
<div id=main-suggestion-wrapper>
<div class=col>I'm a test!</div>
</div>
</template>
<style>
@element #main-suggestion-wrapper .col and (max-width: 800px) {
$this { background: red; }
}
</style>
<script src=https://elementqueries.com/EQCSS.min.js></script>
<script>
// Add HTML from <template> to <body> after 1 second
setTimeout(() => {
const template = document.querySelector('template')
Array.from(template.content.children).forEach(child =>
document.body.appendChild(child)
)
EQCSS.apply()
}, 1000)
</script> If this demo didn't have |
Thanks for that Interestingly I get:
I have done the same test as you:
Am I correct in thinking the rules should be loaded into I expect you are in bed now, so I will carry on playing with it. Hopefully I can resolve it :) Thanks Andy |
OK I'm getting closer. It seems it doesn't like it when the CSS is loaded dynamically:
Shouldn't it detect a new CSS file was added, and then process that as well? If I change it to a static tag in the HTML page it works fine:
Gives me:
|
BTW I wonder if its possible in a future version to allow people to decide what they want to actually process? i.e there is little point processing inline styles or .css files, if all the work is in the .css files. For me I have just commented out:
I'm going to put all the stuff in the .eqcss files to keep it tidy (as your suggested), so there is no point processing the .css / <style> bits. Maybe you could put some options at the top, so people could update the flags for |
Yes, any rules that have been parsed or loaded into the
You can run If you are adding only EQCSS to the page, you can also parse and load the code via JS directly to get it into You can also use If you're working with the EQCSS syntax as a string in JS you can get it right into the plugin without it ever existing in the DOM.
As EQCSS parses styles from a tag it adds a |
Hi, Cool thanks :) so if I added Cheers Andy |
Yes, put that on any Since EQCSS I've continued working on a number of different plugins that all solve similar issues. Lately the performance of jsincss and some of its plugins can be 10x faster than similar functionality in EQCSS. I'll show a few examples :D First we'll start with an EQCSS example. Here I have a <div>EQCSS</div>
<script src=https://unpkg.com/eqcss/EQCSS.js></script>
<script>
EQCSS.process(`
@element div and (min-width: 800px) {
:self {
background: lime;
}
}
`)
</script> We can eliminate the need for reading the custom style if we write <div>jsincss + jsincss-element-query</div>
<script type=module>
import jsincss from 'https://unpkg.com/jsincss/index.vanilla.js'
import element from 'https://unpkg.com/jsincss-element-query/index.vanilla.js'
jsincss(() => `
${element('div', {minWidth: 800}, `
[--self] {
background: lime;
}
`)}
`)
</script> And if you squint your eyes it kinda sorta looks something like our EQCSS syntax before, but instead of writing CSS you're writing JavaScript. The other benefit is that you have easy flexibility of what functionality you want to use. EQCSS has element queries, extra selectors, JS evaluation in CSS, element based units, etc, and you don't always need all of the features. With jsincss you can make individual functions for each feature you want to use and load only the parts that matter. That's where part of the performance increase comes from. But, just this summer I learned how we could express this in valid CSS, so you can write a valid CSS stylesheet that contains the information you otherwise would have put in EQCSS. You can preprocess it server-side with qaffeine or client-side in the browser with deqaf and extract the values that jsincss and its plugins are looking for. Here's the same example, except instead of a custom script type I'm writing the information in pure CSS, in a way that the browser will ignore, but JS can read and act on. This allows you to run code very similar to the previous jsincss example, only you're writing CSS instead of Javascript. And it still resembles EQCSS if you squint your eyes! <div>deqaf + jsincss-element-query</div>
<style>
@supports (--element("div", {"minWidth": 800})) {
[--self] {
background: lime;
}
}
</style>
<script type=module>
import deqaf from 'https://unpkg.com/deqaf/index.js'
import element from 'https://unpkg.com/jsincss-element-query/index.vanilla.js'
deqaf({stylesheet: {element}})
</script> So there are a lot of different ways you can express the same kind of logic, and ways you can easily use your own functionality for styling! |
Hi, Wow thanks for the detailed reply! I will have a look into the tweaking of specific features for what we need. TBH I'm only processing a short file with a few rules in - so it may be better to run the EQCSS.process() method inline in the JS, so there is no need for the extra .eqcss file (seeing as its only a few lines) Thanks again - I really appreciate the time and effort that you've put into this plugin 💯 Cheers andy |
Hi,
I can't get this to work. I can see the script loading in the timeline, but if I try and do:
EQCSS.apply()
I get an error. Looking on here you say you try running
EQCSS
in the Firebug console line. I run it, and I get:What am I doing wrong?
Thanks
Andy
The text was updated successfully, but these errors were encountered: