scrivito_table_widget 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8b4b4dd403b5309ea5cfb5fe6fb957fa50e02f09
4
+ data.tar.gz: 6aa97aff54af329efec45da1a7081f3a7a522cb3
5
+ SHA512:
6
+ metadata.gz: 74dc31085867e65bb5ff2c78f5c90b52b5549b4e8c7136f1d5a8e1e7813068c5c64c37352efd35a04c46e9a2c0de07ce385ea5b1130d9588c4fbf34470fb5ed0
7
+ data.tar.gz: aac856e902a88137a608d13170f0467a948b31579b1c960b2eaf1dff1eae0e1b24433e3418ba7077194c56e0702d12340b20431b807bc1ee8d2d3c201338a9d0
data/LICENSE ADDED
@@ -0,0 +1,4 @@
1
+ Copyright (c) 2009 - 2014 Infopark AG (http://www.infopark.com)
2
+
3
+ This software can be used and modified under the LGPL-3.0. Please refer to
4
+ http://www.gnu.org/licenses/lgpl-3.0.html for the license text.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ scrivito_accordion
2
+ =====================
3
+
4
+ [![Gem Version](https://badge.fury.io/rb/scrivito_table_widget.svg)](http://badge.fury.io/rb/scrivito_table_widget)
5
+ [![Code Climate](https://codeclimate.com/github/Scrivito/scrivito_table_widget/badges/gpa.svg)](https://codeclimate.com/github/Scrivito/scrivito_table_widget)
6
+
7
+ A Widget for Scrivito for a table. It is using Bootstrap 3.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's `Gemfile`:
12
+
13
+ gem 'scrivito_table_widget'
14
+
15
+ Add this line to your editing javascript manifest:
16
+
17
+ /= require scrivito_table_widget/editing
18
+
19
+ After that, execute:
20
+
21
+ $ bundle
22
+ $ rake cms:migrate:install
23
+ $ rake cms:migrate
24
+ $ rake cms:migrate:publish
25
+
26
+ ## Changelog
27
+ See [Changelog](https://github.com/Scrivito/scrivito_table_widget/blob/master/CHANGELOG.md) for more
28
+ details.
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it ( https://github.com/Scrivito/scrivito_table_widget/fork )
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,21 @@
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 = 'ScrivitoTableWidget'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+ Bundler::GemHelper.install_tasks
21
+
@@ -0,0 +1,14 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require table_widget/jquery.edit.table
14
+ //= require table_widget/tableEditor
@@ -0,0 +1,130 @@
1
+ (function($, App) {
2
+ 'use strict';
3
+
4
+ var activeElement = null;
5
+ var initialized = false;
6
+ var activeTable = null;
7
+ var keysBound = false;
8
+ var rows = 0;
9
+ var cols = 0;
10
+
11
+ $.fn.edittable = function(opts) {
12
+ $.fn.edittable.options = $.extend({
13
+ css_class: 'table table-responsive table-striped',
14
+ header: true
15
+ }, opts);
16
+
17
+ activeTable = this.prop("tagName") == "DIV" ? this : this.parents("[data-editor=table-editor]");
18
+
19
+ if(!keysBound) {
20
+ $.fn.edittable.bindKeys();
21
+ }
22
+
23
+ if(!initialized || activeTable != this) {
24
+ $.fn.edittable.initialize(this);
25
+ }
26
+
27
+ activeElement = this.prop("tagName") == "DIV" ? this.find("td, th").first() : this;
28
+ activeElement.attr("contenteditable", true);
29
+
30
+ rows = $.fn.edittable.getRowCount();
31
+ cols = $.fn.edittable.getColCount();
32
+ };
33
+
34
+ $.fn.edittable.getRowCount = function() {
35
+ return activeTable.find("tbody tr").length;
36
+ };
37
+
38
+ $.fn.edittable.getColCount = function() {
39
+ return activeTable.find("tbody tr").first().children().length;
40
+ };
41
+
42
+ $.fn.edittable.initialize = function(element) {
43
+ if(element.prop("tagName") == "DIV" && element.html() === "") {
44
+ $.fn.edittable.createNewTable(element);
45
+ }
46
+ initialized = true;
47
+ };
48
+
49
+ $.fn.edittable.table = function(element) {
50
+ var tableContent = activeTable.html();
51
+
52
+ activeElement.removeAttr("contenteditable");
53
+ activeElement = null;
54
+ activeTable = null;
55
+ initialized = false;
56
+
57
+ rows = 0;
58
+ cols = 0;
59
+ return tableContent;
60
+ };
61
+
62
+ $.fn.edittable.createNewTable = function(element) {
63
+ if($.fn.edittable.options.header) {
64
+ element.html("<table class='"+ $.fn.edittable.options.css_class +"'><thead><tr><th>TableHead</th></tr></thead><tbody><tr><td>Content</td></tr></tbody></table>");
65
+ } else {
66
+ element.html("<table class='"+ $.fn.edittable.options.css_class +"'><tbody><tr><td>Content</td></tr></tbody></table>");
67
+ }
68
+ };
69
+
70
+ $.fn.edittable.bindKeys = function() {
71
+ $('body').keydown(function(e) {
72
+ if (e.ctrlKey || e.metaKey) {
73
+ if(e.keyCode == 8) { // CMD + Backspace
74
+ e.preventDefault();
75
+ $.fn.edittable.removeColumn();
76
+ }
77
+ if(e.keyCode == 13) { // CMD + Enter
78
+ e.preventDefault();
79
+ $.fn.edittable.removeRow();
80
+ }
81
+ }
82
+ if(e.altKey) {
83
+ if(e.keyCode == 9) { // Alt+Tab
84
+ e.preventDefault();
85
+ $.fn.edittable.addColumn();
86
+ }
87
+ if(e.keyCode == 13) { // Alt+Enter
88
+ e.preventDefault();
89
+ $.fn.edittable.addRow();
90
+ }
91
+ }
92
+ });
93
+ keysBound = true;
94
+ };
95
+
96
+ $.fn.edittable.addRow = function() {
97
+ var newRow = "<tr>"+ new Array(cols + 1).join("<td>Content</td>"); +"</tr>";
98
+ if(activeElement.prop("tagName") == "TH") {
99
+ activeTable.find("tbody").prepend(newRow);
100
+ } else {
101
+ activeElement.parents("tr").first().after(newRow);
102
+ }
103
+ rows += 1;
104
+ };
105
+
106
+ $.fn.edittable.addColumn = function() {
107
+ var pos = activeElement.index();
108
+ $(activeTable.find("thead tr").find("th")[pos]).after("<th>TableHead</th>");
109
+ activeTable.find("tbody tr").each(function(index, row) {
110
+ $($(row).find("td")[pos]).after("<td>Content</td>");
111
+ });
112
+ cols += 1;
113
+ };
114
+
115
+ $.fn.edittable.removeColumn = function() {
116
+ var pos = activeElement.index();
117
+ if(window.confirm("Delete this column?")) {
118
+ activeTable.find("tr").each(function(index, row) {
119
+ $(row).children()[pos].remove();
120
+ });
121
+ }
122
+ };
123
+
124
+ $.fn.edittable.removeRow = function() {
125
+ if(window.confirm("Delete this row?")) {
126
+ activeElement.parents("tr").remove();
127
+ }
128
+ };
129
+
130
+ })(jQuery, this);
@@ -0,0 +1,38 @@
1
+ (function($, App) {
2
+ 'use strict';
3
+
4
+ $(function() {
5
+ App.tableEditor = {
6
+ // set selector for Editor
7
+ selector: '[data-editor=table-editor]',
8
+
9
+ // set function triggert on click
10
+ clickFunction: function(cmsField) {
11
+ cmsField.edittable();
12
+ },
13
+
14
+ blurFunction: function(cmsField) {
15
+ var text = $.fn.edittable.table(cmsField);
16
+ return cmsField.parents(tableEditor.selector).scrivito('save', text);
17
+ }
18
+ };
19
+
20
+ // Set click event
21
+ scrivito.on('load', function() {
22
+ return $('body').on('click', tableEditor.selector, function(event) {
23
+ if(scrivito.in_editable_view()) {
24
+ tableEditor.clickFunction($(event.target));
25
+ };
26
+ });
27
+ });
28
+
29
+ scrivito.on('load', function() {
30
+ return $('body').on('blur', tableEditor.selector, function(event) {
31
+ if(scrivito.in_editable_view()) {
32
+ tableEditor.blurFunction($(event.target));
33
+ };
34
+ });
35
+ });
36
+ });
37
+
38
+ })(jQuery, this);
@@ -0,0 +1,2 @@
1
+ class TableWidget < Widget
2
+ end
@@ -0,0 +1,13 @@
1
+ <div class="editing-dialog-thumbnail">
2
+ <div class="visualization">
3
+ <span class="icon editing-icon-headline"></span>
4
+ </div>
5
+
6
+ <div class="title">
7
+ Table
8
+ </div>
9
+
10
+ <div class="description">
11
+ A Editable Table.
12
+ </div>
13
+ </div>
@@ -0,0 +1 @@
1
+ <%= scrivito_tag(:div, widget, :table, data: {editor: 'table-editor'}) %>
@@ -0,0 +1,13 @@
1
+ <div class="editing-dialog-thumbnail">
2
+ <div class="visualization">
3
+ <span class="icon editing-icon-headline"></span>
4
+ </div>
5
+
6
+ <div class="title">
7
+ Table
8
+ </div>
9
+
10
+ <div class="description">
11
+ A Table.
12
+ </div>
13
+ </div>
@@ -0,0 +1,5 @@
1
+ module ScrivitoTableWidget
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace ScrivitoTableWidget
4
+ end
5
+ end
@@ -0,0 +1,3 @@
1
+ module ScrivitoTableWidget
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "scrivito_table_widget/engine"
2
+
3
+ module ScrivitoTableWidget
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :scrivito_table_widget do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,100 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: scrivito_table_widget
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Scrivito
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-11-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: scrivito
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description: Scrivito Widget for a table.
56
+ email:
57
+ - support@scrivito.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/assets/javascripts/table_widget/editing.js
66
+ - app/assets/javascripts/table_widget/jquery.edit.table.js
67
+ - app/assets/javascripts/table_widget/tableEditor.js
68
+ - app/models/table_widget.rb
69
+ - app/views/table_widget/details.html.erb
70
+ - app/views/table_widget/show.html.erb
71
+ - app/views/table_widget/thumbnail.html.erb
72
+ - lib/scrivito_table_widget.rb
73
+ - lib/scrivito_table_widget/engine.rb
74
+ - lib/scrivito_table_widget/version.rb
75
+ - lib/tasks/scrivito_table_widget_tasks.rake
76
+ homepage: https://www.scrivito.com
77
+ licenses:
78
+ - LGPL-3.0
79
+ metadata: {}
80
+ post_install_message:
81
+ rdoc_options: []
82
+ require_paths:
83
+ - lib
84
+ required_ruby_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ required_rubygems_version: !ruby/object:Gem::Requirement
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project:
96
+ rubygems_version: 2.3.0
97
+ signing_key:
98
+ specification_version: 4
99
+ summary: Scrivito Widget for a table.
100
+ test_files: []