Git Product home page Git Product logo

twitter-bootstrap-rails-confirm's Introduction

Twitter::Bootstrap::Rails::Confirm

This gem adds some javascript to change the default behaviour of data-confirm processing for both Boostrap 2, 3 and 4.

The normal confirm dialog shows a text with buttons 'ok' and 'cancel'. More information is needed here for a user to make the right decision. This gem therefore also adds:

  • data-confirm-fade (default: false)
  • data-confirm-title (default: window.top.location.origin)
  • data-confirm-cancel (default: 'cancel')
  • data-confirm-cancel-class (default: 'btn cancel')
  • data-confirm-proceed (default: 'ok')
  • data-confirm-proceed-class (default: 'btn-primary')

This behaviour is similar to that of a "regular" confirm box in ways that it uses the same title and button labels. Defaults can be changed in two ways:

Changing all default values:

$.fn.twitter_bootstrap_confirmbox.defaults = {
  fade: false,
  title: null, // if title equals null window.top.location.origin is used
  cancel: "Cancel",
  cancel_class: "btn cancel",
  proceed: "OK",
  proceed_class: "btn proceed btn-primary",
  modal_class: ""
};

Only changing one default value:

$.fn.twitter_bootstrap_confirmbox.defaults.proceed_class = "btn proceed btn-success";

Installation

Add this line to your application's Gemfile:

gem 'twitter-bootstrap-rails-confirm'

And then execute:

$ bundle

Note: jQuery-Rails should be > 2.2.1. The exact required version has not yet been determined.

Usage

Add it to your application.js, anywhere after you require jquery_ujs:

//= require twitter/bootstrap/rails/confirm

Next... nothing. There is nothing you need to do to get this working. A helper could be useful for handling large amount of destroy buttons:

def destroy_link_to(path, options)
  link_to t('.destroy'), path,
    :method => :delete,
    :class => "btn",
    :confirm => t('.destroy_confirm.body', :item => options[:item]),
    "data-confirm-fade" => true,
    "data-confirm-title" => t('.destroy_confirm.title', :item => options[:item]),
    "data-confirm-cancel" => t('.destroy_confirm.cancel', :item => options[:item]),
    "data-confirm-cancel-class" => "btn-cancel"),
    "data-confirm-proceed" => t('.destroy_confirm.proceed', :item => options[:item]),
    "data-confirm-proceed-class" => "btn-danger"
end

Testing

See Twitter Bootstrap Rails Confirm Test for a simple app that loads Bootstrap and this gem.

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Changelog

1.0.7 (November 24, 2017)

1.0.6 (June 9, 2016)

1.0.5 (February 5, 2016)

1.0.4 (November 25, 2014)

1.0.3 (September 4, 2014)

1.0.2 (Oktober 11, 2013)

1.0.1 (April 23, 2013)

1.0.0 (February 22, 2013)

  • First 'official' release
  • Many thanks to taavo for his contributions

twitter-bootstrap-rails-confirm's People

Contributors

rvanlieshout avatar taavo avatar stevelacey avatar digitalfrost avatar kramerc avatar tobscher avatar joseramonc avatar marceuy avatar martijn avatar mfrederickson avatar zsy056 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.