base-client.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. //XXX not sure this is still working properly?
  2. FS.Utility.connectionLogin = function(connection) {
  3. // We check if the accounts package is installed, since we depend on
  4. // `Meteor.userId()`
  5. if (typeof Accounts !== 'undefined') {
  6. // Monitor logout from main connection
  7. Meteor.startup(function() {
  8. Tracker.autorun(function() {
  9. var userId = Meteor.userId();
  10. if (userId) {
  11. connection.onReconnect = function() {
  12. var token = Accounts._storedLoginToken();
  13. connection.apply('login', [{resume: token}], function(err, result) {
  14. if (!err && result) {
  15. connection.setUserId(result.id);
  16. }
  17. });
  18. };
  19. } else {
  20. connection.onReconnect = null;
  21. connection.setUserId(null);
  22. }
  23. });
  24. });
  25. }
  26. };
  27. /**
  28. * @method FS.Utility.eachFile
  29. * @public
  30. * @param {Event} e - Browser event
  31. * @param {Function} f - Function to run for each file found in the event.
  32. * @returns {undefined}
  33. *
  34. * Utility for iteration over files in event
  35. */
  36. FS.Utility.eachFile = function(e, f) {
  37. var evt = (e.originalEvent || e);
  38. var files = evt.target.files;
  39. if (!files || files.length === 0) {
  40. files = evt.dataTransfer ? evt.dataTransfer.files : [];
  41. }
  42. for (var i = 0; i < files.length; i++) {
  43. f(files[i], i);
  44. }
  45. };