sensu-dashboard-sonian 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +4 -0
  3. data/MIT-LICENSE.txt +20 -0
  4. data/README.org +4 -0
  5. data/Rakefile +1 -0
  6. data/bin/sensu-dashboard +9 -0
  7. data/lib/sensu-dashboard/app.rb +449 -0
  8. data/lib/sensu-dashboard/public/css/autoSuggest.css +217 -0
  9. data/lib/sensu-dashboard/public/css/style.css +177 -0
  10. data/lib/sensu-dashboard/public/img/cross.png +0 -0
  11. data/lib/sensu-dashboard/public/img/footer_bg.png +0 -0
  12. data/lib/sensu-dashboard/public/img/header_bg.png +0 -0
  13. data/lib/sensu-dashboard/public/img/loading_circle.gif +0 -0
  14. data/lib/sensu-dashboard/public/img/main_content_bg.png +0 -0
  15. data/lib/sensu-dashboard/public/img/megaphone_icon.png +0 -0
  16. data/lib/sensu-dashboard/public/img/megaphone_icon_off.png +0 -0
  17. data/lib/sensu-dashboard/public/js/FABridge.js +604 -0
  18. data/lib/sensu-dashboard/public/js/functions.js +379 -0
  19. data/lib/sensu-dashboard/public/js/jquery-1.5.1.min.js +16 -0
  20. data/lib/sensu-dashboard/public/js/jquery.autoSuggest.js +375 -0
  21. data/lib/sensu-dashboard/public/js/jquery.leanModal.min.js +1 -0
  22. data/lib/sensu-dashboard/public/js/jquery.sortElements.js +69 -0
  23. data/lib/sensu-dashboard/public/js/jquery.tmpl.min.js +1 -0
  24. data/lib/sensu-dashboard/public/js/jquery.zclip.min.js +12 -0
  25. data/lib/sensu-dashboard/public/js/modernizr-1.7.min.js +2 -0
  26. data/lib/sensu-dashboard/public/js/swfobject.js +4 -0
  27. data/lib/sensu-dashboard/public/js/web_socket.js +312 -0
  28. data/lib/sensu-dashboard/public/js/webtoolkit.sha1.js +174 -0
  29. data/lib/sensu-dashboard/public/swf/WebSocketMain.swf +0 -0
  30. data/lib/sensu-dashboard/public/swf/ZeroClipboard.swf +0 -0
  31. data/lib/sensu-dashboard/version.rb +5 -0
  32. data/lib/sensu-dashboard/views/client_templates.erb +68 -0
  33. data/lib/sensu-dashboard/views/clients.erb +37 -0
  34. data/lib/sensu-dashboard/views/event_templates.erb +190 -0
  35. data/lib/sensu-dashboard/views/index.erb +48 -0
  36. data/lib/sensu-dashboard/views/layout.erb +124 -0
  37. data/lib/sensu-dashboard/views/sonian.sass +213 -0
  38. data/lib/sensu-dashboard/views/stash_templates.erb +44 -0
  39. data/lib/sensu-dashboard/views/stashes.erb +32 -0
  40. data/sensu-dashboard.gemspec +22 -0
  41. metadata +166 -0
