This repository has been archived by the owner on Nov 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Added drag and drop plugin. #111
Open
malakada
wants to merge
1
commit into
master
Choose a base branch
from
feature/drag_and_drop_files
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
Copyright (C) 2014 Mojo Lingo LLC | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining | ||
a copy of this software and associated documentation files (the | ||
"Software"), to deal in the Software without restriction, including | ||
without limitation the rights to use, copy, modify, merge, publish, | ||
distribute, sublicense, and/or sell copies of the Software, and to | ||
permit persons to whom the Software is furnished to do so, subject to | ||
the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be | ||
included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# Drag and Drop | ||
|
||
A plugin for Candy Chat to allow drag and drop file uploads. | ||
|
||
Requires jquery-fileupload/basic. | ||
|
||
## Usage | ||
|
||
Include the JavaScript file: | ||
|
||
```HTML | ||
<script type="text/javascript" src="candyshop/dragdrop/dragdrop.js"></script> | ||
``` | ||
|
||
To enable this plugin, add its `init` method after you `init` Candy, but before `Candy.connect()`: | ||
|
||
```JavaScript | ||
CandyShop.DragDrop.init(); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
.message-form-dropzone { | ||
display: none; | ||
} | ||
|
||
.message-form-dropzone.show { | ||
background: palegreen; | ||
border: 2px dashed rgb(52, 167, 52); | ||
display: initial; | ||
font-weight: bold; | ||
height: 30px; | ||
line-height: 50px; | ||
margin-bottom: 5px; | ||
text-align: center; | ||
width: 100%; | ||
} | ||
|
||
.message-form-dropzone.show.in.hover { | ||
background: rgb(202, 235, 202); | ||
border-color: rgb(98, 196, 98); | ||
} | ||
|
||
.message-form-dropzone { | ||
-webkit-transition: all 0.2s ease-out; | ||
-moz-transition: all 0.2s ease-out; | ||
-ms-transition: all 0.2s ease-out; | ||
-o-transition: all 0.2s ease-out; | ||
transition: all 0.2s ease-out; | ||
opacity: 1; | ||
} | ||
|
||
.roomtype-lobby .message-form-dropzone { | ||
display: none !important; | ||
} | ||
|
||
#fileupload { | ||
display: none; | ||
} | ||
|
||
/* Style progress bar. */ | ||
.file-progress-bar { | ||
background: rgba(23, 99, 176, 0.24); | ||
height: 20px; | ||
width: 100%; | ||
} | ||
|
||
.file-progress-bar .bar { | ||
background: #1763b0; | ||
height: 100%; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
//= require jquery-fileupload/basic | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This won't work in plain JS. Move this dependency to the readme? |
||
|
||
/** File: dragdrop.js | ||
* Candy Plugin Drag and Drop | ||
* Author: Melissa Adamaitis <madamei@mojolingo.com> | ||
*/ | ||
|
||
var CandyShop = (function(self) { return self; }(CandyShop || {})); | ||
|
||
CandyShop.DragDrop = (function(self, Candy, $) { | ||
/** Object: about | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Plugins don't have this block on the dev branch. |
||
* | ||
* Contains: | ||
* (String) name - Candy Plugin Drag and Drop | ||
* (Float) version - 1.0 | ||
*/ | ||
self.about = { | ||
name: 'Candy Plugin Drag and Drop', | ||
version: '1.0' | ||
}; | ||
|
||
/** | ||
* Initializes the CreateRoom plugin with the default settings. | ||
*/ | ||
self.init = function(){ | ||
$('#fileupload').fileupload({ | ||
drop: function (e, data) { | ||
// Show that the image is loading. | ||
Candy.View.Pane.Chat.Modal.show(self.Template.loading, false, true); | ||
}, | ||
done: function (e, data) { | ||
// Put the file url in the form input area. | ||
$('.room-pane:visible .message-form input[name="message"]').val(window.location.origin + data.result.path); | ||
// On image upload completion, remove the loading modal. | ||
Candy.View.Pane.Chat.Modal.hide(); | ||
}, | ||
error: function(jqXHR, textStatus, errorThrown) { | ||
Candy.View.Pane.Chat.Modal.show(Mustache.to_html(self.Template.failedUpload, | ||
{errorMessage: errorThrown, statusCode: jqXHR.status}), true, false); | ||
}, | ||
progressall: function (e, data) { | ||
var progress = parseInt(data.loaded / data.total * 100, 10); | ||
$('.file-progress-bar .bar').css('width', progress + '%'); | ||
} | ||
}); | ||
|
||
$(Candy).on('candy:view.room.after-add', function() { | ||
// Add the dropzone. | ||
$('.message-form-wrapper').before(self.Template.dropzone); | ||
}); | ||
|
||
// Bind on dragover. | ||
$(document).bind('dragover', function (e) { | ||
var dropZone = $('.room-pane:visible .message-form-dropzone'), | ||
timeout = window.dropZoneTimeout; | ||
|
||
dropZone.addClass('show'); | ||
|
||
if (!timeout) { | ||
dropZone.addClass('in'); | ||
} else { | ||
clearTimeout(timeout); | ||
} | ||
|
||
var found = false, | ||
node = e.target; | ||
|
||
do { | ||
if (node === dropZone[0]) { | ||
found = true; | ||
break; | ||
} | ||
node = node.parentNode; | ||
} while (node !== null); | ||
|
||
if (found) { | ||
dropZone.addClass('hover'); | ||
} else { | ||
dropZone.removeClass('hover'); | ||
} | ||
|
||
window.dropZoneTimeout = setTimeout(function () { | ||
window.dropZoneTimeout = null; | ||
dropZone.removeClass('in hover show'); | ||
}, 100); | ||
}); | ||
|
||
$(document).bind('drop', function(e) { | ||
// On a successful drop, put it in the input bar. | ||
$('.room-pane:visible .message-form-dropzone').removeClass('in hover show'); | ||
}); | ||
|
||
// Prevent the default browser action. | ||
$(document).bind('drop dragover', function (e) { | ||
e.preventDefault(); | ||
}); | ||
}; | ||
|
||
self.Template = { | ||
dropzone: '<div class="message-form-dropzone"></div>', | ||
failedUpload: '<h4>File Upload Error</h4><p>{{statusCode}}: {{errorMessage}}</p>', | ||
loading: '<h4>Loading...</h4><div class="file-progress-bar"><div class="bar" style="width: 0%"></div></div>' | ||
}; | ||
|
||
return self; | ||
}(CandyShop.DragDrop || {}, Candy, jQuery)); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not necessary to include a license file in plugins. All plugins have one top-level license: https://github.com/candy-chat/candy-plugins/blob/dev/LICENSE