fullstack-ckeditor 0.1.1 → 0.1.2

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 (47) hide show
  1. data/VERSION +1 -1
  2. data/app/assets/javascripts/fullstack/ckeditor.js.coffee +64 -4
  3. data/app/controllers/ckeditor/application_controller.rb +32 -0
  4. data/app/controllers/ckeditor/attachment_files_controller.rb +23 -0
  5. data/app/controllers/ckeditor/pictures_controller.rb +23 -0
  6. data/app/models/ckeditor/asset.rb +43 -3
  7. data/app/models/ckeditor/attachment_file.rb +3 -2
  8. data/app/models/ckeditor/picture.rb +4 -1
  9. data/config/routes.rb +6 -0
  10. data/fullstack-ckeditor.gemspec +38 -2
  11. data/lib/fullstack/ckeditor/engine.rb +13 -1
  12. data/lib/generators/fullstack/ckeditor/install_generator.rb +5 -1
  13. data/{app/assets/javascripts/fullstack → lib/generators/fullstack/ckeditor/templates}/ckeditor/ckeditor.js +0 -0
  14. data/lib/generators/fullstack/ckeditor/templates/ckeditor/config.js +17 -3
  15. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_add.jpg +0 -0
  16. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_add.png +0 -0
  17. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_del.png +0 -0
  18. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_more.gif +0 -0
  19. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/preloader.gif +0 -0
  20. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/avi.gif +0 -0
  21. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/ckfnothumb.gif +0 -0
  22. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/doc.gif +0 -0
  23. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/docx.gif +0 -0
  24. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/exe.gif +0 -0
  25. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/gz.gif +0 -0
  26. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/htm.gif +0 -0
  27. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/jpg.gif +0 -0
  28. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mp3.gif +0 -0
  29. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mpg.gif +0 -0
  30. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/pdf.gif +0 -0
  31. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/psd.gif +0 -0
  32. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/rar.gif +0 -0
  33. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/swf.gif +0 -0
  34. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/tar.gif +0 -0
  35. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/txt.gif +0 -0
  36. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/unknown.gif +0 -0
  37. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/wmv.gif +0 -0
  38. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xls.gif +0 -0
  39. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xlsx.gif +0 -0
  40. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/zip.gif +0 -0
  41. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/application.js +221 -0
  42. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/fileuploader.js +1301 -0
  43. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/jquery.min.js +4 -0
  44. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/jquery.tmpl.min.js +10 -0
  45. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/rails.js +373 -0
  46. data/lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/stylesheets/uploader.css +118 -0
  47. metadata +39 -3
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -1,6 +1,66 @@
1
- #= require 'fullstack/ckeditor/ckeditor
2
-
3
1
  $(document).ready ->
4
- $( 'textarea.markup, textarea.markup-ckeditor' ).each ->
5
- CKEDITOR.replace( $(this).attr('id') );
2
+ if typeof CKEDITOR is "undefined"
3
+
4
+ window.CKEDITOR_BASEPATH = '/ckeditor/'
6
5
 
