fullstack-ckeditor 0.1.2 → 0.1.3

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.
Files changed (69) hide show
  1. data/TODO.tasks +14 -0
  2. data/VERSION +1 -1
  3. data/app/assets/javascripts/fullstack/ckeditor.js.coffee +8 -55
  4. data/app/controllers/admin/ckeditor/assets_controller.rb +49 -0
  5. data/app/controllers/admin/ckeditor/attachments_controller.rb +11 -0
  6. data/app/controllers/admin/ckeditor/pictures_controller.rb +10 -0
  7. data/app/views/admin/ckeditor/attachments/index.html.erb +15 -0
  8. data/app/views/admin/ckeditor/pictures/_picture.html.erb +25 -0
  9. data/app/views/admin/ckeditor/pictures/create.js.coffee +8 -0
  10. data/app/views/admin/ckeditor/pictures/destroy.js.coffee +6 -0
  11. data/app/views/admin/ckeditor/pictures/index.html.erb +31 -0
  12. data/config/locales/cs.ckeditor.yml +8 -0
  13. data/config/locales/de.ckeditor.yml +8 -0
  14. data/config/locales/el-GR.cdkeditor.yml +8 -0
  15. data/config/locales/en.ckeditor.yml +8 -0
  16. data/config/locales/es.ckeditor.yml +8 -0
  17. data/config/locales/fr.ckeditor.yml +8 -0
  18. data/config/locales/it.ckeditor.yml +8 -0
  19. data/config/locales/nl.ckeditor.yml +8 -0
  20. data/config/locales/pl.ckeditor.yml +8 -0
  21. data/config/locales/pt-BR.ckeditor.yml +8 -0
  22. data/config/locales/ru.ckeditor.yml +8 -0
  23. data/config/locales/sv-SE.ckeditor.yml +8 -0
  24. data/config/locales/uk.ckeditor.yml +8 -0
  25. data/config/locales/zh-CN.ckeditor.yml +8 -0
  26. data/config/routes.rb +7 -5
  27. data/fullstack-ckeditor.gemspec +25 -40
  28. data/lib/fullstack/ckeditor.rb +28 -0
  29. data/lib/generators/fullstack/ckeditor/install_generator.rb +0 -4
  30. data/lib/generators/fullstack/ckeditor/templates/ckeditor/config.js +2 -3
  31. metadata +26 -41
  32. data/app/controllers/ckeditor/application_controller.rb +0 -32
  33. data/app/controllers/ckeditor/attachment_files_controller.rb +0 -23
  34. data/app/controllers/ckeditor/pictures_controller.rb +0 -23
  35. data/app/models/ckeditor/asset.rb +0 -44
  36. data/app/models/ckeditor/attachment_file.rb +0 -11
  37. data/app/models/ckeditor/picture.rb +0 -13
  38. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_add.jpg +0 -0
  39. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_add.png +0 -0
  40. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_del.png +0 -0
  41. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_more.gif +0 -0
  42. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/preloader.gif +0 -0
  43. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/avi.gif +0 -0
  44. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/ckfnothumb.gif +0 -0
  45. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/doc.gif +0 -0
  46. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/docx.gif +0 -0
  47. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/exe.gif +0 -0
  48. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/gz.gif +0 -0
  49. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/htm.gif +0 -0
  50. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/jpg.gif +0 -0
  51. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mp3.gif +0 -0
  52. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mpg.gif +0 -0
  53. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/pdf.gif +0 -0
  54. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/psd.gif +0 -0
  55. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/rar.gif +0 -0
  56. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/swf.gif +0 -0
  57. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/tar.gif +0 -0
  58. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/txt.gif +0 -0
  59. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/unknown.gif +0 -0
  60. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/wmv.gif +0 -0
  61. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xls.gif +0 -0
  62. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xlsx.gif +0 -0
  63. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/zip.gif +0 -0
  64. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/application.js +0 -221
  65. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/fileuploader.js +0 -1301
  66. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/jquery.min.js +0 -4
  67. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/jquery.tmpl.min.js +0 -10
  68. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/rails.js +0 -373
  69. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/stylesheets/uploader.css +0 -118
@@ -1,5 +1,33 @@
1
1
  require 'fullstack/ckeditor/engine'
2
+
2
3
  module Fullstack
3
4
  module Ckeditor
