Commit 3398e0a3d7a1bed8efb7e700dee92f95173d8334
1 parent
31fcac9f
Exists in
spb-stable
and in
2 other branches
Revert "Implements and refactors clipboard feature for markdown."
This reverts commit 2273234653924b731f9ef01432e392481ee1d4e2. Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> Conflicts: app/views/projects/issues/_form.html.haml app/views/projects/merge_requests/_form.html.haml app/views/projects/merge_requests/_new_submit.html.haml app/views/projects/milestones/_form.html.haml app/views/projects/notes/_form.html.haml app/views/projects/wikis/_form.html.haml
Showing
9 changed files
with
25 additions
and
126 deletions
Show diff stats
app/assets/javascripts/markdown_area.js.coffee
1 | +formatLink = (str) -> | |
2 | + "" | |
3 | + | |
1 | 4 | $(document).ready -> |
2 | 5 | alertClass = "alert alert-danger alert-dismissable div-dropzone-alert" |
3 | 6 | alertAttr = "class=\"close\" data-dismiss=\"alert\"" + "aria-hidden=\"true\"" |
... | ... | @@ -10,12 +13,15 @@ $(document).ready -> |
10 | 13 | project_image_path_upload = window.project_image_path_upload or null |
11 | 14 | |
12 | 15 | $("textarea.markdown-area").wrap "<div class=\"div-dropzone\"></div>" |
16 | + | |
13 | 17 | $(".div-dropzone").parent().addClass "div-dropzone-wrapper" |
18 | + | |
14 | 19 | $(".div-dropzone").append divHover |
15 | 20 | $(".div-dropzone-hover").append iconPicture |
16 | 21 | $(".div-dropzone").append divSpinner |
17 | 22 | $(".div-dropzone-spinner").append iconSpinner |
18 | 23 | |
24 | + | |
19 | 25 | dropzone = $(".div-dropzone").dropzone( |
20 | 26 | url: project_image_path_upload |
21 | 27 | dictDefaultMessage: "" |
... | ... | @@ -30,7 +36,7 @@ $(document).ready -> |
30 | 36 | previewContainer: false |
31 | 37 | |
32 | 38 | processing: -> |
33 | - closeAlertMessage() | |
39 | + $(".div-dropzone-alert").alert "close" | |
34 | 40 | |
35 | 41 | dragover: -> |
36 | 42 | $(".div-dropzone > textarea").addClass "div-dropzone-focus" |
... | ... | @@ -49,127 +55,31 @@ $(document).ready -> |
49 | 55 | return |
50 | 56 | |
51 | 57 | success: (header, response) -> |
52 | - appendToTextArea(formatLink(response.link)) | |
58 | + child = $(dropzone[0]).children("textarea") | |
59 | + $(child).val $(child).val() + formatLink(response.link) + "\n" | |
53 | 60 | return |
54 | 61 | |
55 | 62 | error: (temp, errorMessage) -> |
56 | - showError(errorMessage) | |
63 | + checkIfMsgExists = $(".error-alert").children().length | |
64 | + if checkIfMsgExists is 0 | |
65 | + $(".error-alert").append divAlert | |
66 | + $(".div-dropzone-alert").append btnAlert + errorMessage | |
57 | 67 | return |
58 | 68 | |
59 | 69 | sending: -> |
60 | - showSpinner() | |
70 | + $(".div-dropzone-spinner").css "opacity", 0.7 | |
61 | 71 | return |
62 | 72 | |
63 | 73 | complete: -> |
64 | 74 | $(".dz-preview").remove() |
65 | 75 | $(".markdown-area").trigger "input" |
66 | - closeSpinner() | |
76 | + $(".div-dropzone-spinner").css "opacity", 0 | |
67 | 77 | return |
68 | 78 | ) |
69 | 79 | |
70 | - child = $(dropzone[0]).children("textarea") | |
71 | - | |
72 | - formatLink = (str) -> | |
73 | - "" | |
74 | - | |
75 | - handlePaste = (e) -> | |
76 | - e.preventDefault() | |
77 | - my_event = e.originalEvent | |
78 | - | |
79 | - if my_event.clipboardData and my_event.clipboardData.items | |
80 | - i = 0 | |
81 | - while i < my_event.clipboardData.items.length | |
82 | - item = my_event.clipboardData.items[i] | |
83 | - processItem(my_event, item) | |
84 | - i++ | |
85 | - | |
86 | - processItem = (e, item) -> | |
87 | - if isImage(item) | |
88 | - filename = getFilename(e) or "image.png" | |
89 | - text = "{{" + filename + "}}" | |
90 | - pasteText(text) | |
91 | - uploadFile item.getAsFile(), filename | |
92 | - else if e.clipboardData.items.length == 1 | |
93 | - text = e.clipboardData.getData("text/plain") | |
94 | - pasteText(text) | |
95 | - | |
96 | - isImage = (item) -> | |
97 | - if item | |
98 | - item.type.indexOf("image") isnt -1 | |
99 | - | |
100 | - pasteText = (text) -> | |
101 | - caretStart = $(child)[0].selectionStart | |
102 | - caretEnd = $(child)[0].selectionEnd | |
103 | - textEnd = $(child).val().length | |
104 | - | |
105 | - beforeSelection = $(child).val().substring 0, caretStart | |
106 | - afterSelection = $(child).val().substring caretEnd, textEnd | |
107 | - $(child).val beforeSelection + text + afterSelection | |
108 | - $(".markdown-area").trigger "input" | |
109 | - | |
110 | - getFilename = (e) -> | |
111 | - if window.clipboardData and window.clipboardData.getData | |
112 | - value = window.clipboardData.getData("Text") | |
113 | - else if e.clipboardData and e.clipboardData.getData | |
114 | - value = e.clipboardData.getData("text/plain") | |
115 | - | |
116 | - value = value.split("\r") | |
117 | - value.first() | |
118 | - | |
119 | - uploadFile = (item, filename) -> | |
120 | - formData = new FormData() | |
121 | - formData.append "markdown_img", item, filename | |
122 | - $.ajax | |
123 | - url: project_image_path_upload | |
124 | - type: "POST" | |
125 | - data: formData | |
126 | - dataType: "json" | |
127 | - processData: false | |
128 | - contentType: false | |
129 | - headers: | |
130 | - "X-CSRF-Token": $("meta[name=\"csrf-token\"]").attr("content") | |
131 | - | |
132 | - beforeSend: -> | |
133 | - showSpinner() | |
134 | - closeAlertMessage() | |
135 | - | |
136 | - success: (e, textStatus, response) -> | |
137 | - insertToTextArea(filename, formatLink(response.responseJSON.link)) | |
138 | - | |
139 | - error: (response) -> | |
140 | - showError(response.responseJSON.message) | |
141 | - | |
142 | - complete: -> | |
143 | - closeSpinner() | |
144 | - | |
145 | - insertToTextArea = (filename, url) -> | |
146 | - $(child).val (index, val) -> | |
147 | - val.replace("{{" + filename + "}}", url + "\n") | |
148 | - | |
149 | - appendToTextArea = (url) -> | |
150 | - $(child).val (index, val) -> | |
151 | - val + url + "\n" | |
152 | - | |
153 | - showSpinner = (e) -> | |
154 | - $(".div-dropzone-spinner").css "opacity", 0.7 | |
155 | - | |
156 | - closeSpinner = -> | |
157 | - $(".div-dropzone-spinner").css "opacity", 0 | |
158 | - | |
159 | - showError = (message) -> | |
160 | - checkIfMsgExists = $(".error-alert").children().length | |
161 | - if checkIfMsgExists is 0 | |
162 | - $(".error-alert").append divAlert | |
163 | - $(".div-dropzone-alert").append btnAlert + message | |
164 | - | |
165 | - closeAlertMessage = -> | |
166 | - $(".div-dropzone-alert").alert "close" | |
167 | - | |
168 | 80 | $(".markdown-selector").click (e) -> |
169 | 81 | e.preventDefault() |
170 | 82 | $(".div-dropzone").click() |
171 | 83 | return |
172 | 84 | |
173 | - $(".div-dropzone").on "paste", handlePaste | |
174 | - | |
175 | 85 | return |
176 | 86 | \ No newline at end of file | ... | ... |
app/assets/stylesheets/generic/markdown_area.scss
app/controllers/projects_controller.rb
... | ... | @@ -11,8 +11,6 @@ class ProjectsController < ApplicationController |
11 | 11 | layout 'navless', only: [:new, :create, :fork] |
12 | 12 | before_filter :set_title, only: [:new, :create] |
13 | 13 | |
14 | - rescue_from CarrierWave::IntegrityError, with: :invalid_file | |
15 | - | |
16 | 14 | def new |
17 | 15 | @project = Project.new |
18 | 16 | end |
... | ... | @@ -187,10 +185,6 @@ class ProjectsController < ApplicationController |
187 | 185 | %w(png jpg jpeg gif) |
188 | 186 | end |
189 | 187 | |
190 | - def invalid_file(error) | |
191 | - render json: { message: error.message }, status: :internal_server_error | |
192 | - end | |
193 | - | |
194 | 188 | def set_title |
195 | 189 | @title = 'New Project' |
196 | 190 | end | ... | ... |
app/views/projects/issues/_form.html.haml
... | ... | @@ -23,7 +23,7 @@ |
23 | 23 | = f.text_area :description, class: 'form-control js-gfm-input markdown-area', rows: 14 |
24 | 24 | .col-sm-12.hint |
25 | 25 | .pull-left Issues are parsed with #{link_to "GitLab Flavored Markdown", help_page_path("markdown", "markdown"), target: '_blank'}. |
26 | - .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping, #{link_to "selecting them", '#', class: 'markdown-selector' } or pasting from the clipboard. | |
26 | + .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping or #{link_to "selecting them", '#', class: 'markdown-selector' }. | |
27 | 27 | .clearfix |
28 | 28 | .error-alert |
29 | 29 | %hr | ... | ... |
app/views/projects/merge_requests/_form.html.haml
... | ... | @@ -25,7 +25,7 @@ |
25 | 25 | = f.text_area :description, class: "form-control js-gfm-input markdown-area", rows: 14 |
26 | 26 | .col-sm-12.hint |
27 | 27 | .pull-left Description is parsed with #{link_to "GitLab Flavored Markdown", help_page_path("markdown", "markdown"), target: '_blank'}. |
28 | - .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping, #{link_to "selecting them", '#', class: 'markdown-selector' } or pasting from the clipboard. | |
28 | + .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping or #{link_to "selecting them", '#', class: 'markdown-selector' }. | |
29 | 29 | .clearfix |
30 | 30 | .error-alert |
31 | 31 | %hr | ... | ... |
app/views/projects/merge_requests/_new_submit.html.haml
... | ... | @@ -26,7 +26,7 @@ |
26 | 26 | = f.text_area :description, class: "form-control js-gfm-input markdown-area", rows: 10 |
27 | 27 | .col-sm-12.hint |
28 | 28 | .pull-left Description is parsed with #{link_to "GitLab Flavored Markdown", help_page_path("markdown", "markdown"), target: '_blank'}. |
29 | - .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping, #{link_to "selecting them", '#', class: 'markdown-selector' } or pasting from the clipboard. | |
29 | + .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping or #{link_to "selecting them", '#', class: 'markdown-selector' }. | |
30 | 30 | .clearfix |
31 | 31 | .error-alert |
32 | 32 | .form-group |
... | ... | @@ -84,5 +84,5 @@ |
84 | 84 | $('#merge_request_assignee_id').val("#{current_user.id}").trigger("change"); |
85 | 85 | e.preventDefault(); |
86 | 86 | }); |
87 | - | |
87 | + | |
88 | 88 | window.project_image_path_upload = "#{upload_image_project_path @project}"; | ... | ... |
app/views/projects/milestones/_form.html.haml
... | ... | @@ -24,7 +24,7 @@ |
24 | 24 | = f.text_area :description, maxlength: 2000, class: "form-control markdown-area", rows: 10 |
25 | 25 | .hint |
26 | 26 | .pull-left Milestones are parsed with #{link_to "GitLab Flavored Markdown", help_page_path("markdown", "markdown"), target: '_blank'}. |
27 | - .pull-left Attach images (JPG, PNG, GIF) by dragging & dropping, #{link_to "selecting them", '#', class: 'markdown-selector' } or pasting from the clipboard. | |
27 | + .pull-left Attach images (JPG, PNG, GIF) by dragging & dropping or #{link_to "selecting them", '#', class: 'markdown-selector' }. | |
28 | 28 | .clearfix |
29 | 29 | .error-alert |
30 | 30 | .col-md-6 | ... | ... |
app/views/projects/notes/_form.html.haml
... | ... | @@ -16,10 +16,10 @@ |
16 | 16 | .note-write-holder |
17 | 17 | = f.text_area :note, size: 255, class: 'note_text js-note-text js-gfm-input markdown-area' |
18 | 18 | |
19 | - .light.clearfix.hint | |
19 | + .light.clearfix | |
20 | 20 | .pull-left Comments are parsed with #{link_to "GitLab Flavored Markdown", help_page_path("markdown", "markdown"), target: '_blank'} |
21 | - .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping, #{link_to "selecting them", '#', class: 'markdown-selector' } or pasting from the clipboard. | |
22 | - .error-alert | |
21 | + .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping or #{link_to "selecting them", '#', class: 'markdown-selector' }. | |
22 | + | |
23 | 23 | .note-preview-holder.hide |
24 | 24 | .js-note-preview |
25 | 25 | ... | ... |
app/views/projects/wikis/_form.html.haml
... | ... | @@ -25,7 +25,7 @@ |
25 | 25 | = f.text_area :content, class: 'form-control js-gfm-input markdown-area', rows: 18 |
26 | 26 | .col-sm-12.hint |
27 | 27 | .pull-left Wiki content is parsed with #{link_to "GitLab Flavored Markdown", help_page_path("markdown", "markdown"), target: '_blank'} |
28 | - .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping, #{link_to "selecting them", '#', class: 'markdown-selector' } or pasting from the clipboard. | |
28 | + .pull-right Attach images (JPG, PNG, GIF) by dragging & dropping or #{link_to "selecting them", '#', class: 'markdown-selector' }. | |
29 | 29 | .clearfix |
30 | 30 | .error-alert |
31 | 31 | .form-group |
... | ... | @@ -39,7 +39,7 @@ |
39 | 39 | - else |
40 | 40 | = f.submit 'Create page', class: "btn-create btn" |
41 | 41 | = link_to "Cancel", project_wiki_path(@project, :home), class: "btn btn-cancel" |
42 | - | |
42 | + | |
43 | 43 | :javascript |
44 | 44 | window.project_image_path_upload = "#{upload_image_project_path @project}"; |
45 | 45 | ... | ... |