sports_db 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- if ($.client && $.client.android || Application.client && Application.client.android) {
1
+ if (window.location.search.indexOf("client=android") !== -1) {
2
2
  console.log('=> Using AndroidClient.js');
3
3
 
4
4
  // This should be in a mock file...
@@ -1,13 +1,18 @@
1
- if ($.client.ios) {
1
+ if (window.location.search.indexOf("client=ios") !== -1) {
2
2
  console.log('=> Using iOSClient.js');
3
3
 
4
4
  var Client = Class.extend({
5
+ initialize: function() {
6
+ this.commands = [];
7
+ this.timer = new Timer($.proxy(this._sendNotifications, this), 133);
8
+ this.timer.start();
9
+ },
5
10
  // Called by the web application to send values to the client.
6
11
  //
7
12
  // @param {Object} obj - a set of key/value parameters to send to client
8
13
  notify: function(obj) {
9
14
  if (top.location === self.location) {
10
- this._createUrlForClientInterception("client_notify", obj);
15
+ this.commands.push(obj);
11
16
  }
12
17
  },
13
18
  // Called by the client to set a value or trigger an action in the web page.
@@ -17,6 +22,14 @@ if ($.client.ios) {
17
22
  callback: function(name, value) {
18
23
  Application.onClientCallback(name, value);
19
24
  },
25
+ _sendNotifications: function() {
26
+ // Do nothing if array is empty.
27
+ if (this.commands.length === 0) return;
28
+
29
+ // Send the first command in the array.
30
+ this._createUrlForClientInterception("client_notify", this.commands[0]);
31
+ this.commands.shift();
32
+ },
20
33
  _createUrlForClientInterception: function(prefix, obj) {
21
34
  this._initClientTransportIfNecessary(prefix);
22
35
  for (var prop in obj) {
@@ -0,0 +1,121 @@
1
+ // A basic view implementation that expects an `URL` to be passed as one of the parameters
2
+ // to the view; it will format that `URL` using any other parameters, and use it to retrieve
3
+ // an `HTML` fragment from the server. This is only one of many strategies that could be
4
+ // followed to create views, of course. It also assumes that the parameters object will
5
+ // get a title property.
6
+ var BaseView = View.extend({
7
+ // Subclasses must ensure there is an url property to the parameter object passed
8
+ // into this superconstructor, i.e.:
9
+ //
10
+ // this._super(params)
11
+ //
12
+ // Any parameters passed in to the view constructor will be substituted
13
+ // into the URL string using the String format method (see utilities.js).
14
+ //
15
+ // @param {Object} params
16
+ initialize: function(params) {
17
+ this.url = this.getUrl(params);
18
+ this.params = params;
19
+ },
20
+ getUrl: function(params) {
21
+ if (params.url) {
22
+ return params.url.format(params);
23
+ } else {
24
+ return "/"+Application.params.serverPath+"/" + params.view;
25
+ }
26
+ },
27
+ getTitle: function() {
28
+ // The title varies on the Team View between Android and iOS.
29
+ // cstuart 2011-08-29
30
+ if (Application.client.ios) {
31
+ this.params.title = this.params.ios_title || this.params.title;
32
+ }
33
+ return this.params.title || this.params.view.capitalize();
34
+ },
35
+ getMetric: function() {
36
+ return this.params.metric || "/" + this.params.view.capitalize();
37
+ },
38
+ setMetric: function(metric) {
39
+ $.log('((( setMetric '+ metric +' )))');
40
+ return this.params.metric = metric;
41
+ },
42
+ getButtons: function() {
43
+ return this.params.buttons || "Back:";
44
+ },
45
+ getAction: function() {
46
+ return this.params.action || "<None>";
47
+ },
48
+ getFilter: function() {
49
+ return this.params.filter || "<None>";
50
+ },
51
+ getSection: function() {
52
+ return this.params.section || this.params.view;
53
+ },
54
+ shouldRefreshAd: function() {
55
+ return this.params.hasOwnProperty('refreshAd') ? this.params.refreshAd : true;
56
+ },
57
+ // Loads the content of the view from the server (the content should be wrapped by a `div`).
58
+ // The content is inserted into the page.
59
+ create: function(params) {
60
+ if (!params.skipLoadingIndicator) {
61
+ $.showLoader();
62
+ }
63
+ // This is a hack. The TSN keys include periods that confuse the Rails page caching system. Convert
64
+ // here to underscores, and back to periods again on the server using a filter.
65
+ this.url = this.url.dotToBar();
66
+
67
+ $.ajax({
68
+ url: this.url,
69
+ success: $.proxy(function(response) {
70
+ if (params.isAutoUpdating && params.view !== Application.currentView.params.view) {
71
+ console.log('$$ BaseView.create(): Not appending autoupdate view. We are no longer on that view!');
72
+ } else {
73
+ // NBA3 only
74
+ if ($.highResifyLogosForRetinaAndAndroid) {
75
+ console.log('adjusting Android');
76
+ response = $.highResifyLogosForRetinaAndAndroid(response);
77
+ }
78
+
79
+ // Get a node rather than plain HTML
80
+ this.element = Application.buffer.html(response).find('div').get(0);
81
+ Application.appendView(this);
82
+
83
+ // NBA3 only
84
+ if ($.delayedLoad) {
85
+ $.delayedLoad();
86
+ }
87
+ }
88
+ }, this),
89
+ error: function(e) {
90
+ $.hideLoader();
91
+ $.flash("A network error occurred.", Application.currentView.params, true);
92
+ throw new Error('An error occurred.');
93
+ }
94
+ });
95
+ },
96
+ onClientCallback: function(name, value) {
97
+ $.log('BaseView.onClientCallback({' + name + ': ' + value + '})');
98
+ },
99
+ // If HTML returned from the server includes a `<div id="html_data" data-params=""></div>` element,
100
+ // this should contain an object literal (JSON string) with values that will be merged into
101
+ // the parameters for this view instance. This is used to pass back additional information
102
+ // from the server via the HTML. For example, when loading a player it might be useful to
103
+ // return the key for the player's team so that can be used when communicating with the client:
104
+ //
105
+ // <data id="view_data" data="{'title': '<%= @team.city_name %> <%= @team.team_name %>'}"></data>
106
+ //
107
+ // This will add the integer 1588 (correctly typed) under the property "team_key" to the
108
+ // parameters (`this.params`) for this view.
109
+ _evaluateDataAttribute: function() {
110
+ var params = $('#html_params', Application.wrapper).data('params');
111
+
112
+ if (params) {
113
+ var data = JSON.parse(params);
114
+
115
+ for (var key in data) {
116
+ // If you escape a non-string value, it is first converted to a string, which we don't want
117
+ this.params[key] = (typeof data[key] == "string") ? unescape(data[key]) : data[key];
118
+ }
119
+ }
120
+ }
121
+ });
@@ -1,8 +1,10 @@
1
+ //= require core/mock_config.js
2
+
1
3
  // Mock client interface
2
4
  var Mock = Class.extend({
3
5
  initialize: function(client) {
4
6
  this.client = client;
5
- window.addEventListener("load", this._makeToolbar.bind(this), true);
7
+ window.addEventListener("load", $.proxy(this._makeToolbar, this), true);
6
8
  },
7
9
  _makeToolbar: function(){
8
10
  var toolbar = document.createElement("div");
@@ -21,33 +23,6 @@ var Mock = Class.extend({
21
23
 
22
24
  var Mock = new Mock(Client);
23
25
 
24
- Client.notify = function(obj) {
25
- if (typeof obj.buttons !== 'undefined') {
26
- this.makeButtons(obj.buttons);
27
- }
28
- if (typeof obj.title !== 'undefined') {
29
- this.makeTitle(obj.title);
30
- }
31
-
32
- if (obj.action === "getFavesAndNotifs") {
33
- Client.callback("favesAndNotifs", {
34
- faves: Application.params.MOCK_FAVORITES,
35
- notifs: Application.params.MOCK_NOTIFS
36
- });
37
- }
38
-
39
- // Client.notify logs notifications to the console.
40
- if (window.console && window.console.log) {
41
- var arr = [];
42
- for (var prop in obj) {
43
- if (typeof obj[prop] !== "function") {
44
- arr.push(escape(prop) + ": " + escape(obj[prop]));
45
- }
46
- }
47
- console.log("Client.notify({ " + arr.join(", ") + " })");
48
- }
49
- };
50
-
51
26
  Client.makeButtons = function(str) {
52
27
  if (!str) return;
53
28
  var specs = str.split(":");
@@ -63,7 +38,7 @@ Client.makeButtons = function(str) {
63
38
  $('#'+id).show();
64
39
  if (str === "NudgeNav") {
65
40
  // Support for nudge nav in mock toolbar.
66
- $('#'+id).html("<action name='nudge' value='prev'>&uarr;</action>&nbsp;<action name='nudge' value='next'>&darr;</action>");
41
+ $('#'+id).html("<action id='nudge_prev' name='nudge' value='prev'>&uarr;</action>&nbsp;<action id='nudge_next' name='nudge' value='next'>&darr;</action>");
67
42
  } else {
68
43
  $('#'+id).html("<action name='callback' value=" + str + ">" + str + "</action>");
69
44
  }
@@ -71,13 +46,49 @@ Client.makeButtons = function(str) {
71
46
  }
72
47
  };
73
48
 
49
+ Client.notify = function(obj) {
50
+ if (typeof obj.buttons !== 'undefined') {
51
+ this.makeButtons(obj.buttons);
52
+ }
53
+ if (typeof obj.title !== 'undefined' && typeof obj.action !== 'undefined' && obj.action !== 'share') {
54
+ this.makeTitle(obj.title);
55
+ }
56
+
57
+ if (obj.action === "getFavesAndNotifs") {
58
+ Client.callback("favesAndNotifs", MOCK_FAVES_CONFIG);
59
+ }
60
+
61
+ // CFB2 only
62
+ if (obj.action === "alert") {
63
+ alert(obj.heading + "\n" + obj.text);
64
+ }
65
+
66
+ // CFB2 only
67
+ if (obj.action === "navigateTo") {
68
+ if (obj.location === 'home') {
69
+ document.location = 'zcanvas.html';
70
+ } else {
71
+ alert('Pretend you have navigated to: ' + obj.location + '.');
72
+ }
73
+ }
74
+
75
+ // Client.notify logs notifications to the console.
76
+ if (window.console && window.console.log) {
77
+ var arr = [];
78
+ for (var prop in obj) {
79
+ arr.push(prop + ": " + obj[prop]);
80
+ }
81
+ console.log("))) Client.notify({ " + arr.join(", ") + " })");
82
+ }
83
+ };
84
+
74
85
  // Set the view title
75
86
  Client.makeTitle = function(title) {
76
87
  $("#mock-center").html(title);
77
88
  };
78
89
 
79
90
  setTimeout(function() {
80
- $('#mock-toolbar').delegate('action', 'click', function(e) {
91
+ $('#mock-toolbar').on('click', 'action', function(e) {
81
92
  var name = $(e.target).attr('name');
82
93
  var value = $(e.target).attr('value');
83
94
 
@@ -86,5 +97,6 @@ setTimeout(function() {
86
97
  }, 400);
87
98
 
88
99
  Application.clientCallbackHandlers.push(function(name, value) {
89
- if (value === "Back") history.back();
100
+ if (value === 'Back') history.back();
101
+ if (value === 'Close') Client.callback('close');
90
102
  });
@@ -0,0 +1,55 @@
1
+ // If your view implements an initialization function, that function will be passed a parameter
2
+ // object containing all the query parameters in the URL that triggered the view's creation, plus
3
+ // all of those values that were assigned to the view when it was registered and bound to a name.
4
+ // It does not need to hold on to these values (although the base implementation of view does, as
5
+ // `this.params`). At the end of a view's create method, it should have inserted a dom element into
6
+ // the body of the page. This will be assigned as the "element" property to the view by the application,
7
+ // as it needs to be referenced outside your view class.
8
+ var View = Class.extend({
9
+ // This method should create (by any means desirable) a DOM element and insert it into the page.
10
+ // Our base implementation queries for an HTML fragment from the server, but this is up to
11
+ // your view implementation.
12
+ create: function() {
13
+ throw new Error("Create method not implemented in subclass");
14
+ },
15
+ // Title of this view. We may not actually use titles in this version of the application,
16
+ // but we needed to provide this in the past.
17
+ getTitle: function() {
18
+ throw new Error("getTitle method not implemented in subclass");
19
+ },
20
+ // The name of the view that is used to log metrics to Google Analytics. The view
21
+ // may also provide additional calls to `Client.notify({'metric': 'metricName'})` if it updates
22
+ // internally (changing tabs, for example).
23
+ getMetric: function() {
24
+ throw new Error("getMetric method not implemented in subclass");
25
+ },
26
+ getButtons: function() {
27
+ throw new Error("getButtons method not implemented in subclass");
28
+ },
29
+ // Send off any necessary notifications to the client. This avoids and issue on iOS where
30
+ // two notifications send right after one another causes one of them to fail.
31
+ getAction: function() {
32
+ throw new Error("getAction method not implemented in subclass");
33
+ },
34
+ // Tell the client what a filtereable view is filtered to.
35
+ getFilter: function() {
36
+ throw new Error("getFilter method not implemented in subclass");
37
+ },
38
+ // Tell the client what section we are in.
39
+ getSection: function() {
40
+ throw new Error("getSection method not implemented in subclass");
41
+ },
42
+ // Tell the client if a new ad should be displayed.
43
+ shouldRefreshAd: function() {
44
+ throw new Error("shouldRefreshAd method not implemented in subclass");
45
+ },
46
+ // Called before the view is appended to the page.
47
+ onViewChanged: function() {
48
+ console.log('### View#onViewChanged');
49
+ }
50
+ // The client has executed a callback on the web page, to pass a value to the page
51
+ // or to execute some functionality.
52
+ /*
53
+ ,onClientCallback( name, value ) {}
54
+ */
55
+ });
@@ -167,3 +167,15 @@ $.fixImage = function(elem, src) {
167
167
  }
168
168
  elem.fixed = true;
169
169
  };
170
+
171
+
172
+
173
+ var macrojungle = function(tmpl) {
174
+ // This is kind of stupid.
175
+ // But at least it's only written once.
176
+ var html = $('#tmp').empty().microjungle(tmpl).html();
177
+ // If we don't actually want to get any html back (just a string),
178
+ // we wrap the string in <tmp>string</tmp> and then remove
179
+ // the tags here.
180
+ return html.replace(/<(\/){0,1}tmp>/g, '');
181
+ };
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= CONFIG.app_path %> - <%= Rails.env %></title>
5
+ <meta name="viewport" content="user-scalable=no, initial-scale=1">
6
+ <%= stylesheet_link_tag "application" %>
7
+ </head>
8
+ <body>
9
+ <%= yield %>
10
+ <div id="app_wrapper">
11
+ <div id="flash" style="display:none"></div>
12
+ <div id="view_wrapper"></div>
13
+ <%= render "shared/footer" %>
14
+ <div id="loading" class="loading" style="display:none">
15
+ <div id="loading_text" class="loading_text">Loading&hellip;</div>
16
+ </div>
17
+ </div>
18
+ <div id="tmp" style="display:none"></div>
19
+ <%= javascript_include_tag "application" %>
20
+ <%# Allows us to use mock on test or production without screwing up caching of page. %>
21
+ <script>
22
+ if (Application.params.mock === 'true' || '<%= request.host %>' == 'localhost' || '<%= request.host %>'.indexOf('.dev') !== -1) {
23
+ document.write("<link rel='stylesheet' href='/<%= CONFIG.app_path %>/assets/mock.css'>");
24
+ document.write("<script src='/<%= CONFIG.app_path %>/assets/core/Mock.js'><\/script>");
25
+ }
26
+ </script>
27
+ </body>
28
+ </html>
@@ -1,3 +1,3 @@
1
1
  module SportsDb
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sports_db
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-06 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -52,10 +52,12 @@ extra_rdoc_files: []
52
52
  files:
53
53
  - app/assets/javascripts/clients/android/client.js
54
54
  - app/assets/javascripts/clients/ios/client.js
55
+ - app/assets/javascripts/core/BaseView.js
55
56
  - app/assets/javascripts/core/History.js
56
57
  - app/assets/javascripts/core/Mock.js
57
58
  - app/assets/javascripts/core/Timer.js
58
59
  - app/assets/javascripts/core/utilities.js
60
+ - app/assets/javascripts/core/View.js
59
61
  - app/assets/javascripts/libs/ICanHaz.js
60
62
  - app/assets/javascripts/libs/microjungle.zepto.js
61
63
  - app/assets/javascripts/libs/SimpleInheritance.js
@@ -113,6 +115,7 @@ files:
113
115
  - app/models/score_notification.rb
114
116
  - app/models/twitter.rb
115
117
  - app/views/application/load.html.erb
118
+ - app/views/layouts/application.html.erb
116
119
  - app/views/shared/_heading.html.erb
117
120
  - app/views/shared/_poster.html.erb
118
121
  - app/views/shared/_sharing.html.erb