PageRenderTime 44ms CodeModel.GetById 22ms RepoModel.GetById 0ms app.codeStats 0ms

/app/scripts/collections/stop-collection.js

https://github.com/davidchchang/mystops
JavaScript | 40 lines | 33 code | 6 blank | 1 comment | 3 complexity | 54d0d079fff0bb8d8e6e641b9582777b MD5 | raw file
  1. /*global mystops, Backbone*/
  2. mystops.Collections.StopCollection = Backbone.Collection.extend({
  3. model: mystops.Models.StopModel,
  4. url: 'http://webservices.nextbus.com/service/publicXMLFeed?command=routeConfig&a=ttc',
  5. parse: function (data) {
  6. var parsed = [];
  7. var directions = {};
  8. $(data).find('direction').each(function(index){
  9. var dataDir = $(this).attr("tag");
  10. directions[dataDir] = [];
  11. $(this).find('stop').each(function(jndex){
  12. dataTag = $(this).attr("tag");
  13. directions[dataDir][jndex] = dataTag;
  14. });
  15. });
  16. $(data).find('route > stop').each(function (index) {
  17. var dataTag = $(this).attr('tag');
  18. var dataTitle = $(this).attr('title');
  19. var dataDir = "";
  20. for (var direction in directions) {
  21. if (directions[direction].indexOf(dataTag) > -1) {
  22. dataDir = direction;
  23. }
  24. }
  25. parsed.push({tag: dataTag, title: dataTitle, direction: dataDir});
  26. });
  27. return parsed;
  28. },
  29. fetch: function (options) {
  30. options = options || {};
  31. options.dataType = "xml";
  32. Backbone.Collection.prototype.fetch.call(this, options);
  33. }
  34. });