Code Monkey home page Code Monkey logo

fancybrowser's Introduction

Fancy Browser

This is a collection of DOM helpers, keyboard keycodes, and more (but not much more) for Haxe. Think of it as jQuery, but without most of the features and with none of the cross-browser normalization. Mostly, this provides some helpful extension methods on top of js.html.Element in Haxe.

This was extracted without any modification from FancySearch. It wasn't originally intended to be a reusable library, but I have use for it in other fancy.* libraries, so here it is.

fancybrowser's People

Contributors

mlms13 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

fancybrowser's Issues

IE struggles with prependChild

If the element has no children when we try to prepend a child, IE 10 (and probably other IEs) chokes on el.insertBefore(newNode, el.children[0]). Since el.children is an empty array (or nodelist, probably), accessing its first child returns undefined. MDN has a confusing paragraph about how undefined is treated differently than null in this case, yet things seem to work everywhere except IE.

Surely we can find a solution, possibly by checking the length of el.children first, and maybe explicitly passing null if need be, or... something.

Use classlist in browsers that support it

It would be nice if addClass and removeClass could still accept a space-separated list of classes. We'll just handle the splitting and iterating. So to be clear:

  • Detect browser support for el.classList
  • Split the input string on spaces
  • addClass
    • If classList is supported, iterate over each class and add it
    • If classList is not supported, just concat the entire string
  • removeClass
    • If classList is supported, iterate over each class and remove
    • If classList is not supported, we still need to iterate over each class, removing it with a regex

Allow creating elements with an id and other attributes

Currently we're splitting name on . and treating everything as a classname. Really we should also:

  • First split the name for [] pairs and push everything we find to the attrs object
  • Also check for # in the name and use that to set an id
  • Push all of the . classes we find to attrs so we can deal with all attributes at once
  • Write some serious tests for all of this

Default Dom.create() to div

If no element name is provided (name string begins with a symbol such as .), don't shift the nameParts, and instead set name to "div".

Replace Elements with Nodes in some places

Many of our methods could expect a Node instead of an Element, particularly methods that insert children into the DOM. As it's currently written, our library won't accept the result of cloneNode() as a valid child, even though it totally is. This should be easy to fix without breaking any existing APIs.

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.