Coder Social home page Coder Social logo

backbone-wordpress-demo's Introduction

Refactoring WordPress PHP & jQuery code to use Backbone

Inspired by Step by Step from jQuery to Backbone, this is an example of how to take a small gallery component, primarily authored within the PHP of a WordPress theme and refactor it to render on the front-end, first with jQuery and then finally by using Backbone models and views.

  1. Our baseline: an old-fashioned PHP-heavy solution
  2. Move gallery rendering to JS): Reduce iteration within the PHP by adding data- attributes to the trigger links, and use that object's .data() to render out the featured image JS-side
  3. Get that HTML out of our JavaScript by embedding the markup back in the .php file as an inline template and using _.template to render
  4. Move the markup into an HTML partial and pre-compile the template with Grunt
  5. Refactor the jQuery used to render the featured image using a Backbone model and view
  6. Move the model and view code into separate files
  7. Refactor the remaining pure jQuery code into Backbone views

With the exception of the first step, each of those links will take you to the pull request where I walk through the code changes being made as we move from one step to the next.

backbone-wordpress-demo's People

Contributors

kadamwhite avatar

Watchers

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