releaf-core 1.0.4 → 1.0.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0729e307c18711ce4f77879c011eeba4b383e0d1
4
- data.tar.gz: eef36e2915a38c27d9456088d295a6c1472f4e5f
3
+ metadata.gz: 1fcd7c58a85b8dc627c79cf87eb23b6ac23ffd76
4
+ data.tar.gz: ae97a97f22f3f64facb61b0eaa77b96f5210f2c0
5
5
  SHA512:
6
- metadata.gz: 1742cbb9ae99eaf6883f7258fdf09d5c16e4b86738cd18cc9003dba4aa5d96bba96dd2ef44bd7d49596fb9347f1e48541ea0cd8d196a8ad1a95ed78cf9e1f751
7
- data.tar.gz: 3447fd842ef858b232a879ae648e1af8aef808e1acf689335e67c7e1abef2003501ec235eab3550c5d243ad10a2abfddf34c4c3314fabd926c4b3001f8c0d58b
6
+ metadata.gz: e97a051440a22cb2ced65bc7583cc817f3ffe41a8e88215cb09d835c9f9a8da67f6f0547762c7161c1042db0587bab53f94312600d242c62a62209fc3c49d59f
7
+ data.tar.gz: 7d6f1ec452391adbf6ef7fde0da1072a62b48e506d963a12ff41dd7f4cc1ca3a6d78178f35097901cf9d83e3dd0cb7125cc8775f899e7f91ff34ba2d55bda9f4
@@ -58,7 +58,7 @@ jQuery(function()
58
58
  type = 'default';
59
59
  }
60
60
 
61
- if (typeof window.ckeditor_configuration[type] == 'undefined')
61
+ if (typeof window.ckeditor_configuration[type] === 'undefined')
62
62
  {
63
63
  return;
64
64
  }
@@ -10,7 +10,7 @@ var RemoteValidator = function( form )
10
10
  v.form = form;
11
11
  v.clicked_button = null;
12
12
 
13
- v.form.on('click.rails', submit_elements_selector, function( event ) {
13
+ v.form.on('click', submit_elements_selector, function( event ) {
14
14
  var target = jQuery( event.target );
15
15
 
16
16
  // webkit sends inner button elements as event targets instead of the button
@@ -21,14 +21,15 @@ var RemoteValidator = function( form )
21
21
  target = closest_button;
22
22
  }
23
23
 
24
- // register only submit buttons - buttons with type="submit" or without type attribute at all
24
+ // register only submit buttons - buttons with type="submit" or without type attribute at all.
25
25
  // direct target[0].type property is used because of inconsistent attr() method return values
26
26
  // between older and newer jQuery versions
27
27
  if (target.is( 'button' ) && target[0].type !== 'submit' )
28
28
  {
29
29
  return;
30
30
  }
31
- v.clicked_button = target;
31
+
32
+ v.register_clicked_button( target );
32
33
  });
33
34
 
34
35
  v.form.on( 'ajax:before', function( event )
@@ -368,7 +369,7 @@ var RemoteValidator = function( form )
368
369
 
369
370
  case 'validation:error': // validation error
370
371
 
371
- v.clicked_button = null;
372
+ v.clear_clicked_button();
372
373
 
373
374
  break;
374
375
 
@@ -381,27 +382,57 @@ var RemoteValidator = function( form )
381
382
  });
382
383
  };
383
384
 
