rails_admin_live_edit 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +19 -0
- data/Rakefile +24 -0
- data/app/views/live_edit/_ra_live_editor.html.haml +136 -0
- data/lib/rails_admin_live_edit.rb +1 -0
- data/lib/rails_admin_live_edit/engine.rb +4 -0
- data/lib/rails_admin_live_edit/version.rb +3 -0
- data/vendor/assets/javascripts/rails_admin/plugins/live_edit/ui.js +23 -0
- data/vendor/assets/javascripts/rmodal.js/LICENSE +21 -0
- data/vendor/assets/javascripts/rmodal.js/README.md +57 -0
- data/vendor/assets/javascripts/rmodal.js/bower.json +28 -0
- data/vendor/assets/javascripts/rmodal.js/dist/rmodal-no-bootstrap.css +37 -0
- data/vendor/assets/javascripts/rmodal.js/dist/rmodal.css +14 -0
- data/vendor/assets/javascripts/rmodal.js/dist/rmodal.js +201 -0
- data/vendor/assets/javascripts/rmodal.js/dist/rmodal.js.map +1 -0
- data/vendor/assets/javascripts/rmodal.js/dist/rmodal.min.js +2 -0
- data/vendor/assets/javascripts/rmodal.js/dist/rmodal.min.js.map +1 -0
- data/vendor/assets/javascripts/rmodal.js/gulpfile.js +99 -0
- data/vendor/assets/javascripts/rmodal.js/index.html +111 -0
- data/vendor/assets/javascripts/rmodal.js/index.js +193 -0
- data/vendor/assets/javascripts/rmodal.js/index.js.map +1 -0
- data/vendor/assets/javascripts/rmodal.js/karma.conf.js +66 -0
- data/vendor/assets/javascripts/rmodal.js/logo.png +0 -0
- data/vendor/assets/javascripts/rmodal.js/package.json +59 -0
- data/vendor/assets/javascripts/rmodal.js/src/rmodal-no-bootstrap.css +37 -0
- data/vendor/assets/javascripts/rmodal.js/src/rmodal.css +14 -0
- data/vendor/assets/javascripts/rmodal.js/src/rmodal.js +188 -0
- data/vendor/assets/javascripts/rmodal.js/test/rmodal.test.js +636 -0
- metadata +72 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2339a07dddfcdd5690c3a14fcfdfac0f2c15762a
|
4
|
+
data.tar.gz: 2b1fa5756f528501112543fdccb3fdc8b3c22c6a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5a36675771287fe3ee9b334f8cccfbe6e6173453d3ed12221473d2cc1e9fc8498ab001100e1136bace1c49af827fa0de008444dc5889631c838645585f2ff786
|
7
|
+
data.tar.gz: 44947a9be01ce4ea66ce32f85457db65553ea87cb89e8d72cf1ab854c8b8fe7b8533976660835d8bfe937bbf83bbf7430dc4fddf6935c3d854b7f045ab96064b
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2017
|
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,19 @@
|
|
1
|
+
# RailsAdminLiveEdit
|
2
|
+
|
3
|
+
A [rails_admin](https://github.com/sferik/rails_admin) plugin to edit site contents from the frontend.
|
4
|
+
|
5
|
+
If the user is logged in in rails_admin and is viewing an editable page an edit button is shown on the top right which allow to open a modal window to edit the page content.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
- Add to Gemfile: `gem 'rails_admin_live_edit'`
|
10
|
+
|
11
|
+
- Add to application layout (in body) (erb example): `<%= render 'live_edit/ra_live_editor' %>`
|
12
|
+
|
13
|
+
- Add to *app/assets/javascripts/application.js*: `//= require rmodal.js/dist/rmodal`
|
14
|
+
|
15
|
+
- Edit or create *app/assets/javascripts/rails_admin/custom/ui.js* and add: `//= require rails_admin/plugins/live_edit/ui.js`
|
16
|
+
|
17
|
+
## Contributors
|
18
|
+
|
19
|
+
- [Mattia Roccoberton](http://blocknot.es) - creator, maintainer
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'RailsAdminLiveEdit'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
load 'rails/tasks/statistics.rake'
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
require 'bundler/gem_tasks'
|
24
|
+
|
@@ -0,0 +1,136 @@
|
|
1
|
+
:ruby
|
2
|
+
ra_le_model = false
|
3
|
+
if defined?( current_user ) && current_user && action_name == 'show' && params[:id]
|
4
|
+
ra_le_model = controller_name.singularize
|
5
|
+
ra_le_id = params[:id]
|
6
|
+
end
|
7
|
+
|
8
|
+
- if ra_le_model && ra_le_id
|
9
|
+
:css
|
10
|
+
.ra-le-button {
|
11
|
+
background: #ddd;
|
12
|
+
color: #004;
|
13
|
+
display: inline-block;
|
14
|
+
padding: 5px 10px;
|
15
|
+
text-decoration: none;
|
16
|
+
}
|
17
|
+
.ra-le-button.btn1 {
|
18
|
+
border-left: 1px solid #aaa;
|
19
|
+
border-bottom: 1px solid #aaa;
|
20
|
+
border-radius: 0 0 0 5px;
|
21
|
+
}
|
22
|
+
.ra-le-button.btn2 {
|
23
|
+
border-left: 1px solid #aaa;
|
24
|
+
border-right: 1px solid #aaa;
|
25
|
+
border-bottom: 1px solid #aaa;
|
26
|
+
border-radius: 0 0 5px 0;
|
27
|
+
}
|
28
|
+
.ra-le-controls {
|
29
|
+
position: fixed;
|
30
|
+
top: 0;
|
31
|
+
right: 10px;
|
32
|
+
}
|
33
|
+
.ra-le-controls > a:hover {
|
34
|
+
background: #eee;
|
35
|
+
color: #000;
|
36
|
+
}
|
37
|
+
#ra-le-modal {
|
38
|
+
display: none;
|
39
|
+
background: rgba(0, 0, 0, .30);
|
40
|
+
z-index: 999;
|
41
|
+
padding: 30px 0;
|
42
|
+
position: fixed;
|
43
|
+
top: 0;
|
44
|
+
left: 0;
|
45
|
+
right: 0;
|
46
|
+
bottom: 0;
|
47
|
+
overflow-x: hidden;
|
48
|
+
overflow-y: auto;
|
49
|
+
}
|
50
|
+
#ra-le-modal > .modal-dialog {
|
51
|
+
position: relative;
|
52
|
+
margin: 30px auto;
|
53
|
+
width: 940px;
|
54
|
+
-webkit-box-shadow: 0 3px 9px rgba(0, 0, 0, .5);
|
55
|
+
box-shadow: 0 3px 9px rgba(0, 0, 0, .5);
|
56
|
+
background: #fff;
|
57
|
+
margin: 0 auto;
|
58
|
+
}
|
59
|
+
#ra-le-modal .dlg-buttons {
|
60
|
+
background: #ccc;
|
61
|
+
text-align: right;
|
62
|
+
padding: 0 4px;
|
63
|
+
}
|
64
|
+
#ra-le-modal .dlg-buttons > a {
|
65
|
+
border: 1px solid #888;
|
66
|
+
color: #888;
|
67
|
+
text-decoration: none;
|
68
|
+
}
|
69
|
+
#ra-le-modal .dlg-buttons > a:hover {
|
70
|
+
background: #eee;
|
71
|
+
color: #004;
|
72
|
+
}
|
73
|
+
#ra-le-modal .modal-footer > .dlg-buttons {
|
74
|
+
text-align: center;
|
75
|
+
}
|
76
|
+
#ra-le-content {
|
77
|
+
background: #ccc;
|
78
|
+
color: #222;
|
79
|
+
font-style: italic;
|
80
|
+
padding-top: 4px;
|
81
|
+
text-align: center;
|
82
|
+
}
|
83
|
+
#ra-le-content > iframe {
|
84
|
+
border: 1px solid #888;
|
85
|
+
}
|
86
|
+
|
87
|
+
#ra-le-modal
|
88
|
+
.modal-dialog
|
89
|
+
.dlg-buttons
|
90
|
+
%a.btn-close.ra-le-button{ href: '#', onclick: 'event.preventDefault();modal.close();' }== ×
|
91
|
+
#ra-le-content = t 'live_edit.loading'
|
92
|
+
.modal-footer
|
93
|
+
.dlg-buttons
|
94
|
+
%a.btn-close.ra-le-button{ href: '#', onclick: 'event.preventDefault();modal.close();' }= t 'live_edit.button.close'
|
95
|
+
.ra-le-controls
|
96
|
+
%a.btn1.ra-le-button#ra-le-open-modal{ href: '#' }>= t 'live_edit.button.edit_page'
|
97
|
+
= link_to t('live_edit.button.admin'), rails_admin_path, class: 'btn2 ra-le-button'
|
98
|
+
|
99
|
+
:javascript
|
100
|
+
window.onload = function() {
|
101
|
+
var modal = new RModal(document.getElementById('ra-le-modal'), {
|
102
|
+
beforeOpen: function(next) {
|
103
|
+
console.log('beforeOpen');
|
104
|
+
document.getElementById('ra-le-content').innerHTML = '<iframe src="#{rails_admin.edit_path( ra_le_model, ra_le_id )}" width="930px" height="470px"></iframe>';
|
105
|
+
next();
|
106
|
+
},
|
107
|
+
afterOpen: function() {
|
108
|
+
console.log('opened');
|
109
|
+
},
|
110
|
+
beforeClose: function(next) {
|
111
|
+
console.log('beforeClose');
|
112
|
+
next();
|
113
|
+
},
|
114
|
+
afterClose: function() {
|
115
|
+
console.log('closed');
|
116
|
+
window.location.reload( true );
|
117
|
+
}
|
118
|
+
// , bodyClass: 'modal-open'
|
119
|
+
// , dialogClass: 'modal-dialog modal-dialog-lg'
|
120
|
+
// , dialogOpenClass: 'animated fadeIn'
|
121
|
+
// , dialogCloseClass: 'animated fadeOut'
|
122
|
+
|
123
|
+
// , focus: true
|
124
|
+
// , focusElements: ['input.form-control', 'textarea', 'button.btn-primary']
|
125
|
+
|
126
|
+
// , escapeClose: true
|
127
|
+
});
|
128
|
+
document.addEventListener('keydown', function(ev) {
|
129
|
+
modal.keydown(ev);
|
130
|
+
}, false);
|
131
|
+
document.getElementById('ra-le-open-modal').addEventListener("click", function(ev) {
|
132
|
+
ev.preventDefault();
|
133
|
+
modal.open();
|
134
|
+
}, false);
|
135
|
+
window.modal = modal;
|
136
|
+
}
|
@@ -0,0 +1 @@
|
|
1
|
+
require "rails_admin_live_edit/engine"
|
@@ -0,0 +1,23 @@
|
|
1
|
+
function inIframe() {
|
2
|
+
try {
|
3
|
+
return window.self !== window.top;
|
4
|
+
} catch (e) {
|
5
|
+
return true;
|
6
|
+
}
|
7
|
+
}
|
8
|
+
|
9
|
+
if( inIframe() ) {
|
10
|
+
$(document).ready( function() {
|
11
|
+
$('body').css('padding-top', '0');
|
12
|
+
$('nav.navbar').hide();
|
13
|
+
$('.breadcrumb').hide();
|
14
|
+
$('.content > .nav.nav-tabs').hide();
|
15
|
+
$('.sidebar-nav').hide();
|
16
|
+
$('.sidebar-nav ~ div').attr( 'class', 'col-md-12' );
|
17
|
+
$('button[name="_save"]').hide();
|
18
|
+
$('button[name="_add_another"]').hide();
|
19
|
+
$('button[name="_continue"]').hide();
|
20
|
+
$('.content > .page-header > h1').css( 'text-align', 'center' );
|
21
|
+
$('.content > .page-header > h1').css( 'font-size', '125%' );
|
22
|
+
});
|
23
|
+
}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Iskren Slavov
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
@@ -0,0 +1,57 @@
|
|
1
|
+
[![NPM version](https://img.shields.io/npm/v/rmodal.svg?style=flat-square)](https://www.npmjs.com/package/rmodal)
|
2
|
+
[![Build Status](https://travis-ci.org/zewish/rmodal.js.svg?branch=master)](https://travis-ci.org/zewish/rmodal.js)
|
3
|
+
[![Coverage Status](https://coveralls.io/repos/github/zewish/rmodal.js/badge.svg?branch=master)](https://coveralls.io/github/zewish/rmodal.js?branch=master)
|
4
|
+
[![Dependencies](https://david-dm.org/zewish/rmodal.js.svg)](https://david-dm.org/zewish/rmodal.js)
|
5
|
+
[![Downloads](https://img.shields.io/npm/dm/rmodal.svg?style=flat-square)](https://www.npmjs.com/package/rmodal)
|
6
|
+
|
7
|
+
1.2 KB modal dialog box, with no dependencies
|
8
|
+
|
9
|
+
<br />
|
10
|
+
[![logo](https://raw.githubusercontent.com/zewish/rmodal.js/master/logo.png)](https://github.com/zewish/rmodal.js)
|
11
|
+
|
12
|
+
- A simple and fast modal dialog
|
13
|
+
- Plain JavaScript only - no dependencies
|
14
|
+
- All browsers supported (IE9+)
|
15
|
+
- Less than 1.2 KB when gzipped and minified
|
16
|
+
- Bootstrap and Animate.css friendly
|
17
|
+
- Supports CommonJS, AMD or globals
|
18
|
+
|
19
|
+
|
20
|
+
Demo
|
21
|
+
----
|
22
|
+
http://plnkr.co/edit/XXFKwHHcZD4Ecjh8twaW?p=preview
|
23
|
+
|
24
|
+
|
25
|
+
Documentation
|
26
|
+
-------------
|
27
|
+
http://rmodal.js.org/
|
28
|
+
|
29
|
+
|
30
|
+
Installation
|
31
|
+
------------
|
32
|
+
```
|
33
|
+
$ npm install rmodal --save
|
34
|
+
# or
|
35
|
+
$ bower install rmodal --save
|
36
|
+
```
|
37
|
+
|
38
|
+
|
39
|
+
Development
|
40
|
+
-----------
|
41
|
+
```
|
42
|
+
$ npm install
|
43
|
+
$ npm install -g gulp
|
44
|
+
```
|
45
|
+
|
46
|
+
Development: build
|
47
|
+
------------------
|
48
|
+
```
|
49
|
+
$ gulp build
|
50
|
+
```
|
51
|
+
|
52
|
+
|
53
|
+
Development: test
|
54
|
+
-----------------
|
55
|
+
```
|
56
|
+
$ gulp lint test
|
57
|
+
```
|
@@ -0,0 +1,28 @@
|
|
1
|
+
{
|
2
|
+
"name": "rmodal",
|
3
|
+
"main": "rmodal.js",
|
4
|
+
"version": "1.0.24",
|
5
|
+
"authors": [
|
6
|
+
"Iskren Slavov <iskren.s@gmail.com>"
|
7
|
+
],
|
8
|
+
"description": "A simple modal dialog with no external dependencies. IE9+ supported.",
|
9
|
+
"keywords": [
|
10
|
+
"modal",
|
11
|
+
"dialog",
|
12
|
+
"javascript",
|
13
|
+
"simple",
|
14
|
+
"plain",
|
15
|
+
"browser",
|
16
|
+
"browserify"
|
17
|
+
],
|
18
|
+
"dependencies": {},
|
19
|
+
"license": "MIT",
|
20
|
+
"homepage": "http://rmodal.js.org/",
|
21
|
+
"ignore": [
|
22
|
+
"**/.*",
|
23
|
+
"node_modules",
|
24
|
+
"bower_components",
|
25
|
+
"test",
|
26
|
+
"tests"
|
27
|
+
]
|
28
|
+
}
|
@@ -0,0 +1,37 @@
|
|
1
|
+
body {
|
2
|
+
padding: 0;
|
3
|
+
margin: 0;
|
4
|
+
}
|
5
|
+
|
6
|
+
body.modal-open {
|
7
|
+
overflow-x: hidden;
|
8
|
+
overflow-y: auto;
|
9
|
+
}
|
10
|
+
|
11
|
+
.modal {
|
12
|
+
display: none;
|
13
|
+
background: rgba(0, 0, 0, .30);
|
14
|
+
z-index: 999;
|
15
|
+
padding: 30px 0;
|
16
|
+
|
17
|
+
position: fixed;
|
18
|
+
top: 0;
|
19
|
+
left: 0;
|
20
|
+
right: 0;
|
21
|
+
bottom: 0;
|
22
|
+
|
23
|
+
overflow-x: hidden;
|
24
|
+
overflow-y: auto;
|
25
|
+
}
|
26
|
+
|
27
|
+
.modal .modal-dialog {
|
28
|
+
position: relative;
|
29
|
+
margin: 30px auto;
|
30
|
+
width: 1100px;
|
31
|
+
border-radius: 6px;
|
32
|
+
-webkit-box-shadow: 0 3px 9px rgba(0, 0, 0, .5);
|
33
|
+
box-shadow: 0 3px 9px rgba(0, 0, 0, .5);
|
34
|
+
|
35
|
+
background: #fff;
|
36
|
+
margin: 0 auto;
|
37
|
+
}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
.modal {
|
2
|
+
display: none;
|
3
|
+
background: rgba(0, 0, 0, .30);
|
4
|
+
z-index: 999;
|
5
|
+
}
|
6
|
+
|
7
|
+
.modal .modal-dialog {
|
8
|
+
position: relative;
|
9
|
+
margin: 30px auto;
|
10
|
+
width: 1100px;
|
11
|
+
border-radius: 6px;
|
12
|
+
-webkit-box-shadow: 0 3px 9px rgba(0, 0, 0, .5);
|
13
|
+
box-shadow: 0 3px 9px rgba(0, 0, 0, .5);
|
14
|
+
}
|
@@ -0,0 +1,201 @@
|
|
1
|
+
(function (global, factory) {
|
2
|
+
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() :
|
3
|
+
typeof define === 'function' && define.amd ? define(factory) :
|
4
|
+
(global.RModal = factory());
|
5
|
+
}(this, (function () {
|
6
|
+
|
7
|
+
var is = function (obj, type) { return Object.prototype.toString.call(obj).toLowerCase() === ("[object " + type + "]"); };
|
8
|
+
|
9
|
+
var addClass = function (el, cls) {
|
10
|
+
var arr = el.className
|
11
|
+
.split(/\s+/)
|
12
|
+
.filter(function (c) { return !!c && c == cls; });
|
13
|
+
|
14
|
+
if (!arr.length) {
|
15
|
+
el.className += " " + cls;
|
16
|
+
}
|
17
|
+
};
|
18
|
+
|
19
|
+
var removeClass = function (el, cls) {
|
20
|
+
el.className = el.className
|
21
|
+
.split(/\s+/)
|
22
|
+
.filter(function (c) { return !!c && c != cls; })
|
23
|
+
.join(' ');
|
24
|
+
};
|
25
|
+
|
26
|
+
var RModal = function RModal(el, opts) {
|
27
|
+
var this$1 = this;
|
28
|
+
|
29
|
+
this.opened = false;
|
30
|
+
|
31
|
+
this.opts = {
|
32
|
+
bodyClass: 'modal-open'
|
33
|
+
, dialogClass: 'modal-dialog'
|
34
|
+
, dialogOpenClass: 'bounceInDown'
|
35
|
+
, dialogCloseClass: 'bounceOutUp'
|
36
|
+
|
37
|
+
, focus: true
|
38
|
+
, focusElements: [
|
39
|
+
'a[href]', 'area[href]', 'input:not([disabled]):not([type=hidden])'
|
40
|
+
, 'button:not([disabled])', 'select:not([disabled])'
|
41
|
+
, 'textarea:not([disabled])', 'iframe', 'object', 'embed'
|
42
|
+
, '*[tabindex]', '*[contenteditable]'
|
43
|
+
]
|
44
|
+
|
45
|
+
, escapeClose: true
|
46
|
+
, content: null
|
47
|
+
, closeTimeout: 500
|
48
|
+
};
|
49
|
+
|
50
|
+
Object.keys(opts || {})
|
51
|
+
.forEach(function (key) {
|
52
|
+
/* istanbul ignore else */
|
53
|
+
if (opts[key] !== undefined) {
|
54
|
+
this$1.opts[key] = opts[key];
|
55
|
+
}
|
56
|
+
});
|
57
|
+
|
58
|
+
this.overlay = el;
|
59
|
+
this.dialog = el.querySelector(("." + (this.opts.dialogClass)));
|
60
|
+
|
61
|
+
if (this.opts.content) {
|
62
|
+
this.content(this.opts.content);
|
63
|
+
}
|
64
|
+
};
|
65
|
+
|
66
|
+
RModal.prototype.open = function open (content) {
|
67
|
+
var this$1 = this;
|
68
|
+
|
69
|
+
this.content(content);
|
70
|
+
|
71
|
+
if (!is(this.opts.beforeOpen, 'function')) {
|
72
|
+
return this._doOpen();
|
73
|
+
}
|
74
|
+
|
75
|
+
this.opts.beforeOpen(function () {
|
76
|
+
this$1._doOpen();
|
77
|
+
});
|
78
|
+
};
|
79
|
+
|
80
|
+
RModal.prototype._doOpen = function _doOpen () {
|
81
|
+
addClass(document.body, this.opts.bodyClass);
|
82
|
+
|
83
|
+
removeClass(this.dialog, this.opts.dialogCloseClass);
|
84
|
+
addClass(this.dialog, this.opts.dialogOpenClass);
|
85
|
+
|
86
|
+
this.overlay.style.display = 'block';
|
87
|
+
|
88
|
+
if (this.opts.focus) {
|
89
|
+
this.focusOutElement = document.activeElement;
|
90
|
+
this.focus();
|
91
|
+
}
|
92
|
+
|
93
|
+
if (is(this.opts.afterOpen, 'function')) {
|
94
|
+
this.opts.afterOpen();
|
95
|
+
}
|
96
|
+
this.opened = true;
|
97
|
+
};
|
98
|
+
|
99
|
+
RModal.prototype.close = function close () {
|
100
|
+
var this$1 = this;
|
101
|
+
|
102
|
+
if (!is(this.opts.beforeClose, 'function')) {
|
103
|
+
return this._doClose();
|
104
|
+
}
|
105
|
+
|
106
|
+
this.opts.beforeClose(function () {
|
107
|
+
this$1._doClose();
|
108
|
+
});
|
109
|
+
};
|
110
|
+
|
111
|
+
RModal.prototype._doClose = function _doClose () {
|
112
|
+
var this$1 = this;
|
113
|
+
|
114
|
+
removeClass(this.dialog, this.opts.dialogOpenClass);
|
115
|
+
addClass(this.dialog, this.opts.dialogCloseClass);
|
116
|
+
|
117
|
+
removeClass(document.body, this.opts.bodyClass);
|
118
|
+
|
119
|
+
if (this.opts.focus) {
|
120
|
+
this.focus(this.focusOutElement);
|
121
|
+
}
|
122
|
+
|
123
|
+
if (is(this.opts.afterClose, 'function')) {
|
124
|
+
this.opts.afterClose();
|
125
|
+
}
|
126
|
+
|
127
|
+
this.opened = false;
|
128
|
+
setTimeout(function () {
|
129
|
+
this$1.overlay.style.display = 'none';
|
130
|
+
}, this.opts.closeTimeout);
|
131
|
+
};
|
132
|
+
|
133
|
+
RModal.prototype.content = function content (html) {
|
134
|
+
if (html === undefined) {
|
135
|
+
return this.dialog.innerHTML;
|
136
|
+
}
|
137
|
+
|
138
|
+
this.dialog.innerHTML = html;
|
139
|
+
};
|
140
|
+
|
141
|
+
RModal.prototype.elements = function elements (selector, fallback) {
|
142
|
+
fallback = fallback || window.navigator.appVersion.indexOf('MSIE 9.0') > -1;
|
143
|
+
selector = is(selector, 'array') ? selector.join(',') : selector;
|
144
|
+
|
145
|
+
return [].filter.call(
|
146
|
+
this.dialog.querySelectorAll(selector)
|
147
|
+
, function (element) {
|
148
|
+
if (fallback) {
|
149
|
+
var style = window.getComputedStyle(element);
|
150
|
+
return style.display !== 'none' && style.visibility !== 'hidden';
|
151
|
+
}
|
152
|
+
|
153
|
+
return element.offsetParent !== null;
|
154
|
+
}
|
155
|
+
);
|
156
|
+
};
|
157
|
+
|
158
|
+
RModal.prototype.focus = function focus (el) {
|
159
|
+
el = el || this.elements(this.opts.focusElements)[0] || this.dialog.firstChild;
|
160
|
+
|
161
|
+
if (el && is(el.focus, 'function')) {
|
162
|
+
el.focus();
|
163
|
+
}
|
164
|
+
};
|
165
|
+
|
166
|
+
RModal.prototype.keydown = function keydown (ev) {
|
167
|
+
if (this.opts.escapeClose && ev.which == 27) {
|
168
|
+
this.close();
|
169
|
+
}
|
170
|
+
|
171
|
+
function stopEvent() {
|
172
|
+
ev.preventDefault();
|
173
|
+
ev.stopPropagation();
|
174
|
+
}
|
175
|
+
|
176
|
+
if (this.opened && ev.which == 9 && this.dialog.contains(ev.target)) {
|
177
|
+
var elements = this.elements(this.opts.focusElements)
|
178
|
+
, first = elements[0]
|
179
|
+
, last = elements[elements.length - 1];
|
180
|
+
|
181
|
+
if (first == last) {
|
182
|
+
stopEvent();
|
183
|
+
}
|
184
|
+
else if (ev.target == first && ev.shiftKey) {
|
185
|
+
stopEvent();
|
186
|
+
last.focus();
|
187
|
+
}
|
188
|
+
else if (ev.target == last && !ev.shiftKey) {
|
189
|
+
stopEvent();
|
190
|
+
first.focus();
|
191
|
+
}
|
192
|
+
}
|
193
|
+
};
|
194
|
+
|
195
|
+
RModal.prototype.version = '1.0.24';
|
196
|
+
RModal.version = '1.0.24';
|
197
|
+
|
198
|
+
return RModal;
|
199
|
+
|
200
|
+
})));
|
201
|
+
//# sourceMappingURL=rmodal.js.map
|