Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Cookie Issue (Again!)

Trying to nail down and issue with storing cookies. Think I finally got
it.
  • Loading branch information...
commit 7349ab6b3292aff28d4fc6a4b3007048ccd786e3 1 parent e2dba8d
Doug authored
2  assets/engines/coldfusion8/handler.cfc
@@ -884,7 +884,7 @@
884 884 <cftry>
885 885
886 886 <cfset locvar.requestData = GetHttpRequestData() />
887   - <cfset cj.origFilename = LCase(URLDecode(cgi.http_x_filename)) />
  887 + <cfset cj.origFilename = LCase(URLDecode(cgi.http_x_file_name)) />
888 888
889 889 <cfset cj.nameArr = ListToArray(cj.origFilename, ".") />
890 890 <cfset cj.paramsStr = URLDecode(cgi.http_x_file_params) />
122 assets/js/cj.file_browser.js
@@ -114,7 +114,7 @@
114 114 version: '4.0.1',
115 115 timer: null,
116 116 autoCenter: null,
117   - currentUrl: 0,
  117 + currentPathIdx: 0,
118 118 dirContents: [],
119 119 basePath: '/',
120 120 debug: false
@@ -284,6 +284,16 @@
284 284 * CORE Browser Functions
285 285 */
286 286
  287 + // copy item to new location
  288 + function moveItem() {
  289 +
  290 + }
  291 +
  292 + // rename an item
  293 + function renameItem() {
  294 +
  295 + }
  296 +
