spree_editor 0.30.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ \#*
2
+ *~
3
+ .#*
4
+ .DS_Store
5
+ .idea
6
+ .project
7
+ tmp
8
+ nbproject
9
+ *.swp
data/LICENSE ADDED
@@ -0,0 +1,23 @@
1
+ Redistribution and use in source and binary forms, with or without modification,
2
+ are permitted provided that the following conditions are met:
3
+
4
+ * Redistributions of source code must retain the above copyright notice,
5
+ this list of conditions and the following disclaimer.
6
+ * Redistributions in binary form must reproduce the above copyright notice,
7
+ this list of conditions and the following disclaimer in the documentation
8
+ and/or other materials provided with the distribution.
9
+ * Neither the name of the Rails Dog LLC nor the names of its
10
+ contributors may be used to endorse or promote products derived from this
11
+ software without specific prior written permission.
12
+
13
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
14
+ "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
15
+ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
16
+ A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
17
+ CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18
+ EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19
+ PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20
+ PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21
+ LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
22
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
23
+ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,16 @@
1
+ SpreeEditor
2
+ ===========
3
+
4
+ Rich editor for Spree. Uses Yahoo UI Editor with Image and File uploading.
5
+ Can be used with any model.
6
+
7
+
8
+ Example
9
+ =======
10
+
11
+ In _form.html.erb:
12
+
13
+ <%= rich_editor(:id => 'page_body', :object => @page) %>
14
+
15
+
16
+ Copyright (c) 2010 [divineforest], released under the New BSD License
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require File.expand_path('../../config/application', __FILE__)
2
+
3
+ require 'rubygems'
4
+ require 'rake'
5
+ require 'rake/testtask'
6
+ require 'rake/packagetask'
7
+ require 'rake/gempackagetask'
8
+
9
+ spec = eval(File.read('spree_editor.gemspec'))
10
+
11
+ Rake::GemPackageTask.new(spec) do |p|
12
+ p.gem_spec = spec
13
+ end
14
+
15
+ desc "Release to gemcutter"
16
+ task :release => :package do
17
+ require 'rake/gemcutter'
18
+ Rake::Gemcutter::Tasks.new(spec).define
19
+ Rake::Task['gem:push'].invoke
20
+ end
21
+
22
+ desc "Default Task"
23
+ task :default => [ :spec ]
24
+
25
+ require 'rspec/core/rake_task'
26
+ RSpec::Core::RakeTask.new
27
+
28
+ # require 'cucumber/rake/task'
29
+ # Cucumber::Rake::Task.new do |t|
30
+ # t.cucumber_opts = %w{--format pretty}
31
+ # end
@@ -0,0 +1,10 @@
1
+ class ContentFilesController < Spree::BaseController
2
+
3
+ def create
4
+ @content_file = ContentFile.new(params[:content_file])
5
+ @content_file.save!
6
+
7
+ render :text => "#{@content_file.attachment.url},#{@content_file.attachment_file_name}"
8
+ end
9
+
10
+ end
@@ -0,0 +1,10 @@
1
+ class ContentImagesController < Spree::BaseController
2
+
3
+ def create
4
+ @content_image = ContentImage.new(params[:content_image])
5
+ @content_image.save!
6
+
7
+ render :text => @content_image.attachment.url
8
+ end
9
+
10
+ end
@@ -0,0 +1,5 @@
1
+ class ContentFile < Asset
2
+ has_attached_file :attachment,
3
+ :url => "/assets/content_files/:id/:basename.:extension",
4
+ :path => ":rails_root/public/assets/content_files/:id/:basename.:extension"
5
+ end
@@ -0,0 +1,7 @@
1
+ class ContentImage < Image
2
+ has_attached_file :attachment,
3
+ :styles => {:mini => '48x48#', :large => '600x600>'},
4
+ :default_style => :large,
5
+ :url => "/assets/content_images/:id/:style/:basename.:extension",
6
+ :path => ":rails_root/public/assets/content_images/:id/:style/:basename.:extension"
7
+ end
@@ -0,0 +1,214 @@
1
+ <% content_for :head do %>
2
+ <%= stylesheet_link_tag 'editor' %>
3
+ <% end %>
4
+
5
+ <div class="editor-mask-container">
6
+ <div class="editor-mask"></div
7
+ <div class="editor-mask-label"><%= t("editor.loading") %></div
8
+ </div>
9
+
10
+ <!-- Skin CSS file -->
11
+ <link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.2r1/build/assets/skins/sam/skin.css">
12
+ <!-- Utility Dependencies -->
13
+ <script src="http://yui.yahooapis.com/2.8.2r1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
14
+ <script src="http://yui.yahooapis.com/2.8.2r1/build/element/element-min.js"></script>
15
+ <!-- Needed for Menus, Buttons and Overlays used in the Toolbar -->
16
+ <script src="http://yui.yahooapis.com/2.8.2r1/build/container/container_core-min.js"></script>
17
+ <script src="http://yui.yahooapis.com/2.8.2r1/build/menu/menu-min.js"></script>
18
+ <script src="http://yui.yahooapis.com/2.8.2r1/build/button/button-min.js"></script>
19
+ <!-- Source file for Rich Text Editor-->
20
+ <script src="http://yui.yahooapis.com/2.8.2r1/build/editor/editor-min.js"></script>
21
+
22
+ <%= javascript_include_tag 'jquery.ocupload' %>
23
+
24
+ <script type="text/javascript" charset="utf-8">
25
+ var <%= editor_id %>_editor = new YAHOO.widget.Editor('<%= editor_id %>', {
26
+ height: '350px',
27
+ width: '790px',
28
+ animate: true,
29
+ handleSubmit: true,
30
+ toolbar: {
31
+ collapse: true,
32
+ titlebar: false,
33
+ draggable: false,
34
+ buttonType: 'advanced',
35
+ buttons: [
36
+ { group: 'fontstyle', label: '<%= t("editor.font_name_and_size") %>',
37
+ buttons: [
38
+ { type: 'select', label: 'Arial', value: 'fontname', disabled: true,
39
+ menu: [
40
+ { text: 'Arial', checked: true },
41
+ { text: 'Arial Black' },
42
+ { text: 'Comic Sans MS' },
43
+ { text: 'Courier New' },
44
+ { text: 'Lucida Console' },
45
+ { text: 'Tahoma' },
46
+ { text: 'Times New Roman' },
47
+ { text: 'Trebuchet MS' },
48
+ { text: 'Verdana' }
49
+ ]
50
+ },
51
+ { type: 'spin', label: '13', value: 'fontsize', range: [ 9, 75 ], disabled: true }
52
+ ]
53
+ },
54
+ { type: 'separator' },
55
+ { group: 'textstyle', label: '<%= t("editor.font_style") %>',
56
+ buttons: [
57
+ { type: 'push', label: 'Bold CTRL + SHIFT + B', value: 'bold' },
58
+ { type: 'push', label: 'Italic CTRL + SHIFT + I', value: 'italic' },
59
+ { type: 'push', label: 'Underline CTRL + SHIFT + U', value: 'underline' },
60
+ { type: 'separator' },
61
+ { type: 'push', label: 'Subscript', value: 'subscript', disabled: true },
62
+ { type: 'push', label: 'Superscript', value: 'superscript', disabled: true },
63
+ { type: 'separator' },
64
+ { type: 'color', label: 'Font Color', value: 'forecolor', disabled: true },
65
+ { type: 'color', label: 'Background Color', value: 'backcolor', disabled: true },
66
+ { type: 'separator' },
67
+ { type: 'push', label: 'Remove Formatting', value: 'removeformat', disabled: true },
68
+ { type: 'push', label: 'Show/Hide Hidden Elements', value: 'hiddenelements' }
69
+ ]
70
+ },
71
+ { type: 'separator' },
72
+ { group: 'alignment', label: '<%= t("editor.alignment") %>',
73
+ buttons: [
74
+ { type: 'push', label: 'Align Left CTRL + SHIFT + [', value: 'justifyleft' },
75
+ { type: 'push', label: 'Align Center CTRL + SHIFT + |', value: 'justifycenter' },
76
+ { type: 'push', label: 'Align Right CTRL + SHIFT + ]', value: 'justifyright' },
77
+ { type: 'push', label: 'Justify', value: 'justifyfull' }
78
+ ]
79
+ },
80
+ { type: 'separator' },
81
+ { group: 'parastyle', label: '<%= t("editor.paragraph_style") %>',
82
+ buttons: [
83
+ { type: 'select', label: 'Normal', value: 'heading', disabled: true,
84
+ menu: [
85
+ { text: 'Normal', value: 'none', checked: true },
86
+ { text: 'Header 1', value: 'h1' },
87
+ { text: 'Header 2', value: 'h2' },
88
+ { text: 'Header 3', value: 'h3' },
89
+ { text: 'Header 4', value: 'h4' },
90
+ { text: 'Header 5', value: 'h5' },
91
+ { text: 'Header 6', value: 'h6' }
92
+ ]
93
+ }
94
+ ]
95
+ },
96
+ { type: 'separator' },
97
+ { group: 'indentlist', label: '<%= t("editor.indenting_and_lists") %>',
98
+ buttons: [
99
+ { type: 'push', label: 'Indent', value: 'indent', disabled: true },
100
+ { type: 'push', label: 'Outdent', value: 'outdent', disabled: true },
101
+ { type: 'push', label: 'Create an Unordered List', value: 'insertunorderedlist' },
102
+ { type: 'push', label: 'Create an Ordered List', value: 'insertorderedlist' }
103
+ ]
104
+ },
105
+ { type: 'separator' },
106
+ { group: 'insertitem', label: '<%= t("editor.insert_item") %>',
107
+ buttons: [
108
+ { type: 'push', label: 'HTML Link CTRL + SHIFT + L', value: 'createlink', disabled: true },
109
+ { type: 'push', label: '<%= t("editor.insert_image") %>', value: 'insertimage' }
110
+ ]
111
+ }
112
+ ]
113
+ }
114
+ });
115
+
116
+ <%= editor_id %>_editor.on('toolbarLoaded', function() {
117
+ var imageUploadConfig = {
118
+ type: 'push',
119
+ label: '<%= t("editor.upload_image") %>',
120
+ value: 'imageUpload'
121
+ };
122
+ <%= editor_id %>_editor.toolbar.addButtonToGroup(imageUploadConfig, 'insertitem');
123
+
124
+ var fileUploadConfig = {
125
+ type: 'push',
126
+ label: '<%= t("editor.upload_file") %>',
127
+ value: 'fileUpload'
128
+ };
129
+ <%= editor_id %>_editor.toolbar.addButtonToGroup(fileUploadConfig, 'insertitem');
130
+ });
131
+
132
+ <%= editor_id %>_editor.addListener('editorContentLoaded', function() {
133
+ $(".yui-toolbar-imageUpload").upload({
134
+ name: 'content_image[attachment]',
135
+ action: '/content_images',
136
+ enctype: 'multipart/form-data',
137
+ params: {'content_image[viewable_type]': '<%= object.class.name %>', 'content_image[viewable_id]': '<%= object.id %>'},
138
+ autoSubmit: true,
139
+ onSubmit: function() {
140
+ $(".editor-mask-container").addClass("active");
141
+ },
142
+ onComplete: function(image_src) {
143
+ var img_html = "<img src='"+image_src+"'/>";
144
+ <%= editor_id %>_editor.execCommand('inserthtml', img_html);
145
+ $(".editor-mask-container").removeClass("active");
146
+ }
147
+ });
148
+
149
+ $(".yui-toolbar-fileUpload").upload({
150
+ name: 'content_file[attachment]',
151
+ action: '/content_files',
152
+ enctype: 'multipart/form-data',
153
+ params: {'content_file[viewable_type]': '<%= object.class.name %>', 'content_file[viewable_id]': '<%= @object.id %>'},
154
+ autoSubmit: true,
155
+ onSubmit: function() {
156
+ $(".editor-mask-container").addClass("active");
157
+ },
158
+ onComplete: function(file_url_and_name) {
159
+ var file_url = file_url_and_name.split(",")[0];
160
+ var file_name_original = file_url_and_name.split(",")[1];
161
+ $(".editor-mask-container").removeClass("active");
162
+ var file_name = prompt('<%= t("editor.enter_file_name") %>', file_name_original);
163
+ var link_html = "<a href='"+file_url+"'/>"+file_name+"</a>";
164
+ <%= editor_id %>_editor.execCommand('inserthtml', link_html);
165
+ }
166
+ });
167
+ });
168
+
169
+ <%= editor_id %>_editor.render();
170
+
171
+ $("#<%= editor_id %>_switch_simple, #<%= editor_id %>_switch_rich").click(function() {
172
+ $("#<%= editor_id %>_switch_simple, #<%= editor_id %>_switch_rich").toggle();
173
+ return false;
174
+ });
175
+ $("#<%= editor_id %>_switch_simple").click(function() {
176
+ <%= editor_id %>_editor.saveHTML();
177
+
178
+ var fc = <%= editor_id %>_editor.get('element').previousSibling,
179
+ el = <%= editor_id %>_editor.get('element');
180
+
181
+ YAHOO.util.Dom.setStyle(fc, 'position', 'absolute');
182
+ YAHOO.util.Dom.setStyle(fc, 'top', '-9999px');
183
+ YAHOO.util.Dom.setStyle(fc, 'left', '-9999px');
184
+ <%= editor_id %>_editor.get('element_cont').removeClass('yui-editor-container');
185
+ YAHOO.util.Dom.setStyle(el, 'visibility', 'visible');
186
+ YAHOO.util.Dom.setStyle(el, 'top', '');
187
+ YAHOO.util.Dom.setStyle(el, 'left', '');
188
+ YAHOO.util.Dom.setStyle(el, 'position', 'static');
189
+ YAHOO.util.Dom.setStyle(el, 'width', '780px');
190
+
191
+ <%= editor_id %>_editor.set('handleSubmit', false);
192
+
193
+ return false;
194
+ });
195
+ $("#<%= editor_id %>_switch_rich").click(function() {
196
+ var fc = <%= editor_id %>_editor.get('element').previousSibling,
197
+ el = <%= editor_id %>_editor.get('element');
198
+
199
+ YAHOO.util.Dom.setStyle(fc, 'position', 'static');
200
+ YAHOO.util.Dom.setStyle(fc, 'top', '0');
201
+ YAHOO.util.Dom.setStyle(fc, 'left', '0');
202
+ YAHOO.util.Dom.setStyle(el, 'visibility', 'hidden');
203
+ YAHOO.util.Dom.setStyle(el, 'top', '-9999px');
204
+ YAHOO.util.Dom.setStyle(el, 'left', '-9999px');
205
+ YAHOO.util.Dom.setStyle(el, 'position', 'absolute');
206
+ <%= editor_id %>_editor.get('element_cont').addClass('yui-editor-container');
207
+ <%= editor_id %>_editor._setDesignMode('on');
208
+ <%= editor_id %>_editor.setEditorHTML(<%= editor_id %>_editor.get('textarea').value);
209
+
210
+ <%= editor_id %>_editor.set('handleSubmit', true);
211
+
212
+ return false;
213
+ });
214
+ </script>
@@ -0,0 +1,21 @@
1
+ ---
2
+ en:
3
+ editor:
4
+ loading: Loading
5
+ font_name_and_size: Font Name and Size
6
+ font_style: Font Style
7
+ alignment: Alignment
8
+ paragraph_style: Paragraph Style
9
+ indenting_and_lists: "Indenting/Lists"
10
+ insert_item: Insert Item
11
+ insert_image: Insert Image
12
+ upload_image: Upload Image
13
+ upload_image: Upload File
14
+ show_more_fields: Show more fields
15
+ hide_more_fields: Hide more fields
16
+ switch_simple: Switch to Simple Editor
17
+ switch_rich: Switch to Rich Editor
18
+ sidebar: Sidebar
19
+ header: Header
20
+ footer: Footer
21
+ enter_file_name: Enter file name
@@ -0,0 +1,20 @@
1
+ ru:
2
+ editor:
3
+ loading: Загружается
4
+ font_name_and_size: Шрифт и размер
5
+ font_style: Стиль
6
+ alignment: Выравнивание
7
+ paragraph_style: Стиль
8
+ indenting_and_lists: "Отступы/списки"
9
+ insert_item: Вставка
10
+ insert_image: Вставить картинки по адресу
11
+ upload_image: Загрузить картинку
12
+ upload_image: Загрузить файл
13
+ show_more_fields: Показать дополнительные поля
14
+ hide_more_fields: Скрыть дополнительные поля
15
+ switch_simple: Переключиться на простой редактор
16
+ switch_rich: Переключиться на расширенный
17
+ sidebar: Боковое меню
18
+ header: Верхнее меню
19
+ footer: Нижнее меню
20
+ enter_file_name: Введите имя файла
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+
3
+ resources :content_images, :only => [:create]
4
+ resources :content_files, :only => [:create]
5
+
6
+ end
@@ -0,0 +1,10 @@
1
+ module EditorHelper
2
+
3
+ def rich_editor(options)
4
+ options[:editor_id] = options[:id]
5
+ options.delete(:id)
6
+
7
+ render :partial => "shared/editor", :locals => options
8
+ end
9
+
10
+ end
@@ -0,0 +1,22 @@
1
+ require 'spree_core'
2
+ require 'spree_editor_hooks'
3
+ require 'helpers/editor_helper'
4
+
5
+ module SpreeEditor
6
+ class Engine < Rails::Engine
7
+
8
+ config.autoload_paths += %W(#{config.root}/lib)
9
+
10
+ def self.activate
11
+ Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
12
+ Rails.env.production? ? require(c) : load(c)
13
+ end
14
+ end
15
+
16
+ config.to_prepare &method(:activate).to_proc
17
+ end
18
+ end
19
+
20
+ ActionView::Base.class_eval do
21
+ include EditorHelper
22
+ end
@@ -0,0 +1,3 @@
1
+ class SpreeEditorHooks < Spree::ThemeSupport::HookListener
2
+ # custom hooks go here
3
+ end
@@ -0,0 +1,26 @@
1
+ namespace :spree_editor do
2
+ desc "Copies all migrations and assets (NOTE: This will be obsolete with Rails 3.1)"
3
+ task :install do
4
+ # No migrations
5
+ # Rake::Task['spree_editor:install:migrations'].invoke
6
+ Rake::Task['spree_editor:install:assets'].invoke
7
+ end
8
+
9
+ namespace :install do
10
+ desc "Copies all migrations (NOTE: This will be obsolete with Rails 3.1)"
11
+ task :migrations do
12
+ source = File.join(File.dirname(__FILE__), '..', '..', 'db')
13
+ destination = File.join(Rails.root, 'db')
14
+ Spree::FileUtilz.mirror_files(source, destination)
15
+ end
16
+
17
+ desc "Copies all assets (NOTE: This will be obsolete with Rails 3.1)"
18
+ task :assets do
19
+ source = File.join(File.dirname(__FILE__), '..', '..', 'public')
20
+ destination = File.join(Rails.root, 'public')
21
+ puts "INFO: Mirroring assets from #{source} to #{destination}"
22
+ Spree::FileUtilz.mirror_files(source, destination)
23
+ end
24
+ end
25
+
26
+ end
@@ -0,0 +1 @@
1
+ # add custom rake tasks here
Binary file
Binary file
@@ -0,0 +1,240 @@
1
+ /*
2
+ * One Click Upload - jQuery Plugin
3
+ * Copyright (c) 2008 Michael Mitchell - http://www.michaelmitchell.co.nz
4
+ */
5
+ (function($){
6
+ $.fn.upload = function(options) {
7
+ /** Merge the users options with our defaults */
8
+ options = $.extend({
9
+ name: 'file',
10
+ enctype: 'multipart/form-data',
11
+ action: '',
12
+ autoSubmit: true,
13
+ onSubmit: function() {},
14
+ onComplete: function() {},
15
+ onSelect: function() {},
16
+ params: {}
17
+ }, options);
18
+
19
+ return new $.ocupload(this, options);
20
+ },
21
+
22
+ $.ocupload = function(element, options) {
23
+ /** Fix scope problems */
24
+ var self = this;
25
+
26
+ /** A unique id so we can find our elements later */
27
+ var id = new Date().getTime().toString().substr(8);
28
+
29
+ /** Upload Iframe */
30
+ var iframe = $(
31
+ '<iframe '+
32
+ 'id="iframe'+id+'" '+
33
+ 'name="iframe'+id+'"'+
34
+ '></iframe>'
35
+ ).css({
36
+ display: 'none'
37
+ });
38
+
39
+ /** Form */
40
+ var form = $(
41
+ '<form '+
42
+ 'method="post" '+
43
+ 'enctype="'+options.enctype+'" '+
44
+ 'action="'+options.action+'" '+
45
+ 'target="iframe'+id+'"'+
46
+ '></form>'
47
+ ).css({
48
+ margin: 0,
49
+ padding: 0
50
+ });
51
+
52
+ /** File Input */
53
+ var input = $(
54
+ '<input '+
55
+ 'name="'+options.name+'" '+
56
+ 'type="file" '+
57
+ '/>'
58
+ ).css({
59
+ position: 'relative',
60
+ display: 'block',
61
+ marginLeft: -175+'px',
62
+ opacity: 0
63
+ });
64
+
65
+ /** Put everything together */
66
+ element.wrap('<div></div>'); //container
67
+ form.append(input);
68
+ element.after(form);
69
+ element.after(iframe);
70
+
71
+ /** Find the container and make it nice and snug */
72
+ var container = element.parent().css({
73
+ position: 'relative',
74
+ height: element.outerHeight()+'px',
75
+ overflow: 'hidden',
76
+ cursor: 'pointer',
77
+ margin: 0,
78
+ padding: 0
79
+ });
80
+
81
+ /** Put our file input in the right place */
82
+ input.css('marginTop', -container.height()-10+'px');
83
+
84
+ /** Move the input with the mouse to make sure it get clicked! */
85
+ container.mousemove(function(e){
86
+ input.css({
87
+ top: e.pageY-container.offset().top+'px',
88
+ left: e.pageX-container.offset().left+'px'
89
+ });
90
+ });
91
+
92
+ /** Watch for file selection */
93
+ input.change(function() {
94
+ /** Do something when a file is selected. */
95
+ self.onSelect();
96
+
97
+ /** Submit the form automaticly after selecting the file */
98
+ if(self.autoSubmit) {
99
+ self.submit();
100
+ }
101
+ });
102
+
103
+ /** Methods */
104
+ $.extend(this, {
105
+ autoSubmit: true,
106
+ onSubmit: options.onSubmit,
107
+ onComplete: options.onComplete,
108
+ onSelect: options.onSelect,
109
+
110
+ /** get filename */
111
+ filename: function() {
112
+ return input.attr('value');
113
+ },
114
+
115
+ /** get/set params */
116
+ params: function(params) {
117
+ var params = params ? params : false;
118
+
119
+ if(params) {
120
+ options.params = $.extend(options.params, params);
121
+ }
122
+ else {
123
+ return options.params;
124
+ }
125
+ },
126
+
127
+ /** get/set name */
128
+ name: function(name) {
129
+ var name = name ? name : false;
130
+
131
+ if(name) {
132
+ input.attr('name', value);
133
+ }
134
+ else {
135
+ return input.attr('name');
136
+ }
137
+ },
138
+
139
+ /** get/set action */
140
+ action: function(action) {
141
+ var action = action ? action : false;
142
+
143
+ if(action) {
144
+ form.attr('action', action);
145
+ }
146
+ else {
147
+ return form.attr('action');
148
+ }
149
+ },
150
+
151
+ /** get/set enctype */
152
+ enctype: function(enctype) {
153
+ var enctype = enctype ? enctype : false;
154
+
155
+ if(enctype) {
156
+ form.attr('enctype', enctype);
157
+ }
158
+ else {
159
+ return form.attr('enctype');
160
+ }
161
+ },
162
+
163
+ /** set options */
164
+ set: function(obj, value) {
165
+ var value = value ? value : false;
166
+
167
+ function option(action, value) {
168
+ switch(action) {
169
+ default:
170
+ throw new Error('[jQuery.ocupload.set] \''+action+'\' is an invalid option.');
171
+ break;
172
+ case 'name':
173
+ self.name(value);
174
+ break;
175
+ case 'action':
176
+ self.action(value);
177
+ break;
178
+ case 'enctype':
179
+ self.enctype(value);
180
+ break;
181
+ case 'params':
182
+ self.params(value);
183
+ break;
184
+ case 'autoSubmit':
185
+ self.autoSubmit = value;
186
+ break;
187
+ case 'onSubmit':
188
+ self.onSubmit = value;
189
+ break;
190
+ case 'onComplete':
191
+ self.onComplete = value;
192
+ break;
193
+ case 'onSelect':
194
+ self.onSelect = value;
195
+ break;
196
+ }
197
+ }
198
+
199
+ if(value) {
200
+ option(obj, value);
201
+ }
202
+ else {
203
+ $.each(obj, function(key, value) {
204
+ option(key, value);
205
+ });
206
+ }
207
+ },
208
+
209
+ /** Submit the form */
210
+ submit: function() {
211
+ /** Do something before we upload */
212
+ this.onSubmit();
213
+
214
+ /** add additional paramters before sending */
215
+ $.each(options.params, function(key, value) {
216
+ form.append($(
217
+ '<input '+
218
+ 'type="hidden" '+
219
+ 'name="'+key+'" '+
220
+ 'value="'+value+'" '+
221
+ '/>'
222
+ ));
223
+ });
224
+
225
+ /** Submit the actual form */
226
+ form.submit();
227
+
228
+ /** Do something after we are finished uploading */
229
+ iframe.unbind().load(function() {
230
+ /** Get a response from the server in plain text */
231
+ var myFrame = document.getElementById(iframe.attr('name'));
232
+ var response = $(myFrame.contentWindow.document.body).text();
233
+
234
+ /** Do something on complete */
235
+ self.onComplete(response); //done :D
236
+ });
237
+ }
238
+ });
239
+ }
240
+ })(jQuery);
@@ -0,0 +1,37 @@
1
+ .yui-editor-container A {color: black !important;}
2
+ .editor-mask-container.active .editor-mask {
3
+ background-color: black;
4
+ filter:progid:DXImageTransform.Microsoft.Alpha(opacity=30); /* IE 5.5+*/
5
+ -moz-opacity: 0.3; /* Mozilla 1.6 */
6
+ -webkit-opacity: 0.3; /* Mozilla 1.6 */
7
+ -khtml-opacity: 0.3; /* Konqueror 3.1, Safari 1.1 */
8
+ opacity: 0.3;
9
+ width: 100%;
10
+ height: 100%;
11
+ width: 100%;
12
+ z-index: 100;
13
+ position: fixed;
14
+ top: 0;
15
+ left: 0;
16
+ }
17
+ .editor-mask-container .editor-mask-label {display: none;}
18
+ .editor-mask-container.active .editor-mask-label {
19
+ background-color: black;
20
+ color: white;
21
+ font-weight: bold;
22
+ height: 25px;
23
+ left: 50%;
24
+ margin-left: -130px;
25
+ padding: 30px 50px;
26
+ position: fixed;
27
+ top: 250px;
28
+ width: 200px;
29
+ z-index: 101;
30
+ display: block !important;
31
+ }
32
+ .yui-toolbar-imageUpload {
33
+ background: url("/images/upload_image.png") no-repeat scroll 50% 50% transparent !important;
34
+ }
35
+ .yui-toolbar-fileUpload {
36
+ background: url("/images/upload_file.png") no-repeat scroll 50% 50% transparent !important;
37
+ }
@@ -0,0 +1,30 @@
1
+ # This file is copied to ~/spec when you run 'ruby script/generate rspec'
2
+ # from the project root directory.
3
+ ENV["RAILS_ENV"] ||= 'test'
4
+ require File.expand_path("../../../config/environment", __FILE__)
5
+ require 'rspec/rails'
6
+
7
+ # Requires supporting files with custom matchers and macros, etc,
8
+ # in ./support/ and its subdirectories.
9
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
10
+
11
+ RSpec.configure do |config|
12
+ # == Mock Framework
13
+ #
14
+ # If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
15
+ #
16
+ # config.mock_with :mocha
17
+ # config.mock_with :flexmock
18
+ # config.mock_with :rr
19
+ config.mock_with :rspec
20
+
21
+ config.fixture_path = "#{::Rails.root}/spec/fixtures"
22
+
23
+ #config.include Devise::TestHelpers, :type => :controller
24
+ # If you're not using ActiveRecord, or you'd prefer not to run each of your
25
+ # examples within a transaction, comment the following line or assign false
26
+ # instead of true.
27
+ config.use_transactional_fixtures = true
28
+ end
29
+
30
+ @configuration ||= AppConfiguration.find_or_create_by_name("Default configuration")
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.platform = Gem::Platform::RUBY
3
+ s.name = 'spree_editor'
4
+ s.version = '0.30.0'
5
+ s.summary = 'Add gem summary here'
6
+ #s.description = 'Add (optional) gem description here'
7
+ s.required_ruby_version = '>= 1.8.7'
8
+
9
+ s.author = 'divineforest'
10
+ # s.email = 'david@loudthinking.com'
11
+ s.homepage = 'http://github.com/divineforest/spree_editor'
12
+ # s.rubyforge_project = 'actionmailer'
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.require_path = 'lib'
17
+ s.requirements << 'none'
18
+
19
+ s.has_rdoc = true
20
+
21
+ s.add_dependency('spree_core', '>= 0.30.0')
22
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spree_editor
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 30
8
+ - 0
9
+ version: 0.30.0
10
+ platform: ruby
11
+ authors:
12
+ - divineforest
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-01-20 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: spree_core
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ - 30
30
+ - 0
31
+ version: 0.30.0
32
+ type: :runtime
33
+ version_requirements: *id001
34
+ description:
35
+ email:
36
+ executables: []
37
+
38
+ extensions: []
39
+
40
+ extra_rdoc_files: []
41
+
42
+ files:
43
+ - .gitignore
44
+ - LICENSE
45
+ - README.md
46
+ - Rakefile
47
+ - app/controllers/content_files_controller.rb
48
+ - app/controllers/content_images_controller.rb
49
+ - app/models/content_file.rb
50
+ - app/models/content_image.rb
51
+ - app/views/shared/_editor.html.erb
52
+ - config/locales/en.yml
53
+ - config/locales/ru.yml
54
+ - config/routes.rb
55
+ - lib/helpers/editor_helper.rb
56
+ - lib/spree_editor.rb
57
+ - lib/spree_editor_hooks.rb
58
+ - lib/tasks/install.rake
59
+ - lib/tasks/spree_editor.rake
60
+ - public/images/upload_file.png
61
+ - public/images/upload_image.png
62
+ - public/javascripts/jquery.ocupload.js
63
+ - public/stylesheets/editor.css
64
+ - spec/spec_helper.rb
65
+ - spree_editor.gemspec
66
+ has_rdoc: true
67
+ homepage: http://github.com/divineforest/spree_editor
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options: []
72
+
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ segments:
80
+ - 1
81
+ - 8
82
+ - 7
83
+ version: 1.8.7
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ segments:
89
+ - 0
90
+ version: "0"
91
+ requirements:
92
+ - none
93
+ rubyforge_project:
94
+ rubygems_version: 1.3.6
95
+ signing_key:
96
+ specification_version: 3
97
+ summary: Add gem summary here
98
+ test_files: []
99
+