inplace_editing 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/app/views/inplace_editing/edit/_element.html.slim +1 -1
- data/app/views/inplace_editing/edit/_image.html.slim +2 -32
- data/app/views/inplace_editing/edit/_string.html.slim +1 -1
- data/app/views/inplace_editing/edit/_text.html.slim +1 -1
- data/lib/assets/javascripts/inplace_editing.js +71 -6
- data/lib/inplace_editing/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f84872e5235d8573b8d8e14ad609a734f19c136
|
4
|
+
data.tar.gz: 0a8bbb3f59c143ec2fa8b814a41c9d5e01180225
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 478a8c79dae580791237d0660b4d54a4b746894d7c7d2edd8d78ff1604b29dd9f318165d79332ab3552dd33fb7b7afed92e8c39711e7f183d105f1ca0f42e1ba
|
7
|
+
data.tar.gz: 9da3ba4f6843bea3ddb477583956206c110f1030fd9d359d06b967092e531f8e0030ab2c11b9e6eb24d25362e86fc8eb91970a620f2995abfef35d2eb0661063
|
data/README.md
CHANGED
@@ -36,8 +36,8 @@ Don't forget to add scripts
|
|
36
36
|
//= require inplace_editing
|
37
37
|
|
38
38
|
$(document).ready(function() {
|
39
|
-
/* Activating
|
40
|
-
|
39
|
+
/* Activating Inplace Editor */
|
40
|
+
InplaceEditingManager.bindAll();
|
41
41
|
});
|
42
42
|
|
43
43
|
## Usage
|
@@ -2,5 +2,5 @@
|
|
2
2
|
.best_before
|
3
3
|
- if local_assigns[:label]
|
4
4
|
label = local_assigns[:label] + ' '
|
5
|
-
= best_in_place localized_object, property, as: :input, :ok_button => 'Salvar', :cancel_button => 'Cancelar', :place_holder => (local_assigns[:place_holder] ? local_assigns[:place_holder] : "[texto aqui]")
|
5
|
+
= best_in_place localized_object, property, as: :input, class: 'inplace_editor inplace_editor_element', :ok_button => 'Salvar', :cancel_button => 'Cancelar', :place_holder => (local_assigns[:place_holder] ? local_assigns[:place_holder] : "[texto aqui]")
|
6
6
|
= yield(local_assigns)
|
@@ -1,6 +1,5 @@
|
|
1
|
-
- form_id = 'image_editor_' + localized_object.class.name + '' + localized_object.id.to_s + '_' + property.to_s
|
2
1
|
- image_src = localized_object[property] ? localized_object.send(property.to_s + '_url') : local_assigns[:default_value]
|
3
|
-
= simple_form_for(localized_object, html: {
|
2
|
+
= simple_form_for(localized_object, html: { class: 'inplace_editor inplace_editor_image' :multipart => true, novalidate: true }, :format => :json, :remote => true, authenticity_token: true) do |f|
|
4
3
|
= f.input_field property, as: :file, label: "Trocar Imagem", style: 'display:none'
|
5
4
|
= f.input property.to_s + "_cache", as: :hidden
|
6
5
|
.image-container
|
@@ -9,33 +8,4 @@
|
|
9
8
|
a.insert-image href="" Clique para inserir imagem
|
10
9
|
.actions-container style="display:none;"
|
11
10
|
input.saveButton type="submit" value="Salvar"
|
12
|
-
input.cancelButton type="button" value="Cancelar"
|
13
|
-
javascript:
|
14
|
-
$(document).ready(function() {
|
15
|
-
var form_id = "#{form_id}";
|
16
|
-
var imageEditor = asyncImageForm({
|
17
|
-
formSelector: 'form#' + form_id,
|
18
|
-
inputFileSelector: 'form#' + form_id + ' input[type=file]',
|
19
|
-
inputSubmitSelector: 'form#' + form_id + ' input[type=submit].saveButton',
|
20
|
-
imagePreviewSelector: 'form#' + form_id + ' img.editable-preview',
|
21
|
-
imageChangerSelector: 'form#' + form_id + ' img.preview, form#' + form_id + ' a.insert-image',
|
22
|
-
errorsGroup: '#{localized_object.class.name.downcase}',
|
23
|
-
events: {
|
24
|
-
imageChanged: function() {
|
25
|
-
$('form#' + form_id + ' a.insert-image').hide();
|
26
|
-
$('form#' + form_id + ' .actions-container').show();
|
27
|
-
$('form#' + form_id + ' .actions-container input').prop('disabled', false);
|
28
|
-
},
|
29
|
-
imageUploading: function() {
|
30
|
-
$('form#' + form_id + ' .actions-container input').prop('disabled', true)
|
31
|
-
},
|
32
|
-
imageUploadSuccess: function() {
|
33
|
-
$('form#' + form_id + ' .actions-container').hide();
|
34
|
-
},
|
35
|
-
imageUploadFail: function() {
|
36
|
-
$('form#' + form_id + ' .actions-container').show();
|
37
|
-
$('form#' + form_id + ' .actions-container input').prop('disabled', false)
|
38
|
-
}
|
39
|
-
}
|
40
|
-
});
|
41
|
-
});
|
11
|
+
input.cancelButton type="button" value="Cancelar"
|
@@ -1 +1 @@
|
|
1
|
-
= best_in_place localized_object, property, as: :input, :ok_button => 'Salvar', :cancel_button => 'Cancelar', :place_holder => local_assigns[:place_holder] ? local_assigns[:place_holder] : "[troque o texto aqui]"
|
1
|
+
= best_in_place localized_object, property, as: :input, class: 'inplace_editor inplace_editor_string', :ok_button => 'Salvar', :cancel_button => 'Cancelar', :place_holder => local_assigns[:place_holder] ? local_assigns[:place_holder] : "[troque o texto aqui]"
|
@@ -1 +1 @@
|
|
1
|
-
= best_in_place localized_object, property, as: :textarea, class:'best_in_place_textarea', :place_holder => local_assigns[:place_holder] ? local_assigns[:place_holder] : "[texto aqui]", sanitize: false, :ok_button => 'Salvar', :cancel_button => 'Cancelar', :display_with => lambda { |v| markdown(v, '[texto aqui]') }
|
1
|
+
= best_in_place localized_object, property, as: :textarea, class: 'best_in_place_textarea inplace_editor inplace_editor_text', :place_holder => local_assigns[:place_holder] ? local_assigns[:place_holder] : "[texto aqui]", sanitize: false, :ok_button => 'Salvar', :cancel_button => 'Cancelar', :display_with => lambda { |v| markdown(v, '[texto aqui]') }
|
@@ -1,11 +1,71 @@
|
|
1
|
+
var InplaceEditingManager = {
|
2
|
+
bindText: function(element) {
|
3
|
+
$(element).best_in_place();
|
4
|
+
},
|
5
|
+
tryBindText: function(parentElementOrSelector) {
|
6
|
+
var self = this;
|
7
|
+
$.each($(parentElementOrSelector).find('.best_in_place.inplace_editor'), function(index, element) {
|
8
|
+
self.bindText(element);
|
9
|
+
});
|
10
|
+
}
|
11
|
+
bindImage: function(imageForm) {
|
12
|
+
return asyncImageForm({
|
13
|
+
formElement: $(imageForm),
|
14
|
+
inputFileElement: $(imageForm).find('input[type=file]'),
|
15
|
+
imagePreviewElement: $(imageForm).find('img.editable-preview'),
|
16
|
+
imageChangerElement: $(imageForm).find('img.preview, a.insert-image'),
|
17
|
+
errorsGroup: '#{localized_object.class.name.downcase}',
|
18
|
+
events: {
|
19
|
+
imageChanged: function() {
|
20
|
+
$(imageForm).find('a.insert-image').hide();
|
21
|
+
$(imageForm).find('.actions-container').show();
|
22
|
+
$(imageForm).find('.actions-container input').prop('disabled', false);
|
23
|
+
},
|
24
|
+
imageUploading: function() {
|
25
|
+
$(imageForm).find('.actions-container input').prop('disabled', true)
|
26
|
+
},
|
27
|
+
imageUploadSuccess: function() {
|
28
|
+
$(imageForm).find('.actions-container').hide();
|
29
|
+
},
|
30
|
+
imageUploadFail: function() {
|
31
|
+
$(imageForm).find('.actions-container').show();
|
32
|
+
$(imageForm).find('.actions-container input').prop('disabled', false)
|
33
|
+
}
|
34
|
+
}
|
35
|
+
});
|
36
|
+
}
|
37
|
+
tryBindImage: function(parentElement) {
|
38
|
+
var self = this;
|
39
|
+
$.each($(parentElementOrSelector).find('.inplace_editor_image'), function(index, element) {
|
40
|
+
self.bindImage(element);
|
41
|
+
});
|
42
|
+
},
|
43
|
+
bindAll: function(parentElement) {
|
44
|
+
if (!parentElement)
|
45
|
+
parentElement = 'body';
|
46
|
+
tryBindText(parentElement);
|
47
|
+
tryBindImage(parentElement);
|
48
|
+
}
|
49
|
+
}
|
50
|
+
|
1
51
|
function asyncImageForm(config) {
|
2
52
|
this.config = config;
|
53
|
+
this.config.setConfigOrSelector = function(prefix) {
|
54
|
+
var self = this;
|
55
|
+
var key = prefix + 'Element';
|
56
|
+
if (!self.hasOwnProperty(key) || !self[key]) {
|
57
|
+
self[key] = $(self[prefix + 'Selector']);
|
58
|
+
}
|
59
|
+
};
|
3
60
|
// var config = {
|
4
61
|
// formSelector: 'form.async-republic-image',
|
62
|
+
// formElement: null,
|
5
63
|
// inputFileSelector: 'form.async-republic-image .input_addPictureButton',
|
6
|
-
//
|
64
|
+
// inputFileElement: null,
|
7
65
|
// imagePreviewSelector: 'form.async-republic-image img.preview',
|
66
|
+
// imagePreviewElement: null,
|
8
67
|
// imageChangerSelector: 'form.async-republic-image img.preview',
|
68
|
+
// imageChangerElement: null,
|
9
69
|
// errorsGroup: 'republic_image',
|
10
70
|
// events: {
|
11
71
|
// imageChanged: function() {},
|
@@ -15,25 +75,30 @@ function asyncImageForm(config) {
|
|
15
75
|
// }
|
16
76
|
// }
|
17
77
|
|
78
|
+
var elementProperties = ['form', 'inputFile', 'imagePreview', 'imageChanger'];
|
79
|
+
for (var i = 0; i < elementProperties.length; i++) {
|
80
|
+
this.config.setConfigOrSelector(elementProperties[i]);
|
81
|
+
}
|
82
|
+
|
18
83
|
function defaultPostImageSuccess() {
|
19
84
|
window.location.reload();
|
20
85
|
return false;
|
21
86
|
};
|
22
87
|
|
23
|
-
|
24
|
-
setImagePreview(this,
|
88
|
+
config.inputFileElement.change(function(){
|
89
|
+
setImagePreview(this, config.imagePreviewElement);
|
25
90
|
config.events.imageChanged(this);
|
26
91
|
});
|
27
92
|
|
28
|
-
|
93
|
+
config.imageChangerElement.click(function(e){
|
29
94
|
if(typeof e.preventDefault === 'function')
|
30
95
|
e.preventDefault();
|
31
96
|
|
32
|
-
|
97
|
+
config.inputFileElement.click();
|
33
98
|
return false;
|
34
99
|
});
|
35
100
|
|
36
|
-
|
101
|
+
config.formElement.submit(function (event) {
|
37
102
|
event.preventDefault();
|
38
103
|
|
39
104
|
//grab all form data
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inplace_editing
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Henrique Rangel
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|