fanforce-plugin-factory 2.0.0.rc3 → 2.0.0.rc5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. checksums.yaml +5 -13
  2. data/.ruby-version +1 -1
  3. data/Gemfile +2 -0
  4. data/README.md +1 -1
  5. data/fanforce-plugin-factory.gemspec +16 -16
  6. data/lib/fanforce/plugin_factory/Rakefile +2 -0
  7. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/_directives.scss +1 -0
  8. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/campaign-added/_campaign-added.coffee +21 -0
  9. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/campaign-added/_campaign-added.scss +15 -0
  10. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/initiative-added/_initiative-added.coffee +1 -1
  11. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/directives/page/_page.scss +1 -1
  12. data/lib/fanforce/plugin_factory/asset_framework/plugin_factory/vendors/cross-dresser.js +698 -0
  13. data/lib/fanforce/plugin_factory/core_config.rb +31 -14
  14. data/lib/fanforce/plugin_factory/directive_views/campaign-added.haml +13 -0
  15. data/lib/fanforce/plugin_factory/directive_views/initiative-added.haml +3 -3
  16. data/lib/fanforce/plugin_factory/scaffolding/._Gemfile.registry +2 -0
  17. data/lib/fanforce/plugin_factory/scaffolding/Gemfile +1 -1
  18. data/lib/fanforce/plugin_factory/scaffolding/assets/css/._fembedded.scss.registry +3 -0
  19. data/lib/fanforce/plugin_factory/scaffolding/assets/css/._fembedded_native.scss.registry +2 -0
  20. data/lib/fanforce/plugin_factory/scaffolding/assets/css/fembedded.scss +3 -4
  21. data/lib/fanforce/plugin_factory/scaffolding/assets/css/fembedded_native.scss +3 -3
  22. data/lib/fanforce/plugin_factory/scaffolding/assets/js/._app-fembedded.coffee.registry +2 -0
  23. data/lib/fanforce/plugin_factory/scaffolding/assets/js/._fembedded.js.registry +2 -0
  24. data/lib/fanforce/plugin_factory/scaffolding/assets/js/app-fembedded.coffee +11 -0
  25. data/lib/fanforce/plugin_factory/scaffolding/assets/js/lib/._cookie.coffee.registry +1 -0
  26. data/lib/fanforce/plugin_factory/scaffolding/assets/js/lib/cookie.coffee +1 -1
  27. data/lib/fanforce/plugin_factory/scaffolding/layouts/._fembedded.haml.registry +7 -0
  28. data/lib/fanforce/plugin_factory/scaffolding/layouts/._fembedded_native.haml.registry +2 -0
  29. data/lib/fanforce/plugin_factory/scaffolding/layouts/._promotional.haml.registry +2 -0
  30. data/lib/fanforce/plugin_factory/scaffolding/layouts/._visitor.haml.registry +1 -0
  31. data/lib/fanforce/plugin_factory/scaffolding/layouts/fembedded.haml +12 -9
  32. data/lib/fanforce/plugin_factory/scaffolding/layouts/fembedded_native.haml +3 -1
  33. data/lib/fanforce/plugin_factory/scaffolding/layouts/promotional.haml +5 -6
  34. data/lib/fanforce/plugin_factory/scaffolding/layouts/visitor.haml +22 -20
  35. data/lib/fanforce/plugin_factory/scaffolding/views/._cross-dresser.html.registry +2 -0
  36. data/lib/fanforce/plugin_factory/scaffolding/views/._index.haml.registry +1 -0
  37. data/lib/fanforce/plugin_factory/scaffolding/views/cross-dresser.html +26 -0
  38. data/lib/fanforce/plugin_factory/scaffolding/views/index.haml +3 -2
  39. data/lib/fanforce/plugin_factory/sinatra/_load.rb +25 -7
  40. data/lib/fanforce/plugin_factory/sinatra/helpers/fanforce.rb +2 -1
  41. data/lib/fanforce/plugin_factory/sinatra/route_helpers/base.rb +13 -0
  42. data/lib/fanforce/plugin_factory/sinatra/route_helpers/com_campaign.rb +7 -0
  43. data/lib/fanforce/plugin_factory/sinatra/route_helpers/com_database.rb +11 -0
  44. data/lib/fanforce/plugin_factory/sinatra/{helper_routes → route_helpers}/com_identifier.rb +0 -0
  45. data/lib/fanforce/plugin_factory/sinatra/{helper_routes → route_helpers}/com_initiative.rb +6 -3
  46. data/lib/fanforce/plugin_factory/sinatra/{helper_routes → route_helpers}/com_js_widget.rb +0 -0
  47. data/lib/fanforce/plugin_factory/sinatra/{helper_routes → route_helpers}/plugin.rb +1 -1
  48. data/lib/fanforce/plugin_factory/version.rb +1 -1
  49. metadata +131 -110
  50. data/lib/fanforce/plugin_factory/sinatra/helper_routes/com_campaign.rb +0 -11
  51. data/lib/fanforce/plugin_factory/sinatra/helper_routes/com_database.rb +0 -11
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjE0YjljNWI1NGZhMjRmNWQyNmM5M2Y5YTQxMzM3NWFlZWVhODE0Ng==
5
- data.tar.gz: !binary |-
6
- ZmMwYTI3NTI0NTE1OTk3M2ZjYjM1YzUxNGIzOWRhN2YzYjZlNjY3Mg==
2
+ SHA1:
3
+ metadata.gz: 15f4a3def684be1f6d5ff4b73e3cdb9b1910b67a
4
+ data.tar.gz: b046c14c20345ccb61da8988cfc374efb7aba067
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- OGM3Mzc3NzYxMjVkMzk0MjcxZTkyNTc1ZDI4OGZlYzViOGQxY2FjMDE1NTIw
10
- ZTNiNGRmZTExY2RhNDMyNmY5M2U0NzUwMjlmNDAxNDM4NjEzMzU3YTYzNWM1
11
- M2Q3ZWMwYzVjYmVmMGZhMTViNjQ1YjZmNjAyN2E3MWI2ZTI2YjM=
12
- data.tar.gz: !binary |-
13
- M2Y1MDI5MTdlNmZmNGJiOGFkM2U0ZmFiZTEyNmZmZDY0NjYxYjllZTA5YWMx
14
- YzBlZDA0ODViNTA4MzA3ZjU2MTM1ZGFkNmQ2MGUyYTk1NDM4ZThkZTQzYTM1
15
- ODczOWM0NTQzN2FhYzc2Y2Y1N2ZjNGU4YjA1NmZkMWJkNTEwM2E=
6
+ metadata.gz: bb2461aa38d0eb742520a754710c866e6e26f4268d77c44063464277044edc23b469216a37817f937adb6aafab85ec84965ecfe24067c1774691041a9ac63f0b
7
+ data.tar.gz: 237f6beca5f5177a757c1432b9dd29ba070c8c206d47f7339753ea0bc127cb7f95663b78751da24693ffcee84201ec05820ea141e9592b77826b188e3b4dbe08
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 1.9.3-p194
1
+ 2.1.6
data/Gemfile CHANGED
@@ -2,6 +2,8 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  group :development, :test do
5
+ gem 'fanforce-cli', '= 2.0.0.rc11'
6
+ gem 'rake', '~> 10.4.2'
5
7
  gem 'minitest'
