scrivito_advanced_editors 0.0.10 → 0.0.11

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6812757790c4b39db1e079941b07335eeb49d689
4
- data.tar.gz: d153d49a8623dd765c6f5a9a765cb733e8e52c79
3
+ metadata.gz: b51dfae24a2825a862c6e7eaa6e333335834b705
4
+ data.tar.gz: 17687e42c503593f89216d0e9514848e553d1994
5
5
  SHA512:
6
- metadata.gz: 8b13224bfbac76e597ff861d7a8358f5dffd35fd80c298ec19dd499a0624ff8c9832c165608ee786346d3f9249a2aa9f7a40c5b241f29246f95de16ab7ef5959
7
- data.tar.gz: e06893831b87eedfe44ff79e625d6d853714d278f3632435acab762060a1d7be1e79e02adbaf2dec54df2e8380972fe84d37554b04c2babb43e0fc3b0848bbf5
6
+ metadata.gz: 02307b30f93e3823a72602f7e9d5a92050a9fadd9110ad0cb46b461080684bd063aa6ac447c9731857cc02c065acec20cde5111db94a65e9039611208c675f60
7
+ data.tar.gz: 9f80b016caace20101fe72d5dae4afca54135cc6106f9f558134e011d8bc33738ca33ffaac0d5b464dafb51ae7fbaea4729604b57d190f31e8127d1c15cc5e6a
@@ -3,11 +3,11 @@
3
3
 
