Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Extension of scriptData
  • Hi guys, I love you, uploadify is amazing, so cool. Wau
    I want to send some other data with files, so I use scriptData: ... but it requires an object and if I have a form and I putting to scriptData data form this form, it is annoying to do object from this form when I use serialize() in jQuery.

    I change it, but I think that it could be in original source. Here is my solution.
    This is on line 74 in jquery.uploadify.v2.1.4.js

    ...
    if (settings.scriptData) {
    if(typeof settings.scriptData === "object"){
    var scriptDataString = '';
    for (var name in settings.scriptData) {
    scriptDataString += '&' + name + '=' + settings.scriptData[name];
    }
    data.scriptData = escape(scriptDataString.substr(1));
    }else{
    data.scriptData = settings.scriptData;
    }
    }
    ...


    And how it works? If user puts there an object, like {attributy: value...}, it does what it does to this time, but if he puts there a string which serialize() returns, it only copy it to data.scriptData.
    Docs of serialize() on official jQuery page.

    P.S. If you replay to this thread, you can also tell me where I have mistake in my English :D
  • Uups I have a error there, you have to escaped it, so ...
    if (settings.scriptData) {
    if(typeof settings.scriptData === "object"){
    var scriptDataString = '';
    for (var name in settings.scriptData) {
    scriptDataString += '&' + name + '=' + settings.scriptData[name];
    }
    data.scriptData = escape(scriptDataString.substr(1));
    }else{
    data.scriptData = escapesettings.scriptData);
    }
    }
    ...


    And if you use a .uploadifySettings(); then you have to put it also into this function.
    On line 253
    uploadifySettings:function(settingName, settingValue, resetObject) {
    var returnValue = false;
    jQuery(this).each(function() {
    if (settingName == 'scriptData' && settingValue != null) {
    if (resetObject) {
    var scriptData = settingValue;
    } else {
    var scriptData = jQuery.extend(jQuery(this).data('settings').scriptData, settingValue);
    }
    var scriptDataString = '';
    if(typeof scriptData === "object"){
    for (var name in settings.scriptData) {
    scriptDataString += '&' + name + '=' + scriptData[name];
    }
    settingValue = escape(scriptDataString.substr(1));
    }else{
    settingValue = escape(scriptData);
    }
    }
    returnValue = document.getElementById(jQuery(this).attr('id') + 'Uploader').updateSettings(settingName, settingValue);
    });
    ...
  • HERE you can download core with this upgrade