Giter Site home page Giter Site logo

emamatcyber90 / amdquery Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 244 KB

A selector plugin for RequireJS with a dynamic query selector polyfill, supporting modular DOM utilities and builds.

License: MIT License

JavaScript 99.20% Shell 0.06% CSS 0.17% HTML 0.56%

amdquery's Introduction

AMD Query

An AMD DOM utility plugin.

No longer maintained, or advised for use.

Conditionally polyfills the native selector engine, and is compatible with modular query methods to provide DOM traversal, events, animations, etc.

Usage is of the form:

require(['amdquery!events,animations'], function($) {
  $('#some-element').click(...);
});

Where events and animations are modular query methods.

Installation

volo add guybedford/amdquery

(after npm install volo -g)

This will also download the require-is loader module dependency.

When in an AMD project, Volo will automatically generate wrapper modules at is.js and amdquery.js for the folder files.

If not using Volo, download amdquery and require-is into their folders in the main library folder.

Then ensure that amdquery and is are added in the requirejs map config:

{
  map: {
    '*': {
      is: 'require-is/is',
      amdquery: 'amdquery/amdquery'
    }
  }
}

Currently Supported Query Methods

Currently, the following query method libraries are supported:

Bean (bridge module)

Bonzo (bridge module)

Morpheus (bridge module)

To submit a new query method module, submit a pull request.

Native Selector Polyfill

Feature detects the native selector engine, loading Sizzle from CDN as a fallback only when necessary.

Feature detections are the attribute selector, attribute equals selector, direct child and sibling selector support.

When using the native selector, contextual selection of the form $('selector', context) is fixed to work naturally instead of to the spec (http://ejohn.org/blog/thoughts-on-queryselectorall/).

The selector also adds support to the native selector for the leading direct child selector within contextual selectors of the form: $('> child', context)

Pluggable Selector Functionality

AMD Query provides a plugin API for loading selector-compatible modules for modular selector functionality loaded with the syntax 'amdquery!moduleName'

For example, an event module can provide the click event method as:

click.js:

define({
  prototype: {
    click: function(callback) {
      this[0].addEventListener('click', callback);
    }
  }
});

which can then be used with:

app.js:

require(['amdquery!click'], function($) {
  $('#myel').click(function(){ /* etc */ });
});

Static methods can be provided outside of the prototype property with:

static.js

define({
  ready: function() { /* ... */ }
});

which can be used as:

require(['amdquery!static'], function($) {
  $.ready('...');
});

All combinations of query method bundles are generated uniquely to avoid namespace collissions.

This allows separate modules to define the same click method for example without clashing.

Builds

When running a build with the r.js optimizer, only those selector features needed by the layer get traced. Sizzle is always excluded from the build and downloaded dynamically on older browsers, meaning the loading experience is modern browsers doesn't suffer due to having to provide legacy support.

Uses the require-is module to conditionally load sizzle.

Footprint

2.7KB minified and gzipped, in contrast to 33KB for jQuery.

So for example if you just need DOM events with Bean, only download 6.7KB instead of 33KB.

License

MIT

amdquery's People

Contributors

guybedford avatar

Watchers

 avatar

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.