6
+ $.getScript "/ckeditor/ckeditor.js", ->
7
+
8
+ # Integrate Rails CSRF token into file upload dialogs (link, image, attachment and flash)
9
+ CKEDITOR.on "dialogDefinition", (ev) ->
10
+
11
+ # Take the dialog name and its definition from the event data.
12
+ dialogName = ev.data.name
13
+ dialogDefinition = ev.data.definition
14
+ content = undefined
15
+ upload = undefined
16
+ if CKEDITOR.tools.indexOf(["link", "image", "attachment", "flash"], dialogName) > -1
17
+ content = (dialogDefinition.getContents("Upload") or dialogDefinition.getContents("upload"))
18
+ upload = ((if not content? then null else content.get("upload")))
19
+ if upload and not upload.filebrowser["params"]?
20
+ upload.filebrowser["params"] = config.filebrowserParams()
21
+ upload.action = config.addQueryString(upload.action, upload.filebrowser["params"])
22
+
23
+
24
+ $( 'textarea.markup, textarea.markup-ckeditor' ).each ->
25
+ textarea = $(@)
26
+ id = textarea.attr('id')
27
+
28
+ config = {}
29
+ config.width = textarea.outerWidth()
30
+ config.filebrowserBrowseUrl = "/ckeditor/attachment_files"
31
+ config.filebrowserFlashBrowseUrl = "/ckeditor/attachment_files"
32
+ config.filebrowserFlashUploadUrl = "/ckeditor/attachment_files"
33
+ config.filebrowserImageBrowseLinkUrl = "/ckeditor/pictures"
34
+ config.filebrowserImageBrowseUrl = "/ckeditor/pictures"
35
+ config.filebrowserImageUploadUrl = "/ckeditor/pictures"
36
+ config.filebrowserUploadUrl = "/ckeditor/attachment_files"
37
+
38
+ config.filebrowserParams = ->
39
+ csrf_token = undefined
40
+ csrf_param = undefined
41
+ meta = undefined
42
+ metas = document.getElementsByTagName("meta")
43
+ params = new Object()
44
+ i = 0
45
+
46
+ while i < metas.length
47
+ meta = metas[i]
48
+ switch meta.name
49
+ when "csrf-token"
50
+ csrf_token = meta.content
51
+ when "csrf-param"
52
+ csrf_param = meta.content
53
+ i++
54
+ params[csrf_param] = csrf_token if csrf_param isnt `undefined` and csrf_token isnt `undefined`
55
+ params
56
+
57
+ config.addQueryString = (url, params) ->
58
+ queryString = []
59
+ unless params
60
+ return url
61
+ else
62
+ for i of params
63
+ queryString.push i + "=" + encodeURIComponent(params[i])
64
+ url + ((if (url.indexOf("?") isnt -1) then "&" else "?")) + queryString.join("&")
65
+
66
+ CKEDITOR.replace( id , config )
@@ -0,0 +1,32 @@
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
@@ -0,0 +1,23 @@
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
@@ -0,0 +1,23 @@
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,4 +1,44 @@
1
1
  class Ckeditor::Asset < ActiveRecord::Base
2
- include Ckeditor::Orm::ActiveRecord::AssetBase
3
- include Ckeditor::Backend::Paperclip
4
- end
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,7 +1,8 @@
1
1
  class Ckeditor::AttachmentFile < Ckeditor::Asset
2
+
2
3
  has_attached :data
3
-
4
- validates_attachment_size :data, :less_than => 100.megabytes
4
+
5
+ validates_attachment_size :data, :less_than => 50.megabytes
5
6
  validates_attachment_presence :data
6
7
 
7
8
  def url_thumb
@@ -1,9 +1,12 @@
1
1
  class Ckeditor::Picture < Ckeditor::Asset
2
2
  has_attached :data, :styles => { :content => '800>', :thumb => '118x100#' }
3
3
 
4
- validates_attachment_size :data, :less_than => 2.megabytes
4
+ validates_attachment_size :data, :less_than => 5.megabytes
5
5
  validates_attachment_presence :data
6
6
 
7
+ field :width
8
+ field :height
9
+
7
10
  def url_content
8
11
  url(:content)
9
12
  end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ namespace :ckeditor do
3
+ resources :pictures, :only => [:index, :create, :destroy]
4
+ resources :attachment_files, :only => [:index, :create, :destroy]
5
+ end
6
+ end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "fullstack-ckeditor"
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["mcasimir"]
@@ -22,18 +22,54 @@ Gem::Specification.new do |s|
22
22
  "Rakefile",
23
23
  "VERSION",
24
24
  "app/assets/javascripts/fullstack/ckeditor.js.coffee",
25
- "app/assets/javascripts/fullstack/ckeditor/ckeditor.js",
25
+ "app/controllers/ckeditor/application_controller.rb",
26
+ "app/controllers/ckeditor/attachment_files_controller.rb",
27
+ "app/controllers/ckeditor/pictures_controller.rb",
26
28
  "app/inputs/markup_input.rb",
27
29
  "app/models/ckeditor/asset.rb",
28
30
  "app/models/ckeditor/attachment_file.rb",
29
31
  "app/models/ckeditor/picture.rb",
32
+ "config/routes.rb",
30
33
  "fullstack-ckeditor.gemspec",
