cdddn 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +39 -0
- data/Rakefile +34 -0
- data/app/assets/javascripts/cdddn/application.js +1 -0
- data/app/assets/javascripts/cdddn/cookie.js +172 -0
- data/app/assets/stylesheets/cdddn/application.css +13 -0
- data/app/controllers/cdddn/application_controller.rb +4 -0
- data/app/controllers/cdddn/cdddn_action_controller_extension.rb +12 -0
- data/app/controllers/cdddn/root_controller.rb +9 -0
- data/app/helpers/cdddn/application_helper.rb +4 -0
- data/app/views/cdddn/root/get.html.erb +26 -0
- data/app/views/cdddn/root/set.html.erb +40 -0
- data/app/views/layouts/cdddn/application.html.erb +14 -0
- data/app/views/shared/cdddn/_desktop_layout.html.erb +11 -0
- data/app/views/shared/cdddn/_mobile_detection.html.erb +15 -0
- data/app/views/shared/cdddn/_mobile_full_site_btn.html.erb +21 -0
- data/app/views/shared/cdddn/_mobile_layout.html.erb +11 -0
- data/config/routes.rb +4 -0
- data/lib/cdddn.rb +4 -0
- data/lib/cdddn/engine.rb +11 -0
- data/lib/cdddn/version.rb +3 -0
- data/lib/generators/cdddn_mobile_layout/cdddn_mobile_layout_generator.rb +9 -0
- data/lib/generators/cdddn_mobile_layout/templates/application.mobile.erb +16 -0
- data/lib/tasks/cdddn_tasks.rake +4 -0
- data/test/cdddn_test.rb +7 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/root_controller.rb +7 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/views/layouts/application.html.erb +18 -0
- data/test/dummy/app/views/layouts/application.mobile.erb +16 -0
- data/test/dummy/app/views/root/index.html.erb +1 -0
- data/test/dummy/app/views/root/index.mobile.erb +1 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +6 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +6 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/log/development.log +24695 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/3539a948b0d8cd52f2560d1ef9d80240 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/38941bc7b19e15db64b700f1602bb327 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/42c5c5d20c86089d33eef6afa4464d83 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/463b862c35394851a9e33143b2730368 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/51e36daa1672ba24c987f0b76cca8a1c +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/86a3f50effbb675808d6a90e4c5b3f7a +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/92e3003c5848c6e455282ac14683bfa0 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9da463b58711b12d435eebd70b729b7f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/9ddd0b2d7c130f3be5b11b6ed748a0e9 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/becc603f1178154905794d5ffbf1db80 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/c3643a51ece3148899c1933a269a2269 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/fc1dc89af269d2b98909f69ddc40d17f +0 -0
- data/test/dummy/tmp/pids/server.pid +1 -0
- data/test/integration/navigation_test.rb +10 -0
- data/test/test_helper.rb +15 -0
- metadata +219 -0
checksums.yaml
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
---
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
N2ZhNTUxZWY3ZjViMzg0MTJmY2ZmODEzYzM0ZjA5ZDUxMDBhNjUyZg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
ZTYzODA4Y2Y4MDBhMjQ1ZDdkZWRkYWIzNTczZjYxYThkOTZhY2FmNQ==
|
7
|
+
SHA512:
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
ZTg1MDNiNTA4ZThkNGY5ZDM0MDBmODA0N2IyZjYwMDE4YWUzZjk2NjZkZTc2
|
10
|
+
NDBlNWE0Zjg0N2M2MTU1ZGNkZTZjMjExYTBmOGMyYTc3MWRjOTRkMzE2YTM1
|
11
|
+
ZGFmZjk1NWU4N2EyODA2YWI1NTM1ZmM4ZTZkOTJmYjJiNTY4MDE=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
MDRhM2ZkZTFhZTQ5YTU3MTQ4YmM4YzRhNzZiMTFkMjgyOWRmZWI2MzY1ZDMx
|
14
|
+
MDRhMzZmNzkzZGMwYWM1NmE4YWRlMzFkMzIzYjUzODE1ZjkyZDFkYTNjOWEy
|
15
|
+
OGVjNWMzMWE3MTE5ZjJhNzVmMjMxMzRhNjU5NGU1NmE1ZTYwMTc=
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2014 YOURNAME
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,39 @@
|
|
1
|
+
# CDDDN
|
2
|
+
|
3
|
+
Content Delivery & Device Detection Network (CDDDN) is a rails engine that provides mobile detection functionality for use in CDNs, like CloudFront and Akamai. This engine specifically allows you to cache static pages in both desktop and mobile versions for the same domain & url, rather than using an m.example.com approach.
|
4
|
+
|
5
|
+
## What this solves
|
6
|
+
|
7
|
+
* Mobile device detection on the client. With a CDN in front of your server, you can't do server side device detection.
|
8
|
+
* Avoid having to use separate domains (m.example.com and example.com) for mobile vs desktop.
|
9
|
+
* Using a CDN's device detection functionality makes development difficult since you'd have to fake those headers locally.
|
10
|
+
* Using a CDN's device detection functionality doesn't allow for the user to overwrite the device detection. (Ex: User wants to see desktop site on tablet.)
|
11
|
+
|
12
|
+
## How it works
|
13
|
+
|
14
|
+
On the initial request, CDDDN automatically detects the user's device and then sets the Rails' `request.format` to be either `:mobile` or `:html`. This means that you can provide separate views for mobile and desktop by having views name `index.mobile.erb` for mobile and `index.html.erb` for desktop. It also means that you can provide different data in your controllers using conditionals based on the `request.format`. For example:
|
15
|
+
|
16
|
+
```rb
|
17
|
+
if request.format == :mobile
|
18
|
+
sql_limit_number = 5
|
19
|
+
else
|
20
|
+
sql_limit_number = 20
|
21
|
+
end
|
22
|
+
```
|
23
|
+
|
24
|
+
This gem also allows the user to decide to view the full desktop site any time they'd like. They can also manually override which device they would like to see the site as by going to `/cdddn/set`. This is especially useful for developers testing on multiple devices, since normally they would need to clear their cookies each time they want to go from desktop to mobile.
|
25
|
+
|
26
|
+
## Requirement
|
27
|
+
|
28
|
+
This gem uses [localStorage](http://caniuse.com/#feat=namevalue-storage) to help the user get back to the page they first visited the site on. This means all browsers except Opera Mini and IE7 & below are supported officially. If a user visits the site with one of those browsers, they'll be redirected to the home page.
|
29
|
+
|
30
|
+
## Installation
|
31
|
+
|
32
|
+
1. Add `gem 'cdddn'` to your Gemfile.
|
33
|
+
2. `bundle install`
|
34
|
+
3. Create a mobile layout by using `rails generate cdddn_mobile_layout`
|
35
|
+
4. Add the following line in the `head` of your desktop layout (`app/views/layouts/application.html.erb`) before any of your javascript tags: `<%= render 'shared/cdddn/desktop_layout' %>`
|
36
|
+
5. In `config/initializers/mime_types.rb`, add the following line: `Mime::Type.register_alias "text/html", :mobile`
|
37
|
+
6. In your CDN configuration, you'll need to whitelist a single cookie, called `cdddn_device`.
|
38
|
+
|
39
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Cdddn'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'lib'
|
28
|
+
t.libs << 'test'
|
29
|
+
t.pattern = 'test/**/*_test.rb'
|
30
|
+
t.verbose = false
|
31
|
+
end
|
32
|
+
|
33
|
+
|
34
|
+
task default: :test
|
@@ -0,0 +1 @@
|
|
1
|
+
//= require_tree .
|
@@ -0,0 +1,172 @@
|
|
1
|
+
// Copyright (c) 2012 Florian H., https://github.com/js-coder https://github.com/js-coder/cookie.js
|
2
|
+
|
3
|
+
!function (document, undefined) {
|
4
|
+
|
5
|
+
var cookie = function () {
|
6
|
+
return cookie.get.apply(cookie, arguments);
|
7
|
+
};
|
8
|
+
|
9
|
+
var utils = cookie.utils = {
|
10
|
+
|
11
|
+
// Is the given value an array? Use ES5 Array.isArray if it's available.
|
12
|
+
isArray: Array.isArray || function (value) {
|
13
|
+
return Object.prototype.toString.call(value) === '[object Array]';
|
14
|
+
},
|
15
|
+
|
16
|
+
// Is the given value a plain object / an object whose constructor is `Object`?
|
17
|
+
isPlainObject: function (value) {
|
18
|
+
return !!value && Object.prototype.toString.call(value) === '[object Object]';
|
19
|
+
},
|
20
|
+
|
21
|
+
// Convert an array-like object to an array – for example `arguments`.
|
22
|
+
toArray: function (value) {
|
23
|
+
return Array.prototype.slice.call(value);
|
24
|
+
},
|
25
|
+
|
26
|
+
// Get the keys of an object. Use ES5 Object.keys if it's available.
|
27
|
+
getKeys: Object.keys || function (obj) {
|
28
|
+
var keys = [],
|
29
|
+
key = '';
|
30
|
+
for (key in obj) {
|
31
|
+
if (obj.hasOwnProperty(key)) keys.push(key);
|
32
|
+
}
|
33
|
+
return keys;
|
34
|
+
},
|
35
|
+
|
36
|
+
// Unlike JavaScript's built-in escape functions, this method
|
37
|
+
// only escapes characters that are not allowed in cookies.
|
38
|
+
escape: function (value) {
|
39
|
+
return String(value).replace(/[,;"\\=\s%]/g, function (character) {
|
40
|
+
return encodeURIComponent(character);
|
41
|
+
});
|
42
|
+
},
|
43
|
+
|
44
|
+
// Return fallback if the value is not defined, otherwise return value.
|
45
|
+
retrieve: function (value, fallback) {
|
46
|
+
return value == null ? fallback : value;
|
47
|
+
}
|
48
|
+
|
49
|
+
};
|
50
|
+
|
51
|
+
cookie.defaults = {};
|
52
|
+
|
53
|
+
cookie.expiresMultiplier = 60 * 60 * 24;
|
54
|
+
|
55
|
+
cookie.set = function (key, value, options) {
|
56
|
+
|
57
|
+
if (utils.isPlainObject(key)) { // Then `key` contains an object with keys and values for cookies, `value` contains the options object.
|
58
|
+
|
59
|
+
|
60
|
+
for (var k in key) { // TODO: `k` really sucks as a variable name, but I didn't come up with a better one yet.
|
61
|
+
if (key.hasOwnProperty(k)) this.set(k, key[k], value);
|
62
|
+
}
|
63
|
+
|
64
|
+
} else {
|
65
|
+
|
66
|
+
options = utils.isPlainObject(options) ? options : { expires: options };
|
67
|
+
|
68
|
+
var expires = options.expires !== undefined ? options.expires : (this.defaults.expires || ''), // Empty string for session cookies.
|
69
|
+
expiresType = typeof(expires);
|
70
|
+
|
71
|
+
if (expiresType === 'string' && expires !== '') expires = new Date(expires);
|
72
|
+
else if (expiresType === 'number') expires = new Date(+new Date + 1000 * this.expiresMultiplier * expires); // This is needed because IE does not support the `max-age` cookie attribute.
|
73
|
+
|
74
|
+
if (expires !== '' && 'toGMTString' in expires) expires = ';expires=' + expires.toGMTString();
|
75
|
+
|
76
|
+
var path = options.path || this.defaults.path; // TODO: Too much code for a simple feature.
|
77
|
+
path = path ? ';path=' + path : '';
|
78
|
+
|
79
|
+
var domain = options.domain || this.defaults.domain;
|
80
|
+
domain = domain ? ';domain=' + domain : '';
|
81
|
+
|
82
|
+
var secure = options.secure || this.defaults.secure ? ';secure' : '';
|
83
|
+
|
84
|
+
document.cookie = utils.escape(key) + '=' + utils.escape(value) + expires + path + domain + secure;
|
85
|
+
|
86
|
+
}
|
87
|
+
|
88
|
+
return this; // Return the `cookie` object to make chaining possible.
|
89
|
+
|
90
|
+
};
|
91
|
+
|
92
|
+
// TODO: This is commented out, because I didn't come up with a better method name yet. Any ideas?
|
93
|
+
// cookie.setIfItDoesNotExist = function (key, value, options) {
|
94
|
+
// if (this.get(key) === undefined) this.set.call(this, arguments);
|
95
|
+
// },
|
96
|
+
|
97
|
+
cookie.remove = function (keys) {
|
98
|
+
|
99
|
+
keys = utils.isArray(keys) ? keys : utils.toArray(arguments);
|
100
|
+
|
101
|
+
for (var i = 0, l = keys.length; i < l; i++) {
|
102
|
+
this.set(keys[i], '', -1);
|
103
|
+
}
|
104
|
+
|
105
|
+
return this; // Return the `cookie` object to make chaining possible.
|
106
|
+
};
|
107
|
+
|
108
|
+
cookie.empty = function () {
|
109
|
+
|
110
|
+
return this.remove(utils.getKeys(this.all()));
|
111
|
+
|
112
|
+
};
|
113
|
+
|
114
|
+
cookie.get = function (keys, fallback) {
|
115
|
+
|
116
|
+
fallback = fallback || undefined;
|
117
|
+
var cookies = this.all();
|
118
|
+
|
119
|
+
if (utils.isArray(keys)) {
|
120
|
+
|
121
|
+
var result = {};
|
122
|
+
|
123
|
+
for (var i = 0, l = keys.length; i < l; i++) {
|
124
|
+
var value = keys[i];
|
125
|
+
result[value] = utils.retrieve(cookies[value], fallback);
|
126
|
+
}
|
127
|
+
|
128
|
+
return result;
|
129
|
+
|
130
|
+
} else return utils.retrieve(cookies[keys], fallback);
|
131
|
+
|
132
|
+
};
|
133
|
+
|
134
|
+
cookie.all = function () {
|
135
|
+
|
136
|
+
if (document.cookie === '') return {};
|
137
|
+
|
138
|
+
var cookies = document.cookie.split('; '),
|
139
|
+
result = {};
|
140
|
+
|
141
|
+
for (var i = 0, l = cookies.length; i < l; i++) {
|
142
|
+
var item = cookies[i].split('=');
|
143
|
+
result[decodeURIComponent(item[0])] = decodeURIComponent(item[1]);
|
144
|
+
}
|
145
|
+
|
146
|
+
return result;
|
147
|
+
|
148
|
+
};
|
149
|
+
|
150
|
+
cookie.enabled = function () {
|
151
|
+
|
152
|
+
if (navigator.cookieEnabled) return true;
|
153
|
+
|
154
|
+
var ret = cookie.set('_', '_').get('_') === '_';
|
155
|
+
cookie.remove('_');
|
156
|
+
return ret;
|
157
|
+
|
158
|
+
};
|
159
|
+
|
160
|
+
// If an AMD loader is present use AMD.
|
161
|
+
// If a CommonJS loader is present use CommonJS.
|
162
|
+
// Otherwise assign the `cookie` object to the global scope.
|
163
|
+
|
164
|
+
if (typeof define === 'function' && define.amd) {
|
165
|
+
define(function () {
|
166
|
+
return cookie;
|
167
|
+
});
|
168
|
+
} else if (typeof exports !== 'undefined') {
|
169
|
+
exports.cookie = cookie;
|
170
|
+
} else window.cookie = cookie;
|
171
|
+
|
172
|
+
}(document);
|
@@ -0,0 +1,13 @@
|
|
1
|
+
/*
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
3
|
+
* listed below.
|
4
|
+
*
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
|
+
*
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
10
|
+
*
|
11
|
+
*= require_self
|
12
|
+
*= require_tree .
|
13
|
+
*/
|
@@ -0,0 +1,26 @@
|
|
1
|
+
<script>
|
2
|
+
|
3
|
+
function isMobile(){
|
4
|
+
var MOBILE_USER_AGENTS = 'palm|blackberry|nokia|phone|midp|mobi|symbian|chtml|ericsson|minimo|' +
|
5
|
+
'audiovox|motorola|samsung|telit|upg1|windows ce|ucweb|astel|plucker|' +
|
6
|
+
'x320|x240|j2me|sgh|portable|sprint|docomo|kddi|softbank|android|mmp|' +
|
7
|
+
'pdxgw|netfront|xiino|vodafone|portalmmm|sagem|mot-|sie-|ipod|up\\.b|' +
|
8
|
+
'webos|amoi|novarra|cdm|alcatel|pocket|ipad|iphone|mobileexplorer|' +
|
9
|
+
'mobile|zune',
|
10
|
+
mobile_regex = new RegExp(MOBILE_USER_AGENTS, "i");
|
11
|
+
|
12
|
+
return navigator.userAgent.match(mobile_regex);
|
13
|
+
}
|
14
|
+
|
15
|
+
// setting the device cookie to what we detect
|
16
|
+
var detected_device = isMobile() ? 'mobile' : 'desktop';
|
17
|
+
|
18
|
+
cookie.set('device', detected_device, {
|
19
|
+
domain: '<%= Rails.env.development? ? '' : Settings.host %>',
|
20
|
+
path : '/'
|
21
|
+
});
|
22
|
+
|
23
|
+
// window.location to whereever you came from
|
24
|
+
window.location.assign(localStorage.getItem('referrer_href') || '/');
|
25
|
+
|
26
|
+
</script>
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<h1>Which device do you want to see the site as?</h1>
|
2
|
+
|
3
|
+
<form id="device_selection_form">
|
4
|
+
<input type="radio" name="device_option" value="desktop">Desktop</input>
|
5
|
+
<input type="radio" name="device_option" value="mobile">Mobile</input>
|
6
|
+
|
7
|
+
<button id="set_device_btn">Set device</button>
|
8
|
+
</form>
|
9
|
+
|
10
|
+
|
11
|
+
<script>
|
12
|
+
|
13
|
+
document.getElementById('set_device_btn').addEventListener('click', function(e){
|
14
|
+
|
15
|
+
// setting the device cookie to your selection
|
16
|
+
var options = document.getElementsByName('device_option'),
|
17
|
+
selected_device = '';
|
18
|
+
|
19
|
+
for(var i=0; i < options.length; i++){
|
20
|
+
if (options[i].checked) {
|
21
|
+
selected_device = options[i].value;
|
22
|
+
}
|
23
|
+
}
|
24
|
+
|
25
|
+
cookie.set('device', selected_device, {
|
26
|
+
domain: '<%= Rails.env.development? ? '' : Settings.host %>',
|
27
|
+
path : '/'
|
28
|
+
});
|
29
|
+
|
30
|
+
// window.location to whereever you came from
|
31
|
+
window.location.assign(localStorage.getItem('referrer_href') || '/');
|
32
|
+
|
33
|
+
alert('Okay, we set your device to be ' + selected_device);
|
34
|
+
|
35
|
+
e.preventDefault();
|
36
|
+
return false;
|
37
|
+
});
|
38
|
+
|
39
|
+
|
40
|
+
</script>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
<html>
|
3
|
+
<head>
|
4
|
+
<title>Cdddn</title>
|
5
|
+
<%= stylesheet_link_tag "cdddn/application", media: "all" %>
|
6
|
+
<%= javascript_include_tag "cdddn/application" %>
|
7
|
+
<%= csrf_meta_tags %>
|
8
|
+
</head>
|
9
|
+
<body>
|
10
|
+
|
11
|
+
<%= yield %>
|
12
|
+
|
13
|
+
</body>
|
14
|
+
</html>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<%= javascript_include_tag 'cdddn/application' %>
|
2
|
+
<%= render 'shared/cdddn/mobile_detection' %>
|
3
|
+
|
4
|
+
<script>
|
5
|
+
var device_cookie = cookie.get('cdddn_device'),
|
6
|
+
cookiesEnabled = cookie.enabled();
|
7
|
+
|
8
|
+
if (cookiesEnabled && device_cookie != 'desktop') {
|
9
|
+
window.location.reload(true);
|
10
|
+
}
|
11
|
+
</script>
|
@@ -0,0 +1,15 @@
|
|
1
|
+
<script>
|
2
|
+
|
3
|
+
if (!window.location.href.match(/cdddn\/get|cdddn\/set/)){
|
4
|
+
console.log('logging the window.location.href = ' + window.location.href);
|
5
|
+
localStorage.setItem('referrer_href', window.location.href);
|
6
|
+
}
|
7
|
+
|
8
|
+
var device_cookie = cookie.get('cdddn_device'),
|
9
|
+
cookiesEnabled = cookie.enabled();
|
10
|
+
|
11
|
+
if (cookiesEnabled && device_cookie == undefined) {
|
12
|
+
window.location.assign('/cdddn/get');
|
13
|
+
}
|
14
|
+
|
15
|
+
</script>
|