Skip to content

Instantly share code, notes, and snippets.

@pastcompute
Last active July 24, 2016 09:13
Show Gist options
  • Save pastcompute/d103281eafe4c338c2b213a68c354e82 to your computer and use it in GitHub Desktop.
Save pastcompute/d103281eafe4c338c2b213a68c354e82 to your computer and use it in GitHub Desktop.
Javascript annoyances

Key Takeaways

  • margin is outside the border
  • padding is inside the border
  • fixed is relative to viewport, absolute is relative to position, relative is to where it otherwise would be ... sigh
  • bottom is positive up relative to container, when position==absolute. Clobbers parent bottom-padding
  • border-width can offset DOM-nested items appearing like extra margin... To fix border outside of div, use box-sizing:border-box
  • The border of body can enclose nothing if first DOM-child is absolute
  • overflow works at parent
  • white-space:nowrap is as needed as overflow:hidden. Prevents drawing across border - but not padding ...

The special character aligns badly with text depending on font, which means it might be safer to use a bitmap?

Filling height to 100% requires 100% all the way to <html> - turtles all the way up? Also, excess commas in CSS cause things to not work but don't report errors only warnings, which are usually off in the console because of flooding FFF!

Javascript patterns

requirejs and AMD

  • requirejs - text.js - the browser wont load text! templates for security reasons

Debugging Requirejs

{"requireType":"scripterror","requireModules":["galleria"],"originalError":{"isTrusted":true}} main.js:30:3
Error: Script error for "galleria", needed by: app
http://requirejs.org/docs/errors.html#scripterror

The error occurs for a variety of reasons, but with no actual useful detail.

Typical cause:

  • Specifying the module with '.js' appended in require.config({ paths: {
  • Wrong actual path to the file, or incorrect file name
TypeError: something is undefined

Check further up the log for a syntax error in the js file defining something.

AssertionError: Assertion failed: opt_onFulfilled should be a function.

Somewhere code is directly used inside then, instead of a function name or a ()=>{} construct

$ grunt copy
Loading "Gruntfile.js" tasks...ERROR
>> SyntaxError: Unexpected identifier
Warning: Task "copy" not found. Use --force to continue.

Probably missed a comma

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment