Giter Site home page Giter Site logo

tomchentw / angular-ujs Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 7.0 1.04 MB

Unobtrusive scripting for AngularJS ( without jQuery dependency )

Home Page: http://tomchentw.github.io/angular-ujs

License: MIT License

Ruby 36.99% LiveScript 31.97% CSS 2.79% JavaScript 9.72% Makefile 2.66% HTML 15.87%

angular-ujs's Introduction

angular-ujs

Distributed via

Version

Unobtrusive scripting for AngularJS ( without jQuery dependency )

Travis CI   Quality     Coverage    Dependencies

Project philosophy

Develop in LiveScript

LiveScript is a compile-to-js language, which provides us more robust way to write JavaScript.
It also has great readibility and lots of syntax sugar just like you're writting python/ruby.

Native, lightweight directives

Unobtrusive scripting in jquery_ujs provides the same interface with angular directives.
We use the similarity between them and provides seamless intergration with jquery_ujs.

Spec / Scenario coverage

We use krama to run unit test against angular-ujs.spec.ls and use protractor to run intergration test via angular-ujs.scenario.ls.

Installation

We follow DRY and has one dependency only on angularjs.
However, we recommend you add ng-rails-csrf into your project. As it name suggests, ng-rails-csrf automatically resolves CSRF in angularjs environment without jquery_ujs.

Just use it

Then include them through script tag in your HTML.

Rails projects (Only support 3.1+)

Add this line to your application's Gemfile:

gem 'ng-rails-csrf' # Optional
gem 'angular-ujs'

And then execute:

$ bundle

Then add these lines to the top of your app/assets/javascripts/application.js file:

//= require angular
//= require ng-rails-csrf (Optional)
//= require angular-ujs

And include in your angular module definition:

/* 'angular.ujs' DO NOT depend on 'ng-rails-csrf' module.
* You need to include it yourself.
*/  
var module = angular.module('my-awesome-project', ['angular.ujs']).

Note: Ensure that the ng-app is specified in your application layout (app/views/layouts/application.html.erb):

<!DOCTYPE html>
<html ng-app="my-awesome-project">
<head>

Usage

"data-confirm": Confirmation dialogs for links and forms

<form data-confirm="Are you sure you want to submit?">...</form>

"data-method": Links that result in POST, PUT, or DELETE requests

<a href="..." data-method="delete" rel="nofollow">Delete this entry</a>

"data-remote": Make links and forms submit asynchronously with Ajax

** Notice : API changed **

For angularjs apps, ONLY those items with ng-model will be submitted with data-remote

<form data-remote="true" action="...">
  <input type="text" name="name" ng-model="name">
</form>

You can specify the model name via data-remote :

<form data-remote="user" action="...">
  <input type="text" name="name" ng-model="user.name">
  <input type="email" name="email" ng-model="user.email">
</form>

Use them all together :

<a href="..." data-method="delete" data-remote="true" data-confirm="Are you sure you want to delete?" rel="nofollow">Delete this entry</a>

Contributing

devDependency Status

  1. Fork it ( https://github.com/tomchentw/angular-ujs/fork )
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

angular-ujs's People

Contributors

tomchentw avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

angular-ujs's Issues

Add Note To Ensure ng-app is specified

Hi

I followed your fantastic instructions and love the functionality, I wasn't all that familiar with angular and I was missing the ng-app in the layout. And (of course) it wasn't working. I've added a pull request to include this in the README.md

Thanks!

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.