287 297 // displays our dialog boxes
288 298 function displayDialog(opts) {
289 299 // opts: type, state, label, content, cbOk, cbCancel
@@ -449,10 +459,10 @@
449 459 $('#directories optgroup').remove();
450 460 $('#directories').append('<optgroup label="Current Directory Path" title="Current Directory Path">');
451 461 $(opts.baseRelPath).each(function (intIndex, objValue) {
452   - $('#directories').append('<option value="' + objValue + '"' + (intIndex === sys.currentUrl ? ' selected="selected"' : '') + '>' + objValue + '<\/option>').attr("disabled", false);
  462 + $('#directories').append('<option value="' + objValue + '"' + (intIndex === sys.currentPathIdx ? ' selected="selected"' : '') + '>' + objValue + '<\/option>').attr("disabled", false);
453 463 });
454 464 // need to see if we have more than one directory and change the directory NAVIGATION accordingly
455   - if (opts.baseRelPath.length > 1 && sys.currentUrl > 0) {
  465 + if (opts.baseRelPath.length > 1 && sys.currentPathIdx > 0) {
456 466 $('#directoryOut').attr('disabled', false);
457 467 } else {
458 468 $('#directoryOut').attr('disabled', true);
@@ -460,7 +470,7 @@
460 470 }
461 471
462 472 function doLoadDirectoryImage($elem, idx, currentDir) {
463   - if ($elem.length > 0 && currentDir === sys.currentUrl) {
  473 + if ($elem.length > 0 && currentDir === sys.currentPathIdx) {
464 474 $elem.each(function() {
465 475 var $this = $(this),
466 476 fname = window.encodeURIComponent($this.find('.diritem').attr('rel')),
@@ -473,7 +483,7 @@
473 483 method: 'getImageThumb',
474 484 returnFormat: 'json',
475 485 timeOut: parseInt(opts.timeOut, 10),
476   - baseRelPath: window.encodeURIComponent(opts.baseRelPath[sys.currentUrl]),
  486 + baseRelPath: window.encodeURIComponent(opts.baseRelPath[sys.currentPathIdx]),
477 487 elemID: $this.attr('id'),
478 488 fileName: fname
479 489 },
@@ -518,7 +528,7 @@
518 528 function getDirectoryImages() {
519 529 // show image previews?
520 530 if (opts.showImgPreview) {
521   - doLoadDirectoryImage($('#browser ul li.GIF, #browser ul li.JPG, #browser ul li.PNG'), 0, sys.currentUrl);
  531 + doLoadDirectoryImage($('#browser ul li.GIF, #browser ul li.JPG, #browser ul li.PNG'), 0, sys.currentPathIdx);
522 532 }
523 533 }
524 534
@@ -548,7 +558,7 @@
548 558 method: 'getDirectoryList',
549 559 returnFormat: 'json',
550 560 timeOut: parseInt(opts.timeOut, 10),
551   - baseRelPath: window.encodeURIComponent(opts.baseRelPath[sys.currentUrl]),
  561 + baseRelPath: window.encodeURIComponent(opts.baseRelPath[sys.currentPathIdx]),
552 562 fileExts: window.encodeURIComponent(opts.fileExts)
553 563 },
554 564 dataType: 'json',
@@ -573,10 +583,14 @@
573 583 state: 'hide'
574 584 });
575 585 if (typeof sys.dirContents === 'object' && sys.dirContents.length > 0) {
576   - $.cookie('cj_dir', opts.baseRelPath[sys.currentUrl], {
  586 + sys.basePath = opts.baseRelPath[sys.currentPathIdx];
  587 + $.cookie('cj_dir', sys.basePath, {
577 588 expires: 1,
578   - path: sys.basePath
  589 + path: opts.baseRelPath[0]
579 590 });
  591 + if (sys.debug) {
  592 + console.log($.cookie('cj_dir'));
  593 + }
580 594 if ($.isFunction(clb)) {
581 595 clb.apply();
582 596 }
@@ -717,7 +731,9 @@
717 731 '<div class="name">' + doShortentFileName(objValue.NAME, 20) + '<\/div>' +
718 732 '<div class="namefull">' + objValue.NAME + '<\/div>' +
719 733 (objValue.TYPE === 'FILE' ? '<div class="size">' + displayFileSize(parseInt(objValue.SIZE, 10)) + '<\/div>' : '') +
720   - (typeof objValue.WIDTH === 'number' && typeof objValue.HEIGHT === 'number' ? '<div class="dimensions"><span class="width">' + objValue.WIDTH + '<\/span> x <span class="height">' + objValue.HEIGHT + '<\/span> pixels<\/div>' : '') +
  734 +
  735 + (parseInt(objValue.WIDTH, 10) && parseInt(objValue.HEIGHT, 10) ? '<div class="dimensions"><span class="width">' + parseInt(objValue.WIDTH, 10) + '<\/span> x <span class="height">' + parseInt(objValue.HEIGHT, 10) + '<\/span> pixels<\/div>' : '') +
  736 +
721 737 (objValue.DATELASTMODIFIED.length > 0 ? '<div class="modified">' + dateFormat(objValue.DATELASTMODIFIED, 'mmm dS, yyyy, h:MM:ss TT') + '<\/div>' : '') +
722 738 '<div class="mimeType">' + objValue.MIME + '<\/div>'
723 739 );
@@ -726,7 +742,7 @@
726 742 total_size += parseInt(objValue.SIZE, 10);
727 743
728 744 // append out info string to the list items
729   - infoStr = objValue.NAME + ' \n' + (objValue.TYPE === 'FILE' ? displayFileSize(parseInt(objValue.SIZE, 10)) + ' \n' : '') + (typeof objValue.WIDTH === 'number' && typeof objValue.HEIGHT === 'number' ? objValue.WIDTH + ' x ' + objValue.HEIGHT + ' pixels \n' : '') + dateFormat(objValue.DATELASTMODIFIED, 'mmm dS, yyyy, h:MM:ss TT');
  745 + infoStr = objValue.NAME + ' \n' + (objValue.TYPE === 'FILE' ? displayFileSize(parseInt(objValue.SIZE, 10)) + ' \n' : '') + (parseInt(objValue.WIDTH, 10) && parseInt(objValue.HEIGHT, 10) ? parseInt(objValue.WIDTH, 10) + ' x ' + parseInt(objValue.HEIGHT, 10) + ' pixels \n' : '') + dateFormat(objValue.DATELASTMODIFIED, 'mmm dS, yyyy, h:MM:ss TT');
730 746 $(lis).attr('title', infoStr);
731 747 $(lib).attr('title', infoStr).append(info);
732 748
@@ -785,8 +801,8 @@
785 801 $('#directoryIn').attr('disabled', false).on('click', function (e) {
786 802 if ($this.attr('disabled') !== 'disabled' && $this.attr('disabled') !== true) {
787 803 var path = $('#sidebar ul li.selected').find('span').attr('rel');
788   - opts.baseRelPath.push(opts.baseRelPath[sys.currentUrl] + path + '/');
789   - sys.currentUrl += 1;
  804 + opts.baseRelPath.push(opts.baseRelPath[sys.currentPathIdx] + path + '/');
  805 + sys.currentPathIdx += 1;
790 806 updateDirOptions();
791 807 doDirListing(function() {
792 808 displayDirListing();
@@ -805,8 +821,8 @@
805 821 fileObj = sys.dirContents[parseInt(($this.attr('ID')).replace('sidebar_ID', ''), 10)];
806 822 doFileSelect(fileObj);
807 823 } else if ($this.attr('rel') === 'Directory') {
808   - opts.baseRelPath.push(opts.baseRelPath[sys.currentUrl] + path + '/');
809   - sys.currentUrl += 1;
  824 + opts.baseRelPath.push(opts.baseRelPath[sys.currentPathIdx] + path + '/');
  825 + sys.currentPathIdx += 1;
810 826 updateDirOptions();
811 827 doDirListing(function() {
812 828 displayDirListing();
@@ -865,8 +881,8 @@
865 881 $('#directoryIn').attr('disabled', false).on('click', function (e) {
866 882 if ($this.attr('disabled') !== 'disabled' && $this.attr('disabled') !== true) {
867 883 var path = $('#browser ul li.selected').find('.diritem').attr('rel');
868   - opts.baseRelPath.push(opts.baseRelPath[sys.currentUrl] + path + '/');
869   - sys.currentUrl += 1;
  884 + opts.baseRelPath.push(opts.baseRelPath[sys.currentPathIdx] + path + '/');
  885 + sys.currentPathIdx += 1;
870 886 updateDirOptions();
871 887 doDirListing(function() {
872 888 displayDirListing();
@@ -885,14 +901,24 @@
885 901 fileObj = sys.dirContents[parseInt(($this.attr('ID')).replace('browser_ID', ''), 10)];
886 902 doFileSelect(fileObj);
887 903 } else if ($this.attr('rel') === 'Directory') {
888   - opts.baseRelPath.push(opts.baseRelPath[sys.currentUrl] + path + '/');
889   - sys.currentUrl += 1;
  904 + opts.baseRelPath.push(opts.baseRelPath[sys.currentPathIdx] + path + '/');
  905 + sys.currentPathIdx += 1;
890 906 updateDirOptions();
891 907 doDirListing(function() {
892 908 displayDirListing();
893 909 });
894 910 }
895 911 e.stopImmediatePropagation();
  912 + }).draggable({
  913 + cursor: 'move',
  914 + helper: 'clone',
  915 + opacity: 0.5,
  916 + containment: '#browser',
  917 + scroll: true,
  918 + start: function(event, ui) {
  919 + var $this = $(event.target).parents('li');
  920 + console.log($this);
  921 + }
896 922 });
897 923
898 924 getDirectoryImages();
@@ -906,7 +932,7 @@
906 932 });
907 933
908 934 // update display stats info
909   - updateDisplayStats(opts.baseRelPath[sys.currentUrl], dir.length, total_size);
  935 + updateDisplayStats(opts.baseRelPath[sys.currentPathIdx], dir.length, total_size);
910 936 }
911 937
912 938
@@ -1088,7 +1114,7 @@
1088 1114 true
1089 1115 );
1090 1116 xhr.setRequestHeader('Content-Type', file.type);
1091   - xhr.setRequestHeader('X-Filename', window.encodeURIComponent(file.name) || window.encodeURIComponent(file.fileName));
  1117 + xhr.setRequestHeader('X-File-Name', window.encodeURIComponent(file.name) || window.encodeURIComponent(file.fileName));
1092 1118 xhr.setRequestHeader('X-File-Params', window.encodeURIComponent(prms));
1093 1119 xhr.send(file);
1094 1120 }
@@ -1181,8 +1207,8 @@
1181 1207 $('#directoryOut').mouseup(function () {
1182 1208 var $this = $(this);
1183 1209 if ($this.attr('disabled') !== 'disabled' && $this.attr('disabled') !== true) {
1184   - sys.currentUrl = sys.currentUrl - 1 >= 0 ? sys.currentUrl - 1 : 0;
1185   - opts.baseRelPath.remove(sys.currentUrl + 1, opts.baseRelPath.length - sys.currentUrl + 1);
  1210 + sys.currentPathIdx = sys.currentPathIdx - 1 >= 0 ? sys.currentPathIdx - 1 : 0;
  1211 + opts.baseRelPath.remove(sys.currentPathIdx + 1, opts.baseRelPath.length - sys.currentPathIdx + 1);
1186 1212 doDirListing(function() {
1187 1213 displayDirListing();
1188 1214 });
@@ -1192,9 +1218,9 @@
1192 1218 // set up the directories SELECT menu
1193 1219 $('#directories').change(function () {
1194 1220 var $this = $(this);
1195   - if ($this.get(0).selectedIndex < sys.currentUrl) {
  1221 + if ($this.get(0).selectedIndex < sys.currentPathIdx) {
1196 1222 opts.baseRelPath.remove($this.get(0).selectedIndex + 1, opts.baseRelPath.length - $this.get(0).selectedIndex + 1);
1197   - sys.currentUrl = $this.get(0).selectedIndex;
  1223 + sys.currentPathIdx = $this.get(0).selectedIndex;
1198 1224 doDirListing(function() {
1199 1225 displayDirListing();
1200 1226 });
@@ -1250,7 +1276,7 @@
1250 1276 method: 'doCreateNewDirectory',
1251 1277 returnFormat: 'json',
1252 1278 timeOut: parseInt(opts.timeOut, 10),
1253   - baseRelPath: window.encodeURIComponent(opts.baseRelPath[sys.currentUrl]),
  1279 + baseRelPath: window.encodeURIComponent(opts.baseRelPath[sys.currentPathIdx]),
1254 1280 dirName: window.encodeURIComponent(dirName)
1255 1281 },
1256 1282 dataType: 'json',
@@ -1346,7 +1372,7 @@
1346 1372 method: curType === 'File' ? 'doDeleteFile' : 'doDeleteDirectory',
1347 1373 returnFormat: 'json',
1348 1374 timeOut: parseInt(opts.timeOut, 10),
1349   - baseRelPath: window.encodeURIComponent(opts.baseRelPath[sys.currentUrl]),
  1375 + baseRelPath: window.encodeURIComponent(opts.baseRelPath[sys.currentPathIdx]),
1350 1376 dirName: window.encodeURIComponent(curFile),
1351 1377 fileName: window.encodeURIComponent(curFile)
1352 1378 },
@@ -1421,7 +1447,7 @@
1421 1447 if ($('#CJUploadForm #fileUploadField').val() !== '') {
1422 1448 $('#CJFileBrowser #CJFileBrowserForm').append(
1423 1449 '<div class="hider">' +
1424   - '<input type="hidden" name="baseUrl" value="' + window.encodeURIComponent(opts.baseRelPath[sys.currentUrl]) + '" \/>' +
  1450 + '<input type="hidden" name="baseUrl" value="' + window.encodeURIComponent(opts.baseRelPath[sys.currentPathIdx]) + '" \/>' +
1425 1451 '<input type="hidden" name="fileExts" value="' + window.encodeURIComponent(opts.fileExts) + '" \/>' +
1426 1452 '<input type="hidden" name="maxSize" value="' + window.encodeURIComponent(opts.maxSize) + '" \/>' +
1427 1453 '<input type="hidden" name="maxWidth" value="' + window.encodeURIComponent(opts.maxWidth) + '" \/>' +
@@ -1574,22 +1600,36 @@
1574 1600 // initial test to see if our handler exists
1575 1601 function getHandler() {
1576 1602 var json,
1577   - initPath = $.cookie('cj_dir') || (opts.baseRelPath.length > 0 ? opts.baseRelPath[0] : null);
1578   -
1579   - // the cookie path should never be shorter than the passed path
1580   - initPath = initPath.length != opts.baseRelPath[0].length ? opts.baseRelPath[0] : initPath;
  1603 + re = new RegExp('/\/|\\/', 'gim'),
  1604 + pathArr;
  1605 +
  1606 + sys.basePath = $.cookie('cj_dir') || (opts.baseRelPath.length > 0 ? opts.baseRelPath[0] : null);
  1607 +
  1608 + // need to set the basePath based on cookie (if valid) or the opts.baseRelPath
  1609 + if (sys.basePath && sys.basePath.indexOf(opts.baseRelPath[0]) > -1) {
  1610 + // the path is valid, but we need to loop through it to populate our path object
  1611 + sys.basePath = sys.basePath.length > 1 ? sys.basePath.substring(1, sys.basePath.length - 1) : '/';
  1612 + pathArr = sys.basePath.split(re);
  1613 + $.each(pathArr, function(a, b) {
  1614 + opts.baseRelPath.push(opts.baseRelPath[opts.baseRelPath.length - 1] + b + '/');
  1615 + });
  1616 + } else {
  1617 + sys.basePath = opts.baseRelPath[0];
  1618 + }
  1619 + sys.currentPathIdx = opts.baseRelPath.length - 1;
  1620 + sys.basePath = opts.baseRelPath[sys.currentPathIdx];
1581 1621
1582 1622 if (sys.debug) {
1583   - console.log('initPath: ' + initPath);
  1623 + console.log('sys.basePath: ' + sys.basePath);
1584 1624 }
1585 1625
1586   - if (!initPath) {
  1626 + if (!sys.basePath) {
1587 1627 // if either path is invalid, then make sure the cookie get's removed.
1588 1628 $.cookie('cj_dir', null, {
1589 1629 expires: -1,
1590 1630 path: sys.basePath
1591 1631 });
1592   - throw('Oops! There was a problem\n\nThe initial path is not valid (' + initPath + ').');
  1632 + throw('Oops! There was a problem\n\nThe initial path is not valid (' + sys.basePath + ').');
1593 1633 } else {
1594 1634
1595 1635 json = $.parseJSON(
@@ -1599,7 +1639,7 @@
1599 1639 data: {
1600 1640 method: 'isHandlerReady',
1601 1641 returnFormat: 'json',
1602   - dirPath: window.escape(initPath), // we can now validate the initial directory path
  1642 + dirPath: window.escape(sys.basePath), // validates the initial directory path
1603 1643 timeOut: parseInt(opts.timeOut, 10),
1604 1644 version: sys.version
1605 1645 },
@@ -1685,7 +1725,7 @@
1685 1725 }
1686 1726
1687 1727 // need to verify that we have valid setting values...
1688   - if ((typeof opts.actions !== 'object' || opts.actions.length === 0) || (typeof opts.baseRelPath !== 'object' || opts.baseRelPath.length === 0) || (typeof opts.fileExts !== 'string' || opts.fileExts.length === 0) || (typeof opts.maxSize !== 'number' || opts.maxSize === 0) || (typeof opts.maxWidth !== 'number' || opts.maxWidth === 0) || (typeof opts.maxHeight !== 'number' || opts.maxHeight === 0) || (typeof opts.showImgPreview !== 'boolean') || (typeof opts.engine !== 'string' || opts.engine === '') || (typeof opts.handler !== 'string' || opts.handler === '') || (typeof opts.timeOut !== 'number' || opts.timeOut < 0) || (typeof opts.callBack !== 'function' && opts.callBack !== null) || (typeof sys.currentUrl !== 'number' || sys.currentUrl < 0)) {
  1728 + if ((typeof opts.actions !== 'object' || opts.actions.length === 0) || (typeof opts.baseRelPath !== 'object' || opts.baseRelPath.length === 0) || (typeof opts.fileExts !== 'string' || opts.fileExts.length === 0) || (typeof opts.maxSize !== 'number' || opts.maxSize === 0) || (typeof opts.maxWidth !== 'number' || opts.maxWidth === 0) || (typeof opts.maxHeight !== 'number' || opts.maxHeight === 0) || (typeof opts.showImgPreview !== 'boolean') || (typeof opts.engine !== 'string' || opts.engine === '') || (typeof opts.handler !== 'string' || opts.handler === '') || (typeof opts.timeOut !== 'number' || opts.timeOut < 0) || (typeof opts.callBack !== 'function' && opts.callBack !== null) || (parseInt(sys.currentPathIdx, 10) || 0)) {
1689 1729
1690 1730 // problem initializing the script
1691 1731 throw('Oops! There was a problem\n\nVariables were not initialized properly or missing values.');
@@ -1703,8 +1743,12 @@
1703 1743
1704 1744 // init our navbar
1705 1745 if (!JSON) {
1706   - $.getScript('assets/js/json2.js', function() {
1707   - init();
  1746 + $.getScript('assets/js/json2.js', function(data, statusText) {
  1747 + if (!statusText || statusText !== "success") {
  1748 + throw('Problems initializing json2.js (cj.file_browser.js)');
  1749 + } else {
  1750 + init();
  1751 + }
1708 1752 });
1709 1753 } else {
1710 1754 init();

0 comments on commit 7349ab6

Please sign in to comment.
Something went wrong with that request. Please try again.