initial commit
This commit is contained in:
parent
bcb4250466
commit
bcb79777a6
194
lib/phast/client/scripts/Base64.js
Normal file
194
lib/phast/client/scripts/Base64.js
Normal file
@ -0,0 +1,194 @@
|
|||||||
|
/*
|
||||||
|
* $Id: base64.js,v 2.15 2014/04/05 12:58:57 dankogai Exp dankogai $
|
||||||
|
*
|
||||||
|
* Licensed under the BSD 3-Clause License.
|
||||||
|
* http://opensource.org/licenses/BSD-3-Clause
|
||||||
|
*
|
||||||
|
* References:
|
||||||
|
* http://en.wikipedia.org/wiki/Base64
|
||||||
|
*/
|
||||||
|
|
||||||
|
(function(global) {
|
||||||
|
'use strict';
|
||||||
|
// existing version for noConflict()
|
||||||
|
var _Base64 = global.Base64;
|
||||||
|
var version = "2.1.9";
|
||||||
|
// if node.js, we use Buffer
|
||||||
|
var buffer;
|
||||||
|
if (typeof module !== 'undefined' && module.exports) {
|
||||||
|
try {
|
||||||
|
buffer = require('buffer').Buffer;
|
||||||
|
} catch (err) {}
|
||||||
|
}
|
||||||
|
// constants
|
||||||
|
var b64chars
|
||||||
|
= 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
||||||
|
var b64tab = function(bin) {
|
||||||
|
var t = {};
|
||||||
|
for (var i = 0, l = bin.length; i < l; i++) t[bin.charAt(i)] = i;
|
||||||
|
return t;
|
||||||
|
}(b64chars);
|
||||||
|
var fromCharCode = String.fromCharCode;
|
||||||
|
// encoder stuff
|
||||||
|
var cb_utob = function(c) {
|
||||||
|
if (c.length < 2) {
|
||||||
|
var cc = c.charCodeAt(0);
|
||||||
|
return cc < 0x80 ? c
|
||||||
|
: cc < 0x800 ? (fromCharCode(0xc0 | (cc >>> 6))
|
||||||
|
+ fromCharCode(0x80 | (cc & 0x3f)))
|
||||||
|
: (fromCharCode(0xe0 | ((cc >>> 12) & 0x0f))
|
||||||
|
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
||||||
|
+ fromCharCode(0x80 | ( cc & 0x3f)));
|
||||||
|
} else {
|
||||||
|
var cc = 0x10000
|
||||||
|
+ (c.charCodeAt(0) - 0xD800) * 0x400
|
||||||
|
+ (c.charCodeAt(1) - 0xDC00);
|
||||||
|
return (fromCharCode(0xf0 | ((cc >>> 18) & 0x07))
|
||||||
|
+ fromCharCode(0x80 | ((cc >>> 12) & 0x3f))
|
||||||
|
+ fromCharCode(0x80 | ((cc >>> 6) & 0x3f))
|
||||||
|
+ fromCharCode(0x80 | ( cc & 0x3f)));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var re_utob = /[\uD800-\uDBFF][\uDC00-\uDFFFF]|[^\x00-\x7F]/g;
|
||||||
|
var utob = function(u) {
|
||||||
|
return u.replace(re_utob, cb_utob);
|
||||||
|
};
|
||||||
|
var cb_encode = function(ccc) {
|
||||||
|
var padlen = [0, 2, 1][ccc.length % 3],
|
||||||
|
ord = ccc.charCodeAt(0) << 16
|
||||||
|
| ((ccc.length > 1 ? ccc.charCodeAt(1) : 0) << 8)
|
||||||
|
| ((ccc.length > 2 ? ccc.charCodeAt(2) : 0)),
|
||||||
|
chars = [
|
||||||
|
b64chars.charAt( ord >>> 18),
|
||||||
|
b64chars.charAt((ord >>> 12) & 63),
|
||||||
|
padlen >= 2 ? '=' : b64chars.charAt((ord >>> 6) & 63),
|
||||||
|
padlen >= 1 ? '=' : b64chars.charAt(ord & 63)
|
||||||
|
];
|
||||||
|
return chars.join('');
|
||||||
|
};
|
||||||
|
var btoa = global.btoa ? function(b) {
|
||||||
|
return global.btoa(b);
|
||||||
|
} : function(b) {
|
||||||
|
return b.replace(/[\s\S]{1,3}/g, cb_encode);
|
||||||
|
};
|
||||||
|
var _encode = buffer ? function (u) {
|
||||||
|
return (u.constructor === buffer.constructor ? u : new buffer(u))
|
||||||
|
.toString('base64')
|
||||||
|
}
|
||||||
|
: function (u) { return btoa(utob(u)) }
|
||||||
|
;
|
||||||
|
var encode = function(u, urisafe) {
|
||||||
|
return !urisafe
|
||||||
|
? _encode(String(u))
|
||||||
|
: _encode(String(u)).replace(/[+\/]/g, function(m0) {
|
||||||
|
return m0 == '+' ? '-' : '_';
|
||||||
|
}).replace(/=/g, '');
|
||||||
|
};
|
||||||
|
var encodeURI = function(u) { return encode(u, true) };
|
||||||
|
// decoder stuff
|
||||||
|
var re_btou = new RegExp([
|
||||||
|
'[\xC0-\xDF][\x80-\xBF]',
|
||||||
|
'[\xE0-\xEF][\x80-\xBF]{2}',
|
||||||
|
'[\xF0-\xF7][\x80-\xBF]{3}'
|
||||||
|
].join('|'), 'g');
|
||||||
|
var cb_btou = function(cccc) {
|
||||||
|
switch(cccc.length) {
|
||||||
|
case 4:
|
||||||
|
var cp = ((0x07 & cccc.charCodeAt(0)) << 18)
|
||||||
|
| ((0x3f & cccc.charCodeAt(1)) << 12)
|
||||||
|
| ((0x3f & cccc.charCodeAt(2)) << 6)
|
||||||
|
| (0x3f & cccc.charCodeAt(3)),
|
||||||
|
offset = cp - 0x10000;
|
||||||
|
return (fromCharCode((offset >>> 10) + 0xD800)
|
||||||
|
+ fromCharCode((offset & 0x3FF) + 0xDC00));
|
||||||
|
case 3:
|
||||||
|
return fromCharCode(
|
||||||
|
((0x0f & cccc.charCodeAt(0)) << 12)
|
||||||
|
| ((0x3f & cccc.charCodeAt(1)) << 6)
|
||||||
|
| (0x3f & cccc.charCodeAt(2))
|
||||||
|
);
|
||||||
|
default:
|
||||||
|
return fromCharCode(
|
||||||
|
((0x1f & cccc.charCodeAt(0)) << 6)
|
||||||
|
| (0x3f & cccc.charCodeAt(1))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
var btou = function(b) {
|
||||||
|
return b.replace(re_btou, cb_btou);
|
||||||
|
};
|
||||||
|
var cb_decode = function(cccc) {
|
||||||
|
var len = cccc.length,
|
||||||
|
padlen = len % 4,
|
||||||
|
n = (len > 0 ? b64tab[cccc.charAt(0)] << 18 : 0)
|
||||||
|
| (len > 1 ? b64tab[cccc.charAt(1)] << 12 : 0)
|
||||||
|
| (len > 2 ? b64tab[cccc.charAt(2)] << 6 : 0)
|
||||||
|
| (len > 3 ? b64tab[cccc.charAt(3)] : 0),
|
||||||
|
chars = [
|
||||||
|
fromCharCode( n >>> 16),
|
||||||
|
fromCharCode((n >>> 8) & 0xff),
|
||||||
|
fromCharCode( n & 0xff)
|
||||||
|
];
|
||||||
|
chars.length -= [0, 0, 2, 1][padlen];
|
||||||
|
return chars.join('');
|
||||||
|
};
|
||||||
|
var atob = global.atob ? function(a) {
|
||||||
|
return global.atob(a);
|
||||||
|
} : function(a){
|
||||||
|
return a.replace(/[\s\S]{1,4}/g, cb_decode);
|
||||||
|
};
|
||||||
|
var _decode = buffer ? function(a) {
|
||||||
|
return (a.constructor === buffer.constructor
|
||||||
|
? a : new buffer(a, 'base64')).toString();
|
||||||
|
}
|
||||||
|
: function(a) { return btou(atob(a)) };
|
||||||
|
var decode = function(a){
|
||||||
|
return _decode(
|
||||||
|
String(a).replace(/[-_]/g, function(m0) { return m0 == '-' ? '+' : '/' })
|
||||||
|
.replace(/[^A-Za-z0-9\+\/]/g, '')
|
||||||
|
);
|
||||||
|
};
|
||||||
|
var noConflict = function() {
|
||||||
|
var Base64 = global.Base64;
|
||||||
|
global.Base64 = _Base64;
|
||||||
|
return Base64;
|
||||||
|
};
|
||||||
|
// export Base64
|
||||||
|
global.Base64 = {
|
||||||
|
VERSION: version,
|
||||||
|
atob: atob,
|
||||||
|
btoa: btoa,
|
||||||
|
fromBase64: decode,
|
||||||
|
toBase64: encode,
|
||||||
|
utob: utob,
|
||||||
|
encode: encode,
|
||||||
|
encodeURI: encodeURI,
|
||||||
|
btou: btou,
|
||||||
|
decode: decode,
|
||||||
|
noConflict: noConflict
|
||||||
|
};
|
||||||
|
// if ES5 is available, make Base64.extendString() available
|
||||||
|
if (typeof Object.defineProperty === 'function') {
|
||||||
|
var noEnum = function(v){
|
||||||
|
return {value:v,enumerable:false,writable:true,configurable:true};
|
||||||
|
};
|
||||||
|
global.Base64.extendString = function () {
|
||||||
|
Object.defineProperty(
|
||||||
|
String.prototype, 'fromBase64', noEnum(function () {
|
||||||
|
return decode(this)
|
||||||
|
}));
|
||||||
|
Object.defineProperty(
|
||||||
|
String.prototype, 'toBase64', noEnum(function (urisafe) {
|
||||||
|
return encode(this, urisafe)
|
||||||
|
}));
|
||||||
|
Object.defineProperty(
|
||||||
|
String.prototype, 'toBase64URI', noEnum(function () {
|
||||||
|
return encode(this, true)
|
||||||
|
}));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
// that's it!
|
||||||
|
if (global['Meteor']) {
|
||||||
|
Base64 = global.Base64; // for normal export in Meteor.js
|
||||||
|
}
|
||||||
|
})(this);
|
||||||
469
lib/phast/client/scripts/JSMin.inc.php
Normal file
469
lib/phast/client/scripts/JSMin.inc.php
Normal file
@ -0,0 +1,469 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace JSMin;
|
||||||
|
|
||||||
|
class UnterminatedStringException extends \Exception {
|
||||||
|
}
|
||||||
|
class UnterminatedRegExpException extends \Exception {
|
||||||
|
}
|
||||||
|
class UnterminatedCommentException extends \Exception {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSMin.php - modified PHP implementation of Douglas Crockford's JSMin.
|
||||||
|
*
|
||||||
|
* <code>
|
||||||
|
* $minifiedJs = JSMin::minify($js);
|
||||||
|
* </code>
|
||||||
|
*
|
||||||
|
* This is a modified port of jsmin.c. Improvements:
|
||||||
|
*
|
||||||
|
* Does not choke on some regexp literals containing quote characters. E.g. /'/
|
||||||
|
*
|
||||||
|
* Spaces are preserved after some add/sub operators, so they are not mistakenly
|
||||||
|
* converted to post-inc/dec. E.g. a + ++b -> a+ ++b
|
||||||
|
*
|
||||||
|
* Preserves multi-line comments that begin with /*!
|
||||||
|
*
|
||||||
|
* PHP 5 or higher is required.
|
||||||
|
*
|
||||||
|
* Permission is hereby granted to use this version of the library under the
|
||||||
|
* same terms as jsmin.c, which has the following license:
|
||||||
|
*
|
||||||
|
* --
|
||||||
|
* Copyright (c) 2002 Douglas Crockford (www.crockford.com)
|
||||||
|
*
|
||||||
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||||
|
* this software and associated documentation files (the "Software"), to deal in
|
||||||
|
* the Software without restriction, including without limitation the rights to
|
||||||
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
|
||||||
|
* of the Software, and to permit persons to whom the Software is furnished to do
|
||||||
|
* so, subject to the following conditions:
|
||||||
|
*
|
||||||
|
* The above copyright notice and this permission notice shall be included in all
|
||||||
|
* copies or substantial portions of the Software.
|
||||||
|
*
|
||||||
|
* The Software shall be used for Good, not Evil.
|
||||||
|
*
|
||||||
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
* SOFTWARE.
|
||||||
|
* --
|
||||||
|
*
|
||||||
|
* @package JSMin
|
||||||
|
* @author Ryan Grove <ryan@wonko.com> (PHP port)
|
||||||
|
* @author Steve Clay <steve@mrclay.org> (modifications + cleanup)
|
||||||
|
* @author Andrea Giammarchi <http://www.3site.eu> (spaceBeforeRegExp)
|
||||||
|
* @copyright 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
|
||||||
|
* @copyright 2008 Ryan Grove <ryan@wonko.com> (PHP port)
|
||||||
|
* @license http://opensource.org/licenses/mit-license.php MIT License
|
||||||
|
* @link http://code.google.com/p/jsmin-php/
|
||||||
|
*/
|
||||||
|
class JSMin {
|
||||||
|
const ACTION_KEEP_A = 1;
|
||||||
|
const ACTION_DELETE_A = 2;
|
||||||
|
const ACTION_DELETE_A_B = 3;
|
||||||
|
|
||||||
|
protected $a = "\n";
|
||||||
|
protected $b = '';
|
||||||
|
protected $input = '';
|
||||||
|
protected $inputIndex = 0;
|
||||||
|
protected $inputLength = 0;
|
||||||
|
protected $lookAhead = null;
|
||||||
|
protected $output = '';
|
||||||
|
protected $lastByteOut = '';
|
||||||
|
protected $keptComment = '';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Minify Javascript.
|
||||||
|
*
|
||||||
|
* @param string $js Javascript to be minified
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public static function minify($js)
|
||||||
|
{
|
||||||
|
$jsmin = new JSMin($js);
|
||||||
|
return $jsmin->min();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $input
|
||||||
|
*/
|
||||||
|
public function __construct($input)
|
||||||
|
{
|
||||||
|
$this->input = $input;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Perform minification, return result
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function min()
|
||||||
|
{
|
||||||
|
if ($this->output !== '') { // min already run
|
||||||
|
return $this->output;
|
||||||
|
}
|
||||||
|
|
||||||
|
$mbIntEnc = null;
|
||||||
|
if (function_exists('mb_strlen') && ((int)ini_get('mbstring.func_overload') & 2)) {
|
||||||
|
$mbIntEnc = mb_internal_encoding();
|
||||||
|
mb_internal_encoding('8bit');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($this->input[0]) && $this->input[0] === "\xef") {
|
||||||
|
$this->input = substr($this->input, 3);
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->input = str_replace("\r\n", "\n", $this->input);
|
||||||
|
$this->inputLength = strlen($this->input);
|
||||||
|
|
||||||
|
$this->action(self::ACTION_DELETE_A_B);
|
||||||
|
|
||||||
|
while ($this->a !== null) {
|
||||||
|
// determine next command
|
||||||
|
$command = self::ACTION_KEEP_A; // default
|
||||||
|
if ($this->isWhiteSpace($this->a)) {
|
||||||
|
if (($this->lastByteOut === '+' || $this->lastByteOut === '-')
|
||||||
|
&& ($this->b === $this->lastByteOut)) {
|
||||||
|
// Don't delete this space. If we do, the addition/subtraction
|
||||||
|
// could be parsed as a post-increment
|
||||||
|
} elseif (! $this->isAlphaNum($this->b)) {
|
||||||
|
$command = self::ACTION_DELETE_A;
|
||||||
|
}
|
||||||
|
} elseif ($this->isLineTerminator($this->a)) {
|
||||||
|
if ($this->isWhiteSpace($this->b)) {
|
||||||
|
$command = self::ACTION_DELETE_A_B;
|
||||||
|
|
||||||
|
// in case of mbstring.func_overload & 2, must check for null b,
|
||||||
|
// otherwise mb_strpos will give WARNING
|
||||||
|
} elseif ($this->b === null
|
||||||
|
|| (false === strpos('{[(+-!~#', $this->b)
|
||||||
|
&& ! $this->isAlphaNum($this->b))) {
|
||||||
|
$command = self::ACTION_DELETE_A;
|
||||||
|
}
|
||||||
|
} elseif (! $this->isAlphaNum($this->a)) {
|
||||||
|
if ($this->isWhiteSpace($this->b)
|
||||||
|
|| ($this->isLineTerminator($this->b)
|
||||||
|
&& (false === strpos('}])+-"\'`', $this->a)))) {
|
||||||
|
$command = self::ACTION_DELETE_A_B;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$this->action($command);
|
||||||
|
}
|
||||||
|
$this->output = trim($this->output);
|
||||||
|
|
||||||
|
if ($mbIntEnc !== null) {
|
||||||
|
mb_internal_encoding($mbIntEnc);
|
||||||
|
}
|
||||||
|
return $this->output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
|
||||||
|
* ACTION_DELETE_A = Copy B to A. Get the next B.
|
||||||
|
* ACTION_DELETE_A_B = Get the next B.
|
||||||
|
*
|
||||||
|
* @param int $command
|
||||||
|
* @throws UnterminatedRegExpException|UnterminatedStringException
|
||||||
|
*/
|
||||||
|
protected function action($command)
|
||||||
|
{
|
||||||
|
// make sure we don't compress "a + ++b" to "a+++b", etc.
|
||||||
|
if ($command === self::ACTION_DELETE_A_B
|
||||||
|
&& $this->b === ' '
|
||||||
|
&& ($this->a === '+' || $this->a === '-')) {
|
||||||
|
// Note: we're at an addition/substraction operator; the inputIndex
|
||||||
|
// will certainly be a valid index
|
||||||
|
if ($this->input[$this->inputIndex] === $this->a) {
|
||||||
|
// This is "+ +" or "- -". Don't delete the space.
|
||||||
|
$command = self::ACTION_KEEP_A;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch ($command) {
|
||||||
|
case self::ACTION_KEEP_A: // 1
|
||||||
|
$this->output .= $this->a;
|
||||||
|
|
||||||
|
if ($this->keptComment) {
|
||||||
|
$this->output = rtrim($this->output, "\n");
|
||||||
|
$this->output .= $this->keptComment;
|
||||||
|
$this->keptComment = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->lastByteOut = $this->a;
|
||||||
|
|
||||||
|
// fallthrough intentional
|
||||||
|
case self::ACTION_DELETE_A: // 2
|
||||||
|
$this->a = $this->b;
|
||||||
|
if ($this->a === "'" || $this->a === '"' || $this->a === '`') { // string/template literal
|
||||||
|
$delimiter = $this->a;
|
||||||
|
$str = $this->a; // in case needed for exception
|
||||||
|
for(;;) {
|
||||||
|
$this->output .= $this->a;
|
||||||
|
$this->lastByteOut = $this->a;
|
||||||
|
|
||||||
|
$this->a = $this->get();
|
||||||
|
if ($this->a === $this->b) { // end quote
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($delimiter === '`' && $this->isLineTerminator($this->a)) {
|
||||||
|
// leave the newline
|
||||||
|
} elseif ($this->isEOF($this->a)) {
|
||||||
|
$byte = $this->inputIndex - 1;
|
||||||
|
throw new UnterminatedStringException(
|
||||||
|
"JSMin: Unterminated String at byte {$byte}: {$str}");
|
||||||
|
}
|
||||||
|
$str .= $this->a;
|
||||||
|
if ($this->a === '\\') {
|
||||||
|
$this->output .= $this->a;
|
||||||
|
$this->lastByteOut = $this->a;
|
||||||
|
|
||||||
|
$this->a = $this->get();
|
||||||
|
$str .= $this->a;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// fallthrough intentional
|
||||||
|
case self::ACTION_DELETE_A_B: // 3
|
||||||
|
$this->b = $this->next();
|
||||||
|
if ($this->b === '/' && $this->isRegexpLiteral()) {
|
||||||
|
$this->output .= $this->a . $this->b;
|
||||||
|
$pattern = '/'; // keep entire pattern in case we need to report it in the exception
|
||||||
|
for(;;) {
|
||||||
|
$this->a = $this->get();
|
||||||
|
$pattern .= $this->a;
|
||||||
|
if ($this->a === '[') {
|
||||||
|
for(;;) {
|
||||||
|
$this->output .= $this->a;
|
||||||
|
$this->a = $this->get();
|
||||||
|
$pattern .= $this->a;
|
||||||
|
if ($this->a === ']') {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ($this->a === '\\') {
|
||||||
|
$this->output .= $this->a;
|
||||||
|
$this->a = $this->get();
|
||||||
|
$pattern .= $this->a;
|
||||||
|
}
|
||||||
|
if ($this->isEOF($this->a)) {
|
||||||
|
throw new UnterminatedRegExpException(
|
||||||
|
"JSMin: Unterminated set in RegExp at byte "
|
||||||
|
. $this->inputIndex .": {$pattern}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($this->a === '/') { // end pattern
|
||||||
|
break; // while (true)
|
||||||
|
} elseif ($this->a === '\\') {
|
||||||
|
$this->output .= $this->a;
|
||||||
|
$this->a = $this->get();
|
||||||
|
$pattern .= $this->a;
|
||||||
|
} elseif ($this->isEOF($this->a)) {
|
||||||
|
$byte = $this->inputIndex - 1;
|
||||||
|
throw new UnterminatedRegExpException(
|
||||||
|
"JSMin: Unterminated RegExp at byte {$byte}: {$pattern}");
|
||||||
|
}
|
||||||
|
$this->output .= $this->a;
|
||||||
|
$this->lastByteOut = $this->a;
|
||||||
|
}
|
||||||
|
$this->b = $this->next();
|
||||||
|
}
|
||||||
|
// end case ACTION_DELETE_A_B
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isRegexpLiteral()
|
||||||
|
{
|
||||||
|
if (false !== strpos("(,=:[!&|?+-~*{;", $this->a)) {
|
||||||
|
// we can't divide after these tokens
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if first non-ws token is "/" (see starts-regex.js)
|
||||||
|
$length = strlen($this->output);
|
||||||
|
if ($this->isWhiteSpace($this->a) || $this->isLineTerminator($this->a)) {
|
||||||
|
if ($length < 2) { // weird edge case
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// if the "/" follows a keyword, it must be a regexp, otherwise it's best to assume division
|
||||||
|
|
||||||
|
$subject = $this->output . trim($this->a);
|
||||||
|
if (!preg_match('/(?:case|else|in|return|typeof)$/', $subject, $m)) {
|
||||||
|
// not a keyword
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// can't be sure it's a keyword yet (see not-regexp.js)
|
||||||
|
$charBeforeKeyword = substr($subject, 0 - strlen($m[0]) - 1, 1);
|
||||||
|
if ($this->isAlphaNum($charBeforeKeyword)) {
|
||||||
|
// this is really an identifier ending in a keyword, e.g. "xreturn"
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// it's a regexp. Remove unneeded whitespace after keyword
|
||||||
|
if ($this->isWhiteSpace($this->a) || $this->isLineTerminator($this->a)) {
|
||||||
|
$this->a = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the next character from stdin. Watch out for lookahead. If the character is a control character,
|
||||||
|
* translate it to a space or linefeed.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function get()
|
||||||
|
{
|
||||||
|
$c = $this->lookAhead;
|
||||||
|
$this->lookAhead = null;
|
||||||
|
if ($c === null) {
|
||||||
|
// getc(stdin)
|
||||||
|
if ($this->inputIndex < $this->inputLength) {
|
||||||
|
$c = $this->input[$this->inputIndex];
|
||||||
|
$this->inputIndex += 1;
|
||||||
|
} else {
|
||||||
|
$c = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if ($c === "\r") {
|
||||||
|
return "\n";
|
||||||
|
}
|
||||||
|
return $c;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Does $a indicate end of input?
|
||||||
|
*
|
||||||
|
* @param string $a
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isEOF($a)
|
||||||
|
{
|
||||||
|
return $a === null || $this->isLineTerminator($a);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get next char (without getting it). If is ctrl character, translate to a space or newline.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function peek()
|
||||||
|
{
|
||||||
|
$this->lookAhead = $this->get();
|
||||||
|
return $this->lookAhead;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
|
||||||
|
*
|
||||||
|
* @param string $c
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
protected function isAlphaNum($c)
|
||||||
|
{
|
||||||
|
return (preg_match('/^[a-z0-9A-Z_\\$\\\\]$/', $c) || ord($c) > 126);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consume a single line comment from input (possibly retaining it)
|
||||||
|
*/
|
||||||
|
protected function consumeSingleLineComment()
|
||||||
|
{
|
||||||
|
$comment = '';
|
||||||
|
while (true) {
|
||||||
|
$get = $this->get();
|
||||||
|
$comment .= $get;
|
||||||
|
if ($this->isEOF($get)) {
|
||||||
|
// if IE conditional comment
|
||||||
|
if (preg_match('/^\\/@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||||
|
$this->keptComment .= "/{$comment}";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Consume a multiple line comment from input (possibly retaining it)
|
||||||
|
*
|
||||||
|
* @throws UnterminatedCommentException
|
||||||
|
*/
|
||||||
|
protected function consumeMultipleLineComment()
|
||||||
|
{
|
||||||
|
$this->get();
|
||||||
|
$comment = '';
|
||||||
|
for(;;) {
|
||||||
|
$get = $this->get();
|
||||||
|
if ($get === '*') {
|
||||||
|
if ($this->peek() === '/') { // end of comment reached
|
||||||
|
$this->get();
|
||||||
|
if (0 === strpos($comment, '!')) {
|
||||||
|
// preserved by YUI Compressor
|
||||||
|
if (!$this->keptComment) {
|
||||||
|
// don't prepend a newline if two comments right after one another
|
||||||
|
$this->keptComment = "\n";
|
||||||
|
}
|
||||||
|
$this->keptComment .= "/*!" . substr($comment, 1) . "*/\n";
|
||||||
|
} else if (preg_match('/^@(?:cc_on|if|elif|else|end)\\b/', $comment)) {
|
||||||
|
// IE conditional
|
||||||
|
$this->keptComment .= "/*{$comment}*/";
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} elseif ($get === null) {
|
||||||
|
throw new UnterminatedCommentException(
|
||||||
|
"JSMin: Unterminated comment at byte {$this->inputIndex}: /*{$comment}");
|
||||||
|
}
|
||||||
|
$comment .= $get;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the next character, skipping over comments. Some comments may be preserved.
|
||||||
|
*
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
protected function next()
|
||||||
|
{
|
||||||
|
$get = $this->get();
|
||||||
|
if ($get === '/') {
|
||||||
|
switch ($this->peek()) {
|
||||||
|
case '/':
|
||||||
|
$this->consumeSingleLineComment();
|
||||||
|
$get = "\n";
|
||||||
|
break;
|
||||||
|
case '*':
|
||||||
|
$this->consumeMultipleLineComment();
|
||||||
|
$get = ' ';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $get;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isWhiteSpace($s) {
|
||||||
|
// https://www.ecma-international.org/ecma-262/#sec-white-space
|
||||||
|
return $s !== null && strpos(" \t\v\f", $s) !== false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function isLineTerminator($s) {
|
||||||
|
// https://www.ecma-international.org/ecma-262/#sec-line-terminators
|
||||||
|
return $s !== null && strpos("\n\r", $s) !== false;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
lib/phast/client/scripts/MousePosition.js
Normal file
11
lib/phast/client/scripts/MousePosition.js
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
function MousePosition()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
MousePosition.X = 0;
|
||||||
|
MousePosition.Y = 0;
|
||||||
|
|
||||||
|
document.addEventListener("mousemove", function(e)
|
||||||
|
{
|
||||||
|
MousePosition.X = e.clientX;
|
||||||
|
MousePosition.Y = e.clientY;
|
||||||
|
});
|
||||||
13
lib/phast/client/scripts/PrependArgument.js
Normal file
13
lib/phast/client/scripts/PrependArgument.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
Function.prototype.PrependArgument = function(arg)
|
||||||
|
{
|
||||||
|
var func = this;
|
||||||
|
return function()
|
||||||
|
{
|
||||||
|
var newargs = [arg];
|
||||||
|
for (var i = 0; i < arguments.length; i++)
|
||||||
|
{
|
||||||
|
newargs.push(arguments[i]);
|
||||||
|
}
|
||||||
|
return func.apply(this, newargs);
|
||||||
|
};
|
||||||
|
};
|
||||||
770
lib/phast/client/scripts/System.js
Normal file
770
lib/phast/client/scripts/System.js
Normal file
@ -0,0 +1,770 @@
|
|||||||
|
function StringPadDirection(value)
|
||||||
|
{
|
||||||
|
this._value = value;
|
||||||
|
}
|
||||||
|
StringPadDirection.Left = new StringPadDirection(1);
|
||||||
|
StringPadDirection.Right = new StringPadDirection(2);
|
||||||
|
StringPadDirection.Both = new StringPadDirection(3);
|
||||||
|
|
||||||
|
function StringPad(str, len, pad, dir)
|
||||||
|
{
|
||||||
|
if (typeof(len) == "undefined") len = 0;
|
||||||
|
if (typeof(pad) == "undefined") pad = ' ';
|
||||||
|
if (typeof(dir) == "undefined") dir = StringPadDirection.Right;
|
||||||
|
|
||||||
|
if (len + 1 >= str.length)
|
||||||
|
{
|
||||||
|
if (dir == StringPadDirection.Left)
|
||||||
|
{
|
||||||
|
str = Array(len + 1 - str.length).join(pad) + str;
|
||||||
|
}
|
||||||
|
else if (dir == StringPadDirection.Both)
|
||||||
|
{
|
||||||
|
var right = Math.ceil((padlen = len - str.length) / 2);
|
||||||
|
var left = padlen - right;
|
||||||
|
str = Array(left+1).join(pad) + str + Array(right+1).join(pad);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str = str + Array(len + 1 - str.length).join(pad);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
String.prototype.padLeft = function(length, value)
|
||||||
|
{
|
||||||
|
return StringPad(this, length, value, StringPadDirection.Left);
|
||||||
|
}
|
||||||
|
String.prototype.padRight = function(length, value)
|
||||||
|
{
|
||||||
|
return StringPad(this, length, value, StringPadDirection.Right);
|
||||||
|
}
|
||||||
|
String.prototype.pad = function(length, value)
|
||||||
|
{
|
||||||
|
return StringPad(this, length, value, StringPadDirection.Both);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Event arguments for an event that can be canceled.
|
||||||
|
*/
|
||||||
|
function CancelEventArgs()
|
||||||
|
{
|
||||||
|
this.Cancel = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function EventArgs()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
EventArgs.Empty = new EventArgs();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration for mouse button values
|
||||||
|
*/
|
||||||
|
function MouseButtons()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* No mouse buttons are being pressed.
|
||||||
|
*/
|
||||||
|
MouseButtons.None = 0;
|
||||||
|
/**
|
||||||
|
* The primary (usually left) button is being pressed.
|
||||||
|
*/
|
||||||
|
MouseButtons.Primary = 1;
|
||||||
|
/**
|
||||||
|
* The secondary (usually right) button is being pressed.
|
||||||
|
*/
|
||||||
|
MouseButtons.Secondary = 2;
|
||||||
|
/**
|
||||||
|
* The tertiary (usually wheel) button is being pressed.
|
||||||
|
*/
|
||||||
|
MouseButtons.Tertiary = 4;
|
||||||
|
/**
|
||||||
|
* The additional primary button is being pressed.
|
||||||
|
*/
|
||||||
|
MouseButtons.XButton1 = 8;
|
||||||
|
/**
|
||||||
|
* The additional secondary button is being pressed.
|
||||||
|
*/
|
||||||
|
MouseButtons.XButton2 = 16;
|
||||||
|
|
||||||
|
function MouseEventArgs(button, x, y)
|
||||||
|
{
|
||||||
|
this.Button = button;
|
||||||
|
this.X = x;
|
||||||
|
this.Y = y;
|
||||||
|
this.NativeEventArgs = null;
|
||||||
|
|
||||||
|
this.Control = false;
|
||||||
|
this.Alt = false;
|
||||||
|
this.Shift = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
MouseEventArgs.FromNativeEventArgs = function(e)
|
||||||
|
{
|
||||||
|
var ee = new MouseEventArgs(0);
|
||||||
|
ee.X = e.clientX;
|
||||||
|
ee.Y = e.clientY;
|
||||||
|
|
||||||
|
ee.Control = e.ctrlKey;
|
||||||
|
ee.Alt = e.altKey;
|
||||||
|
ee.Shift = e.shiftKey;
|
||||||
|
|
||||||
|
ee.NativeEventArgs = e;
|
||||||
|
|
||||||
|
if (e.which)
|
||||||
|
{
|
||||||
|
switch (e.which)
|
||||||
|
{
|
||||||
|
case 1:
|
||||||
|
{
|
||||||
|
ee.Button |= MouseButtons.Primary;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2:
|
||||||
|
{
|
||||||
|
ee.Button |= MouseButtons.Tertiary;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 3:
|
||||||
|
{
|
||||||
|
ee.Button |= MouseButtons.Secondary;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (e.button)
|
||||||
|
{
|
||||||
|
if ((e.button & 1) == 1) ee.Button |= MouseButtons.Primary;
|
||||||
|
if ((e.button & 4) == 4) ee.Button |= MouseButtons.Tertiary;
|
||||||
|
if ((e.button & 2) == 2) ee.Button |= MouseButtons.Secondary;
|
||||||
|
}
|
||||||
|
return ee;
|
||||||
|
};
|
||||||
|
function KeyboardKeys()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* The ENTER key.
|
||||||
|
*/
|
||||||
|
KeyboardKeys.Enter = 13;
|
||||||
|
/**
|
||||||
|
* The ESC key.
|
||||||
|
*/
|
||||||
|
KeyboardKeys.Escape = 27;
|
||||||
|
/**
|
||||||
|
* The F1 function key.
|
||||||
|
*/
|
||||||
|
KeyboardKeys.F1 = 112;
|
||||||
|
|
||||||
|
KeyboardKeys.Control = 17;
|
||||||
|
KeyboardKeys.Alt = 18;
|
||||||
|
|
||||||
|
KeyboardKeys.ArrowLeft = 37;
|
||||||
|
KeyboardKeys.ArrowUp = 38;
|
||||||
|
KeyboardKeys.ArrowRight = 39;
|
||||||
|
KeyboardKeys.ArrowDown = 40;
|
||||||
|
|
||||||
|
KeyboardKeys.Meta = 91;
|
||||||
|
KeyboardKeys.ContextMenu = 93;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration for horizontal alignment values
|
||||||
|
*/
|
||||||
|
function HorizontalAlignment(value)
|
||||||
|
{
|
||||||
|
this._value = value;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Specifies that content is aligned to the left.
|
||||||
|
*/
|
||||||
|
HorizontalAlignment.Left = new HorizontalAlignment(0);
|
||||||
|
/**
|
||||||
|
* Specifies that content is aligned in the center of the screen.
|
||||||
|
*/
|
||||||
|
HorizontalAlignment.Center = new HorizontalAlignment(1);
|
||||||
|
/**
|
||||||
|
* Specifies that content is aligned to the right.
|
||||||
|
*/
|
||||||
|
HorizontalAlignment.Right = new HorizontalAlignment(2);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration for vertical alignment values
|
||||||
|
*/
|
||||||
|
function VerticalAlignment(value)
|
||||||
|
{
|
||||||
|
this._value = value;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Specifies that content is aligned to the top.
|
||||||
|
*/
|
||||||
|
VerticalAlignment.Top = new VerticalAlignment(0);
|
||||||
|
/**
|
||||||
|
* Specifies that content is aligned in the middle of the screen.
|
||||||
|
*/
|
||||||
|
VerticalAlignment.Middle = new VerticalAlignment(1);
|
||||||
|
/**
|
||||||
|
* Specifies that content is aligned to the bottom.
|
||||||
|
*/
|
||||||
|
VerticalAlignment.Bottom = new VerticalAlignment(2);
|
||||||
|
|
||||||
|
function Callback(sender)
|
||||||
|
{
|
||||||
|
this._items = [];
|
||||||
|
this._sender = sender;
|
||||||
|
|
||||||
|
this.Add = function(func)
|
||||||
|
{
|
||||||
|
this._items.push(func);
|
||||||
|
};
|
||||||
|
this.Execute = function(e)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < this._items.length; i++)
|
||||||
|
{
|
||||||
|
this._items[i](this._sender, e);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function CallbackArgument()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
CallbackArgument.Empty = new CallbackArgument();
|
||||||
|
|
||||||
|
function Page()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
Page.Cookies = new Object();
|
||||||
|
/**
|
||||||
|
* Gets the cookie with the specified name.
|
||||||
|
*/
|
||||||
|
Page.Cookies.Get = function(name)
|
||||||
|
{
|
||||||
|
var cookie = document.cookie.split(';');
|
||||||
|
for (var i = 0; i < cookie.length; i++)
|
||||||
|
{
|
||||||
|
var cookie1 = cookie[i].split(';', 2);
|
||||||
|
if (cookie1[0] == name) return cookie1[1];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Sets the cookie with the given name to the given value, and optionally sets an expiration date.
|
||||||
|
* @param name string The name of the cookie to set or update.
|
||||||
|
* @param value string The value of the cookie.
|
||||||
|
* @param expires string The date and time at which the cookie should expire.
|
||||||
|
*/
|
||||||
|
Page.Cookies.Set = function(name, value, expires)
|
||||||
|
{
|
||||||
|
var cookie = name + "=" + value;
|
||||||
|
if (expires)
|
||||||
|
{
|
||||||
|
cookie += ";expires=" + expires;
|
||||||
|
}
|
||||||
|
document.cookie = cookie;
|
||||||
|
};
|
||||||
|
|
||||||
|
Page.Path = new Object();
|
||||||
|
Page.Path.GetParts = function()
|
||||||
|
{
|
||||||
|
var p = window.location.href.substring(System.ExpandRelativePath("~/").length + 5);
|
||||||
|
return p.split('/');
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Phast static members
|
||||||
|
*/
|
||||||
|
function System()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Redirects the browser to the given page.
|
||||||
|
*/
|
||||||
|
System.Redirect = function(path)
|
||||||
|
{
|
||||||
|
window.location.href = System.ExpandRelativePath(path);
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Expands the given path using the tilde (~) character and variable replacement.
|
||||||
|
*/
|
||||||
|
System.ExpandRelativePath = function(path)
|
||||||
|
{
|
||||||
|
var replpath = System.BasePath;
|
||||||
|
if (System.IsTenantedHostingEnabled())
|
||||||
|
{
|
||||||
|
replpath = replpath + "/" + System.GetTenantName();
|
||||||
|
}
|
||||||
|
return path.replace(/~\//, replpath + "/");
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Raises a custom DOM event on the given element.
|
||||||
|
* @param element string The element on which to raise the event.
|
||||||
|
* @param eventName string The name of the Event to raise.
|
||||||
|
* @param args any Arguments passed into the event handler.
|
||||||
|
*/
|
||||||
|
System.RaiseEvent = function(element, eventName, args)
|
||||||
|
{
|
||||||
|
var event; // The custom event that will be created
|
||||||
|
if (document.createEvent)
|
||||||
|
{
|
||||||
|
event = document.createEvent("HTMLEvents");
|
||||||
|
event.initEvent(eventName, true, true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
event = document.createEventObject();
|
||||||
|
event.eventType = eventName;
|
||||||
|
}
|
||||||
|
event.eventName = eventName;
|
||||||
|
|
||||||
|
if (document.createEvent)
|
||||||
|
{
|
||||||
|
return element.dispatchEvent(event);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
element.fireEvent("on" + eventName, event);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Provides an event handler for custom-handled events.
|
||||||
|
* @deprecated Use DOM events and System.RaiseEvent() instead.
|
||||||
|
*/
|
||||||
|
System.EventHandler = function()
|
||||||
|
{
|
||||||
|
this._functions = new Array();
|
||||||
|
this.Add = function (func)
|
||||||
|
{
|
||||||
|
this._functions.push(func);
|
||||||
|
};
|
||||||
|
this.Execute = function(sender, e)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < this._functions.length; i++)
|
||||||
|
{
|
||||||
|
var retval = this._functions[i](sender, e);
|
||||||
|
if (!retval) return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
System.Navigation = new Object();
|
||||||
|
/**
|
||||||
|
* Retrieves partial content from a URL and loads it into the specified element's innerHTML property.
|
||||||
|
*
|
||||||
|
* @param url string The URL to fetch.
|
||||||
|
* @param targetFrame string The DOM element in which to load the data.
|
||||||
|
* @param throbber DOMElement The DOM element used as the waiting indicator (optional).
|
||||||
|
* @param throbberClassDefault string The CSS class for the waiting indicator (optional).
|
||||||
|
* @param throbberClassHidden string The CSS class for the hidden waiting indicator (optional).
|
||||||
|
* @param throbberClassVisible string The CSS class for the visible waiting indicator (optional).
|
||||||
|
*/
|
||||||
|
System.Navigation.LoadPartialContent = function(url, targetFrame, async, throbber, throbberClassDefault, throbberClassHidden, throbberClassVisible)
|
||||||
|
{
|
||||||
|
if (typeof(async) === "undefined") async = false;
|
||||||
|
if (!throbberClassDefault) throbberClassDefault = "";
|
||||||
|
if (!throbberClassHidden) throbberClassHidden = "Hidden";
|
||||||
|
if (!throbberClassVisible) throbberClassHidden = "Visible";
|
||||||
|
|
||||||
|
// fetch the data from the URL, should be a same-origin URL
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (this.readyState == 4)
|
||||||
|
{
|
||||||
|
targetFrame.innerHTML = xhr.responseText;
|
||||||
|
if (throbber)
|
||||||
|
{
|
||||||
|
var cssclass = "";
|
||||||
|
if (throbberClassDefault) cssclass += throbberClassDefault + " ";
|
||||||
|
if (throbberClassVisible) cssclass += throbberClassHidden;
|
||||||
|
throbber.className = cssclass;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.open('GET', url, async);
|
||||||
|
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||||
|
xhr.send(null);
|
||||||
|
|
||||||
|
if (throbber)
|
||||||
|
{
|
||||||
|
var cssclass = "";
|
||||||
|
if (throbberClassDefault) cssclass += throbberClassDefault + " ";
|
||||||
|
if (throbberClassVisible) cssclass += throbberClassVisible;
|
||||||
|
throbber.className = cssclass;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
System.TerminateIfSenderIs = function(sender, compareTo)
|
||||||
|
{
|
||||||
|
while (sender != null)
|
||||||
|
{
|
||||||
|
if (sender.classList)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < compareTo.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(sender, compareTo[i]))
|
||||||
|
{
|
||||||
|
// do not close the popup when we click inside itself
|
||||||
|
// e.preventDefault();
|
||||||
|
// e.stopPropagation();
|
||||||
|
// alert(compareTo[i] + " = " + sender.className + " ? true ");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender = sender.parentNode;
|
||||||
|
if (sender == null) break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Enters full screen mode on the specified element. If no element is specified, the entire page becomes full screen.
|
||||||
|
* @param element DOMElement The element with which to fill the screen. If not specified, document.body will be used.
|
||||||
|
*/
|
||||||
|
System.EnterFullScreen = function(element)
|
||||||
|
{
|
||||||
|
if (!element) element = document.body;
|
||||||
|
if (element.requestFullscreen)
|
||||||
|
{
|
||||||
|
// The HTML5 way
|
||||||
|
element.requestFullscreen();
|
||||||
|
}
|
||||||
|
else if (element.webkitRequestFullscreen)
|
||||||
|
{
|
||||||
|
// The WebKit (safari/chrome) way
|
||||||
|
element.webkitRequestFullscreen();
|
||||||
|
}
|
||||||
|
else if (element.mozRequestFullScreen)
|
||||||
|
{
|
||||||
|
// The Firefox way
|
||||||
|
element.mozRequestFullScreen();
|
||||||
|
}
|
||||||
|
else if (element.msRequestFullscreen)
|
||||||
|
{
|
||||||
|
// The Internet Explorer way
|
||||||
|
element.msRequestFullscreen();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Exits full screen mode.
|
||||||
|
*/
|
||||||
|
System.ExitFullScreen = function()
|
||||||
|
{
|
||||||
|
if (document.exitFullscreen)
|
||||||
|
{
|
||||||
|
document.exitFullscreen();
|
||||||
|
}
|
||||||
|
else if (document.webkitExitFullscreen)
|
||||||
|
{
|
||||||
|
document.webkitExitFullscreen();
|
||||||
|
}
|
||||||
|
else if (document.mozCancelFullScreen)
|
||||||
|
{
|
||||||
|
document.mozCancelFullScreen();
|
||||||
|
}
|
||||||
|
else if (document.msExitFullscreen)
|
||||||
|
{
|
||||||
|
document.msExitFullscreen();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the predefined Phast events that are passed into event handlers.
|
||||||
|
*/
|
||||||
|
System.Events = new Object();
|
||||||
|
|
||||||
|
System.Events.MouseClick = new Object();
|
||||||
|
System.Events.MouseClick.Name = "click";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The event that is raised when the mouse wheel is scrolled over an element.
|
||||||
|
*/
|
||||||
|
System.Events.MouseWheel = new Object();
|
||||||
|
//FF doesn't recognize mousewheel as of FF3.x
|
||||||
|
/**
|
||||||
|
* Gets the name of this event.
|
||||||
|
*/
|
||||||
|
System.Events.MouseWheel.Name = ((/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel");
|
||||||
|
/**
|
||||||
|
* Gets the event arguments for this event.
|
||||||
|
*/
|
||||||
|
System.Events.GetEventArgs = function(e)
|
||||||
|
{
|
||||||
|
var delta = e.detail ? e.detail * (-120) : e.wheelDelta;
|
||||||
|
// delta returns +120 when wheel is scrolled up, -120 when scrolled down
|
||||||
|
var evt =
|
||||||
|
{
|
||||||
|
"Cancel": false,
|
||||||
|
"Delta": delta
|
||||||
|
};
|
||||||
|
return evt;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of the ClientProperty with the given propertyName for the control with the given controlName.
|
||||||
|
* @param controlName string The name of the control for which to retrieve a ClientProperty.
|
||||||
|
* @param propertyName string The name of the property to search for.
|
||||||
|
*/
|
||||||
|
System.GetClientProperty = function(controlName, propertyName)
|
||||||
|
{
|
||||||
|
return Page.Cookies.Get(controlName + "__ClientProperty_" + propertyName);
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Sets the value of the ClientProperty with the given propertyName for the control with the given controlName to the given propertyValue.
|
||||||
|
* @param controlName string The name of the control for which to update a ClientProperty.
|
||||||
|
* @param propertyName string The name of the property to search for.
|
||||||
|
* @param propertyValue string The new value of the property.
|
||||||
|
*/
|
||||||
|
System.SetClientProperty = function(controlName, propertyName, propertyValue)
|
||||||
|
{
|
||||||
|
Page.Cookies.Set(controlName + "__ClientProperty_" + propertyName, propertyValue);
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Adds an event listener with the given eventTypeOrName to the parent element.
|
||||||
|
* @param parent DOMElement The element on which to add an event listener.
|
||||||
|
* @param eventTypeOrName string The name of the event for which to add a listener, minus the "on" prefix.
|
||||||
|
* @param callback EventListener The event listener that will be called when this event is raised.
|
||||||
|
*/
|
||||||
|
System.AddEventListener = function(parent, eventTypeOrName, callback)
|
||||||
|
{
|
||||||
|
function CustomCallback(evt)
|
||||||
|
{
|
||||||
|
if (typeof eventTypeOrName.GetEventArgs !== 'undefined')
|
||||||
|
{
|
||||||
|
var eas = eventTypeOrName.GetEventArgs(evt);
|
||||||
|
eas.Cancel = false;
|
||||||
|
callback(eas);
|
||||||
|
if (eas.Cancel)
|
||||||
|
{
|
||||||
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var eas = evt;
|
||||||
|
eas.Cancel = false;
|
||||||
|
callback(eas);
|
||||||
|
if (eas.Cancel)
|
||||||
|
{
|
||||||
|
evt.preventDefault();
|
||||||
|
evt.stopPropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof eventTypeOrName !== "object")
|
||||||
|
{
|
||||||
|
if (parent.attachEvent)
|
||||||
|
{
|
||||||
|
//if IE (and Opera depending on user setting)
|
||||||
|
parent.attachEvent("on" + eventTypeOrName, callback);
|
||||||
|
}
|
||||||
|
else if (parent.addEventListener) //WC3 browsers
|
||||||
|
{
|
||||||
|
parent.addEventListener(eventTypeOrName, callback, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (parent.attachEvent)
|
||||||
|
{
|
||||||
|
//if IE (and Opera depending on user setting)
|
||||||
|
parent.attachEvent("on" + eventTypeOrName.Name, CustomCallback);
|
||||||
|
}
|
||||||
|
else if (parent.addEventListener) //WC3 browsers
|
||||||
|
{
|
||||||
|
parent.addEventListener(eventTypeOrName.Name, CustomCallback, false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
System.ClassList =
|
||||||
|
{
|
||||||
|
"Add": function (object, className)
|
||||||
|
{
|
||||||
|
if (object.classList && object.classList.add)
|
||||||
|
{
|
||||||
|
object.classList.add(className);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var splits = object.className.split(" ");
|
||||||
|
for (var i = 0; i < splits.length; i++)
|
||||||
|
{
|
||||||
|
if (splits[i] == className) return true;
|
||||||
|
}
|
||||||
|
splits.push(className);
|
||||||
|
object.className = splits.join(" ");
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
"Remove": function (object, className)
|
||||||
|
{
|
||||||
|
if (object.classList && object.classList.remove)
|
||||||
|
{
|
||||||
|
object.classList.remove(className);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var splits = object.className.split(" ");
|
||||||
|
var newsplits = new Array();
|
||||||
|
for (var i = 0; i < splits.length; i++)
|
||||||
|
{
|
||||||
|
if (splits[i] == className) continue;
|
||||||
|
newsplits.push(splits[i]);
|
||||||
|
}
|
||||||
|
object.className = newsplits.join(" ");
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
"Contains": function (object, className)
|
||||||
|
{
|
||||||
|
if (object.classList && object.classList.contains)
|
||||||
|
{
|
||||||
|
return object.classList.contains(className);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!object.className) return false;
|
||||||
|
|
||||||
|
var splits = object.className.split(" ");
|
||||||
|
for (var i = 0; i < splits.length; i++)
|
||||||
|
{
|
||||||
|
if (splits[i] == className) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
},
|
||||||
|
"Toggle": function (object, className)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(object, className))
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(object, className);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Add(object, className);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
System.StringMethods =
|
||||||
|
{
|
||||||
|
"Contains": function(string, value)
|
||||||
|
{
|
||||||
|
if (string.includes) return string.includes(value);
|
||||||
|
if (string.contains) return string.contains(value);
|
||||||
|
|
||||||
|
console.error("Neither String.includes nor String.contains were found");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var WebPage =
|
||||||
|
{
|
||||||
|
"Postback": function(url)
|
||||||
|
{
|
||||||
|
var WebPageForm = document.getElementById("WebPageForm");
|
||||||
|
if (url)
|
||||||
|
{
|
||||||
|
// Set the action of the WebPageForm to the specified PostBackURL before submitting
|
||||||
|
WebPageForm.action = url;
|
||||||
|
}
|
||||||
|
if (!WebPageForm)
|
||||||
|
{
|
||||||
|
console.warn("WebPage.Postback: could not find WebPageForm, postbacks are not enabled");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
WebPageForm.submit();
|
||||||
|
},
|
||||||
|
"IsVariableDefined": function(name)
|
||||||
|
{
|
||||||
|
var txtWebPageVariable = document.getElementById("WebPageVariable_" + name + "_Value");
|
||||||
|
if (!txtWebPageVariable) return false;
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
"IsVariableSet": function(name)
|
||||||
|
{
|
||||||
|
var txtWebPageVariable_IsSet = document.getElementById("WebPageVariable_" + name + "_IsSet");
|
||||||
|
if (!txtWebPageVariable_IsSet)
|
||||||
|
{
|
||||||
|
console.warn("WebPage.IsVariableSet: undefined variable '" + name + "'");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
"ClearVariableValue": function(name, value)
|
||||||
|
{
|
||||||
|
var txtWebPageVariable = document.getElementById("WebPageVariable_" + name + "_Value");
|
||||||
|
var txtWebPageVariable_IsSet = document.getElementById("WebPageVariable_" + name + "_IsSet");
|
||||||
|
if (!txtWebPageVariable || !txtWebPageVariable_IsSet)
|
||||||
|
{
|
||||||
|
console.error("WebPage.ClearVariableValue: undefined variable '" + name + "'");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
txtWebPageVariable_IsSet.value = "false";
|
||||||
|
txtWebPageVariable.value = "";
|
||||||
|
|
||||||
|
WebPage.Postback();
|
||||||
|
return true;
|
||||||
|
},
|
||||||
|
"GetVariableValue": function(name)
|
||||||
|
{
|
||||||
|
var txtWebPageVariable = document.getElementById("WebPageVariable_" + name + "_Value");
|
||||||
|
if (!txtWebPageVariable)
|
||||||
|
{
|
||||||
|
console.error("WebPage.GetVariableValue: undefined variable '" + name + "'");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return txtWebPageVariable.value;
|
||||||
|
},
|
||||||
|
"SetVariableValue": function(name, value, autoPostback)
|
||||||
|
{
|
||||||
|
var txtWebPageVariable = document.getElementById("WebPageVariable_" + name + "_Value");
|
||||||
|
var txtWebPageVariable_IsSet = document.getElementById("WebPageVariable_" + name + "_IsSet");
|
||||||
|
if (!txtWebPageVariable || !txtWebPageVariable_IsSet)
|
||||||
|
{
|
||||||
|
console.error("WebPage.GetVariableValue: undefined variable '" + name + "'");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
txtWebPageVariable_IsSet.value = "true";
|
||||||
|
txtWebPageVariable.value = value;
|
||||||
|
|
||||||
|
if (autoPostback !== false)
|
||||||
|
{
|
||||||
|
WebPage.Postback();
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
Provide the XMLHttpRequest constructor for Internet Explorer 5.x-6.x:
|
||||||
|
Other browsers (including Internet Explorer 7.x-9.x) do not redefine
|
||||||
|
XMLHttpRequest if it already exists.
|
||||||
|
|
||||||
|
This example is based on findings at:
|
||||||
|
http://blogs.msdn.com/xmlteam/archive/2006/10/23/using-the-right-version-of-msxml-in-internet-explorer.aspx
|
||||||
|
*/
|
||||||
|
if (typeof XMLHttpRequest === "undefined")
|
||||||
|
{
|
||||||
|
XMLHttpRequest = function ()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new ActiveXObject("Msxml2.XMLHTTP.6.0");
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new ActiveXObject("Msxml2.XMLHTTP.3.0");
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new ActiveXObject("Microsoft.XMLHTTP");
|
||||||
|
}
|
||||||
|
catch (e) {}
|
||||||
|
console.log("This browser does not support XMLHttpRequest.");
|
||||||
|
};
|
||||||
|
}
|
||||||
60
lib/phast/client/scripts/System.js.php
Normal file
60
lib/phast/client/scripts/System.js.php
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
<?php
|
||||||
|
if (file_exists(dirname(__FILE__) . "/JSMin.inc.php"))
|
||||||
|
{
|
||||||
|
include_once(dirname(__FILE__) . "/JSMin.inc.php");
|
||||||
|
}
|
||||||
|
|
||||||
|
$last_modified_time = filemtime(__FILE__);
|
||||||
|
$etag = md5_file(__FILE__);
|
||||||
|
// always send headers
|
||||||
|
header("Last-Modified: ".gmdate("D, d M Y H:i:s", $last_modified_time)." GMT");
|
||||||
|
header("Etag: $etag");
|
||||||
|
|
||||||
|
// exit if not modified
|
||||||
|
if (@strtotime($_SERVER['HTTP_IF_MODIFIED_SINCE']) == $last_modified_time ||
|
||||||
|
@trim($_SERVER['HTTP_IF_NONE_MATCH']) == $etag)
|
||||||
|
{
|
||||||
|
header("HTTP/1.1 304 Not Modified");
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
|
header ("Content-Type: text/javascript");
|
||||||
|
|
||||||
|
$bundles = array();
|
||||||
|
$files = glob("*.js");
|
||||||
|
foreach ($files as $file)
|
||||||
|
{
|
||||||
|
$bundles[] = $file;
|
||||||
|
}
|
||||||
|
$files = glob("controls/*.js");
|
||||||
|
foreach ($files as $file)
|
||||||
|
{
|
||||||
|
$bundles[] = $file;
|
||||||
|
}
|
||||||
|
|
||||||
|
$input = "";
|
||||||
|
foreach ($bundles as $bundle)
|
||||||
|
{
|
||||||
|
$input .= "/* BEGIN '" . $bundle . "' */\r\n";
|
||||||
|
$input .= file_get_contents($bundle) . "\r\n";
|
||||||
|
$input .= "/* END '" . $bundle . "' */\r\n\r\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($_GET["minify"]) && $_GET["minify"] == "false")
|
||||||
|
{
|
||||||
|
echo($input);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (class_exists("\\JSMin\\JSMin"))
|
||||||
|
{
|
||||||
|
$output = \JSMin\JSMin::minify($input);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
$output = "/* could not find class '\\JSMin\\JSMin'; minify is unavailable */\r\n";
|
||||||
|
$output .= $input;
|
||||||
|
}
|
||||||
|
echo($output);
|
||||||
|
}
|
||||||
|
?>
|
||||||
34
lib/phast/client/scripts/WindowDimensions.js
Normal file
34
lib/phast/client/scripts/WindowDimensions.js
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
window.GetWidth = function()
|
||||||
|
{
|
||||||
|
var x = 0;
|
||||||
|
if (self.innerHeight)
|
||||||
|
{
|
||||||
|
x = self.innerWidth;
|
||||||
|
}
|
||||||
|
else if (document.documentElement && document.documentElement.clientHeight)
|
||||||
|
{
|
||||||
|
x = document.documentElement.clientWidth;
|
||||||
|
}
|
||||||
|
else if (document.body)
|
||||||
|
{
|
||||||
|
x = document.body.clientWidth;
|
||||||
|
}
|
||||||
|
return x;
|
||||||
|
};
|
||||||
|
window.GetHeight = function()
|
||||||
|
{
|
||||||
|
var y = 0;
|
||||||
|
if (self.innerHeight)
|
||||||
|
{
|
||||||
|
y = self.innerHeight;
|
||||||
|
}
|
||||||
|
else if (document.documentElement && document.documentElement.clientHeight)
|
||||||
|
{
|
||||||
|
y = document.documentElement.clientHeight;
|
||||||
|
}
|
||||||
|
else if (document.body)
|
||||||
|
{
|
||||||
|
y = document.body.clientHeight;
|
||||||
|
}
|
||||||
|
return y;
|
||||||
|
}
|
||||||
53
lib/phast/client/scripts/controls/AdditionalDetailWidget.js
Normal file
53
lib/phast/client/scripts/controls/AdditionalDetailWidget.js
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
function AdditionalDetailWidget(parent)
|
||||||
|
{
|
||||||
|
this.Parent = parent;
|
||||||
|
this.Show = function ()
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.Parent, "Visible");
|
||||||
|
};
|
||||||
|
this.Hide = function ()
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.Parent, "Visible");
|
||||||
|
};
|
||||||
|
|
||||||
|
this.TextLink = parent.childNodes[0];
|
||||||
|
this.ButtonLink = parent.childNodes[1];
|
||||||
|
|
||||||
|
this.ButtonLink.NativeObject = this;
|
||||||
|
this.ButtonLink.addEventListener("click", function (e)
|
||||||
|
{
|
||||||
|
if (e.which == MouseButtons.Primary)
|
||||||
|
{
|
||||||
|
this.NativeObject.Show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("AdditionalDetailWidget");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new AdditionalDetailWidget(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("mousedown", function (e)
|
||||||
|
{
|
||||||
|
var sender = null;
|
||||||
|
if (!e) e = window.event;
|
||||||
|
if (e.target)
|
||||||
|
{
|
||||||
|
sender = e.target;
|
||||||
|
}
|
||||||
|
else if (e.srcElement)
|
||||||
|
{
|
||||||
|
sender = e.srcElement;
|
||||||
|
}
|
||||||
|
if (!System.TerminateIfSenderIs(sender, ["AdditionalDetailWidget"]))
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("AdditionalDetailWidget");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject.Hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
13
lib/phast/client/scripts/controls/Alert.js
Normal file
13
lib/phast/client/scripts/controls/Alert.js
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
window.addEventListener("load", function()
|
||||||
|
{
|
||||||
|
|
||||||
|
window.setTimeout(function()
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("uwt-alert");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].style.right = "-2000px";
|
||||||
|
}
|
||||||
|
}, 5000);
|
||||||
|
|
||||||
|
});
|
||||||
68
lib/phast/client/scripts/controls/Button.js
Normal file
68
lib/phast/client/scripts/controls/Button.js
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
function Button(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
this.ButtonElement = this.ParentElement.children[0];
|
||||||
|
this.ButtonElement.NativeObject = this;
|
||||||
|
|
||||||
|
this.DropDownButtonElement = this.ParentElement.children[1];
|
||||||
|
this.DropDownButtonElement.NativeObject = this;
|
||||||
|
|
||||||
|
this.DropDownContentElement = this.ParentElement.children[2];
|
||||||
|
|
||||||
|
this.getDropDownOpened = function()
|
||||||
|
{
|
||||||
|
return System.ClassList.Contains(this.DropDownContentElement, "Visible");
|
||||||
|
};
|
||||||
|
this.setDropDownOpened = function(value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.DropDownContentElement, "Visible");
|
||||||
|
if (this.ParentElement.getAttribute("data-pwt-dropdown-direction") == "right")
|
||||||
|
{
|
||||||
|
this.DropDownContentElement.style.left = (this.ParentElement.offsetLeft - this.ParentElement.offsetWidth) + "px";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.DropDownContentElement, "Visible");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.toggleDropDownOpened = function()
|
||||||
|
{
|
||||||
|
this.setDropDownOpened(!this.getDropDownOpened());
|
||||||
|
};
|
||||||
|
|
||||||
|
this.isDropDownRequired = function()
|
||||||
|
{
|
||||||
|
return System.ClassList.Contains(this.ParentElement, "pwt-DropDownRequired");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ButtonElement.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
if (this.NativeObject.isDropDownRequired())
|
||||||
|
{
|
||||||
|
this.NativeObject.setDropDownOpened(true);
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.DropDownButtonElement.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
this.NativeObject.setDropDownOpened(true);
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("pwt-Button");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
if (items[i].tagName.toLowerCase() != "div") continue;
|
||||||
|
items[i].NativeObject = new Button(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
83
lib/phast/client/scripts/controls/CheckBox.js
Normal file
83
lib/phast/client/scripts/controls/CheckBox.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
function CheckBox(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
this.mvarChecked = parentElement.hasAttribute("checked");
|
||||||
|
this.SetChecked = function(value)
|
||||||
|
{
|
||||||
|
var changed = (this.GetChecked() != value);
|
||||||
|
|
||||||
|
this.mvarChecked = value;
|
||||||
|
this.ParentElement.checked = this.mvarChecked;
|
||||||
|
if (this.mvarChecked)
|
||||||
|
{
|
||||||
|
this.NewParentElement.className = "CheckBox Checked";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.NewParentElement.className = "CheckBox";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!changed) return;
|
||||||
|
System.RaiseEvent(this.ParentElement, "change", null);
|
||||||
|
}
|
||||||
|
this.GetChecked = function()
|
||||||
|
{
|
||||||
|
return this.mvarChecked;
|
||||||
|
}
|
||||||
|
this.ToggleChecked = function()
|
||||||
|
{
|
||||||
|
this.SetChecked(!this.GetChecked());
|
||||||
|
}
|
||||||
|
|
||||||
|
var child = document.createElement("div");
|
||||||
|
child.className = "CheckBox";
|
||||||
|
child.NativeObject = this;
|
||||||
|
child.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
child.NativeObject.ToggleChecked();
|
||||||
|
});
|
||||||
|
|
||||||
|
var fa = document.createElement("i");
|
||||||
|
fa.className = "fa fa-check";
|
||||||
|
child.appendChild(fa);
|
||||||
|
|
||||||
|
parentElement.style.display = "none";
|
||||||
|
parentElement.parentNode.insertBefore(child, parentElement);
|
||||||
|
|
||||||
|
this.NewParentElement = child;
|
||||||
|
|
||||||
|
parentElement.addEventListener("change", function(e)
|
||||||
|
{
|
||||||
|
parentElement.NativeObject.SetChecked(parentElement.checked);
|
||||||
|
});
|
||||||
|
this.SetChecked(parentElement.checked);
|
||||||
|
}
|
||||||
|
function RadioButton(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByTagName("input");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
if (items[i].attributes["type"] != null)
|
||||||
|
{
|
||||||
|
switch (items[i].attributes["type"].value)
|
||||||
|
{
|
||||||
|
case "checkbox":
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new CheckBox(items[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "radio":
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new RadioButton(items[i]);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
14
lib/phast/client/scripts/controls/CodeEditor.js
Normal file
14
lib/phast/client/scripts/controls/CodeEditor.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var CodeEditors = document.getElementsByTagName("textarea");
|
||||||
|
for(var i = 0; i < CodeEditors.length; i++)
|
||||||
|
{
|
||||||
|
if (CodeEditors[i].className == "CodeEditor")
|
||||||
|
{
|
||||||
|
CodeEditors[i].NativeEditor = CodeMirror.fromTextArea(CodeEditors[i],
|
||||||
|
{
|
||||||
|
mode: CodeEditors[i].attributes["data-mode"].value
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
82
lib/phast/client/scripts/controls/CommandBar.js
Normal file
82
lib/phast/client/scripts/controls/CommandBar.js
Normal file
@ -0,0 +1,82 @@
|
|||||||
|
function CommandBarItem(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
parentElement.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
parentElement.className = "CommandBarItem Selected";
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
parentElement.addEventListener("mousemove", function(e)
|
||||||
|
{
|
||||||
|
var selected = false;
|
||||||
|
for (var i = 0; i < parentElement.parentNode.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (parentElement.parentNode.childNodes[i].className == "CommandBarItem Selected")
|
||||||
|
{
|
||||||
|
selected = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (selected)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < parentElement.parentNode.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
parentElement.parentNode.childNodes[i].className = "CommandBarItem";
|
||||||
|
}
|
||||||
|
parentElement.className = "CommandBarItem Selected";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function CommandBar(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
var items = parentElement.childNodes;
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new CommandBarItem(items[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
function CommandBarContainer(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
var items = parentElement.childNodes;
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new CommandBar(items[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
parentElement.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("CommandBarContainer");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new CommandBarContainer(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("CommandBarContainer");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
var items1 = items[i].childNodes;
|
||||||
|
for (var j = 0; j < items1.length; j++)
|
||||||
|
{
|
||||||
|
var items2 = items1[j].childNodes;
|
||||||
|
for (var k = 0; k < items2.length; k++)
|
||||||
|
{
|
||||||
|
items2[k].className = "CommandBarItem";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
171
lib/phast/client/scripts/controls/Countdown.js
Normal file
171
lib/phast/client/scripts/controls/Countdown.js
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
function Countdown(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.ParentElement.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.mvarTargetYear = parentElement.getAttribute("data-target-year");
|
||||||
|
this.get_TargetYear = function() { return this.mvarTargetYear; };
|
||||||
|
this.set_TargetYear = function(value) { this.mvarTargetYear = value; };
|
||||||
|
|
||||||
|
this.mvarTargetMonth = parentElement.getAttribute("data-target-month");
|
||||||
|
this.get_TargetMonth = function() { return this.mvarTargetMonth; };
|
||||||
|
this.set_TargetMonth = function(value) { this.mvarTargetMonth = value; };
|
||||||
|
|
||||||
|
this.mvarTargetDay = parentElement.getAttribute("data-target-day");
|
||||||
|
this.get_TargetDay = function() { return this.mvarTargetDay; };
|
||||||
|
this.set_TargetDay = function(value) { this.mvarTargetDay = value; };
|
||||||
|
|
||||||
|
this.mvarTargetHour = parentElement.getAttribute("data-target-hour");
|
||||||
|
this.get_TargetHour = function() { return this.mvarTargetHour; };
|
||||||
|
this.set_TargetHour = function(value) { this.mvarTargetHour = value; };
|
||||||
|
|
||||||
|
this.mvarTargetMinute = parentElement.getAttribute("data-target-minute");
|
||||||
|
this.get_TargetMinute = function() { return this.mvarTargetMinute; };
|
||||||
|
this.set_TargetMinute = function(value) { this.mvarTargetMinute = value; };
|
||||||
|
|
||||||
|
this.mvarTargetSecond = parentElement.getAttribute("data-target-second");
|
||||||
|
this.get_TargetSecond = function() { return this.mvarTargetSecond; };
|
||||||
|
this.set_TargetSecond = function(value) { this.mvarTargetSecond = value; };
|
||||||
|
|
||||||
|
this.get_Year = function()
|
||||||
|
{
|
||||||
|
return parseInt(this.ParentElement.children[0].children[0].innerHTML);
|
||||||
|
};
|
||||||
|
this.set_Year = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.children[0].children[0].innerHTML = value.toString();
|
||||||
|
};
|
||||||
|
this.get_Month = function()
|
||||||
|
{
|
||||||
|
return parseInt(this.ParentElement.children[1].children[0].innerHTML);
|
||||||
|
};
|
||||||
|
this.set_Month = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.children[1].children[0].innerHTML = value.toString();
|
||||||
|
};
|
||||||
|
this.get_Day = function()
|
||||||
|
{
|
||||||
|
return parseInt(this.ParentElement.children[2].children[0].innerHTML);
|
||||||
|
};
|
||||||
|
this.set_Day = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.children[2].children[0].innerHTML = value.toString();
|
||||||
|
};
|
||||||
|
this.get_Hour = function()
|
||||||
|
{
|
||||||
|
return parseInt(this.ParentElement.children[3].children[0].innerHTML);
|
||||||
|
};
|
||||||
|
this.set_Hour = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.children[3].children[0].innerHTML = value.toString();
|
||||||
|
};
|
||||||
|
this.get_Minute = function()
|
||||||
|
{
|
||||||
|
return parseInt(this.ParentElement.children[4].children[0].innerHTML);
|
||||||
|
};
|
||||||
|
this.set_Minute = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.children[4].children[0].innerHTML = value.toString();
|
||||||
|
};
|
||||||
|
this.get_Second = function()
|
||||||
|
{
|
||||||
|
return parseInt(this.ParentElement.children[5].children[0].innerHTML);
|
||||||
|
};
|
||||||
|
this.set_Second = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.children[5].children[0].innerHTML = value.toString();
|
||||||
|
};
|
||||||
|
|
||||||
|
var thiss = this;
|
||||||
|
this._timer = null;
|
||||||
|
this._timer_Tick = function()
|
||||||
|
{
|
||||||
|
if (thiss.get_Second() == 0)
|
||||||
|
{
|
||||||
|
if (thiss.get_Minute() == 0)
|
||||||
|
{
|
||||||
|
if (thiss.get_Hour() == 0)
|
||||||
|
{
|
||||||
|
if (thiss.get_Day() == 0)
|
||||||
|
{
|
||||||
|
if (thiss.get_Month() == 0)
|
||||||
|
{
|
||||||
|
if (thiss.get_Year() == 0)
|
||||||
|
{
|
||||||
|
// everything is 0 so we can stop
|
||||||
|
thiss.Stop();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thiss.set_Year(thiss.get_Year() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thiss.set_Month(thiss.get_Month() - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: figure out how many days are left for this month... probably using target date
|
||||||
|
thiss.set_Day(31);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thiss.set_Day(thiss.get_Day() - 1);
|
||||||
|
}
|
||||||
|
thiss.set_Hour(23);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thiss.set_Hour(thiss.get_Hour() - 1);
|
||||||
|
}
|
||||||
|
thiss.set_Minute(59);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thiss.set_Minute(thiss.get_Minute() - 1);
|
||||||
|
}
|
||||||
|
thiss.set_Second(59);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
thiss.set_Second(thiss.get_Second() - 1);
|
||||||
|
}
|
||||||
|
thiss._timer = window.setTimeout(thiss._timer_Tick, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Stop = function()
|
||||||
|
{
|
||||||
|
if (this._timer == null) return;
|
||||||
|
window.clearTimeout(this._timer);
|
||||||
|
};
|
||||||
|
this.Start = function()
|
||||||
|
{
|
||||||
|
this._timer = window.setTimeout(this._timer_Tick, 1000);
|
||||||
|
};
|
||||||
|
|
||||||
|
var date = new Date();
|
||||||
|
var targetDate = new Date(this.get_TargetYear(), this.get_TargetMonth(), this.get_TargetDay(), this.get_TargetHour(), this.get_TargetMinute(), this.get_TargetSecond());
|
||||||
|
|
||||||
|
this.set_Year(targetDate.getFullYear() - date.getFullYear());
|
||||||
|
this.set_Month((targetDate.getMonth() - date.getMonth()) + 1);
|
||||||
|
this.set_Day(targetDate.getDate() - date.getDate());
|
||||||
|
this.set_Hour(date.getHours() - targetDate.getHours());
|
||||||
|
this.set_Minute(date.getMinutes() - targetDate.getMinutes());
|
||||||
|
this.set_Second(date.getSeconds() - targetDate.getSeconds());
|
||||||
|
|
||||||
|
this.Start();
|
||||||
|
}
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("Countdown");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new Countdown(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
50
lib/phast/client/scripts/controls/Disclosure.js
Normal file
50
lib/phast/client/scripts/controls/Disclosure.js
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
function Disclosure(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
parentElement.childNodes[0].childNodes[0].addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
parentElement.NativeObject.ToggleExpanded();
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.mvarExpanded = (parentElement.attributes["data-expanded"] != null ? parentElement.attributes["data-expanded"].value == "true" : false);
|
||||||
|
this.GetExpanded = function()
|
||||||
|
{
|
||||||
|
return this.mvarExpanded;
|
||||||
|
};
|
||||||
|
this.SetExpanded = function(value)
|
||||||
|
{
|
||||||
|
this.mvarExpanded = value;
|
||||||
|
this.Refresh();
|
||||||
|
};
|
||||||
|
this.ToggleExpanded = function()
|
||||||
|
{
|
||||||
|
this.SetExpanded(!this.GetExpanded());
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Refresh = function()
|
||||||
|
{
|
||||||
|
var disclosure = this.ParentElement;
|
||||||
|
if (this.GetExpanded())
|
||||||
|
{
|
||||||
|
disclosure.className = "Disclosure Expanded";
|
||||||
|
disclosure.attributes["data-expanded"].value = "true";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
disclosure.className = "Disclosure";
|
||||||
|
disclosure.attributes["data-expanded"].value = "false";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("Disclosure");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new Disclosure(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
286
lib/phast/client/scripts/controls/DropDown.js
Normal file
286
lib/phast/client/scripts/controls/DropDown.js
Normal file
@ -0,0 +1,286 @@
|
|||||||
|
function DropDownWrapper(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
function DropDown(id)
|
||||||
|
{
|
||||||
|
this.ID = id;
|
||||||
|
this.IsOpen = false;
|
||||||
|
|
||||||
|
var Container = document.getElementById("DropDown_" + id);
|
||||||
|
Container.Parent = this;
|
||||||
|
if (Container.className == "DropDown SelectionRequired")
|
||||||
|
{
|
||||||
|
Container.onmousedown = function(e)
|
||||||
|
{
|
||||||
|
if (e.button == 0)
|
||||||
|
{
|
||||||
|
// open the dropdown
|
||||||
|
if (this.Parent.IsOpen)
|
||||||
|
{
|
||||||
|
this.Parent.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Parent.Open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
};
|
||||||
|
Container.onmouseup = function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
Container.oncontextmenu = function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var Button = document.getElementById("DropDown_" + id + "_Button");
|
||||||
|
Button.Parent = this;
|
||||||
|
Button.onmousedown = function(e)
|
||||||
|
{
|
||||||
|
if (e.button == 0)
|
||||||
|
{
|
||||||
|
// open the dropdown
|
||||||
|
if (this.Parent.IsOpen)
|
||||||
|
{
|
||||||
|
this.Parent.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Parent.Open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
};
|
||||||
|
Button.onmouseup = function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
var ItemList_Items = document.getElementById("DropDown_" + id + "_ItemList_Items");
|
||||||
|
ItemList_Items.Parent = this;
|
||||||
|
ItemList_Items.onmousedown = function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
};
|
||||||
|
ItemList_Items.oncontextmenu = function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
var Search = document.getElementById("DropDown_" + id + "_ItemList_Search");
|
||||||
|
Search.onmousedown = function(e)
|
||||||
|
{
|
||||||
|
// e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Select = function(index)
|
||||||
|
{
|
||||||
|
// Selects the item with the specified index.
|
||||||
|
var dd_Text = document.getElementById("DropDown_" + this.ID + "_Text");
|
||||||
|
var dd_Input = document.getElementById("DropDown_" + this.ID + "_Input");
|
||||||
|
|
||||||
|
var menuItemsContainer = document.getElementById("DropDown_" + this.ID + "_ItemList_Items");
|
||||||
|
var menuItems = menuItemsContainer.getElementsByTagName("A");
|
||||||
|
var menuItem = menuItems[index];
|
||||||
|
|
||||||
|
if (dd_Text)
|
||||||
|
{
|
||||||
|
dd_Text.innerHTML = menuItem.innerHTML;
|
||||||
|
}
|
||||||
|
else if (dd_Input)
|
||||||
|
{
|
||||||
|
dd_Input.value = menuItem.innerHTML;
|
||||||
|
dd_Input.focus();
|
||||||
|
dd_Input.select();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.Open = function()
|
||||||
|
{
|
||||||
|
DropDown.CloseAll();
|
||||||
|
|
||||||
|
var dd = document.getElementById("DropDown_" + this.ID);
|
||||||
|
var dd_Button = document.getElementById("DropDown_" + this.ID + "_Button");
|
||||||
|
var dd_DropDown = document.getElementById("DropDown_" + this.ID + "_ItemList");
|
||||||
|
var dd_ItemList_Search = document.getElementById("DropDown_" + this.ID + "_ItemList_Search");
|
||||||
|
var dd_Text = document.getElementById("DropDown_" + this.ID + "_Text");
|
||||||
|
var dd_Input = document.getElementById("DropDown_" + this.ID + "_Input");
|
||||||
|
|
||||||
|
if (dd.className == "DropDown SelectionRequired")
|
||||||
|
{
|
||||||
|
dd.className = "DropDown SelectionRequired Opened";
|
||||||
|
}
|
||||||
|
else if (dd.className == "DropDown")
|
||||||
|
{
|
||||||
|
dd.className = "DropDown Opened";
|
||||||
|
}
|
||||||
|
|
||||||
|
dd_DropDown.style.width = dd.offsetWidth + "px";
|
||||||
|
|
||||||
|
dd_Button.className = "Button Pressed";
|
||||||
|
|
||||||
|
dd_ItemList_Search.focus();
|
||||||
|
dd_ItemList_Search.value = "";
|
||||||
|
this.UpdateFilter();
|
||||||
|
|
||||||
|
dd_DropDown.style.display = "block";
|
||||||
|
|
||||||
|
this.IsOpen = true;
|
||||||
|
|
||||||
|
if (dd_Input) dd_Input.select();
|
||||||
|
/*
|
||||||
|
if (dd_Input)
|
||||||
|
{
|
||||||
|
dd_ItemList_Search.value = dd_Input.value;
|
||||||
|
}
|
||||||
|
else if (dd_Text)
|
||||||
|
{
|
||||||
|
dd_ItemList_Search.value = dd_Text.innerHTML;
|
||||||
|
}
|
||||||
|
dd_ItemList_Search.select();
|
||||||
|
*/
|
||||||
|
};
|
||||||
|
this.Close = function()
|
||||||
|
{
|
||||||
|
var dd = document.getElementById("DropDown_" + this.ID);
|
||||||
|
var dd_Button = document.getElementById("DropDown_" + this.ID + "_Button");
|
||||||
|
var dd_DropDown = document.getElementById("DropDown_" + this.ID + "_ItemList");
|
||||||
|
|
||||||
|
if (dd.className == "DropDown SelectionRequired Opened")
|
||||||
|
{
|
||||||
|
dd.className = "DropDown SelectionRequired";
|
||||||
|
}
|
||||||
|
else if (dd.className == "DropDown Opened")
|
||||||
|
{
|
||||||
|
dd.className = "DropDown";
|
||||||
|
}
|
||||||
|
|
||||||
|
dd_DropDown.style.width = dd.offsetWidth;
|
||||||
|
|
||||||
|
dd_Button.className = "Button";
|
||||||
|
|
||||||
|
dd_DropDown.style.display = "none";
|
||||||
|
|
||||||
|
this.IsOpen = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
// go through and initialize all of the links in the menu items, for menu items that are already created
|
||||||
|
var menuItemsContainer = document.getElementById("DropDown_" + this.ID + "_ItemList_Items");
|
||||||
|
var menuItems = menuItemsContainer.getElementsByTagName("A");
|
||||||
|
for (var i = 0; i < menuItems.length; i++)
|
||||||
|
{
|
||||||
|
menuItems[i].Index = i;
|
||||||
|
menuItems[i].Parent = this;
|
||||||
|
menuItems[i].onmousedown = function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
menuItems[i].onmouseup = function(e)
|
||||||
|
{
|
||||||
|
if (e.button == 0)
|
||||||
|
{
|
||||||
|
this.Parent.Select(this.Index);
|
||||||
|
this.Parent.Close();
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
menuItems[i].oncontextmenu = function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
this.UpdateFilter = function()
|
||||||
|
{
|
||||||
|
var dd_Search = document.getElementById("DropDown_" + this.ID + "_ItemList_Search");
|
||||||
|
// filter the text in the text box
|
||||||
|
var menuItemsContainer = document.getElementById("DropDown_" + this.ID + "_ItemList_Items");
|
||||||
|
var menuItems = menuItemsContainer.getElementsByTagName("A");
|
||||||
|
for (var i = 0; i < menuItems.length; i++)
|
||||||
|
{
|
||||||
|
if (dd_Search.value == "" || menuItems[i].innerHTML.toLowerCase().indexOf(dd_Search.value.toLowerCase()) != -1)
|
||||||
|
{
|
||||||
|
menuItems[i].style.display = "block";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
menuItems[i].style.display = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// set up the search text box
|
||||||
|
var dd_Search = document.getElementById("DropDown_" + this.ID + "_ItemList_Search");
|
||||||
|
dd_Search.Parent = this;
|
||||||
|
dd_Search.onkeyup = function()
|
||||||
|
{
|
||||||
|
this.Parent.UpdateFilter();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
DropDown.CloseAll = function()
|
||||||
|
{
|
||||||
|
var dropdowns = document.getElementsByClassName("DropDown");
|
||||||
|
for (var i = 0; i < dropdowns.length; i++)
|
||||||
|
{
|
||||||
|
dropdowns[i].Parent.Close();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// add a global hook to close all the dropdown lists when the mouse button is pressed
|
||||||
|
document.addEventListener("mousedown", function(e)
|
||||||
|
{
|
||||||
|
DropDown.CloseAll();
|
||||||
|
});
|
||||||
|
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
// find DropDownButtons to trigger
|
||||||
|
var dropdowns = document.getElementsByClassName("DropDownButton");
|
||||||
|
for (var i = 0; i < dropdowns.length; i++)
|
||||||
|
{
|
||||||
|
(function(index)
|
||||||
|
{
|
||||||
|
dropdowns[index].addEventListener("mousedown", function(ee)
|
||||||
|
{
|
||||||
|
if (dropdowns[index].className == "DropDownButton")
|
||||||
|
{
|
||||||
|
dropdowns[index].className = "DropDownButton Opened";
|
||||||
|
}
|
||||||
|
else if (dropdowns[index].className == "DropDownButton Opened")
|
||||||
|
{
|
||||||
|
dropdowns[index].className = "DropDownButton";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
// retrofit SELECT elements
|
||||||
|
var selects = document.getElementsByTagName("SELECT");
|
||||||
|
for (var i = 0; i < selects.length; i++)
|
||||||
|
{
|
||||||
|
selects[i].NativeObject = new DropDownWrapper(selects[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
54
lib/phast/client/scripts/controls/FlyoutTabContainer.js
Normal file
54
lib/phast/client/scripts/controls/FlyoutTabContainer.js
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
function FlyoutTabContainer(id)
|
||||||
|
{
|
||||||
|
this.ID = id;
|
||||||
|
this.ToggleItem = function(itemID)
|
||||||
|
{
|
||||||
|
var tab = document.getElementById("FlyoutTabContainer_" + this.ID + "_" + itemID + "_Tab");
|
||||||
|
var content = document.getElementById("FlyoutTabContainer_" + this.ID + "_" + itemID + "_Content");
|
||||||
|
|
||||||
|
if (tab == null)
|
||||||
|
{
|
||||||
|
console.log("FlyoutTabContainer: nonexistent tab '" + itemID + "' on container '" + this.ID + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (content == null)
|
||||||
|
{
|
||||||
|
console.log("FlyoutTabContainer: nonexistent content '" + itemID + "' on container '" + this.ID + "'");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var parent = tab.parentNode;
|
||||||
|
if (tab.className == "FlyoutTab Active")
|
||||||
|
{
|
||||||
|
tab.className = "FlyoutTab";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var i = 0; i < parent.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (parent.childNodes[i].className == "FlyoutTab Active" && parent.childNodes[i] != tab);
|
||||||
|
{
|
||||||
|
parent.childNodes[i].className = "FlyoutTab";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
tab.className = "FlyoutTab Active";
|
||||||
|
}
|
||||||
|
|
||||||
|
parent = content.parentNode;
|
||||||
|
if (content.className == "FlyoutTabContent Active")
|
||||||
|
{
|
||||||
|
content.className = "FlyoutTabContent";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (var i = 0; i < parent.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (parent.childNodes[i].className == "FlyoutTabContent Active" && parent.childNodes[i] != content);
|
||||||
|
{
|
||||||
|
parent.childNodes[i].className = "FlyoutTabContent";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
content.className = "FlyoutTabContent Active";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
5
lib/phast/client/scripts/controls/LinkButton.js
Normal file
5
lib/phast/client/scripts/controls/LinkButton.js
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
function LinkButton(id)
|
||||||
|
{
|
||||||
|
this.ID = id;
|
||||||
|
this.PopupMenu = new Popup(id + "_menu");
|
||||||
|
}
|
||||||
546
lib/phast/client/scripts/controls/ListView.js
Normal file
546
lib/phast/client/scripts/controls/ListView.js
Normal file
@ -0,0 +1,546 @@
|
|||||||
|
var ListViewMode =
|
||||||
|
{
|
||||||
|
"Detail": 1,
|
||||||
|
"Tile": 2
|
||||||
|
};
|
||||||
|
function ListViewItemActivationMode(value)
|
||||||
|
{
|
||||||
|
this._value = value;
|
||||||
|
}
|
||||||
|
ListViewItemActivationMode.SingleClick = new ListViewItemActivationMode(1);
|
||||||
|
ListViewItemActivationMode.DoubleClick = new ListViewItemActivationMode(2);
|
||||||
|
|
||||||
|
function ListViewColumnResizer(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
for (var i = 0; i < this.ParentElement.parentNode.children.length; i++)
|
||||||
|
{
|
||||||
|
if (this.ParentElement.parentNode.children[i] == this.ParentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement.parentNode.children[i].index = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ParentElement.addEventListener("mousedown", function(e)
|
||||||
|
{
|
||||||
|
ListViewColumnResizer._moving = true;
|
||||||
|
this._prevX = e.clientX;
|
||||||
|
this._prevWidth = this.parentNode.children[this.index - 1].clientWidth;
|
||||||
|
ListViewColumnResizer._current = this;
|
||||||
|
|
||||||
|
// document.body.style.cursor = "ew-resize";
|
||||||
|
e.preventDefault();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
ListViewColumnResizer._moving = false;
|
||||||
|
ListViewColumnResizer._current = null;
|
||||||
|
|
||||||
|
window.addEventListener("mousemove", function(e)
|
||||||
|
{
|
||||||
|
if (ListViewColumnResizer._moving)
|
||||||
|
{
|
||||||
|
var lvcr = ListViewColumnResizer._current;
|
||||||
|
var w = lvcr._prevWidth + (e.clientX - lvcr._prevX);
|
||||||
|
lvcr.parentNode.children[lvcr.index - 1].style.width = w.toString() + "px";
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("mouseup", function(e)
|
||||||
|
{
|
||||||
|
ListViewColumnResizer._moving = false;
|
||||||
|
});
|
||||||
|
|
||||||
|
function ListViewItemColumn(parentItem)
|
||||||
|
{
|
||||||
|
this.mvarParentItem = parentItem;
|
||||||
|
this.get_ParentItem = function()
|
||||||
|
{
|
||||||
|
return this.mvarParentItem;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get_Value = function()
|
||||||
|
{
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function ListViewItem(parentListView, index)
|
||||||
|
{
|
||||||
|
this.mvarParentListView = parentListView;
|
||||||
|
this.get_ParentListView = function()
|
||||||
|
{
|
||||||
|
return this.mvarParentListView;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.mvarIndex = index;
|
||||||
|
this.get_Index = function()
|
||||||
|
{
|
||||||
|
return this.mvarIndex;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get_ParentElement = function()
|
||||||
|
{
|
||||||
|
return this.get_ParentListView().ItemsElement.children[this.get_Index()];
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get_Value = function()
|
||||||
|
{
|
||||||
|
return this.get_ParentElement().getAttribute("data-value");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function ListViewColumn()
|
||||||
|
{
|
||||||
|
this.Title = null;
|
||||||
|
this.ItemTemplate = null;
|
||||||
|
}
|
||||||
|
function ListView(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.ColumnHeaderElement = this.ParentElement.children[0];
|
||||||
|
//this.EmptyMessageElement = this.ParentElement.children[1];
|
||||||
|
this.ItemsElement = this.ParentElement.children[1];
|
||||||
|
|
||||||
|
this.AddRemoveColumnHeaderElement = this.ColumnHeaderElement.children[0];
|
||||||
|
this.AddRemoveColumnHeaderAddColumnButton = this.AddRemoveColumnHeaderElement.children[0];
|
||||||
|
|
||||||
|
this.AddRemoveColumnHeaderAddColumnButton.NativeObject = this;
|
||||||
|
this.AddRemoveColumnHeaderAddColumnButton.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
this.NativeObject.InsertRowAfter(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Inserts a row after the row at the specified index.
|
||||||
|
*/
|
||||||
|
this.InsertRowAfter = function(index)
|
||||||
|
{
|
||||||
|
var rw = document.createElement("div");
|
||||||
|
rw.className = "ListViewItem";
|
||||||
|
|
||||||
|
var col = document.createElement("div");
|
||||||
|
col.className = "ListViewItemColumn AddRemoveRowItemColumn";
|
||||||
|
|
||||||
|
var aAdd = document.createElement("a");
|
||||||
|
aAdd.className = "Add";
|
||||||
|
col.appendChild(aAdd);
|
||||||
|
|
||||||
|
var aRemove = document.createElement("a");
|
||||||
|
aRemove.className = "Remove";
|
||||||
|
col.appendChild(aRemove);
|
||||||
|
|
||||||
|
rw.appendChild(col);
|
||||||
|
|
||||||
|
for (var i = 0; i < this.Columns.Count(); i++)
|
||||||
|
{
|
||||||
|
var column = this.Columns.GetByIndex(i);
|
||||||
|
var col = document.createElement("div");
|
||||||
|
col.className = "ListViewItemColumn";
|
||||||
|
|
||||||
|
col.innerHTML = column.ItemTemplate;
|
||||||
|
|
||||||
|
if (col.children.length > 0)
|
||||||
|
{
|
||||||
|
col.children[0].id = "ListView_" + this.ParentElement.id + "_Rows_" + this.ItemsElement.children.length + "_Columns_" + column.ID + "_Value";
|
||||||
|
}
|
||||||
|
|
||||||
|
rw.appendChild(col);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((index + 1) > this.ItemsElement.children.length)
|
||||||
|
{
|
||||||
|
this.ItemsElement.appendChild(rw);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.ItemsElement.insertBefore(rw, this.ItemsElement.children[index + 1]);
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Refresh = function()
|
||||||
|
{
|
||||||
|
if (this.Rows.Count() > 0)
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.ParentElement, "Empty");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.ParentElement, "Empty");
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < this.ColumnHeaderElement.children.length; i++)
|
||||||
|
{
|
||||||
|
if (this.ColumnHeaderElement.children[i].className == "ColumnResizer")
|
||||||
|
{
|
||||||
|
this.ColumnHeaderElement.children[i].NativeObject = new ListViewColumnResizer(this.ColumnHeaderElement.children[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < this.ItemsElement.children.length; i++)
|
||||||
|
{
|
||||||
|
var row = this.ItemsElement.children[i];
|
||||||
|
|
||||||
|
row.m_Index = i;
|
||||||
|
|
||||||
|
var AddRemoveRowItemColumnElement = row.children[0];
|
||||||
|
var AddRowButton = AddRemoveRowItemColumnElement.children[0];
|
||||||
|
if (AddRowButton)
|
||||||
|
{
|
||||||
|
AddRowButton.m_Index = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
var RemoveRowButton = AddRemoveRowItemColumnElement.children[1];
|
||||||
|
if (RemoveRowButton)
|
||||||
|
{
|
||||||
|
RemoveRowButton.m_Index = i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// if it has already been processed, skip it
|
||||||
|
if (row.NativeObject) continue;
|
||||||
|
|
||||||
|
row.NativeObject = this;
|
||||||
|
|
||||||
|
if (AddRowButton)
|
||||||
|
{
|
||||||
|
AddRowButton.NativeObject = this;
|
||||||
|
AddRowButton.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
this.NativeObject.InsertRowAfter(this.m_Index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (RemoveRowButton)
|
||||||
|
{
|
||||||
|
RemoveRowButton.NativeObject = this;
|
||||||
|
RemoveRowButton.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
this.NativeObject.Rows.RemoveAt(this.m_Index);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
row.addEventListener("mousedown", function(e)
|
||||||
|
{
|
||||||
|
if (e.ctrlKey && System.ClassList.Contains(this.NativeObject.ParentElement, "MultiSelect"))
|
||||||
|
{
|
||||||
|
this.NativeObject.SelectedRows.Toggle(this.m_Index);
|
||||||
|
}
|
||||||
|
else if (e.shiftKey && System.ClassList.Contains(this.NativeObject.ParentElement, "MultiSelect"))
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!(this.NativeObject.SelectedRows.Count() == 1 && this.NativeObject.SelectedRows.ContainsIndex(this.m_Index)))
|
||||||
|
{
|
||||||
|
this.NativeObject.SelectedRows.Clear();
|
||||||
|
this.NativeObject.SelectedRows.Add(this.m_Index);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// WARNING: this messes with input elements and other controls - don't uncomment unless you KNOW WHAT YOU'RE DOING
|
||||||
|
// e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
row.addEventListener("dblclick", function(e)
|
||||||
|
{
|
||||||
|
if (this.NativeObject.get_ItemActivationMode() == ListViewItemActivationMode.DoubleClick)
|
||||||
|
{
|
||||||
|
this.NativeObject.EventHandlers.ItemActivated.Execute();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
row.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
this.NativeObject.SelectedRows.Clear();
|
||||||
|
this.NativeObject.SelectedRows.Add(this.m_Index);
|
||||||
|
// e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.mvarItemActivationMode = ListViewItemActivationMode.DoubleClick;
|
||||||
|
this.get_ItemActivationMode = function()
|
||||||
|
{
|
||||||
|
return this.mvarItemActivationMode;
|
||||||
|
};
|
||||||
|
this.set_ItemActivationMode = function(value)
|
||||||
|
{
|
||||||
|
this.mvarItemActivationMode = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.ParentElement.hasAttribute("data-item-activation-mode"))
|
||||||
|
{
|
||||||
|
switch (this.ParentElement.getAttribute("data-item-activation-mode").toLowerCase())
|
||||||
|
{
|
||||||
|
case "singleclick":
|
||||||
|
{
|
||||||
|
this.set_ItemActivationMode(ListViewItemActivationMode.SingleClick);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "doubleclick":
|
||||||
|
{
|
||||||
|
this.set_ItemActivationMode(ListViewItemActivationMode.DoubleClick);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.EventHandlers =
|
||||||
|
{
|
||||||
|
"ItemActivated": new System.EventHandler(),
|
||||||
|
"SelectionChanging": new System.EventHandler(),
|
||||||
|
"SelectionChanged": new System.EventHandler()
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Columns =
|
||||||
|
{
|
||||||
|
"NativeObject": null,
|
||||||
|
|
||||||
|
// # of predefined columns; e.g. add/remove column, row ordering column, etc.
|
||||||
|
"_predefinedColumnsCount": 1,
|
||||||
|
|
||||||
|
"Count": function()
|
||||||
|
{
|
||||||
|
return this.NativeObject.ColumnHeaderElement.children.length - this._predefinedColumnsCount;
|
||||||
|
},
|
||||||
|
"GetByIndex": function(index)
|
||||||
|
{
|
||||||
|
var col = this.NativeObject.ColumnHeaderElement.children[index + this._predefinedColumnsCount];
|
||||||
|
var column = new ListViewColumn();
|
||||||
|
column.ID = col.getAttribute("data-id");
|
||||||
|
column.Title = col.children[0].innerHTML;
|
||||||
|
column.ItemTemplate = col.children[1].innerHTML;
|
||||||
|
return column;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.Columns.NativeObject = this;
|
||||||
|
|
||||||
|
this.Rows =
|
||||||
|
{
|
||||||
|
"NativeObject": null,
|
||||||
|
"Count": function()
|
||||||
|
{
|
||||||
|
return this.NativeObject.ItemsElement.children.length;
|
||||||
|
},
|
||||||
|
"Remove": function(row)
|
||||||
|
{
|
||||||
|
this.NativeObject.ItemsElement.removeChild(row.ParentElement);
|
||||||
|
},
|
||||||
|
"RemoveAt": function(index)
|
||||||
|
{
|
||||||
|
this.NativeObject.ItemsElement.removeChild(this.NativeObject.ItemsElement.children[index]);
|
||||||
|
this.NativeObject.Refresh();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.Rows.NativeObject = this;
|
||||||
|
|
||||||
|
this.SelectedRows =
|
||||||
|
{
|
||||||
|
"NativeObject": null,
|
||||||
|
"Clear": function()
|
||||||
|
{
|
||||||
|
var changed = false;
|
||||||
|
for (var i = 0; i < this.NativeObject.ItemsElement.children.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(this.NativeObject.ItemsElement.children[i], "Selected"))
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!changed) return;
|
||||||
|
|
||||||
|
this.NativeObject.EventHandlers.SelectionChanging.Execute();
|
||||||
|
for (var i = 0; i < this.NativeObject.ItemsElement.children.length; i++)
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.NativeObject.ItemsElement.children[i], "Selected");
|
||||||
|
}
|
||||||
|
this.NativeObject.EventHandlers.SelectionChanged.Execute();
|
||||||
|
},
|
||||||
|
"AddRange": function(indices)
|
||||||
|
{
|
||||||
|
var changed = false;
|
||||||
|
for (var i = 0; i < indices.length; i++)
|
||||||
|
{
|
||||||
|
if (!System.ClassList.Contains(this.NativeObject.ItemsElement.children[indices[i]], "Selected"))
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!changed) return;
|
||||||
|
|
||||||
|
this.NativeObject.EventHandlers.SelectionChanging.Execute();
|
||||||
|
for (var i = 0; i < indices.length; i++)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.NativeObject.ItemsElement.children[indices[i]], "Selected");
|
||||||
|
}
|
||||||
|
this.NativeObject.EventHandlers.SelectionChanged.Execute();
|
||||||
|
},
|
||||||
|
"RemoveRange": function(indices)
|
||||||
|
{
|
||||||
|
var changed = false;
|
||||||
|
for (var i = 0; i < indices.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(this.NativeObject.ItemsElement.children[indices[i]], "Selected"))
|
||||||
|
{
|
||||||
|
changed = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!changed) return;
|
||||||
|
|
||||||
|
this.NativeObject.EventHandlers.SelectionChanging.Execute();
|
||||||
|
for (var i = 0; i < indices.length; i++)
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.NativeObject.ItemsElement.children[indices[i]], "Selected");
|
||||||
|
}
|
||||||
|
this.NativeObject.EventHandlers.SelectionChanged.Execute();
|
||||||
|
},
|
||||||
|
"Add": function(index)
|
||||||
|
{
|
||||||
|
this.AddRange([index]);
|
||||||
|
},
|
||||||
|
"Remove": function(index)
|
||||||
|
{
|
||||||
|
this.RemoveRange([index]);
|
||||||
|
},
|
||||||
|
"Count": function()
|
||||||
|
{
|
||||||
|
return this.Get().length;
|
||||||
|
},
|
||||||
|
"Get": function()
|
||||||
|
{
|
||||||
|
var items = new Array();
|
||||||
|
for (var i = 0; i < this.NativeObject.ItemsElement.children.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(this.NativeObject.ItemsElement.children[i], "Selected"))
|
||||||
|
{
|
||||||
|
items.push(new ListViewItem(this, i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return items;
|
||||||
|
},
|
||||||
|
"ContainsIndex": function(index)
|
||||||
|
{
|
||||||
|
return System.ClassList.Contains(this.NativeObject.ItemsElement.children[index], "Selected");
|
||||||
|
},
|
||||||
|
"Toggle": function(index)
|
||||||
|
{
|
||||||
|
if (this.ContainsIndex(index))
|
||||||
|
{
|
||||||
|
this.Remove(index);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Add(index);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"ToggleRange": function(indices)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < indices.length; i++)
|
||||||
|
{
|
||||||
|
this.Toggle(indices[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.SelectedRows.NativeObject = this;
|
||||||
|
|
||||||
|
/*
|
||||||
|
if (parentElement.tHead != null && parentElement.tHead.rows[0] != null)
|
||||||
|
{
|
||||||
|
// begin : magic - do not even begin to attempt to understand this logic
|
||||||
|
for (var i = 0; i < parentElement.tHead.rows[0].cells.length; i++)
|
||||||
|
{
|
||||||
|
if (parentElement.tHead.rows[0].cells[i].childNodes[0].className == "CheckBox")
|
||||||
|
{
|
||||||
|
(function(i)
|
||||||
|
{
|
||||||
|
parentElement.tHead.rows[0].cells[i].childNodes[1].addEventListener("change", function(e)
|
||||||
|
{
|
||||||
|
for (var j = 0; j < parentElement.tBodies[0].rows.length; j++)
|
||||||
|
{
|
||||||
|
parentElement.tBodies[0].rows[j].cells[i].childNodes[0].NativeObject.SetChecked(parentElement.tHead.rows[0].cells[i].childNodes[0].NativeObject.GetChecked());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
})(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// end : magic
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
this.ParentElement.addEventListener("mousedown", function(e)
|
||||||
|
{
|
||||||
|
this.NativeObject.SelectedRows.Clear();
|
||||||
|
// e.preventDefault();
|
||||||
|
// e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.Refresh();
|
||||||
|
}
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("ListView");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new ListView(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
ListView.create = function(container, createParms)
|
||||||
|
{
|
||||||
|
var table = document.createElement("table");
|
||||||
|
table.className = "uwt-listview";
|
||||||
|
|
||||||
|
if (createParms.columns)
|
||||||
|
{
|
||||||
|
var thead = document.createElement("thead");
|
||||||
|
var tr = document.createElement("tr");
|
||||||
|
|
||||||
|
for (var i = 0; i < createParms.columns.length; i++)
|
||||||
|
{
|
||||||
|
var td = document.createElement("td");
|
||||||
|
var a = document.createElement("a");
|
||||||
|
a.href = "#";
|
||||||
|
a.innerHTML = createParms.columns[i].title;
|
||||||
|
td.appendChild(a);
|
||||||
|
// createParms.columns[i].id;
|
||||||
|
tr.appendChild(td);
|
||||||
|
}
|
||||||
|
|
||||||
|
thead.appendChild(tr);
|
||||||
|
table.appendChild(thead);
|
||||||
|
}
|
||||||
|
if (createParms.items)
|
||||||
|
{
|
||||||
|
var tbody = document.createElement("tbody");
|
||||||
|
for (var i = 0; i < createParms.items.length; i++)
|
||||||
|
{
|
||||||
|
var tr = document.createElement("tr");
|
||||||
|
for (var j = 0; j < createParms.items[i].columns.length; j++)
|
||||||
|
{
|
||||||
|
var td = document.createElement("td");
|
||||||
|
|
||||||
|
var value = createParms.items[i].columns[j].value;
|
||||||
|
if (typeof(value) === "function")
|
||||||
|
{
|
||||||
|
value = value();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
td.innerHTML = value;
|
||||||
|
}
|
||||||
|
tr.appendChild(td);
|
||||||
|
}
|
||||||
|
tbody.appendChild(tr);
|
||||||
|
}
|
||||||
|
table.appendChild(tbody);
|
||||||
|
}
|
||||||
|
container.appendChild(table);
|
||||||
|
|
||||||
|
var listview = new ListView(table);
|
||||||
|
return listview;
|
||||||
|
};
|
||||||
179
lib/phast/client/scripts/controls/Menu.js
Normal file
179
lib/phast/client/scripts/controls/Menu.js
Normal file
@ -0,0 +1,179 @@
|
|||||||
|
function Menu(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.set_Expanded = function(value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.ParentElement.parentNode, "Opened");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case false:
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.ParentElement.parentNode, "Opened");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
for (var i = 0; i < this.ParentElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
this.ParentElement.childNodes[i].childNodes[0].addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
if (this.parentNode.childNodes.length > 1)
|
||||||
|
{
|
||||||
|
System.ClassList.Toggle(this.parentNode, "Opened");
|
||||||
|
}
|
||||||
|
|
||||||
|
this.blur();
|
||||||
|
|
||||||
|
if (this.href == "" || this.href == window.location.href + "#")
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("uwt-menu");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
if (items[i].NativeObject) continue;
|
||||||
|
items[i].NativeObject = new uwt-menu(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function ContextMenu()
|
||||||
|
{
|
||||||
|
this.Items = [];
|
||||||
|
this.ParentElement = null;
|
||||||
|
this.Show = function(x, y, parent)
|
||||||
|
{
|
||||||
|
ContextMenu.HideAll();
|
||||||
|
if (this.ParentElement == null)
|
||||||
|
{
|
||||||
|
var elem = document.createElement("ul");
|
||||||
|
elem.className = "uwt-menu uwt-popup";
|
||||||
|
elem.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
for (var i = 0; i < this.Items.length; i++)
|
||||||
|
{
|
||||||
|
var li = document.createElement("li");
|
||||||
|
System.ClassList.Add(li, "uwt-menu-item");
|
||||||
|
if (this.Items[i].Visible)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(li, "uwt-visible");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.Items[i].ClassName == "MenuItemCommand")
|
||||||
|
{
|
||||||
|
var elem1 = document.createElement("a");
|
||||||
|
elem1.setAttribute("href", "#");
|
||||||
|
elem1.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
this.NativeObject.Hide();
|
||||||
|
this.MenuItem.Execute();
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
elem1.innerHTML = this.Items[i].Title;
|
||||||
|
elem1.NativeObject = this;
|
||||||
|
elem1.MenuItem = this.Items[i];
|
||||||
|
li.appendChild(elem1);
|
||||||
|
|
||||||
|
System.ClassList.Add(li, "Command");
|
||||||
|
}
|
||||||
|
else if (this.Items[i].ClassName == "MenuItemSeparator")
|
||||||
|
{
|
||||||
|
System.ClassList.Add(li, "Separator");
|
||||||
|
}
|
||||||
|
else if (this.Items[i].ClassName == "MenuItemHeader")
|
||||||
|
{
|
||||||
|
System.ClassList.Add(li, "Header");
|
||||||
|
li.innerHTML = this.Items[i].Title;
|
||||||
|
}
|
||||||
|
elem.appendChild(li);
|
||||||
|
}
|
||||||
|
|
||||||
|
elem.style.left = x + "px";
|
||||||
|
elem.style.top = y + "px";
|
||||||
|
|
||||||
|
if (parent == null) parent = document.body;
|
||||||
|
parent.appendChild(elem);
|
||||||
|
this.ParentElement = elem;
|
||||||
|
}
|
||||||
|
this.ParentElement.className = "uwt-menu uwt-popup";
|
||||||
|
|
||||||
|
this.ParentElement.offsetWidth = this.ParentElement.offsetWidth; // thanks https://stackoverflow.com/a/24195559
|
||||||
|
System.ClassList.Add(this.ParentElement, "uwt-visible");
|
||||||
|
};
|
||||||
|
this.Hide = function()
|
||||||
|
{
|
||||||
|
if (this.ParentElement == null) return;
|
||||||
|
this.ParentElement.className = "uwt-menu uwt-popup";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
ContextMenu.HideAll = function()
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("uwt-menu");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(items[i], "uwt-popup"))
|
||||||
|
{
|
||||||
|
if (!System.ClassList.Contains(items[i], "uwt-visible-always"))
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(items[i], "uwt-visible");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function MenuItemHeader(id, title)
|
||||||
|
{
|
||||||
|
this.ClassName = "MenuItemHeader";
|
||||||
|
this.ID = id;
|
||||||
|
this.Title = title;
|
||||||
|
this.Visible = true;
|
||||||
|
}
|
||||||
|
function MenuItemSeparator(id)
|
||||||
|
{
|
||||||
|
this.ClassName = "MenuItemSeparator";
|
||||||
|
this.ID = id;
|
||||||
|
this.Visible = true;
|
||||||
|
}
|
||||||
|
function MenuItemCommand(id, title, onclick)
|
||||||
|
{
|
||||||
|
this.ClassName = "MenuItemCommand";
|
||||||
|
this.ID = id;
|
||||||
|
this.Title = title;
|
||||||
|
this.OnClientClick = onclick;
|
||||||
|
this.Visible = true;
|
||||||
|
|
||||||
|
this.Execute = function()
|
||||||
|
{
|
||||||
|
if (this.OnClientClick != null) this.OnClientClick();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("contextmenu", function()
|
||||||
|
{
|
||||||
|
ContextMenu.HideAll();
|
||||||
|
});
|
||||||
|
window.addEventListener("mousedown", function()
|
||||||
|
{
|
||||||
|
ContextMenu.HideAll();
|
||||||
|
});
|
||||||
219
lib/phast/client/scripts/controls/Meter.js
Normal file
219
lib/phast/client/scripts/controls/Meter.js
Normal file
@ -0,0 +1,219 @@
|
|||||||
|
function MeterDisplayStyle(value)
|
||||||
|
{
|
||||||
|
this._value = value;
|
||||||
|
}
|
||||||
|
MeterDisplayStyle.None = new MeterDisplayStyle(0);
|
||||||
|
MeterDisplayStyle.Percent = new MeterDisplayStyle(1);
|
||||||
|
MeterDisplayStyle.Decimal = new MeterDisplayStyle(2);
|
||||||
|
|
||||||
|
function Meter(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.ContentWrapperElement = this.ParentElement.childNodes[0];
|
||||||
|
this.ContentElement = this.ContentWrapperElement.childNodes[0];
|
||||||
|
this.CanvasElement = this.ContentWrapperElement.childNodes[1];
|
||||||
|
this.LabelElement = this.ParentElement.childNodes[1];
|
||||||
|
|
||||||
|
this.get_Title = function()
|
||||||
|
{
|
||||||
|
return this.LabelElement.innerHTML;
|
||||||
|
};
|
||||||
|
this.set_Title = function(value)
|
||||||
|
{
|
||||||
|
this.LabelElement.innerHTML = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get_MinimumValue = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.getAttribute("data-minimum-value");
|
||||||
|
};
|
||||||
|
this.set_MinimumValue = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("data-minimum-value", value);
|
||||||
|
};
|
||||||
|
this.get_MaximumValue = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.getAttribute("data-maximum-value");
|
||||||
|
};
|
||||||
|
this.set_MaximumValue = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("data-maximum-value", value);
|
||||||
|
};
|
||||||
|
this.get_CurrentValue = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.getAttribute("data-current-value");
|
||||||
|
};
|
||||||
|
this.set_CurrentValue = function(value)
|
||||||
|
{
|
||||||
|
if (value < this.get_MinimumValue() || value > this.get_MaximumValue()) return false;
|
||||||
|
|
||||||
|
this.ParentElement.setAttribute("data-current-value", value);
|
||||||
|
this.Refresh();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get_DisplayStyle = function()
|
||||||
|
{
|
||||||
|
var displayStyle = this.ParentElement.getAttribute("data-display-style");
|
||||||
|
switch (displayStyle.toLowerCase())
|
||||||
|
{
|
||||||
|
case "none":
|
||||||
|
{
|
||||||
|
return MeterDisplayStyle.None;
|
||||||
|
}
|
||||||
|
case "decimal":
|
||||||
|
{
|
||||||
|
return MeterDisplayStyle.Decimal;
|
||||||
|
}
|
||||||
|
case "percent":
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
return MeterDisplayStyle.Percent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.set_DisplayStyle = function(value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case MeterDisplayStyle.None:
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("data-display-style", "none");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MeterDisplayStyle.Decimal:
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("data-display-style", "decimal");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MeterDisplayStyle.Percent:
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("data-display-style", "percent");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.Refresh();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ParentElement.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
var contextMenu = new ContextMenu();
|
||||||
|
contextMenu.Items =
|
||||||
|
[
|
||||||
|
new MenuItemHeader(null, "Meter - " + this.NativeObject.get_Title()),
|
||||||
|
new MenuItemCommand(null, "Decimal", null),
|
||||||
|
new MenuItemCommand(null, "Percent", null)
|
||||||
|
];
|
||||||
|
|
||||||
|
if (this.NativeObject.ParentElement.hasAttribute("data-enable-default-contextmenu") && this.NativeObject.ParentElement.getAttribute("data-enable-default-contextmenu") == "true")
|
||||||
|
{
|
||||||
|
contextMenu.Show(e.clientX, e.clientY);
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.Refresh = function()
|
||||||
|
{
|
||||||
|
var canvas = this.CanvasElement;
|
||||||
|
canvas.height = canvas.width;
|
||||||
|
|
||||||
|
var scaleBy = 1;
|
||||||
|
var context = canvas.getContext('2d');
|
||||||
|
|
||||||
|
// support retina devices
|
||||||
|
if (window.devicePixelRatio > 1)
|
||||||
|
{
|
||||||
|
scaleBy = window.devicePixelRatio;
|
||||||
|
// canvas.style.width = canvas.style.height = [options.size, 'px'].join('');
|
||||||
|
// canvas.width = canvas.height = options.size * scaleBy;
|
||||||
|
context.scale(scaleBy, scaleBy);
|
||||||
|
}
|
||||||
|
|
||||||
|
// canvas center point
|
||||||
|
var centerX = canvas.width / 2;
|
||||||
|
var centerY = canvas.height / 2;
|
||||||
|
|
||||||
|
// radius of arc
|
||||||
|
var lineWidth = 16;
|
||||||
|
var radius = (canvas.width - lineWidth) / 2;
|
||||||
|
radius -= 2;
|
||||||
|
|
||||||
|
// 0% = 0.0, 100% = 2.0
|
||||||
|
var minimumValue = this.ParentElement.getAttribute("data-minimum-value");
|
||||||
|
var maximumValue = this.ParentElement.getAttribute("data-maximum-value");
|
||||||
|
var currentValue = this.ParentElement.getAttribute("data-current-value");
|
||||||
|
|
||||||
|
var decimalValue = ((minimumValue + currentValue) / (maximumValue - minimumValue));
|
||||||
|
if ((maximumValue - minimumValue) <= 0) decimalValue = 0;
|
||||||
|
|
||||||
|
var percentValue = (decimalValue * 100).toString() + "%";
|
||||||
|
|
||||||
|
switch (this.get_DisplayStyle())
|
||||||
|
{
|
||||||
|
case MeterDisplayStyle.None:
|
||||||
|
{
|
||||||
|
this.ContentElement.innerHTML = "";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MeterDisplayStyle.Decimal:
|
||||||
|
{
|
||||||
|
this.ContentElement.innerHTML = decimalValue * (maximumValue - minimumValue);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case MeterDisplayStyle.Percent:
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
this.ContentElement.innerHTML = percentValue;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
context.translate(centerX, centerY);
|
||||||
|
context.rotate((-1 / 2 + 0 / 180) * Math.PI);
|
||||||
|
|
||||||
|
context.beginPath();
|
||||||
|
context.lineWidth = lineWidth;
|
||||||
|
context.arc(0, 0, radius, 0, Math.PI * 2 * decimalValue, false);
|
||||||
|
|
||||||
|
if (this.ParentElement.hasAttribute("data-foreground-color"))
|
||||||
|
{
|
||||||
|
context.strokeStyle = this.ParentElement.getAttribute("data-foreground-color");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.strokeStyle = '#000000';
|
||||||
|
}
|
||||||
|
context.stroke();
|
||||||
|
context.closePath();
|
||||||
|
|
||||||
|
// rest of meter
|
||||||
|
context.beginPath();
|
||||||
|
context.arc(0, 0, radius, Math.PI * 2 * decimalValue, Math.PI * 2, false);
|
||||||
|
|
||||||
|
// line color
|
||||||
|
if (this.ParentElement.hasAttribute("data-background-color"))
|
||||||
|
{
|
||||||
|
context.strokeStyle = this.ParentElement.getAttribute("data-background-color");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
context.strokeStyle = '#CCCCCC';
|
||||||
|
}
|
||||||
|
context.stroke();
|
||||||
|
context.closePath();
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("Meter");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new Meter(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
121
lib/phast/client/scripts/controls/Notification.js
Normal file
121
lib/phast/client/scripts/controls/Notification.js
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
function Notification(parentElement)
|
||||||
|
{
|
||||||
|
this.mvarTitle = "";
|
||||||
|
this.SetTitle = function(value)
|
||||||
|
{
|
||||||
|
this.mvarTitle = value;
|
||||||
|
};
|
||||||
|
this.GetTitle = function()
|
||||||
|
{
|
||||||
|
return this.mvarTitle;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mvarContent = "";
|
||||||
|
this.SetContent = function(value)
|
||||||
|
{
|
||||||
|
this.mvarContent = value;
|
||||||
|
};
|
||||||
|
this.GetContent = function()
|
||||||
|
{
|
||||||
|
return this.mvarContent;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.mvarCssClass = "";
|
||||||
|
this.SetCssClass = function(value)
|
||||||
|
{
|
||||||
|
this.mvarCssClass = value;
|
||||||
|
};
|
||||||
|
this.GetCssClass = function()
|
||||||
|
{
|
||||||
|
return this.mvarCssClass;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.mvarTimeout = -1;
|
||||||
|
this.SetTimeout = function(value)
|
||||||
|
{
|
||||||
|
this.mvarTimeout = value;
|
||||||
|
}
|
||||||
|
this.GetTimeout = function()
|
||||||
|
{
|
||||||
|
return this.mvarTimeout;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.mvarParentElement = null;
|
||||||
|
this.Show = function(timeoutInMilliseconds)
|
||||||
|
{
|
||||||
|
var element = document.createElement("DIV");
|
||||||
|
var cssClass = "Notification";
|
||||||
|
if (this.GetCssClass() != "") cssClass += " " + this.GetCssClass();
|
||||||
|
element.className = cssClass;
|
||||||
|
element.ObjectReference = this;
|
||||||
|
|
||||||
|
element.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
this.ObjectReference.Hide();
|
||||||
|
});
|
||||||
|
|
||||||
|
this.mvarParentElement = element;
|
||||||
|
|
||||||
|
var elemTitle = document.createElement("DIV");
|
||||||
|
elemTitle.className = "Title";
|
||||||
|
elemTitle.innerHTML = this.GetTitle();
|
||||||
|
element.appendChild(elemTitle);
|
||||||
|
|
||||||
|
var elemContent = document.createElement("DIV");
|
||||||
|
elemContent.className = "Content";
|
||||||
|
elemContent.innerHTML = this.GetContent();
|
||||||
|
element.appendChild(elemContent);
|
||||||
|
|
||||||
|
document.body.appendChild(element);
|
||||||
|
cssClass += " Visible";
|
||||||
|
|
||||||
|
// timeout required to see the transition when first adding the element to the page
|
||||||
|
window.setTimeout(function()
|
||||||
|
{
|
||||||
|
element.className = cssClass;
|
||||||
|
}, 50);
|
||||||
|
|
||||||
|
if (typeof(timeoutInMilliseconds) != "undefined")
|
||||||
|
{
|
||||||
|
window.setTimeout(function(sender)
|
||||||
|
{
|
||||||
|
sender.Hide();
|
||||||
|
}, timeoutInMilliseconds, this);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.Hide = function()
|
||||||
|
{
|
||||||
|
var cssClass = "Notification";
|
||||||
|
if (this.GetCssClass() != "") cssClass += " " + this.GetCssClass();
|
||||||
|
this.mvarParentElement.className = cssClass;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Notification.Show = function(content, title, cssClass, timeoutInMilliseconds)
|
||||||
|
{
|
||||||
|
var n = new Notification();
|
||||||
|
|
||||||
|
if (typeof(content) === "undefined")
|
||||||
|
{
|
||||||
|
console.warn("showing notification with empty content");
|
||||||
|
content = "";
|
||||||
|
}
|
||||||
|
n.SetContent(content);
|
||||||
|
|
||||||
|
if (typeof(title) === "undefined")
|
||||||
|
{
|
||||||
|
console.warn("showing notification with empty title");
|
||||||
|
title = "";
|
||||||
|
}
|
||||||
|
n.SetTitle(title);
|
||||||
|
|
||||||
|
if (typeof(cssClass) === "undefined") cssClass = "";
|
||||||
|
n.SetCssClass(cssClass);
|
||||||
|
|
||||||
|
if (typeof(timeoutInMilliseconds) !== "undefined")
|
||||||
|
{
|
||||||
|
n.SetTimeout(timeoutInMilliseconds);
|
||||||
|
}
|
||||||
|
|
||||||
|
n.Show();
|
||||||
|
};
|
||||||
21
lib/phast/client/scripts/controls/Panel.js
Normal file
21
lib/phast/client/scripts/controls/Panel.js
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
function Panel(id)
|
||||||
|
{
|
||||||
|
this._iframe = document.getElementById("Panel_" + id + "_IFrame");
|
||||||
|
this._iframe.onload = function(sender)
|
||||||
|
{
|
||||||
|
sender._throbber.style.display = "none";
|
||||||
|
sender._content.style.display = "block";
|
||||||
|
}.PrependArgument(this);
|
||||||
|
|
||||||
|
this._content = document.getElementById("Panel_" + id + "_Content");
|
||||||
|
|
||||||
|
this._throbber = document.getElementById("Panel_" + id + "_Throbber");
|
||||||
|
|
||||||
|
this.ID = id;
|
||||||
|
this.NavigateTo = function(url)
|
||||||
|
{
|
||||||
|
this._throbber.style.display = "block";
|
||||||
|
// this._content.style.display = "none";
|
||||||
|
this._iframe.src = url;
|
||||||
|
};
|
||||||
|
}
|
||||||
92
lib/phast/client/scripts/controls/Popup.js
Normal file
92
lib/phast/client/scripts/controls/Popup.js
Normal file
@ -0,0 +1,92 @@
|
|||||||
|
function Popup(idOrParentElement)
|
||||||
|
{
|
||||||
|
if (typeof(idOrParentElement) === "string")
|
||||||
|
{
|
||||||
|
this.ID = id;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.ParentElement = idOrParentElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Show = function()
|
||||||
|
{
|
||||||
|
Popup.HideAll();
|
||||||
|
|
||||||
|
if (this.ParentElement)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.ParentElement, "uwt-visible");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var obj = document.getElementById("Popup_" + this.ID);
|
||||||
|
obj.classList.add("Visible");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.Hide = function()
|
||||||
|
{
|
||||||
|
if (this.ParentElement)
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.ParentElement, "uwt-visible");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var obj = document.getElementById("Popup_" + this.ID);
|
||||||
|
obj.classList.remove("Visible");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
Popup.HideAll = function()
|
||||||
|
{
|
||||||
|
var elems = document.getElementsByClassName("uwt-popup");
|
||||||
|
for (var i = 0; i < elems.length; i++)
|
||||||
|
{
|
||||||
|
if (!System.ClassList.Contains(elems[i], "uwt-visible-always"))
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(elems[i], "uwt-visible");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Popup.create = function(container)
|
||||||
|
{
|
||||||
|
console.log(container);
|
||||||
|
|
||||||
|
var parentElement = document.createElement("div");
|
||||||
|
parentElement.className = "uwt-popup";
|
||||||
|
|
||||||
|
container.appendChild(parentElement);
|
||||||
|
|
||||||
|
var popup = new Popup(parentElement);
|
||||||
|
return popup;
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("mousedown", function(e)
|
||||||
|
{
|
||||||
|
var sender;
|
||||||
|
if (!e)
|
||||||
|
{
|
||||||
|
e = window.event;
|
||||||
|
}
|
||||||
|
if (e.target)
|
||||||
|
{
|
||||||
|
sender = e.target;
|
||||||
|
}
|
||||||
|
else if (e.srcElement)
|
||||||
|
{
|
||||||
|
sender = e.srcElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
while (sender != null)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(sender, "Popup"))
|
||||||
|
{
|
||||||
|
// do not close the popup when we click inside itself
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
sender = sender.parentNode;
|
||||||
|
if (sender == null) break;
|
||||||
|
}
|
||||||
|
Popup.HideAll();
|
||||||
|
});
|
||||||
28
lib/phast/client/scripts/controls/ProgressBar.js
Normal file
28
lib/phast/client/scripts/controls/ProgressBar.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
function ProgressBar(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.MinimumValue = 0;
|
||||||
|
this.MaximumValue = 100;
|
||||||
|
this.CurrentValue = 0;
|
||||||
|
this.SetCurrentValue = function(value)
|
||||||
|
{
|
||||||
|
this.CurrentValue = value;
|
||||||
|
this.Update();
|
||||||
|
};
|
||||||
|
this.Update = function()
|
||||||
|
{
|
||||||
|
var pb_fill = document.getElementById("ProgressBar_" + this.ID + "_ValueFill");
|
||||||
|
var pb_label = document.getElementById("ProgressBar_" + this.ID + "_ValueLabel");
|
||||||
|
pb_fill.style.width = ((this.CurrentValue / (this.MaximumValue - this.MinimumValue)) * 100).toFixed(0).toString() + "%";
|
||||||
|
pb_label.innerHTML = ((this.CurrentValue / (this.MaximumValue - this.MinimumValue)) * 100).toFixed(0).toString() + "%";
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("ProgressBar");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new ProgressBar(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
457
lib/phast/client/scripts/controls/Ribbon.js
Normal file
457
lib/phast/client/scripts/controls/Ribbon.js
Normal file
@ -0,0 +1,457 @@
|
|||||||
|
function Ribbon(id, parent)
|
||||||
|
{
|
||||||
|
var ribbon = this;
|
||||||
|
this.ID = id;
|
||||||
|
this.ParentElement = parent;
|
||||||
|
|
||||||
|
System.AddEventListener(parent, System.Events.MouseWheel, function(e)
|
||||||
|
{
|
||||||
|
if (e.Delta > 0)
|
||||||
|
{
|
||||||
|
ribbon.PreviousTab();
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
|
else if (e.Delta < 0)
|
||||||
|
{
|
||||||
|
// forward
|
||||||
|
ribbon.NextTab();
|
||||||
|
e.Cancel = true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var applicationButton = parent.getElementsByClassName("ApplicationButton")[0];
|
||||||
|
var applicationMenu = document.getElementById("Ribbon_" + this.ID + "_ApplicationMenu");
|
||||||
|
|
||||||
|
this.PreviousTab = function()
|
||||||
|
{
|
||||||
|
var tabContainer = document.getElementById("Ribbon_" + this.ID + "_TabContainer");
|
||||||
|
var tabContentContainer = document.getElementById("Ribbon_" + this.ID + "_TabContentContainer");
|
||||||
|
var tabs = tabContentContainer.getElementsByClassName("RibbonTabContent");
|
||||||
|
for (var i = 1; i < tabs.length; i++)
|
||||||
|
{
|
||||||
|
if (tabs[i].className == "RibbonTabContent Selected")
|
||||||
|
{
|
||||||
|
ribbon.ActivateTab(tabs[i - 1]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.NextTab = function()
|
||||||
|
{
|
||||||
|
var tabContainer = document.getElementById("Ribbon_" + this.ID + "_TabContainer");
|
||||||
|
var tabContentContainer = document.getElementById("Ribbon_" + this.ID + "_TabContentContainer");
|
||||||
|
var tabs = tabContentContainer.getElementsByClassName("RibbonTabContent");
|
||||||
|
for (var i = 0; i < tabs.length - 1; i++)
|
||||||
|
{
|
||||||
|
if (tabs[i].className == "RibbonTabContent Selected")
|
||||||
|
{
|
||||||
|
ribbon.ActivateTab(tabs[i + 1]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.GetActiveTab = function()
|
||||||
|
{
|
||||||
|
var tabContentContainer = document.getElementById("Ribbon_" + this.ID + "_TabContentContainer");
|
||||||
|
var tabs = tabContentContainer.getElementsByClassName("RibbonTabContent");
|
||||||
|
for (var i = 0; i < tabs.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(tabs[i], "Selected"))
|
||||||
|
{
|
||||||
|
return tabs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
this.ActivateTab = function (tab)
|
||||||
|
{
|
||||||
|
if (tab != null) ribbon.SetOpened(true);
|
||||||
|
var tabContainer = document.getElementById("Ribbon_" + this.ID + "_TabContainer");
|
||||||
|
var ribbonTabs = tabContainer.getElementsByTagName("A");
|
||||||
|
|
||||||
|
var tabContentContainer = document.getElementById("Ribbon_" + this.ID + "_TabContentContainer");
|
||||||
|
var tabs = tabContentContainer.getElementsByClassName("RibbonTabContent");
|
||||||
|
for (var i = 0; i < tabs.length; i++)
|
||||||
|
{
|
||||||
|
if (tabs[i] === tab)
|
||||||
|
{
|
||||||
|
ribbonTabs[i].className = "RibbonTab Selected";
|
||||||
|
tabs[i].className = "RibbonTabContent Selected";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ribbonTabs[i].className = "RibbonTab";
|
||||||
|
tabs[i].className = "RibbonTabContent";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tab == null)
|
||||||
|
{
|
||||||
|
// System.ClearClientProperty(this.ID, "ActiveTabID");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.SetClientProperty(this.ID, "ActiveTabID", tab.attributes["data-tab-id"].value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ToggleOpened = function ()
|
||||||
|
{
|
||||||
|
if (ribbon.IsOpened())
|
||||||
|
{
|
||||||
|
ribbon.SetOpened(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ribbon.SetOpened(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.IsOpened = function ()
|
||||||
|
{
|
||||||
|
return (ribbon.ParentElement.className != "Ribbon Collapsed");
|
||||||
|
}
|
||||||
|
this.SetOpened = function (value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
{
|
||||||
|
ribbon.ParentElement.className = "Ribbon";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case false:
|
||||||
|
{
|
||||||
|
ribbon.ParentElement.className = "Ribbon Collapsed";
|
||||||
|
ribbon.ActivateTab(null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ToggleCollapsed = function ()
|
||||||
|
{
|
||||||
|
if (ribbon.IsCollapsed())
|
||||||
|
{
|
||||||
|
ribbon.SetCollapsed(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ribbon.SetCollapsed(true);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.IsCollapsed = function ()
|
||||||
|
{
|
||||||
|
var ribbonSpacer = document.getElementById("Ribbon_" + ribbon.ID + "_Spacer");
|
||||||
|
return (ribbonSpacer.className == "RibbonSpacer Collapsed");
|
||||||
|
};
|
||||||
|
this.SetCollapsed = function (value)
|
||||||
|
{
|
||||||
|
var ribbonSpacer = document.getElementById("Ribbon_" + ribbon.ID + "_Spacer");
|
||||||
|
ribbon.SetOpened(!value);
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
{
|
||||||
|
ribbonSpacer.className = "RibbonSpacer Collapsed";
|
||||||
|
ribbon.ActivateTab(null);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case false:
|
||||||
|
{
|
||||||
|
ribbonSpacer.className = "RibbonSpacer";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.SetClientProperty(this.ID, "Collapsed", value);
|
||||||
|
};
|
||||||
|
this.SetApplicationMenuVisible = function (value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
{
|
||||||
|
applicationButton.className = "ApplicationButton Selected";
|
||||||
|
applicationMenu.className = "ApplicationMenu Visible";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case false:
|
||||||
|
{
|
||||||
|
applicationButton.className = "ApplicationButton";
|
||||||
|
applicationMenu.className = "ApplicationMenu";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.GetTabByIndex = function (i)
|
||||||
|
{
|
||||||
|
var tabContentContainer = document.getElementById("Ribbon_" + this.ID + "_TabContentContainer");
|
||||||
|
var tabs = tabContentContainer.getElementsByClassName("RibbonTabContent");
|
||||||
|
return tabs[i];
|
||||||
|
};
|
||||||
|
this.GetTabByName = function (name)
|
||||||
|
{
|
||||||
|
var tabContentContainer = document.getElementById("Ribbon_" + this.ID + "_TabContentContainer");
|
||||||
|
var tabs = tabContentContainer.getElementsByClassName("RibbonTabContent");
|
||||||
|
for (var i = 0; i < tabs.length; i++)
|
||||||
|
{
|
||||||
|
if (tabs[i].attributes["data-tab-id"].value == name)
|
||||||
|
{
|
||||||
|
return tabs[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
System.AddEventListener(applicationButton, System.Events.MouseClick, function (e)
|
||||||
|
{
|
||||||
|
if (applicationButton.className == "ApplicationButton")
|
||||||
|
{
|
||||||
|
if (ribbon.IsCollapsed() && ribbon.IsOpened())
|
||||||
|
{
|
||||||
|
ribbon.SetOpened(false);
|
||||||
|
}
|
||||||
|
ribbon.SetApplicationMenuVisible(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ribbon.SetApplicationMenuVisible(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
var tabContainer = document.getElementById("Ribbon_" + this.ID + "_TabContainer");
|
||||||
|
|
||||||
|
var ribbonTabs = tabContainer.getElementsByTagName("A");
|
||||||
|
for (var i = 0; i < ribbonTabs.length; i++)
|
||||||
|
{
|
||||||
|
var tab = ribbonTabs[i];
|
||||||
|
tab.addEventListener("click", function (e)
|
||||||
|
{
|
||||||
|
if (this.attributes["href"].value == "#")
|
||||||
|
{
|
||||||
|
// only activate tab if the tab is not a "navigational" tab
|
||||||
|
ribbon.ActivateTab(ribbon.GetTabByName(this.attributes["data-tab-id"].value));
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
tab.addEventListener("dblclick", function (e)
|
||||||
|
{
|
||||||
|
ribbon.ToggleCollapsed();
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var Ribbons = new Array();
|
||||||
|
window.addEventListener('load', function (e)
|
||||||
|
{
|
||||||
|
var ribbons = document.getElementsByClassName("Ribbon");
|
||||||
|
for (var i = 0; i < ribbons.length; i++)
|
||||||
|
{
|
||||||
|
var parent = ribbons[i];
|
||||||
|
if (parent.tagName != "DIV") continue;
|
||||||
|
var ribbon = new Ribbon(parent.attributes["data-id"].value, parent);
|
||||||
|
parent.Ribbon = ribbon;
|
||||||
|
|
||||||
|
parent.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
Ribbons.push(ribbon);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("keydown", function (e)
|
||||||
|
{
|
||||||
|
switch (e.keyCode)
|
||||||
|
{
|
||||||
|
case 27: /* ESC */
|
||||||
|
{
|
||||||
|
// ESCAPE was pressed; hide all application menus
|
||||||
|
for (var i = 0; i < Ribbons.length; i++)
|
||||||
|
{
|
||||||
|
Ribbons[i].SetApplicationMenuVisible(false);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
function TerminateIfSenderIs(sender, compareTo)
|
||||||
|
{
|
||||||
|
while (sender != null)
|
||||||
|
{
|
||||||
|
if (sender.classList)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < compareTo.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(sender, compareTo[i]))
|
||||||
|
{
|
||||||
|
// do not close the popup when we click inside itself
|
||||||
|
// e.preventDefault();
|
||||||
|
// e.stopPropagation();
|
||||||
|
// alert(compareTo[i] + " = " + sender.className + " ? true ");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
sender = sender.parentNode;
|
||||||
|
if (sender == null) break;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("mousedown", function (e)
|
||||||
|
{
|
||||||
|
var sender = null;
|
||||||
|
if (!e) e = window.event;
|
||||||
|
if (e.target)
|
||||||
|
{
|
||||||
|
sender = e.target;
|
||||||
|
}
|
||||||
|
else if (e.srcElement)
|
||||||
|
{
|
||||||
|
sender = e.srcElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TerminateIfSenderIs(sender, ["ApplicationMenu"]))
|
||||||
|
{
|
||||||
|
for (var i = 0; i < Ribbons.length; i++)
|
||||||
|
{
|
||||||
|
Ribbons[i].SetApplicationMenuVisible(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TerminateIfSenderIs(sender, ["Ribbon"]))
|
||||||
|
{
|
||||||
|
for (var i = 0; i < Ribbons.length; i++)
|
||||||
|
{
|
||||||
|
if (Ribbons[i].IsCollapsed())
|
||||||
|
{
|
||||||
|
Ribbons[i].SetOpened(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TerminateIfSenderIs(sender, ["RibbonDropDownCommand"]))
|
||||||
|
{
|
||||||
|
Ribbon.CloseAllRibbonDropDownMenus();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Ribbon.FromID = function (id)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < Ribbons.length; i++)
|
||||||
|
{
|
||||||
|
if (Ribbons[i].ID == id) return Ribbons[i];
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
Ribbon.CloseAllRibbonDropDownMenus = function()
|
||||||
|
{
|
||||||
|
var RibbonDropDownItems = document.getElementsByClassName("RibbonDropDownCommand");
|
||||||
|
for (var i = 0; i < RibbonDropDownItems.length; i++)
|
||||||
|
{
|
||||||
|
RibbonDropDownItems[i].classList.remove("Selected");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
Ribbon.CurrentContextHelpURL = "";
|
||||||
|
Ribbon.CurrentContextHelpTargetName = "_blank";
|
||||||
|
|
||||||
|
function RibbonButtonCommand(id)
|
||||||
|
{
|
||||||
|
this.ID = id;
|
||||||
|
this.SetSelected = function(value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
{
|
||||||
|
var rbc_array = document.getElementsByClassName(this.ID);
|
||||||
|
for (var i = 0; i < rbc_array.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(rbc_array[i], "Disabled")) continue;
|
||||||
|
System.ClassList.Add(rbc_array[i], "Selected");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case false:
|
||||||
|
{
|
||||||
|
var rbc_array = document.getElementsByClassName(this.ID);
|
||||||
|
for (var i = 0; i < rbc_array.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(rbc_array[i], "Disabled")) continue;
|
||||||
|
System.ClassList.Remove(rbc_array[i], "Selected");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.IsSelected = function()
|
||||||
|
{
|
||||||
|
var rbc_array = document.getElementsByClassName(this.ID);
|
||||||
|
for (var i = 0; i < rbc_array.length; i++)
|
||||||
|
{
|
||||||
|
if (rbc_array[i].className == "RibbonCommand RibbonButtonCommand " + this.ID + " Selected") return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
this.ToggleSelected = function()
|
||||||
|
{
|
||||||
|
this.SetSelected(!this.IsSelected());
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function RibbonDropDownCommand(id)
|
||||||
|
{
|
||||||
|
this.ID = id;
|
||||||
|
this.SetSelected = function(value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case true:
|
||||||
|
{
|
||||||
|
Ribbon.CloseAllRibbonDropDownMenus();
|
||||||
|
var rbc_array = document.getElementsByClassName(this.ID);
|
||||||
|
for (var i = 0; i < rbc_array.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(rbc_array[i], "Disabled")) continue;
|
||||||
|
System.ClassList.Add(rbc_array[i], "Selected");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case false:
|
||||||
|
{
|
||||||
|
var rbc_array = document.getElementsByClassName(this.ID);
|
||||||
|
for (var i = 0; i < rbc_array.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(rbc_array[i], "Disabled")) continue;
|
||||||
|
System.ClassList.Remove(rbc_array[i], "Selected");
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.IsSelected = function()
|
||||||
|
{
|
||||||
|
var rbc_array = document.getElementsByClassName(this.ID);
|
||||||
|
for (var i = 0; i < rbc_array.length; i++)
|
||||||
|
{
|
||||||
|
if (rbc_array[i].className == "RibbonCommand RibbonDropDownCommand " + this.ID + " Selected") return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
this.ToggleSelected = function()
|
||||||
|
{
|
||||||
|
this.SetSelected(!this.IsSelected());
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
}
|
||||||
26
lib/phast/client/scripts/controls/Sidebar.js
Normal file
26
lib/phast/client/scripts/controls/Sidebar.js
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
function Sidebar(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.MenuElement = this.ParentElement.children[0];
|
||||||
|
|
||||||
|
for (var i = 0; i < this.MenuElement.children.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(this.MenuElement.children[i], "Command"))
|
||||||
|
{
|
||||||
|
var a = this.MenuElement.children[i].children[0];
|
||||||
|
if (a.href == window.location.href)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.MenuElement.children[i], "Selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", function()
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("Sidebar");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new Sidebar(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
84
lib/phast/client/scripts/controls/SlideContainer.js
Normal file
84
lib/phast/client/scripts/controls/SlideContainer.js
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
function SlideContainer(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
this.mvarCurrentPageIndex = 0;
|
||||||
|
this.GetPageCount = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.children.length;
|
||||||
|
};
|
||||||
|
this.ScrollDown = function()
|
||||||
|
{
|
||||||
|
if (this.mvarCurrentPageIndex < this.GetPageCount() - 1)
|
||||||
|
{
|
||||||
|
this.mvarCurrentPageIndex++;
|
||||||
|
this.Update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.ScrollUp = function()
|
||||||
|
{
|
||||||
|
if (this.mvarCurrentPageIndex > 0)
|
||||||
|
{
|
||||||
|
this.mvarCurrentPageIndex--;
|
||||||
|
this.Update();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
/*
|
||||||
|
this._animationFrame = 0;
|
||||||
|
this._animationStop = 0;
|
||||||
|
this._animateFrame = function(frame)
|
||||||
|
{
|
||||||
|
var startFrame = (document.body.scrollHeight * (this.mvarCurrentPageIndex - 1)) * frame;
|
||||||
|
var endFrame = (document.body.scrollHeight * this.mvarCurrentPageIndex) * frame;
|
||||||
|
|
||||||
|
window.scrollTo("100%", endFrame - startFrame);
|
||||||
|
if (frame < 1.0)
|
||||||
|
{
|
||||||
|
window.setTimeout(function(p, f)
|
||||||
|
{
|
||||||
|
p._animateFrame(f + 0.01);
|
||||||
|
}, 10, this, frame);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
*/
|
||||||
|
this.Update = function()
|
||||||
|
{
|
||||||
|
// this._animationStop = document.body.scrollHeight * this.mvarCurrentPageIndex;
|
||||||
|
// this._animateFrame(0.0);
|
||||||
|
window.scrollTo("100%", (document.body.scrollHeight * this.mvarCurrentPageIndex));
|
||||||
|
};
|
||||||
|
}
|
||||||
|
SlideContainer.Create = function(element)
|
||||||
|
{
|
||||||
|
if (!System.ClassList.Contains(element, "SlideContainer")) return null;
|
||||||
|
return new SlideContainer(element);
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
window.SlideContainer = SlideContainer.Create(document.body);
|
||||||
|
if (window.SlideContainer != null)
|
||||||
|
{
|
||||||
|
window.addEventListener("DOMMouseScroll", function(ee)
|
||||||
|
{
|
||||||
|
if (ee.detail > 0)
|
||||||
|
{
|
||||||
|
// scroll down
|
||||||
|
ee.preventDefault();
|
||||||
|
ee.stopPropagation();
|
||||||
|
|
||||||
|
window.SlideContainer.ScrollDown();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else if (ee.detail < 0)
|
||||||
|
{
|
||||||
|
// scroll up
|
||||||
|
ee.preventDefault();
|
||||||
|
ee.stopPropagation();
|
||||||
|
|
||||||
|
window.SlideContainer.ScrollUp();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
0
lib/phast/client/scripts/controls/Slider.js
Normal file
0
lib/phast/client/scripts/controls/Slider.js
Normal file
43
lib/phast/client/scripts/controls/SplitContainer.js
Normal file
43
lib/phast/client/scripts/controls/SplitContainer.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
function SplitContainer(id, splitterPosition)
|
||||||
|
{
|
||||||
|
this.ID = id;
|
||||||
|
this.SplitterPosition = splitterPosition;
|
||||||
|
|
||||||
|
var parent = this;
|
||||||
|
var splitPanelPrimary = document.getElementById("SplitContainer_" + this.ID + "_Primary");
|
||||||
|
var splitter = document.getElementById("SplitContainer_" + this.ID + "_Splitter");
|
||||||
|
|
||||||
|
this.Update = function()
|
||||||
|
{
|
||||||
|
splitPanelPrimary.style.width = (parent.SplitterPosition + "px");
|
||||||
|
};
|
||||||
|
|
||||||
|
splitter.addEventListener("mousedown", function(e)
|
||||||
|
{
|
||||||
|
parent._Dragging = true;
|
||||||
|
|
||||||
|
parent.InitialSplitterPosition = splitPanelPrimary.offsetWidth;
|
||||||
|
parent.InitialX = e.clientX;
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
|
||||||
|
document.body.style.cursor = "col-resize !important";
|
||||||
|
});
|
||||||
|
window.addEventListener("mousemove", function(e)
|
||||||
|
{
|
||||||
|
if (parent._Dragging)
|
||||||
|
{
|
||||||
|
parent.SplitterPosition = (parent.InitialSplitterPosition + (e.clientX - parent.InitialX));
|
||||||
|
parent.Update();
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("mouseup", function(e)
|
||||||
|
{
|
||||||
|
parent._Dragging = false;
|
||||||
|
document.body.style.cursor = "inherit";
|
||||||
|
});
|
||||||
|
}
|
||||||
84
lib/phast/client/scripts/controls/TabContainer.js
Normal file
84
lib/phast/client/scripts/controls/TabContainer.js
Normal file
@ -0,0 +1,84 @@
|
|||||||
|
function TabContainer(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
this.mvarSelectedTabID = null;
|
||||||
|
this.GetSelectedTabID = function()
|
||||||
|
{
|
||||||
|
return this.mvarSelectedTabID;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.SetSelectedTab = function(tab)
|
||||||
|
{
|
||||||
|
var tabContainer = this.ParentElement;
|
||||||
|
if (tabContainer == null) return;
|
||||||
|
|
||||||
|
var tabs = tabContainer.childNodes[0];
|
||||||
|
var tabPages = tabContainer.childNodes[1];
|
||||||
|
var selectedIndex = -1;
|
||||||
|
for (var i = 0; i < tabs.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(tabs.childNodes[i], "Selected"))
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(tabs.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (tabs.childNodes[i] === tab)
|
||||||
|
{
|
||||||
|
selectedIndex = i;
|
||||||
|
System.ClassList.Add(tabs.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 0; i < tabPages.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (selectedIndex > -1 && selectedIndex < tabPages.childNodes.length && i == selectedIndex)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(tabPages.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(tabPages.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
System.SetClientProperty(this.ID, "SelectedTabIndex", selectedIndex);
|
||||||
|
|
||||||
|
if (tabs.childNodes[selectedIndex] != null && tabs.childNodes[selectedIndex].attributes["data-id"] != null)
|
||||||
|
{
|
||||||
|
this.mvarSelectedTabID = tabs.childNodes[selectedIndex].attributes["data-id"].value;
|
||||||
|
}
|
||||||
|
|
||||||
|
var attOnClientTabChanged = tabContainer.attributes["data-onclienttabchanged"];
|
||||||
|
if (attOnClientTabChanged != null)
|
||||||
|
{
|
||||||
|
eval(attOnClientTabChanged.value);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
var tabContainer = this.ParentElement;
|
||||||
|
var tabs = tabContainer.childNodes[0];
|
||||||
|
for (var i = 0; i < tabs.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
(function(i, tc)
|
||||||
|
{
|
||||||
|
tabs.childNodes[i].addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
tc.SetSelectedTab(tabs.childNodes[i]);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
})(i, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
eval("window." + tabContainer.attributes["id"].value + " = this;");
|
||||||
|
}
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var tbss = document.getElementsByClassName("TabContainer");
|
||||||
|
for (var i = 0; i < tbss.length; i++)
|
||||||
|
{
|
||||||
|
tbss[i].ObjectReference = new TabContainer(tbss[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
556
lib/phast/client/scripts/controls/TextBox.js
Normal file
556
lib/phast/client/scripts/controls/TextBox.js
Normal file
@ -0,0 +1,556 @@
|
|||||||
|
function TextBoxItem(parent, value, title)
|
||||||
|
{
|
||||||
|
this.NativeObject = parent;
|
||||||
|
this.Title = title;
|
||||||
|
this.Value = value;
|
||||||
|
|
||||||
|
this.GetSelected = function()
|
||||||
|
{
|
||||||
|
for (var i = 0; i < this.NativeObject.SelectElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (this.NativeObject.SelectElement.childNodes[i].value == this.Value)
|
||||||
|
{
|
||||||
|
if (this.NativeObject.SelectElement.childNodes[i].hasAttribute("selected")) return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
this.SetSelected = function(value)
|
||||||
|
{
|
||||||
|
var changed = false;
|
||||||
|
for (var i = 0; i < this.NativeObject.SelectElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (this.NativeObject.SelectElement.childNodes[i].value == this.Value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
changed = changed || !this.NativeObject.SelectElement.childNodes[i].hasAttribute("selected");
|
||||||
|
this.NativeObject.SelectElement.childNodes[i].setAttribute("selected", "selected");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
changed = changed || !this.NativeObject.SelectElement.childNodes[i].hasAttribute("selected");
|
||||||
|
this.NativeObject.SelectElement.childNodes[i].removeAttribute("selected", "selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!this.NativeObject.IsMultiSelect())
|
||||||
|
{
|
||||||
|
changed = changed || this.NativeObject.SelectElement.childNodes[i].hasAttribute("selected");
|
||||||
|
this.NativeObject.SelectElement.childNodes[i].removeAttribute("selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.NativeObject.UpdateSelectedItems();
|
||||||
|
|
||||||
|
if (changed)
|
||||||
|
{
|
||||||
|
this.NativeObject.EventHandlers.SelectionChanged.Execute(this.NativeObject, null);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
function TextBox(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.TextBoxElement = parentElement.children[0].children[1];
|
||||||
|
this.PopupElement = parentElement.children[1];
|
||||||
|
this.DropDownElement = this.PopupElement.children[0];
|
||||||
|
this.SelectElement = parentElement.children[2];
|
||||||
|
|
||||||
|
this.EventHandlers =
|
||||||
|
{
|
||||||
|
"DropDownOpening": new System.EventHandler(),
|
||||||
|
"DropDownOpened": new System.EventHandler(),
|
||||||
|
"SelectionChanged": new System.EventHandler()
|
||||||
|
};
|
||||||
|
|
||||||
|
this.SetLoading = function(value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.ParentElement, "Loading");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.ParentElement, "Loading");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ShouldClearOnFocus = function()
|
||||||
|
{
|
||||||
|
return System.ClassList.Contains(this.ParentElement, "ClearOnFocus");
|
||||||
|
};
|
||||||
|
this.IsMultiSelect = function()
|
||||||
|
{
|
||||||
|
return System.ClassList.Contains(this.ParentElement, "MultiSelect");
|
||||||
|
};
|
||||||
|
|
||||||
|
this.UpdateSelectedItems = function()
|
||||||
|
{
|
||||||
|
var selectedItems = [];
|
||||||
|
var text = "";
|
||||||
|
for (var i = 0; i < this.SelectElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (this.SelectElement.childNodes[i].hasAttribute("selected"))
|
||||||
|
{
|
||||||
|
selectedItems.push(new TextBoxItem(this, this.SelectElement.childNodes[i].value, this.SelectElement.childNodes[i].innerHTML));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 0; i < this.DropDownElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.DropDownElement.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
for (var i = 0; i < selectedItems.length; i++)
|
||||||
|
{
|
||||||
|
text += selectedItems[i].Title;
|
||||||
|
if (i < selectedItems.length - 1) text += "; ";
|
||||||
|
|
||||||
|
for (var j = 0; j < this.DropDownElement.childNodes.length; j++)
|
||||||
|
{
|
||||||
|
if (this.DropDownElement.childNodes[j].childNodes[0].getAttribute("data-value") == selectedItems[i].Value)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.DropDownElement.childNodes[j], "Selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.TextBoxElement.placeholder = text;
|
||||||
|
this.ParentElement.selectedItems = selectedItems;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parentElement.attributes["name"] != null)
|
||||||
|
{
|
||||||
|
this.Name = parentElement.attributes["name"].value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.Name = "";
|
||||||
|
}
|
||||||
|
if (parentElement.attributes["data-suggestion-url"] != null)
|
||||||
|
{
|
||||||
|
this.SuggestionURL = parentElement.attributes["data-suggestion-url"].value;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.SuggestionURL = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Focus = function()
|
||||||
|
{
|
||||||
|
this.TextBoxElement.focus();
|
||||||
|
};
|
||||||
|
this.ClearText = function()
|
||||||
|
{
|
||||||
|
this.TextBoxElement.value = "";
|
||||||
|
};
|
||||||
|
this.GetText = function()
|
||||||
|
{
|
||||||
|
return this.TextBoxElement.value;
|
||||||
|
};
|
||||||
|
this.SetText = function(value)
|
||||||
|
{
|
||||||
|
this.TextBoxElement.value = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.TextBoxElement.NativeObject = this;
|
||||||
|
this.TextBoxElement.addEventListener("focus", function(e)
|
||||||
|
{
|
||||||
|
if (this.NativeObject.ShouldClearOnFocus())
|
||||||
|
{
|
||||||
|
this.NativeObject.TextBoxElement.placeholder = this.NativeObject.TextBoxElement.value;
|
||||||
|
this.NativeObject.ClearText();
|
||||||
|
}
|
||||||
|
if (this.NativeObject.ParentElement.attributes["data-auto-open"] != null)
|
||||||
|
{
|
||||||
|
if (this.NativeObject.ParentElement.attributes["data-auto-open"].value == "true")
|
||||||
|
{
|
||||||
|
this.NativeObject.Refresh();
|
||||||
|
this.NativeObject.DropDown.Open();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.TextBoxElement.addEventListener("blur", function(e)
|
||||||
|
{
|
||||||
|
if (this.value == "" && this.placeholder != "")
|
||||||
|
{
|
||||||
|
this.value = this.placeholder;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
this.TextBoxElement.addEventListener("keydown", function(e)
|
||||||
|
{
|
||||||
|
var no = this.NativeObject;
|
||||||
|
if (e.keyCode == KeyboardKeys.ArrowDown || e.keyCode == KeyboardKeys.ArrowUp)
|
||||||
|
{
|
||||||
|
if (no.DropDownElement.children.length > 0)
|
||||||
|
{
|
||||||
|
var found = false;
|
||||||
|
var firstI = -1;
|
||||||
|
for (var i = 0; i < no.DropDownElement.children.length; i++)
|
||||||
|
{
|
||||||
|
if (!System.ClassList.Contains(no.DropDownElement.children[i], "Visible"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (firstI == -1)
|
||||||
|
firstI = i;
|
||||||
|
|
||||||
|
if (System.ClassList.Contains(no.DropDownElement.children[i], "Hover"))
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(no.DropDownElement.children[i], "Hover");
|
||||||
|
if (e.keyCode == KeyboardKeys.ArrowDown)
|
||||||
|
{
|
||||||
|
if (i < no.DropDownElement.children.length - 1)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(no.DropDownElement.children[i + 1], "Hover");
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (e.keyCode == KeyboardKeys.ArrowUp)
|
||||||
|
{
|
||||||
|
if (i > 0)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(no.DropDownElement.children[i - 1], "Hover");
|
||||||
|
found = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found)
|
||||||
|
{
|
||||||
|
if (e.keyCode == KeyboardKeys.ArrowDown)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(no.DropDownElement.children[firstI], "Hover");
|
||||||
|
}
|
||||||
|
else if (e.keyCode == KeyboardKeys.ArrowUp)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(no.DropDownElement.children[no.DropDownElement.children.length - (firstI + 1)], "Hover");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (e.keyCode == KeyboardKeys.Enter)
|
||||||
|
{
|
||||||
|
// activate the selected menu item
|
||||||
|
for (var i = 0; i < no.DropDownElement.children.length; i++)
|
||||||
|
{
|
||||||
|
if (!System.ClassList.Contains(no.DropDownElement.children[i], "Visible"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if (System.ClassList.Contains(no.DropDownElement.children[i], "Hover"))
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(no.DropDownElement.children[i], "Hover");
|
||||||
|
|
||||||
|
var a = no.DropDownElement.children[i].children[0];
|
||||||
|
if (e.ctrlKey)
|
||||||
|
{
|
||||||
|
window.open(a.href);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
window.location.href = a.href;
|
||||||
|
}
|
||||||
|
break;2
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.RefreshTimeout = null;
|
||||||
|
|
||||||
|
this.TextBoxElement.onkeyup = function(sender, e)
|
||||||
|
{
|
||||||
|
if (e.keyCode == 27) // ESC
|
||||||
|
{
|
||||||
|
sender.DropDown.Close();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (sender.RefreshTimeout != null)
|
||||||
|
{
|
||||||
|
window.clearTimeout(sender.RefreshTimeout);
|
||||||
|
}
|
||||||
|
sender.RefreshTimeout = window.setTimeout(function()
|
||||||
|
{
|
||||||
|
sender.Refresh();
|
||||||
|
}, 100);
|
||||||
|
}
|
||||||
|
}.PrependArgument(this);
|
||||||
|
|
||||||
|
for (var i = 0; i < this.DropDownElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
this.DropDownElement.childNodes[i].childNodes[0].NativeObject = this;
|
||||||
|
this.DropDownElement.childNodes[i].childNodes[0].addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
if (!this.NativeObject.IsMultiSelect())
|
||||||
|
{
|
||||||
|
this.NativeObject.GetItemByValue(this.getAttribute("data-value")).SetSelected(true);
|
||||||
|
|
||||||
|
this.NativeObject.DropDown.Close();
|
||||||
|
this.NativeObject.TextBoxElement.blur();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var item = this.NativeObject.GetItemByValue(this.getAttribute("data-value"));
|
||||||
|
item.SetSelected(!item.GetSelected());
|
||||||
|
}
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.GetSelectedItems = function()
|
||||||
|
{
|
||||||
|
this.UpdateSelectedItems();
|
||||||
|
return this.ParentElement.selectedItems;
|
||||||
|
}
|
||||||
|
this.GetItemByValue = function(value)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < this.SelectElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (this.SelectElement.childNodes[i].value == value)
|
||||||
|
{
|
||||||
|
return new TextBoxItem(this, this.SelectElement.childNodes[i].value, this.SelectElement.childNodes[i].innerHTML);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Refresh = function()
|
||||||
|
{
|
||||||
|
var ret = null;
|
||||||
|
if (this.Suggest)
|
||||||
|
{
|
||||||
|
ret = this.Suggest(this.GetText());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (ret != null)
|
||||||
|
{
|
||||||
|
var html = "";
|
||||||
|
html += this.FormatStart();
|
||||||
|
for (var i = 0; i < ret.length; i++)
|
||||||
|
{
|
||||||
|
html += this.FormatItem(ret[i], (i % 2) != 0);
|
||||||
|
}
|
||||||
|
html += this.FormatEnd();
|
||||||
|
|
||||||
|
this.DropDown.SetInnerHTML(html);
|
||||||
|
this.DropDown.Open();
|
||||||
|
}
|
||||||
|
else if (this.SuggestionURL)
|
||||||
|
{
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.parentTextbox = this;
|
||||||
|
xhr.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (xhr.readyState === 4)
|
||||||
|
{
|
||||||
|
if (xhr.status != 200)
|
||||||
|
{
|
||||||
|
console.log("TextBox: XMLHttpRequest returned response code " + xhr.status + ": " + xhr.statusText);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var html = "";
|
||||||
|
html += xhr.parentTextbox.FormatStart();
|
||||||
|
var obj = JSON.parse(xhr.responseText);
|
||||||
|
if (obj.result == "success")
|
||||||
|
{
|
||||||
|
for (var i = 0; i < obj.items.length; i++)
|
||||||
|
{
|
||||||
|
html += xhr.parentTextbox.FormatItem(obj.items[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
html += xhr.parentTextbox.FormatEnd();
|
||||||
|
|
||||||
|
xhr.parentTextbox.DropDown.SetInnerHTML(html);
|
||||||
|
xhr.parentTextbox.DropDown.Open();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.open('GET', this.SuggestionURL.replace(/\%1/g, this.GetText()), true);
|
||||||
|
xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
|
||||||
|
xhr.send(null); // No data need to send along with the request.
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// console.error("TextBox: no data retrieval functionality (SuggestionURL/Suggest) has been implemented");
|
||||||
|
var ul = this.DropDownElement;
|
||||||
|
for (var i = 0; i < ul.children.length; i++)
|
||||||
|
{
|
||||||
|
var spanText = ul.children[i].children[0].children[1];
|
||||||
|
if (System.StringMethods.Contains(spanText.innerHTML.toLowerCase(), this.GetText().toLowerCase()))
|
||||||
|
{
|
||||||
|
System.ClassList.Add(ul.childNodes[i], "Visible");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(ul.childNodes[i], "Visible");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.FormatStart = function()
|
||||||
|
{
|
||||||
|
return "<div class=\"Menu\" style=\"width: 100%;\">";
|
||||||
|
};
|
||||||
|
this.FormatItemID = function(item)
|
||||||
|
{
|
||||||
|
return item.ID;
|
||||||
|
};
|
||||||
|
this.FormatItemText = function(item)
|
||||||
|
{
|
||||||
|
return "<span class=\"Title\">" + item.Title + "</span>"
|
||||||
|
+ "<span class=\"Subtitle\">" + item.Subtitle + "</span>"
|
||||||
|
+ "<span class=\"Description\">" + item.Description + "</span>";
|
||||||
|
};
|
||||||
|
this.FormatItemTargetURL = function(item)
|
||||||
|
{
|
||||||
|
return item.TargetURL;
|
||||||
|
};
|
||||||
|
this.FormatItem = function(item, alternate)
|
||||||
|
{
|
||||||
|
var html = "<a";
|
||||||
|
if (alternate)
|
||||||
|
{
|
||||||
|
html += " class=\"Alternate\"";
|
||||||
|
}
|
||||||
|
html += " href=\"" + this.FormatItemTargetURL(item) + "\" onclick=\"" + this.ID + ".AddItem('" + this.FormatItemID(item) + "');\">" + this.FormatItemText(item) + "</a>";
|
||||||
|
return html;
|
||||||
|
};
|
||||||
|
this.FormatEnd = function()
|
||||||
|
{
|
||||||
|
return "</div>";
|
||||||
|
};
|
||||||
|
|
||||||
|
this.DropDown =
|
||||||
|
{
|
||||||
|
"NativeObject": null,
|
||||||
|
"SetInnerHTML": function(html)
|
||||||
|
{
|
||||||
|
var popup = this.NativeObject.DropDownElement;
|
||||||
|
popup.innerHTML = html;
|
||||||
|
},
|
||||||
|
"Open": function()
|
||||||
|
{
|
||||||
|
var ee = new CancelEventArgs();
|
||||||
|
this.NativeObject.EventHandlers.DropDownOpening.Execute(this.NativeObject, ee);
|
||||||
|
|
||||||
|
if (ee.Cancel) return;
|
||||||
|
|
||||||
|
var dropdown = this.NativeObject.DropDownElement;
|
||||||
|
var popup = this.NativeObject.PopupElement;
|
||||||
|
dropdown.style.minWidth = this.NativeObject.ParentElement.offsetWidth + "px";
|
||||||
|
popup.style.minWidth = this.NativeObject.ParentElement.offsetWidth + "px";
|
||||||
|
|
||||||
|
System.ClassList.Add(dropdown, "Visible");
|
||||||
|
|
||||||
|
this.NativeObject.EventHandlers.DropDownOpened.Execute(this.NativeObject, EventArgs.Empty);
|
||||||
|
},
|
||||||
|
"Close": function()
|
||||||
|
{
|
||||||
|
var popup = this.NativeObject.DropDownElement;
|
||||||
|
System.ClassList.Remove(popup, "Visible");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.DropDown.NativeObject = this;
|
||||||
|
|
||||||
|
this.Items =
|
||||||
|
{
|
||||||
|
"NativeObject": null,
|
||||||
|
"_items": new Array(),
|
||||||
|
"Add": function(item)
|
||||||
|
{
|
||||||
|
this._items.push(item);
|
||||||
|
|
||||||
|
var li = document.createElement("li");
|
||||||
|
System.ClassList.Add(li, "MenuItem");
|
||||||
|
System.ClassList.Add(li, "Command");
|
||||||
|
System.ClassList.Add(li, "Visible");
|
||||||
|
|
||||||
|
li._item = item;
|
||||||
|
|
||||||
|
var a = document.createElement("a");
|
||||||
|
var iCheckmark = document.createElement("i");
|
||||||
|
System.ClassList.Add(iCheckmark, "fa");
|
||||||
|
System.ClassList.Add(iCheckmark, "fa-check");
|
||||||
|
System.ClassList.Add(iCheckmark, "Checkmark");
|
||||||
|
a.appendChild(iCheckmark);
|
||||||
|
|
||||||
|
var spanText = document.createElement("span");
|
||||||
|
spanText.innerHTML = item.Title;
|
||||||
|
a.appendChild(spanText);
|
||||||
|
|
||||||
|
if (typeof(item.TargetURL) === "string")
|
||||||
|
{
|
||||||
|
a.href = item.TargetURL;
|
||||||
|
}
|
||||||
|
li.appendChild(a);
|
||||||
|
|
||||||
|
this.NativeObject.DropDownElement.appendChild(li);
|
||||||
|
},
|
||||||
|
"Clear": function()
|
||||||
|
{
|
||||||
|
this._items = new Array();
|
||||||
|
this.NativeObject.DropDownElement.innerHTML = "";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.Items.NativeObject = this;
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
this.Suggest = function(filter)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.SelectedItems = new Array();
|
||||||
|
|
||||||
|
this.CountItems = function()
|
||||||
|
{
|
||||||
|
var items = this.GetElement("items");
|
||||||
|
return items.childNodes.length - 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.AddItem = function(item)
|
||||||
|
{
|
||||||
|
if (this.EnableMultipleSelection)
|
||||||
|
{
|
||||||
|
var i = this.CountItems();
|
||||||
|
|
||||||
|
var html = this.GetElement("items").innerHTML;
|
||||||
|
html += "<span id=\"Textbox_" + this.ID + "_items_" + i + "\" class=\"TextboxSelectedItem\">";
|
||||||
|
html += "<span class=\"TextboxSelectedItemText\">" + this.FormatItemText(item) + "</span>";
|
||||||
|
html += "<a class=\"TextboxSelectedItemCloseButton\" onclick=\"" + this.ID + ".RemoveItemAtIndex(" + i + ");\" href=\"#\">x</a>";
|
||||||
|
html += "</span>";
|
||||||
|
this.GetElement("items").innerHTML = html;
|
||||||
|
|
||||||
|
this.GetElement("popup").style.display = "none";
|
||||||
|
|
||||||
|
this.SelectedItems.push(item);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.SelectedItems = new Array();
|
||||||
|
this.SelectedItems.push(item);
|
||||||
|
this.SetText(this.FormatItemText(item));
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.RemoveItemAtIndex = function(index)
|
||||||
|
{
|
||||||
|
var items = this.GetElement("items");
|
||||||
|
index++;
|
||||||
|
items.removeChild(items.childNodes[index]);
|
||||||
|
};
|
||||||
|
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var textBoxes = document.getElementsByClassName("TextBox");
|
||||||
|
for (var i = 0; i < textBoxes.length; i++)
|
||||||
|
{
|
||||||
|
textBoxes[i].NativeObject = new TextBox(textBoxes[i]);
|
||||||
|
if (textBoxes[i].id != "") eval("window." + textBoxes[i].id + " = document.getElementById('" + textBoxes[i].id + "').NativeObject;");
|
||||||
|
}
|
||||||
|
});
|
||||||
80
lib/phast/client/scripts/controls/ToggleSwitch.js
Normal file
80
lib/phast/client/scripts/controls/ToggleSwitch.js
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
function ToggleSwitch(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
parentElement.addEventListener("click", function(e)
|
||||||
|
{
|
||||||
|
if (e.which == 1)
|
||||||
|
{
|
||||||
|
if (!this.hasAttribute("disabled"))
|
||||||
|
{
|
||||||
|
var changed = System.ClassList.Toggle(this, "Checked");
|
||||||
|
if (changed) this.NativeObject.on_Changed();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
parentElement.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.get_Enabled = function()
|
||||||
|
{
|
||||||
|
return !(this.ParentElement.hasAttribute("disabled"));
|
||||||
|
};
|
||||||
|
this.set_Enabled = function(value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
this.ParentElement.removeAttribute("disabled");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("disabled", "disabled");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.EventHandlers =
|
||||||
|
{
|
||||||
|
"Changed": new System.EventHandler()
|
||||||
|
};
|
||||||
|
|
||||||
|
this.on_Changed = function()
|
||||||
|
{
|
||||||
|
this.EventHandlers.Changed.Execute(this, null);
|
||||||
|
};
|
||||||
|
|
||||||
|
this.set_Checked = function(value)
|
||||||
|
{
|
||||||
|
if (this.get_Checked() == value) return false;
|
||||||
|
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.ParentElement, "Checked");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.ParentElement, "Checked");
|
||||||
|
}
|
||||||
|
this.on_Changed();
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
this.get_Checked = function()
|
||||||
|
{
|
||||||
|
return System.ClassList.Contains(this.ParentElement, "Checked");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
window.addEventListener("load", function ()
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("ToggleSwitch");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new ToggleSwitch(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
149
lib/phast/client/scripts/controls/ToolTip.js
Normal file
149
lib/phast/client/scripts/controls/ToolTip.js
Normal file
@ -0,0 +1,149 @@
|
|||||||
|
window.addEventListener('load', function (e)
|
||||||
|
{
|
||||||
|
var tooltips = document.getElementsByTagName("*");
|
||||||
|
for (var i = 0; i < tooltips.length; i++)
|
||||||
|
{
|
||||||
|
(function(tt)
|
||||||
|
{
|
||||||
|
if (typeof(tt.attributes["data-tooltip-content"]) === 'undefined' && typeof(tt.attributes["data-tooltip-title"]) === 'undefined') return;
|
||||||
|
|
||||||
|
var delay = 1000;
|
||||||
|
if (tt.attributes["data-tooltip-delay"])
|
||||||
|
{
|
||||||
|
delay = tt.attributes["data-tooltip-delay"];
|
||||||
|
}
|
||||||
|
|
||||||
|
tt.tooltipTimer = null;
|
||||||
|
tt.onmousemove = function(e)
|
||||||
|
{
|
||||||
|
tt.mouseX = e.clientX;
|
||||||
|
tt.mouseY = e.clientY;
|
||||||
|
};
|
||||||
|
tt.onmouseover = function(e)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(tt, "Disabled")) return;
|
||||||
|
|
||||||
|
if (ToolTip.Timer != null) window.clearTimeout(ToolTip.Timer);
|
||||||
|
tt.tooltipTimer = window.setTimeout(function(tt)
|
||||||
|
{
|
||||||
|
var x = tt.mouseX;
|
||||||
|
var y = tt.mouseY;
|
||||||
|
|
||||||
|
var tooltipTitle = (tt.attributes["data-tooltip-title"] != null ? tt.attributes["data-tooltip-title"].value : "");
|
||||||
|
var tooltipContent = (tt.attributes["data-tooltip-content"] != null ? tt.attributes["data-tooltip-content"].value : "");
|
||||||
|
var tooltipContextHelpURL = (tt.attributes["data-tooltip-contexthelpurl"] != null ? tt.attributes["data-tooltip-contexthelpurl"].value : "");
|
||||||
|
var tooltipContextHelpTargetName = (tt.attributes["data-tooltip-contexthelptarget"] != null ? tt.attributes["data-tooltip-contexthelptarget"].value : "_blank");
|
||||||
|
|
||||||
|
if (tooltipTitle == "" || tooltipContent == "") return;
|
||||||
|
|
||||||
|
ToolTip.Show(tooltipContent, tooltipTitle, x, y, tooltipContextHelpURL, tooltipContextHelpTargetName);
|
||||||
|
}, delay, tt);
|
||||||
|
};
|
||||||
|
tt.onmouseout = function(e)
|
||||||
|
{
|
||||||
|
ToolTip.Hide();
|
||||||
|
};
|
||||||
|
})(tooltips[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
function ToolTip()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolTip.CurrentContextHelpURL = "";
|
||||||
|
ToolTip.CurrentContextHelpTargetName = null;
|
||||||
|
|
||||||
|
ToolTip.ParentElement = null;
|
||||||
|
ToolTip.Timer = null;
|
||||||
|
|
||||||
|
ToolTip.Show = function(content, title, x, y, contextHelpURL, contextHelpTargetName)
|
||||||
|
{
|
||||||
|
if (ToolTip.ParentElement == null)
|
||||||
|
{
|
||||||
|
ToolTip.ParentElement = document.createElement("div");
|
||||||
|
ToolTip.ParentElement.className = "ToolTip";
|
||||||
|
|
||||||
|
var ttTitleElement = document.createElement("div");
|
||||||
|
ttTitleElement.className = "Title";
|
||||||
|
ToolTip.ParentElement.appendChild(ttTitleElement);
|
||||||
|
|
||||||
|
var ttContentElement = document.createElement("div");
|
||||||
|
ttContentElement.className = "Content";
|
||||||
|
ToolTip.ParentElement.appendChild(ttContentElement);
|
||||||
|
|
||||||
|
var ttContextHelpElement = document.createElement("div");
|
||||||
|
ttContextHelpElement.className = "ContextHelp";
|
||||||
|
ToolTip.ParentElement.appendChild(ttContextHelpElement);
|
||||||
|
|
||||||
|
document.body.appendChild(ToolTip.ParentElement);
|
||||||
|
}
|
||||||
|
|
||||||
|
var tooltipTitleElement = ToolTip.ParentElement.childNodes[0];
|
||||||
|
var tooltipContentElement = ToolTip.ParentElement.childNodes[1];
|
||||||
|
var tooltipContextHelpElement = ToolTip.ParentElement.childNodes[2];
|
||||||
|
|
||||||
|
if (title != "")
|
||||||
|
{
|
||||||
|
tooltipTitleElement.innerHTML = title;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tooltipTitleElement.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (content != "")
|
||||||
|
{
|
||||||
|
tooltipContentElement.innerHTML = content;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tooltipContentElement.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contextHelpURL)
|
||||||
|
{
|
||||||
|
tooltipContextHelpElement.style.display = "block";
|
||||||
|
ToolTip.CurrentContextHelpURL = contextHelpURL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
tooltipContextHelpElement.style.display = "none";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (contextHelpTargetName)
|
||||||
|
{
|
||||||
|
ToolTip.CurrentContextHelpTargetName = contextHelpTargetName;
|
||||||
|
}
|
||||||
|
|
||||||
|
ToolTip.ParentElement.style.left = x + "px";
|
||||||
|
ToolTip.ParentElement.style.top = (y + 16) + "px";
|
||||||
|
|
||||||
|
System.ClassList.Add(ToolTip.ParentElement, "Visible");
|
||||||
|
};
|
||||||
|
ToolTip.Hide = function()
|
||||||
|
{
|
||||||
|
ToolTip.CurrentContextHelpURL = "";
|
||||||
|
ToolTip.CurrentContextHelpTargetName = "_blank";
|
||||||
|
if (ToolTip.Timer != null) window.clearTimeout(ToolTip.Timer);
|
||||||
|
|
||||||
|
if (ToolTip.ParentElement == null) return;
|
||||||
|
System.ClassList.Remove(ToolTip.ParentElement, "Visible");
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
window.addEventListener("keydown", function (e)
|
||||||
|
{
|
||||||
|
switch (e.keyCode)
|
||||||
|
{
|
||||||
|
case KeyboardKeys.F1: /* F1 */
|
||||||
|
{
|
||||||
|
if (ToolTip.CurrentContextHelpURL != "")
|
||||||
|
{
|
||||||
|
var path = System.ExpandRelativePath(ToolTip.CurrentContextHelpURL);
|
||||||
|
window.open(path, ToolTip.CurrentContextHelpTargetName);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
283
lib/phast/client/scripts/controls/TrackBar.js
Normal file
283
lib/phast/client/scripts/controls/TrackBar.js
Normal file
@ -0,0 +1,283 @@
|
|||||||
|
function TrackBarOrientation(value)
|
||||||
|
{
|
||||||
|
this._value = value;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* The TrackBar is displayed horizontally.
|
||||||
|
*/
|
||||||
|
TrackBarOrientation.Horizontal = new TrackBarOrientation(1);
|
||||||
|
/**
|
||||||
|
* The TrackBar is displayed vertically.
|
||||||
|
*/
|
||||||
|
TrackBarOrientation.Vertical = new TrackBarOrientation(2);
|
||||||
|
|
||||||
|
function TrackBar(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.TrackElement = this.ParentElement.childNodes[0];
|
||||||
|
this.QuantityElement = this.TrackElement.childNodes[0];
|
||||||
|
this.ThumbElement = this.TrackElement.childNodes[1];
|
||||||
|
this.ThumbTextElement = this.ThumbElement.childNodes[0];
|
||||||
|
|
||||||
|
this.EventHandlers =
|
||||||
|
{
|
||||||
|
"Change": new System.EventHandler()
|
||||||
|
};
|
||||||
|
|
||||||
|
this.OnMouseWheel = function(e)
|
||||||
|
{
|
||||||
|
if (e.detail > 0)
|
||||||
|
{
|
||||||
|
// scrolling down
|
||||||
|
var value = this.NativeObject.get_CurrentValue() - this.NativeObject.get_ScrollInterval();
|
||||||
|
if (value < 0) value = 0;
|
||||||
|
if (value > this.NativeObject.get_MaximumValue()) value = this.NativeObject.get_MaximumValue();
|
||||||
|
|
||||||
|
this.NativeObject.set_CurrentValue(this.NativeObject.get_CurrentValue() - this.NativeObject.get_ScrollInterval());
|
||||||
|
}
|
||||||
|
else if (e.detail < 0)
|
||||||
|
{
|
||||||
|
// scrolling up
|
||||||
|
var value = this.NativeObject.get_CurrentValue() + this.NativeObject.get_ScrollInterval();
|
||||||
|
if (value < 0) value = 0;
|
||||||
|
if (value > this.NativeObject.get_MaximumValue()) value = this.NativeObject.get_MaximumValue();
|
||||||
|
|
||||||
|
this.NativeObject.set_CurrentValue(value);
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ParentElement.addEventListener("mousewheel", this.OnMouseWheel);
|
||||||
|
this.ParentElement.addEventListener("DOMMouseScroll", this.OnMouseWheel);
|
||||||
|
|
||||||
|
this.mvarScrollInterval = 5;
|
||||||
|
this.get_ScrollInterval = function()
|
||||||
|
{
|
||||||
|
if (this.ParentElement.hasAttribute("data-scroll-interval"))
|
||||||
|
{
|
||||||
|
return this.ParentElement.getAttribute("data-scroll-interval");
|
||||||
|
}
|
||||||
|
return this.mvarScrollInterval;
|
||||||
|
};
|
||||||
|
this.set_ScrollInterval = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("data-scroll-interval", value);
|
||||||
|
this.mvarScrollInterval = value;
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get_Orientation = function()
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(this.ParentElement, "Vertical"))
|
||||||
|
{
|
||||||
|
return TrackBarOrientation.Vertical;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return TrackBarOrientation.Horizontal;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.set_Orientation = function(value)
|
||||||
|
{
|
||||||
|
switch (value)
|
||||||
|
{
|
||||||
|
case TrackBarOrientation.Horizontal:
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.ParentElement, "Vertical");
|
||||||
|
System.ClassList.Add(this.ParentElement, "Horizontal");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case TrackBarOrientation.Vertical:
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.ParentElement, "Horizontal");
|
||||||
|
System.ClassList.Add(this.ParentElement, "Vertical");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
default:
|
||||||
|
{
|
||||||
|
console.log("Invalid value '" + value + "' for property 'Orientation'");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.get_MinimumValue = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.getAttribute("data-minimum-value");
|
||||||
|
};
|
||||||
|
this.set_MinimumValue = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("data-minimum-value", value);
|
||||||
|
};
|
||||||
|
this.get_MaximumValue = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.getAttribute("data-maximum-value");
|
||||||
|
};
|
||||||
|
this.set_MaximumValue = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.setAttribute("data-maximum-value", value);
|
||||||
|
};
|
||||||
|
this.get_CurrentValue = function()
|
||||||
|
{
|
||||||
|
return parseInt(this.ParentElement.getAttribute("data-current-value"));
|
||||||
|
};
|
||||||
|
this.set_CurrentValue = function(value)
|
||||||
|
{
|
||||||
|
value = parseInt(value);
|
||||||
|
|
||||||
|
var changed = (this.get_CurrentValue() != value);
|
||||||
|
if (!changed) return value;
|
||||||
|
|
||||||
|
this.ParentElement.setAttribute("data-current-value", value);
|
||||||
|
|
||||||
|
var decimalPos = ((value - this.get_MinimumValue()) / (this.get_MaximumValue() - this.get_MinimumValue()));
|
||||||
|
var intPos = decimalPos * 100;
|
||||||
|
var percentPos = intPos + "%";
|
||||||
|
|
||||||
|
if (this.get_Orientation() == TrackBarOrientation.Vertical)
|
||||||
|
{
|
||||||
|
intPos = 100 - intPos;
|
||||||
|
this.ThumbElement.style.top = intPos + "%";
|
||||||
|
this.QuantityElement.style.top = intPos + "%";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.ThumbElement.style.left = percentPos;
|
||||||
|
this.QuantityElement.style.width = percentPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.ParentElement.setAttribute("data-tooltip-content", this.ParentElement.getAttribute("data-current-value"));
|
||||||
|
this.ThumbTextElement.innerHTML = value;
|
||||||
|
|
||||||
|
this.EventHandlers.Change.Execute(this, null);
|
||||||
|
return value;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ParentElement.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.TrackElement.NativeObject = this;
|
||||||
|
|
||||||
|
// When the user clicks the primary mouse button on the track (large change)
|
||||||
|
this.TrackElement.addEventListener("mousedown", function(ee)
|
||||||
|
{
|
||||||
|
var e = MouseEventArgs.FromNativeEventArgs(ee);
|
||||||
|
if (e.Button == MouseButtons.Primary)
|
||||||
|
{
|
||||||
|
var elementSize = this.NativeObject.ParentElement.clientWidth;
|
||||||
|
var currentPos = e.X - this.NativeObject.TrackElement.offsetLeft;
|
||||||
|
if (this.NativeObject.get_Orientation() == TrackBarOrientation.Vertical)
|
||||||
|
{
|
||||||
|
elementSize = this.NativeObject.ParentElement.clientHeight;
|
||||||
|
currentPos = e.Y - this.NativeObject.TrackElement.offsetTop;
|
||||||
|
}
|
||||||
|
|
||||||
|
var decimalPos = (currentPos / elementSize);
|
||||||
|
if (decimalPos < 0) decimalPos = 0;
|
||||||
|
if (decimalPos > 1) decimalPos = 1;
|
||||||
|
|
||||||
|
var intPos = decimalPos * 100;
|
||||||
|
var percentPos = (intPos + "%");
|
||||||
|
|
||||||
|
if (this.NativeObject.get_Orientation() == TrackBarOrientation.Vertical)
|
||||||
|
{
|
||||||
|
decimalPos = 1 - decimalPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.NativeObject.set_CurrentValue(parseInt(this.NativeObject.get_MinimumValue()) + (decimalPos * (this.NativeObject.get_MaximumValue() - this.NativeObject.get_MinimumValue())));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.BeginDrag = function(e)
|
||||||
|
{
|
||||||
|
TrackBar._draggingObject = this;
|
||||||
|
};
|
||||||
|
this.ContinueDrag = function(e)
|
||||||
|
{
|
||||||
|
var elementSize = this.ParentElement.clientWidth;
|
||||||
|
var currentPos = e.X - this.ParentElement.offsetLeft;
|
||||||
|
if (this.ParentElement.getBoundingClientRect)
|
||||||
|
{
|
||||||
|
currentPos = e.X - this.ParentElement.getBoundingClientRect().x;
|
||||||
|
}
|
||||||
|
if (this.get_Orientation() == TrackBarOrientation.Vertical)
|
||||||
|
{
|
||||||
|
elementSize = this.ParentElement.clientHeight;
|
||||||
|
currentPos = e.Y - this.ParentElement.offsetTop;
|
||||||
|
if (this.ParentElement.getBoundingClientRect)
|
||||||
|
{
|
||||||
|
currentPos = e.Y - this.ParentElement.getBoundingClientRect().y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
var decimalPos = (currentPos / elementSize);
|
||||||
|
if (decimalPos < 0) decimalPos = 0;
|
||||||
|
if (decimalPos > 1) decimalPos = 1;
|
||||||
|
|
||||||
|
var intPos = decimalPos * 100;
|
||||||
|
var percentPos = (intPos + "%");
|
||||||
|
|
||||||
|
if (this.get_Orientation() == TrackBarOrientation.Vertical)
|
||||||
|
{
|
||||||
|
decimalPos = 1 - decimalPos;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.set_CurrentValue(parseInt(this.get_MinimumValue()) + (decimalPos * (this.get_MaximumValue() - this.get_MinimumValue())));
|
||||||
|
};
|
||||||
|
this.EndDrag = function()
|
||||||
|
{
|
||||||
|
TrackBar._draggingObject = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.ThumbElement.NativeObject = this;
|
||||||
|
this.ThumbElement.addEventListener("mousedown", function(ee)
|
||||||
|
{
|
||||||
|
var e = MouseEventArgs.FromNativeEventArgs(ee);
|
||||||
|
if (e.Button == MouseButtons.Primary)
|
||||||
|
{
|
||||||
|
this.NativeObject.BeginDrag(e);
|
||||||
|
}
|
||||||
|
ee.preventDefault();
|
||||||
|
ee.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
window.addEventListener("mousemove", function(e)
|
||||||
|
{
|
||||||
|
if (TrackBar._draggingObject != null)
|
||||||
|
{
|
||||||
|
TrackBar._draggingObject.ContinueDrag(MouseEventArgs.FromNativeEventArgs(e));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("mouseup", function(e)
|
||||||
|
{
|
||||||
|
if (TrackBar._draggingObject != null)
|
||||||
|
{
|
||||||
|
TrackBar._draggingObject.EndDrag();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
this.ParentElement.setAttribute("data-tooltip-content", this.ParentElement.getAttribute("data-current-value"));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The currently-dragging TrackBar object.
|
||||||
|
* @var TrackBar
|
||||||
|
*/
|
||||||
|
TrackBar._draggingObject = null;
|
||||||
|
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("TrackBar");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new TrackBar(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
585
lib/phast/client/scripts/controls/Window.js
Normal file
585
lib/phast/client/scripts/controls/Window.js
Normal file
@ -0,0 +1,585 @@
|
|||||||
|
/**
|
||||||
|
* Creates a Window.
|
||||||
|
* @param parentElement Element The parent element with which to associate the Window.
|
||||||
|
*/
|
||||||
|
function Window(parentElement)
|
||||||
|
{
|
||||||
|
if (!parentElement)
|
||||||
|
{
|
||||||
|
parentElement = document.createElement("div");
|
||||||
|
parentElement.className = "Window";
|
||||||
|
|
||||||
|
var titleBar = document.createElement("div");
|
||||||
|
titleBar.className = "Header";
|
||||||
|
|
||||||
|
var title = document.createElement("span");
|
||||||
|
title.className = "Title";
|
||||||
|
titleBar.appendChild(title);
|
||||||
|
|
||||||
|
parentElement.appendChild(titleBar);
|
||||||
|
|
||||||
|
var content = document.createElement("div");
|
||||||
|
content.className = "Content";
|
||||||
|
parentElement.appendChild(content);
|
||||||
|
|
||||||
|
var footer = document.createElement("div");
|
||||||
|
footer.className = "Buttons";
|
||||||
|
footer.NativeObject = this;
|
||||||
|
footer.style.display = "none";
|
||||||
|
parentElement.appendChild(footer);
|
||||||
|
|
||||||
|
document.body.appendChild(parentElement);
|
||||||
|
}
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
|
||||||
|
this.mvarContentURL = null;
|
||||||
|
/**
|
||||||
|
* Gets the content URL used for dynamically-loading content via AJAX.
|
||||||
|
*/
|
||||||
|
this.GetContentURL = function()
|
||||||
|
{
|
||||||
|
return this.mvarContentURL;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Sets the content URL used for dynamically-loading content via AJAX.
|
||||||
|
* @param value string The URL from which to load content when the Window is opened.
|
||||||
|
*/
|
||||||
|
this.SetContentURL = function(value)
|
||||||
|
{
|
||||||
|
this.mvarContentURL = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
// Set the content URL automatically if we specify it in the attribute
|
||||||
|
if (parentElement.hasAttribute("data-content-url"))
|
||||||
|
{
|
||||||
|
this.SetContentURL(parentElement.getAttribute("data-content-url"));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.GetLoading = function()
|
||||||
|
{
|
||||||
|
return System.ClassList.Contains(this.ParentElement, "Loading");
|
||||||
|
};
|
||||||
|
this.SetLoading = function(value)
|
||||||
|
{
|
||||||
|
if (value)
|
||||||
|
{
|
||||||
|
return System.ClassList.Add(this.ParentElement, "Loading");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return System.ClassList.Remove(this.ParentElement, "Loading");
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.GetLoadingText = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.childNodes[1].childNodes[1].childNodes[0].childNodes[1].innerHTML;
|
||||||
|
};
|
||||||
|
this.SetLoadingText = function(value)
|
||||||
|
{
|
||||||
|
this.ParentElement.childNodes[1].childNodes[1].childNodes[0].childNodes[1].innerHTML = value;
|
||||||
|
};
|
||||||
|
|
||||||
|
this.Opened = new Callback(this);
|
||||||
|
this.Closed = new Callback(this);
|
||||||
|
|
||||||
|
this.DefaultHorizontalAlignment = HorizontalAlignment.Center;
|
||||||
|
this.DefaultVerticalAlignment = VerticalAlignment.Middle;
|
||||||
|
|
||||||
|
var TitleBar = parentElement.childNodes[0];
|
||||||
|
TitleBar.Parent = this;
|
||||||
|
TitleBar.addEventListener("mousedown", function(e)
|
||||||
|
{
|
||||||
|
Window.BeginDrag(this.Parent, e);
|
||||||
|
e.preventDefault();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
TitleBar.addEventListener("contextmenu", function(e)
|
||||||
|
{
|
||||||
|
var menu = new ContextMenu();
|
||||||
|
menu.Items =
|
||||||
|
[
|
||||||
|
new MenuItemCommand("mnuWindowClose", "Close", function(e1)
|
||||||
|
{
|
||||||
|
TitleBar.Parent.Hide();
|
||||||
|
})
|
||||||
|
];
|
||||||
|
menu.Show(e.clientX, e.clientY);
|
||||||
|
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
|
||||||
|
this.GetContentElement = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.childNodes[1];
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Gets the content of this Window
|
||||||
|
*/
|
||||||
|
this.GetContent = function()
|
||||||
|
{
|
||||||
|
return this.GetContentElement().innerHTML;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Sets the content of this Window
|
||||||
|
* @param value string The content to insert into this Window
|
||||||
|
*/
|
||||||
|
this.SetContent = function(value)
|
||||||
|
{
|
||||||
|
this.GetContentElement().innerHTML = value;
|
||||||
|
};
|
||||||
|
this.GetFooterElement = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.childNodes[2];
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Gets the footer area content (e.g. buttons, etc.) of this Window
|
||||||
|
*/
|
||||||
|
this.GetFooter = function()
|
||||||
|
{
|
||||||
|
return this.GetFooterElement().innerHTML;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Sets the footer area content (e.g. buttons, etc.) of this Window
|
||||||
|
* @param value string The footer area content (e.g. buttons, etc.) to insert into this Window
|
||||||
|
*/
|
||||||
|
this.SetFooter = function(value)
|
||||||
|
{
|
||||||
|
var footer = this.GetFooterElement();
|
||||||
|
footer.innerHTML = value;
|
||||||
|
if (value == null)
|
||||||
|
{
|
||||||
|
footer.style.display = "none";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
footer.style.display = "block";
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the client width, in pixels, of this Window.
|
||||||
|
*/
|
||||||
|
this.GetWidth = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.clientWidth;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Gets the client height, in pixels, of this Window.
|
||||||
|
*/
|
||||||
|
this.GetHeight = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.clientHeight;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the title of this Window.
|
||||||
|
*/
|
||||||
|
this.GetTitle = function()
|
||||||
|
{
|
||||||
|
return this.ParentElement.childNodes[0].childNodes[0].innerHTML;
|
||||||
|
};
|
||||||
|
/**
|
||||||
|
* Sets the title of this Window.
|
||||||
|
* @param title string The title to set
|
||||||
|
*/
|
||||||
|
this.SetTitle = function(title)
|
||||||
|
{
|
||||||
|
this.ParentElement.childNodes[0].childNodes[0].innerHTML = title;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the horizontal alignment (left, center, right) of this Window.
|
||||||
|
* @param alignment HorizontalAlignment One of these: HorizontalAlignment.Left, HorizontalAlignment.Center, or HorizontalAlignment.Right.
|
||||||
|
*/
|
||||||
|
this.SetHorizontalAlignment = function(alignment)
|
||||||
|
{
|
||||||
|
var Window = this.ParentElement;
|
||||||
|
switch(alignment)
|
||||||
|
{
|
||||||
|
case HorizontalAlignment.Left:
|
||||||
|
{
|
||||||
|
Window.style.left = "16px";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case HorizontalAlignment.Center:
|
||||||
|
{
|
||||||
|
Window.style.left = ((parseInt(window.GetWidth()) - parseInt(this.GetWidth())) / 2) + "px";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case HorizontalAlignment.Right:
|
||||||
|
{
|
||||||
|
Window.style.left = (parseInt(window.GetWidth()) - parseInt(this.GetWidth()) - 16) + "px";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.SetVerticalAlignment = function(alignment)
|
||||||
|
{
|
||||||
|
var Window = this.ParentElement;
|
||||||
|
switch(alignment)
|
||||||
|
{
|
||||||
|
case VerticalAlignment.Top:
|
||||||
|
{
|
||||||
|
Window.style.top = "16px";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case VerticalAlignment.Middle:
|
||||||
|
{
|
||||||
|
Window.style.top = ((parseInt(window.GetHeight()) - parseInt(this.GetHeight())) / 2) + "px";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case VerticalAlignment.Bottom:
|
||||||
|
{
|
||||||
|
Window.style.top = (parseInt(window.GetHeight() - parseInt(this.GetHeight())) - 16) + "px";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
this.SetTop = function(y)
|
||||||
|
{
|
||||||
|
var Window = this.ParentElement;
|
||||||
|
Window.style.top = y + "px";
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Presents this Window to the user.
|
||||||
|
* @param parent Element The Element to assign as the owner of this Window, or null to keep current owner
|
||||||
|
*/
|
||||||
|
this.Show = function(parent)
|
||||||
|
{
|
||||||
|
if (parent)
|
||||||
|
{
|
||||||
|
this.ParentElement.parentNode.removeChild(this.ParentElement);
|
||||||
|
parent.appendChild(this.ParentElement);
|
||||||
|
|
||||||
|
// NOTE: parent must have its style not set to the default for this to work
|
||||||
|
if (!(parent.style.position == "relative" || parent.style.position == "absolute"))
|
||||||
|
{
|
||||||
|
parent.style.position = "relative";
|
||||||
|
}
|
||||||
|
this.ParentElement.style.position = "absolute";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.ParentElement.parentNode.removeChild(this.ParentElement);
|
||||||
|
document.body.appendChild(this.ParentElement);
|
||||||
|
this.ParentElement.style.position = "fixed";
|
||||||
|
}
|
||||||
|
|
||||||
|
var Window = this.ParentElement;
|
||||||
|
Window.className = "Window Visible";
|
||||||
|
|
||||||
|
if (this.mvarContentURL != null)
|
||||||
|
{
|
||||||
|
this.SetContent("<div class=\"Throbber\"> </div>");
|
||||||
|
|
||||||
|
// TODO: execute AJAX request to load content
|
||||||
|
var xhr = new XMLHttpRequest();
|
||||||
|
xhr.ParentWindow = this;
|
||||||
|
xhr.onreadystatechange = function()
|
||||||
|
{
|
||||||
|
if (this.readyState == 4)
|
||||||
|
{
|
||||||
|
if (this.status == 200)
|
||||||
|
{
|
||||||
|
this.ParentWindow.SetContent(this.responseText);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
this.ParentWindow.SetContent("<div class=\"Alert Failure\"><div class=\"Title\">Could not load window content</div><div class=\"Content\">Check your Internet connection and try again</div></div>");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
xhr.open("GET", System.ExpandRelativePath(this.mvarContentURL), true);
|
||||||
|
xhr.setRequestHeader("X-Requested-With", "XMLHttpRequest");
|
||||||
|
xhr.send(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.Opened.Execute(CallbackArgument.Empty);
|
||||||
|
};
|
||||||
|
this.ShowDialog = function()
|
||||||
|
{
|
||||||
|
Window.DialogCount++;
|
||||||
|
|
||||||
|
if (Window.ModalBackgroundElement == null)
|
||||||
|
{
|
||||||
|
Window.ModalBackgroundElement = document.createElement("div");
|
||||||
|
Window.ModalBackgroundElement.className = "WindowModalBackground";
|
||||||
|
document.body.appendChild(Window.ModalBackgroundElement);
|
||||||
|
}
|
||||||
|
Window.ModalBackgroundElement.style.display = "block";
|
||||||
|
Window.ModalBackgroundElement.style.zIndex = (100 + Window.DialogCount);
|
||||||
|
|
||||||
|
var WindowDOMObject = this.ParentElement;
|
||||||
|
WindowDOMObject.className = "Window Visible";
|
||||||
|
|
||||||
|
WindowDOMObject.style.zIndex = (100 + Window.DialogCount + 1);
|
||||||
|
|
||||||
|
this.SetHorizontalAlignment(this.DefaultHorizontalAlignment);
|
||||||
|
this.SetVerticalAlignment(this.DefaultVerticalAlignment);
|
||||||
|
this.Opened.Execute(CallbackArgument.Empty);
|
||||||
|
};
|
||||||
|
this.Hide = function()
|
||||||
|
{
|
||||||
|
var WindowDOMObject = this.ParentElement;
|
||||||
|
WindowDOMObject.className = "Window";
|
||||||
|
this.Closed.Execute(CallbackArgument.Empty);
|
||||||
|
|
||||||
|
Window.DialogCount--;
|
||||||
|
|
||||||
|
if (Window.ModalBackgroundElement != null)
|
||||||
|
{
|
||||||
|
Window.ModalBackgroundElement.style.zIndex = (100 + Window.DialogCount);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Window.DialogCount == 0)
|
||||||
|
{
|
||||||
|
if (Window.ModalBackgroundElement != null)
|
||||||
|
{
|
||||||
|
Window.ModalBackgroundElement.parentNode.removeChild(Window.ModalBackgroundElement);
|
||||||
|
Window.ModalBackgroundElement = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.ParentElement.id != "") eval("window." + this.ParentElement.id + " = this;");
|
||||||
|
};
|
||||||
|
Window.ModalBackgroundElement = null;
|
||||||
|
Window.DialogCount = 0;
|
||||||
|
Window.BeginDrag = function(sender, e)
|
||||||
|
{
|
||||||
|
Window.DragWindow = sender;
|
||||||
|
Window.CursorOriginalX = e.clientX;
|
||||||
|
Window.CursorOriginalY = e.clientY;
|
||||||
|
|
||||||
|
var obj = Window.DragWindow.ParentElement;
|
||||||
|
Window.DragWindowOriginalX = obj.style.left.substring(0, obj.style.left.length - 2);
|
||||||
|
Window.DragWindowOriginalY = obj.style.top.substring(0, obj.style.top.length - 2);
|
||||||
|
};
|
||||||
|
Window.ContinueDrag = function(e)
|
||||||
|
{
|
||||||
|
if (!Window.DragWindow) return;
|
||||||
|
|
||||||
|
var obj = Window.DragWindow.ParentElement;
|
||||||
|
|
||||||
|
var ix = parseInt(Window.DragWindowOriginalX), iy = parseInt(Window.DragWindowOriginalY);
|
||||||
|
if (ix.toString() == "NaN") ix = 0;
|
||||||
|
if (iy.toString() == "NaN") iy = 0;
|
||||||
|
|
||||||
|
obj.style.left = (ix + (e.clientX - Window.CursorOriginalX)) + "px";
|
||||||
|
obj.style.top = (iy + (e.clientY - Window.CursorOriginalY)) + "px";
|
||||||
|
};
|
||||||
|
Window.EndDrag = function()
|
||||||
|
{
|
||||||
|
Window.DragWindow = null;
|
||||||
|
};
|
||||||
|
|
||||||
|
Window.ShowDialog = function(message, title, buttons)
|
||||||
|
{
|
||||||
|
var wnd = new Window();
|
||||||
|
wnd.SetTitle(title);
|
||||||
|
wnd.SetContent(message);
|
||||||
|
wnd.ShowDialog();
|
||||||
|
};
|
||||||
|
|
||||||
|
window.addEventListener("mousemove", function(e)
|
||||||
|
{
|
||||||
|
if (Window.DragWindow)
|
||||||
|
{
|
||||||
|
Window.ContinueDrag(e);
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("mouseup", function(e)
|
||||||
|
{
|
||||||
|
if (Window.DragWindow)
|
||||||
|
{
|
||||||
|
Window.EndDrag();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
window.addEventListener("load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("Window");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new Window(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
//The awesomely cool, really slick jack-of-all-trades ShowDialog function to generate pretty
|
||||||
|
//JavaScript asynchronous dialogs =(^.^)=
|
||||||
|
/**
|
||||||
|
* Shows a JavaScript dialog with the specified parameters.
|
||||||
|
* @param content string The HTML to display in the window's content area.
|
||||||
|
* @param title string The HTML to display in the window's title bar.
|
||||||
|
* @param buttons array Array of button definitions.
|
||||||
|
*
|
||||||
|
* The following properties are currently supported for button definitions:
|
||||||
|
* Enabled, Text, ClassName (optional), OnClientClick
|
||||||
|
*/
|
||||||
|
Window.ShowDialog = function (content, title, buttons, styles, iconName, className)
|
||||||
|
{
|
||||||
|
if (!buttons || buttons === null) buttons =
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"Enabled": true,
|
||||||
|
"Text": "OK",
|
||||||
|
"ClassName": "Primary",
|
||||||
|
"OnClientClick": function (sender, e)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
];
|
||||||
|
if (!styles || styles === null) styles = [];
|
||||||
|
|
||||||
|
content = content.replace(/\r\n/g, "<br />");
|
||||||
|
content = content.replace(/\n/g, "<br />");
|
||||||
|
content = content.replace(/\\r\\n/g, "<br />");
|
||||||
|
content = content.replace(/\\n/g, "<br />");
|
||||||
|
|
||||||
|
var divWindow = document.createElement("div");
|
||||||
|
|
||||||
|
System.ClassList.Add(divWindow, "Window");
|
||||||
|
if (className)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(divWindow, className);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var i = 0; i < styles.length; i++)
|
||||||
|
{
|
||||||
|
divWindow.style.setProperty(styles[i].name, styles[i].value);
|
||||||
|
}
|
||||||
|
|
||||||
|
var divHeader = document.createElement("div");
|
||||||
|
divHeader.className = "Header";
|
||||||
|
|
||||||
|
var spanHeaderTitle = document.createElement("span");
|
||||||
|
spanHeaderTitle.className = "Title";
|
||||||
|
spanHeaderTitle.innerHTML = title;
|
||||||
|
divHeader.appendChild(spanHeaderTitle);
|
||||||
|
|
||||||
|
var divHeaderControlBox = document.createElement("div");
|
||||||
|
divHeaderControlBox.className = "ControlBox";
|
||||||
|
var aButtonClose = document.createElement("a");
|
||||||
|
aButtonClose.className = "Close";
|
||||||
|
aButtonClose.href = "#";
|
||||||
|
aButtonClose.windowElement = divWindow;
|
||||||
|
|
||||||
|
var aButtonCloseText = document.createElement("span");
|
||||||
|
aButtonCloseText.innerHTML = "×";
|
||||||
|
aButtonClose.appendChild(aButtonCloseText);
|
||||||
|
divHeaderControlBox.appendChild(aButtonClose);
|
||||||
|
divHeader.appendChild(divHeaderControlBox);
|
||||||
|
|
||||||
|
divWindow.appendChild(divHeader);
|
||||||
|
|
||||||
|
var divContent = document.createElement("div");
|
||||||
|
divContent.className = "Content";
|
||||||
|
|
||||||
|
var divContentContent = document.createElement("div");
|
||||||
|
divContentContent.className = "Content";
|
||||||
|
|
||||||
|
if (iconName && iconName !== null)
|
||||||
|
{
|
||||||
|
var divIcon = document.createElement("div");
|
||||||
|
divIcon.className = "Icon";
|
||||||
|
|
||||||
|
var divStockIcon = document.createElement("div");
|
||||||
|
divStockIcon.className = "StockIcon si-Large si-" + iconName;
|
||||||
|
|
||||||
|
divIcon.appendChild(divStockIcon);
|
||||||
|
|
||||||
|
divContentContent.appendChild(divIcon);
|
||||||
|
}
|
||||||
|
|
||||||
|
divContentContent.innerHTML = content;
|
||||||
|
|
||||||
|
divContent.appendChild(divContentContent);
|
||||||
|
|
||||||
|
var divLoading = document.createElement("div");
|
||||||
|
divLoading.className = "Loading";
|
||||||
|
|
||||||
|
var divLoadingStatus = document.createElement("div");
|
||||||
|
divLoadingStatus.className = "LoadingStatus";
|
||||||
|
|
||||||
|
var divLoadingStatusThrobber = document.createElement("div");
|
||||||
|
divLoadingStatusThrobber.className = "Throbber";
|
||||||
|
divLoadingStatusThrobber.innerHTML = " ";
|
||||||
|
divLoadingStatus.appendChild(divLoadingStatusThrobber);
|
||||||
|
|
||||||
|
var pLoadingStatusText = document.createElement("p");
|
||||||
|
pLoadingStatusText.className = "LoadingStatusText";
|
||||||
|
divLoadingStatus.appendChild(pLoadingStatusText);
|
||||||
|
|
||||||
|
divLoading.appendChild(divLoadingStatus);
|
||||||
|
|
||||||
|
divContent.appendChild(divLoading);
|
||||||
|
|
||||||
|
divWindow.appendChild(divContent);
|
||||||
|
|
||||||
|
var divFooter = document.createElement("div");
|
||||||
|
divFooter.className = "Footer";
|
||||||
|
for (var i = 0; i < buttons.length; i++)
|
||||||
|
{
|
||||||
|
var aButton = document.createElement("a");
|
||||||
|
aButton.className = "pwt-Button";
|
||||||
|
if (buttons[i].ClassName) aButton.className += " " + buttons[i].ClassName;
|
||||||
|
if ((typeof (buttons[i].Enabled) !== 'undefined') && !buttons[i].Enabled)
|
||||||
|
{
|
||||||
|
aButton.setAttribute("disabled", "disabled");
|
||||||
|
}
|
||||||
|
aButton.innerHTML = buttons[i].Text;
|
||||||
|
aButton.NativeObject = buttons[i];
|
||||||
|
aButton.ParentWindowElement = divWindow;
|
||||||
|
if (buttons[i].TargetURL)
|
||||||
|
{
|
||||||
|
aButton.href = System.ExpandRelativePath(buttons[i].TargetURL);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
aButton.href = "#";
|
||||||
|
}
|
||||||
|
if (buttons[i].TargetFrame)
|
||||||
|
{
|
||||||
|
aButton.setAttribute("target", buttons[i].TargetFrame);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (buttons[i].OnClientClick)
|
||||||
|
{
|
||||||
|
aButton.addEventListener("click", function (e)
|
||||||
|
{
|
||||||
|
if (this.NativeObject.OnClientClick(this, { "NativeObject": this.NativeObject, "ParentWindow": this.ParentWindowElement }))
|
||||||
|
{
|
||||||
|
// close the dialog
|
||||||
|
this.ParentWindowElement.NativeObject.Hide();
|
||||||
|
}
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
divFooter.appendChild(aButton);
|
||||||
|
}
|
||||||
|
divWindow.appendChild(divFooter);
|
||||||
|
|
||||||
|
// Append the newly-created element to the DOM
|
||||||
|
document.body.appendChild(divWindow);
|
||||||
|
|
||||||
|
divWindow.NativeObject = new Window(divWindow);
|
||||||
|
aButtonClose.NativeObject = divWindow.NativeObject;
|
||||||
|
|
||||||
|
window.setTimeout(function()
|
||||||
|
{
|
||||||
|
// Show the newly-created window AFTER we append it to the DOM, otherwise CSS transitions don't
|
||||||
|
// happen
|
||||||
|
divWindow.NativeObject.ShowDialog();
|
||||||
|
}, 100);
|
||||||
|
};
|
||||||
83
lib/phast/client/scripts/controls/Wizard.js
Normal file
83
lib/phast/client/scripts/controls/Wizard.js
Normal file
@ -0,0 +1,83 @@
|
|||||||
|
function Wizard(parentElement)
|
||||||
|
{
|
||||||
|
this.ParentElement = parentElement;
|
||||||
|
this.TabContainerElement = this.ParentElement.childNodes[0];
|
||||||
|
this.TabPageContainerElement = this.ParentElement.childNodes[1];
|
||||||
|
|
||||||
|
for (var i = 0; i < this.TabContainerElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
this.TabContainerElement.childNodes[i].NativeObject = this;
|
||||||
|
this.TabContainerElement.childNodes[i].Index = i;
|
||||||
|
|
||||||
|
System.AddEventListener(this.TabContainerElement.childNodes[i], "click", function(e)
|
||||||
|
{
|
||||||
|
this.NativeObject.SetSelectedPageIndex(this.Index);
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
System.AddEventListener(this.TabContainerElement.childNodes[i], "contextmenu", function(e)
|
||||||
|
{
|
||||||
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
this.GetSelectedPageIndex = function()
|
||||||
|
{
|
||||||
|
for (var i = 0; i < this.TabContainerElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (System.ClassList.Contains(this.TabContainerElement.childNodes[i], "Selected"))
|
||||||
|
{
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
};
|
||||||
|
this.SetSelectedPageIndex = function(index)
|
||||||
|
{
|
||||||
|
for (var i = 0; i < this.TabContainerElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (i == index)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.TabContainerElement.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.TabContainerElement.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i < index)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.TabContainerElement.childNodes[i], "BeforeSelected");
|
||||||
|
System.ClassList.Remove(this.TabContainerElement.childNodes[i], "AfterSelected");
|
||||||
|
}
|
||||||
|
else if (i > index)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.TabContainerElement.childNodes[i], "AfterSelected");
|
||||||
|
System.ClassList.Remove(this.TabContainerElement.childNodes[i], "BeforeSelected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (var i = 0; i < this.TabPageContainerElement.childNodes.length; i++)
|
||||||
|
{
|
||||||
|
if (i == index)
|
||||||
|
{
|
||||||
|
System.ClassList.Add(this.TabPageContainerElement.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
System.ClassList.Remove(this.TabPageContainerElement.childNodes[i], "Selected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
System.AddEventListener(window, "load", function(e)
|
||||||
|
{
|
||||||
|
var items = document.getElementsByClassName("Wizard");
|
||||||
|
for (var i = 0; i < items.length; i++)
|
||||||
|
{
|
||||||
|
items[i].NativeObject = new Wizard(items[i]);
|
||||||
|
}
|
||||||
|
});
|
||||||
503
lib/phast/client/scripts/datetime.1-1.js
Normal file
503
lib/phast/client/scripts/datetime.1-1.js
Normal file
@ -0,0 +1,503 @@
|
|||||||
|
|
||||||
|
/**
|
||||||
|
* Class that handles Date and Time related operations.
|
||||||
|
* It is very similar to .NET's DateTime class
|
||||||
|
* Find reference and documentation at: http://menendezpoo.com
|
||||||
|
*/
|
||||||
|
|
||||||
|
//Constructor
|
||||||
|
function DateTime(){
|
||||||
|
var year = 0;
|
||||||
|
var month = 0;
|
||||||
|
var day = 0;
|
||||||
|
var hour = 0;
|
||||||
|
var minute = 0;
|
||||||
|
var second = 0;
|
||||||
|
var millisecond = 0;
|
||||||
|
|
||||||
|
switch(arguments.length){
|
||||||
|
case 0:
|
||||||
|
var d = new Date();
|
||||||
|
year = d.getFullYear();
|
||||||
|
month = d.getMonth() + 1;
|
||||||
|
day = d.getDay();
|
||||||
|
hour = d.getHours();
|
||||||
|
minute = d.getMinutes();
|
||||||
|
second = d.getSeconds();
|
||||||
|
millisecond = d.getMilliseconds();
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
millisecond = arguments[0];
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
year = arguments[0];
|
||||||
|
month = arguments[1];
|
||||||
|
day = arguments[2];
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
year = arguments[0];
|
||||||
|
month = arguments[1];
|
||||||
|
day = arguments[2];
|
||||||
|
hour = arguments[3];
|
||||||
|
minute = arguments[4];
|
||||||
|
second = arguments[5];
|
||||||
|
break;
|
||||||
|
case 7:
|
||||||
|
year = arguments[0];
|
||||||
|
month = arguments[1];
|
||||||
|
day = arguments[2];
|
||||||
|
hour = arguments[3];
|
||||||
|
minute = arguments[4];
|
||||||
|
second = arguments[5];
|
||||||
|
millisecond = arguments[6];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw("No constructor supports " + arguments.length + " arguments");
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!year && !month && !day)
|
||||||
|
days = 0;
|
||||||
|
else
|
||||||
|
days = Math.round(this.absoluteDays(year, month, day));
|
||||||
|
|
||||||
|
this.span = new TimeSpan(days, hour, minute, second, millisecond);
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
DateTime.prototype = {
|
||||||
|
|
||||||
|
toString : function(){
|
||||||
|
return this.year() + "/" + TimeSpan.pad(this.month()) + "/" + TimeSpan.pad(this.day()) + " " + this.timeOfDay();
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Methods */
|
||||||
|
absoluteDays : function(year, month, day){
|
||||||
|
|
||||||
|
function div(a,b){ return Math.round(a/b); }
|
||||||
|
var num = 0;
|
||||||
|
var num2= 1;
|
||||||
|
var numArray = !DateTime.isLeapYear(year) ? DateTime.monthDays : DateTime.monthDaysLeapYear;
|
||||||
|
while(num2 < month){
|
||||||
|
num += numArray[num2++];
|
||||||
|
}
|
||||||
|
return ((((((day - 1) + num) + (365 * (year - 1))) + ((year -1 ) / 4)) - (( year - 1) / 100)) + ((year - 1) / 400));
|
||||||
|
},
|
||||||
|
|
||||||
|
add : function(timespan){
|
||||||
|
return new DateTime(this.span._millis + timespan._millis);
|
||||||
|
},
|
||||||
|
|
||||||
|
addDays : function(days){
|
||||||
|
return new DateTime(this.span._millis + days * 86400000);
|
||||||
|
},
|
||||||
|
|
||||||
|
addHours : function(hours){
|
||||||
|
return new DateTime(this.span._millis + hours * 3600000);
|
||||||
|
},
|
||||||
|
|
||||||
|
addMilliseconds : function(millis){
|
||||||
|
return new DateTime(this.span._millis + millis);
|
||||||
|
},
|
||||||
|
|
||||||
|
addMinutes : function(minutes){
|
||||||
|
return new DateTime(this.span._millis + minutes * 60000);
|
||||||
|
},
|
||||||
|
|
||||||
|
addMonths : function(months){
|
||||||
|
var day = this.day();
|
||||||
|
var month = this.month() + (months % 12);
|
||||||
|
var year = this.year() + Math.round(months / 12);
|
||||||
|
|
||||||
|
if(month < 1){
|
||||||
|
month = 12 + month;
|
||||||
|
}else if(month > 12){
|
||||||
|
month -=12;
|
||||||
|
year++;
|
||||||
|
}
|
||||||
|
|
||||||
|
var days = DateTime.daysInMonth(year, month);
|
||||||
|
|
||||||
|
if(day > days)
|
||||||
|
day = days;
|
||||||
|
|
||||||
|
var time = new DateTime(year, month, day);
|
||||||
|
return time.add(this.timeOfDay());
|
||||||
|
},
|
||||||
|
|
||||||
|
addSeconds : function(seconds){
|
||||||
|
return new DateTime(this.span._millis + seconds * 1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
addYears : function(years){
|
||||||
|
return this.addMonths(years * 12);
|
||||||
|
},
|
||||||
|
|
||||||
|
compareTo : function(datetime){
|
||||||
|
return this.span.compareTo(datetime.span);
|
||||||
|
},
|
||||||
|
|
||||||
|
equals : function(datetime){
|
||||||
|
return this.span.equals(datetime.span);
|
||||||
|
},
|
||||||
|
|
||||||
|
subtractDate : function(datetime){
|
||||||
|
return new TimeSpan(this.span._millis - datetime.span._millis);
|
||||||
|
},
|
||||||
|
|
||||||
|
subtractTime : function(timespan){
|
||||||
|
return new DateTime(this.span._millis - timespan._millis);
|
||||||
|
},
|
||||||
|
|
||||||
|
fromSpan : function(what){
|
||||||
|
|
||||||
|
var index = 1;
|
||||||
|
var daysmonth = DateTime.monthDays;
|
||||||
|
var days = this.span.days();
|
||||||
|
var num = Math.round(days / 146097);
|
||||||
|
days -= num * 146097;
|
||||||
|
var num2 = Math.round(days / 36524);
|
||||||
|
if(num2 == 4) num2 =3;
|
||||||
|
days -= num2 * 36524;
|
||||||
|
var num3 = Math.round(days / 1461);
|
||||||
|
days -= num3 * 1461;
|
||||||
|
var num4 = Math.round(days / 365);
|
||||||
|
if(num4 == 4) num = 3;
|
||||||
|
if(what == "year")
|
||||||
|
return (((((num * 400) + (num2 * 100)) + (num3 * 4)) + num4) + 1);
|
||||||
|
days -= num4 * 365;
|
||||||
|
if(what != "dayyear"){
|
||||||
|
if((num4==3) && ((num2 == 3) || (num3 != 24)))
|
||||||
|
daysmonth = DateTime.monthDaysLeapYear;
|
||||||
|
while(days >= daysmonth[index])
|
||||||
|
days -= daysmonth[index++];
|
||||||
|
if(what == "month")
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
return days + 1;
|
||||||
|
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
format : function (format){
|
||||||
|
var shortdays = new Array("", DateTime.strings.Mon, DateTime.strings.Tue, DateTime.strings.Wed, DateTime.strings.Thu, DateTime.strings.Fri, DateTime.strings.Sat, DateTime.strings.Sun);
|
||||||
|
var days = new Array("", DateTime.strings.Monday, DateTime.strings.Tuesday, DateTime.strings.Wednesday, DateTime.strings.Thursday, DateTime.strings.Friday, DateTime.strings.Saturday, DateTime.strings.Sunday);
|
||||||
|
var shortmonths = new Array("", DateTime.strings.Jan, DateTime.strings.Feb, DateTime.strings.Mar, DateTime.strings.Apr, DateTime.strings.May, DateTime.strings.Jun, DateTime.strings.Jul, DateTime.strings.Aug, DateTime.strings.Sep, DateTime.strings.Oct, DateTime.strings.Nov, DateTime.strings.Dec);
|
||||||
|
var months = new Array("", DateTime.strings.January, DateTime.strings.February, DateTime.strings.March, DateTime.strings.April, DateTime.strings.MayFull, DateTime.strings.June, DateTime.strings.July, DateTime.strings.August, DateTime.strings.September, DateTime.strings.October, DateTime.strings.November, DateTime.strings.December);
|
||||||
|
|
||||||
|
var day = this.day();
|
||||||
|
var dayOfWeek = this.dayOfWeek();
|
||||||
|
var millisecond = this.millisecond();
|
||||||
|
var hour = this.hour();
|
||||||
|
var minute = this.minute();
|
||||||
|
var second = this.second();
|
||||||
|
var month = this.month();
|
||||||
|
var year = this.year();
|
||||||
|
|
||||||
|
var data = new Array();
|
||||||
|
|
||||||
|
var yearstr = year + "";
|
||||||
|
/*
|
||||||
|
if(yearstr.length > 1)
|
||||||
|
yearstr = yearstr.substr(0, yearstr.length - 2)
|
||||||
|
*/
|
||||||
|
data["dddd"] = days[dayOfWeek];
|
||||||
|
data["ddd"] = shortdays[dayOfWeek];
|
||||||
|
data["dd"] = TimeSpan.pad(day);
|
||||||
|
data["d"] = day;
|
||||||
|
data["fff"] = millisecond;
|
||||||
|
data["ff"] = Math.round(millisecond / 10);
|
||||||
|
data["f"] = Math.round(millisecond / 100);
|
||||||
|
data["hh"] = TimeSpan.pad(hour > 12 ? hour - 12 : hour);
|
||||||
|
data["h"] = hour > 12 ? hour - 12 : hour;
|
||||||
|
data["HH"] = TimeSpan.pad(hour);
|
||||||
|
data["H"] = hour;
|
||||||
|
data["mm"] = TimeSpan.pad(minute);
|
||||||
|
data["m"] = minute;
|
||||||
|
data["MMMM"] = months[month];
|
||||||
|
data["MMM"] = shortmonths[month];
|
||||||
|
data["MM"] = TimeSpan.pad(month);
|
||||||
|
data["M"] = month;
|
||||||
|
data["ss"] = TimeSpan.pad(second);
|
||||||
|
data["s"] = second;
|
||||||
|
data["tt"] = (hour > 12 ? DateTime.strings.PM : DateTime.strings.AM) ;
|
||||||
|
data["t"] = (hour > 12 ? DateTime.strings.P : DateTime.strings.A);
|
||||||
|
data["yyyy"] = year;
|
||||||
|
data["yyy"] = year;
|
||||||
|
data["yy"] = year;
|
||||||
|
data["y"] = year;
|
||||||
|
data[":"] = DateTime.strings.TimeSeparator;
|
||||||
|
data["/"] = DateTime.strings.DateSeparator;
|
||||||
|
|
||||||
|
|
||||||
|
var output = "";
|
||||||
|
var res = format.split(/(dddd|ddd|dd|d|fff|ff|f|hh|h|HH|H||mm|m|MMMM|MMM|MM|M|ss|s|tt|t|yyyy|yyy|yy|y)?/);
|
||||||
|
|
||||||
|
for(var i = 0; i < res.length; i++){
|
||||||
|
if(res[i]){
|
||||||
|
if(data[res[i]]){
|
||||||
|
output += data[res[i]];
|
||||||
|
}else{
|
||||||
|
output += res[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Properties */
|
||||||
|
date : function(){
|
||||||
|
return new DateTime(this.year(), this.month(), this.day());
|
||||||
|
},
|
||||||
|
|
||||||
|
day : function(){
|
||||||
|
return this.fromSpan("day");
|
||||||
|
},
|
||||||
|
|
||||||
|
dayOfWeek : function(){
|
||||||
|
return (this.span.days() + 1) % 7;
|
||||||
|
},
|
||||||
|
|
||||||
|
dayOfYear : function(){
|
||||||
|
return this.fromSpan("dayyear");
|
||||||
|
},
|
||||||
|
|
||||||
|
hour : function(){
|
||||||
|
return this.span.hours();
|
||||||
|
},
|
||||||
|
|
||||||
|
millisecond : function(){
|
||||||
|
return this.span.milliseconds();
|
||||||
|
},
|
||||||
|
|
||||||
|
minute : function(){
|
||||||
|
return this.span.minutes();
|
||||||
|
},
|
||||||
|
|
||||||
|
month : function(){
|
||||||
|
return this.fromSpan("month");
|
||||||
|
},
|
||||||
|
|
||||||
|
second : function(){
|
||||||
|
return this.span.seconds();
|
||||||
|
},
|
||||||
|
|
||||||
|
timeOfDay : function(){
|
||||||
|
return new TimeSpan(this.span._millis % 86400000);
|
||||||
|
},
|
||||||
|
|
||||||
|
year : function(){
|
||||||
|
return this.fromSpan("year");
|
||||||
|
},
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
DateTime.monthDays = new Array(0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
|
||||||
|
DateTime.monthDaysLeapYear = new Array(0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
|
||||||
|
DateTime.daysInMonth = function (year, month){
|
||||||
|
if(DateTime.isLeapYear(year)){
|
||||||
|
return DateTime.monthDaysLeapYear[month];
|
||||||
|
}else{
|
||||||
|
return DateTime.monthDays[month];
|
||||||
|
}
|
||||||
|
};
|
||||||
|
DateTime.now = function(){
|
||||||
|
d = new Date();
|
||||||
|
return new DateTime(d.getFullYear(), d.getMonth() + 1, d.getDay(), d.getHours(), d.getMinutes(), d.getSeconds(), d.getMilliseconds());
|
||||||
|
};
|
||||||
|
DateTime.utcNow = function(){
|
||||||
|
d = new Date();
|
||||||
|
return new DateTime(d.getUTCFullYear(), d.getUTCMonth(), d.getUTCDay(), d.getUTCHours(), d.getUTCMinutes(), d.getUTCSeconds(), d.getUTCMilliseconds());
|
||||||
|
};
|
||||||
|
DateTime.today = function(){
|
||||||
|
var now = DateTime.now();
|
||||||
|
return new DateTime(now.year(), now.month(), now.day());
|
||||||
|
};
|
||||||
|
DateTime.isLeapYear = function(year){
|
||||||
|
if (( (year % 4 == 0) && (year % 100 != 0) ) || (year % 400 == 0))
|
||||||
|
return true;
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
///*
|
||||||
|
DateTime.strings = function(){ };
|
||||||
|
DateTime.strings.Mon = "Mon";
|
||||||
|
DateTime.strings.Monday = "Monday";
|
||||||
|
DateTime.strings.Tue = "Tue";
|
||||||
|
DateTime.strings.Tuesday = "Tuesday";
|
||||||
|
DateTime.strings.Wed = "Wed";
|
||||||
|
DateTime.strings.Wednesday = "Wednesday";
|
||||||
|
DateTime.strings.Thu = "Thu";
|
||||||
|
DateTime.strings.Thursday = "Thursday";
|
||||||
|
DateTime.strings.Fri = "Fri";
|
||||||
|
DateTime.strings.Friday = "Friday";
|
||||||
|
DateTime.strings.Sat = "Sat";
|
||||||
|
DateTime.strings.Saturday = "Saturday";
|
||||||
|
DateTime.strings.Sun = "Sun";
|
||||||
|
DateTime.strings.Sunday = "Sunday";
|
||||||
|
DateTime.strings.Jan = "Jan";
|
||||||
|
DateTime.strings.Januray = "January";
|
||||||
|
DateTime.strings.Feb = "Feb";
|
||||||
|
DateTime.strings.February = "February";
|
||||||
|
DateTime.strings.Mar = "Mar";
|
||||||
|
DateTime.strings.March = "March";
|
||||||
|
DateTime.strings.Apr = "Apr";
|
||||||
|
DateTime.strings.April = "April";
|
||||||
|
DateTime.strings.May = "May";
|
||||||
|
DateTime.strings.MayFull = "May";
|
||||||
|
DateTime.strings.Jun = "Jun";
|
||||||
|
DateTime.strings.June = "June";
|
||||||
|
DateTime.strings.Jul = "Jul";
|
||||||
|
DateTime.strings.July = "July";
|
||||||
|
DateTime.strings.Aug = "Aug";
|
||||||
|
DateTime.strings.August = "August";
|
||||||
|
DateTime.strings.Sep = "Sep";
|
||||||
|
DateTime.strings.September = "September";
|
||||||
|
DateTime.strings.Oct = "Oct";
|
||||||
|
DateTime.strings.October = "October";
|
||||||
|
DateTime.strings.Nov = "Nov";
|
||||||
|
DateTime.strings.November = "November";
|
||||||
|
DateTime.strings.Dec = "Dec";
|
||||||
|
DateTime.strings.December = "December";
|
||||||
|
DateTime.strings.A = "A";
|
||||||
|
DateTime.strings.AM = "AM";
|
||||||
|
DateTime.strings.P = "P";
|
||||||
|
DateTime.strings.PM = "PM";
|
||||||
|
DateTime.strings.TimeSeparator = ":";
|
||||||
|
DateTime.strings.DateSeparator = "/";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that handles time related operations.
|
||||||
|
* It is very similar to .NET's TimeSpan class
|
||||||
|
* Find reference and documentation at: http://menendezpoo.com
|
||||||
|
*/
|
||||||
|
function TimeSpan(){
|
||||||
|
|
||||||
|
var days = 0;
|
||||||
|
var hours = 0;
|
||||||
|
var minutes = 0;
|
||||||
|
var seconds = 0;
|
||||||
|
var milliseconds = 0;
|
||||||
|
|
||||||
|
switch(arguments.length){
|
||||||
|
case 0:
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
milliseconds = arguments[0];
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
days = arguments[0];
|
||||||
|
hours = arguments[1];
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
hours = arguments[0];
|
||||||
|
minutes = arguments[1];
|
||||||
|
seconds = arguments[2];
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
days = arguments[0];
|
||||||
|
hours = arguments[1];
|
||||||
|
minutes = arguments[2];
|
||||||
|
seconds = arguments[3];
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
days = arguments[0];
|
||||||
|
hours = arguments[1];
|
||||||
|
minutes = arguments[2];
|
||||||
|
seconds = arguments[3];
|
||||||
|
milliseconds = arguments[4];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
throw("No constructor of TimeSpan supports " + arguments.length + " arguments");
|
||||||
|
}
|
||||||
|
|
||||||
|
this._millis = (days * 86400 + hours * 3600 + minutes * 60 + seconds) * 1000 + milliseconds;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
TimeSpan.prototype = {
|
||||||
|
/* Methods */
|
||||||
|
add : function(timespan){
|
||||||
|
return new TimeSpan(timespan._millis + this._millis);
|
||||||
|
},
|
||||||
|
|
||||||
|
compareTo : function(timespan){
|
||||||
|
if(this._millis > timespan._millis) return 1;
|
||||||
|
if(this._millis == timespan._millis) return 0;
|
||||||
|
if(this._millis < timespan._millis) return -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
duration : function(){
|
||||||
|
return new TimeSpan(Math.abs(this._millis));
|
||||||
|
},
|
||||||
|
|
||||||
|
equals : function(timespan){
|
||||||
|
return this._millis == timespan._millis;
|
||||||
|
},
|
||||||
|
|
||||||
|
negate : function(){
|
||||||
|
this._millis *= -1;
|
||||||
|
},
|
||||||
|
|
||||||
|
subtract : function(timespan){
|
||||||
|
return new TimeSpan(this._millis - timespan._millis);
|
||||||
|
},
|
||||||
|
|
||||||
|
rounder : function(number){
|
||||||
|
if(this._millis < 0)
|
||||||
|
return Math.ceil(number);
|
||||||
|
return Math.floor(number);
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Properties */
|
||||||
|
|
||||||
|
days : function(){
|
||||||
|
return this.rounder(this._millis / (24 * 3600 * 1000) );
|
||||||
|
},
|
||||||
|
|
||||||
|
hours : function(){
|
||||||
|
return this.rounder( (this._millis % (24 * 3600 * 1000)) / (3600 * 1000));
|
||||||
|
},
|
||||||
|
|
||||||
|
milliseconds : function(){
|
||||||
|
return this.rounder(this._millis % 1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
minutes : function(){
|
||||||
|
return this.rounder( (this._millis % (3600 * 1000)) / (60 * 1000));
|
||||||
|
},
|
||||||
|
|
||||||
|
seconds : function(){
|
||||||
|
return this.rounder((this._millis % 60000) / 1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
totalDays : function(){
|
||||||
|
return this._millis / (24 * 3600 * 1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
totalHours : function(){
|
||||||
|
return this._millis / (3600 * 1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
totalMinutes : function(){
|
||||||
|
return this._millis / (60 * 1000);
|
||||||
|
},
|
||||||
|
|
||||||
|
totalSeconds : function(){
|
||||||
|
return this._millis / 1000;
|
||||||
|
},
|
||||||
|
|
||||||
|
totalMilliseconds : function(){
|
||||||
|
return this._millis;
|
||||||
|
},
|
||||||
|
|
||||||
|
toString : function(){
|
||||||
|
return (this._millis < 0 ? "-" : "") + (Math.abs(this.days()) ? TimeSpan.pad(Math.abs(this.days())) + ".": "") + TimeSpan.pad(Math.abs(this.hours())) + ":" + TimeSpan.pad(Math.abs(this.minutes())) + ":" + TimeSpan.pad(Math.abs(this.seconds())) + "." + Math.abs(this.milliseconds());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
TimeSpan.pad = function(number){ return (number < 10 ? '0' : '') + number; };
|
||||||
1
lib/phast/client/scripts/json2.min.js
vendored
Normal file
1
lib/phast/client/scripts/json2.min.js
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
var JSON;if(!JSON){JSON={};} (function(){"use strict";function f(n){return n<10?'0'+n:n;} if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+ f(this.getUTCMonth()+1)+'-'+ f(this.getUTCDate())+'T'+ f(this.getUTCHours())+':'+ f(this.getUTCMinutes())+':'+ f(this.getUTCSeconds())+'Z':null;};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf();};} var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4);})+'"':'"'+string+'"';} function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key);} if(typeof rep==='function'){value=rep.call(holder,key,value);} switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null';} gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null';} v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v;} if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){if(typeof rep[i]==='string'){k=rep[i];v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}}else{for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v);}}}} v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v;}} if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' ';}}else if(typeof space==='string'){indent=space;} rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');} return str('',{'':value});};} if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.prototype.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v;}else{delete value[k];}}}} return reviver.call(holder,key,value);} text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+ ('0000'+a.charCodeAt(0).toString(16)).slice(-4);});} if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j;} throw new SyntaxError('JSON.parse');};}}());
|
||||||
Loading…
x
Reference in New Issue
Block a user