4
4
  $(function() {
5
5
  scrivito.on('content', function(content) {
6
- $(content).find('[data-scrivito-tab-toggle-details]').on('click', function() {
7
- var tab_details_link = $(this);
8
- var tab_details_id = tab_details_link.attr('data-scrivito-tab-toggle-details');
9
- var tab_details = tab_details_link.parent().find('.scrivito-tab-details-'+tab_details_id);
10
- tab_details.toggle();
6
+ $(content).find('[data-scrivito-toggle-details]').on('click', function() {
7
+ var details_link = $(this);
8
+ var details_id = details_link.data('scrivito-toggle-details');
9
+ var details = details_link.parent().find('.scrivito-details-' + details_id);
10
+ details.toggle();
11
11
  return false;
12
12
  });
13
13
  });
@@ -5,14 +5,15 @@
5
5
  App.ScrivitoListEditor = {
6
6
  // set selector for Editor
7
7
  selector: "[data-editor='scrivito-list-editor']",
8
-
8
+
9
9
  // Function that will be called on scrivito load
10
10
  initFunction: function() { },
11
-
11
+
12
12
  // set function triggert on click
13
13
  clickFunction: function(scrivito_tag, text, delimiter) {
14
14
  var delimiter = $(scrivito_tag).data('delimiter') || '|';
15
- return scrivito_tag.scrivito('save', text.join(delimiter));
15
+ var content = scrivito_tag.data('scrivito-field-type') == 'string' ? text.join(delimiter) : text;
16
+ return scrivito_tag.scrivito('save', content);
16
17
  },
17
18
  };
18
19
 
@@ -22,8 +23,9 @@
22
23
  var elems = $(ScrivitoListEditor.selector);
23
24
  $.each(elems, function(index, elem) {
24
25
  var delimiter = $(elem).data('delimiter') || '|';
26
+ var content = $(elem).data('scrivito-field-type') == 'string' ? $(elem).html().split(delimiter) : $(elem).scrivito('content');
25
27
  $(elem).tagEditor({
26
- initialTags: $(elem).html().split(delimiter),
28
+ initialTags: content,
27
29
  delimiter: delimiter,
28
30
  forceLowercase: false,
29
31
  maxLength: 1000,
@@ -0,0 +1,47 @@
1
+ (function($, App) {
2
+ 'use strict';
3
+
4
+ $(function() {
5
+
6
+ App.ScrivitoMultiSelectButton = {
7
+ // set selector for Editor
8
+ selector: "[data-editor='scrivito-multi-select-button']",
9
+
10
+ // Function that will be called on scrivito load
11
+ initFunction: function() {},
12
+
13
+ // set function triggert on click
14
+ clickFunction: function(scrivito_tag) {
15
+ var content = scrivito_tag.data('content');
16
+ //var text = scrivito_tag.scrivito('content');
17
+ var buttons = scrivito_tag.parent().find('button');
18
+
19
+ var text = [];
20
+ $.each(buttons, function(index, elem) {
21
+ var button = $(elem);
22
+ if(button.hasClass('active')) text.push(button.data('content'));
23
+ });
24
+
25
+ if(scrivito_tag.hasClass('active')) {
26
+ text.splice( text.indexOf(content), 1 );
27
+ } else {
28
+ text.push(content);
29
+ }
30
+
31
+ scrivito_tag.toggleClass('active');
32
+
33
+ return scrivito_tag.scrivito('save', text);
34
+ },
35
+ };
36
+
37
+ // Set click event
38
+ scrivito.on('load', function() {
39
+ if(scrivito.in_editable_view()) {
40
+ return $('body').on('click', ScrivitoMultiSelectButton.selector, function(event) {
41
+ ScrivitoMultiSelectButton.clickFunction($(event.target));
42
+ });
43
+ }
44
+ });
45
+ });
46
+
47
+ })(jQuery, this);
@@ -7,24 +7,24 @@
7
7
  content: "?";
8
8
  }
9
9
 
10
- .scrivito-tab-title-details {
10
+ .scrivito-title-details {
11
11
  background: #ddd;
12
12
  padding: 10px;
13
13
  margin-bottom: 2px;
14
14
  }
15
15
 
16
- .scrivito-tab-title-details h4 {
16
+ .scrivito-title-details h4 {
17
17
  display: inline;
18
18
  }
19
19
 
20
- [data-scrivito-tab-toggle-details] {
20
+ [data-scrivito-toggle-details] {
21
21
  font-size: 12px;
22
22
  padding-left: 5px;
23
23
  }
24
24
 
25
- [class^=scrivito-tab-details-] {
25
+ [class^=scrivito-details-] {
26
26
  display: none;
27
27
  background: #eee;
28
28
  padding: 10px;
29
- margin-top: 5px;
29
+ margin: 5px -10px -10px;
30
30
  }
@@ -0,0 +1,32 @@
1
+ .scrivito_dialog .button_list button[data-editor="scrivito-multi-select-button"] {
2
+ margin: 4px 0;
3
+ min-width: 28px;
4
+ text-shadow: 0 0 2px #222;
5
+ background: #444;
6
+ color: #fff;
7
+ outline: none !important;
8
+ border: none;
9
+ box-shadow: 0 0 5px rgba(0, 0, 0, 0.2);
10
+ font-size: 15px;
11
+ border-radius: 0;
12
+ line-height: 15px;
13
+ width: initial;
14
+ float: left;
15
+ &:first-child {
16
+ margin-left: 4px;
17
+ border-radius: 5px 0 0 5px;
18
+ }
19
+ &:last-child {
20
+ margin-right: 4px;
21
+ border-radius: 0 5px 5px 0;
22
+ }
23
+ }
24
+
25
+ .scrivito_dialog .button_list button[data-editor='scrivito-multi-select-button']:hover {
26
+ background: #888;
27
+ }
28
+
29
+ .scrivito_dialog .button_list button[data-editor='scrivito-multi-select-button'].active {
30
+ box-shadow: 0 0px 5px rgba(0,0,0,0.4) inset;
31
+ background: #888;
32
+ }
@@ -1,42 +1,71 @@
1
1
  module ScrivitoAdvancedEditors
2
2
  module ScrivitoAdvancedTagHelper
3
3
 
4
+ def scrivito_multi_select_button_editor(obj, attribute, list=nil)
5
+ scrivito_button_editor(obj, attribute, 'select', list)
6
+ end
7
+
4
8
  def scrivito_toggle_button_editor(obj, attribute, list=nil)
9
+ scrivito_button_editor(obj, attribute, 'toggle', list)
10
+ end
11
+
12
+ def scrivito_button_editor(obj, attribute, type, list=nil)
5
13
  list = enum_list(obj, attribute) if list.nil?
6
14
 
7
15
  buttons = if block_given?
8
16
  list.map { |elem| yield(elem) }.join('').html_safe
9
17
  else
10
- list.map { |elem| fallback_toggle_button(obj, attribute, elem, obj.send(attribute)) }.join('').html_safe
18
+ list.map { |elem| fallback_toggle_button(obj, attribute, elem, obj.send(attribute), type) }.join('').html_safe
11
19
  end
12
20
 
13
21
  content_tag :div, buttons, class: 'button_list'
14
22
  end
15
23
 
16
24
  def scrivito_selectable_color_classes(class_name, attribute)
17
- if Obj.respond_to?('selectable_color_classes')
25
+ colors = if Obj.respond_to?('selectable_color_classes')
18
26
  Obj.selectable_color_classes(class_name, attribute)
19
27
  else
20
28
  fallback_colors
21
29
  end
30
+
31
+ colors.map { |color| color_hash(color) }
22
32
  end
23
33
 
24
34
  private
25
35
 
26
36
  def fallback_colors
27
- %w(transparent black gray light-gray red green blue yellow)
37
+ ['','transparent', 'black', 'gray', 'light-gray', 'red', 'green', 'blue', 'yellow']
28
38
  end
29
39
 
30
- def fallback_toggle_button(obj, attribute, elem, active)
31
- scrivito_tag(:button, obj, attribute, class: css_class(elem, active), data: data_attribute(elem)) do
32
- elem.to_s
40
+ def fallback_toggle_button(obj, attribute, elem, active, type)
41
+ content = elem.is_a?(Hash) ? elem : content_hash(elem)
42
+ scrivito_tag(:button, obj, attribute, class: (css_class(elem, active,) + content[:css]), style: content[:style], data: data_attribute(content, type)) do
43
+ content[:caption]
33
44
  end
34
45
  end
35
46
 
36
- def data_attribute(elem)
47
+ def content_hash(elem)
37
48
  {
38
- editor: 'scrivito-toggle-button',
39
49
  content: elem,
50
+ caption: (elem.present? ? elem.to_s : 'none'),
51
+ style: '',
52
+ css: ''
53
+ }
54
+ end
55
+
56
+ def color_hash(color)
57
+ {
58
+ content: color,
59
+ caption: (color.present? ? color : 'no selection'),
60
+ style: '',
61
+ css: color,
62
+ }
63
+ end
64
+
65
+ def data_attribute(elem, type)
66
+ {
67
+ editor: (type == 'toggle' ? 'scrivito-toggle-button' : 'scrivito-multi-select-button'),
68
+ content: elem[:content],
40
69
  }
41
70
  end
42
71
 
@@ -45,7 +74,9 @@ module ScrivitoAdvancedEditors
45
74
  end
46
75
 
47
76
  def css_class(elem, active)
48
- elem.to_s == active ? 'active' : ''
77
+ return '' if active.nil?
78
+ return active == elem ? 'active' : '' if active.is_a? String
79
+ active.include?(elem) ? 'active' : ''
49
80
  end
50
81
  end
51
82
  end
@@ -1,5 +1 @@
1
- <%= scrivito_toggle_button_editor(widget, attribute, scrivito_selectable_color_classes(widget.class.to_s, attribute)) do |elem|
2
- scrivito_tag(:button, widget, attribute, class: "#{elem == widget.send(attribute) ? 'active' : ''} #{elem}", data: {editor: 'scrivito-toggle-button', content: elem}) do
3
- elem
4
- end
5
- end %>
1
+ <%= scrivito_toggle_button_editor(widget, attribute, scrivito_selectable_color_classes(widget.class.to_s, attribute)) %>
@@ -1,3 +1,3 @@
1
1
  module ScrivitoAdvancedEditors
2
- VERSION = "0.0.10"
2
+ VERSION = "0.0.11"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: scrivito_advanced_editors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.10
4
+ version: 0.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scrivito
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-23 00:00:00.000000000 Z
11
+ date: 2015-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,7 @@ files:
80
80
  - app/assets/javascripts/scripts/jquery.tag-editor.min.js
81
81
  - app/assets/javascripts/scripts/scrivito_dialog.js
82
82
  - app/assets/javascripts/scripts/scrivito_list_editor.js
83
+ - app/assets/javascripts/scripts/scrivito_multi_select_button.js
83
84
  - app/assets/javascripts/scripts/scrivito_tabs.js
84
85
  - app/assets/javascripts/scripts/scrivito_textarea_editor.js
85
86
  - app/assets/javascripts/scripts/scrivito_toggle_button.js
@@ -88,6 +89,7 @@ files:
88
89
  - app/assets/stylesheets/scrivito_advanced_editors/create_obj.css
89
90
  - app/assets/stylesheets/scrivito_advanced_editors/jquery.tag-editor.css
90
91
  - app/assets/stylesheets/scrivito_advanced_editors/scrivito_dialog.css
92
+ - app/assets/stylesheets/scrivito_advanced_editors/scrivito_mutli_select_button.css.scss
91
93
  - app/assets/stylesheets/scrivito_advanced_editors/scrivito_tabs.css
92
94
  - app/assets/stylesheets/scrivito_advanced_editors/scrivito_toggle_button.css
93
95
  - app/assets/stylesheets/scrivito_advanced_editors/textarea_editor.css.scss