Adding a Custom Button in the template-download
what changes i should make to FU UI to add a custom button in the template-download
the places i have noticed are (i am sure its not 100% correct)
1.add the button to the template html 2.customize function : _renderDownload 2.add new handler function (same as _deleteHandler) 3.add new call back (same as start,stop) with custom code 4.customize _initEventHandlers 5.customize _destroyEventHandlers
You're on the right track, although an additional callback might not be necessary. Just try to implement your button based on the code for the existing buttons functionality.
i did all these steps - it works fine when the page loads and i retreive existing files . when i try to upload a new file the all buttons on the template-download work, except the custom button is not fired. (all previous loaded custom buttons fire correctly) . i think its something with .live code.
Please post your code (make sure to indent it for correct display here), or a link to your website implementation.
here is the code additions to FU UI .js
// Callback for file set as primary image:
setisprimary: function (e, data) {
var that = $(this).data('fileupload');
var currentbutton = data.context.find('button[data-type="PRIMARYIMAGE"]');
if (data.url) {
$.ajax(data)
.success(function () {
//sucess image set as primary
})
.error(function (xhr, status, error) {
// Display a generic error for now.
alert("error .");
});
} else {
//no url found
}
},
--------------------- _renderDownload-------------------------------
tmpl.find('.isprimary button').button({
text: false,
icons: { primary: 'ui-icon-star' }
});
--------------------------handler---------------------------------
_isprimaryHandler: function (e) {
e.preventDefault();
var button = $(this);
e.data.fileupload._trigger('setisprimary', e, {
context: button.closest('.template-download'),
url: button.attr('data-url'),
type: button.attr('data-type'),
dataType: e.data.fileupload.options.dataType
});
},
--------------------------_initEventHandlers---------------------------------
filesList.find('.isprimary button')
.live(
'click.' + this.options.namespace,
eventData,
this._isprimaryHandler
);
---------------------_destroyEventHandlers-----------------------------------
filesList.find('.isprimary button')
.die('click.' + this.options.namespace);
Hmm, looks alright... You will need to debug using Firebug or another tool to find out what's the issue.
Will do , thanks for the great plugin.
I am also trying to add a custom button with a custom handler and I can't find the error I made.
Could you help me with the method you used to debug yours ?
Just in case here is the code I added.
I found the solution and I post it here in case someone wants to do it too.
Remark: I wanted to insert buttons in the .fileupload-buttonbar container not in the file list.
In jquery.fileupload.js
--------------------------_initEventHandlers---------------------------------
this.element.find('.options').each(function () {
$(this).button({
text: false,
icons: {primary: 'ui-icon-gear'}})
.bind('click.' + ns, function (e) {
e.preventDefault();
alert('It works !');
});
});
---------------------HTML code-----------------------------------
<button type="button" class="options">Options</button>
Please read: https://github.com/blueimp/jQuery-File-Upload#support