common-dialogs 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.md +46 -0
- data/Rakefile +27 -0
- data/lib/assets/javascripts/common-dialogs.js.coffee +77 -0
- data/lib/assets/stylesheets/common-dialogs.scss +21 -0
- data/lib/common-dialogs/version.rb +3 -0
- data/lib/common-dialogs.rb +4 -0
- data/lib/tasks/common-dialogs_tasks.rake +4 -0
- metadata +92 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2012 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
# Common Dialogs for replacing JavaScript alert/confirm/prompt.
|
2
|
+
|
3
|
+
This provides asynchronous alternatives to alert, confirm and prompt.
|
4
|
+
|
5
|
+
# Installing
|
6
|
+
|
7
|
+
Add "gem 'common-dialogs'" to your Gemfile and run bundle.
|
8
|
+
|
9
|
+
It also depends on jQuery-UI being installed. I recommend the
|
10
|
+
[jquery-ui-themes](https://github.com/fatdude/jquery-ui-themes-rails) gem.
|
11
|
+
|
12
|
+
Then require the bundled assets after requiring jQuery UI.
|
13
|
+
|
14
|
+
For example, if you're using the jquery-ui-themes gem, your application.js would look like this:
|
15
|
+
|
16
|
+
//= require jquery
|
17
|
+
//= require jquery_ujs
|
18
|
+
//= require jquery-ui
|
19
|
+
//= require common-dialogs
|
20
|
+
CommonDialogs.require() // remove this if you don't want to add the helpers to the window object
|
21
|
+
|
22
|
+
And in application.css (see the supported themes list in the link above):
|
23
|
+
|
24
|
+
/*
|
25
|
+
= require jquery-ui/smoothness
|
26
|
+
= require common-dialogs
|
27
|
+
*/
|
28
|
+
|
29
|
+
# Usage examples (in CoffeeScript for better readability)
|
30
|
+
|
31
|
+
showMessage 'Any message' # Dialog title is "Message" by default
|
32
|
+
showMessage 'Any message', title: 'Dialog Title', onClose: (-> console.log 'closed'), additionalClasses: 'success popup'
|
33
|
+
# the CSS classes in additionalClasses will be added to the dialog div
|
34
|
+
# All dialogs support those options.
|
35
|
+
showError 'An error message with alert icon'
|
36
|
+
confirmDialog 'Really remove task?', (-> console.log 'confirmed'), noAction: -> console.log 'answered no - this option is not required'
|
37
|
+
inputDialog 'What is your name?', ((name)-> console.log "Your name is #{name}"),
|
38
|
+
initialValue: 'Optional initial value'
|
39
|
+
required: false # true by default, which means that an empty string is not allowed by default
|
40
|
+
cancelAction: (-> console.log 'cancel was called - this option is not required')
|
41
|
+
|
42
|
+
# Custom messages and button names
|
43
|
+
|
44
|
+
Feel free to change the default messages and button names by changing the
|
45
|
+
CommonDialogs.defaults object. Just inspect it (console.log(CommonDialogs.defaults))
|
46
|
+
to see what keys to change and what are their default values.
|
data/Rakefile
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
begin
|
8
|
+
require 'rdoc/task'
|
9
|
+
rescue LoadError
|
10
|
+
require 'rdoc/rdoc'
|
11
|
+
require 'rake/rdoctask'
|
12
|
+
RDoc::Task = Rake::RDocTask
|
13
|
+
end
|
14
|
+
|
15
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
16
|
+
rdoc.rdoc_dir = 'rdoc'
|
17
|
+
rdoc.title = 'CommonDialogs'
|
18
|
+
rdoc.options << '--line-numbers'
|
19
|
+
rdoc.rdoc_files.include('README.rdoc')
|
20
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
21
|
+
end
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
|
26
|
+
Bundler::GemHelper.install_tasks
|
27
|
+
|
@@ -0,0 +1,77 @@
|
|
1
|
+
CD = @CommonDialogs =
|
2
|
+
defaults: m =
|
3
|
+
title:
|
4
|
+
message: 'Message'
|
5
|
+
error: 'Error'
|
6
|
+
confirm: 'Please, confirm'
|
7
|
+
input: 'Please, answer'
|
8
|
+
messages:
|
9
|
+
ok: 'Ok'
|
10
|
+
confirm:
|
11
|
+
yes: 'Yes'
|
12
|
+
no: 'No'
|
13
|
+
input:
|
14
|
+
ok: 'Ok'
|
15
|
+
cancel: 'Cancel'
|
16
|
+
cantBeEmpty: "input field can't be empty"
|
17
|
+
|
18
|
+
require: -> window[f] = CD[f] for f in ['showMessage', 'showError', 'confirmDialog', 'inputDialog']
|
19
|
+
|
20
|
+
showMessage: (message, options={})->
|
21
|
+
content = $('<div class=alert-dialog />').text(message)
|
22
|
+
content.addClass(c) if c = options.additionalClasses
|
23
|
+
buttons = createButtons [[m.messages.ok, -> $(this).dialog 'close']]
|
24
|
+
createDialog content, options.title or m.title.message, buttons, options.onClose
|
25
|
+
|
26
|
+
showError: (message, options={})=>
|
27
|
+
options.title ?= m.title.error
|
28
|
+
options.additionalClasses = 'error'
|
29
|
+
CD.showMessage message, options
|
30
|
+
|
31
|
+
confirmDialog: (question, onConfirm, options={})->
|
32
|
+
content = $('<div class=confirm-dialog />').text(question)
|
33
|
+
buttons = createButtons [
|
34
|
+
[m.confirm.yes, -> onConfirm(); $(this).dialog 'close']
|
35
|
+
[m.confirm.no, -> options.noAction?(); $(this).dialog 'close']
|
36
|
+
]
|
37
|
+
createDialog content, options.title or m.title.confirm, buttons, options.onClose
|
38
|
+
|
39
|
+
inputDialog: (message, onConfirm, options={})->
|
40
|
+
options.required ?= true
|
41
|
+
content = $('<div class=input-dialog />')
|
42
|
+
.append($('<div class=message/>').text message)
|
43
|
+
.append(input = $('<input type=text />'))
|
44
|
+
input.val options.initialValue
|
45
|
+
input.keydown (ev)->
|
46
|
+
return unless ev.which is 13 # ENTER
|
47
|
+
dialog.siblings('.ui-dialog-buttonpane').find('button:eq(0)').click()
|
48
|
+
|
49
|
+
canceled = true
|
50
|
+
buttons = createButtons [
|
51
|
+
[m.input.ok, ->
|
52
|
+
value = input.val().trim()
|
53
|
+
unless value or not options.required
|
54
|
+
CD.showError m.input.cantBeEmpty, onClose: -> input.focus()
|
55
|
+
return
|
56
|
+
onConfirm value
|
57
|
+
$(this).dialog 'close'
|
58
|
+
canceled = false
|
59
|
+
]
|
60
|
+
[m.input.cancel, -> $(this).dialog 'close']
|
61
|
+
]
|
62
|
+
dialog = createDialog content, options.title or m.title.input, buttons,
|
63
|
+
-> options.cancelAction?() if canceled
|
64
|
+
input.select().focus()
|
65
|
+
|
66
|
+
createButtons = (buttons) ->
|
67
|
+
hash = {}
|
68
|
+
hash[button[0]] = button[1] for button in buttons
|
69
|
+
hash
|
70
|
+
|
71
|
+
createDialog = (content, title, buttons, onClose)->
|
72
|
+
$('<div/>').append(content).dialog
|
73
|
+
minHeight: 50
|
74
|
+
modal: true
|
75
|
+
close: -> $(this).dialog('destroy').remove(); onClose?()
|
76
|
+
title: title
|
77
|
+
buttons: buttons
|
@@ -0,0 +1,21 @@
|
|
1
|
+
div.alert-dialog, div.confirm-dialog, div.input-dialog {
|
2
|
+
padding-left: 40px;
|
3
|
+
min-height: 32px;
|
4
|
+
}
|
5
|
+
|
6
|
+
div.alert-dialog {
|
7
|
+
background: image-url('application/common-dialogs/info.gif') no-repeat left;
|
8
|
+
}
|
9
|
+
|
10
|
+
div.alert-dialog.error {
|
11
|
+
background-image: image-url('application/common-dialogs/important.gif');
|
12
|
+
}
|
13
|
+
|
14
|
+
div.confirm-dialog, div.input-dialog {
|
15
|
+
background: image-url('application/common-dialogs/help.gif') no-repeat left;
|
16
|
+
}
|
17
|
+
|
18
|
+
div.input-dialog input {
|
19
|
+
display: block;
|
20
|
+
width: 100%;
|
21
|
+
}
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: common-dialogs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Rodrigo Rosenfeld Rosas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-05 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jquery-rails
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: coffee-rails
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :runtime
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
description: Provide non-blocking (asynchronous) alert, confirm and prompt for JavaScript
|
47
|
+
applications
|
48
|
+
email:
|
49
|
+
- rr.rosas@gmail.com
|
50
|
+
executables: []
|
51
|
+
extensions: []
|
52
|
+
extra_rdoc_files: []
|
53
|
+
files:
|
54
|
+
- lib/common-dialogs/version.rb
|
55
|
+
- lib/assets/javascripts/common-dialogs.js.coffee
|
56
|
+
- lib/assets/stylesheets/common-dialogs.scss
|
57
|
+
- lib/tasks/common-dialogs_tasks.rake
|
58
|
+
- lib/common-dialogs.rb
|
59
|
+
- MIT-LICENSE
|
60
|
+
- Rakefile
|
61
|
+
- README.md
|
62
|
+
homepage: http://github.com/rosenfeld/common-dialogs
|
63
|
+
licenses: []
|
64
|
+
post_install_message:
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ! '>='
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '0'
|
74
|
+
segments:
|
75
|
+
- 0
|
76
|
+
hash: -3991690647463446503
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ! '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
hash: -3991690647463446503
|
86
|
+
requirements: []
|
87
|
+
rubyforge_project:
|
88
|
+
rubygems_version: 1.8.21
|
89
|
+
signing_key:
|
90
|
+
specification_version: 3
|
91
|
+
summary: Common JavaScript dialogs
|
92
|
+
test_files: []
|