Permalink
Browse files

Added jslint and updated all scripts to be compatible.

  • Loading branch information...
1 parent a7be6ef commit 2307b3a27d6d7b776093d8d0297e60cb40b7a83f @spocke spocke committed Feb 15, 2010
View
@@ -2,6 +2,7 @@ bin
obj
tmp
docs
+jslint.xml
.settings
*~
*.diff
View
@@ -7,15 +7,20 @@
<path id="tasks.classpath">
<pathelement location="."/>
- <fileset dir="tools\ant">
+ <fileset dir="tools/ant">
<include name="**/*.jar"/>
+
+ <!-- Exclude jslint since it also has the Rhino API -->
+ <exclude name="**/jslint4java.jar"/>
</fileset>
</path>
+
<!-- Task definitions - register new js-build-tools ant tasks -->
<taskdef name="preprocess" classname="com.moxiecode.ant.tasks.PreProcessTask" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />
<taskdef name="yuicompress" classname="com.moxiecode.ant.tasks.YuiCompressTask" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />
<taskdef name="moxiedoc" classname="com.moxiecode.ant.tasks.MoxieDocTask" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="tasks.classpath" loaderref="tasks.classpath.loader" />
+ <taskdef name="jslint" classname="com.googlecode.jslint4java.ant.JSLintTask" classpath="tools/ant/jslint4java.jar" />
<!-- Generate JS documentation -->
<target name="moxiedoc" depends="" description="Generates HTML documentation out of js source">
@@ -32,6 +37,14 @@
</moxiedoc>
</target>
+ <target name="jslint">
+ <jslint>
+ <formatter type="plain" />
+ <formatter type="xml" destfile="jslint.xml" />
+ <fileset dir="src/javascript" includes="*.js" excludes="gears_init.js" />
+ </jslint>
+ </target>
+
<target name="build">
<!-- Concat multuple JS files together -->
<concat destfile="js/plupload.full.tmp.js">
@@ -13,7 +13,7 @@
function _(str) {
return plupload.translate(str) || str;
- };
+ }
function renderUI(id, target) {
target.html(
@@ -65,7 +65,7 @@
'<input type="hidden" id="' + id + '_count" name="' + id + '_count" value="0" />' +
'</div>'
);
- };
+ }
$.fn.pluploadQueue = function(settings) {
if (settings) {
@@ -89,20 +89,24 @@
function handleStatus(file) {
var actionClass;
- if (file.status == plupload.DONE)
+ if (file.status == plupload.DONE) {
actionClass = 'plupload_done';
+ }
- if (file.status == plupload.FAILED)
+ if (file.status == plupload.FAILED) {
actionClass = 'plupload_failed';
+ }
- if (file.status == plupload.QUEUED)
+ if (file.status == plupload.QUEUED) {
actionClass = 'plupload_delete';
+ }
- if (file.status == plupload.UPLOADING)
+ if (file.status == plupload.UPLOADING) {
actionClass = 'plupload_uploading';
+ }
$('#' + file.id).attr('class', actionClass).find('a').css('display', 'block');
- };
+ }
function updateList() {
var fileList = $('ul.plupload_filelist', target).html(''), inputCount = 0, inputHTML;
@@ -111,8 +115,9 @@
inputHTML = '';
if (file.status == plupload.DONE) {
- if (file.target_name)
+ if (file.target_name) {
inputHTML += '<input type="hidden" name="' + id + '_' + inputCount + '_tmpname" value="' + plupload.xmlEncode(file.target_name) + '" />';
+ }
inputHTML += '<input type="hidden" name="' + id + '_' + inputCount + '_name" value="' + plupload.xmlEncode(file.name) + '" />';
inputHTML += '<input type="hidden" name="' + id + '_' + inputCount + '_status" value="' + (file.status == plupload.DONE ? 'done' : 'failed') + '" />';
@@ -145,28 +150,30 @@
$('span.plupload_total_file_size', target).html(plupload.formatSize(uploader.total.size));
- if (uploader.total.queued == 0)
+ if (uploader.total.queued === 0) {
$('span.plupload_add_text', target).text(_('Add files.'));
- else
+ } else {
$('span.plupload_add_text', target).text(uploader.total.queued + ' files queued.');
+ }
- $('a.plupload_start', target).toggleClass('plupload_disabled', uploader.files.length == 0);
+ $('a.plupload_start', target).toggleClass('plupload_disabled', uploader.files.length === 0);
// Scroll to end of file list
fileList[0].scrollTop = fileList[0].scrollHeight;
updateTotalProgress();
- };
+ }
function updateTotalProgress() {
$('span.plupload_total_status', target).html(uploader.total.percent + '%');
$('div.plupload_progress_bar', target).css('width', uploader.total.percent + '%');
$('span.plupload_upload_status', target).text('Uploaded ' + uploader.total.uploaded + '/' + uploader.files.length + ' files');
// All files are uploaded
- if (uploader.total.uploaded == uploader.files.length)
+ if (uploader.total.uploaded == uploader.files.length) {
uploader.stop();
- };
+ }
+ }
// Set unique target filenames
if (uploader.settings.unique_names) {
@@ -192,8 +199,9 @@
$('#' + id + '_container').attr('title', 'Using runtime: ' + res.runtime);
$('a.plupload_start', target).click(function(e) {
- if (!$(this).hasClass('plupload_disabled'))
+ if (!$(this).hasClass('plupload_disabled')) {
uploader.start();
+ }
e.preventDefault();
});
@@ -223,8 +231,9 @@
uploader.bind('QueueChanged', updateList);
uploader.bind('StateChanged', function(up) {
- if (up.state == plupload.STOPPED)
+ if (up.state == plupload.STOPPED) {
updateList();
+ }
});
uploader.bind('FileUploaded', function(up, file) {
@@ -21,7 +21,7 @@
'</div>' +
'</div>'
);
- };
+ }
$.fn.pluploadSingle = function(settings) {
if (settings) {
@@ -72,20 +72,23 @@
});
uploader.bind("UploadProgress", function(up, file) {
- if (file.status == plupload.DONE)
+ if (file.status == plupload.DONE) {
$('.plupload_status', target).html('File uploaded.');
- else
+ } else {
$('.plupload_status', target).html('Uploading: ' + file.percent + '%');
+ }
});
uploader.bind('FileUploaded', function(up, file) {
if (file.status == plupload.DONE) {
- if (file.target_name)
+ if (file.target_name) {
target.append('<input type="hidden" name="' + id + '_tmpname" value="' + plupload.xmlEncode(file.target_name) + '" />');
+ }
target.append('<input type="hidden" name="' + id + '_name" value="' + plupload.xmlEncode(file.name) + '" />');
- } else
+ } else {
$('.plupload_file_name,.plupload_browse', target).attr('disabled', '');
+ }
});
});
@@ -42,9 +42,10 @@
}
// Any files selected fire event
- if (i)
+ if (i) {
uploader.trigger("FilesAdded", selectedFiles);
- };
+ }
+ }
// Check for browserplus object
if (browserPlus) {
@@ -55,23 +56,27 @@
{service: "FileBrowse", version: "1"}
];
- if (resize)
+ if (resize) {
services.push({service : 'ImageAlter', version : "4"});
+ }
if (res.success) {
browserPlus.require({
services : services
}, function() {
- if (res.success)
+ if (res.success) {
setup();
- else
+ } else {
callback();
+ }
});
- } else
+ } else {
callback();
+ }
});
- } else
+ } else {
callback();
+ }
// Setup event listeners if browserplus was initialized
function setup() {
@@ -82,29 +87,36 @@
dropElm = document.getElementById(dropElmId),
lastState;
- if (dropElm) {
- // Enable/disable drop support for the drop target
- // this is needed to resolve IE bubbeling issues and make it possible to drag/drop
- // files into gears runtimes on the same page
- function addDropHandler(id, end_callback) {
- // Add drop target and listener
- browserPlus.DragAndDrop.AddDropTarget({id : id}, function(res) {
- browserPlus.DragAndDrop.AttachCallbacks({
- id : id,
- hover : function(res) {
- if (!res && end_callback)
- end_callback();
- },
- drop : function(res) {
- if (end_callback)
- end_callback();
-
- addSelectedFiles(res);
+ // Enable/disable drop support for the drop target
+ // this is needed to resolve IE bubbeling issues and make it possible to drag/drop
+ // files into gears runtimes on the same page
+ function addDropHandler(id, end_callback) {
+ // Add drop target and listener
+ browserPlus.DragAndDrop.AddDropTarget({id : id}, function(res) {
+ browserPlus.DragAndDrop.AttachCallbacks({
+ id : id,
+ hover : function(res) {
+ if (!res && end_callback) {
+ end_callback();
}
- }, function(){});
+ },
+ drop : function(res) {
+ if (end_callback) {
+ end_callback();
+ }
+
+ addSelectedFiles(res);
+ }
+ }, function() {
});
- };
+ });
+ }
+ function hide() {
+ document.getElementById(dropTargetId).style.top = '-1000px';
+ }
+
+ if (dropElm) {
// Since IE has issues with bubbeling when it comes to the drop of files
// we need to do this hack where we show a drop target div element while dropping
if (document.attachEvent && (/MSIE/gi).test(navigator.userAgent)) {
@@ -134,14 +146,11 @@
height : dropElm.offsetHeight + 'px'
});
});
-
- function hide() {
- document.getElementById(dropTargetId).style.top = '-1000px';
- };
addDropHandler(dropTargetId, hide);
- } else
+ } else {
addDropHandler(dropElmId);
+ }
}
plupload.addEvent(document.getElementById(settings.browse_button), 'click', function(e) {
@@ -153,15 +162,17 @@
for (i = 0; i < filters.length; i++) {
ext = filters[i].extensions.split(',');
- for (a = 0; a < ext.length; a++)
+ for (a = 0; a < ext.length; a++) {
mimeTypes.push(plupload.mimeTypes[ext[a]]);
+ }
}
browserPlus.FileBrowse.OpenBrowseDialog({
mimeTypes : mimeTypes
}, function(res) {
- if (res.success)
+ if (res.success) {
addSelectedFiles(res.value);
+ }
});
});
@@ -192,7 +203,7 @@
});
}
});
- };
+ }
// Resize image if it's a supported format and resize is enabled
if (resize && /\.(png|jpg|jpeg)$/i.test(file.name)) {
@@ -206,11 +217,13 @@
}
}]
}, function(res) {
- if (res.success)
+ if (res.success) {
uploadFile(res.value.file);
+ }
});
- } else
+ } else {
uploadFile(nativeFile);
+ }
});
uploader.features = {
@@ -221,7 +234,7 @@
};
callback({success : TRUE});
- };
+ }
}
});
})(plupload);
Oops, something went wrong.

2 comments on commit 2307b3a

Contributor

olleolleolle replied Feb 15, 2010

Great idea. Instead of having a problem, automate it away.

Why are you using fake constants for undefined, true and false?
You should always check for undefined using typeof foo === "undefined", and true and false, well, they will ALWAYS be true and false :)

Please sign in to comment.