6
8
  gem 'rack-test'
7
9
  gem 'simplecov', :require => false
data/README.md CHANGED
@@ -13,7 +13,7 @@ Since the fanforce-plugin-factory gem is hosted on a private gem server so you'l
13
13
  ```ruby
14
14
  source 'https://rubygems.org'
15
15
  source 'https://gems.gemfury.com/xF8KY9sm8eS9yUQqw1jD/'
16
- ruby '1.9.3'
16
+ ruby '2.1.6'
17
17
 
18
18
  gem 'fanforce-plugin-factory'
19
19
  ```
@@ -16,30 +16,30 @@ Gem::Specification.new do |gem|
16
16
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
17
17
  gem.require_paths = ['lib']
18
18
 
19
- gem.add_runtime_dependency 'rake', '~> 10.3.2'
19
+ gem.add_runtime_dependency 'rake', '~> 10.4.2'
20
20
  gem.add_runtime_dependency 'redis', '~> 3.1.0'
21
21
  gem.add_runtime_dependency 'sinatra', '~> 1.4.5'
22
- gem.add_runtime_dependency 'sinatra-contrib', '~> 1.4.2'
23
22
  gem.add_runtime_dependency 'rack-contrib', '~> 1.2.0'
24
23
  gem.add_runtime_dependency 'rack-cors', '~> 0.2'
25
- gem.add_runtime_dependency 'haml', '~> 4.0.5'
26
- gem.add_runtime_dependency 'coffee-script', '~> 2.3.0'
24
+ gem.add_runtime_dependency 'rack-jsonr', '~> 0.3.0'
25
+ gem.add_runtime_dependency 'rack-jquery-params','~> 0.1.1'
27
26
 
28
- gem.add_runtime_dependency 'sass', '~> 3.4.5'
27
+ gem.add_runtime_dependency 'haml', '~> 4.0.5'
28
+ gem.add_runtime_dependency 'coffee-script', '~> 2.4.1'
29
+ gem.add_runtime_dependency 'coffee-script-source','= 1.8.0'
30
+ gem.add_runtime_dependency 'sass', '~> 3.4.13'
29
31
  gem.add_runtime_dependency 'compass', '~> 1.0.1'
30
- gem.add_runtime_dependency 'sprockets', '~> 2.12.2'
31
- gem.add_runtime_dependency 'sprockets-sass', '~> 1.2.0'
32
+ gem.add_runtime_dependency 'sprockets', '~> 2.12.3'
33
+ gem.add_runtime_dependency 'sprockets-sass', '~> 1.3.1'
32
34
  gem.add_runtime_dependency 'yui-compressor', '~> 0.12.0'
33
- gem.add_runtime_dependency 'uglifier', '~> 2.5.3'
35
+ gem.add_runtime_dependency 'uglifier', '~> 2.7.1'
34
36
  gem.add_runtime_dependency 'therubyracer', '~> 0.12.1'
35
-
36
- gem.add_runtime_dependency 'bugsnag', '~> 2.5.0'
37
- gem.add_runtime_dependency 'rack-jsonr', '~> 0.3.0'
38
- gem.add_runtime_dependency 'rack-jquery-params','~> 0.1.1'
39
-
37
+ gem.add_runtime_dependency 'bugsnag', '~> 2.8.4'
40
38
  gem.add_runtime_dependency 'rest_client', '= 1.7.3'
41
39
 
42
- gem.add_runtime_dependency 'fanforce-base', '>= 1.6.0'
43
- gem.add_runtime_dependency 'fanforce-api', '>= 2.0.0.rc1'
44
- gem.add_runtime_dependency 'fanforce-plugin-worker', '>= 2.0.0.rc1'
40
+ gem.add_runtime_dependency 'fanforce-base', '>= 2.0.0.rc2'
41
+ gem.add_runtime_dependency 'fanforce-api', '>= 2.0.0.rc4'
42
+ gem.add_runtime_dependency 'fanforce-plugin-worker', '>= 2.0.0.rc4'
43
+
44
+ gem.add_development_dependency 'fanforce-test', '>= 2.0.0.rc2'
45
45
  end
