Skip to content

Commit

Permalink
Improvements to mediamanager.js and popup-imagemanager.js
Browse files Browse the repository at this point in the history
 - use jquery's prop function instead of attr
 - properly and consistently encode and decode URI components
 - explicitly use global variables from the global scope
  • Loading branch information
okonomiyaki3000 committed Jun 12, 2019
1 parent c5ff9e5 commit 5722fbe
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 17 deletions.
17 changes: 10 additions & 7 deletions media/media/js/mediamanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,30 @@

var folder = this.getFolder() || '',
query = [],
a = getUriObject( $( '#uploadForm' ).attr( 'action' ) ),
a = getUriObject( $( '#uploadForm' ).prop( 'action' ) ),
q = getQueryObject( a.query ),
k, v;

this.updatepaths.each( function( path, el ) {
el.value = folder;
} );

this.folderpath.value = basepath + (folder ? '/' + folder : '');
this.folderpath.value = scope.basepath + (folder ? '/' + folder : '');

q.folder = folder;

for ( k in q ) {
if (!q.hasOwnProperty( k )) { continue; }

v = q[ k ];
query.push( k + (v === null ? '' : '=' + v) );
query.push(encodeURIComponent(k) + (v === null ? '' : '=' + encodeURIComponent(v)));
}

a.query = query.join( '&' );
a.fragment = null;

$( '#uploadForm' ).attr( 'action', buildUri(a) );
$( '#' + viewstyle ).addClass( 'active' );
$( '#uploadForm' ).prop( 'action', buildUri(a) );
$( '#' + scope.viewstyle ).addClass( 'active' );
},

/**
Expand All @@ -92,10 +92,13 @@
*/
setViewType: function( type ) {
$( '#' + type ).addClass( 'active' );
$( '#' + viewstyle ).removeClass( 'active' );
viewstyle = type;
$( '#' + scope.viewstyle ).removeClass( 'active' );
scope.viewstyle = type;
var folder = this.getFolder();

folder = encodeURIComponent(folder);
type = encodeURIComponent(type);

this.setFrameUrl( 'index.php?option=com_media&view=mediaList&tmpl=component&folder=' + folder + '&layout=' + type );
},

Expand Down
3 changes: 2 additions & 1 deletion media/media/js/mediamanager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions media/media/js/popup-imagemanager.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
this.author = options.author;
this.base = options.base;
this.asset = options.asset;
this.editor = decodeURIComponent(q.e_name);
this.editor = q.e_name;

// Setup image manager fields object
this.fields = {
Expand Down Expand Up @@ -79,7 +79,7 @@
this.frameurl = this.frame.location.href;
this.setFolder(folder);

a = this.getUriObject($form.attr('action'));
a = this.getUriObject($form.prop('action'));
q = this.getQueryObject(a.query);
q.folder = folder;
a.query = $.param(q);
Expand All @@ -89,7 +89,7 @@
portString = ':' + a.port;
}

$form.attr('action', a.scheme + '://' + a.domain + portString + a.path + '?' + a.query);
$form.prop('action', a.scheme + '://' + a.domain + portString + a.path + '?' + a.query);
},

/**
Expand All @@ -99,7 +99,7 @@
*/
getImageFolder: function ()
{
return this.getQueryObject(this.frame.location.search.substring(1)).folder.replace(/%2F/gi, "/");
return this.getQueryObject(this.frame.location.search.substring(1)).folder;
},

/**
Expand Down Expand Up @@ -178,7 +178,6 @@
*/
setFolder: function (folder, asset, author)
{
folder = folder.replace(/%2F/gi, "/");
for (var i = 0, l = this.folderlist.length; i < l; i++)
{
if (folder == this.folderlist.options[i].value)
Expand Down Expand Up @@ -277,11 +276,12 @@
view: 'imagesList',
tmpl: 'component',
asset: asset,
author: author
author: author,
folder: folder
};

// Don't run folder through params because / will end up double encoded.
this.frameurl = 'index.php?' + $.param(qs) + '&folder=' + folder;
this.frameurl = 'index.php?' + $.param(qs);
this.frame.location.href = this.frameurl;
},

Expand All @@ -300,7 +300,7 @@
{
var keys = val.split('=');

rs[keys[0]] = keys.length == 2 ? keys[1] : null;
rs[ decodeURIComponent(keys[0]) ] = keys.length == 2 ? decodeURIComponent(keys[1]) : null;
});

return rs;
Expand Down
3 changes: 2 additions & 1 deletion media/media/js/popup-imagemanager.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 5722fbe

Please sign in to comment.