5
+
6
+ mattr_accessor :picture_class
7
+ mattr_accessor :picture_attachment
8
+
9
+ @@picture_attachment = "data"
10
+
11
+ mattr_accessor :attachment_class
12
+ mattr_accessor :attachment_attachment
13
+
14
+ @@attachment_attachment = "data"
15
+
16
+ def setup
17
+ yield(self)
18
+ end
19
+ module_function :setup
20
+
21
+ def picture_uploader?
22
+ !picture_class.nil?
23
+ end
24
+ module_function :picture_uploader?
25
+
26
+ def attachment_uploader?
27
+ !attachment_class.nil?
28
+ end
29
+ module_function :attachment_uploader?
30
+
31
+
4
32
  end
5
33
  end
@@ -7,10 +7,6 @@ module Fullstack
7
7
  directory "ckeditor", Rails.root.join("public", "ckeditor")
8
8
  end
9
9
 
10
- def install_migration
11
- generate "migration:from Ckeditor::Asset Ckeditor::AttachmentFile Ckeditor::Picture"
12
- end
13
-
14
10
  end
15
11
  end
16
12
  end
@@ -10,15 +10,14 @@ CKEDITOR.editorConfig = function( config ) {
10
10
  config.toolbar = 'Easy';
11
11
  config.toolbar_Easy =
12
12
  [
13
- ['Source','-','Preview'],
13
+ ['Source'],
14
14
  ['Cut','Copy','Paste','PasteText','PasteFromWord',],
15
15
  ['Undo','Redo','-','SelectAll','RemoveFormat'],
16
- ['Styles','Format'], ['Subscript', 'Superscript', 'TextColor'], ['Maximize','-','About'], '/',
16
+ ['Styles','Format'], ['Subscript', 'Superscript', 'TextColor'], ['Maximize'], '/',
17
17
  ['Bold','Italic','Underline','Strike'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
18
18
  ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
19
19
  ['Link','Unlink','Anchor'], ['Image', 'Attachment', 'Flash', 'Embed'],
20
20
  ['Table','HorizontalRule','Smiley','SpecialChar','PageBreak']
21
21
  ];
22
22
 
23
-
24
23
  };
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fullstack-ckeditor
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-01-22 00:00:00.000000000 Z
12
+ date: 2013-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -70,15 +70,32 @@ files:
70
70
  - Gemfile.lock
71
71
  - README.md
72
72
  - Rakefile
73
+ - TODO.tasks
73
74
  - VERSION
74
75
  - app/assets/javascripts/fullstack/ckeditor.js.coffee
75
- - app/controllers/ckeditor/application_controller.rb
76
- - app/controllers/ckeditor/attachment_files_controller.rb
77
- - app/controllers/ckeditor/pictures_controller.rb
76
+ - app/controllers/admin/ckeditor/assets_controller.rb
77
+ - app/controllers/admin/ckeditor/attachments_controller.rb
78
+ - app/controllers/admin/ckeditor/pictures_controller.rb
78
79
  - app/inputs/markup_input.rb
79
- - app/models/ckeditor/asset.rb
80
- - app/models/ckeditor/attachment_file.rb
81
- - app/models/ckeditor/picture.rb
80
+ - app/views/admin/ckeditor/attachments/index.html.erb
81
+ - app/views/admin/ckeditor/pictures/_picture.html.erb
82
+ - app/views/admin/ckeditor/pictures/create.js.coffee
83
+ - app/views/admin/ckeditor/pictures/destroy.js.coffee
84
+ - app/views/admin/ckeditor/pictures/index.html.erb
85
+ - config/locales/cs.ckeditor.yml
86
+ - config/locales/de.ckeditor.yml
87
+ - config/locales/el-GR.cdkeditor.yml
88
+ - config/locales/en.ckeditor.yml
89
+ - config/locales/es.ckeditor.yml
90
+ - config/locales/fr.ckeditor.yml
91
+ - config/locales/it.ckeditor.yml
92
+ - config/locales/nl.ckeditor.yml
93
+ - config/locales/pl.ckeditor.yml
94
+ - config/locales/pt-BR.ckeditor.yml
95
+ - config/locales/ru.ckeditor.yml
96
+ - config/locales/sv-SE.ckeditor.yml
97
+ - config/locales/uk.ckeditor.yml
98
+ - config/locales/zh-CN.ckeditor.yml
82
99
  - config/routes.rb
83
100
  - fullstack-ckeditor.gemspec
84
101
  - lib/fullstack-ckeditor.rb
@@ -88,38 +105,6 @@ files:
88
105
  - lib/generators/fullstack/ckeditor/templates/ckeditor/ckeditor.js
89
106
  - lib/generators/fullstack/ckeditor/templates/ckeditor/config.js
90
107
  - lib/generators/fullstack/ckeditor/templates/ckeditor/contents.css
91
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_add.jpg
92
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_add.png
93
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_del.png
94
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_more.gif
95
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/preloader.gif
96
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/avi.gif
97
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/ckfnothumb.gif
98
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/doc.gif
99
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/docx.gif
100
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/exe.gif
101
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/gz.gif
102
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/htm.gif
103
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/jpg.gif
104
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mp3.gif
105
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mpg.gif
106
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/pdf.gif
107
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/psd.gif
108
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/rar.gif
109
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/swf.gif
110
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/tar.gif
111
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/txt.gif
112
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/unknown.gif
113
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/wmv.gif
114
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xls.gif
115
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xlsx.gif
116
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/zip.gif
117
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/application.js
118
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/fileuploader.js
119
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/jquery.min.js
120
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/jquery.tmpl.min.js
121
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/rails.js
122
- - lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/stylesheets/uploader.css
123
108
  - lib/generators/fullstack/ckeditor/templates/ckeditor/lang/af.js
124
109
  - lib/generators/fullstack/ckeditor/templates/ckeditor/lang/ar.js
125
110
  - lib/generators/fullstack/ckeditor/templates/ckeditor/lang/bg.js
@@ -372,7 +357,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
372
357
  version: '0'
373
358
  segments:
374
359
  - 0
375
- hash: 1284024409390455334
360
+ hash: 1328311174672195272
376
361
  required_rubygems_version: !ruby/object:Gem::Requirement
377
362
  none: false
378
363
  requirements:
@@ -1,32 +0,0 @@
1
- class Ckeditor::ApplicationController < ::ApplicationController
2
- respond_to :html, :json
3
-
4
- before_filter :set_locale
5
- before_filter :find_asset, :only => [:destroy]
6
- before_filter :authenticate_administrator!
7
-
8
- protected
9
-
10
- def set_locale
11
- if !params[:langCode].blank? && I18n.available_locales.include?(params[:langCode].to_sym)
12
- I18n.locale = params[:langCode]
13
- end
14
- end
15
-
16
- def respond_with_asset(asset)
17
- file = params[:CKEditor].blank? ? params[:qqfile] : params[:upload]
18
- asset.data = Ckeditor::Http.normalize_param(file, request)
19
-
20
- callback = ckeditor_before_create_asset(asset)
21
-
22
- if callback && asset.save
23
- body = params[:CKEditor].blank? ? asset.to_json(:only=>[:id, :type]) : %Q"<script type='text/javascript'>
24
- window.parent.CKEDITOR.tools.callFunction(#{params[:CKEditorFuncNum]}, '#{Ckeditor::Utils.escape_single_quotes(asset.url_content)}');
25
- </script>"
26
-
27
- render :text => body
28
- else
29
- render :nothing => true
30
- end
31
- end
32
- end
@@ -1,23 +0,0 @@
1
- class Ckeditor::AttachmentFilesController < Ckeditor::ApplicationController
2
-
3
- def index
4
- @attachments = Ckeditor.attachment_file_model.find_all(ckeditor_attachment_files_scope)
5
- respond_with(@attachments)
6
- end
7
-
8
- def create
9
- @attachment = Ckeditor::AttachmentFile.new
10
- respond_with_asset(@attachment)
11
- end
12
-
13
- def destroy
14
- @attachment.destroy
15
- respond_with(@attachment, :location => attachment_files_path)
16
- end
17
-
18
- protected
19
-
20
- def find_asset
21
- @attachment = Ckeditor.attachment_file_model.get!(params[:id])
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- class Ckeditor::PicturesController < Ckeditor::ApplicationController
2
-
3
- def index
4
- @pictures = Ckeditor.picture_model.find_all(ckeditor_pictures_scope)
5
- respond_with(@pictures)
6
- end
7
-
8
- def create
9
- @picture = Ckeditor::Picture.new
10
- respond_with_asset(@picture)
11
- end
12
-
13
- def destroy
14
- @picture.destroy
15
- respond_with(@picture, :location => pictures_path)
16
- end
17
-
18
- protected
19
-
20
- def find_asset
21
- @picture = Ckeditor.picture_model.get!(params[:id])
22
- end
23
- end
@@ -1,44 +0,0 @@
1
- class Ckeditor::Asset < ActiveRecord::Base
2
- belongs_to :assetable, :polymorphic => true
3
- inheritable
4
- timestamps
5
-
6
-
7
- def filename
8
- data_file_name
9
- end
10
-
11
- def has_dimensions?
12
- respond_to?(:width) && respond_to?(:height)
13
- end
14
-
15
- def image?
16
- Ckeditor::IMAGE_TYPES.include?(data_content_type)
17
- end
18
-
19
- def format_created_at
20
- self.created_at.strftime("%d.%m.%Y")
21
- end
22
-
23
- def url_content
24
- url
25
- end
26
-
27
- def url_thumb
28
- url(:thumb)
29
- end
30
-
31
- def as_json_methods
32
- [:url_content, :url_thumb, :size, :filename, :format_created_at]
33
- end
34
-
35
- def as_json(options = nil)
36
- options = {
37
- :methods => as_json_methods,
38
- :root => "asset"
39
- }.merge(options || {})
40
-
41
- super options
42
- end
43
-
44
- end
@@ -1,11 +0,0 @@
1
- class Ckeditor::AttachmentFile < Ckeditor::Asset
2
-
3
- has_attached :data
4
-
5
- validates_attachment_size :data, :less_than => 50.megabytes
6
- validates_attachment_presence :data
7
-
8
- def url_thumb
9
- @url_thumb ||= Ckeditor::Utils.filethumb(filename)
10
- end
11
- end
@@ -1,13 +0,0 @@
1
- class Ckeditor::Picture < Ckeditor::Asset
2
- has_attached :data, :styles => { :content => '800>', :thumb => '118x100#' }
3
-
4
- validates_attachment_size :data, :less_than => 5.megabytes
5
- validates_attachment_presence :data
6
-
7
- field :width
8
- field :height
9
-
10
- def url_content
11
- url(:content)
12
- end
13
- end
@@ -1,221 +0,0 @@
1
- $.QueryString = (function(a) {
2
- if (a == "") return {};
3
- var b = {};
4
- for (var i = 0; i < a.length; ++i)
5
- {
6
- var p=a[i].split('=');
7
- if (p.length != 2) continue;
8
- b[p[0]] = decodeURIComponent(p[1].replace(/\+/g, " "));
9
- }
10
- return b;
11
- })(window.location.search.substr(1).split('&'))
12
-
13
- $(document).ready(function(){
14
- $("div.gal-item div.gal-inner-holder")
15
- .live('mouseover', function(e){
16
- $(this).addClass('hover');
17
- })
18
- .live('mouseout', function(e){
19
- $(this).removeClass('hover');
20
- })
21
- .live('click', function(e){
22
- var url = $(this).parents('div.gal-item').data('url');
23
- CKEDITOR.tools.callFunction(CKEditorFuncNum, url);
24
- window.close();
25
- });
26
-
27
- $("div.gal-item a.gal-del").live('ajax:complete', function(xhr, status){
28
- $(this).parents('div.gal-item').remove();
29
- });
30
- });
31
-
32
- // Collection of all instances on page
33
- qq.FileUploader.instances = new Object();
34
-
35
- /**
36
- * Class that creates upload widget with drag-and-drop and file list
37
- * @inherits qq.FileUploaderBasic
38
- */
39
- qq.FileUploaderInput = function(o){
40
- // call parent constructor
41
- qq.FileUploaderBasic.apply(this, arguments);
42
-
43
- // additional options
44
- qq.extend(this._options, {
45
- element: null,
46
- // if set, will be used instead of qq-upload-list in template
47
- listElement: null,
48
-
49
- template_id: '#fileupload_tmpl',
50
-
51
- classes: {
52
- // used to get elements from templates
53
- button: 'fileupload-button',
54
- drop: 'fileupload-drop-area',
55
- dropActive: 'fileupload-drop-area-active',
56
- list: 'fileupload-list',
57
- preview: 'fileupload-preview',
58
-
59
- file: 'fileupload-file',
60
- spinner: 'fileupload-spinner',
61
- size: 'fileupload-size',
62
- cancel: 'fileupload-cancel',
63
-
64
- // added to list item when upload completes
65
- // used in css to hide progress spinner
66
- success: 'fileupload-success',
67
- fail: 'fileupload-fail'
68
- }
69
- });
70
- // overwrite options with user supplied
71
- qq.extend(this._options, o);
72
-
73
- this._element = document.getElementById(this._options.element);
74
- this._listElement = this._options.listElement || this._find(this._element, 'list');
75
-
76
- this._classes = this._options.classes;
77
-
78
- this._button = this._createUploadButton(this._find(this._element, 'button'));
79
- this._path = $('meta[name="ckeditor-path"]').attr('content');
80
-
81
- //this._setupDragDrop();
82
-
83
- qq.FileUploader.instances[this._element.id] = this;
84
- };
85
-
86
- // inherit from Basic Uploader
87
- qq.extend(qq.FileUploaderInput.prototype, qq.FileUploaderBasic.prototype);
88
-
89
- qq.extend(qq.FileUploaderInput.prototype, {
90
- /**
91
- * Gets one of the elements listed in this._options.classes
92
- **/
93
- _find: function(parent, type){
94
- var element = qq.getByClass(parent, this._options.classes[type])[0];
95
- if (!element){
96
- alert(type);
97
- throw new Error('element not found ' + type);
98
- }
99
-
100
- return element;
101
- },
102
- _setupDragDrop: function(){
103
- var self = this,
104
- dropArea = this._find(this._element, 'drop');
105
-
106
- var dz = new qq.UploadDropZone({
107
- element: dropArea,
108
- onEnter: function(e){
109
- qq.addClass(dropArea, self._classes.dropActive);
110
- e.stopPropagation();
111
- },
112
- onLeave: function(e){
113
- e.stopPropagation();
114
- },
115
- onLeaveNotDescendants: function(e){
116
- qq.removeClass(dropArea, self._classes.dropActive);
117
- },
118
- onDrop: function(e){
119
- dropArea.style.display = 'none';
120
- qq.removeClass(dropArea, self._classes.dropActive);
121
- self._uploadFileList(e.dataTransfer.files);
122
- }
123
- });
124
-
125
- dropArea.style.display = 'none';
126
-
127
- qq.attach(document, 'dragenter', function(e){
128
- if (!dz._isValidFileDrag(e)) return;
129
-
130
- dropArea.style.display = 'block';
131
- });
132
- qq.attach(document, 'dragleave', function(e){
133
- if (!dz._isValidFileDrag(e)) return;
134
-
135
- var relatedTarget = document.elementFromPoint(e.clientX, e.clientY);
136
- // only fire when leaving document out
137
- if ( ! relatedTarget || relatedTarget.nodeName == "HTML"){
138
- dropArea.style.display = 'none';
139
- }
140
- });
141
- },
142
- _onSubmit: function(id, fileName){
143
- qq.FileUploaderBasic.prototype._onSubmit.apply(this, arguments);
144
- this._addToList(id, fileName);
145
- },
146
- _onProgress: function(id, fileName, loaded, total){
147
- qq.FileUploaderBasic.prototype._onProgress.apply(this, arguments);
148
-
149
- var item = this._getItemByFileId(id);
150
- var size = this._find(item, 'size');
151
-
152
- var text;
153
- if (loaded != total){
154
- text = Math.round(loaded / total * 100) + '% from ' + this._formatSize(total);
155
- } else {
156
- text = this._formatSize(total);
157
- }
158
-
159
- qq.setText(size, text);
160
- },
161
- _onComplete: function(id, fileName, result){
162
- qq.FileUploaderBasic.prototype._onComplete.apply(this, arguments);
163
-
164
- var item = this._getItemByFileId(id);
165
- var asset = result.asset ? result.asset : result;
166
-
167
- if (asset && asset.id){
168
- qq.addClass(item, this._classes.success);
169
-
170
- asset.size = this._formatSize(asset.size);
171
- asset.controller = (asset.type.toLowerCase() == "ckeditor::picture" ? "pictures" : "attachment_files");
172
-
173
- $(item).replaceWith($(this._options.template_id).tmpl(asset));
174
- } else {
175
- qq.addClass(item, this._classes.fail);
176
- }
177
- },
178
- _addToList: function(id, fileName){
179
- if (this._listElement) {
180
- if (this._options.multiple === false) {
181
- $(this._listElement).empty();
182
- }
183
-
184
- var asset = {
185
- id: 0,
186
- filename: this._formatFileName(fileName),
187
- size: 0,
188
- format_created_at: '',
189
- url_content: "#",
190
- controller: "assets",
191
- url_thumb: this._path + "/filebrowser/images/preloader.gif"
192
- };
193
-
194
- var item = $(this._options.template_id)
195
- .tmpl(asset)
196
- .attr('qqfileid', id)
197
- .prependTo( this._listElement );
198
-
199
- item.find('div.img').addClass('preloader');
200
-
201
- this._bindCancelEvent(item);
202
- }
203
- },
204
- _getItemByFileId: function(id){
205
- return $(this._listElement).find('div[qqfileid=' + id +']').get(0);
206
- },
207
- /**
208
- * delegate click event for cancel link
209
- **/
210
- _bindCancelEvent: function(element){
211
- var self = this,
212
- item = $(element);
213
-
214
- item.find('a.' + this._classes.cancel).bind('click', function(e){
215
- self._handler.cancel( item.attr('qqfileid') );
216
- item.remove();
217
- qq.preventDefault(e);
218
- return false;
219
- });
220
- }
221
- });