parent
7bc798f848
commit
da6a31a3a2
@ -0,0 +1,472 @@ |
||||
/** |
||||
* DD_roundies, this adds rounded-corner CSS in standard browsers and VML sublayers in IE that accomplish a similar appearance when comparing said browsers. |
||||
* Author: Drew Diller |
||||
* Email: drew.diller@gmail.com |
||||
* URL: http://www.dillerdesign.com/experiment/DD_roundies/
|
||||
* Version: 0.0.2a |
||||
* Licensed under the MIT License: http://dillerdesign.com/experiment/DD_roundies/#license
|
||||
* |
||||
* Usage: |
||||
* DD_roundies.addRule('#doc .container', '10px 5px'); // selector and multiple radii
|
||||
* DD_roundies.addRule('.box', 5, true); // selector, radius, and optional addition of border-radius code for standard browsers.
|
||||
*
|
||||
* Just want the PNG fixing effect for IE6, and don't want to also use the DD_belatedPNG library? Don't give any additional arguments after the CSS selector. |
||||
* DD_roundies.addRule('.your .example img'); |
||||
**/ |
||||
|
||||
var DD_roundies = { |
||||
|
||||
ns: 'DD_roundies', |
||||
|
||||
IE6: false, |
||||
IE7: false, |
||||
IE8: false, |
||||
IEversion: function() { |
||||
if (document.documentMode != 8 && document.namespaces && !document.namespaces[this.ns]) { |
||||
this.IE6 = true; |
||||
this.IE7 = true; |
||||
} |
||||
else if (document.documentMode == 8) { |
||||
this.IE8 = true; |
||||
} |
||||
}, |
||||
querySelector: document.querySelectorAll, |
||||
selectorsToProcess: [], |
||||
imgSize: {}, |
||||
|
||||
createVmlNameSpace: function() { /* enable VML */ |
||||
if (this.IE6 || this.IE7) { |
||||
document.namespaces.add(this.ns, 'urn:schemas-microsoft-com:vml'); |
||||
} |
||||
if (this.IE8) { |
||||
document.writeln('<?import namespace="' + this.ns + '" implementation="#default#VML" ?>'); |
||||
} |
||||
}, |
||||
|
||||
createVmlStyleSheet: function() { /* style VML, enable behaviors */ |
||||
/* |
||||
Just in case lots of other developers have added |
||||
lots of other stylesheets using document.createStyleSheet |
||||
and hit the 31-limit mark, let's not use that method! |
||||
further reading: http://msdn.microsoft.com/en-us/library/ms531194(VS.85).aspx
|
||||
*/ |
||||
var style = document.createElement('style'); |
||||
document.documentElement.firstChild.insertBefore(style, document.documentElement.firstChild.firstChild); |
||||
if (style.styleSheet) { /* IE */ |
||||
try { |
||||
var styleSheet = style.styleSheet; |
||||
styleSheet.addRule(this.ns + '\\:*', '{behavior:url(#default#VML)}'); |
||||
this.styleSheet = styleSheet; |
||||
} catch(err) {} |
||||
} |
||||
else { |
||||
this.styleSheet = style; |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* Method to use from afar - refer to it whenever. |
||||
* Example for IE only: DD_roundies.addRule('div.boxy_box', '10px 5px'); |
||||
* Example for IE, Firefox, and WebKit: DD_roundies.addRule('div.boxy_box', '10px 5px', true); |
||||
* @param {String} selector - REQUIRED - a CSS selector, such as '#doc .container' |
||||
* @param {Integer} radius - REQUIRED - the desired radius for the box corners |
||||
* @param {Boolean} standards - OPTIONAL - true if you also wish to output -moz-border-radius/-webkit-border-radius/border-radius declarations |
||||
**/ |
||||
addRule: function(selector, rad, standards) { |
||||
if (typeof rad == 'undefined' || rad === null) { |
||||
rad = 0; |
||||
} |
||||
if (rad.constructor.toString().search('Array') == -1) { |
||||
rad = rad.toString().replace(/[^0-9 ]/g, '').split(' '); |
||||
} |
||||
for (var i=0; i<4; i++) { |
||||
rad[i] = (!rad[i] && rad[i] !== 0) ? rad[Math.max((i-2), 0)] : rad[i]; |
||||
} |
||||
if (this.styleSheet) { |
||||
if (this.styleSheet.addRule) { /* IE */ |
||||
var selectors = selector.split(','); /* multiple selectors supported, no need for multiple calls to this anymore */ |
||||
for (var i=0; i<selectors.length; i++) { |
||||
this.styleSheet.addRule(selectors[i], 'behavior:expression(DD_roundies.roundify.call(this, [' + rad.join(',') + ']))'); /* seems to execute the function without adding it to the stylesheet - interesting... */ |
||||
} |
||||
} |
||||
else if (standards) { |
||||
var moz_implementation = rad.join('px ') + 'px'; |
||||
this.styleSheet.appendChild(document.createTextNode(selector + ' {border-radius:' + moz_implementation + '; -moz-border-radius:' + moz_implementation + ';}')); |
||||
this.styleSheet.appendChild(document.createTextNode(selector + ' {-webkit-border-top-left-radius:' + rad[0] + 'px ' + rad[0] + 'px; -webkit-border-top-right-radius:' + rad[1] + 'px ' + rad[1] + 'px; -webkit-border-bottom-right-radius:' + rad[2] + 'px ' + rad[2] + 'px; -webkit-border-bottom-left-radius:' + rad[3] + 'px ' + rad[3] + 'px;}')); |
||||
} |
||||
} |
||||
else if (this.IE8) { |
||||
this.selectorsToProcess.push({'selector':selector, 'radii':rad}); |
||||
} |
||||
}, |
||||
|
||||
readPropertyChanges: function(el) { |
||||
switch (event.propertyName) { |
||||
case 'style.border': |
||||
case 'style.borderWidth': |
||||
case 'style.padding': |
||||
this.applyVML(el); |
||||
break; |
||||
case 'style.borderColor': |
||||
this.vmlStrokeColor(el); |
||||
break; |
||||
case 'style.backgroundColor': |
||||
case 'style.backgroundPosition': |
||||
case 'style.backgroundRepeat': |
||||
this.applyVML(el); |
||||
break; |
||||
case 'style.display': |
||||
el.vmlBox.style.display = (el.style.display == 'none') ? 'none' : 'block'; |
||||
break; |
||||
case 'style.filter': |
||||
this.vmlOpacity(el); |
||||
break; |
||||
case 'style.zIndex': |
||||
el.vmlBox.style.zIndex = el.style.zIndex; |
||||
break; |
||||
} |
||||
}, |
||||
|
||||
applyVML: function(el) { |
||||
el.runtimeStyle.cssText = ''; |
||||
this.vmlFill(el); |
||||
this.vmlStrokeColor(el); |
||||
this.vmlStrokeWeight(el); |
||||
this.vmlOffsets(el); |
||||
this.vmlPath(el); |
||||
this.nixBorder(el); |
||||
this.vmlOpacity(el); |
||||
}, |
||||
|
||||
vmlOpacity: function(el) { |
||||
if (el.currentStyle.filter.search('lpha') != -1) { |
||||
var trans = el.currentStyle.filter; |
||||
trans = parseInt(trans.substring(trans.lastIndexOf('=')+1, trans.lastIndexOf(')')), 10)/100; |
||||
for (var v in el.vml) { |
||||
el.vml[v].filler.opacity = trans; |
||||
} |
||||
} |
||||
}, |
||||
|
||||
vmlFill: function(el) { |
||||
if (!el.currentStyle) { |
||||
return; |
||||
} else { |
||||
var elStyle = el.currentStyle; |
||||
} |
||||
el.runtimeStyle.backgroundColor = ''; |
||||
el.runtimeStyle.backgroundImage = ''; |
||||
var noColor = (elStyle.backgroundColor == 'transparent'); |
||||
var noImg = true; |
||||
if (elStyle.backgroundImage != 'none' || el.isImg) { |
||||
if (!el.isImg) { |
||||
el.vmlBg = elStyle.backgroundImage; |
||||
el.vmlBg = el.vmlBg.substr(5, el.vmlBg.lastIndexOf('")')-5); |
||||
} |
||||
else { |
||||
el.vmlBg = el.src; |
||||
} |
||||
var lib = this; |
||||
if (!lib.imgSize[el.vmlBg]) { /* determine size of loaded image */ |
||||
var img = document.createElement('img'); |
||||
img.attachEvent('onload', function() { |
||||
this.width = this.offsetWidth; /* weird cache-busting requirement! */ |
||||
this.height = this.offsetHeight; |
||||
lib.vmlOffsets(el); |
||||
}); |
||||
img.className = lib.ns + '_sizeFinder'; |
||||
img.runtimeStyle.cssText = 'behavior:none; position:absolute; top:-10000px; left:-10000px; border:none;'; /* make sure to set behavior to none to prevent accidental matching of the helper elements! */ |
||||
img.src = el.vmlBg; |
||||
img.removeAttribute('width'); |
||||
img.removeAttribute('height'); |
||||
document.body.insertBefore(img, document.body.firstChild); |
||||
lib.imgSize[el.vmlBg] = img; |
||||
} |
||||
el.vml.image.filler.src = el.vmlBg; |
||||
noImg = false; |
||||
} |
||||
el.vml.image.filled = !noImg; |
||||
el.vml.image.fillcolor = 'none'; |
||||
el.vml.color.filled = !noColor; |
||||
el.vml.color.fillcolor = elStyle.backgroundColor; |
||||
el.runtimeStyle.backgroundImage = 'none'; |
||||
el.runtimeStyle.backgroundColor = 'transparent'; |
||||
}, |
||||
|
||||
vmlStrokeColor: function(el) { |
||||
el.vml.stroke.fillcolor = el.currentStyle.borderColor; |
||||
}, |
||||
|
||||
vmlStrokeWeight: function(el) { |
||||
var borders = ['Top', 'Right', 'Bottom', 'Left']; |
||||
el.bW = {}; |
||||
for (var b=0; b<4; b++) { |
||||
el.bW[borders[b]] = parseInt(el.currentStyle['border' + borders[b] + 'Width'], 10) || 0; |
||||
} |
||||
}, |
||||
|
||||
vmlOffsets: function(el) { |
||||
var dims = ['Left', 'Top', 'Width', 'Height']; |
||||
for (var d=0; d<4; d++) { |
||||
el.dim[dims[d]] = el['offset'+dims[d]]; |
||||
} |
||||
var assign = function(obj, topLeft) { |
||||
obj.style.left = (topLeft ? 0 : el.dim.Left) + 'px'; |
||||
obj.style.top = (topLeft ? 0 : el.dim.Top) + 'px'; |
||||
obj.style.width = el.dim.Width + 'px'; |
||||
obj.style.height = el.dim.Height + 'px'; |
||||
}; |
||||
for (var v in el.vml) { |
||||
var mult = (v == 'image') ? 1 : 2; |
||||
el.vml[v].coordsize = (el.dim.Width*mult) + ', ' + (el.dim.Height*mult); |
||||
assign(el.vml[v], true); |
||||
} |
||||
assign(el.vmlBox, false); |
||||
|
||||
if (DD_roundies.IE8) { |
||||
el.vml.stroke.style.margin = '-1px'; |
||||
if (typeof el.bW == 'undefined') { |
||||
this.vmlStrokeWeight(el); |
||||
} |
||||
el.vml.color.style.margin = (el.bW.Top-1) + 'px ' + (el.bW.Left-1) + 'px'; |
||||
} |
||||
}, |
||||
|
||||
vmlPath: function(el) { |
||||
var coords = function(direction, w, h, r, aL, aT, mult) { |
||||
var cmd = direction ? ['m', 'qy', 'l', 'qx', 'l', 'qy', 'l', 'qx', 'l'] : ['qx', 'l', 'qy', 'l', 'qx', 'l', 'qy', 'l', 'm']; /* whoa */ |
||||
aL *= mult; |
||||
aT *= mult; |
||||
w *= mult; |
||||
h *= mult; |
||||
var R = r.slice(); /* do not affect original array */ |
||||
for (var i=0; i<4; i++) { |
||||
R[i] *= mult; |
||||
R[i] = Math.min(w/2, h/2, R[i]); /* make sure you do not get funky shapes - pick the smallest: half of the width, half of the height, or current value */ |
||||
} |
||||
var coords = [ |
||||
cmd[0] + Math.floor(0+aL) +','+ Math.floor(R[0]+aT), |
||||
cmd[1] + Math.floor(R[0]+aL) +','+ Math.floor(0+aT), |
||||
cmd[2] + Math.ceil(w-R[1]+aL) +','+ Math.floor(0+aT), |
||||
cmd[3] + Math.ceil(w+aL) +','+ Math.floor(R[1]+aT), |
||||
cmd[4] + Math.ceil(w+aL) +','+ Math.ceil(h-R[2]+aT), |
||||
cmd[5] + Math.ceil(w-R[2]+aL) +','+ Math.ceil(h+aT), |
||||
cmd[6] + Math.floor(R[3]+aL) +','+ Math.ceil(h+aT), |
||||
cmd[7] + Math.floor(0+aL) +','+ Math.ceil(h-R[3]+aT), |
||||
cmd[8] + Math.floor(0+aL) +','+ Math.floor(R[0]+aT) |
||||
]; |
||||
if (!direction) { |
||||
coords.reverse(); |
||||
} |
||||
var path = coords.join(''); |
||||
return path; |
||||
}; |
||||
|
||||
if (typeof el.bW == 'undefined') { |
||||
this.vmlStrokeWeight(el); |
||||
} |
||||
var bW = el.bW; |
||||
var rad = el.DD_radii.slice(); |
||||
|
||||
/* determine outer curves */ |
||||
var outer = coords(true, el.dim.Width, el.dim.Height, rad, 0, 0, 2); |
||||
|
||||
/* determine inner curves */ |
||||
rad[0] -= Math.max(bW.Left, bW.Top); |
||||
rad[1] -= Math.max(bW.Top, bW.Right); |
||||
rad[2] -= Math.max(bW.Right, bW.Bottom); |
||||
rad[3] -= Math.max(bW.Bottom, bW.Left); |
||||
for (var i=0; i<4; i++) { |
||||
rad[i] = Math.max(rad[i], 0); |
||||
} |
||||
var inner = coords(false, el.dim.Width-bW.Left-bW.Right, el.dim.Height-bW.Top-bW.Bottom, rad, bW.Left, bW.Top, 2); |
||||
var image = coords(true, el.dim.Width-bW.Left-bW.Right+1, el.dim.Height-bW.Top-bW.Bottom+1, rad, bW.Left, bW.Top, 1); |
||||
|
||||
/* apply huge path string */ |
||||
el.vml.color.path = inner; |
||||
el.vml.image.path = image; |
||||
el.vml.stroke.path = outer + inner; |
||||
|
||||
this.clipImage(el); |
||||
}, |
||||
|
||||
nixBorder: function(el) { |
||||
var s = el.currentStyle; |
||||
var sides = ['Top', 'Left', 'Right', 'Bottom']; |
||||
for (var i=0; i<4; i++) { |
||||
el.runtimeStyle['padding' + sides[i]] = (parseInt(s['padding' + sides[i]], 10) || 0) + (parseInt(s['border' + sides[i] + 'Width'], 10) || 0) + 'px'; |
||||
} |
||||
el.runtimeStyle.border = 'none'; |
||||
}, |
||||
|
||||
clipImage: function(el) { |
||||
var lib = DD_roundies; |
||||
if (!el.vmlBg || !lib.imgSize[el.vmlBg]) { |
||||
return; |
||||
} |
||||
var thisStyle = el.currentStyle; |
||||
var bg = {'X':0, 'Y':0}; |
||||
var figurePercentage = function(axis, position) { |
||||
var fraction = true; |
||||
switch(position) { |
||||
case 'left': |
||||
case 'top': |
||||
bg[axis] = 0; |
||||
break; |
||||
case 'center': |
||||
bg[axis] = 0.5; |
||||
break; |
||||
case 'right': |
||||
case 'bottom': |
||||
bg[axis] = 1; |
||||
break; |
||||
default: |
||||
if (position.search('%') != -1) { |
||||
bg[axis] = parseInt(position, 10) * 0.01; |
||||
} |
||||
else { |
||||
fraction = false; |
||||
} |
||||
} |
||||
var horz = (axis == 'X'); |
||||
bg[axis] = Math.ceil(fraction ? (( el.dim[horz ? 'Width' : 'Height'] - (el.bW[horz ? 'Left' : 'Top'] + el.bW[horz ? 'Right' : 'Bottom']) ) * bg[axis]) - (lib.imgSize[el.vmlBg][horz ? 'width' : 'height'] * bg[axis]) : parseInt(position, 10)); |
||||
bg[axis] += 1; |
||||
}; |
||||
for (var b in bg) { |
||||
figurePercentage(b, thisStyle['backgroundPosition'+b]); |
||||
} |
||||
el.vml.image.filler.position = (bg.X/(el.dim.Width-el.bW.Left-el.bW.Right+1)) + ',' + (bg.Y/(el.dim.Height-el.bW.Top-el.bW.Bottom+1)); |
||||
var bgR = thisStyle.backgroundRepeat; |
||||
var c = {'T':1, 'R':el.dim.Width+1, 'B':el.dim.Height+1, 'L':1}; /* these are defaults for repeat of any kind */ |
||||
var altC = { 'X': {'b1': 'L', 'b2': 'R', 'd': 'Width'}, 'Y': {'b1': 'T', 'b2': 'B', 'd': 'Height'} }; |
||||
if (bgR != 'repeat') { |
||||
c = {'T':(bg.Y), 'R':(bg.X+lib.imgSize[el.vmlBg].width), 'B':(bg.Y+lib.imgSize[el.vmlBg].height), 'L':(bg.X)}; /* these are defaults for no-repeat - clips down to the image location */ |
||||
if (bgR.search('repeat-') != -1) { /* now let's revert to dC for repeat-x or repeat-y */ |
||||
var v = bgR.split('repeat-')[1].toUpperCase(); |
||||
c[altC[v].b1] = 1; |
||||
c[altC[v].b2] = el.dim[altC[v].d]+1; |
||||
} |
||||
if (c.B > el.dim.Height) { |
||||
c.B = el.dim.Height+1; |
||||
} |
||||
} |
||||
el.vml.image.style.clip = 'rect('+c.T+'px '+c.R+'px '+c.B+'px '+c.L+'px)'; |
||||
}, |
||||
|
||||
pseudoClass: function(el) { |
||||
var self = this; |
||||
setTimeout(function() { /* would not work as intended without setTimeout */ |
||||
self.applyVML(el); |
||||
}, 1); |
||||
}, |
||||
|
||||
reposition: function(el) { |
||||
this.vmlOffsets(el); |
||||
this.vmlPath(el); |
||||
}, |
||||
|
||||
roundify: function(rad) { |
||||
this.style.behavior = 'none'; |
||||
if (!this.currentStyle) { |
||||
return; |
||||
} |
||||
else { |
||||
var thisStyle = this.currentStyle; |
||||
} |
||||
var allowed = {BODY: false, TABLE: false, TR: false, TD: false, SELECT: false, OPTION: false, TEXTAREA: false}; |
||||
if (allowed[this.nodeName] === false) { /* elements not supported yet */ |
||||
return; |
||||
} |
||||
var self = this; /* who knows when you might need a setTimeout */ |
||||
var lib = DD_roundies; |
||||
this.DD_radii = rad; |
||||
this.dim = {}; |
||||
|
||||
/* attach handlers */ |
||||
var handlers = {resize: 'reposition', move: 'reposition'}; |
||||
if (this.nodeName == 'A') { |
||||
var moreForAs = {mouseleave: 'pseudoClass', mouseenter: 'pseudoClass', focus: 'pseudoClass', blur: 'pseudoClass'}; |
||||
for (var a in moreForAs) { |
||||
handlers[a] = moreForAs[a]; |
||||
} |
||||
} |
||||
for (var h in handlers) { |
||||
this.attachEvent('on' + h, function() { |
||||
lib[handlers[h]](self); |
||||
}); |
||||
} |
||||
this.attachEvent('onpropertychange', function() { |
||||
lib.readPropertyChanges(self); |
||||
}); |
||||
|
||||
/* ensure that this elent and its parent is given hasLayout (needed for accurate positioning) */ |
||||
var giveLayout = function(el) { |
||||
el.style.zoom = 1; |
||||
if (el.currentStyle.position == 'static') { |
||||
el.style.position = 'relative'; |
||||
} |
||||
}; |
||||
giveLayout(this.offsetParent); |
||||
giveLayout(this); |
||||
|
||||
/* create vml elements */ |
||||
this.vmlBox = document.createElement('ignore'); /* IE8 really wants to be encased in a wrapper element for the VML to work, and I don't want to disturb getElementsByTagName('div') - open to suggestion on how to do this differently */ |
||||
this.vmlBox.runtimeStyle.cssText = 'behavior:none; position:absolute; margin:0; padding:0; border:0; background:none;'; /* super important - if something accidentally matches this (you yourseld did this once, Drew), you'll get infinitely-created elements and a frozen browser! */ |
||||
this.vmlBox.style.zIndex = thisStyle.zIndex; |
||||
this.vml = {'color':true, 'image':true, 'stroke':true}; |
||||
for (var v in this.vml) { |
||||
this.vml[v] = document.createElement(lib.ns + ':shape'); |
||||
this.vml[v].filler = document.createElement(lib.ns + ':fill'); |
||||
this.vml[v].appendChild(this.vml[v].filler); |
||||
this.vml[v].stroked = false; |
||||
this.vml[v].style.position = 'absolute'; |
||||
this.vml[v].style.zIndex = thisStyle.zIndex; |
||||
this.vml[v].coordorigin = '1,1'; |
||||
this.vmlBox.appendChild(this.vml[v]); |
||||
} |
||||
this.vml.image.fillcolor = 'none'; |
||||
this.vml.image.filler.type = 'tile'; |
||||
this.parentNode.insertBefore(this.vmlBox, this); |
||||
|
||||
this.isImg = false; |
||||
if (this.nodeName == 'IMG') { |
||||
this.isImg = true; |
||||
this.style.visibility = 'hidden'; |
||||
} |
||||
|
||||
setTimeout(function() { |
||||
lib.applyVML(self); |
||||
}, 1); |
||||
} |
||||
|
||||
}; |
||||
|
||||
try { |
||||
document.execCommand("BackgroundImageCache", false, true); |
||||
} catch(err) {} |
||||
DD_roundies.IEversion(); |
||||
DD_roundies.createVmlNameSpace(); |
||||
DD_roundies.createVmlStyleSheet(); |
||||
|
||||
if (DD_roundies.IE8 && document.attachEvent && DD_roundies.querySelector) { |
||||
document.attachEvent('onreadystatechange', function() { |
||||
if (document.readyState == 'complete') { |
||||
var selectors = DD_roundies.selectorsToProcess; |
||||
var length = selectors.length; |
||||
var delayedCall = function(node, radii, index) { |
||||
setTimeout(function() { |
||||
DD_roundies.roundify.call(node, radii); |
||||
}, index*100); |
||||
}; |
||||
for (var i=0; i<length; i++) { |
||||
var results = document.querySelectorAll(selectors[i].selector); |
||||
var rLength = results.length; |
||||
for (var r=0; r<rLength; r++) { |
||||
if (results[r].nodeName != 'INPUT') { /* IE8 doesn't like to do this to inputs yet */ |
||||
delayedCall(results[r], selectors[i].radii, r); |
||||
} |
||||
} |
||||
} |
||||
} |
||||
}); |
||||
} |
@ -0,0 +1,74 @@ |
||||
/* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
function addChar(input, character) { |
||||
if(input.value == null || input.value == "0") |
||||
input.value = character |
||||
else |
||||
input.value += character |
||||
} |
||||
|
||||
function cos(form) { |
||||
form.display.value = Math.cos(form.display.value); |
||||
} |
||||
|
||||
function sin(form) { |
||||
form.display.value = Math.sin(form.display.value); |
||||
} |
||||
|
||||
function tan(form) { |
||||
form.display.value = Math.tan(form.display.value); |
||||
} |
||||
|
||||
function sqrt(form) { |
||||
form.display.value = Math.sqrt(form.display.value); |
||||
} |
||||
|
||||
function ln(form) { |
||||
form.display.value = Math.log(form.display.value); |
||||
} |
||||
|
||||
function exp(form) { |
||||
form.display.value = Math.exp(form.display.value); |
||||
} |
||||
|
||||
function deleteChar(input) { |
||||
input.value = input.value.substring(0, input.value.length - 1) |
||||
} |
||||
|
||||
function changeSign(input) { |
||||
if(input.value.substring(0, 1) == "-") |
||||
input.value = input.value.substring(1, input.value.length) |
||||
else |
||||
input.value = "-" + input.value |
||||
} |
||||
|
||||
function square(form) { |
||||
form.display.value = eval(form.display.value) * eval(form.display.value) |
||||
} |
||||
|
||||
function checkNum(str) { |
||||
for (var i = 0; i < str.length; i++) { |
||||
var ch = str.substring(i, i+1) |
||||
if (ch < "0" || ch > "9") { |
||||
if (ch != "/" && ch != "*" && ch != "+" && ch != "-" && ch != "." |
||||
&& ch != "(" && ch!= ")") { |
||||
$("#display").text("ERROR"); |
||||
return false |
||||
} |
||||
} |
||||
} |
||||
return true |
||||
} |
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -0,0 +1,56 @@ |
||||
jQuery.fn.center = function(params) { |
||||
|
||||
var options = { |
||||
|
||||
vertical: true, |
||||
horizontal: true |
||||
|
||||
} |
||||
op = jQuery.extend(options, params); |
||||
|
||||
this.each(function(){ |
||||
|
||||
//initializing variables
|
||||
var $self = jQuery(this); |
||||
//get the dimensions using dimensions plugin
|
||||
var width = $self.width(); |
||||
var height = $self.height(); |
||||
//get the paddings
|
||||
var paddingTop = parseInt($self.css("padding-top")); |
||||
var paddingBottom = parseInt($self.css("padding-bottom")); |
||||
//get the borders
|
||||
var borderTop = parseInt($self.css("border-top-width")); |
||||
var borderBottom = parseInt($self.css("border-bottom-width")); |
||||
//get the media of padding and borders
|
||||
var mediaBorder = (borderTop+borderBottom)/2; |
||||
var mediaPadding = (paddingTop+paddingBottom)/2; |
||||
//get the type of positioning
|
||||
var positionType = $self.parent().css("position"); |
||||
// get the half minus of width and height
|
||||
var halfWidth = (width/2)*(-1); |
||||
var halfHeight = ((height/2)*(-1))-mediaPadding-mediaBorder; |
||||
// initializing the css properties
|
||||
var cssProp = { |
||||
position: 'absolute' |
||||
}; |
||||
|
||||
if(op.vertical) { |
||||
cssProp.height = height; |
||||
cssProp.top = '50%'; |
||||
cssProp.marginTop = halfHeight; |
||||
} |
||||
if(op.horizontal) { |
||||
cssProp.width = width; |
||||
cssProp.left = '50%'; |
||||
cssProp.marginLeft = halfWidth; |
||||
} |
||||
//check the current position
|
||||
if(positionType == 'static') { |
||||
$self.parent().css("position","relative"); |
||||
} |
||||
//aplying the css
|
||||
$self.css(cssProp); |
||||
|
||||
}); |
||||
|
||||
}; |
@ -0,0 +1,62 @@ |
||||
/** |
||||
* .disableTextSelect - Disable Text Select Plugin |
||||
* |
||||
* Version: 1.1 |
||||
* Updated: 2007-11-28 |
||||
* |
||||
* Used to stop users from selecting text |
||||
* |
||||
* Copyright (c) 2007 James Dempster (letssurf@gmail.com, http://www.jdempster.com/category/jquery/disabletextselect/)
|
||||
* |
||||
* Dual licensed under the MIT (MIT-LICENSE.txt) |
||||
* and GPL (GPL-LICENSE.txt) licenses. |
||||
**/ |
||||
|
||||
/** |
||||
* Requirements: |
||||
* - jQuery (John Resig, http://www.jquery.com/)
|
||||
**/ |
||||
(function($) { |
||||
if ($.browser.mozilla) { |
||||
$.fn.disableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).css({ |
||||
'MozUserSelect' : 'none' |
||||
}); |
||||
}); |
||||
}; |
||||
$.fn.enableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).css({ |
||||
'MozUserSelect' : '' |
||||
}); |
||||
}); |
||||
}; |
||||
} else if ($.browser.msie) { |
||||
$.fn.disableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).bind('selectstart.disableTextSelect', function() { |
||||
return false; |
||||
}); |
||||
}); |
||||
}; |
||||
$.fn.enableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).unbind('selectstart.disableTextSelect'); |
||||
}); |
||||
}; |
||||
} else { |
||||
$.fn.disableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).bind('mousedown.disableTextSelect', function() { |
||||
return false; |
||||
}); |
||||
}); |
||||
}; |
||||
$.fn.enableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).unbind('mousedown.disableTextSelect'); |
||||
}); |
||||
}; |
||||
} |
||||
})(jQuery); |
@ -0,0 +1,140 @@ |
||||
/* |
||||
* jQuery EasIng v1.1.2 - http://gsgd.co.uk/sandbox/jquery.easIng.php
|
||||
* |
||||
* Uses the built In easIng capabilities added In jQuery 1.1 |
||||
* to offer multiple easIng options |
||||
* |
||||
* Copyright (c) 2007 George Smith |
||||
* Licensed under the MIT License: |
||||
* http://www.opensource.org/licenses/mit-license.php
|
||||
*/ |
||||
|
||||
// t: current time, b: begInnIng value, c: change In value, d: duration
|
||||
|
||||
jQuery.extend( jQuery.easing, |
||||
{ |
||||
easeInQuad: function (x, t, b, c, d) { |
||||
return c*(t/=d)*t + b; |
||||
}, |
||||
easeOutQuad: function (x, t, b, c, d) { |
||||
return -c *(t/=d)*(t-2) + b; |
||||
}, |
||||
easeInOutQuad: function (x, t, b, c, d) { |
||||
if ((t/=d/2) < 1) return c/2*t*t + b; |
||||
return -c/2 * ((--t)*(t-2) - 1) + b; |
||||
}, |
||||
easeInCubic: function (x, t, b, c, d) { |
||||
return c*(t/=d)*t*t + b; |
||||
}, |
||||
easeOutCubic: function (x, t, b, c, d) { |
||||
return c*((t=t/d-1)*t*t + 1) + b; |
||||
}, |
||||
easeInOutCubic: function (x, t, b, c, d) { |
||||
if ((t/=d/2) < 1) return c/2*t*t*t + b; |
||||
return c/2*((t-=2)*t*t + 2) + b; |
||||
}, |
||||
easeInQuart: function (x, t, b, c, d) { |
||||
return c*(t/=d)*t*t*t + b; |
||||
}, |
||||
easeOutQuart: function (x, t, b, c, d) { |
||||
return -c * ((t=t/d-1)*t*t*t - 1) + b; |
||||
}, |
||||
easeInOutQuart: function (x, t, b, c, d) { |
||||
if ((t/=d/2) < 1) return c/2*t*t*t*t + b; |
||||
return -c/2 * ((t-=2)*t*t*t - 2) + b; |
||||
}, |
||||
easeInQuint: function (x, t, b, c, d) { |
||||
return c*(t/=d)*t*t*t*t + b; |
||||
}, |
||||
easeOutQuint: function (x, t, b, c, d) { |
||||
return c*((t=t/d-1)*t*t*t*t + 1) + b; |
||||
}, |
||||
easeInOutQuint: function (x, t, b, c, d) { |
||||
if ((t/=d/2) < 1) return c/2*t*t*t*t*t + b; |
||||
return c/2*((t-=2)*t*t*t*t + 2) + b; |
||||
}, |
||||
easeInSine: function (x, t, b, c, d) { |
||||
return -c * Math.cos(t/d * (Math.PI/2)) + c + b; |
||||
}, |
||||
easeOutSine: function (x, t, b, c, d) { |
||||
return c * Math.sin(t/d * (Math.PI/2)) + b; |
||||
}, |
||||
easeInOutSine: function (x, t, b, c, d) { |
||||
return -c/2 * (Math.cos(Math.PI*t/d) - 1) + b; |
||||
}, |
||||
easeInExpo: function (x, t, b, c, d) { |
||||
return (t==0) ? b : c * Math.pow(2, 10 * (t/d - 1)) + b; |
||||
}, |
||||
easeOutExpo: function (x, t, b, c, d) { |
||||
return (t==d) ? b+c : c * (-Math.pow(2, -10 * t/d) + 1) + b; |
||||
}, |
||||
easeInOutExpo: function (x, t, b, c, d) { |
||||
if (t==0) return b; |
||||
if (t==d) return b+c; |
||||
if ((t/=d/2) < 1) return c/2 * Math.pow(2, 10 * (t - 1)) + b; |
||||
return c/2 * (-Math.pow(2, -10 * --t) + 2) + b; |
||||
}, |
||||
easeInCirc: function (x, t, b, c, d) { |
||||
return -c * (Math.sqrt(1 - (t/=d)*t) - 1) + b; |
||||
}, |
||||
easeOutCirc: function (x, t, b, c, d) { |
||||
return c * Math.sqrt(1 - (t=t/d-1)*t) + b; |
||||
}, |
||||
easeInOutCirc: function (x, t, b, c, d) { |
||||
if ((t/=d/2) < 1) return -c/2 * (Math.sqrt(1 - t*t) - 1) + b; |
||||
return c/2 * (Math.sqrt(1 - (t-=2)*t) + 1) + b; |
||||
}, |
||||
easeInElastic: function (x, t, b, c, d) { |
||||
var s=1.70158;var p=0;var a=c; |
||||
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; |
||||
if (a < Math.abs(c)) { a=c; var s=p/4; } |
||||
else var s = p/(2*Math.PI) * Math.asin (c/a); |
||||
return -(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; |
||||
}, |
||||
easeOutElastic: function (x, t, b, c, d) { |
||||
var s=1.70158;var p=0;var a=c; |
||||
if (t==0) return b; if ((t/=d)==1) return b+c; if (!p) p=d*.3; |
||||
if (a < Math.abs(c)) { a=c; var s=p/4; } |
||||
else var s = p/(2*Math.PI) * Math.asin (c/a); |
||||
return a*Math.pow(2,-10*t) * Math.sin( (t*d-s)*(2*Math.PI)/p ) + c + b; |
||||
}, |
||||
easeInOutElastic: function (x, t, b, c, d) { |
||||
var s=1.70158;var p=0;var a=c; |
||||
if (t==0) return b; if ((t/=d/2)==2) return b+c; if (!p) p=d*(.3*1.5); |
||||
if (a < Math.abs(c)) { a=c; var s=p/4; } |
||||
else var s = p/(2*Math.PI) * Math.asin (c/a); |
||||
if (t < 1) return -.5*(a*Math.pow(2,10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )) + b; |
||||
return a*Math.pow(2,-10*(t-=1)) * Math.sin( (t*d-s)*(2*Math.PI)/p )*.5 + c + b; |
||||
}, |
||||
easeInBack: function (x, t, b, c, d, s) { |
||||
if (s == undefined) s = 1.70158; |
||||
return c*(t/=d)*t*((s+1)*t - s) + b; |
||||
}, |
||||
easeOutBack: function (x, t, b, c, d, s) { |
||||
if (s == undefined) s = 1.70158; |
||||
return c*((t=t/d-1)*t*((s+1)*t + s) + 1) + b; |
||||
}, |
||||
easeInOutBack: function (x, t, b, c, d, s) { |
||||
if (s == undefined) s = 1.70158;
|
||||
if ((t/=d/2) < 1) return c/2*(t*t*(((s*=(1.525))+1)*t - s)) + b; |
||||
return c/2*((t-=2)*t*(((s*=(1.525))+1)*t + s) + 2) + b; |
||||
}, |
||||
easeInBounce: function (x, t, b, c, d) { |
||||
return c - jQuery.easing.easeOutBounce (x, d-t, 0, c, d) + b; |
||||
}, |
||||
easeOutBounce: function (x, t, b, c, d) { |
||||
if ((t/=d) < (1/2.75)) { |
||||
return c*(7.5625*t*t) + b; |
||||
} else if (t < (2/2.75)) { |
||||
return c*(7.5625*(t-=(1.5/2.75))*t + .75) + b; |
||||
} else if (t < (2.5/2.75)) { |
||||
return c*(7.5625*(t-=(2.25/2.75))*t + .9375) + b; |
||||
} else { |
||||
return c*(7.5625*(t-=(2.625/2.75))*t + .984375) + b; |
||||
} |
||||
}, |
||||
easeInOutBounce: function (x, t, b, c, d) { |
||||
if (t < d/2) return jQuery.easing.easeInBounce (x, t*2, 0, c, d) * .5 + b; |
||||
return jQuery.easing.easeOutBounce (x, t*2-d, 0, c, d) * .5 + c*.5 + b; |
||||
} |
||||
}); |
@ -0,0 +1,259 @@ |
||||
(function($) { |
||||
jQuery.fn.ubwidget = function(options) { |
||||
var settings = jQuery.extend({}, jQuery.fn.ubwidget.defaults, options); |
||||
|
||||
DD_roundies.addRule('.ubw-standard-corners', '5px', true); |
||||
DD_roundies.addRule('.ubw-button-corners', '4px', true); |
||||
DD_roundies.addRule('.ubw-i-corners', '4px', true); |
||||
|
||||
$(window) |
||||
.bind("blur", function(event){
|
||||
}) |
||||
.trigger("focus"); |
||||
|
||||
return this.each(function() {
|
||||
var ubwbody = $(this)
|
||||
.addClass("ubw-body"); |
||||
|
||||
var ubwcontainer = $("<div></div>") |
||||
.append(ubwbody)
|
||||
.addClass("ubw-container") |
||||
.css({ |
||||
width:settings.width, |
||||
height:settings.height |
||||
}) |
||||
.disableTextSelect(); |
||||
|
||||
$('body').append(ubwcontainer); |
||||
}); |
||||
}; |
||||
|
||||
// Default options
|
||||
|
||||
jQuery.fn.ubwidget.defaults = { |
||||
width:200, |
||||
height:250 |
||||
}; |
||||
|
||||
// Shadows
|
||||
|
||||
jQuery.fn.ubwshadows = function(settings){ |
||||
|
||||
var shadow = $("<div class='ubw-shadow'></div>") |
||||
.addClass("ubw-standard-corners") |
||||
.css({ |
||||
backgroundColor:"#333377", |
||||
opacity:".1", |
||||
filter: "alpha(opacity = 10)",
|
||||
position:"absolute", |
||||
top:settings.t, |
||||
left:settings.l, |
||||
width:settings.w, |
||||
height:settings.h |
||||
}); |
||||
|
||||
$(this).before(shadow); |
||||
}; |
||||
|
||||
jQuery.fn.ubwbutton = function(size, arrows) { |
||||
var arrows = typeof(arrows) != "undefined" ? arrows = arrows : arrows = {top:0, right:0, bottom:0, left:0}; |
||||
var button = null; |
||||
var scale = 0.20; |
||||
var url = ""; |
||||
var buttonbody; |
||||
|
||||
|
||||
return this.each(function() { |
||||
button = $(this) |
||||
.addClass("ubw-button-wrapper") |
||||
.css({zIndex:0});
|
||||
|
||||
url = $(this).find("img").attr("src"); |
||||
url = url.split("."); |
||||
|
||||
var buttonContent = $("<table cellpadding='0' cellspacing='0' border='0' width='auto' height='100%'><tr><td height='auto' width='auto' valign='middle' align='center'></td></tr></table>") |
||||
.addClass("ubw-button-content"); |
||||
buttonContent.find("td").html($(this).html()); |
||||
$(this).empty(); |
||||
|
||||
var buttonCanvas = $("<div></div>") |
||||
.addClass("ubw-button-canvas") |
||||
.appendTo(button) |
||||
.html('<table width="auto" height="auto" cellpadding="0" cellspacing="0"><tr><td class="ubw-button-arrowTop" align="center"><img style="visibility:hidden; margin-bottom:-1px" src="images/arrows_out/top.png"></td></tr><tr><td><table width="auto" height="auto" border="0" cellpadding="0" cellspacing="0"><tr><td class="ubw-button-arrowLeft"><img style="visibility:hidden; margin-right:-1px" src="images/arrows_out/left.png"></td><td class="ubw-button-body"></td><td class="ubw-button-arrowRight"><img style="visibility:hidden; margin-left:-1px" src="images/arrows_out/right.png"></td></tr></table></td></tr><tr><td class="ubw-button-arrowBottom" align="center"><img style="visibility:hidden; margin-top:-1px" src="images/arrows_out/bottom.png"></td></tr></table>'); |
||||
|
||||
if(arrows.top)buttonCanvas.find(".ubw-button-arrowTop").children("img").css({visibility:"visible"}); |
||||
if(arrows.right)buttonCanvas.find(".ubw-button-arrowRight").children("img").css({visibility:"visible"}); |
||||
if(arrows.bottom)buttonCanvas.find(".ubw-button-arrowBottom").children("img").css({visibility:"visible"}); |
||||
if(arrows.left)buttonCanvas.find(".ubw-button-arrowLeft").children("img").css({visibility:"visible"}); |
||||
|
||||
var buttonBody = buttonCanvas.find(".ubw-button-body")
|
||||
.addClass("ubw-button-out") |
||||
.append(buttonContent) |
||||
.bind("mouseenter", buttonOverHandler) |
||||
.bind("mouseleave", buttonOutHandler) |
||||
.bind("mousedown", buttonDownHandler) |
||||
.bind("mouseup", buttonUpHandler) |
||||
.css({ |
||||
width:size.w, |
||||
height:size.h |
||||
}); |
||||
|
||||
button.width(size.w+9).height(size.h+2);
|
||||
buttonbody = buttonBody.find(".ubw-button-content");
|
||||
});
|
||||
|
||||
|
||||
function buttonOverHandler(e) { |
||||
buttonbody.find("img").attr("src", url[0]+"_over.png"); |
||||
|
||||
button.css({ |
||||
zIndex:1 |
||||
}); |
||||
}; |
||||
|
||||
function buttonOutHandler(e){ |
||||
buttonbody.find("img").attr("src", url[0]+".png"); |
||||
|
||||
button.css({ |
||||
zIndex:0 |
||||
}); |
||||
};
|
||||
|
||||
function buttonDownHandler(e){ |
||||
buttonbody.find("img").attr("src", url[0]+"_over_down.png"); |
||||
}; |
||||
|
||||
function buttonUpHandler(e){ |
||||
url[0] = url[0].replace("_down", ""); |
||||
buttonbody.find("img").attr("src", url[0]+"_over.png"); |
||||
}; |
||||
|
||||
}; |
||||
|
||||
jQuery.fn.ubwtoggle = function(activated, _firstFunc, _secondFunc) { |
||||
var activated = typeof(activated) != "undefined" ? activated = 1 : activated = 0; |
||||
|
||||
return this.each(function(){ |
||||
var button = $(this); |
||||
var buttonBody = button.find(".ubw-button-body"); |
||||
var img = buttonBody.find("img"); |
||||
var imgsrc = img.attr("src"); |
||||
|
||||
var firstFunc = _firstFunc; |
||||
var secondFunc = _secondFunc; |
||||
|
||||
buttonBody |
||||
.toggle( |
||||
function(){ |
||||
img.css({visibility:"hidden"}); |
||||
firstFunc(); |
||||
},
|
||||
function(){ |
||||
img.css({visibility:"visible"}); |
||||
secondFunc(); |
||||
} |
||||
);
|
||||
|
||||
if(activated){ |
||||
buttonBody.trigger("click"); |
||||
};
|
||||
}); |
||||
}; |
||||
|
||||
|
||||
jQuery.fn.ubwidget.sliderbutton = function() { |
||||
|
||||
};
|
||||
|
||||
jQuery.fn.ubwidget.inspector = function(_position, content, button){ |
||||
|
||||
var position = {x:_position.x, y:_position.y}; |
||||
|
||||
var catcher = $("<div id='ubw-catcher'></div>") |
||||
.css({ |
||||
position:"absolute", |
||||
width:"100%", |
||||
height:"100%" |
||||
}) |
||||
.mousedown(function(){ |
||||
inspector.hide(); |
||||
removeDropShadow(); |
||||
catcher.hide(); |
||||
//resizeubcanvas()
|
||||
}); |
||||
|
||||
$("body").append(catcher); |
||||
catcher.hide(); |
||||
|
||||
var inspector = $("<div class='ubw-inspector'></div>") |
||||
.css({
|
||||
left:position.x, |
||||
top:position.y |
||||
}) |
||||
.append(content) |
||||
.appendTo($("body")) |
||||
.hide() |
||||
.disableTextSelect(); |
||||
|
||||
var inspectorWidth = inspector.width(); |
||||
var inspectorHeight = inspector.height();
|
||||
var windowWidth = $(window).width(); |
||||
var windowHeight = $(window).height();
|
||||
|
||||
$("body").prepend(button); |
||||
button.addClass("ubw-rounded") |
||||
.click(function(){ |
||||
catcher.show(); |
||||
inspector.show(); |
||||
dropShadow(); |
||||
resizeubcanvas() |
||||
}); |
||||
|
||||
function dropShadow (){ |
||||
inspector.ubwshadows({w:inspectorWidth+23,h:inspectorHeight+22,l:55,t:55})} |
||||
function removeDropShadow (){ |
||||
$(".ubw-shadow").remove()} |
||||
|
||||
// !!
|
||||
$(".ubw-shadow") |
||||
.mousedown(function(){ |
||||
inspector.hide(); |
||||
removeDropShadow(); |
||||
catcher.hide(); |
||||
resizeubcanvas() |
||||
}); |
||||
|
||||
function resizeWidget(w, h){ |
||||
window.resizeTo(w+2, h+2); |
||||
$("#indicator").remove(); |
||||
var indicator = $("<div id='indicator'></div>") |
||||
.css({ |
||||
width:w, |
||||
height:h, |
||||
position:"absolute", |
||||
left:0, |
||||
top:0, |
||||
border:"1px solid #ff0000" |
||||
}); |
||||
//$("body").prepend(indicator);
|
||||
} |
||||
|
||||
function resizeubcanvas(){ |
||||
|
||||
if(inspector.css("display")=="none"){ |
||||
resizeWidget(windowWidth, windowHeight); |
||||
return 0; |
||||
}; |
||||
|
||||
var inspectorbottom = inspector.position().top+inspector.height()+40; |
||||
var inspectorright = inspector.position().left+inspector.width()+40; |
||||
|
||||
if($(window).height()<inspectorbottom){ |
||||
resizeWidget($(window).width(), inspectorbottom)}; |
||||
|
||||
if($(window).width()<inspectorright){ |
||||
resizeWidget(inspectorright, $(window).height())}; |
||||
} |
||||
}; |
||||
|
||||
})(jQuery); |
@ -0,0 +1,526 @@ |
||||
/* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU General Public License as published by |
||||
* the Free Software Foundation, either version 3 of the License, or |
||||
* (at your option) any later version. |
||||
* |
||||
* This program is distributed in the hope that it will be useful, |
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||||
* GNU General Public License for more details. |
||||
* |
||||
* You should have received a copy of the GNU General Public License |
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/ |
||||
|
||||
function init(){ |
||||
var h = 292; |
||||
var w = 160; |
||||
var wh = h+6; |
||||
var ww = w+6; |
||||
var clickFlag = false; |
||||
|
||||
var ubwidget = $("#ubwidget").ubwidget({ |
||||
width:w, |
||||
height:h |
||||
}); |
||||
|
||||
var historyTab = $("<div></div>") |
||||
.css({ |
||||
height:h, |
||||
marginRight:0, |
||||
width:20, |
||||
float:"left", |
||||
backgroundImage:"url(images/historytab.png)", |
||||
backgroundRepeat:"no-repeat" |
||||
}) |
||||
.toggle( |
||||
function(){ |
||||
resizeWidget(370, 294); |
||||
historyPanel.show(); |
||||
$(".ubw-container").css({ |
||||
backgroundImage:"url(images/back.png)", |
||||
width:328 |
||||
}); |
||||
if(window.sankore){ |
||||
window.sankore.setPreference('historyTab', "visible"); |
||||
}; |
||||
}, |
||||
function(){ |
||||
resizeWidget(200, 294); |
||||
historyPanel.hide(); |
||||
$(".ubw-container").css({ |
||||
backgroundImage:"url(images/back_small.png)", |
||||
width:160 |
||||
}); |
||||
if(window.sankore){ |
||||
window.sankore.setPreference('historyTab', "hidden"); |
||||
}; |
||||
} |
||||
) |
||||
.hover( |
||||
function(){ |
||||
$(this).css({ |
||||
backgroundImage:"url(images/historytabOver.png)" |
||||
}); |
||||
}, |
||||
function(){ |
||||
$(this).css({ |
||||
backgroundImage:"url(images/historytab.png)" |
||||
}); |
||||
} |
||||
) |
||||
.appendTo($("body")); |
||||
|
||||
var space = $("<div></div>"); |
||||
space.css({ |
||||
width:5,
|
||||
height:1,
|
||||
float:"left" |
||||
}); |
||||
|
||||
var keysPanel = $("<div id='keysPanel'></div>").css({ |
||||
float:"left" |
||||
}); |
||||
var mode = "standard"; |
||||
var calc = ""; |
||||
var displayTrunk = ""; |
||||
var historyTrunk = ""; |
||||
var lastHistory = ""; |
||||
var subtrunk = 0; |
||||
var itrunk = 0; |
||||
var trunkpos = 0; |
||||
var lastchar = { |
||||
type:"NaN",
|
||||
value:"null" |
||||
}; |
||||
var inparenthesis = false; |
||||
var erase = false; |
||||
var abtn; |
||||
var readyToCompute = false; |
||||
var lastResult = "0"; |
||||
var gDecimalSeparator = ""; |
||||
var gThousandsSeparator = ""; |
||||
var gDecimalCode = 0; |
||||
var gDecimalString = ""; |
||||
var gError = false; |
||||
|
||||
var historyTxt = "0"; |
||||
|
||||
var display = $("<div id='display'>0</div>") |
||||
.addClass("ubw-inputbox") |
||||
.css({ |
||||
padding:"12px", |
||||
marginLeft:"2px", |
||||
marginBottom:"9px",
|
||||
marginTop:7, |
||||
backgroundImage:"url(images/display.png)", |
||||
fontSize:"22px", |
||||
fontFamily:"Arial, Helvetica, Sans-serif", |
||||
color:"#777788", |
||||
width:118, |
||||
height:28, |
||||
overflow:"hidden", |
||||
textAlign:"right", |
||||
}); |
||||
|
||||
var standardPanel = $("<div></div>").css({ |
||||
float:"left" |
||||
}); |
||||
|
||||
var cKeySize = { |
||||
w:33,
|
||||
h:36 |
||||
}; |
||||
|
||||
var btn7 = $("<div><img src='images/touche7.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("7", 1) |
||||
}); |
||||
var btn8 = $("<div><img src='images/touche8.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("8", 1) |
||||
}); |
||||
var btn9 = $("<div><img src='images/touche9.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("9", 1) |
||||
}); |
||||
var btnDiv = $("<div><img src='images/touchediv.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("/", 0) |
||||
}); |
||||
var btn4 = $("<div><img src='images/touche4.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("4", 1) |
||||
}); |
||||
var btn5 = $("<div><img src='images/touche5.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("5", 1) |
||||
}); |
||||
var btn6 = $("<div><img src='images/touche6.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("6", 1) |
||||
}); |
||||
var btnMul = $("<div><img src='images/touchef.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("*", 0) |
||||
}); |
||||
var btn1 = $("<div><img src='images/touche1.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("1", 1) |
||||
}); |
||||
var btn2 = $("<div><img src='images/touche2.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("2", 1) |
||||
}); |
||||
var btn3 = $("<div><img src='images/touche3.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("3", 1) |
||||
}); |
||||
var btnSou = $("<div><img src='images/touchem.png'/></div>").ubwbutton({ |
||||
w:68,
|
||||
h:34 |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("-", 0) |
||||
}); |
||||
var btn0 = $("<div><img src='images/touche0.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("0", 1) |
||||
}); |
||||
var btnDot = $("<div><img src='images/touchedot.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay(".", 1) |
||||
}); |
||||
var btnC = $("<div><img src='images/touchec.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
reset() |
||||
}); |
||||
var btnAdd = $("<div><img src='images/touchep.png'/></div>").ubwbutton({ |
||||
w:68,
|
||||
h:34 |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("+", 0) |
||||
}); |
||||
var btnPaL = $("<div><img src='images/touchepg.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay("(", 1) |
||||
}); |
||||
var btnPaR = $("<div><img src='images/touchepd.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
appendToDisplay(")", 1) |
||||
}); |
||||
var btnEqu = $("<div><img src='images/toucheeq.png'/></div>").ubwbutton({ |
||||
w:cKeySize.w,
|
||||
h:cKeySize.h |
||||
}) |
||||
.mousedown(function(){ |
||||
compute() |
||||
});
|
||||
|
||||
var historyPanel = $("<div id='historyPanel'></div>") |
||||
.css({ |
||||
backgroundImage:"url(images/historyback.png)", |
||||
width:"auto", |
||||
height:"auto", |
||||
float:"left", |
||||
marginLeft:3, |
||||
marginRight:2, |
||||
marginTop:6 |
||||
}) |
||||
.hide(); |
||||
|
||||
var historyBox = $("<textarea id='historyBox'></textarea>") |
||||
.css({ |
||||
padding:10, |
||||
fontSize:"20px", |
||||
fontFamily:"Arial, Helvetica, Sans-serif", |
||||
width:143, |
||||
height:236, |
||||
backgroundColor:"transparent", |
||||
resize:"none", |
||||
border:"none", |
||||
overlay:"none", |
||||
color:"#eeeeee" |
||||
}) |
||||
.val("0"); |
||||
|
||||
historyPanel.append(historyBox); |
||||
|
||||
var stop = $("<div></div>"); |
||||
var sleft = $("<div></div>"); |
||||
var sright = $("<div></div>"); |
||||
|
||||
stop.css({ |
||||
width:140 |
||||
}) |
||||
.append(btnAdd).append(btnSou) |
||||
.append(btn7).append(btn8).append(btn9).append(btnMul) |
||||
.append(btn4).append(btn5).append(btn6).append(btnDiv); |
||||
|
||||
sleft.css({ |
||||
width:105,
|
||||
float:"left" |
||||
}) |
||||
.append(btn1).append(btn2).append(btn3) |
||||
.append(btn0).append(btnDot).append(btnC); |
||||
|
||||
sright.css({ |
||||
width:45,
|
||||
float:"left" |
||||
}) |
||||
.append(btnEqu); |
||||
|
||||
|
||||
standardPanel.css({ |
||||
width:150 |
||||
}) |
||||
.append(stop) |
||||
.append(sleft).append(sright); |
||||
|
||||
keysPanel |
||||
.append(display) |
||||
.append(standardPanel); |
||||
|
||||
ubwidget |
||||
.append(historyPanel) |
||||
.append(keysPanel); |
||||
|
||||
if(window.sankore){ |
||||
historyTxt = window.sankore.preference('historyTxt', historyTxt); |
||||
var ht = window.sankore.preference('historyTab', "hidden"); |
||||
$("#historyBox").val(historyTxt); |
||||
if(ht === "visible"){ |
||||
historyTab.trigger("click"); |
||||
}; |
||||
} |
||||
|
||||
function resizeWidget(w, h){ |
||||
window.sankore.resize(w+2, h+2); |
||||
} |
||||
|
||||
function compute(){ |
||||
var result = eval(calc)
|
||||
|
||||
$("#display").text(updateDisplay(result)); |
||||
lastResult = result; |
||||
lastchar.type = "Nan"; |
||||
lastchar.value = ""; |
||||
calc = ""; |
||||
|
||||
$("#historyBox").val($("#historyBox").val()+historyTrunk+"\n= "+updateDisplay(result)+"\n\n"); |
||||
$("#historyBox").scrollTop(99999); |
||||
|
||||
displayTrunk = ""; |
||||
historyTrunk = ""; |
||||
|
||||
if(window.sankore){ |
||||
window.sankore.setPreference('historyTxt', $("#historyBox").val()); |
||||
}; |
||||
|
||||
lastHistory = $("#historyBox").val(); |
||||
} |
||||
|
||||
function reset(){ |
||||
$("#display").text("0"); |
||||
calc=""; |
||||
displayTrunk=""; |
||||
historyTrunk=""; |
||||
$("#historyBox").val(lastHistory); |
||||
$("#historyBox").scrollTop(99999); |
||||
} |
||||
|
||||
function formatNumberWithDelimiters(number) { |
||||
var delimiter = gThousandsSeparator; |
||||
var numString = number.toString(); |
||||
|
||||
if (!numString) |
||||
return "0"; |
||||
|
||||
var dot = numString.indexOf(gDecimalSeparator); |
||||
if (dot == -1) |
||||
dot = numString.length; |
||||
|
||||
var stop = numString.length-dot; |
||||
var characteristic = numString.substr(0, dot); |
||||
if (!parseInt(characteristic)) |
||||
return numString; |
||||
|
||||
// see if it's a negative number
|
||||
var numIsNegative = (parseInt(characteristic) < 0) |
||||
|
||||
var newNumber = ""; |
||||
var delimiterCount = Math.floor((characteristic.length-1) / 3); |
||||
var extras = characteristic.length % 3; |
||||
if (!extras && characteristic.length > 2) |
||||
extras = 3; |
||||
|
||||
if (extras) |
||||
newNumber = newNumber + characteristic.substr(0, extras); |
||||
|
||||
for (var i=0;i< delimiterCount; i++) { |
||||
|
||||
if ( (0 == i) && numIsNegative && (extras == 1)) |
||||
newNumber = newNumber + characteristic.substr(extras + (i * 3), 3); |
||||
else |
||||
newNumber = newNumber + delimiter + characteristic.substr(extras + (i * 3), 3); |
||||
} |
||||
|
||||
return (dot ? (newNumber + numString.substr(dot, stop)) : newNumber); |
||||
} |
||||
|
||||
|
||||
function formatNumberWithScientificNotation(number) { |
||||
if (number == 0) |
||||
return number; |
||||
|
||||
var numString = number.toString(); |
||||
if (!numString) |
||||
return "0"; |
||||
|
||||
var num = new Number(numString); |
||||
var sci = num.toExponential(5); |
||||
if (sci == "NaN") |
||||
sci = formatNumberWithDelimiters(numString); |
||||
if (!sci) |
||||
return "0"; |
||||
|
||||
return sci; |
||||
} |
||||
|
||||
function updateDisplay(number){ |
||||
if(String(number).length > 8){ |
||||
number = formatNumberWithScientificNotation(number); |
||||
} |
||||
else{ |
||||
number = number; |
||||
} |
||||
|
||||
return number; |
||||
} |
||||
|
||||
function appendToDisplay(_char, v){ |
||||
var char = _char; |
||||
|
||||
// Display
|
||||
if($("#historyBox").val() === "0"){ |
||||
$("#historyBox").val(""); |
||||
}; |
||||
|
||||
if(char == "-" && lastchar.type == "NaN"){ |
||||
char = "m"; |
||||
}; |
||||
|
||||
// char is a number
|
||||
if(char <= 0 || char > 0 || char == "." || char == "m" || char == "(" || char == ")"){ |
||||
if(char == "m"){ |
||||
char = "-"; |
||||
}; |
||||
|
||||
if(lastchar.type == "NaN"){ |
||||
displayTrunk = ""; |
||||
}; |
||||
|
||||
if(lastchar.value == "." && char == "."){ |
||||
calc = calc.substr(0, calc.length-1); |
||||
displayTrunk = displayTrunk.substr(0, displayTrunk.length-1); |
||||
}; |
||||
|
||||
calc += String(char); |
||||
displayTrunk += String(char); |
||||
historyTrunk += String(char); |
||||
lastchar.type = "Number"; |
||||
} |
||||
// char is an operator
|
||||
else { |
||||
if(calc.length === 0){ |
||||
var endCalc = calc; |
||||
calc = lastResult + endCalc; |
||||
historyTrunk = updateDisplay(lastResult); |
||||
} |
||||
|
||||
if(lastchar.type == "NaN"){ |
||||
calc = calc.substr(0, calc.length-1); |
||||
calc += char; |
||||
$("#historyBox").val($("#historyBox").val().substr(0, $("#historyBox").val().length-1)); |
||||
} |
||||
else{ |
||||
try{ |
||||
calc = eval(calc) + String(char); |
||||
}catch(e){} |
||||
} |
||||
|
||||
lastchar.type = "NaN"; |
||||
try{ |
||||
displayTrunk = eval(calc.substr(0, calc.length-1)); |
||||
}catch(e){} |
||||
$("#historyBox").val($("#historyBox").val()+historyTrunk+char); |
||||
$("#historyBox").scrollTop(99999); |
||||
historyTrunk = ""; |
||||
} |
||||
|
||||
lastchar.value = char; |
||||
$("#display").text(updateDisplay(displayTrunk)); |
||||
} |
||||
|
||||
$("#historyBox").click(function(){ |
||||
if(!clickFlag){ |
||||
$(this).select(); |
||||
clickFlag = true;
|
||||
} |
||||
else{ |
||||
clickFlag = false; |
||||
$(this).blur(); |
||||
} |
||||
}); |
||||
$(document).disableTextSelect(); |
||||
}; |
File diff suppressed because one or more lines are too long
@ -0,0 +1,62 @@ |
||||
/** |
||||
* .disableTextSelect - Disable Text Select Plugin |
||||
* |
||||
* Version: 1.1 |
||||
* Updated: 2007-11-28 |
||||
* |
||||
* Used to stop users from selecting text |
||||
* |
||||
* Copyright (c) 2007 James Dempster (letssurf@gmail.com, http://www.jdempster.com/category/jquery/disabletextselect/)
|
||||
* |
||||
* Dual licensed under the MIT (MIT-LICENSE.txt) |
||||
* and GPL (GPL-LICENSE.txt) licenses. |
||||
**/ |
||||
|
||||
/** |
||||
* Requirements: |
||||
* - jQuery (John Resig, http://www.jquery.com/)
|
||||
**/ |
||||
(function($) { |
||||
if ($.browser.mozilla) { |
||||
$.fn.disableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).css({ |
||||
'MozUserSelect' : 'none' |
||||
}); |
||||
}); |
||||
}; |
||||
$.fn.enableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).css({ |
||||
'MozUserSelect' : '' |
||||
}); |
||||
}); |
||||
}; |
||||
} else if ($.browser.msie) { |
||||
$.fn.disableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).bind('selectstart.disableTextSelect', function() { |
||||
return false; |
||||
}); |
||||
}); |
||||
}; |
||||
$.fn.enableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).unbind('selectstart.disableTextSelect'); |
||||
}); |
||||
}; |
||||
} else { |
||||
$.fn.disableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).bind('mousedown.disableTextSelect', function() { |
||||
return false; |
||||
}); |
||||
}); |
||||
}; |
||||
$.fn.enableTextSelect = function() { |
||||
return this.each(function() { |
||||
$(this).unbind('mousedown.disableTextSelect'); |
||||
}); |
||||
}; |
||||
} |
||||
})(jQuery); |
Loading…
Reference in new issue