Skip to content

Commit

Permalink
2.5.5 Release
Browse files Browse the repository at this point in the history
  • Loading branch information
sdturner02 committed Apr 18, 2016
1 parent 04453cf commit 1fb7927
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 24 deletions.
9 changes: 9 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
Change Log
============================
### Version 2.5.5 ###
SimpleAjaxUploader.js:
* Improved drag detection to work around Firefox bug which causes `dragenter` to fire twice (https://bugzilla.mozilla.org/show_bug.cgi?id=804036)
* Set `dataTransfer.dropEffect` to `copy` during `dragover` event

Uploader.php:
* Improved filename sanitation
* Replaced instances of `array_key_exists` with the faster `isset`

### Version 2.5.4 ###
SimpleAjaxUploader.js:
* Added check for parent node inside of `ss.isVisible()` - <a href="https://github.com/LPology/Simple-Ajax-Uploader/issues/160">#160</a>
Expand Down
47 changes: 37 additions & 10 deletions SimpleAjaxUploader.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/**
* Simple Ajax Uploader
* Version 2.5.4
* Version 2.5.5
* https://github.com/LPology/Simple-Ajax-Uploader
*
* Copyright 2012-2016 LPology, LLC
Expand Down Expand Up @@ -364,6 +364,17 @@ ss.indexOf = arr.indexOf ?
return -1;
};

/**
* Removes an element from an array
*/
ss.array_delete = function( array, elem ) {
var index = ss.indexOf( array, elem );

if ( index > -1 ) {
array.splice( index, 1 );
}
};

/**
* Extract file name from path
*/
Expand Down Expand Up @@ -1854,7 +1865,7 @@ ss.DragAndDrop = {

addDropZone: function( elem ) {
var self = this,
depthCounter = 0;
collection = [];

ss.addStyles( elem, {
'zIndex': 16777271
Expand All @@ -1868,14 +1879,25 @@ ss.DragAndDrop = {
return false;
}

ss.addClass( this, self._opts.dragClass );
depthCounter++;
if ( collection.length === 0 ) {
ss.addClass( this, self._opts.dragClass );
}

if ( ss.indexOf( collection, e.target ) === -1 ) {
collection.push( e.target );
}

return false;
};

elem.ondragover = function( e ) {
e.stopPropagation();
e.preventDefault();

if ( self._dragFileCheck( e ) ) {
e.dataTransfer.dropEffect = 'copy';
}

return false;
};

Expand All @@ -1884,20 +1906,25 @@ ss.DragAndDrop = {
return false;
};

elem.ondragleave = function() {
depthCounter--;
if ( depthCounter === 0 ){
ss.removeClass( this, self._opts.dragClass );
elem.ondragleave = function( e ) {
ss.array_delete( collection, e.target );

if ( collection.length === 0 ) {
ss.removeClass( this, self._opts.dragClass );
}

return false;
};

elem.ondrop = function( e ) {
e.stopPropagation();
e.preventDefault();

ss.removeClass( this, self._opts.dragClass );
depthCounter = 0;
ss.array_delete( collection, e.target );

if ( collection.length === 0 ) {
ss.removeClass( this, self._opts.dragClass );
}

if ( !self._dragFileCheck( e ) ) {
return;
Expand Down
4 changes: 2 additions & 2 deletions SimpleAjaxUploader.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "simple-ajax-uploader",
"description": "A Javascript plugin for cross-browser Ajax file uploading. Supports drag and drop, CORS, and multiple file uploading with progress bars. Works in IE7-9, mobile, and all modern browsers.",
"version": "2.5.4",
"version": "2.5.5",
"main": "SimpleAjaxUploader.js",
"keywords": [
"ajax",
Expand Down
29 changes: 22 additions & 7 deletions extras/Uploader.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Simple Ajax Uploader
* Version 2.5.4
* Version 2.5.5
* https://github.com/LPology/Simple-Ajax-Uploader
*
* Copyright 2012-2016 LPology, LLC
Expand Down Expand Up @@ -57,17 +57,32 @@ function __construct($uploadName = null) {
}

if ($this->fileName) {
$this->fileName = $this->sanitizeFilename($this->fileName);
$pathinfo = pathinfo($this->fileName);

if (array_key_exists('extension', $pathinfo) &&
array_key_exists('filename', $pathinfo))
if (isset($pathinfo['extension']) &&
isset($pathinfo['filename']))
{
$this->fileExtension = strtolower($pathinfo['extension']);
$this->fileNameWithoutExt = $pathinfo['filename'];
}
}
}

private function sanitizeFilename($name) {
$name = trim($this->basename(stripslashes($name)), ".\x00..\x20");

$this->fileName = str_replace(array('/','\\'),'_',$this->fileName);
// Use timestamp for empty filenames
if (!$name) {
$name = str_replace('.', '-', microtime(true));
}

return $name;
}

private function basename($filepath, $suffix = null) {
$splited = preg_split('/\//', rtrim($filepath, '/ '));
return substr(basename('X'.$splited[count($splited)-1], $suffix), 1);
}

public function getFileName() {
Expand Down Expand Up @@ -184,7 +199,7 @@ public function getMimeType($path) {
public function isWebImage($path) {
$pathinfo = pathinfo($path);

if (array_key_exists('extension', $pathinfo)) {
if (isset($pathinfo['extension'])) {
if (!in_array(strtolower($pathinfo['extension']), array('gif', 'png', 'jpg', 'jpeg')))
return false;
}
Expand Down Expand Up @@ -266,10 +281,10 @@ public function handleUpload($uploadDir = null, $allowedExtensions = null) {

$pathinfo = pathinfo($this->fileName);

if (array_key_exists('filename', $pathinfo))
if (isset($pathinfo['filename']))
$this->fileNameWithoutExt = $pathinfo['filename'];

if (array_key_exists('extension', $pathinfo))
if (isset($pathinfo['extension']))
$this->fileExtension = strtolower($pathinfo['extension']);
}

Expand Down
2 changes: 1 addition & 1 deletion extras/cors.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Simple Ajax Uploader
* Version 2.5.4
* Version 2.5.5
* https://github.com/LPology/Simple-Ajax-Uploader
*
* Copyright 2012-2016 LPology, LLC
Expand Down
2 changes: 1 addition & 1 deletion extras/sessionProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Simple Ajax Uploader
* Version 2.5.4
* Version 2.5.5
* https://github.com/LPology/Simple-Ajax-Uploader
*
* Copyright 2012-2016 LPology, LLC
Expand Down
2 changes: 1 addition & 1 deletion extras/uploadProgress.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

/**
* Simple Ajax Uploader
* Version 2.5.4
* Version 2.5.5
* https://github.com/LPology/Simple-Ajax-Uploader
*
* Copyright 2012-2016 LPology, LLC
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "simple-ajax-uploader",
"description": "A Javascript plugin for cross-browser Ajax file uploading. Supports drag and drop, CORS, and multiple file uploading with progress bars. Works in IE7-9, mobile, and all modern browsers.",
"version": "2.5.4",
"version": "2.5.5",
"main": "SimpleAjaxUploader.js",
"keywords": [
"ajax",
Expand Down

0 comments on commit 1fb7927

Please sign in to comment.