This commit is contained in:
lxsang
2016-10-29 14:34:29 +02:00
parent 9244208f30
commit f729d5dd8a
2510 changed files with 57350 additions and 0 deletions

View File

@ -0,0 +1,142 @@
/*!
* OS.js - JavaScript Cloud/Web Desktop Platform
*
* Copyright (c) 2011-2015, Anders Evenrud <andersevenrud@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Anders Evenrud <andersevenrud@gmail.com>
* @licence Simplified BSD License
*/
/*.ApplicationCalculatorWindow {
}*/
.ApplicationCalculatorWindow gui-text {
display : block;
margin : 8px;
height : 50px;
}
.ApplicationCalculatorWindow gui-text > input {
font-size : 30px;
font-family : Monospace;
line-height : 50px;
text-align : right;
}
.ApplicationCalculatorWindow.noop {
opacity : .1;
}
.ApplicationCalculatorWindow.NaN {
-webkit-animation:CalculatorSuck 3s linear;
-moz-animation:CalculatorSuck 3s linear;
-ms-animation:CalculatorSuck 3s linear;
-o-animation:CalculatorSuck 3s linear;
animation:CalculatorSuck 3s linear;
}
@-webkit-keyframes CalculatorSuck {
100% {
-webkit-transform: scale(0) rotate(360deg);
transform: scale(0) rotate(360deg);
-webkit-opacity: 0;
}
50% {
-webkit-transform: scale(.5) rotate(180deg);
transform: scale(.5) rotate(180deg);
}
10% {
-webkit-transform: scale(1.5) rotate(0deg);
transform: scale(1.5) rotate(0deg);
}
0% {
-webkit-opacity: 1;
}
}
@-moz-keyframes CalculatorSuck {
100% {
-moz-transform: scale(0) rotate(360deg);
transform: scale(0) rotate(360deg);
-moz-opacity: 0;
}
50% {
-moz-transform: scale(.5) rotate(180deg);
transform: scale(.5) rotate(180deg);
}
10% {
-moz-transform: scale(1.5) rotate(0deg);
transform: scale(1.5) rotate(0deg);
}
0% {
-moz-opacity: 1;
}
}
@-o-keyframes CalculatorSuck {
100% {
-o-transform: scale(0) rotate(360deg);
transform: scale(0) rotate(360deg);
-o-opacity: 0;
}
50% {
-o-transform: scale(.5) rotate(180deg);
transform: scale(.5) rotate(180deg);
}
10% {
-o-transform: scale(1.5) rotate(0deg);
transform: scale(1.5) rotate(0deg);
}
0% {
-o-opacity: 1;
}
}
@keyframes CalculatorSuck {
100% {
transform: scale(0) rotate(360deg);
opacity: 0;
}
50% {
transform: scale(.5) rotate(180deg);
}
10% {
transform: scale(1.5) rotate(0deg);
}
0% {
opacity: 1;
}
}

View File