@@ -1,3 +1,4 @@
1
+ require 'active_support/all'
1
2
  require 'fileutils'
2
3
  require 'json'
3
4
  require 'yaml'
@@ -7,6 +8,7 @@ require_relative 'load_sprockets'
7
8
  ########################################################################################################################
8
9
 
9
10
  Plugin = Fanforce::Plugin
11
+ Plugin.config.load_global_paths
10
12
  Plugin.config.load_env
11
13
 
12
14
  PluginWorker = Fanforce::PluginWorker
@@ -1,4 +1,5 @@
1
1
  @import 'plugin_factory/directives/base-footer/base-footer';
2
+ @import 'plugin_factory/directives/campaign-added/campaign-added';
2
3
  @import 'plugin_factory/directives/campaign-footer/campaign-footer';
3
4
  @import 'plugin_factory/directives/error/error';
4
5
  @import 'plugin_factory/directives/initiative-added/initiative-added';
@@ -0,0 +1,21 @@
1
+ App.directive('campaignAdded', [() ->
2
+ restrict: 'E',
3
+ templateUrl: '/plugin_factory/directives/campaign-added'
4
+ scope: {
5
+ campaign: '=?'
6
+ campaigns: '=?'
7
+ }
8
+ link: (($scope, $element, attrs) ->
9
+
10
+ $scope.has_reset_feature = angular.isFunction($scope.$parent.reset)
11
+
12
+ $scope.close = (->
13
+ CrossDresser.trigger('close-frame')
14
+ )
15
+
16
+ $scope.reset = (->
17
+ $scope.$parent.reset() if angular.isFunction($scope.$parent.reset)
18
+ )
19
+
20
+ )
21
+ ])
@@ -0,0 +1,15 @@
1
+ $module_path: '/assets/plugin_factory/directives/campaign-added';
2
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3
+
4
+ campaign-added { display: block; text-align: center; text-shadow: 1px 1px 0 white;
5
+
6
+ h2 { color: #c0cfa9; font-size: 25px; margin: 30px 0 0; }
7
+ h3 { color: #4a5f2a; font-size: 20px; margin-top: 8px;
8
+ a:hover { text-decoration: none; }
9
+ .campaign { border-bottom: 1px dashed #9fb280; display: inline-block; }
10
+ }
11
+
12
+ .buttons { background: #ebf9d5; display: inline-block; margin: 20px 0 ; border: 1px solid #e4f3cd; @include box-shadow(1px 1px 0 white); @include border-radius(3px); padding: 20px 50px; min-width: 60%;
13
+ .btn { margin: 0 10px; }
14
+ }
15
+ }
@@ -10,7 +10,7 @@ App.directive('initiativeAdded', [() ->
10
10
  $scope.has_reset_feature = angular.isFunction($scope.$parent.reset)
11
11
 
12
12
  $scope.close = (->
13
- FF.frame.close()
13
+ CrossDresser.trigger('close-frame')
14
14
  )
15
15
 
16
16
  $scope.reset = (->
@@ -2,5 +2,5 @@ $module_path: '/assets/plugin_factory/directives/page';
2
2
  ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
3
3
 
4
4
  page { display:block; overflow:hidden; padding-bottom: 40px;
5
- &.success { background: #eefcd8; }
5
+ &.finished { background: #eefcd8; }
6
6
  }
@@ -0,0 +1,698 @@
1
+ var CrossDresser;
2
+ (function (CrossDresser) {
3
+ function deparam(params, coerce) {
4
+ var obj = {}, coerce_types = { 'true': !0, 'false': !1, 'null': null };
5
+ // Iterate over all name=value pairs.
6
+ $.each(params.replace(/\+/g, ' ').split('&'), function (j, v) {
7
+ var param = v.split('='), key = decodeURIComponent(param[0]), val, cur = obj, i = 0,
8
+ // If key is more complex than 'foo', like 'a[]' or 'a[b][c]', split it
9
+ // into its component parts.
10
+ keys = key.split(']['), keys_last = keys.length - 1;
11
+ // If the first keys part contains [ and the last ends with ], then []
12
+ // are correctly balanced.
13
+ if (/\[/.test(keys[0]) && /\]$/.test(keys[keys_last])) {
14
+ // Remove the trailing ] from the last keys part.
15
+ keys[keys_last] = keys[keys_last].replace(/\]$/, '');
16
+ // Split first keys part into two parts on the [ and add them back onto
17
+ // the beginning of the keys array.
18
+ keys = keys.shift().split('[').concat(keys);
19
+ keys_last = keys.length - 1;
20
+ }
21
+ else {
22
+ // Basic 'foo' style key.
23
+ keys_last = 0;
24
+ }
25
+ // Are we dealing with a name=value pair, or just a name?
26
+ if (param.length === 2) {
27
+ val = decodeURIComponent(param[1]);
28
+ // Coerce values.
29
+ if (coerce) {
30
+ val = val && !isNaN(val) ? +val : val === 'undefined' ? undefined : coerce_types[val] !== undefined ? coerce_types[val] : val; // string
31
+ }
32
+ if (keys_last) {
33
+ for (; i <= keys_last; i++) {
34
+ key = keys[i] === '' ? cur.length : keys[i];
35
+ var next_key = keys[i + 1];
36
+ cur = cur[key] = (i < keys_last) ? cur[key] || (next_key && isNaN(next_key) ? {} : []) : val;
37
+ }
38
+ }
39
+ else {
40
+ // Simple key, even simpler rules, since only scalars and shallow
41
+ // arrays are allowed.
42
+ if ($.isArray(obj[key])) {
43
+ // val is already an array, so push on the next value.
44
+ obj[key].push(val);
45
+ }
46
+ else if (obj[key] !== undefined) {
47
+ // val isn't an array, but since a second value has been specified,
48
+ // convert val into an array.
49
+ obj[key] = [obj[key], val];
50
+ }
51
+ else {
52
+ // val is a scalar.
53
+ obj[key] = val;
54
+ }
55
+ }
56
+ }
57
+ else if (key) {
58
+ // No value was defined, so set something meaningful.
59
+ obj[key] = coerce ? undefined : '';
60
+ }
61
+ });
62
+ return obj;
63
+ }
64
+ CrossDresser.deparam = deparam;
65
+ ;
66
+ })(CrossDresser || (CrossDresser = {}));
67
+ ;
68
+ /// <reference path="jquery.d.ts" />
69
+ /// <reference path="deparam.ts" />
70
+ var CrossDresser;
71
+ (function (CrossDresser) {
72
+ var Utils = (function () {
73
+ function Utils() {
74
+ }
75
+ Utils.parseUrl = function (url) {
76
+ var uri_part_names = ["source", "scheme", "authority", "host", "port", "path", "directory_path", "file_name", "query_string", "hash"];
77
+ var uri_parts = new RegExp("^(?:([^:/?#.]+):)?(?://)?(([^:/?#]*)(?::(\\d*))?)?((/(?:[^?#](?![^?#/]*\\.[^?#/.]+(?:[\\?#]|$)))*/?)?([^?#/]*))?(?:\\?([^#]*))?(?:#(.*))?").exec(url);
78
+ var uri = {};
79
+ for (var i = 0, size = uri_part_names.length; i < size; i++) {
80
+ uri[uri_part_names[i]] = (uri_parts[i]) ? uri_parts[i] : '';
81
+ }
82
+ uri.port = uri.port ? parseInt(uri.port) : 80;
83
+ var domain_parts = (/^(.*?)\.?([^\.]*\.\w+)$/).exec(uri.host);
84
+ if (domain_parts) {
85
+ uri.sub_domain = domain_parts[1];
86
+ uri.root_domain = domain_parts[2];
87
+ }
88
+ else {
89
+ uri.sub_domain = uri.root_domain = '';
90
+ }
91
+ if (uri.directory_path.length > 0) {
92
+ uri.directory_path = uri.directory_path.replace(/\/?$/, "/");
93
+ }
94
+ return uri;
95
+ };
96
+ Utils.parseQueryString = function (query_string) {
97
+ return CrossDresser.deparam(query_string);
98
+ };
99
+ Utils.createId = function () {
100
+ var _id = '';
101
+ var possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
102
+ for (var i = 1; i <= 20; i++) {
103
+ _id += possible.charAt(Math.floor(Math.random() * possible.length));
104
+ }
105
+ return _id;
106
+ };
107
+ //docReady(fn, context);
108
+ //the context argument is optional - if present, it will be passed
109
+ //as an argument to the callback
110
+ Utils.documentReady = function (callback, context) {
111
+ // if ready has already fired, then just schedule the callback
112
+ // to fire asynchronously, but right away
113
+ if (readyFired) {
114
+ setTimeout(function () {
115
+ callback(context);
116
+ }, 1);
117
+ return;
118
+ }
119
+ else {
120
+ // add the function and context to the list
121
+ readyList.push({ fn: callback, ctx: context });
122
+ }
123
+ // if document already ready to go, schedule the ready function to run
124
+ if (document.readyState === 'complete') {
125
+ setTimeout(ready, 1);
126
+ }
127
+ else if (!readyEventHandlersInstalled) {
128
+ // otherwise if we don't have event handlers installed, install them
129
+ if (document.addEventListener) {
130
+ // first choice is DOMContentLoaded event
131
+ document.addEventListener('DOMContentLoaded', ready, false);
132
+ // backup is window load event
133
+ window.addEventListener('load', ready, false);
134
+ }
135
+ else {
136
+ // must be IE
137
+ document.attachEvent('onreadystatechange', readyStateChange);
138
+ window.attachEvent('onload', ready);
139
+ }
140
+ readyEventHandlersInstalled = true;
141
+ }
142
+ };
143
+ return Utils;
144
+ })();
145
+ CrossDresser.Utils = Utils;
146
+ })(CrossDresser || (CrossDresser = {}));
147
+ // DOCUMENT READY HELPERS //////////////////////////////////////////////////////////////////////////////////////////////
148
+ var readyList = [];
149
+ var readyFired = false;
150
+ var readyEventHandlersInstalled = false;
151
+ // call this when the document is ready
152
+ // this function protects itself against being called more than once
153
+ function ready() {
154
+ if (!readyFired) {
155
+ // this must be set to true before we start calling callbacks
156
+ readyFired = true;
157
+ for (var i = 0; i < readyList.length; i++) {
158
+ // if a callback here happens to add new ready handlers,
159
+ // the docReady() function will see that it already fired
160
+ // and will schedule the callback to run right after
161
+ // this event loop finishes so all handlers will still execute
162
+ // in order and no new ones will be added to the readyList
163
+ // while we are processing the list
164
+ readyList[i].fn.call(window, readyList[i].ctx);
165
+ }
166
+ // allow any closures held by these functions to free
167
+ readyList = [];
168
+ }
169
+ }
170
+ function readyStateChange() {
171
+ if (document.readyState === "complete") {
172
+ ready();
173
+ }
174
+ }
175
+ /// <reference path="jquery.d.ts" />
176
+ /// <reference path="utils.ts"/>
177
+ var CrossDresser;
178
+ (function (CrossDresser) {
179
+ var INSTANCES = {};
180
+ CrossDresser.frames = INSTANCES;
181
+ var ChildFrame = (function () {
182
+ function ChildFrame(_id) {
183
+ this._id = _id;
184
+ if (!INSTANCES[_id]) {
185
+ throw new RangeError('No frame exists by the referenced _id');
186
+ }
187
+ this.instance = INSTANCES[_id];
188
+ this.url = this.instance.url;
189
+ this.height = this.instance.height;
190
+ this.is_native = this.instance.is_native;
191
+ }
192
+ ChildFrame.prototype.trigger = function (name) {
193
+ var args = [];
194
+ for (var _i = 1; _i < arguments.length; _i++) {
195
+ args[_i - 1] = arguments[_i];
196
+ }
197
+ var callbacks = this.callbacks(name);
198
+ for (var i = 0, size = callbacks.length; i < size; i++) {
199
+ callbacks[i].apply(this, args);
200
+ }
201
+ if (name == 'native-base-ready') {
202
+ this.loadContent();
203
+ }
204
+ else if (name == 'resize-frame') {
205
+ this.resize.apply(this, args);
206
+ }
207
+ };
208
+ ChildFrame.prototype.on = function (name, callback) {
209
+ this.callbacks(name).push(callback);
210
+ };
211
+ ChildFrame.prototype.callbacks = function (name) {
212
+ if (!this.instance.callbacks[name]) {
213
+ this.instance.callbacks[name] = [];
214
+ }
215
+ return this.instance.callbacks[name];
216
+ };
217
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
218
+ ChildFrame.prototype.getElement = function () {
219
+ return this.element = this.element || $('iframe#' + this._id);
220
+ };
221
+ ChildFrame.prototype.loadContent = function () {
222
+ if (this.instance.content_prms) {
223
+ var frame = this;
224
+ this.instance.content_prms.then(function (html) {
225
+ frame.getElement()[0].contentWindow.CrossDresser.injectIntoPage(html);
226
+ });
227
+ }
228
+ };
229
+ ChildFrame.prototype.resize = function (new_height) {
230
+ new_height = (!new_height || parseInt(new_height) < 150) ? 150 : parseInt(new_height);
231
+ this.getElement().attr('height', new_height);
232
+ return null;
233
+ };
234
+ ChildFrame.create = function (settings) {
235
+ if (url) {
236
+ settings = { url: url };
237
+ }
238
+ var _id = CrossDresser.Utils.createId();
239
+ var url = settings.url.replace(/^\/\//, 'http://');
240
+ var attrs = settings.attrs || {};
241
+ var width = settings.width || 500;
242
+ var height = settings.height || 450;
243
+ var is_native = false;
244
+ if (settings.use_native_base) {
245
+ var goto_url = ((url.indexOf('?') > -1) ? url + '&' : url + '?') + $.param(attrs);
246
+ var content_prms = $.ajax({
247
+ url: goto_url,
248
+ dataType: 'jsonp',
249
+ jsonp: 'callback'
250
+ });
251
+ url = settings.use_native_base;
252
+ attrs = {};
253
+ is_native = true;
254
+ }
255
+ attrs.crss_drssr = _id + '::' + encodeURIComponent(CrossDresser.current.getConduitUrl());
256
+ if (goto_url) {
257
+ attrs.crss_drssr += '::' + encodeURIComponent(goto_url);
258
+ }
259
+ url = (url.indexOf('?') > -1) ? url + '&' : url + '?';
260
+ url += $.param(attrs);
261
+ INSTANCES[_id] = {
262
+ callbacks: {},
263
+ width: width,
264
+ height: height,
265
+ url: url,
266
+ is_native: is_native,
267
+ content_prms: content_prms
268
+ };
269
+ return new ChildFrame(_id);
270
+ };
271
+ ChildFrame.find = function (_id) {
272
+ if (INSTANCES[_id]) {
273
+ return new ChildFrame(_id);
274
+ }
275
+ };
276
+ ChildFrame.trigger = function (_id, name, args) {
277
+ var instance = this.find(_id);
278
+ if (!instance) {
279
+ throw ('could not find instance: ' + _id);
280
+ }
281
+ args = args.slice(0);
282
+ args.unshift(name);
283
+ instance.trigger.apply(instance, args);
284
+ };
285
+ return ChildFrame;
286
+ })();
287
+ CrossDresser.ChildFrame = ChildFrame;
288
+ })(CrossDresser || (CrossDresser = {}));
289
+ /// <reference path="jquery.d.ts" />
290
+ /// <reference path="utils.ts"/>
291
+ /// <reference path="base.ts"/>
292
+ var CrossDresser;
293
+ (function (CrossDresser) {
294
+ var INSTANCES = {};
295
+ var DEFAULT_WIDTH = 500;
296
+ var DEFAULT_HEIGHT = 450;
297
+ var ChildPopup = (function () {
298
+ function ChildPopup(_id) {
299
+ this._id = _id;
300
+ if (!INSTANCES[_id]) {
301
+ throw new RangeError('No frame exists by the referenced _id');
302
+ }
303
+ this.instance = INSTANCES[_id];
304
+ this.name = this.instance.name;
305
+ this.url = this.instance.url;
306
+ this.width = this.instance.width;
307
+ this.height = this.instance.height;
308
+ }
309
+ ChildPopup.prototype.trigger = function (name) {
310
+ var args = [];
311
+ for (var _i = 1; _i < arguments.length; _i++) {
312
+ args[_i - 1] = arguments[_i];
313
+ }
314
+ var callbacks = this.callbacks(name);
315
+ for (var i = 0, size = callbacks.length; i < size; i++) {
316
+ callbacks[i].apply(this, args);
317
+ }
318
+ };
319
+ ChildPopup.prototype.on = function (name, callback) {
320
+ this.callbacks(name).push(callback);
321
+ };
322
+ ChildPopup.prototype.callbacks = function (name) {
323
+ if (!this.instance.callbacks[name]) {
324
+ this.instance.callbacks[name] = [];
325
+ }
326
+ return this.instance.callbacks[name];
327
+ };
328
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
329
+ ChildPopup.prototype.open = function () {
330
+ setTimeout(function () {
331
+ var width = this.width, height = this.height, top = (window.screen.height / 2) - (height / 2), left = (window.screen.width / 2) - (width / 2);
332
+ top = top - (top * 0.2);
333
+ window.open(this.url, this.name, 'toolbar=0,scrollbars=0,location=0,statusbar=0,menubar=0,resizable=1,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left);
334
+ }.bind(this));
335
+ };
336
+ ChildPopup.create = function (settings) {
337
+ if (url) {
338
+ settings = { url: url };
339
+ }
340
+ var _id = CrossDresser.Utils.createId();
341
+ var attrs = settings.attrs || {};
342
+ var url = settings.url.replace(/^\/\//, 'http://');
343
+ var width = settings.width || DEFAULT_WIDTH;
344
+ var height = settings.height || DEFAULT_HEIGHT;
345
+ var name = settings.name || _id;
346
+ attrs.crss_drssr = _id + '::' + encodeURIComponent(CrossDresser.current.getConduitUrl());
347
+ url = (url.indexOf('?') > -1) ? url + '&' : url + '?';
348
+ url += $.param(attrs);
349
+ INSTANCES[_id] = {
350
+ url: url,
351
+ name: name,
352
+ width: width,
353
+ height: height,
354
+ callbacks: {}
355
+ };
356
+ return new ChildPopup(_id);
357
+ };
358
+ ChildPopup.find = function (_id) {
359
+ if (INSTANCES[_id]) {
360
+ return new ChildPopup(_id);
361
+ }
362
+ };
363
+ ChildPopup.trigger = function (_id, name, args) {
364
+ var instance = this.find(_id);
365
+ if (!instance) {
366
+ throw ('could not find instance: ' + _id);
367
+ }
368
+ args = args.slice(0);
369
+ args.unshift(name);
370
+ instance.trigger.apply(instance, args);
371
+ };
372
+ return ChildPopup;
373
+ })();
374
+ CrossDresser.ChildPopup = ChildPopup;
375
+ })(CrossDresser || (CrossDresser = {}));
376
+ var CrossDresser;
377
+ (function (CrossDresser) {
378
+ var resizer;
379
+ (function (resizer) {
380
+ var ELEMENTS_IN_HEIGHT = {};
381
+ var ELEMENT_HEIGHT_COUNT = 0;
382
+ var MIN_HEIGHT = 150;
383
+ var HEIGHT = 'auto';
384
+ var CURRENT_HEIGHT;
385
+ var CALLBACKS = {};
386
+ var AUTOSIZE_INTERVAL;
387
+ function run(args) {
388
+ if (!CrossDresser.current.is_frame)
389
+ return console.log('Notice: Skipping resize since we\'re not inside an iframe');
390
+ if (args == false)
391
+ return disableAutosize();
392
+ if (!args)
393
+ return calculateResize();
394
+ var has_changes = false;
395
+ var new_min_height = extractMinHeight(args);
396
+ if (new_min_height != MIN_HEIGHT) {
397
+ MIN_HEIGHT = new_min_height;
398
+ has_changes = true;
399
+ }
400
+ var new_height = extractHeight(args);
401
+ if (new_height != HEIGHT) {
402
+ if (new_height == 'auto')
403
+ enableAutosize();
404
+ if (!isNaN(new_height))
405
+ HEIGHT = new_height;
406
+ has_changes = true;
407
+ }
408
+ if (has_changes)
409
+ calculateResize();
410
+ }
411
+ resizer.run = run;
412
+ function addToHeightCalculations(element) {
413
+ var $element = $(element);
414
+ if (!$element.data('ffcore-element-id')) {
415
+ $element.data('ffcore-element-id', ELEMENT_HEIGHT_COUNT++);
416
+ }
417
+ ELEMENTS_IN_HEIGHT[$element.data('ffcore-element-id')] = $element;
418
+ }
419
+ resizer.addToHeightCalculations = addToHeightCalculations;
420
+ function removeFromHeightCalculations(element) {
421
+ delete ELEMENTS_IN_HEIGHT[$(element).data('ffcore-element-id')];
422
+ }
423
+ resizer.removeFromHeightCalculations = removeFromHeightCalculations;
424
+ function enableAutosize(interval) {
425
+ interval = interval || (CrossDresser.current.is_native ? 500 : 1000);
426
+ interval = interval < 100 ? 100 : interval;
427
+ if (AUTOSIZE_INTERVAL)
428
+ clearInterval(AUTOSIZE_INTERVAL);
429
+ HEIGHT = 'auto';
430
+ AUTOSIZE_INTERVAL = setInterval(function () {
431
+ calculateResize();
432
+ }, interval);
433
+ run();
434
+ }
435
+ resizer.enableAutosize = enableAutosize;
436
+ function disableAutosize() {
437
+ if (AUTOSIZE_INTERVAL) {
438
+ clearInterval(AUTOSIZE_INTERVAL);
439
+ }
440
+ }
441
+ resizer.disableAutosize = disableAutosize;
442
+ ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
443
+ function calculateResize() {
444
+ var new_height = $('html').css('height', 'auto').height();
445
+ for (var k in ELEMENTS_IN_HEIGHT) {
446
+ var $elem = ELEMENTS_IN_HEIGHT[k];
447
+ if ($elem.css('position') != 'absolute')
448
+ continue;
449
+ var element_bottom = $elem.offset().top + $elem.outerHeight();
450
+ if (element_bottom > new_height)
451
+ new_height = element_bottom;
452
+ }
453
+ if (CURRENT_HEIGHT && new_height < MIN_HEIGHT)
454
+ new_height = MIN_HEIGHT;
455
+ var viewport_height = $(window).height();
456
+ if (CURRENT_HEIGHT && ((CURRENT_HEIGHT == viewport_height) || (CURRENT_HEIGHT < viewport_height + 10 && CURRENT_HEIGHT > viewport_height - 10))) {
457
+ if ((CURRENT_HEIGHT == new_height) || (CURRENT_HEIGHT < new_height + 10 && CURRENT_HEIGHT > new_height - 10))
458
+ return;
459
+ }
460
+ CURRENT_HEIGHT = (new_height < MIN_HEIGHT) ? MIN_HEIGHT : new_height;
461
+ CrossDresser.trigger('resize-frame', CURRENT_HEIGHT);
462
+ }
463
+ function extractMinHeight(args) {
464
+ var height;
465
+ if (args['min-height'])
466
+ height = args['min-height'];
467
+ if (args.minHeight)
468
+ height = args.minHeight;
469
+ if (args.min_height)
470
+ height = args.min_height;
471
+ height = parseInt(height);
472
+ return height == NaN ? 0 : height;
473
+ }
474
+ function extractHeight(args) {
475
+ var height;
476
+ if (args['height'])
477
+ height = args['height'];
478
+ height = parseInt(height);
479
+ return height == NaN ? 'auto' : height;
480
+ }
481
+ })(resizer = CrossDresser.resizer || (CrossDresser.resizer = {}));
482
+ })(CrossDresser || (CrossDresser = {}));
483
+ var CrossDresser;
484
+ (function (_CrossDresser) {
485
+ var conduit;
486
+ (function (conduit) {
487
+ function run(command, args) {
488
+ var promise;
489
+ if (_CrossDresser.current.is_native) {
490
+ promise = toParent(command, args);
491
+ }
492
+ else {
493
+ promise = toIframe(command, args);
494
+ }
495
+ return promise;
496
+ }
497
+ conduit.run = run;
498
+ function executeRemoteCommand(CrossDresser, child_type, child_id, command, args) {
499
+ var methods = {
500
+ frame: function () {
501
+ CrossDresser.ChildFrame.trigger(child_id, command, args);
502
+ },
503
+ popup: function () {
504
+ CrossDresser.ChildPopup.trigger(child_id, command, args);
505
+ }
506
+ };
507
+ methods[child_type]();
508
+ }
509
+ function toParent(command, args) {
510
+ var dfr = $.Deferred();
511
+ executeRemoteCommand(_CrossDresser.current.parent.CrossDresser, _CrossDresser.current.environment, _CrossDresser.current._id, command, args);
512
+ return dfr.resolve().promise();
513
+ }
514
+ function toIframe(command, args) {
515
+ var dfr = $.Deferred();
516
+ var attrs = {
517
+ _id: _CrossDresser.current._id,
518
+ command: command,
519
+ environment: _CrossDresser.current.environment,
520
+ args: args
521
+ };
522
+ var url = _CrossDresser.current.parent_conduit_url;
523
+ url = ((url.indexOf('?') > -1) ? url + '&' : url + '?') + $.param(attrs);
524
+ _CrossDresser.Utils.documentReady(function () {
525
+ var $iframe = $('ff-frame-controller');
526
+ if ($iframe)
527
+ $iframe.remove();
528
+ $iframe = $('<iframe id="ff-frame-controller" src="' + url + '" width="10" height="10" style="position : absolute; top : 0px; left : 0px; visibility: hidden"></iframe>');
529
+ $iframe.appendTo('body');
530
+ $iframe.load(function () {
531
+ dfr.resolve();
532
+ });
533
+ });
534
+ return dfr.promise();
535
+ }
536
+ function fromIframe(environment, url) {
537
+ var uri = _CrossDresser.Utils.parseUrl(url);
538
+ var params = _CrossDresser.Utils.parseQueryString(uri.query_string);
539
+ if (environment != params.environment) {
540
+ throw Error('environment does not match params.environment');
541
+ }
542
+ executeRemoteCommand(CrossDresser, environment, params._id, params.command, params.args);
543
+ }
544
+ conduit.fromIframe = fromIframe;
545
+ })(conduit = _CrossDresser.conduit || (_CrossDresser.conduit = {}));
546
+ })(CrossDresser || (CrossDresser = {}));
547
+ /// <reference path="utils.ts"/>
548
+ /// <reference path="conduit.ts"/>
549
+ var CrossDresser;
550
+ (function (CrossDresser) {
551
+ var CONDUIT_PATH = '/cross-dresser.html';
552
+ var CALLBACKS = {};
553
+ var Current = (function () {
554
+ function Current() {
555
+ this.config = {
556
+ conduit_path: CONDUIT_PATH
557
+ };
558
+ this.raw_url = document.location.href;
559
+ this.raw_uri = CrossDresser.Utils.parseUrl(this.raw_url);
560
+ this.raw_params = CrossDresser.Utils.parseQueryString(this.raw_uri.query_string);
561
+ try {
562
+ if (window.opener || (window.top && window.top.opener)) {
563
+ this.environment = 'popup';
564
+ this.parent = window.opener || window.top.opener;
565
+ this.is_popup = true;
566
+ }
567
+ else if (window.top && window.top != window.self && document.referrer != this.raw_url.replace(document.location.hash, '')) {
568
+ this.environment = 'frame';
569
+ this.parent = window.top;
570
+ this.is_frame = true;
571
+ this.is_native = this.isNativeFrame();
572
+ }
573
+ else {
574
+ this.environment = 'toplevel';
575
+ this.parent = null;
576
+ }
577
+ }
578
+ catch (err) {
579
+ this.environment = 'toplevel';
580
+ }
581
+ this.initiateDocumentLoad();
582
+ if (this.is_frame) {
583
+ setTimeout(function () {
584
+ CrossDresser.resizer.enableAutosize();
585
+ });
586
+ }
587
+ }
588
+ Current.prototype.isNativeFrame = function () {
589
+ try {
590
+ var parent_host = CrossDresser.Utils.parseUrl(window.top.location.href).host;
591
+ var current_host = this.raw_uri.host;
592
+ return (parent_host == current_host) ? true : false;
593
+ }
594
+ catch (err) {
595
+ return false;
596
+ }
597
+ };
598
+ Current.prototype.getConduitUrl = function () {
599
+ return this.raw_uri.scheme + '://' + this.raw_uri.host + ([80, 443].indexOf(this.raw_uri.port) > -1 ? '' : ':' + this.raw_uri.port) + (this.config.conduit_path || CONDUIT_PATH);
600
+ };
601
+ Current.prototype.initiateDocumentLoad = function () {
602
+ var _this = this;
603
+ if (!this.raw_params.crss_drssr) {
604
+ return;
605
+ }
606
+ var array = this.raw_params.crss_drssr.split('::');
607
+ this._id = array[0];
608
+ this.parent_conduit_url = decodeURIComponent(array[1]);
609
+ if (array[2]) {
610
+ this.url_to_load = decodeURIComponent(array[2]);
611
+ }
612
+ if (this.url_to_load && !this.is_native) {
613
+ var url = this.url_to_load;
614
+ var crss_drssr = this._id + '::' + encodeURIComponent(this.parent_conduit_url);
615
+ window.location.href = ((url.indexOf('?') > -1) ? url + '&' : url + '?') + 'crss_drssr=' + crss_drssr;
616
+ }
617
+ else if (this.url_to_load && this.is_native) {
618
+ this.url = this.url_to_load;
619
+ this.uri = CrossDresser.Utils.parseUrl(this.url_to_load);
620
+ this.params = CrossDresser.Utils.parseQueryString(this.uri.query_string);
621
+ var bt = document.createElement('base');
622
+ bt.setAttribute('href', 'http://' + this.uri.host);
623
+ document.getElementsByTagName('head')[0].appendChild(bt);
624
+ setTimeout(function () {
625
+ _this.trigger('native-base-ready', _this.url_to_load);
626
+ });
627
+ }
628
+ else if (this.environment == 'toplevel') {
629
+ console.log('NOTICE: CrossDresser parent not found - running as toplevel');
630
+ }
631
+ else {
632
+ this.url = this.raw_url;
633
+ this.uri = this.raw_uri;
634
+ this.params = this.raw_params;
635
+ }
636
+ };
637
+ Current.prototype.trigger = function (name) {
638
+ var args = [];
639
+ for (var _i = 1; _i < arguments.length; _i++) {
640
+ args[_i - 1] = arguments[_i];
641
+ }
642
+ var promise = CrossDresser.conduit.run(name, args);
643
+ var callbacks = CALLBACKS[name] || [];
644
+ setTimeout(function () {
645
+ for (var i = 0, length = callbacks.length; i < length; i++) {
646
+ callbacks[i].apply(CrossDresser.current, args);
647
+ }
648
+ });
649
+ return promise;
650
+ };
651
+ Current.prototype.on = function (name, callback) {
652
+ CALLBACKS[name] = CALLBACKS[name] || [];
653
+ CALLBACKS[name].push(callback);
654
+ };
655
+ return Current;
656
+ })();
657
+ function config(config) {
658
+ CrossDresser.current.config.conduit_path = config.conduit_path || CrossDresser.current.config.conduit_path || CONDUIT_PATH;
659
+ }
660
+ CrossDresser.config = config;
661
+ function injectIntoPage(html) {
662
+ $(function () {
663
+ $('body').html(html);
664
+ });
665
+ }
666
+ CrossDresser.injectIntoPage = injectIntoPage;
667
+ CrossDresser.current = new Current();
668
+ })(CrossDresser || (CrossDresser = {}));
669
+ /// <reference path="child_frame.ts"/>
670
+ /// <reference path="child_popup.ts"/>
671
+ /// <reference path="resizer.ts"/>
672
+ /// <reference path="current.ts"/>
673
+ var CrossDresser;
674
+ (function (CrossDresser) {
675
+ function createFrame() {
676
+ var args = [];
677
+ for (var _i = 0; _i < arguments.length; _i++) {
678
+ args[_i - 0] = arguments[_i];
679
+ }
680
+ return CrossDresser.ChildFrame.create.apply(CrossDresser.ChildFrame, args);
681
+ }
682
+ CrossDresser.createFrame = createFrame;
683
+ function createPopup() {
684
+ var args = [];
685
+ for (var _i = 0; _i < arguments.length; _i++) {
686
+ args[_i - 0] = arguments[_i];
687
+ }
688
+ return CrossDresser.ChildPopup.create.apply(CrossDresser.ChildPopup, args);
689
+ }
690
+ CrossDresser.createPopup = createPopup;
691
+ function resize(args) {
692
+ CrossDresser.resizer.run(args);
693
+ }
694
+ CrossDresser.resize = resize;
695
+ CrossDresser.trigger = CrossDresser.current.trigger;
696
+ CrossDresser.on = CrossDresser.current.on;
697
+ })(CrossDresser || (CrossDresser = {}));
698
+ ;