Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove file button added #472

Merged
merged 8 commits into from
Jun 11, 2020
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions dist/PublicLab.Editor.css
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,27 @@
clear: left;
}

.thumbnailBtn:hover {
background-color: #efefef;
}

.thumbnailBtn:focus {
outline:none
}

.thumbnailBtn:active {
background-color: #d8d3d3;
}

.thumbnailBtn {
color: #000000b8;
background-color: white;
border-radius: 3px;
border: 1px solid black;
padding: 7px 14px;
font-weight: bold;
}

.ple-module-guide .ple-guide-minor p {
font-size: 12px;
}
Expand Down
3 changes: 2 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ <h1>Share</h1>
<div class="ple-module-guide col-md-3"><h2>2</h2></div>

<div class="ple-module-content col-md-9 container">
<div class="ple-drag-drop">
<div id="mainImage" class="ple-drag-drop">
Drag an image here to upload.
</div>
<div class="col-md-6 help">
Expand All @@ -140,6 +140,7 @@ <h1>Share</h1>
</div>

<p><input type="file" name="image[photo]" /></p>
<button id="removeFile" class="thumbnailBtn">Remove File</button>
<p class="ple-help">
<span class="ple-help-minor"
>Select an optional main image for your post.</span
Expand Down
42 changes: 27 additions & 15 deletions src/modules/PublicLab.MainImageModule.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports = PublicLab.MainImageModule = PublicLab.Module.extend({

init: function(_editor, options) {

var showImage = true;
var _module = this;

_module.key = 'main_image_url';
Expand Down Expand Up @@ -96,6 +97,7 @@ module.exports = PublicLab.MainImageModule = PublicLab.Module.extend({

start: function(e) {

showImage = true;
_module.el.find('.progress .progress-bar')
.attr('aria-valuenow', '0')
.css('width', '0%');
Expand All @@ -108,21 +110,22 @@ module.exports = PublicLab.MainImageModule = PublicLab.Module.extend({

done: function (e, data) {

_module.el.find('.progress .progress-bar')
.attr('aria-valuenow', '100')
.css('width', '100%');
_module.el.find('.progress').hide();
_module.dropEl.show();
_module.el.find('.progress').hide();
_module.dropEl.css('background-image', 'url("' + data.result.url + '")');

_module.value(data.result.url, data.result.id);
_module.dropEl.empty();
_editor.validate();

// primarily for testing:
if (_module.options.callback) _module.options.callback();

if (showImage) {
_module.el.find('.progress .progress-bar')
.attr('aria-valuenow', '100')
.css('width', '100%');
_module.el.find('.progress').hide();
_module.dropEl.show();
_module.el.find('.progress').hide();
_module.dropEl.css('background-image', 'url("' + data.result.url + '")');

_module.value(data.result.url, data.result.id);
_module.dropEl.empty();
_editor.validate();

// primarily for testing:
if (_module.options.callback) _module.options.callback();
}
},

// see callbacks at https://github.com/blueimp/jQuery-File-Upload/wiki/Options
Expand All @@ -139,8 +142,17 @@ module.exports = PublicLab.MainImageModule = PublicLab.Module.extend({

}


VladimirMikulic marked this conversation as resolved.
Show resolved Hide resolved
});

// Remove Image button
var mainImage = document.getElementById("mainImage");
VladimirMikulic marked this conversation as resolved.
Show resolved Hide resolved
var removeFile = document.getElementById("removeFile");
VladimirMikulic marked this conversation as resolved.
Show resolved Hide resolved
removeFile.onclick = function() {
mainImage.style.background = "white";
VladimirMikulic marked this conversation as resolved.
Show resolved Hide resolved
_module.el.find('.progress').hide();
showImage = false;
};

}

Expand Down