From 12dc5549bdd9cfff0ea6cfcde0acdc8cd36a88ba Mon Sep 17 00:00:00 2001 From: Martin Donnelly Date: Mon, 1 Aug 2016 16:45:03 +0100 Subject: [PATCH] =?UTF-8?q?=E2=80=9D2016-08-01=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../SODashServer/SODashServer/app/js/mdot.js | 241 ++++++++++++++++++ .../SODashServer/app/lib/base64.js | 61 +++++ .../SODashServer/SODashServer/app/test.html | 196 +++++--------- .../SODashServer/SODashServer/bower.json | 3 +- .../src/bower_modules/base64/.bower.json | 29 +++ .../src/bower_modules/base64/LICENSE | 219 ++++++++++++++++ .../src/bower_modules/base64/README.md | 34 +++ .../src/bower_modules/base64/base64.js | 61 +++++ .../src/bower_modules/base64/base64.min.js | 1 + .../src/bower_modules/base64/bower.json | 18 ++ .../src/bower_modules/base64/package.json | 25 ++ 11 files changed, 750 insertions(+), 138 deletions(-) create mode 100644 smartoffice/SODashServer/SODashServer/app/js/mdot.js create mode 100644 smartoffice/SODashServer/SODashServer/app/lib/base64.js create mode 100644 smartoffice/SODashServer/SODashServer/src/bower_modules/base64/.bower.json create mode 100644 smartoffice/SODashServer/SODashServer/src/bower_modules/base64/LICENSE create mode 100644 smartoffice/SODashServer/SODashServer/src/bower_modules/base64/README.md create mode 100644 smartoffice/SODashServer/SODashServer/src/bower_modules/base64/base64.js create mode 100644 smartoffice/SODashServer/SODashServer/src/bower_modules/base64/base64.min.js create mode 100644 smartoffice/SODashServer/SODashServer/src/bower_modules/base64/bower.json create mode 100644 smartoffice/SODashServer/SODashServer/src/bower_modules/base64/package.json diff --git a/smartoffice/SODashServer/SODashServer/app/js/mdot.js b/smartoffice/SODashServer/SODashServer/app/js/mdot.js new file mode 100644 index 0000000..aaf591e --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/app/js/mdot.js @@ -0,0 +1,241 @@ +'use strict'; +/* global Backbone, _, $ */ +/* global mainview */ +/* jshint browser: true , devel: true*/ + + +(function($) { + + var mqttConfig = { + orgId: 'qz0da4', + userName: 'a-qz0da4-dfwwdkmkzr', + appKey: '9txJEf3Cjy7hkSOvkv', + prefix: 'iot-2/type/mDot/id/' + }; + + var sendAuthentication = function(xhr) { + var user = 'a-qz0da4-dfwwdkmkzr'; // Your actual username + var pass = '9txJEf3Cjy7hkSOvkv'; // Your actual password + var token = user.concat(':', pass); + xhr.setRequestHeader('Authorization', ('Basic '.concat(btoa(token)))); + }; + + var EventsModel = Backbone.Model.extend({ + initialize: function() { + _.bindAll(this, 'processAdded'); + this.on('all',function(d) { + console.log('model:all',d); + + }); + + this.on('add',function() { + this.processAdded(); + }); + + }, + processAdded: function() { + console.log('Model:ProcessAdded'); + + _.invoke(DeviceCollection.toArray(), 'destroy'); + + _(this.get('events')).each(function(i) { + i.evt.decoded = this.decoder(i.evt.data); + i.evt.dateTime = this.dateTime(i.timestamp.$date); + DeviceCollection.add({dt: i.evt.dateTime.dateTime,lux: i.evt.decoded.light, temp: i.evt.decoded.temp, co2: i.evt.decoded.co2, humid: i.evt.decoded.humid, noise: i.evt.decoded.noise}); + + }, this); + }, + decoder: function(data) { + var _obj = {}; + var _data = window.atob(data).split(''); + + var bytes = _data.map(i => i.charCodeAt()); + + _obj.light = parseInt('0x' + ('0' + bytes[0]).substr(-2) + ('0' + bytes[1]).substr(-2)); + _obj.co2 = parseInt(_data[2] + _data[3] + _data[4] + _data[5] + _data[6], 10); + _obj.temp = (parseInt(_data[7] + _data[8] + _data[9] + _data[10] + _data[11], 10) - 1000) / 10; + _obj.humid = (parseInt(_data[12] + _data[13] + _data[14] + _data[15] + _data[16], 10) / 10); + _obj.noise = parseInt('0x' + ('0' + bytes[17]).substr(-2) + ('0' + bytes[18]).substr(-2)); + _obj.binData = bytes; + return _obj; + }, + dateTime: function($date) { + var dateTime = new Date.create($date); + var date = dateTime.format('{yyyy}-{MM}-{dd}'); + var time = dateTime.format('{HH}:{mm}:{ss}'); + return {dateTime: dateTime.format('{yyyy}-{MM}-{dd} {HH}:{mm}:{ss}'), date: date, time: time}; + } + }); + + + var mDotCollection = Backbone.Collection.extend({ + model: EventsModel, + url: 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/', + initialize: function() { + this.on('all',function(d) { + console.log('Collection:all',d); + + }); + this.on('update', function() { + // Console.log('Collection:update',this); + }); + } + + }); + + var ItemView = Backbone.View.extend({ + tagName: 'div', className: 'item mui-container', initialize: function() { + this.template = _.template($('#item-template').html()); + console.log('ItemView:Init'); + this.render(); + }, render: function() { + console.log('ItemView:Render'); + _(this.model.events).each(function(i) { + this.$el.append(this.template({item: i})); + }, this); + + return this; + } + }); + + + + var MDOT = Backbone.View.extend({ + model: EventsModel, el: $('#output'), + + events: { + 'click button#refresh': 'refresh' + }, initialize: function() { + _.bindAll(this, 'render', 'refresh', 'update'); + this.collection.bind('change reset add remove', this.render, this); + + this.template = _.template($('#list-template').html()); + this.render(); + }, refresh: function() { + + }, update: function() { + console.log('MDOT:update'); + this.collection.each(function(model) { + + // Var events = model.get('events'); + // var e = new ItemView({model: model.toJSON()}); + }); + + }, render: function() { + console.log('MDOT:render'); + var that = this; + this.$el.empty(); + this.collection.each(function(model) { + + var events = model.get('events'); + var e = new ItemView({model: model.toJSON()}).render().el; + + console.log('render:done:'); + that.$el.append(e); + + }); + console.log('bah'); + return this; + } + }); + + + + var MainView = Backbone.View.extend({ + el: $('#main'), + template: _.template($('#main-template').html()), + events: { + 'change select#device': 'changeDevice' + }, + initialize: function() { + _.bindAll(this, 'render','changeDevice'); + this.render(); + }, + render: function() { + $(this.el).html(this.template()); + return this; + }, + changeDevice: function() { + var newDevice; + console.log('MainView:ChangeDevice'); + newDevice = this.$el.find('#device')[0].value; + + this.collection.url = 'https://qz0da4.internetofthings.ibmcloud.com/api/v0002/historian/types/mDot/devices/' + newDevice; + this.collection.fetch({beforeSend: sendAuthentication}); + + } + }); + + var GraphView = Backbone.View.extend({ + el: $('#graph'), + template: _.template($('#graph-template').html()), + initialize: function() { + this.modes = ['','lux','temp','co2','humid','noise']; + this.mode = 0; + console.log('GraphView!'); + _.bindAll(this, 'render', 'changeMode', 'updateGraph'); + this.render(); + }, + events: { + 'change select#displaymode': 'changeMode' + }, + render: function() { + $(this.el).html(this.template()); + this.$line = $(this.el).find('#line'); + this.$maxY = $(this.el).find('#maxY'); + + return this; + }, + changeMode: function() { + this.mode = this.$el.find('#displaymode')[0].value; + this.updateGraph(); + console.log('new mode:', this.mode); + + }, + updateGraph: function() { + + var ceiling, ceilingLimit; + var points = []; + var getMode = this.modes[this.mode]; + + _(this.collection.models).each(function(i) { + points.push(i.get(getMode)); + }, this); + + ceiling = points.reduce(function(p, v) { + return (Math.abs(p) > Math.abs(v) ? Math.abs(p) : Math.abs(v)); + }); + + ceilingLimit = (Math.ceil((Math.round(ceiling) + 1) / 10) * 10); + if (ceilingLimit > 1000) { + ceilingLimit = (Math.ceil((Math.round(ceiling) + 1) / 50) * 50); + } + + var scale = 124 / ceilingLimit; + // Var xstep = (280 - 46) / 100; + var xstep = 2.34; + var startX = 46 + (100 - points.length) * xstep; + var calcArray = []; + for (var x = 0;x < points.length;x++) { + calcArray.push((startX + (x * xstep)).toFixed(2) + ',' + (136 - ((points[x]) * scale)).toFixed(2)); + } + + this.$line[0].setAttribute('points',calcArray.join(' ')); + + this.$maxY[0].textContent = ceilingLimit; + + } + + }); + + var DeviceCollection = new Backbone.Collection; + + var mdotCollection = new mDotCollection(); + + var mainview = new MainView({collection: mdotCollection}); + + var mdot = new MDOT({collection: mdotCollection}); + + var grapher = new GraphView({collection: DeviceCollection}); + +})(jQuery); diff --git a/smartoffice/SODashServer/SODashServer/app/lib/base64.js b/smartoffice/SODashServer/SODashServer/app/lib/base64.js new file mode 100644 index 0000000..d5e6af2 --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/app/lib/base64.js @@ -0,0 +1,61 @@ +;(function () { + + var object = typeof exports != 'undefined' ? exports : self; // #8: web workers + var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + function InvalidCharacterError(message) { + this.message = message; + } + InvalidCharacterError.prototype = new Error; + InvalidCharacterError.prototype.name = 'InvalidCharacterError'; + + // encoder + // [https://gist.github.com/999166] by [https://github.com/nignag] + object.btoa || ( + object.btoa = function (input) { + var str = String(input); + for ( + // initialize result and counter + var block, charCode, idx = 0, map = chars, output = ''; + // if the next str index does not exist: + // change the mapping table to "=" + // check if d has no fractional digits + str.charAt(idx | 0) || (map = '=', idx % 1); + // "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8 + output += map.charAt(63 & block >> 8 - idx % 1 * 8) + ) { + charCode = str.charCodeAt(idx += 3/4); + if (charCode > 0xFF) { + throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); + } + block = block << 8 | charCode; + } + return output; + }); + + // decoder + // [https://gist.github.com/1020396] by [https://github.com/atk] + object.atob || ( + object.atob = function (input) { + var str = String(input).replace(/=+$/, ''); + if (str.length % 4 == 1) { + throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded."); + } + for ( + // initialize result and counters + var bc = 0, bs, buffer, idx = 0, output = ''; + // get next character + buffer = str.charAt(idx++); + // character found in table? initialize bit storage and add its ascii value; + ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, + // and if not first of each 4 characters, + // convert the first 8 bits to one ascii character + bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0 + ) { + // try to find character in table (0-63, not found => -1) + buffer = chars.indexOf(buffer); + } + return output; + }); + +}()); diff --git a/smartoffice/SODashServer/SODashServer/app/test.html b/smartoffice/SODashServer/SODashServer/app/test.html index 7c79624..74634c4 100644 --- a/smartoffice/SODashServer/SODashServer/app/test.html +++ b/smartoffice/SODashServer/SODashServer/app/test.html @@ -7,13 +7,9 @@ type="text/css"/> - - -
+
+ + + + + + + + + + + diff --git a/smartoffice/SODashServer/SODashServer/bower.json b/smartoffice/SODashServer/SODashServer/bower.json index d4a01f7..9622781 100644 --- a/smartoffice/SODashServer/SODashServer/bower.json +++ b/smartoffice/SODashServer/SODashServer/bower.json @@ -20,6 +20,7 @@ "jquery": "^2.2.3", "mui": "^0.6.8", "sugarjs-date": "^1.5.1", - "backbone": "^1.3.3" + "backbone": "^1.3.3", + "base64": "^1.0.0" } } diff --git a/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/.bower.json b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/.bower.json new file mode 100644 index 0000000..e263631 --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/.bower.json @@ -0,0 +1,29 @@ +{ + "name": "base64", + "version": "1.0.0", + "description": "Base64 encoding and decoding", + "main": "./base64.js", + "license": "WTFPL", + "repository": { + "type": "git", + "url": "git://github.com/davidchambers/Base64.js.git" + }, + "ignore": [ + "**/.*", + "Makefile", + "coverage/", + "scripts/", + "test/" + ], + "homepage": "https://github.com/davidchambers/Base64.js", + "_release": "1.0.0", + "_resolution": { + "type": "version", + "tag": "1.0.0", + "commit": "8f1b14b549725d55457e2821ca250e523d007822" + }, + "_source": "https://github.com/davidchambers/Base64.js.git", + "_target": "^1.0.0", + "_originalSource": "base64", + "_direct": true +} \ No newline at end of file diff --git a/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/LICENSE b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/LICENSE new file mode 100644 index 0000000..2c5718f --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/LICENSE @@ -0,0 +1,219 @@ +This software is dual-licensed under Apache 2.0 and WTFPL + + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright 2015 David Chambers + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + Version 2, December 2004 + + Copyright (c) 2011..2012 David Chambers + + Everyone is permitted to copy and distribute verbatim or modified + copies of this license document, and changing it is allowed as long + as the name is changed. + + DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. You just DO WHAT THE FUCK YOU WANT TO. diff --git a/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/README.md b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/README.md new file mode 100644 index 0000000..e5dafed --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/README.md @@ -0,0 +1,34 @@ +# Base64.js + +≈ 500 byte* polyfill for browsers which don't provide [`window.btoa`][1] and +[`window.atob`][2]. + +Although the script does no harm in browsers which do provide these functions, +a conditional script loader such as [yepnope][3] can prevent unnecessary HTTP +requests. + +```javascript +yepnope({ + test: window.btoa && window.atob, + nope: 'base64.js', + callback: function () { + // `btoa` and `atob` are now safe to use + } +}) +``` + +Base64.js stems from a [gist][4] by [yahiko][5]. + +### Running the test suite + + make setup + make test + +\* Minified and gzipped. Run `make bytes` to verify. + + +[1]: https://developer.mozilla.org/en/DOM/window.btoa +[2]: https://developer.mozilla.org/en/DOM/window.atob +[3]: http://yepnopejs.com/ +[4]: https://gist.github.com/229984 +[5]: https://github.com/yahiko diff --git a/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/base64.js b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/base64.js new file mode 100644 index 0000000..d5e6af2 --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/base64.js @@ -0,0 +1,61 @@ +;(function () { + + var object = typeof exports != 'undefined' ? exports : self; // #8: web workers + var chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/='; + + function InvalidCharacterError(message) { + this.message = message; + } + InvalidCharacterError.prototype = new Error; + InvalidCharacterError.prototype.name = 'InvalidCharacterError'; + + // encoder + // [https://gist.github.com/999166] by [https://github.com/nignag] + object.btoa || ( + object.btoa = function (input) { + var str = String(input); + for ( + // initialize result and counter + var block, charCode, idx = 0, map = chars, output = ''; + // if the next str index does not exist: + // change the mapping table to "=" + // check if d has no fractional digits + str.charAt(idx | 0) || (map = '=', idx % 1); + // "8 - idx % 1 * 8" generates the sequence 2, 4, 6, 8 + output += map.charAt(63 & block >> 8 - idx % 1 * 8) + ) { + charCode = str.charCodeAt(idx += 3/4); + if (charCode > 0xFF) { + throw new InvalidCharacterError("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range."); + } + block = block << 8 | charCode; + } + return output; + }); + + // decoder + // [https://gist.github.com/1020396] by [https://github.com/atk] + object.atob || ( + object.atob = function (input) { + var str = String(input).replace(/=+$/, ''); + if (str.length % 4 == 1) { + throw new InvalidCharacterError("'atob' failed: The string to be decoded is not correctly encoded."); + } + for ( + // initialize result and counters + var bc = 0, bs, buffer, idx = 0, output = ''; + // get next character + buffer = str.charAt(idx++); + // character found in table? initialize bit storage and add its ascii value; + ~buffer && (bs = bc % 4 ? bs * 64 + buffer : buffer, + // and if not first of each 4 characters, + // convert the first 8 bits to one ascii character + bc++ % 4) ? output += String.fromCharCode(255 & bs >> (-2 * bc & 6)) : 0 + ) { + // try to find character in table (0-63, not found => -1) + buffer = chars.indexOf(buffer); + } + return output; + }); + +}()); diff --git a/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/base64.min.js b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/base64.min.js new file mode 100644 index 0000000..2ad238a --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/base64.min.js @@ -0,0 +1 @@ +!function(){function t(t){this.message=t}var r="undefined"!=typeof exports?exports:self,e="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";t.prototype=new Error,t.prototype.name="InvalidCharacterError",r.btoa||(r.btoa=function(r){for(var o,n,a=String(r),i=0,c=e,d="";a.charAt(0|i)||(c="=",i%1);d+=c.charAt(63&o>>8-i%1*8)){if(n=a.charCodeAt(i+=.75),n>255)throw new t("'btoa' failed: The string to be encoded contains characters outside of the Latin1 range.");o=o<<8|n}return d}),r.atob||(r.atob=function(r){var o=String(r).replace(/=+$/,"");if(o.length%4==1)throw new t("'atob' failed: The string to be decoded is not correctly encoded.");for(var n,a,i=0,c=0,d="";a=o.charAt(c++);~a&&(n=i%4?64*n+a:a,i++%4)?d+=String.fromCharCode(255&n>>(-2*i&6)):0)a=e.indexOf(a);return d})}(); diff --git a/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/bower.json b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/bower.json new file mode 100644 index 0000000..f01bf9b --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/bower.json @@ -0,0 +1,18 @@ +{ + "name": "base64", + "version": "1.0.0", + "description": "Base64 encoding and decoding", + "main": "./base64.js", + "license": "WTFPL", + "repository": { + "type": "git", + "url": "git://github.com/davidchambers/Base64.js.git" + }, + "ignore": [ + "**/.*", + "Makefile", + "coverage/", + "scripts/", + "test/" + ] +} diff --git a/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/package.json b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/package.json new file mode 100644 index 0000000..cb152b7 --- /dev/null +++ b/smartoffice/SODashServer/SODashServer/src/bower_modules/base64/package.json @@ -0,0 +1,25 @@ +{ + "name": "Base64", + "version": "1.0.0", + "description": "Base64 encoding and decoding", + "author": "David Chambers ", + "main": "./base64.js", + "license": "(Apache-2.0 OR WTFPL)", + "repository": { + "type": "git", + "url": "git://github.com/davidchambers/Base64.js.git" + }, + "devDependencies": { + "coffee-script": "1.8.x", + "istanbul": "0.2.x", + "mocha": "1.18.x", + "uglify-js": "2.4.x", + "xyz": "0.5.x" + }, + "files": [ + "/LICENSE", + "/README.md", + "/base64.js", + "/package.json" + ] +}