Skip to content

Commit

Permalink
Added .jshintrc
Browse files Browse the repository at this point in the history
- Also fixes a few JSHint warnings in files app
- Added "global" comment on top of files app to suppress warning and
  also inform devs about what globals are use
  • Loading branch information
Vincent Petry committed Jan 30, 2014
1 parent 299a828 commit d36a2ff
Show file tree
Hide file tree
Showing 11 changed files with 136 additions and 15 deletions.
28 changes: 28 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"camelCase": true,
"eqeqeq": true,
"immed": true,
"latedef": false,
"noarg": true,
"nonbsp": true,
"undef": true,
"unused": true,
"trailing": true,
"maxparams": 5,
"curly": true,
"jquery": true,
"maxlen": 80,
"indent": 4,
"browser": true,
"globals": {
"console": true,
"it": true,
"itx": true,
"expect": true,
"describe": true,
"beforeEach": true,
"afterEach": true,
"sinon": true,
"fakeServer": true
}
}
12 changes: 11 additions & 1 deletion apps/files/js/admin.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

function switchPublicFolder()
{
var publicEnable = $('#publicEnable').is(':checked');
Expand All @@ -10,7 +20,7 @@ function switchPublicFolder()
$(document).ready(function(){
switchPublicFolder(); // Execute the function after loading DOM tree
$('#publicEnable').click(function(){
switchPublicFolder(); // To get rid of onClick()
switchPublicFolder(); // To get rid of onClick()
});

$('#allowZipDownload').bind('change', function() {
Expand Down
12 changes: 12 additions & 0 deletions apps/files/js/file-upload.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,13 @@
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

/**
* The file upload code uses several hooks to interact with blueimps jQuery file upload library:
* 1. the core upload handling hooks are added when initializing the plugin,
Expand All @@ -8,6 +18,8 @@
* - TODO music upload button
*/

/* global OC, t, n */

/**
* Function that will allow us to know if Ajax uploads are supported
* @link https://github.com/New-Bamboo/example-ajax-upload/blob/master/public/index.html
Expand Down
25 changes: 20 additions & 5 deletions apps/files/js/fileactions.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

/* global OC, FileList */
/* global trashBinApp */
var FileActions = {
actions: {},
defaults: {},
Expand Down Expand Up @@ -45,8 +57,9 @@ var FileActions = {
return filteredActions;
},
getDefault: function (mime, type, permissions) {
var mimePart;
if (mime) {
var mimePart = mime.substr(0, mime.indexOf('/'));
mimePart = mime.substr(0, mime.indexOf('/'));
}
var name = false;
if (mime && FileActions.defaults[mime]) {
Expand Down Expand Up @@ -130,13 +143,14 @@ var FileActions = {
parent.parent().children().last().find('.action.delete').remove();
if (actions['Delete']) {
var img = FileActions.icons['Delete'];
var html;
if (img.call) {
img = img(file);
}
if (typeof trashBinApp !== 'undefined' && trashBinApp) {
var html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete delete-icon" />';
html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete delete-icon" />';
} else {
var html = '<a href="#" class="action delete delete-icon" />';
html = '<a href="#" class="action delete delete-icon" />';
}
var element = $(html);
element.data('action', actions['Delete']);
Expand All @@ -163,10 +177,11 @@ var FileActions = {
};

$(document).ready(function () {
var downloadScope;
if ($('#allowZipDownload').val() == 1) {
var downloadScope = 'all';
downloadScope = 'all';
} else {
var downloadScope = 'file';
downloadScope = 'file';
}

if (typeof disableDownloadActions == 'undefined' || !disableDownloadActions) {
Expand Down
17 changes: 15 additions & 2 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
var FileList={
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

/* global OC, t, n, FileList, FileActions, Files */
/* global procesSelection, dragOptions, SVGSupport, replaceSVG */
window.FileList={
useUndo:true,
postProcessList: function() {
$('#fileList tr').each(function() {
Expand Down Expand Up @@ -191,6 +203,7 @@ var FileList={
return OC.linkTo('files', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/');
},
setCurrentDir: function(targetDir, changeUrl) {
var url;
$('#dir').val(targetDir);
if (changeUrl !== false) {
if (window.history.pushState && changeUrl !== false) {
Expand Down Expand Up @@ -833,7 +846,7 @@ $(document).ready(function() {
{name: 'requesttoken', value: oc_requesttoken}
];
};
}
}

});
file_upload_start.on('fileuploadadd', function(e, data) {
Expand Down
23 changes: 18 additions & 5 deletions apps/files/js/files.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
Files={
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

/* global OC, t, n, FileList, FileActions */
/* global getURLParameter, isPublic */
var Files = {
// file space size sync
_updateStorageStatistics: function() {
Files._updateStorageStatisticsTimeout = null;
Expand Down Expand Up @@ -654,10 +666,10 @@ function procesSelection() {
var totalSize = 0;
for(var i=0; i<selectedFiles.length; i++) {
totalSize+=selectedFiles[i].size;
};
}
for(var i=0; i<selectedFolders.length; i++) {
totalSize+=selectedFolders[i].size;
};
}
$('#headerSize').text(humanFileSize(totalSize));
var selection = '';
if (selectedFolders.length > 0) {
Expand Down Expand Up @@ -769,10 +781,11 @@ Files.lazyLoadPreview = function(path, mime, ready, width, height, etag) {
}
img.src = previewURL;
});
}
};

function getUniqueName(name) {
if (FileList.findFileEl(name).exists()) {
var numMatch;
var parts=name.split('.');
var extension = "";
if (parts.length > 1) {
Expand Down Expand Up @@ -806,7 +819,7 @@ function checkTrashStatus() {

function onClickBreadcrumb(e) {
var $el = $(e.target).closest('.crumb'),
$targetDir = $el.data('dir');
$targetDir = $el.data('dir'),
isPublic = !!$('#isPublic').val();

if ($targetDir !== undefined && !isPublic) {
Expand Down
11 changes: 11 additions & 0 deletions apps/files/js/upgrade.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

/* global OC */
$(document).ready(function () {
var eventSource, total, bar = $('#progressbar');
console.log('start');
Expand Down
11 changes: 11 additions & 0 deletions apps/files/js/upload.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
/*
* Copyright (c) 2014
*
* This file is licensed under the Affero General Public License version 3
* or later.
*
* See the COPYING-README file.
*
*/

/* global OC */
function Upload(fileSelector) {
if ($.support.xhrFileUpload) {
return new XHRUpload(fileSelector.target.files);
Expand Down
3 changes: 3 additions & 0 deletions apps/files/tests/js/fileactionsSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

/* global OC, FileActions, FileList */
describe('FileActions tests', function() {
var $filesTable;
beforeEach(function() {
// init horrible parameters
var $body = $('body');
Expand Down
2 changes: 2 additions & 0 deletions apps/files/tests/js/filelistSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

/* global OC, FileList */
describe('FileList tests', function() {
beforeEach(function() {
// init horrible parameters
Expand Down
7 changes: 5 additions & 2 deletions apps/files/tests/js/filesSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/

/* global Files */
describe('Files tests', function() {
describe('File name validation', function() {
it('Validates correct file names', function() {
Expand All @@ -36,12 +38,14 @@ describe('Files tests', function() {
'und Ümläüte sind auch willkommen'
];
for ( var i = 0; i < fileNames.length; i++ ) {
var error = false;
try {
expect(Files.isFileNameValid(fileNames[i])).toEqual(true);
}
catch (e) {
fail();
error = e;
}
expect(error).toEqual(false);
}
});
it('Detects invalid file names', function() {
Expand Down Expand Up @@ -69,7 +73,6 @@ describe('Files tests', function() {
var threwException = false;
try {
Files.isFileNameValid(fileNames[i]);
fail();
}
catch (e) {
threwException = true;
Expand Down

0 comments on commit d36a2ff

Please sign in to comment.