proclaim 0.5.6 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/Rakefile +5 -38
- data/app/assets/config/proclaim_manifest.js +2 -0
- data/app/assets/images/{ajax_loader.gif → proclaim/ajax_loader.gif} +0 -0
- data/app/assets/javascripts/proclaim.js +7 -7
- data/app/assets/javascripts/proclaim/{comments_handler.js.coffee → comments_handler.coffee} +16 -10
- data/app/assets/javascripts/proclaim/editor.coffee +55 -0
- data/app/assets/stylesheets/{proclaim.css.scss → proclaim.scss} +7 -8
- data/app/assets/stylesheets/proclaim/{comments.css.scss → comments.scss} +0 -0
- data/app/assets/stylesheets/proclaim/{posts.css.scss → posts.scss} +60 -25
- data/app/assets/stylesheets/proclaim/{subscriptions.css.scss → subscriptions.scss} +0 -0
- data/app/controllers/proclaim/application_controller.rb +60 -56
- data/app/controllers/proclaim/comments_controller.rb +13 -42
- data/app/controllers/proclaim/posts_controller.rb +25 -57
- data/app/controllers/proclaim/subscriptions_controller.rb +3 -3
- data/app/jobs/proclaim/application_job.rb +4 -0
- data/app/mailers/proclaim/application_mailer.rb +5 -0
- data/app/mailers/proclaim/subscription_mailer.rb +19 -17
- data/app/models/proclaim/application_record.rb +5 -0
- data/app/models/proclaim/comment.rb +6 -1
- data/app/models/proclaim/post.rb +20 -28
- data/app/models/proclaim/subscription.rb +33 -11
- data/app/views/layouts/proclaim/subscription_mailer.html.erb +15 -36
- data/app/views/proclaim/comments/_comment.html.erb +7 -7
- data/app/views/proclaim/comments/_form.html.erb +7 -5
- data/app/views/proclaim/posts/_form.html.erb +34 -21
- data/app/views/proclaim/posts/show.html.erb +16 -3
- data/app/views/proclaim/subscription_mailer/welcome_email.html.erb +2 -6
- data/config/initializers/friendly_id.rb +20 -1
- data/config/routes.rb +1 -5
- data/db/migrate/20141108222616_create_proclaim_posts.rb +8 -1
- data/db/migrate/20141114235359_create_proclaim_comments.rb +1 -1
- data/db/migrate/20141115022230_create_proclaim_comment_hierarchies.rb +1 -1
- data/db/migrate/20141210234057_create_proclaim_subscriptions.rb +5 -4
- data/db/migrate/20150213015321_create_friendly_id_slugs.rb +1 -1
- data/lib/generators/proclaim/install_generator.rb +1 -1
- data/lib/generators/proclaim/templates/initialize_proclaim.rb +31 -29
- data/lib/generators/proclaim/views_generator.rb +1 -1
- data/lib/proclaim.rb +15 -15
- data/lib/proclaim/engine.rb +21 -19
- data/lib/proclaim/version.rb +1 -1
- data/vendor/assets/fonts/KaTeX_AMS-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_AMS-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_AMS-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Bold.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Bold.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Bold.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Bold.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Main-BoldItalic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Italic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Italic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Italic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Main-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Math-BoldItalic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Math-Italic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Math-Italic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Math-Italic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Bold.woff +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Italic.woff +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Script-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Script-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Script-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Size1-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Size1-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Size1-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Size2-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Size2-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Size2-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Size3-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Size3-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Size3-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Size4-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Size4-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Size4-Regular.woff2 +0 -0
- data/vendor/assets/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
- data/vendor/assets/fonts/KaTeX_Typewriter-Regular.woff +0 -0
- data/vendor/assets/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
- data/vendor/assets/javascripts/contrib/auto-render.js +339 -0
- data/vendor/assets/javascripts/contrib/auto-render.min.js +1 -0
- data/vendor/assets/javascripts/contrib/auto-render.mjs +215 -0
- data/vendor/assets/javascripts/contrib/copy-tex.css +14 -0
- data/vendor/assets/javascripts/contrib/copy-tex.js +213 -0
- data/vendor/assets/javascripts/contrib/copy-tex.min.css +1 -0
- data/vendor/assets/javascripts/contrib/copy-tex.min.js +1 -0
- data/vendor/assets/javascripts/contrib/copy-tex.mjs +85 -0
- data/vendor/assets/javascripts/contrib/mathtex-script-type.js +137 -0
- data/vendor/assets/javascripts/contrib/mathtex-script-type.min.js +1 -0
- data/vendor/assets/javascripts/contrib/mathtex-script-type.mjs +24 -0
- data/vendor/assets/javascripts/contrib/mhchem.js +3241 -0
- data/vendor/assets/javascripts/contrib/mhchem.min.js +1 -0
- data/vendor/assets/javascripts/contrib/mhchem.mjs +3109 -0
- data/vendor/assets/javascripts/katex.js +16517 -0
- data/vendor/assets/javascripts/katex.min.js +1 -0
- data/vendor/assets/javascripts/katex.mjs +16122 -0
- data/vendor/assets/javascripts/quill.core.js +8522 -0
- data/vendor/assets/javascripts/quill.js +11489 -0
- data/vendor/assets/javascripts/quill.min.js +8 -0
- data/vendor/assets/javascripts/quill.min.js.map +1 -0
- data/vendor/assets/stylesheets/katex.css +1011 -0
- data/vendor/assets/stylesheets/katex.min.css +1 -0
- data/vendor/assets/stylesheets/quill.bubble.css +952 -0
- data/vendor/assets/stylesheets/quill.core.css +397 -0
- data/vendor/assets/stylesheets/quill.snow.css +945 -0
- metadata +169 -278
- data/CHANGELOG +0 -77
- data/Gemfile +0 -14
- data/VERSION +0 -1
- data/app/assets/javascripts/proclaim/editor.js.coffee +0 -52
- data/app/assets/javascripts/proclaim/images.js.coffee +0 -3
- data/app/assets/javascripts/proclaim/subscriptions.js.coffee +0 -3
- data/app/assets/stylesheets/proclaim/images.scss +0 -3
- data/app/controllers/proclaim/images_controller.rb +0 -67
- data/app/helpers/proclaim/comments_helper.rb +0 -4
- data/app/helpers/proclaim/images_helper.rb +0 -4
- data/app/helpers/proclaim/subscriptions_helper.rb +0 -4
- data/app/models/proclaim/image.rb +0 -19
- data/app/policies/proclaim/image_policy.rb +0 -29
- data/app/uploaders/proclaim/image_uploader.rb +0 -82
- data/db/migrate/20141222224905_create_proclaim_images.rb +0 -12
- data/db/migrate/20150123115226_add_name_to_subscriptions.rb +0 -7
- data/db/migrate/20150213015850_add_slug_to_posts.rb +0 -20
- data/proclaim.gemspec +0 -51
- data/test/controllers/proclaim/comments_controller_test.rb +0 -228
- data/test/controllers/proclaim/images_controller_test.rb +0 -166
- data/test/controllers/proclaim/posts_controller_test.rb +0 -465
- data/test/controllers/proclaim/subscriptions_controller_test.rb +0 -154
- data/test/dummy/README.rdoc +0 -28
- data/test/dummy/Rakefile +0 -6
- data/test/dummy/app/assets/javascripts/application.js +0 -14
- data/test/dummy/app/assets/stylesheets/application.css +0 -16
- data/test/dummy/app/controllers/application_controller.rb +0 -15
- data/test/dummy/app/helpers/application_helper.rb +0 -28
- data/test/dummy/app/models/user.rb +0 -7
- data/test/dummy/app/views/layouts/application.html.erb +0 -16
- data/test/dummy/bin/bundle +0 -3
- data/test/dummy/bin/rails +0 -4
- data/test/dummy/bin/rake +0 -4
- data/test/dummy/config.ru +0 -4
- data/test/dummy/config/application.rb +0 -24
- data/test/dummy/config/boot.rb +0 -5
- data/test/dummy/config/database.yml +0 -25
- data/test/dummy/config/environment.rb +0 -5
- data/test/dummy/config/environments/development.rb +0 -45
- data/test/dummy/config/environments/production.rb +0 -80
- data/test/dummy/config/environments/test.rb +0 -49
- data/test/dummy/config/initializers/assets.rb +0 -8
- data/test/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/test/dummy/config/initializers/cookies_serializer.rb +0 -3
- data/test/dummy/config/initializers/filter_parameter_logging.rb +0 -4
- data/test/dummy/config/initializers/inflections.rb +0 -16
- data/test/dummy/config/initializers/mime_types.rb +0 -4
- data/test/dummy/config/initializers/session_store.rb +0 -3
- data/test/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/test/dummy/config/locales/en.yml +0 -23
- data/test/dummy/config/routes.rb +0 -5
- data/test/dummy/config/secrets.yml +0 -22
- data/test/dummy/db/migrate/20141117214323_create_users.rb +0 -10
- data/test/dummy/db/schema.rb +0 -91
- data/test/dummy/public/404.html +0 -67
- data/test/dummy/public/422.html +0 -67
- data/test/dummy/public/500.html +0 -66
- data/test/dummy/public/favicon.ico +0 -0
- data/test/factories/proclaim/comment.rb +0 -11
- data/test/factories/proclaim/image.rb +0 -6
- data/test/factories/proclaim/post.rb +0 -14
- data/test/factories/proclaim/subscription.rb +0 -14
- data/test/factories/user.rb +0 -6
- data/test/helpers/proclaim/comments_helper_test.rb +0 -6
- data/test/helpers/proclaim/posts_helper_test.rb +0 -6
- data/test/helpers/proclaim/subscriptions_helper_test.rb +0 -6
- data/test/integration/with_javascript/comment_test.rb +0 -391
- data/test/integration/with_javascript/post_form_test.rb +0 -225
- data/test/integration/with_javascript/post_show_test.rb +0 -47
- data/test/integration/with_javascript/post_subscription_test.rb +0 -302
- data/test/integration/without_javascript/blog_subscription_test.rb +0 -114
- data/test/integration/without_javascript/manage_subscriptions_test.rb +0 -37
- data/test/integration/without_javascript/post_test.rb +0 -234
- data/test/integration/without_javascript/subscription_email_test.rb +0 -95
- data/test/integration/without_javascript/unsubscribe_test.rb +0 -32
- data/test/mailers/previews/proclaim/subscription_mailer_preview.rb +0 -22
- data/test/mailers/proclaim/subscription_mailer_test.rb +0 -91
- data/test/models/proclaim/comment_test.rb +0 -41
- data/test/models/proclaim/image_test.rb +0 -70
- data/test/models/proclaim/post_test.rb +0 -193
- data/test/models/proclaim/subscription_test.rb +0 -77
- data/test/policies/application_policy_test.rb +0 -87
- data/test/policies/proclaim/comment_policy_test.rb +0 -71
- data/test/policies/proclaim/image_policy_test.rb +0 -83
- data/test/policies/proclaim/post_policy_test.rb +0 -98
- data/test/policies/proclaim/subscription_policy_test.rb +0 -103
- data/test/proclaim_test.rb +0 -7
- data/test/support/images/test.jpg +0 -0
- data/test/support/pages/posts/edit_page.rb +0 -5
- data/test/support/pages/posts/show_page.rb +0 -47
- data/test/support/wait_for_ajax.rb +0 -11
- data/test/test_helper.rb +0 -71
- data/test/unit/proclaim/new_comment_callback_test.rb +0 -62
- data/test/unit/proclaim/new_subscription_callback_test.rb +0 -62
- data/test/unit/proclaim/post_published_callback_test.rb +0 -74
- data/vendor/assets/images/link.png +0 -0
- data/vendor/assets/images/remove.png +0 -0
- data/vendor/assets/images/resize-bigger.png +0 -0
- data/vendor/assets/images/resize-smaller.png +0 -0
- data/vendor/assets/images/unlink.png +0 -0
- data/vendor/assets/javascripts/addons/medium-editor-insert-embeds.js +0 -197
- data/vendor/assets/javascripts/addons/medium-editor-insert-images.js +0 -572
- data/vendor/assets/javascripts/addons/medium-editor-insert-maps.js +0 -50
- data/vendor/assets/javascripts/addons/medium-editor-insert-plugin.js +0 -496
- data/vendor/assets/javascripts/addons/medium-editor-insert-tables.js +0 -132
- data/vendor/assets/javascripts/medium-editor-insert-plugin.all.js +0 -1415
- data/vendor/assets/stylesheets/medium-editor-insert-plugin-frontend.css.scss +0 -55
- data/vendor/assets/stylesheets/medium-editor-insert-plugin.css.scss +0 -277
@@ -1,572 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* medium-editor-insert-plugin v0.3.2 - jQuery insert plugin for MediumEditor
|
3
|
-
*
|
4
|
-
* https://github.com/orthes/medium-editor-insert-plugin
|
5
|
-
*
|
6
|
-
* Copyright (c) 2014 Pavel Linkesch (http://linkesch.sk)
|
7
|
-
* Released under the MIT license
|
8
|
-
*/
|
9
|
-
|
10
|
-
(function ($) {
|
11
|
-
|
12
|
-
$.fn.mediumInsert.registerAddon('images', {
|
13
|
-
|
14
|
-
/**
|
15
|
-
* Images default options
|
16
|
-
*/
|
17
|
-
|
18
|
-
defaults: {
|
19
|
-
/**
|
20
|
-
* Active or inactive image's drag and drop
|
21
|
-
*/
|
22
|
-
useDragAndDrop: true,
|
23
|
-
|
24
|
-
/**
|
25
|
-
* Relative path to a script that handles file uploads
|
26
|
-
*/
|
27
|
-
imagesUploadScript: 'upload.php',
|
28
|
-
|
29
|
-
/**
|
30
|
-
* Relative path to a script that handles file deleting
|
31
|
-
*/
|
32
|
-
imagesDeleteScript: 'delete.php',
|
33
|
-
|
34
|
-
/**
|
35
|
-
* Placeeholder text for inserting link
|
36
|
-
*/
|
37
|
-
urlPlaceholder: 'Paste or type a link',
|
38
|
-
|
39
|
-
/**
|
40
|
-
* Format data before sending them to server while uploading an image
|
41
|
-
*
|
42
|
-
* @param {File} file File to upload
|
43
|
-
* @return {object} formData FormData instance
|
44
|
-
*/
|
45
|
-
formatData: function (file) {
|
46
|
-
var formData = new FormData();
|
47
|
-
formData.append('file', file);
|
48
|
-
return formData;
|
49
|
-
},
|
50
|
-
|
51
|
-
/**
|
52
|
-
* Upload single file
|
53
|
-
*
|
54
|
-
* @param {element} $placeholder Placeholder to add image to
|
55
|
-
* @param {File} file File to upload
|
56
|
-
* @param {object} that Context
|
57
|
-
* @param {void}
|
58
|
-
*/
|
59
|
-
uploadFile: function ($placeholder, file, that) {
|
60
|
-
$.ajax({
|
61
|
-
type: "post",
|
62
|
-
url: that.options.imagesUploadScript,
|
63
|
-
xhr: function () {
|
64
|
-
var xhr = new XMLHttpRequest();
|
65
|
-
xhr.upload.onprogress = that.updateProgressBar;
|
66
|
-
return xhr;
|
67
|
-
},
|
68
|
-
cache: false,
|
69
|
-
contentType: false,
|
70
|
-
complete: function (jqxhr) {
|
71
|
-
that.uploadCompleted(jqxhr, $placeholder);
|
72
|
-
},
|
73
|
-
processData: false,
|
74
|
-
data: that.options.formatData(file)
|
75
|
-
});
|
76
|
-
},
|
77
|
-
|
78
|
-
/**
|
79
|
-
* Makes ajax call for deleting a file on a server
|
80
|
-
*
|
81
|
-
* @param {string} file File name
|
82
|
-
* @param {object} that Context
|
83
|
-
* @return {void}
|
84
|
-
*/
|
85
|
-
deleteFile: function (file, that) {
|
86
|
-
$.ajax({
|
87
|
-
type: "post",
|
88
|
-
url: that.options.imagesDeleteScript,
|
89
|
-
data: {
|
90
|
-
file: file
|
91
|
-
}
|
92
|
-
});
|
93
|
-
}
|
94
|
-
},
|
95
|
-
|
96
|
-
|
97
|
-
/**
|
98
|
-
* Images initial function
|
99
|
-
*
|
100
|
-
* @param {object} options Options to overide defaults
|
101
|
-
* @return {void}
|
102
|
-
*/
|
103
|
-
|
104
|
-
init: function (options) {
|
105
|
-
if (options && options.$el) {
|
106
|
-
this.$el = options.$el;
|
107
|
-
}
|
108
|
-
this.options = $.extend(this.defaults, options);
|
109
|
-
|
110
|
-
this.setImageEvents();
|
111
|
-
|
112
|
-
if (this.options.useDragAndDrop === true){
|
113
|
-
this.setDragAndDropEvents();
|
114
|
-
}
|
115
|
-
|
116
|
-
this.preparePreviousImages();
|
117
|
-
|
118
|
-
},
|
119
|
-
|
120
|
-
|
121
|
-
/**
|
122
|
-
* Returns insert button
|
123
|
-
*
|
124
|
-
* @param {string} buttonLabels
|
125
|
-
* @return {string}
|
126
|
-
*/
|
127
|
-
|
128
|
-
insertButton: function(buttonLabels){
|
129
|
-
var label = 'Img';
|
130
|
-
if (buttonLabels === 'fontawesome' || typeof buttonLabels === 'object' && !!(buttonLabels.fontawesome)) {
|
131
|
-
label = '<i class="fa fa-picture-o"></i>';
|
132
|
-
}
|
133
|
-
|
134
|
-
if (typeof buttonLabels === 'object' && buttonLabels.img) {
|
135
|
-
label = buttonLabels.img;
|
136
|
-
}
|
137
|
-
|
138
|
-
return '<button data-addon="images" data-action="add" class="medium-editor-action mediumInsert-action">'+label+'</button>';
|
139
|
-
},
|
140
|
-
|
141
|
-
/**
|
142
|
-
* Make existing images interactive
|
143
|
-
*
|
144
|
-
* @return {void}
|
145
|
-
*/
|
146
|
-
|
147
|
-
preparePreviousImages: function () {
|
148
|
-
this.$el.find('.mediumInsert-images').each(function() {
|
149
|
-
var $parent = $(this).parent();
|
150
|
-
if (!$parent.hasClass('mediumInsert-placeholder')) {
|
151
|
-
$parent.html($.fn.mediumInsert.insert.getButtons('images') +
|
152
|
-
'<div class="mediumInsert-placeholder" draggable="true">' + $parent.html() + '</div>'
|
153
|
-
);
|
154
|
-
}
|
155
|
-
});
|
156
|
-
},
|
157
|
-
|
158
|
-
/**
|
159
|
-
* Add image to placeholder
|
160
|
-
*
|
161
|
-
* @param {element} $placeholder Placeholder to add image to
|
162
|
-
* @return {element} $selectFile <input type="file"> element
|
163
|
-
*/
|
164
|
-
|
165
|
-
add: function ($placeholder) {
|
166
|
-
var that = this,
|
167
|
-
$selectFile, files;
|
168
|
-
|
169
|
-
$selectFile = $('<input type="file" multiple="multiple">').click();
|
170
|
-
$selectFile.change(function () {
|
171
|
-
files = this.files;
|
172
|
-
that.uploadFiles($placeholder, files, that);
|
173
|
-
});
|
174
|
-
|
175
|
-
$.fn.mediumInsert.insert.deselect();
|
176
|
-
|
177
|
-
return $selectFile;
|
178
|
-
},
|
179
|
-
|
180
|
-
/**
|
181
|
-
* Update progressbar while upload
|
182
|
-
*
|
183
|
-
* @param {event} e XMLHttpRequest.upload.onprogress event
|
184
|
-
* @return {void}
|
185
|
-
*/
|
186
|
-
|
187
|
-
updateProgressBar: function (e) {
|
188
|
-
var $progress = $('.progress:first', this.$el),
|
189
|
-
complete;
|
190
|
-
|
191
|
-
if (e.lengthComputable) {
|
192
|
-
complete = e.loaded / e.total * 100;
|
193
|
-
complete = complete ? complete : 0;
|
194
|
-
$progress.attr('value', complete);
|
195
|
-
$progress.html(complete);
|
196
|
-
}
|
197
|
-
},
|
198
|
-
|
199
|
-
/**
|
200
|
-
* Show uploaded image after upload completed
|
201
|
-
*
|
202
|
-
* @param {jqXHR} jqxhr jqXHR object
|
203
|
-
* @return {void}
|
204
|
-
*/
|
205
|
-
|
206
|
-
uploadCompleted: function (jqxhr, $placeholder) {
|
207
|
-
var $progress = $('.progress:first', $placeholder),
|
208
|
-
$img;
|
209
|
-
|
210
|
-
$progress.attr('value', 100);
|
211
|
-
$progress.html(100);
|
212
|
-
|
213
|
-
if (jqxhr.responseText) {
|
214
|
-
$progress.before('<figure class="mediumInsert-images"><img src="'+ jqxhr.responseText +'" draggable="true" alt=""></figure>');
|
215
|
-
$img = $progress.siblings('img');
|
216
|
-
|
217
|
-
$img.load(function () {
|
218
|
-
$img.parent().mouseleave().mouseenter();
|
219
|
-
});
|
220
|
-
} else {
|
221
|
-
$progress.before('<div class="mediumInsert-error">There was a problem uploading the file.</div>');
|
222
|
-
|
223
|
-
setTimeout(function () {
|
224
|
-
$('.mediumInsert-error:first', $placeholder).fadeOut(function () {
|
225
|
-
$(this).remove();
|
226
|
-
});
|
227
|
-
}, 3000);
|
228
|
-
}
|
229
|
-
|
230
|
-
$progress.remove();
|
231
|
-
|
232
|
-
$placeholder.closest('[data-medium-element]').trigger('keyup').trigger('input');
|
233
|
-
},
|
234
|
-
|
235
|
-
/**
|
236
|
-
* Upload single file
|
237
|
-
*
|
238
|
-
* @param {element} $placeholder Placeholder to add image to
|
239
|
-
* @param {File} file File to upload
|
240
|
-
* @param {object} that Context
|
241
|
-
* @param {void}
|
242
|
-
*/
|
243
|
-
|
244
|
-
uploadFile: function ($placeholder, file, that) {
|
245
|
-
return that.options.uploadFile($placeholder, file, that);
|
246
|
-
},
|
247
|
-
|
248
|
-
/**
|
249
|
-
* Lopp though files, check file types and call uploadFile() function on each file that passes
|
250
|
-
*
|
251
|
-
* @param {element} placeholder Placeholder to add image to
|
252
|
-
* @param {FileList} files Files to upload
|
253
|
-
* @param {object} that Context
|
254
|
-
* @return {void}
|
255
|
-
*/
|
256
|
-
|
257
|
-
uploadFiles: function ($placeholder, files, that) {
|
258
|
-
var acceptedTypes = {
|
259
|
-
'image/png': true,
|
260
|
-
'image/jpeg': true,
|
261
|
-
'image/gif': true
|
262
|
-
};
|
263
|
-
|
264
|
-
for (var i = 0; i < files.length; i++) {
|
265
|
-
var file = files[i];
|
266
|
-
|
267
|
-
if (acceptedTypes[file.type] === true) {
|
268
|
-
$placeholder.append('<progress class="progress" min="0" max="100" value="0">0</progress>');
|
269
|
-
|
270
|
-
that.uploadFile($placeholder, file, that);
|
271
|
-
}
|
272
|
-
}
|
273
|
-
},
|
274
|
-
|
275
|
-
/**
|
276
|
-
* Makes ajax call for deleting a file on a server
|
277
|
-
*
|
278
|
-
* @param {string} file File name
|
279
|
-
* @param {object} that Context
|
280
|
-
* @return {void}
|
281
|
-
*/
|
282
|
-
|
283
|
-
deleteFile: function (file, that) {
|
284
|
-
return that.options.deleteFile(file, that);
|
285
|
-
},
|
286
|
-
|
287
|
-
/**
|
288
|
-
* Set image events displaying remove and resize buttons
|
289
|
-
*
|
290
|
-
* @return {void}
|
291
|
-
*/
|
292
|
-
|
293
|
-
setImageEvents: function () {
|
294
|
-
var that = this;
|
295
|
-
|
296
|
-
this.$el.on('mouseenter', '.mediumInsert-images', function () {
|
297
|
-
var $img = $('img', this),
|
298
|
-
positionTop,
|
299
|
-
positionLeft;
|
300
|
-
|
301
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
302
|
-
return;
|
303
|
-
}
|
304
|
-
|
305
|
-
if ($img.length > 0) {
|
306
|
-
$(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageRemove"></a>');
|
307
|
-
|
308
|
-
if ($(this).prevAll().length === 0) {
|
309
|
-
if ($(this).parent().parent().hasClass('small')) {
|
310
|
-
$(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageResizeBigger"></a>');
|
311
|
-
} else {
|
312
|
-
$(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageResizeSmaller"></a>');
|
313
|
-
}
|
314
|
-
}
|
315
|
-
|
316
|
-
if ($(this).siblings().length === 0) {
|
317
|
-
if ($img.parent().is('a')) {
|
318
|
-
$(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageUnlink"></a>');
|
319
|
-
} else {
|
320
|
-
$(this).append('<a class="mediumInsert-imageIcon mediumInsert-imageLink"></a>');
|
321
|
-
}
|
322
|
-
}
|
323
|
-
|
324
|
-
positionTop = $img.position().top + parseInt($img.css('margin-top'), 10);
|
325
|
-
positionLeft = $img.position().left + $img.width() -30;
|
326
|
-
$('.mediumInsert-imageRemove', this).css({
|
327
|
-
'right': 'auto',
|
328
|
-
'top': positionTop,
|
329
|
-
'left': positionLeft
|
330
|
-
});
|
331
|
-
$('.mediumInsert-imageResizeBigger, .mediumInsert-imageResizeSmaller', this).css({
|
332
|
-
'right': 'auto',
|
333
|
-
'top': positionTop,
|
334
|
-
'left': positionLeft-31
|
335
|
-
});
|
336
|
-
$('.mediumInsert-imageLink, .mediumInsert-imageUnlink', this).css({
|
337
|
-
'right': 'auto',
|
338
|
-
'top': positionTop,
|
339
|
-
'left': positionLeft-62
|
340
|
-
});
|
341
|
-
}
|
342
|
-
});
|
343
|
-
|
344
|
-
this.$el.on('mouseleave', '.mediumInsert-images', function () {
|
345
|
-
$('.mediumInsert-imageIcon', this).remove();
|
346
|
-
});
|
347
|
-
|
348
|
-
this.$el.on('click', '.mediumInsert-imageResizeSmaller', function () {
|
349
|
-
$(this).parent().parent().parent().addClass('small');
|
350
|
-
$(this).parent().mouseleave().mouseleave();
|
351
|
-
|
352
|
-
$.fn.mediumInsert.insert.deselect();
|
353
|
-
that.$el.trigger('keyup').trigger('input');
|
354
|
-
});
|
355
|
-
|
356
|
-
this.$el.on('click', '.mediumInsert-imageResizeBigger', function () {
|
357
|
-
$(this).parent().parent().parent().removeClass('small');
|
358
|
-
$(this).parent().mouseleave().mouseleave();
|
359
|
-
|
360
|
-
$.fn.mediumInsert.insert.deselect();
|
361
|
-
that.$el.trigger('keyup').trigger('input');
|
362
|
-
});
|
363
|
-
|
364
|
-
this.$el.on('click', '.mediumInsert-imageRemove', function () {
|
365
|
-
var img = $(this).siblings('img').attr('src');
|
366
|
-
|
367
|
-
if ($(this).parent().siblings().length === 0) {
|
368
|
-
$(this).parent().parent().parent().removeClass('small');
|
369
|
-
}
|
370
|
-
$(this).parent().remove();
|
371
|
-
|
372
|
-
that.deleteFile(img, that);
|
373
|
-
|
374
|
-
$.fn.mediumInsert.insert.deselect();
|
375
|
-
|
376
|
-
that.$el.trigger('keyup').trigger('input');
|
377
|
-
});
|
378
|
-
|
379
|
-
this.$el.on('click', '.mediumInsert-imageLink', function () {
|
380
|
-
var $placeholder = $(this).closest('.mediumInsert-placeholder'),
|
381
|
-
$formHtml = $('<div class="medium-editor-toolbar medium-editor-toolbar-active medium-editor-toolbar-form-anchor mediumInsert-imageLinkWire" style="display: block;"><input type="text" value="" placeholder="' + that.options.urlPlaceholder + '" class="mediumInsert-imageLinkText medium-editor-toolbar-anchor-input"></div>');
|
382
|
-
|
383
|
-
$formHtml.appendTo($placeholder);
|
384
|
-
setTimeout(function () {
|
385
|
-
$formHtml.find('input').focus();
|
386
|
-
}, 50);
|
387
|
-
|
388
|
-
$.fn.mediumInsert.insert.deselect();
|
389
|
-
});
|
390
|
-
|
391
|
-
this.$el.on('click', '.mediumInsert-imageUnlink', function () {
|
392
|
-
var $figure = $(this).closest('.mediumInsert-images');
|
393
|
-
|
394
|
-
$figure.find('img').unwrap();
|
395
|
-
|
396
|
-
$(this).removeClass('mediumInsert-imageUnlink')
|
397
|
-
.addClass('mediumInsert-imageLink');
|
398
|
-
|
399
|
-
that.$el.trigger('keyup').trigger('input');
|
400
|
-
});
|
401
|
-
|
402
|
-
this.$el
|
403
|
-
.on('keypress', '.mediumInsert-imageLinkText', function (e) {
|
404
|
-
var $placeholder = $(this).closest('.mediumInsert-placeholder');
|
405
|
-
|
406
|
-
if ((e.which && e.which === 13) || (e.keyCode && e.keyCode === 13)) {
|
407
|
-
$placeholder.find('.mediumInsert-images:first').find('img').wrap('<a href="'+ $(this).val() +'" target="_blank"></a>');
|
408
|
-
$placeholder.find('.mediumInsert-imageLink')
|
409
|
-
.removeClass('mediumInsert-imageLink')
|
410
|
-
.addClass('mediumInsert-imageUnlink');
|
411
|
-
|
412
|
-
// Workaround for "Uncaught NotFoundError: Failed to execute 'removeChild' on 'Node': The node to be removed is no longer a child of this node. Perhaps it was moved in a 'blur' event handler?"
|
413
|
-
try {
|
414
|
-
$('.mediumInsert-imageLinkWire').remove();
|
415
|
-
} catch(err) {}
|
416
|
-
|
417
|
-
that.$el.trigger('keyup').trigger('input');
|
418
|
-
}
|
419
|
-
})
|
420
|
-
.on('blur', '.mediumInsert-imageLinkText', function () {
|
421
|
-
$('.mediumInsert-imageLinkWire').remove();
|
422
|
-
})
|
423
|
-
.on('paste', '.mediumInsert-imageLinkText', function (e) {
|
424
|
-
if ($.fn.mediumInsert.insert.isFirefox && e.originalEvent.clipboardData) {
|
425
|
-
$(this).val(e.originalEvent.clipboardData.getData('text/plain'));
|
426
|
-
}
|
427
|
-
});
|
428
|
-
},
|
429
|
-
|
430
|
-
/**
|
431
|
-
* Set drag and drop events
|
432
|
-
*
|
433
|
-
* @return {void}
|
434
|
-
*/
|
435
|
-
|
436
|
-
setDragAndDropEvents: function () {
|
437
|
-
var that = this,
|
438
|
-
dropSuccessful = false,
|
439
|
-
dropSort = false,
|
440
|
-
dropSortIndex, dropSortParent;
|
441
|
-
|
442
|
-
$(document).on('dragover', 'body', function () {
|
443
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
444
|
-
return;
|
445
|
-
}
|
446
|
-
|
447
|
-
that.$el.addClass('hover');
|
448
|
-
});
|
449
|
-
|
450
|
-
$(document).on('dragend', 'body', function () {
|
451
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
452
|
-
return;
|
453
|
-
}
|
454
|
-
|
455
|
-
that.$el.removeClass('hover');
|
456
|
-
});
|
457
|
-
|
458
|
-
this.$el.on('dragover', '.mediumInsert', function () {
|
459
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
460
|
-
return;
|
461
|
-
}
|
462
|
-
|
463
|
-
$(this).addClass('hover');
|
464
|
-
$(this).attr('contenteditable', true);
|
465
|
-
});
|
466
|
-
|
467
|
-
this.$el.on('dragleave', '.mediumInsert', function () {
|
468
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
469
|
-
return;
|
470
|
-
}
|
471
|
-
|
472
|
-
$(this).removeClass('hover');
|
473
|
-
$(this).attr('contenteditable', false);
|
474
|
-
});
|
475
|
-
|
476
|
-
this.$el.on('dragstart', '.mediumInsert .mediumInsert-images img', function () {
|
477
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
478
|
-
return;
|
479
|
-
}
|
480
|
-
|
481
|
-
dropSortIndex = $(this).parent().index();
|
482
|
-
dropSortParent = $(this).parent().parent().parent().attr('id');
|
483
|
-
});
|
484
|
-
|
485
|
-
this.$el.on('dragend', '.mediumInsert .mediumInsert-images img', function (e) {
|
486
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
487
|
-
return;
|
488
|
-
}
|
489
|
-
|
490
|
-
if (dropSuccessful === true) {
|
491
|
-
if ($(e.originalEvent.target.parentNode).siblings().length === 0) {
|
492
|
-
$(e.originalEvent.target.parentNode).parent().parent().removeClass('small');
|
493
|
-
}
|
494
|
-
$(e.originalEvent.target.parentNode).mouseleave();
|
495
|
-
$(e.originalEvent.target.parentNode).remove();
|
496
|
-
dropSuccessful = false;
|
497
|
-
dropSort = false;
|
498
|
-
|
499
|
-
that.$el.trigger('keyup').trigger('input');
|
500
|
-
}
|
501
|
-
});
|
502
|
-
|
503
|
-
this.$el.on('dragover', '.mediumInsert .mediumInsert-images img', function (e) {
|
504
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
505
|
-
return;
|
506
|
-
}
|
507
|
-
|
508
|
-
e.preventDefault();
|
509
|
-
});
|
510
|
-
|
511
|
-
this.$el.on('drop', '.mediumInsert .mediumInsert-images img', function () {
|
512
|
-
var index, $dragged, finalIndex;
|
513
|
-
|
514
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
515
|
-
return;
|
516
|
-
}
|
517
|
-
|
518
|
-
|
519
|
-
if (dropSortParent !== $(this).parent().parent().parent().attr('id')) {
|
520
|
-
dropSort = false;
|
521
|
-
dropSortIndex = dropSortParent = null;
|
522
|
-
return;
|
523
|
-
}
|
524
|
-
|
525
|
-
index = parseInt(dropSortIndex, 10);
|
526
|
-
|
527
|
-
// Sort
|
528
|
-
$dragged = $(this).parent().parent().find('.mediumInsert-images:nth-child('+ (index+1) +')');
|
529
|
-
finalIndex = $(this).parent().index();
|
530
|
-
if(index < finalIndex) {
|
531
|
-
$dragged.insertAfter($(this).parent());
|
532
|
-
} else if(index > finalIndex) {
|
533
|
-
$dragged.insertBefore($(this).parent());
|
534
|
-
}
|
535
|
-
|
536
|
-
$dragged.mouseleave();
|
537
|
-
|
538
|
-
dropSort = true;
|
539
|
-
dropSortIndex = null;
|
540
|
-
|
541
|
-
that.$el.trigger('keyup').trigger('input');
|
542
|
-
});
|
543
|
-
|
544
|
-
this.$el.on('drop', '.mediumInsert', function (e) {
|
545
|
-
var files;
|
546
|
-
|
547
|
-
e.preventDefault();
|
548
|
-
|
549
|
-
if ($.fn.mediumInsert.settings.enabled === false) {
|
550
|
-
return;
|
551
|
-
}
|
552
|
-
|
553
|
-
$(this).removeClass('hover');
|
554
|
-
that.$el.removeClass('hover');
|
555
|
-
$(this).attr('contenteditable', false);
|
556
|
-
|
557
|
-
files = e.originalEvent.dataTransfer.files;
|
558
|
-
if (files.length > 0) {
|
559
|
-
// File upload
|
560
|
-
that.uploadFiles($('.mediumInsert-placeholder', this), files, that);
|
561
|
-
} else if (dropSort === true) {
|
562
|
-
dropSort = false;
|
563
|
-
} else {
|
564
|
-
// Image move from block to block
|
565
|
-
$('.mediumInsert-placeholder', this).append('<figure class="mediumInsert-images">'+ e.originalEvent.dataTransfer.getData('text/html') +'</figure>');
|
566
|
-
$('meta', this).remove();
|
567
|
-
dropSuccessful = true;
|
568
|
-
}
|
569
|
-
});
|
570
|
-
}
|
571
|
-
});
|
572
|
-
}(jQuery));
|