on_the_spot 1.1.3 → 1.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +2 -1
- data/README.markdown +32 -1
- data/Rakefile +47 -0
- data/VERSION +1 -1
- data/app/assets/javascripts/jquery.jeditable.checkbox.js +51 -23
- data/app/assets/javascripts/jquery.jeditable.js +76 -52
- data/app/assets/javascripts/on_the_spot_code.js +4 -0
- data/app/assets/{css → stylesheets}/on_the_spot.css +0 -0
- data/lib/generators/on_the_spot/install/install_generator.rb +4 -4
- data/lib/on_the_spot/on_the_spot_helpers.rb +4 -0
- data/npm/README.md +6 -0
- data/npm/package.json.erb +22 -0
- data/on_the_spot.gemspec +7 -6
- data/spec/generators/install_generator_spec.rb +3 -3
- data/spec/on_the_spot_spec.rb +3 -0
- metadata +6 -6
- data/app/assets/javascripts/jquery.jeditable.mini.js +0 -38
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 90cbf6521a31499df8dd05c1afa968a5032b33a6f87501d357ee235c058efc51
|
4
|
+
data.tar.gz: 1a39af6e2f4a77851649fb7ee2a38ca8969b1eb3245544bbbd1f104ae5aaea65
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 41e9055ca232c6d9e7a97d5c3bf0f129af1c6f6b359560900cfd87ddaa9c11c6934995dfc1fc9310dc94195aac61695e07273e51339ab7954b23bf44665a9186
|
7
|
+
data.tar.gz: 379a3bb4cf943e9bedcc366364d2b749161e5349286d5b3910380c953f3db69dcb3d5b7416599101c2a661c04ff65a1ec8eec9a64950dbf803137071edf24a25
|
data/Gemfile
CHANGED
data/README.markdown
CHANGED
@@ -27,6 +27,21 @@ Run the installation task:
|
|
27
27
|
|
28
28
|
This will copy the default translation files, and for rails 3.0 it will also copy the needed assets (javascript files).
|
29
29
|
|
30
|
+
### Rails 6
|
31
|
+
|
32
|
+
Add the componanion package
|
33
|
+
|
34
|
+
yarn add @nathanvda/on_the_spot
|
35
|
+
|
36
|
+
and then in your `app/javascripts/packs/application.js` you should add
|
37
|
+
|
38
|
+
require("jquery")
|
39
|
+
require("jquery-jeditable")
|
40
|
+
require("@nathanvda/on_the_spot")
|
41
|
+
|
42
|
+
|
43
|
+
|
44
|
+
|
30
45
|
### Rails 3.1+/4/5
|
31
46
|
|
32
47
|
Add the following to application.js so it compiles to the asset_pipeline
|
@@ -128,6 +143,8 @@ The `on_the_spot_edit` also accepts options:
|
|
128
143
|
* `:cancel_text` : the text for the cancel-button
|
129
144
|
* `:display_text`: if you want to overrule the displayed text, especially useful when using your own `:url` or `:loadurl`
|
130
145
|
* `:tooltip` : the tooltip-text
|
146
|
+
* `:form_css`: the css class for the form
|
147
|
+
* `:input_css`: the css class for the input itself
|
131
148
|
* `:rows`: for textarea, the number of rows, defaults to 5
|
132
149
|
* `:columns`: for textarea, the number of columns, defaults to 40
|
133
150
|
* `:data`: for select, the lookup-data, should be in an array of id-value pairs. E.g. `[[1, 'ok'], [2, 'not ok'], [3, 'not decided']]`.
|
@@ -142,7 +159,21 @@ The `on_the_spot_edit` also accepts options:
|
|
142
159
|
* `:onblur`: accepts `cancel`, `submit` or `ignore` changes the behavior of the onblur handler accordingly
|
143
160
|
|
144
161
|
|
145
|
-
For the texts: if a text is not specified, the default is taken from the `on_the_spot.en.yml` (or your current language).
|
162
|
+
For the texts and css classes: if a text is not specified, the default is taken from the `on_the_spot.en.yml` (or your current language).
|
163
|
+
|
164
|
+
E.g. in the translations file `on_the_spot.en.yml` you could do the following to get the inline editor look good when using bootstrap:
|
165
|
+
|
166
|
+
```
|
167
|
+
en:
|
168
|
+
on_the_spot:
|
169
|
+
ok: <button class="btn btn-primary btn-sm">Ok</button>
|
170
|
+
cancel: <button class="btn btn-sm">Cancel</button>
|
171
|
+
tooltip: Click to edit ...
|
172
|
+
access_not_allowed: Access is not allowed
|
173
|
+
form_css: 'form form-inline'
|
174
|
+
input_css: 'form-control'
|
175
|
+
```
|
176
|
+
|
146
177
|
|
147
178
|
## Styling
|
148
179
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
3
|
require "rspec/core/rake_task"
|
4
|
+
require 'erb'
|
5
|
+
require 'JSON'
|
4
6
|
|
5
7
|
begin
|
6
8
|
require 'jeweler'
|
@@ -23,6 +25,51 @@ rescue LoadError
|
|
23
25
|
end
|
24
26
|
|
25
27
|
|
28
|
+
require 'bundler/gem_tasks'
|
29
|
+
|
30
|
+
spec = Bundler.load_gemspec('./on_the_spot.gemspec')
|
31
|
+
|
32
|
+
|
33
|
+
npm_src_dir = './npm'
|
34
|
+
npm_dest_dir = './dist'
|
35
|
+
CLOBBER.include 'dist'
|
36
|
+
|
37
|
+
assets_dir = './app/assets/'
|
38
|
+
|
39
|
+
npm_files = {
|
40
|
+
File.join(npm_dest_dir, 'on_the_spot_code.js') => File.join(assets_dir, 'javascripts', 'on_the_spot_code.js'),
|
41
|
+
File.join(npm_dest_dir, 'on_the_spot.css') => File.join(assets_dir, 'stylesheets', 'on_the_spot.css'),
|
42
|
+
File.join(npm_dest_dir, 'README.md') => File.join(npm_src_dir, 'README.md'),
|
43
|
+
File.join(npm_dest_dir, 'LICENSE') => './LICENSE'
|
44
|
+
}
|
45
|
+
|
46
|
+
namespace :npm do
|
47
|
+
npm_files.each do |dest, src|
|
48
|
+
file dest => src do
|
49
|
+
cp src, dest
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
task :'package-json' do
|
54
|
+
template = ERB.new(File.read(File.join(npm_src_dir, 'package.json.erb')))
|
55
|
+
content = template.result_with_hash(spec: spec)
|
56
|
+
File.write(File.join(npm_dest_dir, 'package.json'),
|
57
|
+
JSON.pretty_generate(JSON.parse(content)))
|
58
|
+
end
|
59
|
+
|
60
|
+
desc "Build nathanvda-on_the_spot-#{spec.version}.tgz into the pkg directory"
|
61
|
+
task build: (%i[package-json] + npm_files.keys) do
|
62
|
+
system("cd #{npm_dest_dir} && npm pack && mv ./nathanvda-on_the_spot-#{spec.version}.tgz ../pkg/")
|
63
|
+
end
|
64
|
+
|
65
|
+
desc "Build and push nathanvda-on_the_spot-#{spec.version}.tgz to https://npmjs.org"
|
66
|
+
task release: %i[build] do
|
67
|
+
system("npm publish ./pkg/nathanvda-on_the_spot-#{spec.version}.tgz --access public")
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
|
26
73
|
RSpec::Core::RakeTask.new(:spec)
|
27
74
|
|
28
75
|
task :default => :spec
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.4
|
@@ -1,26 +1,54 @@
|
|
1
|
-
|
2
|
-
*
|
3
|
-
*
|
4
|
-
*
|
5
|
-
|
1
|
+
/**
|
2
|
+
* @file checkbox plugin for jquery-jeditable
|
3
|
+
* @author Mika Tuupola, Nicolas CARPi
|
4
|
+
* @home https://github.com/NicolasCARPi/jquery_jeditable
|
5
|
+
* @licence MIT (see LICENCE file)
|
6
|
+
* @name PluginCheckbox
|
7
|
+
*/
|
8
|
+
'use strict';
|
9
|
+
(function ($) {
|
10
|
+
$.editable.addInputType('checkbox', {
|
11
|
+
element : function(settings, original) {
|
12
|
+
var input = $('<input type="checkbox">');
|
13
|
+
$(this).append(input);
|
6
14
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
$(input).bind('click', function() {
|
16
|
+
if ($(input).val() === 'on') {
|
17
|
+
$(input).val('off');
|
18
|
+
$(input).removeAttr('checked');
|
19
|
+
} else {
|
20
|
+
$(input).val('on');
|
21
|
+
$(input).attr('checked', 'checked');
|
22
|
+
}
|
23
|
+
});
|
12
24
|
|
13
|
-
|
14
|
-
|
25
|
+
return(input);
|
26
|
+
},
|
27
|
+
|
28
|
+
content : function(string, settings, original) {
|
29
|
+
|
30
|
+
var checked = (string === 'yes') ? 'on' : 'off';
|
31
|
+
var input = $(':input:first', this);
|
32
|
+
|
33
|
+
if (checked === 'on') {
|
34
|
+
$(input).attr('checked', checked);
|
35
|
+
} else {
|
36
|
+
$(input).removeAttr('checked');
|
37
|
+
}
|
38
|
+
|
39
|
+
var value = $(input).is(':checked') ? 'on' : 'off';
|
15
40
|
$(input).val(value);
|
16
|
-
}
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
41
|
+
},
|
42
|
+
|
43
|
+
submit: function (settings, original) {
|
44
|
+
var value;
|
45
|
+
var input = $(':input:first', this);
|
46
|
+
if (input.is(':checked')) {
|
47
|
+
value = '1';
|
48
|
+
} else {
|
49
|
+
value = '0';
|
50
|
+
}
|
51
|
+
$('input', this).val(value);
|
52
|
+
}
|
53
|
+
});
|
54
|
+
})(jQuery);
|
@@ -17,6 +17,7 @@
|
|
17
17
|
* @param {Number} [options.cols] - Number of columns if using textarea
|
18
18
|
* @param {String} [options.cssclass] - CSS class to apply to input form; use 'inherit' to copy from parent
|
19
19
|
* @param {String} [options.inputcssclass] - CSS class to apply to input. 'inherit' to copy from parent
|
20
|
+
* @param {Function} [options.intercept] - Intercept the returned data so you have a chance to process it before returning it in the page
|
20
21
|
* @param {String|Function} [options.data] - Content loaded in the form
|
21
22
|
* @param {String} [options.event='click'] - jQuery event such as 'click' of 'dblclick'. See https://api.jquery.com/category/events/
|
22
23
|
* @param {String} [options.formid] - Give an id to the form that is produced
|
@@ -46,6 +47,7 @@
|
|
46
47
|
* @param {Boolean} [options.select] - When true text is selected
|
47
48
|
* @param {Function} [options.showfn]- Function that can animate the element when switching to edit mode
|
48
49
|
* @param {String} [options.size] - The size of the text field
|
50
|
+
* @param {String} [options.sortselectoptions] - Sort the options of a select form
|
49
51
|
* @param {Number} [options.step] - Step size for number type
|
50
52
|
* @param {String} [options.style] - Style to apply to input form; 'inherit' to copy from parent
|
51
53
|
* @param {String} [options.submit] - submit button value, empty means no button
|
@@ -88,7 +90,7 @@
|
|
88
90
|
}
|
89
91
|
if ('destroy' === target) {
|
90
92
|
$(this)
|
91
|
-
.
|
93
|
+
.off($(this).data('event.editable'))
|
92
94
|
.removeData('disabled.editable')
|
93
95
|
.removeData('event.editable');
|
94
96
|
return;
|
@@ -135,7 +137,7 @@
|
|
135
137
|
}
|
136
138
|
|
137
139
|
// EVENT IS FIRED
|
138
|
-
$(this).
|
140
|
+
$(this).on(settings.event, function(e) {
|
139
141
|
|
140
142
|
/* Abort if element is disabled. */
|
141
143
|
if (true === $(this).data('disabled.editable')) {
|
@@ -143,7 +145,7 @@
|
|
143
145
|
}
|
144
146
|
|
145
147
|
// do nothing if user press Tab again, just go to next element, not into edit mode
|
146
|
-
if (e.
|
148
|
+
if (e.which === 9) {
|
147
149
|
return;
|
148
150
|
}
|
149
151
|
|
@@ -159,7 +161,7 @@
|
|
159
161
|
|
160
162
|
/* execute the before function if any was specified */
|
161
163
|
if (settings.before && jQuery.isFunction(settings.before)) {
|
162
|
-
settings.before();
|
164
|
+
settings.before(e);
|
163
165
|
} else if (settings.before && !jQuery.isFunction(settings.before)) {
|
164
166
|
throw "The 'before' option needs to be provided as a function!";
|
165
167
|
}
|
@@ -231,7 +233,7 @@
|
|
231
233
|
|
232
234
|
// timeout function
|
233
235
|
var t;
|
234
|
-
var
|
236
|
+
var isSubmitting = false;
|
235
237
|
|
236
238
|
if (settings.loadurl) {
|
237
239
|
t = self.setTimeout(function() {
|
@@ -298,7 +300,7 @@
|
|
298
300
|
plugin.apply(form, [settings, self]);
|
299
301
|
|
300
302
|
/* Focus to first visible form element. */
|
301
|
-
form.find(':input:visible:enabled:first').focus
|
303
|
+
form.find(':input:visible:enabled:first').trigger('focus');
|
302
304
|
|
303
305
|
/* Highlight input contents when requested. */
|
304
306
|
if (settings.select) {
|
@@ -306,30 +308,35 @@
|
|
306
308
|
}
|
307
309
|
|
308
310
|
/* discard changes if pressing esc */
|
309
|
-
|
310
|
-
if (e.
|
311
|
+
$(this).on('keydown', function(e) {
|
312
|
+
if (e.which === 27) {
|
311
313
|
e.preventDefault();
|
312
314
|
reset.apply(form, [settings, self]);
|
315
|
+
/* allow shift+enter to submit form (required for textarea) */
|
316
|
+
} else if (e.which == 13 && e.shiftKey){
|
317
|
+
e.preventDefault();
|
318
|
+
form.trigger('submit');
|
313
319
|
}
|
314
320
|
});
|
315
321
|
|
316
322
|
/* Discard, submit or nothing with changes when clicking outside. */
|
317
323
|
/* Do nothing is usable when navigating with tab. */
|
318
324
|
if ('cancel' === settings.onblur) {
|
319
|
-
input.blur
|
325
|
+
input.on('blur', function(e) {
|
320
326
|
/* Prevent canceling if submit was clicked. */
|
321
327
|
t = self.setTimeout(function() {
|
322
328
|
reset.apply(form, [settings, self]);
|
323
329
|
}, 500);
|
324
330
|
});
|
325
331
|
} else if ('submit' === settings.onblur) {
|
326
|
-
input.blur
|
332
|
+
input.on('blur', function(e) {
|
327
333
|
/* Prevent double submit if submit was clicked. */
|
328
|
-
|
329
|
-
|
334
|
+
t = self.setTimeout(function() {
|
335
|
+
form.trigger('submit');
|
336
|
+
}, 200);
|
330
337
|
});
|
331
338
|
} else if ($.isFunction(settings.onblur)) {
|
332
|
-
input.blur
|
339
|
+
input.on('blur', function(e) {
|
333
340
|
// reset the form if the onblur function returns false
|
334
341
|
if (false === settings.onblur.apply(self, [input.val(), settings, form])) {
|
335
342
|
reset.apply(form, [settings, self]);
|
@@ -337,18 +344,17 @@
|
|
337
344
|
});
|
338
345
|
}
|
339
346
|
|
340
|
-
form.submit
|
341
|
-
console.log("Form.submit");
|
347
|
+
form.on('submit', function(e) {
|
342
348
|
|
343
349
|
/* Do no submit. */
|
344
350
|
e.preventDefault();
|
345
351
|
e.stopPropagation();
|
346
352
|
|
347
|
-
if (
|
348
|
-
|
353
|
+
if (isSubmitting) {
|
354
|
+
// we are already submitting! Stop right here.
|
349
355
|
return false;
|
350
356
|
} else {
|
351
|
-
|
357
|
+
isSubmitting = true;
|
352
358
|
}
|
353
359
|
|
354
360
|
if (t) {
|
@@ -357,27 +363,32 @@
|
|
357
363
|
|
358
364
|
/* Call before submit hook. */
|
359
365
|
/* If it returns false abort submitting. */
|
360
|
-
|
366
|
+
isSubmitting = false !== onsubmit.apply(form, [settings, self]);
|
367
|
+
if (isSubmitting) {
|
361
368
|
/* Custom inputs call before submit hook. */
|
362
369
|
/* If it returns false abort submitting. */
|
363
|
-
|
370
|
+
isSubmitting = false !== submit.apply(form, [settings, self]);
|
371
|
+
if (isSubmitting) {
|
364
372
|
|
365
373
|
/* Check if given target is function */
|
366
374
|
if ($.isFunction(settings.target)) {
|
367
375
|
/* Callback function to handle the target reponse */
|
368
|
-
var responseHandler = function(value) {
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
376
|
+
var responseHandler = function(value, complete) {
|
377
|
+
isSubmitting = false;
|
378
|
+
if (false !== complete) {
|
379
|
+
$(self).html(value);
|
380
|
+
self.editing = false;
|
381
|
+
callback.apply(self, [self.innerText, settings]);
|
382
|
+
if (!$.trim($(self).html())) {
|
383
|
+
$(self).html(settings.placeholder);
|
384
|
+
}
|
374
385
|
}
|
375
386
|
};
|
376
387
|
/* Call the user target function */
|
377
388
|
var userTarget = settings.target.apply(self, [input.val(), settings, responseHandler]);
|
378
389
|
/* Handle the target function return for compatibility */
|
379
390
|
if (false !== userTarget && undefined !== userTarget) {
|
380
|
-
responseHandler(userTarget);
|
391
|
+
responseHandler(userTarget, userTarget);
|
381
392
|
}
|
382
393
|
|
383
394
|
} else {
|
@@ -403,6 +414,9 @@
|
|
403
414
|
/* Defaults for ajaxoptions. */
|
404
415
|
var ajaxoptions = {
|
405
416
|
type : 'POST',
|
417
|
+
complete: function (xhr, status) {
|
418
|
+
isSubmitting = false;
|
419
|
+
},
|
406
420
|
data : submitdata,
|
407
421
|
dataType: 'html',
|
408
422
|
url : settings.target,
|
@@ -446,7 +460,7 @@
|
|
446
460
|
if (self.editing) {
|
447
461
|
/* Before reset hook, if it returns false abort reseting. */
|
448
462
|
if (false !== onreset.apply(form, [settings, self])) {
|
449
|
-
$(self).
|
463
|
+
$(self).text(self.revert);
|
450
464
|
self.editing = false;
|
451
465
|
if (!$.trim($(self).html())) {
|
452
466
|
$(self).html(settings.placeholder);
|
@@ -462,7 +476,7 @@
|
|
462
476
|
// DESTROY
|
463
477
|
self.destroy = function(form) {
|
464
478
|
$(self)
|
465
|
-
.
|
479
|
+
.off($(self).data('event.editable'))
|
466
480
|
.removeData('disabled.editable')
|
467
481
|
.removeData('event.editable');
|
468
482
|
|
@@ -504,7 +518,6 @@
|
|
504
518
|
|
505
519
|
// SETTIMEOUT
|
506
520
|
self.setTimeout = function(callback, time) {
|
507
|
-
console.log("SELF :: setTimeout");
|
508
521
|
var timeouts = $(self).data('timeouts');
|
509
522
|
var t = setTimeout(function() {
|
510
523
|
callback();
|
@@ -550,12 +563,9 @@
|
|
550
563
|
if (settings.submit) {
|
551
564
|
/* If given html string use that. */
|
552
565
|
if (settings.submit.match(/>$/)) {
|
553
|
-
submit = $(settings.submit).click
|
554
|
-
e.stopPropagation();
|
555
|
-
e.preventDefault();
|
566
|
+
submit = $(settings.submit).on('click', function() {
|
556
567
|
if (submit.attr('type') !== 'submit') {
|
557
|
-
|
558
|
-
form.submit();
|
568
|
+
form.trigger('submit');
|
559
569
|
}
|
560
570
|
});
|
561
571
|
/* Otherwise use button with given string as text. */
|
@@ -583,7 +593,7 @@
|
|
583
593
|
}
|
584
594
|
$(this).append(cancel);
|
585
595
|
|
586
|
-
$(cancel).click
|
596
|
+
$(cancel).on('click', function(event) {
|
587
597
|
var reset;
|
588
598
|
if ($.isFunction($.editable.types[settings.type].reset)) {
|
589
599
|
reset = $.editable.types[settings.type].reset;
|
@@ -678,16 +688,29 @@
|
|
678
688
|
// Create tuples for sorting
|
679
689
|
var tuples = [];
|
680
690
|
var key;
|
681
|
-
|
682
|
-
|
691
|
+
|
692
|
+
if (Array.isArray(json) && json.every(Array.isArray)) {
|
693
|
+
// Process list of tuples
|
694
|
+
tuples = json // JSON already contains list of [key, value]
|
695
|
+
json = {};
|
696
|
+
tuples.forEach(function(e) {
|
697
|
+
json[e[0]] = e[1]; // Recreate json object to comply with following code
|
698
|
+
});
|
699
|
+
} else {
|
700
|
+
// Process object
|
701
|
+
for (key in json) {
|
702
|
+
tuples.push([key, json[key]]); // Store: [key, value]
|
703
|
+
}
|
683
704
|
}
|
684
|
-
// sort it
|
685
|
-
//tuples.sort(function(a, b) {
|
686
|
-
// a = a[1];
|
687
|
-
// b = b[1];
|
688
|
-
// return a < b ? -1 : (a > b ? 1 : 0);
|
689
|
-
//});
|
690
705
|
|
706
|
+
if (settings.sortselectoptions) {
|
707
|
+
// sort it
|
708
|
+
tuples.sort(function (a, b) {
|
709
|
+
a = a[1];
|
710
|
+
b = b[1];
|
711
|
+
return a < b ? -1 : (a > b ? 1 : 0);
|
712
|
+
});
|
713
|
+
}
|
691
714
|
// now add the options to our select
|
692
715
|
var option;
|
693
716
|
for (var i = 0; i < tuples.length; i++) {
|
@@ -700,21 +723,21 @@
|
|
700
723
|
|
701
724
|
if (key !== 'selected') {
|
702
725
|
option = $('<option />').val(key).append(value);
|
703
|
-
}
|
704
726
|
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
727
|
+
// add the selected prop if it's the same as original or if the key is 'selected'
|
728
|
+
if (json.selected === key || key === $.trim(original.revert)) {
|
729
|
+
$(option).prop('selected', 'selected');
|
730
|
+
}
|
709
731
|
|
710
|
-
|
732
|
+
$(this).find('select').append(option);
|
733
|
+
}
|
711
734
|
}
|
712
735
|
|
713
736
|
// submit on change if no submit button defined
|
714
737
|
if (!settings.submit) {
|
715
738
|
var form = this;
|
716
739
|
$(this).find('select').change(function() {
|
717
|
-
form.submit
|
740
|
+
form.trigger('submit');
|
718
741
|
});
|
719
742
|
}
|
720
743
|
}
|
@@ -796,9 +819,10 @@
|
|
796
819
|
loadtype : 'GET',
|
797
820
|
loadtext : 'Loading...',
|
798
821
|
placeholder: 'Click to edit',
|
822
|
+
sortselectoptions: false,
|
799
823
|
loaddata : {},
|
800
824
|
submitdata : {},
|
801
825
|
ajaxoptions: {}
|
802
826
|
};
|
803
827
|
|
804
|
-
})(jQuery);
|
828
|
+
})(jQuery);
|
@@ -29,6 +29,8 @@ function initializeOnTheSpot(n){
|
|
29
29
|
ok_text = el.attr('data-ok') || 'OK',
|
30
30
|
cancel_text = el.attr('data-cancel') || 'Cancel',
|
31
31
|
tooltip_text = el.attr('data-tooltip') || 'Click to edit ...',
|
32
|
+
form_css = el.attr('data-form-css'),
|
33
|
+
input_css = el.attr('data-input-css'),
|
32
34
|
edit_type = el.attr('data-edittype'),
|
33
35
|
select_data = el.attr('data-select'),
|
34
36
|
rows = el.attr('data-rows'),
|
@@ -45,6 +47,8 @@ function initializeOnTheSpot(n){
|
|
45
47
|
placeholder: tooltip_text,
|
46
48
|
cancel: cancel_text,
|
47
49
|
submit: ok_text,
|
50
|
+
cssclass: form_css,
|
51
|
+
inputcssclass: input_css,
|
48
52
|
select: selected,
|
49
53
|
onerror: function (settings, original, xhr) {
|
50
54
|
original.reset();
|
File without changes
|
@@ -6,7 +6,7 @@ module OnTheSpot
|
|
6
6
|
|
7
7
|
#def download_jeditable
|
8
8
|
# # Downloading latest jEditable
|
9
|
-
# get "http://www.appelsiini.net/download/jquery.jeditable.
|
9
|
+
# get "http://www.appelsiini.net/download/jquery.jeditable.js", "public/javascripts/jquery.jeditable.mini.js"
|
10
10
|
#end
|
11
11
|
|
12
12
|
def copy_javascripts
|
@@ -14,9 +14,9 @@ module OnTheSpot
|
|
14
14
|
#puts "The javascripts do not need to be installed since Rails 3.1"
|
15
15
|
else
|
16
16
|
copy_file "../../../../../app/assets/javascripts/on_the_spot_code.js", "public/javascripts/on_the_spot.js"
|
17
|
-
copy_file "../../../../../app/assets/javascripts/jquery.jeditable.
|
17
|
+
copy_file "../../../../../app/assets/javascripts/jquery.jeditable.js", "public/javascripts/jquery.jeditable.js"
|
18
18
|
copy_file "../../../../../app/assets/javascripts/jquery.jeditable.checkbox.js", "public/javascripts/jquery.jeditable.checkbox.js"
|
19
|
-
copy_file "../../../../../app/assets/
|
19
|
+
copy_file "../../../../../app/assets/stylesheets/on_the_spot.css", "public/stylesheets/on_the_spot.css"
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
@@ -27,4 +27,4 @@ module OnTheSpot
|
|
27
27
|
|
28
28
|
end
|
29
29
|
end
|
30
|
-
end
|
30
|
+
end
|
@@ -23,6 +23,8 @@ module OnTheSpot
|
|
23
23
|
options.reverse_merge!(:ok_text => t('on_the_spot.ok'),
|
24
24
|
:cancel_text => t('on_the_spot.cancel'),
|
25
25
|
:tooltip => t('on_the_spot.tooltip'),
|
26
|
+
:form_css => t('on_the_spot.form_css'),
|
27
|
+
:input_css => t('on_the_spot.input_css'),
|
26
28
|
:rows => 5,
|
27
29
|
:columns => 40,
|
28
30
|
:url => {:action => 'update_attribute_on_the_spot'}
|
@@ -58,6 +60,8 @@ module OnTheSpot
|
|
58
60
|
html_options[:'data-onblur'] = options[:onblur] if options[:onblur] && ['cancel','submit', 'ignore'].include?(options[:onblur])
|
59
61
|
html_options[:'data-loadurl'] = options[:loadurl] unless options[:loadurl].nil?
|
60
62
|
html_options[:'data-display-method'] = options[:display_method] unless options[:display_method].nil?
|
63
|
+
html_options[:'data-form-css'] = options[:form_css] if options[:form_css].present?
|
64
|
+
html_options[:'data-input-css'] = options[:input_css] if options[:input_css].present?
|
61
65
|
if html_options[:'data-display-method'].present? && html_options[:'data-loadurl'].nil?
|
62
66
|
html_options[:'data-loadurl'] = url_for(:action => 'get_attribute_on_the_spot')
|
63
67
|
end
|
data/npm/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
{
|
2
|
+
"name": "@nathanvda/on_the_spot",
|
3
|
+
"version": "<%= spec.version %>",
|
4
|
+
"license": "MIT",
|
5
|
+
|
6
|
+
"description": "Companion package for the on_the_spot Ruby gem.",
|
7
|
+
"homepage": "https://github.com/nathanvda/on_the_spot",
|
8
|
+
"repository": "https://github.com/nathanvda/on_the_spot",
|
9
|
+
"bugs": {
|
10
|
+
"url": "https://github.com/nathanvda/on_the_spot/issues"
|
11
|
+
},
|
12
|
+
|
13
|
+
"author": "nathan@dixis.com",
|
14
|
+
|
15
|
+
"main": "on_the_spot_code.js",
|
16
|
+
"files": ["on_the_spot_code.js", "on_the_spot.css", "README", "LICENSE", "package.json"],
|
17
|
+
|
18
|
+
"dependencies": {
|
19
|
+
"jquery": "^3.3.1",
|
20
|
+
"jquery-jeditable": "^2.0.16"
|
21
|
+
}
|
22
|
+
}
|
data/on_the_spot.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: on_the_spot 1.1.
|
5
|
+
# stub: on_the_spot 1.1.4 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "on_the_spot".freeze
|
9
|
-
s.version = "1.1.
|
9
|
+
s.version = "1.1.4"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib".freeze]
|
13
13
|
s.authors = ["Nathan Van der Auwera".freeze]
|
14
|
-
s.date = "
|
14
|
+
s.date = "2020-04-27"
|
15
15
|
s.description = "Unobtrusive in place editing, using jEditable; only works in Rails 3".freeze
|
16
16
|
s.email = "nathan@dixis.com".freeze
|
17
17
|
s.extra_rdoc_files = [
|
@@ -29,12 +29,11 @@ Gem::Specification.new do |s|
|
|
29
29
|
"README.markdown",
|
30
30
|
"Rakefile",
|
31
31
|
"VERSION",
|
32
|
-
"app/assets/css/on_the_spot.css",
|
33
32
|
"app/assets/javascripts/jquery.jeditable.checkbox.js",
|
34
33
|
"app/assets/javascripts/jquery.jeditable.js",
|
35
|
-
"app/assets/javascripts/jquery.jeditable.mini.js",
|
36
34
|
"app/assets/javascripts/on_the_spot.js",
|
37
35
|
"app/assets/javascripts/on_the_spot_code.js",
|
36
|
+
"app/assets/stylesheets/on_the_spot.css",
|
38
37
|
"lib/generators/on_the_spot/install/install_generator.rb",
|
39
38
|
"lib/generators/on_the_spot/install/templates/jquery.jeditable.mini.js",
|
40
39
|
"lib/generators/on_the_spot/install/templates/on_the_spot.en.yml",
|
@@ -43,6 +42,8 @@ Gem::Specification.new do |s|
|
|
43
42
|
"lib/on_the_spot.rb",
|
44
43
|
"lib/on_the_spot/controller_extension.rb",
|
45
44
|
"lib/on_the_spot/on_the_spot_helpers.rb",
|
45
|
+
"npm/README.md",
|
46
|
+
"npm/package.json.erb",
|
46
47
|
"on_the_spot.gemspec",
|
47
48
|
"spec/dummy/Rakefile",
|
48
49
|
"spec/dummy/app/controllers/application_controller.rb",
|
@@ -84,7 +85,7 @@ Gem::Specification.new do |s|
|
|
84
85
|
]
|
85
86
|
s.homepage = "http://github.com/nathanvda/on_the_spot".freeze
|
86
87
|
s.licenses = ["MIT".freeze]
|
87
|
-
s.rubygems_version = "
|
88
|
+
s.rubygems_version = "3.0.8".freeze
|
88
89
|
s.summary = "unobtrusive in place editing".freeze
|
89
90
|
|
90
91
|
if s.respond_to? :specification_version then
|
@@ -29,7 +29,7 @@ describe OnTheSpot::Generators::InstallGenerator do
|
|
29
29
|
expect(test_version).to eq(false)
|
30
30
|
end
|
31
31
|
|
32
|
-
['on_the_spot.js', 'jquery.jeditable.
|
32
|
+
['on_the_spot.js', 'jquery.jeditable.js', 'jquery.jeditable.checkbox.js'].each do |js_file|
|
33
33
|
it "copies #{js_file} to the correct folder" do
|
34
34
|
assert_file "public/javascripts/#{js_file}"
|
35
35
|
end
|
@@ -49,7 +49,7 @@ describe OnTheSpot::Generators::InstallGenerator do
|
|
49
49
|
run_generator
|
50
50
|
end
|
51
51
|
|
52
|
-
['on_the_spot.js', 'jquery.jeditable.
|
52
|
+
['on_the_spot.js', 'jquery.jeditable.js', 'jquery.jeditable.checkbox.js'].each do |js_file|
|
53
53
|
it "does not copy #{js_file}" do
|
54
54
|
assert_no_file "public/javascripts/#{js_file}"
|
55
55
|
end
|
@@ -61,4 +61,4 @@ describe OnTheSpot::Generators::InstallGenerator do
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
end
|
64
|
+
end
|
data/spec/on_the_spot_spec.rb
CHANGED
@@ -55,6 +55,8 @@ RSpec.describe "OnTheSpot" do
|
|
55
55
|
expect(@tester).to receive(:t).with('on_the_spot.ok').and_return("ok")
|
56
56
|
expect(@tester).to receive(:t).with('on_the_spot.cancel').and_return("cancel")
|
57
57
|
expect(@tester).to receive(:t).with('on_the_spot.tooltip').and_return("tooltip")
|
58
|
+
expect(@tester).to receive(:t).with('on_the_spot.form_css').and_return(nil)
|
59
|
+
expect(@tester).to receive(:t).with('on_the_spot.input_css').and_return(nil)
|
58
60
|
end
|
59
61
|
|
60
62
|
context "with standard route" do
|
@@ -168,3 +170,4 @@ RSpec.describe "OnTheSpot" do
|
|
168
170
|
end
|
169
171
|
end
|
170
172
|
end
|
173
|
+
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: on_the_spot
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nathan Van der Auwera
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -70,12 +70,11 @@ files:
|
|
70
70
|
- README.markdown
|
71
71
|
- Rakefile
|
72
72
|
- VERSION
|
73
|
-
- app/assets/css/on_the_spot.css
|
74
73
|
- app/assets/javascripts/jquery.jeditable.checkbox.js
|
75
74
|
- app/assets/javascripts/jquery.jeditable.js
|
76
|
-
- app/assets/javascripts/jquery.jeditable.mini.js
|
77
75
|
- app/assets/javascripts/on_the_spot.js
|
78
76
|
- app/assets/javascripts/on_the_spot_code.js
|
77
|
+
- app/assets/stylesheets/on_the_spot.css
|
79
78
|
- lib/generators/on_the_spot/install/install_generator.rb
|
80
79
|
- lib/generators/on_the_spot/install/templates/jquery.jeditable.mini.js
|
81
80
|
- lib/generators/on_the_spot/install/templates/on_the_spot.en.yml
|
@@ -84,6 +83,8 @@ files:
|
|
84
83
|
- lib/on_the_spot.rb
|
85
84
|
- lib/on_the_spot/controller_extension.rb
|
86
85
|
- lib/on_the_spot/on_the_spot_helpers.rb
|
86
|
+
- npm/README.md
|
87
|
+
- npm/package.json.erb
|
87
88
|
- on_the_spot.gemspec
|
88
89
|
- spec/dummy/Rakefile
|
89
90
|
- spec/dummy/app/controllers/application_controller.rb
|
@@ -141,8 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
141
142
|
- !ruby/object:Gem::Version
|
142
143
|
version: '0'
|
143
144
|
requirements: []
|
144
|
-
|
145
|
-
rubygems_version: 2.7.10
|
145
|
+
rubygems_version: 3.0.8
|
146
146
|
signing_key:
|
147
147
|
specification_version: 4
|
148
148
|
summary: unobtrusive in place editing
|
@@ -1,38 +0,0 @@
|
|
1
|
-
|
2
|
-
(function($){$.fn.editable=function(target,options){if('disable'==target){$(this).data('disabled.editable',true);return;}
|
3
|
-
if('enable'==target){$(this).data('disabled.editable',false);return;}
|
4
|
-
if('destroy'==target){$(this).unbind($(this).data('event.editable')).removeData('disabled.editable').removeData('event.editable');return;}
|
5
|
-
var settings=$.extend({},$.fn.editable.defaults,{target:target},options);var plugin=$.editable.types[settings.type].plugin||function(){};var submit=$.editable.types[settings.type].submit||function(){};var buttons=$.editable.types[settings.type].buttons||$.editable.types['defaults'].buttons;var content=$.editable.types[settings.type].content||$.editable.types['defaults'].content;var element=$.editable.types[settings.type].element||$.editable.types['defaults'].element;var reset=$.editable.types[settings.type].reset||$.editable.types['defaults'].reset;var callback=settings.callback||function(){};var onedit=settings.onedit||function(){};var onsubmit=settings.onsubmit||function(){};var onreset=settings.onreset||function(){};var onerror=settings.onerror||reset;if(settings.tooltip){$(this).attr('title',settings.tooltip);}
|
6
|
-
settings.autowidth='auto'==settings.width;settings.autoheight='auto'==settings.height;return this.each(function(){var self=this;var savedwidth=$(self).width();var savedheight=$(self).height();$(this).data('event.editable',settings.event);if(!$.trim($(this).html())){$(this).html(settings.placeholder);}
|
7
|
-
$(this).bind(settings.event,function(e){if(true===$(this).data('disabled.editable')){return;}
|
8
|
-
if(self.editing){return;}
|
9
|
-
if(false===onedit.apply(this,[settings,self])){return;}
|
10
|
-
e.preventDefault();e.stopPropagation();if(settings.tooltip){$(self).removeAttr('title');}
|
11
|
-
if(0==$(self).width()){settings.width=savedwidth;settings.height=savedheight;}else{if(settings.width!='none'){settings.width=settings.autowidth?$(self).width():settings.width;}
|
12
|
-
if(settings.height!='none'){settings.height=settings.autoheight?$(self).height():settings.height;}}
|
13
|
-
if($(this).html().toLowerCase().replace(/(;|")/g,'')==settings.placeholder.toLowerCase().replace(/(;|")/g,'')){$(this).html('');}
|
14
|
-
self.editing=true;self.revert=$(self).html();$(self).html('');var form=$('<form />');if(settings.cssclass){if('inherit'==settings.cssclass){form.attr('class',$(self).attr('class'));}else{form.attr('class',settings.cssclass);}}
|
15
|
-
if(settings.style){if('inherit'==settings.style){form.attr('style',$(self).attr('style'));form.css('display',$(self).css('display'));}else{form.attr('style',settings.style);}}
|
16
|
-
var input=element.apply(form,[settings,self]);var input_content;if(settings.loadurl){var t=setTimeout(function(){input.disabled=true;content.apply(form,[settings.loadtext,settings,self]);},100);var loaddata={};loaddata[settings.id]=self.id;if($.isFunction(settings.loaddata)){$.extend(loaddata,settings.loaddata.apply(self,[self.revert,settings]));}else{$.extend(loaddata,settings.loaddata);}
|
17
|
-
$.ajax({type:settings.loadtype,url:settings.loadurl,data:loaddata,async:false,success:function(result){window.clearTimeout(t);input_content=result;input.disabled=false;}});}else if(settings.data){input_content=settings.data;if($.isFunction(settings.data)){input_content=settings.data.apply(self,[self.revert,settings]);}}else{input_content=self.revert;}
|
18
|
-
content.apply(form,[input_content,settings,self]);input.attr('name',settings.name);buttons.apply(form,[settings,self]);$(self).append(form);plugin.apply(form,[settings,self]);$(':input:visible:enabled:first',form).focus();if(settings.select){input.select();}
|
19
|
-
input.keydown(function(e){if(e.keyCode==27){e.preventDefault();reset.apply(form,[settings,self]);}});var t;if('cancel'==settings.onblur){input.blur(function(e){t=setTimeout(function(){reset.apply(form,[settings,self]);},500);});}else if('submit'==settings.onblur){input.blur(function(e){t=setTimeout(function(){form.submit();},200);});}else if($.isFunction(settings.onblur)){input.blur(function(e){settings.onblur.apply(self,[input.val(),settings]);});}else{input.blur(function(e){});}
|
20
|
-
form.submit(function(e){if(t){clearTimeout(t);}
|
21
|
-
e.preventDefault();if(false!==onsubmit.apply(form,[settings,self])){if(false!==submit.apply(form,[settings,self])){if($.isFunction(settings.target)){var str=settings.target.apply(self,[input.val(),settings]);$(self).html(str);self.editing=false;callback.apply(self,[self.innerHTML,settings]);if(!$.trim($(self).html())){$(self).html(settings.placeholder);}}else{var submitdata={};submitdata[settings.name]=input.val();submitdata[settings.id]=self.id;if($.isFunction(settings.submitdata)){$.extend(submitdata,settings.submitdata.apply(self,[self.revert,settings]));}else{$.extend(submitdata,settings.submitdata);}
|
22
|
-
if('PUT'==settings.method){submitdata['_method']='put';}
|
23
|
-
$(self).html(settings.indicator);var ajaxoptions={type:'POST',data:submitdata,dataType:'html',url:settings.target,success:function(result,status){if(ajaxoptions.dataType=='html'){$(self).html(result);}
|
24
|
-
self.editing=false;callback.apply(self,[result,settings]);if(!$.trim($(self).html())){$(self).html(settings.placeholder);}},error:function(xhr,status,error){onerror.apply(form,[settings,self,xhr]);}};$.extend(ajaxoptions,settings.ajaxoptions);$.ajax(ajaxoptions);}}}
|
25
|
-
$(self).attr('title',settings.tooltip);return false;});});this.reset=function(form){if(this.editing){if(false!==onreset.apply(form,[settings,self])){$(self).html(self.revert);self.editing=false;if(!$.trim($(self).html())){$(self).html(settings.placeholder);}
|
26
|
-
if(settings.tooltip){$(self).attr('title',settings.tooltip);}}}};});};$.editable={types:{defaults:{element:function(settings,original){var input=$('<input type="hidden"></input>');$(this).append(input);return(input);},content:function(string,settings,original){$(':input:first',this).val(string);},reset:function(settings,original){original.reset(this);},buttons:function(settings,original){var form=this;if(settings.submit){if(settings.submit.match(/>$/)){var submit=$(settings.submit).click(function(){if(submit.attr("type")!="submit"){form.submit();}});}else{var submit=$('<button type="submit" />');submit.html(settings.submit);}
|
27
|
-
$(this).append(submit);}
|
28
|
-
if(settings.cancel){if(settings.cancel.match(/>$/)){var cancel=$(settings.cancel);}else{var cancel=$('<button type="cancel" />');cancel.html(settings.cancel);}
|
29
|
-
$(this).append(cancel);$(cancel).click(function(event){if($.isFunction($.editable.types[settings.type].reset)){var reset=$.editable.types[settings.type].reset;}else{var reset=$.editable.types['defaults'].reset;}
|
30
|
-
reset.apply(form,[settings,original]);return false;});}}},text:{element:function(settings,original){var input=$('<input />');if(settings.width!='none'){input.width(settings.width);}
|
31
|
-
if(settings.height!='none'){input.height(settings.height);}
|
32
|
-
input.attr('autocomplete','off');$(this).append(input);return(input);}},textarea:{element:function(settings,original){var textarea=$('<textarea />');if(settings.rows){textarea.attr('rows',settings.rows);}else if(settings.height!="none"){textarea.height(settings.height);}
|
33
|
-
if(settings.cols){textarea.attr('cols',settings.cols);}else if(settings.width!="none"){textarea.width(settings.width);}
|
34
|
-
$(this).append(textarea);return(textarea);}},select:{element:function(settings,original){var select=$('<select />');$(this).append(select);return(select);},content:function(data,settings,original){if(String==data.constructor){eval('var json = '+data);}else{var json=data;}
|
35
|
-
for(var key in json){if(!json.hasOwnProperty(key)){continue;}
|
36
|
-
if('selected'==key){continue;}
|
37
|
-
var option=$('<option />').val(key).append(json[key]);$('select',this).append(option);}
|
38
|
-
$('select',this).children().each(function(){if($(this).val()==json['selected']||$(this).text()==$.trim(original.revert)){$(this).attr('selected','selected');}});}}},addInputType:function(name,input){$.editable.types[name]=input;}};$.fn.editable.defaults={name:'value',id:'id',type:'text',width:'auto',height:'auto',event:'click.editable',onblur:'cancel',loadtype:'GET',loadtext:'Loading...',placeholder:'Click to edit',loaddata:{},submitdata:{},ajaxoptions:{}};})(jQuery);
|