less.js icon indicating copy to clipboard operation
less.js copied to clipboard

@height: document.body.clientHeight - Not work

Open Pestov opened this issue 14 years ago • 4 comments

It is also possible to access the JavaScript environment:

@height: document.body.clientHeight;

This is information on http://lesscss.org. It's no work!

@screenWidth: document.body.clientWidth; @screenHeight: document.body.clientHeight;

#leadBody {
   background: url('../images/sidebar_body.png') repeat fixed left center #0296BA;
   width: @screenWidth;
   overflow: hidden;
}

Or

@screenWidth: ~document.body.clientWidth; @screenHeight: ~ document.body.clientHeight;

#leadBody {
   background: url('../images/sidebar_body.png') repeat fixed left center #0296BA;
   width: @screenWidth;
   overflow: hidden;
}

It's no work

Pestov avatar Nov 05 '12 22:11 Pestov

In what browser?

lukeapage avatar Nov 07 '12 19:11 lukeapage

I get this with iOS UIWebView or when emulating iOS+phonegap via Mac Chrome + Fiddle. The error is not on the JS execution, but on trying to use that value elsewhere. For instance, if I set @viewportHeight to clientHeight and then set height: @viewportHeight - 42px; for a class I get an exception every time.

Here's an example trace when doing the above (not using .min for clarity here and removed the base href):

Object # has no method 'operate'
in App.less 
at tree.Operation.eval (less-1.3.1.js:2947:14)
at tree.Operation.eval (less-1.3.1.js:2935:30)
at Object.tree.Expression.eval (less-1.3.1.js:2493:34)
at Object.tree.Value.eval (less-1.3.1.js:3527:34)
at tree.Rule.eval (less-1.3.1.js:3056:38)
at Object.tree.Ruleset.eval (ess-1.3.1.js:3136:53)
at Object.tree.Ruleset.eval (less-1.3.1.js:3136:53)
at Object.less.Parser.parser.parse.i [as toCSS] (less-1.3.1.js:545:44)
at less.refresh (less-1.3.1.js:3698:28)
at href (less-1.3.1.js:3775:25)

When I pause on exception, I can see that the "a" var declared on line 2935 is tree.Anonymous and doesn't have the "operate" prototype method (or the prototype of that prototype), as indicated by Chrome's inspector of local scope on the exception:

<exception>: TypeError
a: tree.Anonymous
  value: 38
  __proto__: Object
    compare: function (x) {
    eval: function () { return this }
    toCSS: function () {
    __proto__: Object
b: tree.Dimension
  unit: "px"
  value: 42
  __proto__: Object
env: Object
  frames: Array[2]
    0: tree.Ruleset
    1: tree.Ruleset
    length: 2
     __proto__: Array[0]
  __proto__: Object
temp: undefined
this: tree.Expression

I hope some of this is helpful.

ziemkowski avatar Nov 16 '12 06:11 ziemkowski

Just tried it with less-1.4.0.js in the 1_4_0 branch and it does recognize it as a type error and throws a more specific exception on line 3316:

<exception>: Object
  message: "Operation on an invalid type"
  name: "OperationError"
  __proto__: Object
a: tree.Anonymous
  value: 38
  __proto__: Object
b: tree.Dimension
  unit: tree.Unit
  value: 42
  __proto__: Object
env: Object
temp: undefined
this: tree.Operation

FWIW, the red error box message is less informative in that codeline:

Operation on an invalid type
in App.less on line null, column 0:
NaN

Doesn't suggest a way to actually use the value though.

ziemkowski avatar Nov 16 '12 06:11 ziemkowski

ok, I understand.. yes javascript isn't "parsed".. that bug is discussed in #88 #349 and #476

closing as duplicate

lukeapage avatar Dec 06 '12 13:12 lukeapage