@ -0,0 +1,256 @@
/*!
* OS.js - JavaScript Cloud/Web Desktop Platform
*
* Copyright (c) 2011-2016, Anders Evenrud <andersevenrud@gmail.com>
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* @author Anders Evenrud <andersevenrud@gmail.com>
* @licence Simplified BSD License
*/
(function(Application, Window, Utils, API, VFS, GUI) {
/*eslint eqeqeq: "off"*/
'use strict';
var ops = {
dec : '.',
perc : '%',
minus : '-',
plus : '+',
multiply : '*',
divide : '/'
};
var keys = {
107: 'plus',
109: 'minus',
106: 'multiply',
111: 'divide',
110: 'dec',
188: 'dec',
13: 'equal',
47: 'divide',
46: 'CE',
45: 'minus',
44: 'dec',
43: 'plus',
42: 'multiply',
27: 'CE',
8: 'nbs'
};
var labels = {
'CE' : 'CE', 'AC' : 'AC', 'perc' : '%', 'plus' : '+',
'7' : '7', '8' : '8', '9' : '9', 'minus' : '-',
'4' : '4', '5' : '5', '6' : '6', 'multiply' : 'x',
'1' : '1', '2' : '2', '3' : '3', 'divide' : '÷',
'0' : '0', 'swap': '±', 'dec' : ',', 'equal' : '='
};
var buttons = [
['CE', 'AC', 'perc', 'plus'],
['7', '8', '9', 'minus'],
['4', '5', '6', 'multiply'],
['1', '2', '3', 'divide'],
['0', 'dec', 'equal']
];
/////////////////////////////////////////////////////////////////////////////
// WINDOWS
/////////////////////////////////////////////////////////////////////////////
function ApplicationCalculatorWindow(app, metadata, scheme) {
Window.apply(this, ['ApplicationCalculatorWindow', {
icon: metadata.icon,
title: metadata.name,
allow_resize: false,
allow_maximize: false,
width: 220,
height: 340
}, app, scheme]);
this.total = 0;
this.entries = [];
this.temp = '';
}
ApplicationCalculatorWindow.prototype = Object.create(Window.prototype);
ApplicationCalculatorWindow.constructor = Window.prototype;
ApplicationCalculatorWindow.prototype.init = function(wm, app, scheme) {
var root = Window.prototype.init.apply(this, arguments);
var self = this;
// Load and gel.set up scheme (GUI) here
scheme.render(this, 'CalculatorWindow', root);
this._scheme.find(this, 'Output').on('keypress', function(ev) {
ev.stopPropagation();
ev.preventDefault();
var keyCode = ev.which || ev.keyCode;
if ( (keyCode > 95) && (keyCode < 106) ) {
self.operation(keyCode - 96);
} else if ( (keyCode > 47) && (keyCode < 58) ) {
self.operation(keyCode - 48);
} else {
if ( typeof keys[keyCode] !== 'undefined' ) {
self.operation(keys[keyCode]);
}
}
}).set('readonly', true).focus();
root.querySelectorAll('gui-button').forEach(function(el, idx) {
var r = parseInt(idx / 4, 10);
var c = idx % 4;
var op = buttons[r][c];
el = scheme.get(el);
el.set('value', labels[op] || '');
if ( op === null ) {
Utils.$addClass(el.$element, 'noop');
el.set('disabled', true);
} else {
el.on('click', function() {
self.operation(op);
});
}
});
return root;
};
ApplicationCalculatorWindow.prototype.operation = function(val) {
var self = this;
if (this.temp == '' && ['plus', 'minus', 'multiply', 'divide'].indexOf(val) !== -1) {
this.temp = this._scheme.find(this, 'Output').get('value');
}
function getAnswer() {
var nt = Number(self.entries[0]);
for ( var i = 1; i < self.entries.length; i++ ) {
var nextNum = Number(self.entries[i + 1]);
var symbol = self.entries[i];
if (symbol === '+') {
nt += nextNum;
} else if ( symbol === '-' ) {
nt -= nextNum;
} else if ( symbol === '*' ) {
nt *= nextNum;
} else if ( symbol === '/' ) {
nt /= nextNum;
}
i++;
}
if ( nt < 0 ) {
nt = '-' + Math.abs(nt);
}
return nt;
}
var output = (function() {
// Kudos http://codepen.io/GeoffStorbeck/pen/zxgaqw
if ( !isNaN(val) || val === 'dec' ) { // Number
self.temp += val === 'dec' ? ops[val] : val;
return self.temp.substring(0,10);
} else if ( val === 'AC' ) { // Clear
self.entries = [];
self.temp = '';
self.total = 0;
return '';
} else if ( val === 'CE' ) { // Clear Last Entry
self.temp = '';
return '';
} else if ( val === 'equal' ) { // Equal
self.entries.push(self.temp);
var nt = getAnswer();
self.entries = [];
self.temp = '';
return nt;
} else {
if ( typeof ops[val] !== 'undefined' ) {
val = ops[val];
}
self.entries.push(self.temp);
self.entries.push(val);
self.temp = '';
}
return null;
})();
if ( output !== null ) {
if ( !String(output).length ) {
output = String(0);
}
if ( output === 'NaN' || output === 'Infinity' || isNaN(output) || !isFinite(output) ) {
Utils.$addClass(this._$element, 'NaN');
setTimeout(function() {
Utils.$removeClass(self._$element, 'NaN');
}, 3000);
}
this._scheme.find(this, 'Output').set('value', String(output));
}
this._scheme.find(this, 'Output').focus();
};
/////////////////////////////////////////////////////////////////////////////
// APPLICATION
/////////////////////////////////////////////////////////////////////////////
var ApplicationCalculator = function(args, metadata) {
Application.apply(this, ['ApplicationCalculator', args, metadata]);
};
ApplicationCalculator.prototype = Object.create(Application.prototype);
ApplicationCalculator.constructor = Application;
ApplicationCalculator.prototype.init = function(settings, metadata, scheme) {
Application.prototype.init.apply(this, arguments);
this._addWindow(new ApplicationCalculatorWindow(this, metadata, scheme));
};
/////////////////////////////////////////////////////////////////////////////
// EXPORTS
/////////////////////////////////////////////////////////////////////////////
OSjs.Applications = OSjs.Applications || {};
OSjs.Applications.ApplicationCalculator = OSjs.Applications.ApplicationCalculator || {};
OSjs.Applications.ApplicationCalculator.Class = Object.seal(ApplicationCalculator);
})(OSjs.Core.Application, OSjs.Core.Window, OSjs.Utils, OSjs.API, OSjs.VFS, OSjs.GUI);

View File

@ -0,0 +1,37 @@
{
"className": "ApplicationCalculator",
"name": "Calculator",
"names": {
"bg_Bg": "Клакулатор",
"fr_FR": "Calculatrice",
"it_IT": "Calcolatrice",
"ko_KR": "계산기",
"nl_NL": "Rekenmachine",
"no_NO": "Kalkulator",
"pl_PL": "Kalkulator",
"ru_RU": "Калькулятор",
"sk_SK": "Kalkulačka",
"tr_TR": "Hesap Makinesi",
"vi_VN": "Máy tính"
},
"icon": "apps/calc.png",
"category": "office",
"preload": [
{
"type": "javascript",
"src": "combined.js"
},
{
"type": "stylesheet",
"src": "combined.css"
},
{
"src": "scheme.html",
"type": "scheme"
}
],
"type": "application",
"path": "default/Calculator",
"build": {},
"repo": "default"
}

View File

@ -0,0 +1,87 @@
<application-window data-id="CalculatorWindow">
<gui-vbox>
<gui-vbox-container data-grow="0" data-shrink="1" data-basis="auto">
<gui-text data-id="Output">0</gui-text>
</gui-vbox-container>
<gui-vbox-container data-grow="1" data-shrink="0" data-basis="auto" data-fill="true">
<gui-grid>
<gui-grid-row>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
</gui-grid-row>
<gui-grid-row>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
</gui-grid-row>
<gui-grid-row>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
</gui-grid-row>
<gui-grid-row>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
</gui-grid-row>
<gui-grid-row>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry>
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
<gui-grid-entry style="flex:2 0 auto;">
<gui-button data-id="ButtonX">X</gui-button>
</gui-grid-entry>
</gui-grid-row>
</gui-grid>
</gui-vbox-container>
</gui-vbox>
</application-window>