31
34
  "lib/fullstack-ckeditor.rb",
32
35
  "lib/fullstack/ckeditor.rb",
33
36
  "lib/fullstack/ckeditor/engine.rb",
34
37
  "lib/generators/fullstack/ckeditor/install_generator.rb",
38
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/ckeditor.js",
35
39
  "lib/generators/fullstack/ckeditor/templates/ckeditor/config.js",
36
40
  "lib/generators/fullstack/ckeditor/templates/ckeditor/contents.css",
41
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_add.jpg",
42
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_add.png",
43
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_del.png",
44
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/gal_more.gif",
45
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/preloader.gif",
46
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/avi.gif",
47
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/ckfnothumb.gif",
48
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/doc.gif",
49
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/docx.gif",
50
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/exe.gif",
51
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/gz.gif",
52
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/htm.gif",
53
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/jpg.gif",
54
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mp3.gif",
55
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/mpg.gif",
56
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/pdf.gif",
57
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/psd.gif",
58
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/rar.gif",
59
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/swf.gif",
60
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/tar.gif",
61
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/txt.gif",
62
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/unknown.gif",
63
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/wmv.gif",
64
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xls.gif",
65
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/xlsx.gif",
66
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/images/thumbs/zip.gif",
67
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/application.js",
68
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/fileuploader.js",
69
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/jquery.min.js",
70
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/jquery.tmpl.min.js",
71
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/javascripts/rails.js",
72
+ "lib/generators/fullstack/ckeditor/templates/ckeditor/filebrowser/stylesheets/uploader.css",
37
73
  "lib/generators/fullstack/ckeditor/templates/ckeditor/lang/af.js",
38
74
  "lib/generators/fullstack/ckeditor/templates/ckeditor/lang/ar.js",
39
75
  "lib/generators/fullstack/ckeditor/templates/ckeditor/lang/bg.js",
@@ -3,7 +3,19 @@ require 'rails'
3
3
  module Fullstack
4
4
  module Ckeditor
5
5
  class Engine < ::Rails::Engine
6
-
6
+ # initializer "fullstack-admin precompile" do |app|
7
+ # app.config.assets.precompile += Ckeditor.assets
8
+ # end
9
+ #
10
+ # initializer 'fullstack.autoload', :after => :set_autoload_paths do |app|
11
+ # Ckeditor.setup do |config|
12
+ # require "ckeditor/orm/active_record"
13
+ # end
14
+ # Ckeditor::ApplicationController.class_eval do
15
+ # before_filter :authenticate_administrator!
16
+ # end
17
+ # end
18
+
7
19
  end
8
20
  end
9
21
  end
@@ -1,12 +1,16 @@
1
1
  module Fullstack
2
2
  module Ckeditor
3
- class InstallGenerator < Rails::Generators::NamedBase
3
+ class InstallGenerator < Rails::Generators::Base
4
4
  source_root File.expand_path('../templates', __FILE__)
5
5
 
6
6
  def install_assets
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
+
10
14
  end
11
15
  end
12
16
  end
@@ -4,7 +4,21 @@
4
4
  */
5
5
 
6
6
  CKEDITOR.editorConfig = function( config ) {
7
- // Define changes to default configuration here. For example:
8
- // config.language = 'fr';
9
- // config.uiColor = '#AADC6E';
7
+
8
+ // config.language = 'it';
9
+
10
+ config.toolbar = 'Easy';
11
+ config.toolbar_Easy =
12
+ [
13
+ ['Source','-','Preview'],
14
+ ['Cut','Copy','Paste','PasteText','PasteFromWord',],
15
+ ['Undo','Redo','-','SelectAll','RemoveFormat'],
16
+ ['Styles','Format'], ['Subscript', 'Superscript', 'TextColor'], ['Maximize','-','About'], '/',
17
+ ['Bold','Italic','Underline','Strike'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote'],
18
+ ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'],
19
+ ['Link','Unlink','Anchor'], ['Image', 'Attachment', 'Flash', 'Embed'],
20
+ ['Table','HorizontalRule','Smiley','SpecialChar','PageBreak']
21
+ ];
22
+
23
+
10
24
  };
@@ -0,0 +1,221 @@
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
+ });