From 90b819ac0341287e52f9b356cb00200f1f9be87e Mon Sep 17 00:00:00 2001 From: vikas5914 Date: Sat, 28 Jun 2014 02:56:39 +0530 Subject: [PATCH] add Jcalculator Add Epoch time --- .../jcalculator/1403955268/jcalculator.css | 38 ++++++ .../jcalculator/1403955268/jcalculator.js | 129 ++++++++++++++++++ .../1403955268/jcalculator.min.css | 1 + .../jcalculator/1403955268/jcalculator.min.js | 1 + ajax/libs/jcalculator/package.json | 13 ++ 5 files changed, 182 insertions(+) create mode 100644 ajax/libs/jcalculator/1403955268/jcalculator.css create mode 100644 ajax/libs/jcalculator/1403955268/jcalculator.js create mode 100644 ajax/libs/jcalculator/1403955268/jcalculator.min.css create mode 100644 ajax/libs/jcalculator/1403955268/jcalculator.min.js create mode 100644 ajax/libs/jcalculator/package.json diff --git a/ajax/libs/jcalculator/1403955268/jcalculator.css b/ajax/libs/jcalculator/1403955268/jcalculator.css new file mode 100644 index 000000000..bf5ee7565 --- /dev/null +++ b/ajax/libs/jcalculator/1403955268/jcalculator.css @@ -0,0 +1,38 @@ +.jcalculator_wrap { + position: relative; +} +.jcalculator { + background: #232323; + width: 200px; + display: none; + position: absolute; + top: 82px; + right: 0; + font-family: Helvetica, Arial, Verdana, sans-serif; + border-top: 1px solid #000; + border-left: 1px solid #000; +} +.jcalculator span { + cursor: pointer; + color: #fff; + float: left; + display: block; + width: 50px; + height: 50px; + line-height: 50px; + font-size: 12px; + box-sizing: border-box; + -moz-box-sizing: border-box; + -webkit-box-sizing: border-box; + border-right: 1px solid #000; + border-bottom: 1px solid #000; +} +.jcalculator span:active { + line-height: 52px; +} +.jcalculator .operation { + background: #191919; +} +.jcalculator .operation.equal { + background: #eb0934; +} diff --git a/ajax/libs/jcalculator/1403955268/jcalculator.js b/ajax/libs/jcalculator/1403955268/jcalculator.js new file mode 100644 index 000000000..eb1e58ca5 --- /dev/null +++ b/ajax/libs/jcalculator/1403955268/jcalculator.js @@ -0,0 +1,129 @@ +var template = + '
' + + '7' + + '8' + + '9' + + '+' + + '4' + + '5' + + '6' + + '-' + + '1' + + '2' + + '3' + + 'x' + + 'C' + + '0' + + '=' + + '÷' + + '
'; + + +(function($) { + $.fn.calculator = function(theme) { + function Controller(el) { + var self = this; + el.wrap("
"); + el.after(template); + + this.display = el; + this.element = el.next(); + + if (theme) { + this.element.addClass(theme); + } + + this.value = this.load(); + + this.stack = null; + this.stackOp = null; + this.clearStack = true; + + $("span", this.element).on('click', function() { + var code = $(this).text().trim(); + if (isNaN(code)) { + if (code == "C") { + self.digit; + } else if (code.charCodeAt(0) == 247) { + self.op = "/"; + } else { + self.op = code; + } + } else { + self.digit = code; + } + }); + } + + Controller.prototype = { + load: function() { + return this.display.val() || this.display.text(); + }, + save: function() { + if (this.display.is("input")) this.display.val(this.value); + else this.display.text(this.value); + }, + get v() { + return this.value; + }, + set v(val) { + this.clearStack = false; + this.value = val; + this.save(); + }, + get op() { + return this.stackOp; + }, + set op(value) { + switch (this.stackOp) { + case "+": + this.v = this.stack + this.v; + break; + case "-": + this.v = this.stack - this.v; + break; + case "x": + this.v = this.stack * this.v; + break; + case "/": + this.v = this.stack / this.v; + break; + } + this.stack = this.v; + this.stackOp = value; + this.clearStack = true; + }, + set digit(d) { + d = parseInt(d); + if (this.clearStack) return this.v = d; + return this.v = this.v * 10 + d; + }, + get digit() { + if (this.clearStack) return this.v = 0; + return this.v = Math.floor(this.v / 10); + } + }; + + var controller; + this.each(function() { + controller = new Controller($(this)); + $(this).on('focus', function() { + $(".jcalculator").show(); + }); + $("body").click(function() { + $(".jcalculator").hide(); + }); + $(".jcalculator_wrap").click(function(event) { + event.stopPropagation(); + }); + $(document).keyup(function(e) { + if (e.keyCode == 27) { + $(".jcalculator").hide(); + } + }); + + }); + + return controller; + }; +})(jQuery); diff --git a/ajax/libs/jcalculator/1403955268/jcalculator.min.css b/ajax/libs/jcalculator/1403955268/jcalculator.min.css new file mode 100644 index 000000000..6aa757468 --- /dev/null +++ b/ajax/libs/jcalculator/1403955268/jcalculator.min.css @@ -0,0 +1 @@ +.jcalculator_wrap{position:relative}.jcalculator{background:#232323;width:200px;display:none;position:absolute;top:82px;right:0;font-family:Helvetica,Arial,Verdana,sans-serif;border-top:1px solid #000;border-left:1px solid #000}.jcalculator span{cursor:pointer;color:#fff;float:left;display:block;width:50px;height:50px;line-height:50px;font-size:12px;box-sizing:border-box;-moz-box-sizing:border-box;-webkit-box-sizing:border-box;border-right:1px solid #000;border-bottom:1px solid #000}.jcalculator span:active{line-height:52px}.jcalculator .operation{background:#191919}.jcalculator .operation.equal{background:#eb0934} \ No newline at end of file diff --git a/ajax/libs/jcalculator/1403955268/jcalculator.min.js b/ajax/libs/jcalculator/1403955268/jcalculator.min.js new file mode 100644 index 000000000..a25d81785 --- /dev/null +++ b/ajax/libs/jcalculator/1403955268/jcalculator.min.js @@ -0,0 +1 @@ +var template='
789+456-123xC0=÷
';!function(t){t.fn.calculator=function(s){function a(a){var i=this;a.wrap("
"),a.after(template),this.display=a,this.element=a.next(),s&&this.element.addClass(s),this.value=this.load(),this.stack=null,this.stackOp=null,this.clearStack=!0,t("span",this.element).on("click",function(){var s=t(this).text().trim();isNaN(s)?"C"==s?i.digit:i.op=247==s.charCodeAt(0)?"/":s:i.digit=s})}a.prototype={load:function(){return this.display.val()||this.display.text()},save:function(){this.display.is("input")?this.display.val(this.value):this.display.text(this.value)},get v(){return this.value},set v(t){this.clearStack=!1,this.value=t,this.save()},get op(){return this.stackOp},set op(t){switch(this.stackOp){case"+":this.v=this.stack+this.v;break;case"-":this.v=this.stack-this.v;break;case"x":this.v=this.stack*this.v;break;case"/":this.v=this.stack/this.v}this.stack=this.v,this.stackOp=t,this.clearStack=!0},set digit(t){return t=parseInt(t),this.v=this.clearStack?t:10*this.v+t},get digit(){return this.v=this.clearStack?0:Math.floor(this.v/10)}};var i;return this.each(function(){i=new a(t(this)),t(this).on("focus",function(){t(".jcalculator").show()}),t("body").click(function(){t(".jcalculator").hide()}),t(".jcalculator_wrap").click(function(t){t.stopPropagation()}),t(document).keyup(function(s){27==s.keyCode&&t(".jcalculator").hide()})}),i}}(jQuery); \ No newline at end of file diff --git a/ajax/libs/jcalculator/package.json b/ajax/libs/jcalculator/package.json new file mode 100644 index 000000000..b1a424508 --- /dev/null +++ b/ajax/libs/jcalculator/package.json @@ -0,0 +1,13 @@ +{ + "name": "jcalculator", + "filename": "jcalculator.min.js", + "version": "1403955268", + "description": "Awesome jQuery plugin for calculator inputs", + "homepage": "http://mariusbalaj.com/dev/jcalculator/", + "keywords": [ + "calculator", + "jquery", + "input" + ], + "author": "balajmarius" +} \ No newline at end of file