GithubHelp home page GithubHelp logo

wordpressdev / ajax-include-pattern Goto Github PK

View Code? Open in Web Editor NEW

This project forked from filamentgroup/ajax-include-pattern

0.0 2.0 0.0 205 KB

An Ajax-Include Pattern for Modular Content

Home Page: http://filamentgroup.com/lab/ajax_includes_modular_content/

License: MIT License

ajax-include-pattern's Introduction

Ajax-include pattern

  • Copyright 2012, Scott Jehl, Filament Group, Inc. Original idea from Scott Gonzalez :)

Build Status

Getting Started

Download the production version or the development version.

How-to

To use, add attributes to elements in your page where non-essential fragments of content can be included from an external URL, using jQuery-api-like qualifiers like data-after, data-before, data-append, and data-replace:

Replace:

<a href="..." data-replace="articles/latest/fragment">Latest Articles</a>

Before:

<a href="..." data-before="articles/latest/fragment">Latest Articles</a>

After:

<a href="..." data-after="articles/latest/fragment">Latest Articles</a>

Append:

<a href="..." data-append="articles/latest/fragment">Latest Articles</a>

Note: these attributes can be placed on any element, not just anchors.

Once the DOM is ready, you can apply the plugin like this:

$("[data-append],[data-replace],[data-after],[data-before]").ajaxInclude();

media-qualified includes

To include content based on a particular CSS3 Media Query, you can add a data-media attribute to the element that already has one of the ajax-include data attributes specified above, and give that attribute a value of any CSS3 media query. The content of that include will only be requested and inserted into the page if and when that media query is valid (which could happen at page load or later on, after an orientation change or resize for example).

Include the referenced fragment at viewport widths of 30em and up:

<a href="..." data-append="articles/latest/fragment" data-media="(min-width: 30em)">Latest Articles</a>

Demos

To view some demos, you can visit the following page in your browser, or clone down this repo and browse to the test/functional/ directory (you'll need to be running a local web server for the ajax to work in most browsers).

Ajax-Include Demos

(Note that the proxy demo page will not work at the above URL because it needs to be run on a web server with PHP support.)

Optional Proxy

To use the proxy and include all ajax includes in one call, just pass in a URL that is ready to accept a list of files, such as the included quickconcat.php file in the root of this demo, as an argument to the ajaxInclude method. Note that quickconcat.php is from the external project, quickconcat - check out that project for usage examples.

$("[data-append],[data-replace],[data-after],[data-before]").ajaxInclude( { proxy: "quickconcat.php?wrap&files=" } );

Note: in prior versions, ajaxInclude supported a single string argument for the proxy url. This is currently deprecated and will be removed in an upcoming version.

Browser Support

Ajax-Include works in most modern and semi-modern browsers, even IE6. That said, the data-media feature will only work in media-query supporting browsers, and for broad compatibility within media-query supporting browsers, it's recommended that you include the MatchMedia polyfill and MatchMedia addListener polyfill. Both can be found in the libs/ directory, or at the matchMedia polyfill project on Github. To see how these are used alongside ajaxInclude, check out the source of any of the demo pages.

Unit Tests

The unit test suite can be run via tests/ajaxInclude.html, or on the Github site here. Note that the unit tests for the optional proxy noted above will only run on a php-supporting web server.

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using grunt.

Also, please don't edit files in the "dist" subdirectory as they are generated via grunt. You'll find source code in the "src" subdirectory!

Release History

License

Copyright (c) 2012 @scottjehl, Filament Group, Inc.
Licensed under the MIT license.

ajax-include-pattern's People

Contributors

jefflembeck avatar patocallaghan avatar

Watchers

 avatar  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.