384
- RemoteValidator.prototype.submit_form = function()
385
+ RemoteValidator.prototype.register_clicked_button = function(button)
385
386
  {
386
387
  var v = this;
387
-
388
- // add originally clicked submit button to form as a hidden field
389
- if (v.clicked_button)
388
+ v.clicked_button = button;
389
+
390
+ // when sending form values with FormData, the clicked button value is not included in the data
391
+ // (except on Safari, and therefore also on PhantomJS - that's why the tests worked fine even without this).
392
+
393
+ // since releaf sometimes uses the clicked button value to modify the action on the server side,
394
+ // (e.g. for "Save and create another" feature), the value of the clicked button must be appended
395
+ // to the form as a hidden field before the validation / submission starts.
396
+
397
+ // longer description:
398
+ // the algorithm to construct the form data set for a form optionally in the context
399
+ // of a submitter is as follows:
400
+ // https://www.w3.org/TR/html5/forms.html#constructing-form-data-set
401
+ // https://xhr.spec.whatwg.org/#dom-formdata
402
+ // If not specified otherwise, submitter is null.
403
+ // when this algorithm is executed from the FormData constructor, no submitter is specified,
404
+ // so no buttons are included in the form data set automatically.
405
+
406
+ var form = button.closest('form');
407
+ var hidden_field = form.find('input.submit-button-value').first();
408
+ if (hidden_field.length < 1)
390
409
  {
391
- var button = v.clicked_button.first();
392
- var name = button.attr('name');
393
- if (name)
394
- {
395
- var input = v.form.find('input[type="hidden"][name="' + name + '"]');
396
- if (input.length < 1)
397
- {
398
- input = jQuery('<input />').attr('type', 'hidden').attr('name', button.attr('name'));
399
- input.appendTo(v.form);
400
- }
401
- input.val(button.val());
402
- }
410
+ hidden_field = jQuery('<input type="hidden" class="submit-button-value" />');
411
+ hidden_field.appendTo(form);
412
+ }
413
+ var name = button.attr('name');
414
+ if (name)
415
+ {
416
+ hidden_field.attr('name', name);
417
+ hidden_field.val(button.val());
418
+ }
419
+ else
420
+ {
421
+ // no need for the hidden field in case of nameless buttons
422
+ hidden_field.remove();
403
423
  }
404
- v.form[0].submit();
424
+ };
425
+
426
+ RemoteValidator.prototype.clear_clicked_button = function()
427
+ {
428
+ var v = this;
429
+ v.clicked_button = null;
430
+ v.form.find('input.submit-button-value').remove();
431
+ };
432
+
433
+ RemoteValidator.prototype.submit_form = function()
434
+ {
435
+ this.form[0].submit();
405
436
  };
406
437
 
407
438
  jQuery(function(){
@@ -6,6 +6,7 @@ feature "Richtext editing", js: true do
6
6
 
7
7
  scenario "Image toolbar available when controller support attachments" do
8
8
  visit new_admin_node_path(content_type: 'TextPage')
9
+ wait_for_all_richtexts
9
10
  fill_in_richtext 'Text', with: "some text"
10
11
  expect(page).to have_css("a.cke_button__image")
11
12
  end
@@ -13,6 +14,7 @@ feature "Richtext editing", js: true do
13
14
  scenario "Image toolbar unavailable when controller doesn't support attachments" do
14
15
  allow_any_instance_of(Admin::BooksController).to receive(:releaf_richtext_attachment_upload_url).and_return("")
15
16
  visit new_admin_book_path
17
+ wait_for_all_richtexts
16
18
  fill_in_richtext "Summary", with: "some text"
17
19
  expect(page).to_not have_css("a.cke_button__image")
18
20
  end
@@ -20,6 +22,7 @@ feature "Richtext editing", js: true do
20
22
  scenario "Test helper fills in correct value" do
21
23
  visit new_admin_node_path(content_type: 'TextPage')
22
24
  html = %Q[ <p class="xxx" id='yyy'> &quot;HTML&quot; 'content' </p> ]
25
+ wait_for_all_richtexts
23
26
  fill_in_richtext 'Text', with: html
24
27
  content = evaluate_script('CKEDITOR.instances["resource_content_attributes_text_html"].getData();')
25
28
  expect(content).to match_html html
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: releaf-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - CubeSystems
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-01 00:00:00.000000000 Z
11
+ date: 2016-12-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -630,7 +630,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
630
630
  version: '0'
631
631
  requirements: []
632
632
  rubyforge_project:
633
- rubygems_version: 2.5.1
633
+ rubygems_version: 2.6.7
634
634
  signing_key:
635
635
  specification_version: 4
636
636
  summary: core gem for releaf