@@ -0,0 +1,217 @@
1
+ /* AutoSuggest CSS - Version 1.2 */
2
+
3
+ ul.as-selections {
4
+ list-style-type: none;
5
+ border-top: 1px solid #888;
6
+ border-bottom: 1px solid #b6b6b6;
7
+ border-left: 1px solid #aaa;
8
+ border-right: 1px solid #aaa;
9
+ padding: 4px 0 4px 4px;
10
+ margin: 0;
11
+ overflow: auto;
12
+ background-color: #fff;
13
+ box-shadow:inset 0 1px 2px #888;
14
+ -webkit-box-shadow:inset 0 1px 2px #888;
15
+ -moz-box-shadow:inset 0 1px 2px #888;
16
+ }
17
+
18
+ ul.as-selections.loading {
19
+ background-color: #eee;
20
+ }
21
+
22
+ ul.as-selections li {
23
+ float: left;
24
+ margin: 1px 4px 1px 0;
25
+ }
26
+
27
+ ul.as-selections li.as-selection-item {
28
+ color: #2b3840;
29
+ font-size: 13px;
30
+ font-family: "Lucida Grande", arial, sans-serif;
31
+ text-shadow: 0 1px 1px #fff;
32
+ background-color: #ddeefe;
33
+ background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#ddeefe), to(#bfe0f1));
34
+ border: 1px solid #acc3ec;
35
+ border-top-color: #c0d9e9;
36
+ padding: 2px 7px 2px 10px;
37
+ border-radius: 12px;
38
+ -webkit-border-radius: 12px;
39
+ -moz-border-radius: 12px;
40
+ box-shadow: 0 1px 1px #e4edf2;
41
+ -webkit-box-shadow: 0 1px 1px #e4edf2;
42
+ -moz-box-shadow: 0 1px 1px #e4edf2;
43
+ }
44
+
45
+ ul.as-selections li.as-selection-item:last-child {
46
+ margin-left: 30px;
47
+ }
48
+
49
+ ul.as-selections li.as-selection-item a.as-close {
50
+ float: right;
51
+ margin: 1px 0 0 7px;
52
+ padding: 0 2px;
53
+ cursor: pointer;
54
+ color: #5491be;
55
+ font-family: "Helvetica", helvetica, arial, sans-serif;
56
+ font-size: 14px;
57
+ font-weight: bold;
58
+ text-shadow: 0 1px 1px #fff;
59
+ -webkit-transition: color .1s ease-in;
60
+ }
61
+
62
+ ul.as-selections li.as-selection-item.blur {
63
+ color: #666666;
64
+ background-color: #f4f4f4;
65
+ background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#f4f4f4), to(#d5d5d5));
66
+ border-color: #bbb;
67
+ border-top-color: #ccc;
68
+ box-shadow: 0 1px 1px #e9e9e9;
69
+ -webkit-box-shadow: 0 1px 1px #e9e9e9;
70
+ -moz-box-shadow: 0 1px 1px #e9e9e9;
71
+ }
72
+
73
+ ul.as-selections li.as-selection-item.blur a.as-close {
74
+ color: #999;
75
+ }
76
+
77
+ ul.as-selections li:hover.as-selection-item {
78
+ color: #2b3840;
79
+ background-color: #bbd4f1;
80
+ background-image: -webkit-gradient(linear, 0% 0%, 0% 100%, from(#bbd4f1), to(#a3c2e5));
81
+ border-color: #6da0e0;
82
+ border-top-color: #8bb7ed;
83
+ }
84
+
85
+ ul.as-selections li:hover.as-selection-item a.as-close {
86
+ color: #4d70b0;
87
+ }
88
+
89
+ ul.as-selections li.as-selection-item.selected {
90
+ border-color: #1f30e4;
91
+ }
92
+
93
+ ul.as-selections li.as-selection-item a:hover.as-close {
94
+ color: #1b3c65;
95
+ }
96
+
97
+ ul.as-selections li.as-selection-item a:active.as-close {
98
+ color: #4d70b0;
99
+ }
100
+
101
+ ul.as-selections li.as-original {
102
+ margin-left: 0;
103
+ }
104
+
105
+ ul.as-selections li.as-original input {
106
+ border: none;
107
+ outline: none;
108
+ font-size: 13px;
109
+ width: 120px;
110
+ height: 18px;
111
+ padding-top: 3px;
112
+ }
113
+
114
+ ul.as-list {
115
+ position: absolute;
116
+ list-style-type: none;
117
+ margin: 2px 0 0 0;
118
+ padding: 0;
119
+ font-size: 14px;
120
+ color: #000;
121
+ font-family: "Lucida Grande", arial, sans-serif;
122
+ background-color: #fff;
123
+ background-color: rgba(255,255,255,0.95);
124
+ z-index: 2;
125
+ box-shadow: 0 2px 12px #222;
126
+ -webkit-box-shadow: 0 2px 12px #222;
127
+ -moz-box-shadow: 0 2px 12px #222;
128
+ border-radius: 5px;
129
+ -webkit-border-radius: 5px;
130
+ -moz-border-radius: 5px;
131
+ }
132
+
133
+ li.as-result-item, li.as-message {
134
+ margin: 0 0 0 0;
135
+ padding: 5px 12px;
136
+ background-color: transparent;
137
+ border: 1px solid #fff;
138
+ border-bottom: 1px solid #ddd;
139
+ cursor: pointer;
140
+ border-radius: 5px;
141
+ -webkit-border-radius: 5px;
142
+ -moz-border-radius: 5px;
143
+ }
144
+
145
+ li:first-child.as-result-item {
146
+ margin: 0;
147
+ }
148
+
149
+ li.as-message {
150
+ margin: 0;
151
+ cursor: default;
152
+ }
153
+
154
+ li.as-result-item.active {
155
+ background-color: #3668d9;
156
+ background-image: -webkit-gradient(linear, 0% 0%, 0% 64%, from(rgb(110, 129, 245)), to(rgb(62, 82, 242)));
157
+ border-color: #3342e8;
158
+ color: #fff;
159
+ text-shadow: 0 1px 2px #122042;
160
+ }
161
+
162
+ li.as-result-item em {
163
+ font-style: normal;
164
+ background: #444;
165
+ padding: 0 2px;
166
+ color: #fff;
167
+ }
168
+
169
+ li.as-result-item.active em {
170
+ background: #253f7a;
171
+ color: #fff;
172
+ }
173
+
174
+ /* Webkit Hacks */
175
+ @media screen and (-webkit-min-device-pixel-ratio:0) {
176
+ ul.as-selections {
177
+ border-top-width: 2px;
178
+ }
179
+ ul.as-selections li.as-selection-item {
180
+ padding-top: 3px;
181
+ padding-bottom: 3px;
182
+ }
183
+ ul.as-selections li.as-selection-item a.as-close {
184
+ margin-top: -1px;
185
+ }
186
+ ul.as-selections li.as-original input {
187
+ height: 19px;
188
+ }
189
+ }
190
+
191
+ /* Opera Hacks */
192
+ @media all and (-webkit-min-device-pixel-ratio:10000), not all and (-webkit-min-device-pixel-ratio:0) {
193
+ ul.as-list {
194
+ border: 1px solid #888;
195
+ }
196
+ ul.as-selections li.as-selection-item a.as-close {
197
+ margin-left: 4px;
198
+ margin-top: 0;
199
+ }
200
+ }
201
+
202
+ /* IE Hacks */
203
+ ul.as-list {
204
+ border: 1px solid #888\9;
205
+ }
206
+ ul.as-selections li.as-selection-item a.as-close {
207
+ margin-left: 4px\9;
208
+ margin-top: 0\9;
209
+ }
210
+
211
+ /* Firefox 3.0 Hacks */
212
+ ul.as-list, x:-moz-any-link, x:default {
213
+ border: 1px solid #888;
214
+ }
215
+ BODY:first-of-type ul.as-list, x:-moz-any-link, x:default { /* Target FF 3.5+ */
216
+ border: none;
217
+ }
@@ -0,0 +1,177 @@
1
+ /*
2
+ HTML5 Reset :: style.css
3
+ ----------------------------------------------------------
4
+ We have learned much from/been inspired by/taken code where offered from:
5
+
6
+ Eric Meyer :: http://ericmeyer.com
7
+ HTML5 Doctor :: http://html5doctor.com
8
+ and the HTML5 Boilerplate :: http://html5boilerplate.com
9
+
10
+ -------------------------------------------------------------------------------*/
11
+
12
+ /* Let's default this puppy out
13
+ -------------------------------------------------------------------------------*/
14
+
15
+ html, body, body div, span, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp, small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, figure, footer, header, hgroup, menu, nav, section, time, mark, audio, video {
16
+ margin: 0;
17
+ padding: 0;
18
+ border: 0;
19
+ outline: 0;
20
+ font-size: 100%;
21
+ vertical-align: baseline;
22
+ background: transparent;
23
+ }
24
+
25
+ article, aside, figure, footer, header, hgroup, nav, section {display: block;}
26
+
27
+ /* Responsive images and other embedded objects
28
+ Note: keeping IMG here will cause problems if you're using foreground images as sprites.
29
+ If this default setting for images is causing issues, you might want to replace it with a .responsive class instead. */
30
+ img,
31
+ object,
32
+ embed {max-width: 100%;}
33
+
34
+ /* force a vertical scrollbar to prevent a jumpy page */
35
+ html {overflow-y: scroll;}
36
+
37
+ /* we use a lot of ULs that aren't bulleted.
38
+ don't forget to restore the bullets within content. */
39
+ ul {list-style: none;}
40
+
41
+ blockquote, q {quotes: none;}
42
+
43
+ blockquote:before,
44
+ blockquote:after,
45
+ q:before,
46
+ q:after {content: ''; content: none;}
47
+
48
+ a {margin: 0; padding: 0; font-size: 100%; vertical-align: baseline; background: transparent;}
49
+
50
+ del {text-decoration: line-through;}
51
+
52
+ abbr[title], dfn[title] {border-bottom: 1px dotted #000; cursor: help;}
53
+
54
+ /* tables still need cellspacing="0" in the markup */
55
+ table {border-collapse: collapse; border-spacing: 0;}
56
+ th {font-weight: bold; vertical-align: bottom;}
57
+ td {font-weight: normal; vertical-align: top;}
58
+
59
+ hr {display: block; height: 1px; border: 0; border-top: 1px solid #ccc; margin: 1em 0; padding: 0;}
60
+
61
+ input, select {vertical-align: middle;}
62
+
63
+ pre {
64
+ white-space: pre; /* CSS2 */
65
+ white-space: pre-wrap; /* CSS 2.1 */
66
+ white-space: pre-line; /* CSS 3 (and 2.1 as well, actually) */
67
+ word-wrap: break-word; /* IE */
68
+ }
69
+
70
+ input[type="radio"] {vertical-align: text-bottom;}
71
+ input[type="checkbox"] {vertical-align: bottom; *vertical-align: baseline;}
72
+ .ie6 input {vertical-align: text-bottom;}
73
+
74
+ select, input, textarea {font: 99% sans-serif;}
75
+
76
+ table {font-size: inherit; font: 100%;}
77
+
78
+ /* Accessible focus treatment
79
+ people.opera.com/patrickl/experiments/keyboard/test */
80
+ a:hover, a:active {outline: none;}
81
+
82
+ small {font-size: 85%;}
83
+
84
+ strong, th {font-weight: bold;}
85
+
86
+ td, td img {vertical-align: top;}
87
+
88
+ /* Make sure sup and sub don't screw with your line-heights
89
+ gist.github.com/413930 */
90
+ sub, sup {font-size: 75%; line-height: 0; position: relative;}
91
+ sup {top: -0.5em;}
92
+ sub {bottom: -0.25em;}
93
+
94
+ /* standardize any monospaced elements */
95
+ pre, code, kbd, samp {font-family: monospace, sans-serif;}
96
+
97
+ /* hand cursor on clickable elements */
98
+ .clickable,
99
+ label,
100
+ input[type=button],
101
+ input[type=submit],
102
+ button {cursor: pointer;}
103
+
104
+ /* Webkit browsers add a 2px margin outside the chrome of form elements */
105
+ button, input, select, textarea {margin: 0;}
106
+
107
+ /* make buttons play nice in IE */
108
+ button {width: auto; overflow: visible;}
109
+
110
+ /* scale images in IE7 more attractively */
111
+ .ie7 img {-ms-interpolation-mode: bicubic;}
112
+
113
+ /* prevent BG image flicker upon hover */
114
+ .ie6 html {filter: expression(document.execCommand("BackgroundImageCache", false, true));}
115
+
116
+ /* let's clear some floats */
117
+ .clearfix:before, .clearfix:after { content: "\0020"; display: block; height: 0; overflow: hidden; }
118
+ .clearfix:after { clear: both; }
119
+ .clearfix { zoom: 1; }
120
+
121
+
122
+
123
+ /* Ok, this is where the fun starts.
124
+ -------------------------------------------------------------------------------*/
125
+
126
+ /* new Linux- and Windows-friendly sans-serif font stack: http://mky.be/fontstack */
127
+ body {font: 13px Helmet, Freesans, sans-serif;}
128
+
129
+ /* using local fonts? make sure to read up on Paul Irish's
130
+ Bulletproof @font-face syntax: http://mky.be/font-face/bulletproof/ */
131
+
132
+ /* we like off-black for text */
133
+ body, select, input, textarea {color: #333;}
134
+
135
+ a {color: #03f;}
136
+ a:hover {color: #69f;}
137
+
138
+ /* Custom text-selection colors (remove any text shadows: twitter.com/miketaylr/status/12228805301) */
139
+ ::-moz-selection{background: #920000; color: #fff; text-shadow: none;}
140
+ ::selection {background: #920000; color: #fff; text-shadow: none;}
141
+
142
+ /* j.mp/webkit-tap-highlight-color */
143
+ a:link {-webkit-tap-highlight-color: #fcd700;}
144
+
145
+ ins {background-color: #fcd700; color: #000; text-decoration: none;}
146
+ mark {background-color: #fcd700; color: #000; font-style: italic; font-weight: bold;}
147
+
148
+
149
+
150
+
151
+
152
+ /* Print styles!
153
+ -------------------------------------------------------------------------------*/
154
+ @media print {
155
+
156
+
157
+
158
+ }
159
+
160
+
161
+ /* Media queries!
162
+ -------------------------------------------------------------------------------*/
163
+
164
+ /* Consider this: www.cloudfour.com/css-media-query-for-mobile-is-fools-gold/ */
165
+ @media screen and (max-device-width: 480px) {
166
+
167
+
168
+ }
169
+
170
+ @media all and (orientation: portrait) {
171
+
172
+ }
173
+
174
+ @media all and (orientation: landscape) {
175
+
176
+ }
177
+
@@ -0,0 +1,604 @@
1
+ /*
2
+ /*
3
+ Copyright 2006 Adobe Systems Incorporated
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
6
+ to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
7
+ and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8
+
9
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
10
+
11
+
12
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
14
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
15
+ OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
16
+
17
+ */
18
+
19
+
20
+ /*
21
+ * The Bridge class, responsible for navigating AS instances
22
+ */
23
+ function FABridge(target,bridgeName)
24
+ {
25
+ this.target = target;
26
+ this.remoteTypeCache = {};
27
+ this.remoteInstanceCache = {};
28
+ this.remoteFunctionCache = {};
29
+ this.localFunctionCache = {};
30
+ this.bridgeID = FABridge.nextBridgeID++;
31
+ this.name = bridgeName;
32
+ this.nextLocalFuncID = 0;
33
+ FABridge.instances[this.name] = this;
34
+ FABridge.idMap[this.bridgeID] = this;
35
+
36
+ return this;
37
+ }
38
+
39
+ // type codes for packed values
40
+ FABridge.TYPE_ASINSTANCE = 1;
41
+ FABridge.TYPE_ASFUNCTION = 2;
42
+
43
+ FABridge.TYPE_JSFUNCTION = 3;
44
+ FABridge.TYPE_ANONYMOUS = 4;
45
+
46
+ FABridge.initCallbacks = {};
47
+ FABridge.userTypes = {};
48
+
49
+ FABridge.addToUserTypes = function()
50
+ {
51
+ for (var i = 0; i < arguments.length; i++)
52
+ {
53
+ FABridge.userTypes[arguments[i]] = {
54
+ 'typeName': arguments[i],
55
+ 'enriched': false
56
+ };
57
+ }
58
+ }
59
+
60
+ FABridge.argsToArray = function(args)
61
+ {
62
+ var result = [];
63
+ for (var i = 0; i < args.length; i++)
64
+ {
65
+ result[i] = args[i];
66
+ }
67
+ return result;
68
+ }
69
+
70
+ function instanceFactory(objID)
71
+ {
72
+ this.fb_instance_id = objID;
73
+ return this;
74
+ }
75
+
76
+ function FABridge__invokeJSFunction(args)
77
+ {
78
+ var funcID = args[0];
79
+ var throughArgs = args.concat();//FABridge.argsToArray(arguments);
80
+ throughArgs.shift();
81
+
82
+ var bridge = FABridge.extractBridgeFromID(funcID);
83
+ return bridge.invokeLocalFunction(funcID, throughArgs);
84
+ }
85
+
86
+ FABridge.addInitializationCallback = function(bridgeName, callback)
87
+ {
88
+ var inst = FABridge.instances[bridgeName];
89
+ if (inst != undefined)
90
+ {
91
+ callback.call(inst);
92
+ return;
93
+ }
94
+
95
+ var callbackList = FABridge.initCallbacks[bridgeName];
96
+ if(callbackList == null)
97
+ {
98
+ FABridge.initCallbacks[bridgeName] = callbackList = [];
99
+ }
100
+
101
+ callbackList.push(callback);
102
+ }
103
+
104
+ // updated for changes to SWFObject2
105
+ function FABridge__bridgeInitialized(bridgeName) {
106
+ var objects = document.getElementsByTagName("object");
107
+ var ol = objects.length;
108
+ var activeObjects = [];
109
+ if (ol > 0) {
110
+ for (var i = 0; i < ol; i++) {
111
+ if (typeof objects[i].SetVariable != "undefined") {
112
+ activeObjects[activeObjects.length] = objects[i];
113
+ }
114
+ }
115
+ }
116
+ var embeds = document.getElementsByTagName("embed");
117
+ var el = embeds.length;
118
+ var activeEmbeds = [];
119
+ if (el > 0) {
120
+ for (var j = 0; j < el; j++) {
121
+ if (typeof embeds[j].SetVariable != "undefined") {
122
+ activeEmbeds[activeEmbeds.length] = embeds[j];
123
+ }
124
+ }
125
+ }
126
+ var aol = activeObjects.length;
127
+ var ael = activeEmbeds.length;
128
+ var searchStr = "bridgeName="+ bridgeName;
129
+ if ((aol == 1 && !ael) || (aol == 1 && ael == 1)) {
130
+ FABridge.attachBridge(activeObjects[0], bridgeName);
131
+ }
132
+ else if (ael == 1 && !aol) {
133
+ FABridge.attachBridge(activeEmbeds[0], bridgeName);
134
+ }
135
+ else {
136
+ var flash_found = false;
137
+ if (aol > 1) {
138
+ for (var k = 0; k < aol; k++) {
139
+ var params = activeObjects[k].childNodes;
140
+ for (var l = 0; l < params.length; l++) {
141
+ var param = params[l];
142
+ if (param.nodeType == 1 && param.tagName.toLowerCase() == "param" && param["name"].toLowerCase() == "flashvars" && param["value"].indexOf(searchStr) >= 0) {
143
+ FABridge.attachBridge(activeObjects[k], bridgeName);
144
+ flash_found = true;
145
+ break;
146
+ }
147
+ }
148
+ if (flash_found) {
149
+ break;
150
+ }
151
+ }
152
+ }
153
+ if (!flash_found && ael > 1) {
154
+ for (var m = 0; m < ael; m++) {
155
+ var flashVars = activeEmbeds[m].attributes.getNamedItem("flashVars").nodeValue;
156
+ if (flashVars.indexOf(searchStr) >= 0) {
157
+ FABridge.attachBridge(activeEmbeds[m], bridgeName);
158
+ break;
159
+ }
160
+ }
161
+ }
162
+ }
163
+ return true;
164
+ }
165
+
166
+ // used to track multiple bridge instances, since callbacks from AS are global across the page.
167
+
168
+ FABridge.nextBridgeID = 0;
169
+ FABridge.instances = {};
170
+ FABridge.idMap = {};
171
+ FABridge.refCount = 0;
172
+
173
+ FABridge.extractBridgeFromID = function(id)
174
+ {
175
+ var bridgeID = (id >> 16);
176
+ return FABridge.idMap[bridgeID];
177
+ }
178
+
179
+ FABridge.attachBridge = function(instance, bridgeName)
180
+ {
181
+ var newBridgeInstance = new FABridge(instance, bridgeName);
182
+
183
+ FABridge[bridgeName] = newBridgeInstance;
184
+
185
+ /* FABridge[bridgeName] = function() {
186
+ return newBridgeInstance.root();
187
+ }
188
+ */
189
+ var callbacks = FABridge.initCallbacks[bridgeName];
190
+ if (callbacks == null)
191
+ {
192
+ return;
193
+ }
194
+ for (var i = 0; i < callbacks.length; i++)
195
+ {
196
+ callbacks[i].call(newBridgeInstance);
197
+ }
198
+ delete FABridge.initCallbacks[bridgeName]
199
+ }
200
+
201
+ // some methods can't be proxied. You can use the explicit get,set, and call methods if necessary.
202
+
203
+ FABridge.blockedMethods =
204
+ {
205
+ toString: true,
206
+ get: true,
207
+ set: true,
208
+ call: true
209
+ };
210
+
211
+ FABridge.prototype =
212
+ {
213
+
214
+
215
+ // bootstrapping
216
+
217
+ root: function()
218
+ {
219
+ return this.deserialize(this.target.getRoot());
220
+ },
221
+ //clears all of the AS objects in the cache maps
222
+ releaseASObjects: function()
223
+ {
224
+ return this.target.releaseASObjects();
225
+ },
226
+ //clears a specific object in AS from the type maps
227
+ releaseNamedASObject: function(value)
228
+ {
229
+ if(typeof(value) != "object")
230
+ {
231
+ return false;
232
+ }
233
+ else
234
+ {
235
+ var ret = this.target.releaseNamedASObject(value.fb_instance_id);
236
+ return ret;
237
+ }
238
+ },
239
+ //create a new AS Object
240
+ create: function(className)
241
+ {
242
+ return this.deserialize(this.target.create(className));
243
+ },
244
+
245
+
246
+ // utilities
247
+
248
+ makeID: function(token)
249
+ {
250
+ return (this.bridgeID << 16) + token;
251
+ },
252
+
253
+
254
+ // low level access to the flash object
255
+
256
+ //get a named property from an AS object
257
+ getPropertyFromAS: function(objRef, propName)
258
+ {
259
+ if (FABridge.refCount > 0)
260
+ {
261
+ throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
262
+ }
263
+ else
264
+ {
265
+ FABridge.refCount++;
266
+ retVal = this.target.getPropFromAS(objRef, propName);
267
+ retVal = this.handleError(retVal);
268
+ FABridge.refCount--;
269
+ return retVal;
270
+ }
271
+ },
272
+ //set a named property on an AS object
273
+ setPropertyInAS: function(objRef,propName, value)
274
+ {
275
+ if (FABridge.refCount > 0)
276
+ {
277
+ throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
278
+ }
279
+ else
280
+ {
281
+ FABridge.refCount++;
282
+ retVal = this.target.setPropInAS(objRef,propName, this.serialize(value));
283
+ retVal = this.handleError(retVal);
284
+ FABridge.refCount--;
285
+ return retVal;
286
+ }
287
+ },
288
+
289
+ //call an AS function
290
+ callASFunction: function(funcID, args)
291
+ {
292
+ if (FABridge.refCount > 0)
293
+ {
294
+ throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
295
+ }
296
+ else
297
+ {
298
+ FABridge.refCount++;
299
+ retVal = this.target.invokeASFunction(funcID, this.serialize(args));
300
+ retVal = this.handleError(retVal);
301
+ FABridge.refCount--;
302
+ return retVal;
303
+ }
304
+ },
305
+ //call a method on an AS object
306
+ callASMethod: function(objID, funcName, args)
307
+ {
308
+ if (FABridge.refCount > 0)
309
+ {
310
+ throw new Error("You are trying to call recursively into the Flash Player which is not allowed. In most cases the JavaScript setTimeout function, can be used as a workaround.");
311
+ }
312
+ else
313
+ {
314
+ FABridge.refCount++;
315
+ args = this.serialize(args);
316
+ retVal = this.target.invokeASMethod(objID, funcName, args);
317
+ retVal = this.handleError(retVal);
318
+ FABridge.refCount--;
319
+ return retVal;
320
+ }
321
+ },
322
+
323
+ // responders to remote calls from flash
324
+
325
+ //callback from flash that executes a local JS function
326
+ //used mostly when setting js functions as callbacks on events
327
+ invokeLocalFunction: function(funcID, args)
328
+ {
329
+ var result;
330
+ var func = this.localFunctionCache[funcID];
331
+
332
+ if(func != undefined)
333
+ {
334
+ result = this.serialize(func.apply(null, this.deserialize(args)));
335
+ }
336
+
337
+ return result;
338
+ },
339
+
340
+ // Object Types and Proxies
341
+
342
+ // accepts an object reference, returns a type object matching the obj reference.
343
+ getTypeFromName: function(objTypeName)
344
+ {
345
+ return this.remoteTypeCache[objTypeName];
346
+ },
347
+ //create an AS proxy for the given object ID and type
348
+ createProxy: function(objID, typeName)
349
+ {
350
+ var objType = this.getTypeFromName(typeName);
351
+ instanceFactory.prototype = objType;
352
+ var instance = new instanceFactory(objID);
353
+ this.remoteInstanceCache[objID] = instance;
354
+ return instance;
355
+ },
356
+ //return the proxy associated with the given object ID
357
+ getProxy: function(objID)
358
+ {
359
+ return this.remoteInstanceCache[objID];
360
+ },
361
+
362
+ // accepts a type structure, returns a constructed type
363
+ addTypeDataToCache: function(typeData)
364
+ {
365
+ newType = new ASProxy(this, typeData.name);
366
+ var accessors = typeData.accessors;
367
+ for (var i = 0; i < accessors.length; i++)
368
+ {
369
+ this.addPropertyToType(newType, accessors[i]);
370
+ }
371
+
372
+ var methods = typeData.methods;
373
+ for (var i = 0; i < methods.length; i++)
374
+ {
375
+ if (FABridge.blockedMethods[methods[i]] == undefined)
376
+ {
377
+ this.addMethodToType(newType, methods[i]);
378
+ }
379
+ }
380
+
381
+
382
+ this.remoteTypeCache[newType.typeName] = newType;
383
+ return newType;
384
+ },
385
+
386
+ //add a property to a typename; used to define the properties that can be called on an AS proxied object
387
+ addPropertyToType: function(ty, propName)
388
+ {
389
+ var c = propName.charAt(0);
390
+ var setterName;
391
+ var getterName;
392
+ if(c >= "a" && c <= "z")
393
+ {
394
+ getterName = "get" + c.toUpperCase() + propName.substr(1);
395
+ setterName = "set" + c.toUpperCase() + propName.substr(1);
396
+ }
397
+ else
398
+ {
399
+ getterName = "get" + propName;
400
+ setterName = "set" + propName;
401
+ }
402
+ ty[setterName] = function(val)
403
+ {
404
+ this.bridge.setPropertyInAS(this.fb_instance_id, propName, val);
405
+ }
406
+ ty[getterName] = function()
407
+ {
408
+ return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
409
+ }
410
+ },
411
+
412
+ //add a method to a typename; used to define the methods that can be callefd on an AS proxied object
413
+ addMethodToType: function(ty, methodName)
414
+ {
415
+ ty[methodName] = function()
416
+ {
417
+ return this.bridge.deserialize(this.bridge.callASMethod(this.fb_instance_id, methodName, FABridge.argsToArray(arguments)));
418
+ }
419
+ },
420
+
421
+ // Function Proxies
422
+
423
+ //returns the AS proxy for the specified function ID
424
+ getFunctionProxy: function(funcID)
425
+ {
426
+ var bridge = this;
427
+ if (this.remoteFunctionCache[funcID] == null)
428
+ {
429
+ this.remoteFunctionCache[funcID] = function()
430
+ {
431
+ bridge.callASFunction(funcID, FABridge.argsToArray(arguments));
432
+ }
433
+ }
434
+ return this.remoteFunctionCache[funcID];
435
+ },
436
+
437
+ //reutrns the ID of the given function; if it doesnt exist it is created and added to the local cache
438
+ getFunctionID: function(func)
439
+ {
440
+ if (func.__bridge_id__ == undefined)
441
+ {
442
+ func.__bridge_id__ = this.makeID(this.nextLocalFuncID++);
443
+ this.localFunctionCache[func.__bridge_id__] = func;
444
+ }
445
+ return func.__bridge_id__;
446
+ },
447
+
448
+ // serialization / deserialization
449
+
450
+ serialize: function(value)
451
+ {
452
+ var result = {};
453
+
454
+ var t = typeof(value);
455
+ //primitives are kept as such
456
+ if (t == "number" || t == "string" || t == "boolean" || t == null || t == undefined)
457
+ {
458
+ result = value;
459
+ }
460
+ else if (value instanceof Array)
461
+ {
462
+ //arrays are serializesd recursively
463
+ result = [];
464
+ for (var i = 0; i < value.length; i++)
465
+ {
466
+ result[i] = this.serialize(value[i]);
467
+ }
468
+ }
469
+ else if (t == "function")
470
+ {
471
+ //js functions are assigned an ID and stored in the local cache
472
+ result.type = FABridge.TYPE_JSFUNCTION;
473
+ result.value = this.getFunctionID(value);
474
+ }
475
+ else if (value instanceof ASProxy)
476
+ {
477
+ result.type = FABridge.TYPE_ASINSTANCE;
478
+ result.value = value.fb_instance_id;
479
+ }
480
+ else
481
+ {
482
+ result.type = FABridge.TYPE_ANONYMOUS;
483
+ result.value = value;
484
+ }
485
+
486
+ return result;
487
+ },
488
+
489
+ //on deserialization we always check the return for the specific error code that is used to marshall NPE's into JS errors
490
+ // the unpacking is done by returning the value on each pachet for objects/arrays
491
+ deserialize: function(packedValue)
492
+ {
493
+
494
+ var result;
495
+
496
+ var t = typeof(packedValue);
497
+ if (t == "number" || t == "string" || t == "boolean" || packedValue == null || packedValue == undefined)
498
+ {
499
+ result = this.handleError(packedValue);
500
+ }
501
+ else if (packedValue instanceof Array)
502
+ {
503
+ result = [];
504
+ for (var i = 0; i < packedValue.length; i++)
505
+ {
506
+ result[i] = this.deserialize(packedValue[i]);
507
+ }
508
+ }
509
+ else if (t == "object")
510
+ {
511
+ for(var i = 0; i < packedValue.newTypes.length; i++)
512
+ {
513
+ this.addTypeDataToCache(packedValue.newTypes[i]);
514
+ }
515
+ for (var aRefID in packedValue.newRefs)
516
+ {
517
+ this.createProxy(aRefID, packedValue.newRefs[aRefID]);
518
+ }
519
+ if (packedValue.type == FABridge.TYPE_PRIMITIVE)
520
+ {
521
+ result = packedValue.value;
522
+ }
523
+ else if (packedValue.type == FABridge.TYPE_ASFUNCTION)
524
+ {
525
+ result = this.getFunctionProxy(packedValue.value);
526
+ }
527
+ else if (packedValue.type == FABridge.TYPE_ASINSTANCE)
528
+ {
529
+ result = this.getProxy(packedValue.value);
530
+ }
531
+ else if (packedValue.type == FABridge.TYPE_ANONYMOUS)
532
+ {
533
+ result = packedValue.value;
534
+ }
535
+ }
536
+ return result;
537
+ },
538
+ //increases the reference count for the given object
539
+ addRef: function(obj)
540
+ {
541
+ this.target.incRef(obj.fb_instance_id);
542
+ },
543
+ //decrease the reference count for the given object and release it if needed
544
+ release:function(obj)
545
+ {
546
+ this.target.releaseRef(obj.fb_instance_id);
547
+ },
548
+
549
+ // check the given value for the components of the hard-coded error code : __FLASHERROR
550
+ // used to marshall NPE's into flash
551
+
552
+ handleError: function(value)
553
+ {
554
+ if (typeof(value)=="string" && value.indexOf("__FLASHERROR")==0)
555
+ {
556
+ var myErrorMessage = value.split("||");
557
+ if(FABridge.refCount > 0 )
558
+ {
559
+ FABridge.refCount--;
560
+ }
561
+ throw new Error(myErrorMessage[1]);
562
+ return value;
563
+ }
564
+ else
565
+ {
566
+ return value;
567
+ }
568
+ }
569
+ };
570
+
571
+ // The root ASProxy class that facades a flash object
572
+
573
+ ASProxy = function(bridge, typeName)
574
+ {
575
+ this.bridge = bridge;
576
+ this.typeName = typeName;
577
+ return this;
578
+ };
579
+ //methods available on each ASProxy object
580
+ ASProxy.prototype =
581
+ {
582
+ get: function(propName)
583
+ {
584
+ return this.bridge.deserialize(this.bridge.getPropertyFromAS(this.fb_instance_id, propName));
585
+ },
586
+
587
+ set: function(propName, value)
588
+ {
589
+ this.bridge.setPropertyInAS(this.fb_instance_id, propName, value);
590
+ },
591
+
592
+ call: function(funcName, args)
593
+ {
594
+ this.bridge.callASMethod(this.fb_instance_id, funcName, args);
595
+ },
596
+
597
+ addRef: function() {
598
+ this.bridge.addRef(this);
599
+ },
600
+
601
+ release: function() {
602
+ this.bridge.release(this);
603
+ }
604
+ };