Skip to content

Commit

Permalink
Added jslint and updated all scripts to be compatible.
Browse files Browse the repository at this point in the history
  • Loading branch information
spocke committed Feb 15, 2010
1 parent a7be6ef commit 2307b3a
Show file tree
Hide file tree
Showing 11 changed files with 262 additions and 182 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ bin
obj
tmp
docs
jslint.xml
.settings
*~
*.diff
Expand Down
15 changes: 14 additions & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
Expand All @@ -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">
Expand Down
41 changes: 25 additions & 16 deletions src/javascript/jquery.plupload.queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

function _(str) {
return plupload.translate(str) || str;
};
}

function renderUI(id, target) {
target.html(
Expand Down Expand Up @@ -65,7 +65,7 @@
'<input type="hidden" id="' + id + '_count" name="' + id + '_count" value="0" />' +
'</div>'
);
};
}

$.fn.pluploadQueue = function(settings) {
if (settings) {
Expand All @@ -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;
Expand All @@ -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') + '" />';
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
});
Expand Down Expand Up @@ -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) {
Expand Down
13 changes: 8 additions & 5 deletions src/javascript/jquery.plupload.single.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
'</div>' +
'</div>'
);
};
}

$.fn.pluploadSingle = function(settings) {
if (settings) {
Expand Down Expand Up @@ -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', '');
}
});
});

Expand Down
89 changes: 51 additions & 38 deletions src/javascript/plupload.browserplus.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,10 @@
}

// Any files selected fire event
if (i)
if (i) {
uploader.trigger("FilesAdded", selectedFiles);
};
}
}

// Check for browserplus object
if (browserPlus) {
Expand All @@ -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() {
Expand All @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
}
});
});

Expand Down Expand Up @@ -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)) {
Expand All @@ -206,11 +217,13 @@
}
}]
}, function(res) {
if (res.success)
if (res.success) {
uploadFile(res.value.file);
}
});
} else
} else {
uploadFile(nativeFile);
}
});

uploader.features = {
Expand All @@ -221,7 +234,7 @@
};

callback({success : TRUE});
};
}
}
});
})(plupload);
Loading

0 comments on commit 2307b3a

Please sign in to comment.