/files/w2ui/1.3.0/w2ui.js
JavaScript | 1330 lines | 1080 code | 114 blank | 136 comment | 420 complexity | 870d05bc0657ff55df2ec8a0619ff07b MD5 | raw file
- /* w2ui 1.3 (c) http://w2ui.com, vitmalina@gmail.com */
- var w2ui = w2ui || {};
- var w2obj = w2obj || {}; // expose object to be able to overwrite default functions
- /************************************************
- * Library: Web 2.0 UI for jQuery
- * - Following objects are defines
- * - w2ui - object that will contain all widgets
- * - w2obj - object with widget prototypes
- * - w2utils - basic utilities
- * - $().w2render - common render
- * - $().w2destroy - common destroy
- * - $().w2marker - marker plugin
- * - $().w2tag - tag plugin
- * - $().w2overlay - overlay plugin
- * - $().w2menu - menu plugin
- * - w2utils.event - generic event object
- * - w2utils.keyboard - object for keyboard navigation
- * - Dependencies: jQuery
- *
- * == NICE TO HAVE ==
- * - date has problems in FF new Date('yyyy-mm-dd') breaks
- * - bug: w2utils.formatDate('2011-31-01', 'yyyy-dd-mm'); - wrong foratter
- * - overlay should be displayed where more space (on top or on bottom)
- * - write and article how to replace certain framework functions
- * - format date and time is buggy
- * - onComplete should pass widget as context (this)
- *
- ************************************************/
- var w2utils = (function () {
- var tmp = {}; // for some temp variables
- var obj = {
- settings : {
- "locale" : "en-us",
- "date_format" : "m/d/yyyy",
- "date_display" : "Mon d, yyyy",
- "time_format" : "hh:mi pm",
- "currency" : "^[\$\€\£\¥]?[-]?[0-9]*[\.]?[0-9]+$",
- "currencySymbol": "$",
- "float" : "^[-]?[0-9]*[\.]?[0-9]+$",
- "shortmonths" : ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
- "fullmonths" : ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"],
- "shortdays" : ["M", "T", "W", "T", "F", "S", "S"],
- "fulldays" : ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"],
- "RESTfull" : false,
- "phrases" : {} // empty object for english phrases
- },
- isInt : isInt,
- isFloat : isFloat,
- isMoney : isMoney,
- isHex : isHex,
- isAlphaNumeric : isAlphaNumeric,
- isEmail : isEmail,
- isDate : isDate,
- isTime : isTime,
- age : age,
- date : date,
- size : size,
- formatNumber : formatNumber,
- formatDate : formatDate,
- formatTime : formatTime,
- formatDateTime : formatDateTime,
- stripTags : stripTags,
- encodeTags : encodeTags,
- escapeId : escapeId,
- base64encode : base64encode,
- base64decode : base64decode,
- transition : transition,
- lock : lock,
- unlock : unlock,
- lang : lang,
- locale : locale,
- getSize : getSize,
- scrollBarSize : scrollBarSize
- }
- return obj;
-
- function isInt (val) {
- var re = /^[-]?[0-9]+$/;
- return re.test(val);
- }
-
- function isFloat (val) {
- var re = new RegExp(w2utils.settings["float"]);
- return re.test(val);
- }
- function isMoney (val) {
- var re = new RegExp(w2utils.settings.currency);
- return re.test(val);
- }
-
- function isHex (val) {
- var re = /^[a-fA-F0-9]+$/;
- return re.test(val);
- }
-
- function isAlphaNumeric (val) {
- var re = /^[a-zA-Z0-9_-]+$/;
- return re.test(val);
- }
-
- function isEmail (val) {
- var email = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
- return email.test(val);
- }
- function isDate (val, format, retDate) {
- if (!val) return false;
- if (!format) format = w2utils.settings.date_format;
- // format date
- var tmp = val.replace(/-/g, '/').replace(/\./g, '/').toLowerCase().split('/');
- var tmp2 = format.replace(/-/g, '/').replace(/\./g, '/').toLowerCase();
- var dt = 'Invalid Date';
- var month, day, year;
- if (tmp2 == 'mm/dd/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; }
- if (tmp2 == 'm/d/yyyy') { month = tmp[0]; day = tmp[1]; year = tmp[2]; }
- if (tmp2 == 'dd/mm/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; }
- if (tmp2 == 'd/m/yyyy') { month = tmp[1]; day = tmp[0]; year = tmp[2]; }
- if (tmp2 == 'yyyy/dd/mm') { month = tmp[2]; day = tmp[1]; year = tmp[0]; }
- if (tmp2 == 'yyyy/d/m') { month = tmp[2]; day = tmp[1]; year = tmp[0]; }
- if (tmp2 == 'yyyy/mm/dd') { month = tmp[1]; day = tmp[2]; year = tmp[0]; }
- if (tmp2 == 'yyyy/m/d') { month = tmp[1]; day = tmp[2]; year = tmp[0]; }
- dt = new Date(month + '/' + day + '/' + year);
- // do checks
- if (typeof month == 'undefined') return false;
- if (dt == 'Invalid Date') return false;
- if ((dt.getMonth()+1 != month) || (dt.getDate() != day) || (dt.getFullYear() != year)) return false;
- if (retDate === true) return dt; else return true;
- }
- function isTime (val) {
- // Both formats 10:20pm and 22:20
- if (String(val) == 'undefined') return false;
- var max;
- // -- process american foramt
- val = val.toUpperCase();
- if (val.indexOf('PM') >= 0 || val.indexOf('AM') >= 0) max = 12; else max = 23;
- val = $.trim(val.replace('AM', ''));
- val = $.trim(val.replace('PM', ''));
- // ---
- var tmp = val.split(':');
- if (tmp.length != 2) { return false; }
- if (tmp[0] == '' || parseInt(tmp[0]) < 0 || parseInt(tmp[0]) > max || !this.isInt(tmp[0])) { return false; }
- if (tmp[1] == '' || parseInt(tmp[1]) < 0 || parseInt(tmp[1]) > 59 || !this.isInt(tmp[1])) { return false; }
- return true;
- }
- function age (timeStr) {
- if (timeStr == '' || typeof timeStr == 'undefined' || timeStr == null) return '';
- if (w2utils.isInt(timeStr)) timeStr = Number(timeStr); // for unix timestamps
-
- var d1 = new Date(timeStr);
- if (w2utils.isInt(timeStr)) d1 = new Date(Number(timeStr)); // for unix timestamps
- var tmp = String(timeStr).split('-');
- if (tmp.length == 3) d1 = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd
- var tmp = String(timeStr).split('/');
- if (tmp.length == 3) d1 = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy
- if (d1 == 'Invalid Time') return '';
- var d2 = new Date();
- var sec = (d2.getTime() - d1.getTime()) / 1000;
- var amount = '';
- var type = '';
-
- if (sec < 60) {
- amount = Math.floor(sec);
- type = 'sec';
- if (sec < 0) { amount = 0; type = 'sec' }
- } else if (sec < 60*60) {
- amount = Math.floor(sec/60);
- type = 'min';
- } else if (sec < 24*60*60) {
- amount = Math.floor(sec/60/60);
- type = 'hour';
- } else if (sec < 30*24*60*60) {
- amount = Math.floor(sec/24/60/60);
- type = 'day';
- } else if (sec < 12*30*24*60*60) {
- amount = Math.floor(sec/30/24/60/60*10)/10;
- type = 'month';
- } else if (sec >= 12*30*24*60*60) {
- amount = Math.floor(sec/12/30/24/60/60*10)/10;
- type = 'year';
- }
- return amount + ' ' + type + (amount > 1 ? 's' : '');
- }
-
- function date (dateStr) {
- var months = w2utils.settings.shortmonths;
- if (dateStr == '' || typeof dateStr == 'undefined' || dateStr == null) return '';
- if (w2utils.isInt(dateStr)) dateStr = Number(dateStr); // for unix timestamps
-
- var d1 = new Date(dateStr);
- if (w2utils.isInt(dateStr)) d1 = new Date(Number(dateStr)); // for unix timestamps
- var tmp = String(dateStr).split('-');
- if (tmp.length == 3) d1 = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd
- var tmp = String(dateStr).split('/');
- if (tmp.length == 3) d1 = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy
- if (d1 == 'Invalid Date') return '';
- var d2 = new Date(); // today
- var d3 = new Date();
- d3.setTime(d3.getTime() - 86400000); // yesterday
-
- var dd1 = months[d1.getMonth()] + ' ' + d1.getDate() + ', ' + d1.getFullYear();
- var dd2 = months[d2.getMonth()] + ' ' + d2.getDate() + ', ' + d2.getFullYear();
- var dd3 = months[d3.getMonth()] + ' ' + d3.getDate() + ', ' + d3.getFullYear();
-
- var time = (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am');
- var time2= (d1.getHours() - (d1.getHours() > 12 ? 12 :0)) + ':' + (d1.getMinutes() < 10 ? '0' : '') + d1.getMinutes() + ':' + (d1.getSeconds() < 10 ? '0' : '') + d1.getSeconds() + ' ' + (d1.getHours() >= 12 ? 'pm' : 'am');
- var dsp = dd1;
- if (dd1 == dd2) dsp = time;
- if (dd1 == dd3) dsp = w2utils.lang('Yesterday');
- return '<span title="'+ dd1 +' ' + time2 +'">'+ dsp +'</span>';
- }
- function size (sizeStr) {
- if (!w2utils.isFloat(sizeStr) || sizeStr == '') return '';
- sizeStr = parseFloat(sizeStr);
- if (sizeStr == 0) return 0;
- var sizes = ['Bt', 'KB', 'MB', 'GB', 'TB'];
- var i = parseInt( Math.floor( Math.log(sizeStr) / Math.log(1024) ) );
- return (Math.floor(sizeStr / Math.pow(1024, i) * 10) / 10).toFixed(i == 0 ? 0 : 1) + ' ' + sizes[i];
- }
- function formatNumber (val) {
- var ret = '';
- // check if this is a number
- if (w2utils.isFloat(val) || w2utils.isInt(val) || w2utils.isMoney(val)) {
- ret = String(val).replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,");
- }
- return ret;
- }
-
- function formatDate (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String
- var months = w2utils.settings.shortmonths;
- var fullMonths = w2utils.settings.fullmonths;
- if (typeof format == 'undefined') format = this.settings.date_format;
- if (typeof dateStr == 'undefined' || dateStr == '' || dateStr == null) return '';
- var dt = new Date(dateStr);
- if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps
- var tmp = String(dateStr).split('-');
- if (tmp.length == 3) dt = new Date(tmp[0], Number(tmp[1])-1, tmp[2]); // yyyy-mm-dd
- var tmp = String(dateStr).split('/');
- if (tmp.length == 3) dt = new Date(tmp[2], Number(tmp[0])-1, tmp[1]); // mm/dd/yyyy
- if (dt == 'Invalid Date') return '';
- var year = dt.getFullYear();
- var month = dt.getMonth();
- var date = dt.getDate();
- return format.toLowerCase()
- .replace('month', w2utils.settings.fullmonths[month])
- .replace('mon', w2utils.settings.shortmonths[month])
- .replace(/yyyy/g, year)
- .replace(/yyy/g, year)
- .replace(/yy/g, String(year).substr(2))
- .replace(/(^|[^a-z$])y/g, '$1'+year) // only y's that are not preceeded by a letter
- .replace(/mm/g, (month + 1 < 10 ? '0' : '') + (month + 1))
- .replace(/dd/g, (date < 10 ? '0' : '') + date)
- .replace(/(^|[^a-z$])m/g, '$1'+ (month + 1)) // only y's that are not preceeded by a letter
- .replace(/(^|[^a-z$])d/g, '$1' + date); // only y's that are not preceeded by a letter
- }
- function formatTime (dateStr, format) { // IMPORTANT dateStr HAS TO BE valid JavaScript Date String
- var months = w2utils.settings.shortmonths;
- var fullMonths = w2utils.settings.fullmonths;
- if (typeof format == 'undefined') format = this.settings.time_format;
- if (typeof dateStr == 'undefined' || dateStr == '' || dateStr == null) return '';
- var dt = new Date(dateStr);
- if (w2utils.isInt(dateStr)) dt = new Date(Number(dateStr)); // for unix timestamps
- if (dt == 'Invalid Date') return '';
- var type = 'am';
- var hour = dt.getHours();
- var h24 = dt.getHours();
- var min = dt.getMinutes();
- var sec = dt.getSeconds();
- if (min < 10) min = '0' + min;
- if (sec < 10) sec = '0' + sec;
- if (format.indexOf('am') != -1 || format.indexOf('pm') != -1) {
- if (hour >= 12) type = 'pm';
- if (hour > 12) hour = hour - 12;
- }
- return format.toLowerCase()
- .replace('am', type)
- .replace('pm', type)
- .replace('hh', hour)
- .replace('h24', h24)
- .replace('mm', min)
- .replace('mi', min)
- .replace('ss', sec)
- .replace(/(^|[^a-z$])h/g, '$1' + hour) // only y's that are not preceeded by a letter
- .replace(/(^|[^a-z$])m/g, '$1' + min) // only y's that are not preceeded by a letter
- .replace(/(^|[^a-z$])s/g, '$1' + sec); // only y's that are not preceeded by a letter
- }
- function formatDateTime(dateStr, format) {
- var fmt;
- if (typeof format != 'string') {
- var fmt = [this.settings.date_format, this.settings.time_format];
- } else {
- var fmt = format.split('|');
- }
- return this.formatDate(dateStr, fmt[0]) + ' ' + this.formatTime(dateStr, fmt[1]);
- }
- function stripTags (html) {
- if (html == null) return html;
- switch (typeof html) {
- case 'number':
- break;
- case 'string':
- html = $.trim(String(html).replace(/(<([^>]+)>)/ig, ""));
- break;
- case 'object':
- for (var a in html) html[a] = this.stripTags(html[a]);
- break;
- }
- return html;
- }
- function encodeTags (html) {
- if (html == null) return html;
- switch (typeof html) {
- case 'number':
- break;
- case 'string':
- html = String(html).replace(/&/g, "&").replace(/>/g, ">").replace(/</g, "<").replace(/"/g, """);
- break;
- case 'object':
- for (var a in html) html[a] = this.encodeTags(html[a]);
- break;
- }
- return html;
- }
- function escapeId (id) {
- if (typeof id == 'undefined' || id == '' || id == null) return '';
- return String(id).replace(/([;&,\.\+\*\~'`:"\!\^#$%@\[\]\(\)=<>\|\/? {}\\])/g, '\\$1');
- }
- function base64encode (input) {
- var output = "";
- var chr1, chr2, chr3, enc1, enc2, enc3, enc4;
- var i = 0;
- var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
- input = utf8_encode(input);
- while (i < input.length) {
- chr1 = input.charCodeAt(i++);
- chr2 = input.charCodeAt(i++);
- chr3 = input.charCodeAt(i++);
- enc1 = chr1 >> 2;
- enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
- enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
- enc4 = chr3 & 63;
- if (isNaN(chr2)) {
- enc3 = enc4 = 64;
- } else if (isNaN(chr3)) {
- enc4 = 64;
- }
- output = output + keyStr.charAt(enc1) + keyStr.charAt(enc2) + keyStr.charAt(enc3) + keyStr.charAt(enc4);
- }
- function utf8_encode (string) {
- var string = String(string).replace(/\r\n/g,"\n");
- var utftext = "";
- for (var n = 0; n < string.length; n++) {
- var c = string.charCodeAt(n);
- if (c < 128) {
- utftext += String.fromCharCode(c);
- }
- else if((c > 127) && (c < 2048)) {
- utftext += String.fromCharCode((c >> 6) | 192);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- else {
- utftext += String.fromCharCode((c >> 12) | 224);
- utftext += String.fromCharCode(((c >> 6) & 63) | 128);
- utftext += String.fromCharCode((c & 63) | 128);
- }
- }
- return utftext;
- }
- return output;
- }
- function base64decode (input) {
- var output = "";
- var chr1, chr2, chr3;
- var enc1, enc2, enc3, enc4;
- var i = 0;
- var keyStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
- input = input.replace(/[^A-Za-z0-9\+\/\=]/g, "");
- while (i < input.length) {
- enc1 = keyStr.indexOf(input.charAt(i++));
- enc2 = keyStr.indexOf(input.charAt(i++));
- enc3 = keyStr.indexOf(input.charAt(i++));
- enc4 = keyStr.indexOf(input.charAt(i++));
- chr1 = (enc1 << 2) | (enc2 >> 4);
- chr2 = ((enc2 & 15) << 4) | (enc3 >> 2);
- chr3 = ((enc3 & 3) << 6) | enc4;
- output = output + String.fromCharCode(chr1);
- if (enc3 != 64) {
- output = output + String.fromCharCode(chr2);
- }
- if (enc4 != 64) {
- output = output + String.fromCharCode(chr3);
- }
- }
- output = utf8_decode(output);
- function utf8_decode (utftext) {
- var string = "";
- var i = 0;
- var c = 0, c1 = 0, c2 = 0;
- while ( i < utftext.length ) {
- c = utftext.charCodeAt(i);
- if (c < 128) {
- string += String.fromCharCode(c);
- i++;
- }
- else if((c > 191) && (c < 224)) {
- c2 = utftext.charCodeAt(i+1);
- string += String.fromCharCode(((c & 31) << 6) | (c2 & 63));
- i += 2;
- }
- else {
- c2 = utftext.charCodeAt(i+1);
- c3 = utftext.charCodeAt(i+2);
- string += String.fromCharCode(((c & 15) << 12) | ((c2 & 63) << 6) | (c3 & 63));
- i += 3;
- }
- }
- return string;
- }
- return output;
- }
-
- function transition (div_old, div_new, type, callBack) {
- var width = $(div_old).width();
- var height = $(div_old).height();
- var time = 0.5;
-
- if (!div_old || !div_new) {
- console.log('ERROR: Cannot do transition when one of the divs is null');
- return;
- }
-
- div_old.parentNode.style.cssText += cross('perspective', '700px') +'; overflow: hidden;';
- div_old.style.cssText += '; position: absolute; z-index: 1019; '+ cross('backface-visibility', 'hidden');
- div_new.style.cssText += '; position: absolute; z-index: 1020; '+ cross('backface-visibility', 'hidden');
-
- switch (type) {
- case 'slide-left':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d('+ width + 'px, 0, 0)', 'translate('+ width +'px, 0)');
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_old.style.cssText += cross('transition', time+'s') +';'+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)');
- }, 1);
- break;
- case 'slide-right':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(-'+ width +'px, 0, 0)', 'translate(-'+ width +'px, 0)');
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0px, 0, 0)', 'translate(0px, 0)');
- div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d('+ width +'px, 0, 0)', 'translate('+ width +'px, 0)');
- }, 1);
- break;
- case 'slide-down':
- // init divs
- div_old.style.cssText += 'overflow: hidden; z-index: 1; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_new.style.cssText += 'overflow: hidden; z-index: 0; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)');
- }, 1);
- break;
- case 'slide-up':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, '+ height +'px, 0)', 'translate(0, '+ height +'px)');
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- }, 1);
- break;
- case 'flip-left':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('-transform', 'rotateY(0deg)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(-180deg)');
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)');
- div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(180deg)');
- }, 1);
- break;
- case 'flip-right':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(0deg)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateY(180deg)');
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(0deg)');
- div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateY(-180deg)');
- }, 1);
- break;
- case 'flip-down':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(180deg)');
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)');
- div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(-180deg)');
- }, 1);
- break;
- case 'flip-up':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(0deg)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'rotateX(-180deg)');
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(0deg)');
- div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'rotateX(180deg)');
- }, 1);
- break;
- case 'pop-in':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') + '; '+ cross('transform', 'scale(.8)') + '; opacity: 0;';
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;';
- div_old.style.cssText += cross('transition', time+'s') +';';
- }, 1);
- break;
- case 'pop-out':
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; '+ cross('transform', 'scale(1)') +'; opacity: 1;';
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;';
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time+'s') +'; opacity: 1;';
- div_old.style.cssText += cross('transition', time+'s') +'; '+ cross('transform', 'scale(1.7)') +'; opacity: 0;';
- }, 1);
- break;
- default:
- // init divs
- div_old.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)');
- div_new.style.cssText += 'overflow: hidden; '+ cross('transform', 'translate3d(0, 0, 0)', 'translate(0, 0)') +'; opacity: 0;';
- $(div_new).show();
- // -- need a timing function because otherwise not working
- window.setTimeout(function() {
- div_new.style.cssText += cross('transition', time +'s') +'; opacity: 1;';
- div_old.style.cssText += cross('transition', time +'s');
- }, 1);
- break;
- }
-
- setTimeout(function () {
- if (type == 'slide-down') {
- $(div_old).css('z-index', '1019');
- $(div_new).css('z-index', '1020');
- }
- if (div_new) {
- $(div_new).css({
- 'opacity': '1',
- '-webkit-transition': '',
- '-moz-transition': '',
- '-ms-transition': '',
- '-o-transition': '',
- '-webkit-transform': '',
- '-moz-transform': '',
- '-ms-transform': '',
- '-o-transform': '',
- '-webkit-backface-visibility': '',
- '-moz-backface-visibility': '',
- '-ms-backface-visibility': '',
- '-o-backface-visibility': ''
- });
- }
- if (div_old) {
- $(div_old).css({
- 'opacity': '1',
- '-webkit-transition': '',
- '-moz-transition': '',
- '-ms-transition': '',
- '-o-transition': '',
- '-webkit-transform': '',
- '-moz-transform': '',
- '-ms-transform': '',
- '-o-transform': '',
- '-webkit-backface-visibility': '',
- '-moz-backface-visibility': '',
- '-ms-backface-visibility': '',
- '-o-backface-visibility': ''
- });
- if (div_old.parentNode) $(div_old.parentNode).css({
- '-webkit-perspective': '',
- '-moz-perspective': '',
- '-ms-perspective': '',
- '-o-perspective': ''
- });
- }
- if (typeof callBack == 'function') callBack();
- }, time * 1000);
-
- function cross(property, value, none_webkit_value) {
- var isWebkit=!!window.webkitURL; // jQuery no longer supports $.browser - RR
- if (!isWebkit && typeof none_webkit_value != 'undefined') value = none_webkit_value;
- return ';'+ property +': '+ value +'; -webkit-'+ property +': '+ value +'; -moz-'+ property +': '+ value +'; '+
- '-ms-'+ property +': '+ value +'; -o-'+ property +': '+ value +';';
- }
- }
-
- function lock (box, msg, showSpinner) {
- if (!msg && msg != 0) msg = '';
- w2utils.unlock(box);
- $(box).find('>:first-child').before(
- '<div class="w2ui-lock"></div>'+
- '<div class="w2ui-lock-msg"></div>'
- );
- setTimeout(function () {
- var lock = $(box).find('.w2ui-lock');
- var mess = $(box).find('.w2ui-lock-msg');
- lock.data('old_opacity', lock.css('opacity')).css('opacity', '0').show();
- mess.data('old_opacity', mess.css('opacity')).css('opacity', '0').show();
- setTimeout(function () {
- var lock = $(box).find('.w2ui-lock');
- var mess = $(box).find('.w2ui-lock-msg');
- var left = ($(box).width() - w2utils.getSize(mess, 'width')) / 2;
- var top = ($(box).height() * 0.9 - w2utils.getSize(mess, 'height')) / 2;
- lock.css({
- opacity : lock.data('old_opacity'),
- left : '0px',
- top : '0px',
- width : '100%',
- height : '100%'
- });
- if (!msg) mess.css({ 'background-color': 'transparent', 'border': '0px' });
- if (showSpinner === true) msg = '<div class="w2ui-spinner" '+ (!msg ? 'style="width: 30px; height: 30px"' : '') +'></div>' + msg;
- mess.html(msg).css({
- opacity : mess.data('old_opacity'),
- left : left + 'px',
- top : top + 'px'
- });
- }, 10);
- }, 10);
- // hide all tags (do not hide overlays as the form can be in overlay)
- $().w2tag();
- }
- function unlock (box) {
- $(box).find('.w2ui-lock').remove();
- $(box).find('.w2ui-lock-msg').remove();
- }
- function getSize (el, type) {
- var bwidth = {
- left: parseInt($(el).css('border-left-width')) || 0,
- right: parseInt($(el).css('border-right-width')) || 0,
- top: parseInt($(el).css('border-top-width')) || 0,
- bottom: parseInt($(el).css('border-bottom-width')) || 0
- }
- var mwidth = {
- left: parseInt($(el).css('margin-left')) || 0,
- right: parseInt($(el).css('margin-right')) || 0,
- top: parseInt($(el).css('margin-top')) || 0,
- bottom: parseInt($(el).css('margin-bottom')) || 0
- }
- var pwidth = {
- left: parseInt($(el).css('padding-left')) || 0,
- right: parseInt($(el).css('padding-right')) || 0,
- top: parseInt($(el).css('padding-top')) || 0,
- bottom: parseInt($(el).css('padding-bottom')) || 0
- }
- switch (type) {
- case 'top': return bwidth.top + mwidth.top + pwidth.top;
- case 'bottom': return bwidth.bottom + mwidth.bottom + pwidth.bottom;
- case 'left': return bwidth.left + mwidth.left + pwidth.left;
- case 'right': return bwidth.right + mwidth.right + pwidth.right;
- case 'width': return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right + parseInt($(el).width());
- case 'height': return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom + parseInt($(el).height());
- case '+width': return bwidth.left + bwidth.right + mwidth.left + mwidth.right + pwidth.left + pwidth.right;
- case '+height': return bwidth.top + bwidth.bottom + mwidth.top + mwidth.bottom + pwidth.top + pwidth.bottom;
- }
- return 0;
- }
- function lang (phrase) {
- var translation = this.settings.phrases[phrase];
- if (typeof translation == 'undefined') return phrase; else return translation;
- }
- function locale (locale) {
- if (!locale) locale = 'en-us';
- if (locale.length == 5) locale = 'locale/'+ locale +'.json';
- // load from the file
- $.ajax({
- url : locale,
- type : "GET",
- dataType: "JSON",
- async : false,
- cache : false,
- success : function (data, status, xhr) {
- w2utils.settings = $.extend(true, w2utils.settings, data);
- },
- error : function (xhr, status, msg) {
- console.log('ERROR: Cannot load locale '+ locale);
- }
- });
- }
- function scrollBarSize () {
- if (tmp.scrollBarSize) return tmp.scrollBarSize;
- var html = '<div id="_scrollbar_width" style="position: absolute; top: -300px; width: 100px; height: 100px; overflow-y: scroll;">'+
- ' <div style="height: 120px">1</div>'+
- '</div>';
- $('body').append(html);
- tmp.scrollBarSize = 100 - $('#_scrollbar_width > div').width();
- $('#_scrollbar_width').remove();
- if (String(navigator.userAgent).indexOf('MSIE') >= 0) tmp.scrollBarSize = tmp.scrollBarSize / 2; // need this for IE9+
- return tmp.scrollBarSize;
- }
- })();
- /***********************************************************
- * Generic Event Object
- * --- This object is reused across all other
- * --- widgets in w2ui.
- *
- *********************************************************/
- w2utils.event = {
- on: function (eventData, handler) {
- if (!$.isPlainObject(eventData)) eventData = { type: eventData };
- eventData = $.extend({ type: null, execute: 'before', target: null, onComplete: null }, eventData);
-
- if (typeof eventData.type == 'undefined') { console.log('ERROR: You must specify event type when calling .on() method of '+ this.name); return; }
- if (typeof handler == 'undefined') { console.log('ERROR: You must specify event handler function when calling .on() method of '+ this.name); return; }
- this.handlers.push({ event: eventData, handler: handler });
- },
-
- off: function (eventData, handler) {
- if (!$.isPlainObject(eventData)) eventData = { type: eventData };
- eventData = $.extend({}, { type: null, execute: 'before', target: null, onComplete: null }, eventData);
-
- if (typeof eventData.type == 'undefined') { console.log('ERROR: You must specify event type when calling .off() method of '+ this.name); return; }
- if (typeof handler == 'undefined') { handler = null; }
- // remove handlers
- var newHandlers = [];
- for (var h in this.handlers) {
- var t = this.handlers[h];
- if ( (t.event.type == eventData.type || eventData.type == '*')
- && (t.event.target == eventData.target || eventData.target == null)
- && (t.handler == handler || handler == null)) {
- // match
- } else {
- newHandlers.push(t);
- }
- }
- this.handlers = newHandlers;
- },
-
- trigger: function (eventData) {
- var eventData = $.extend({ type: null, phase: 'before', target: null, isStopped: false, isCancelled: false }, eventData, {
- preventDefault : function () { this.isCancelled = true; },
- stopPropagation : function () { this.isStopped = true; },
- });
- if (typeof eventData.target == 'undefined') eventData.target = null;
- // process events in REVERSE order
- for (var h = this.handlers.length-1; h >= 0; h--) {
- var item = this.handlers[h];
- if ( (item.event.type == eventData.type || item.event.type == '*')
- && (item.event.target == eventData.target || item.event.target == null)
- && (item.event.execute == eventData.phase || item.event.execute == '*' || item.event.phase == '*') ) {
- eventData = $.extend({}, item.event, eventData);
- // check handler arguments
- var args = [];
- var tmp = RegExp(/\((.*?)\)/).exec(item.handler);
- if (tmp) args = tmp[1].split(/\s*,\s*/);
- if (args.length == 2) {
- item.handler.call(this, eventData.target, eventData); // old way for back compatibility
- } else {
- item.handler.call(this, eventData); // new way
- }
- if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true
- }
- }
- // main object events
- var funName = 'on' + eventData.type.substr(0,1).toUpperCase() + eventData.type.substr(1);
- if (eventData.phase == 'before' && typeof this[funName] == 'function') {
- var fun = this[funName];
- // check handler arguments
- var args = [];
- var tmp = RegExp(/\((.*?)\)/).exec(fun);
- if (tmp) args = tmp[1].split(/\s*,\s*/);
- if (args.length == 2) {
- fun.call(this, eventData.target, eventData); // old way for back compatibility
- } else {
- fun.call(this, eventData); // new way
- }
- if (eventData.isStopped === true || eventData.stop === true) return eventData; // back compatibility eventData.stop === true
- }
- // item object events
- if (typeof eventData.object != 'undefined' && eventData.object != null && eventData.phase == 'before'
- && typeof eventData.object[funName] == 'function') {
- var fun = eventData.object[funName];
- // check handler arguments
- var args = [];
- var tmp = RegExp(/\((.*?)\)/).exec(fun);
- if (tmp) args = tmp[1].split(/\s*,\s*/);
- if (args.length == 2) {
- fun.call(this, eventData.target, eventData); // old way for back compatibility
- } else {
- fun.call(this, eventData); // new way
- }
- if (eventData.isStopped === true || eventData.stop === true) return eventData;
- }
- // execute onComplete
- if (eventData.phase == 'after' && eventData.onComplete != null) eventData.onComplete.call(this, eventData);
-
- return eventData;
- }
- };
- /***********************************************************
- * Common Keyboard Handler. Supported in
- * - grid
- * - sidebar
- * - popup
- *
- *********************************************************/
- w2utils.keyboard = (function (obj) {
- // private scope
- var w2ui_name = null;
- obj.active = active;
- obj.clear = clear;
- obj.register = register;
- init();
- return obj;
- function init() {
- $(document).on('keydown', keydown);
- $(document).on('mousedown', mousedown);
- }
- function keydown (event) {
- var tag = event.target.tagName;
- if ($.inArray(tag, ['INPUT', 'SELECT', 'TEXTAREA']) != -1) return;
- if ($(event.target).prop('contenteditable') == 'true') return;
- if (!w2ui_name) return;
- // pass to appropriate widget
- if (w2ui[w2ui_name] && typeof w2ui[w2ui_name].keydown == 'function') {
- w2ui[w2ui_name].keydown.call(w2ui[w2ui_name], event);
- }
- }
- function mousedown (event) {
- var tag = event.target.tagName;
- var obj = $(event.target).parents('.w2ui-reset');
- if (obj.length > 0) {
- w2ui_name = obj.attr('name');
- }
- }
- function active (new_w2ui_name) {
- if (typeof new_w2ui_name == 'undefined') return w2ui_name;
- w2ui_name = new_w2ui_name;
- }
- function clear () {
- w2ui_name = null;
- }
- function register () {
- }
- })({});
- /***********************************************************
- * Commonly used plugins
- * --- used primarily in grid and form
- *
- *********************************************************/
- (function () {
- $.fn.w2render = function (name) {
- if ($(this).length > 0) {
- if (typeof name == 'string' && w2ui[name]) w2ui[name].render($(this)[0]);
- if (typeof name == 'object') name.render($(this)[0]);
- }
- }
- $.fn.w2destroy = function (name) {
- if (!name && this.length > 0) name = this.attr('name');
- if (typeof name == 'string' && w2ui[name]) w2ui[name].destroy();
- if (typeof name == 'object') name.destroy();
- }
- $.fn.w2marker = function (str) {
- if (str == '' || typeof str == 'undefined') { // remove marker
- return $(this).each(function (index, el) {
- el.innerHTML = el.innerHTML.replace(/\<span class=\"w2ui\-marker\"\>(.*)\<\/span\>/ig, '$1'); // unmark
- });
- } else { // add marker
- return $(this).each(function (index, el) {
- if (typeof str == 'string') str = [str];
- el.innerHTML = el.innerHTML.replace(/\<span class=\"w2ui\-marker\"\>(.*)\<\/span\>/ig, '$1'); // unmark
- for (var s in str) {
- var tmp = str[s];
- if (typeof tmp != 'string') tmp = String(tmp);
- // escape regex special chars
- tmp = tmp.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&").replace(/&/g, '&').replace(/</g, '>').replace(/>/g, '<');
- var regex = new RegExp(tmp + '(?!([^<]+)?>)', "gi"); // only outside tags
- el.innerHTML = el.innerHTML.replace(regex, function (matched) { // mark new
- return '<span class="w2ui-marker">' + matched + '</span>';
- });
- }
- });
- }
- }
- // -- w2tag - appears on the right side from element, there can be multiple on screen at a time
- $.fn.w2tag = function (text, options) {
- if (!$.isPlainObject(options)) options = {};
- if (!$.isPlainObject(options.css)) options.css = {};
- if (typeof options['class'] == 'undefined') options['class'] = '';
- // remove all tags
- if ($(this).length == 0) {
- $('.w2ui-tag').each(function (index, elem) {
- var opt = $(elem).data('options');
- if (typeof opt == 'undefined') opt = {};
- $($(elem).data('taged-el')).removeClass( opt['class'] );
- clearInterval($(elem).data('timer'));
- $(elem).remove();
- });
- return;
- }
- return $(this).each(function (index, el) {
- // show or hide tag
- var tagOrigID = el.id;
- var tagID = w2utils.escapeId(el.id);
- if (text == '' || text == null || typeof text == 'undefined') {
- $('#w2ui-tag-'+tagID).css('opacity', 0);
- setTimeout(function () {
- // remmove element
- clearInterval($('#w2ui-tag-'+tagID).data('timer'));
- $('#w2ui-tag-'+tagID).remove();
- }, 300);
- } else {
- // remove elements
- clearInterval($('#w2ui-tag-'+tagID).data('timer'));
- $('#w2ui-tag-'+tagID).remove();
- // insert
- $('body').append('<div id="w2ui-tag-'+ tagOrigID +'" class="w2ui-tag '+ ($(el).parents('.w2ui-popup').length > 0 ? 'w2ui-tag-popup' : '') +'" '+
- ' style=""></div>');
- var timer = setInterval(function () {
- // monitor if destroyed
- if ($(el).length == 0 || ($(el).offset().left == 0 && $(el).offset().top == 0)) {
- clearInterval($('#w2ui-tag-'+tagID).data('timer'));
- tmp_hide();
- return;
- }
- // monitor if moved
- if ($('#w2ui-tag-'+tagID).data('position') != ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top) {
- $('#w2ui-tag-'+tagID).css({
- '-webkit-transition': '.2s',
- '-moz-transition': '.2s',
- '-ms-transition': '.2s',
- '-o-transition': '.2s',
- left: ($(el).offset().left + el.offsetWidth) + 'px',
- top: $(el).offset().top + 'px'
- }).data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top);
- }
- }, 100);
- setTimeout(function () {
- if (!$(el).offset()) return;
- $('#w2ui-tag-'+tagID).css({
- opacity: '1',
- left: ($(el).offset().left + el.offsetWidth) + 'px',
- top: $(el).offset().top + 'px'
- }).html('<div style="margin-top: -2px 0px 0px -2px; white-space: nowrap;"> <div class="w2ui-tag-body">'+ text +'</div> </div>')
- .data('text', text)
- .data('taged-el', el)
- .data('options', options)
- .data('position', ($(el).offset().left + el.offsetWidth) + 'x' + $(el).offset().top)
- .data('timer', timer);
- $(el).off('keypress', tmp_hide).on('keypress', tmp_hide).off('change', tmp_hide).on('change', tmp_hide)
- .css(options.css).addClass(options['class']);
- if (typeof options.onShow == 'function') options.onShow();
- }, 1);
- var originalCSS = '';
- if ($(el).length > 0) originalCSS = $(el)[0].style.cssText;
- // bind event to hide it
- function tmp_hide() {
- if ($('#w2ui-tag-'+tagID).length <= 0) return;
- clearInterval($('#w2ui-tag-'+tagID).data('timer'));
- $('#w2ui-tag-'+tagID).remove();
- $(el).off('keypress', tmp_hide).removeClass(options['class']);
- if ($(el).length > 0) $(el)[0].style.cssText = originalCSS;
- if (typeof options.onHide == 'function') options.onHide();
- }
- }
- });
- }
-
- // w2overlay - appears under the element, there can be only one at a time
- $.fn.w2overlay = function (html, options) {
- if (!$.isPlainObject(options)) options = {};
- if (!$.isPlainObject(options.css)) options.css = {};
- if (this.length == 0 || html == '' || typeof html == 'undefined') { hide(); return $(this); }
- if ($('#w2ui-overlay').length > 0) $(document).click();
- $('body').append('<div id="w2ui-overlay" class="w2ui-reset w2ui-overlay '+
- ($(this).parents('.w2ui-popup').length > 0 ? 'w2ui-overlay-popup' : '') +'">'+
- ' <div></div>'+
- '</div>');
- // init
- var obj = this;
- var div = $('#w2ui-overlay div');
- div.css(options.css).html(html);
- if (typeof options['class'] != 'undefined') div.addClass(options['class']);
- if (typeof options.top == 'undefined') options.top = 0;
- if (typeof options.left == 'undefined') options.left = 0;
- if (typeof options.width == 'undefined') options.width = 100;
- if (typeof options.height == 'undefined') options.height = 0;
- // pickup bg color of first div
- var bc = div.css('background-color');
- var div = $('#w2ui-overlay');
- if (typeof bc != 'undefined' && bc != 'rgba(0, 0, 0, 0)' && bc != 'transparent') div.css('background-color', bc);
- div.css({
- display : 'none',
- left : ($(obj).offset().left + options.left) + 'px',
- top : ($(obj).offset().top + w2utils.getSize($(obj), 'height') + 3 + options.top) + 'px',
- 'min-width' : (options.width ? options.width : 'auto'),
- 'min-height' : (options.height ? options.height : 'auto')
- })
- .fadeIn('fast')
- .data('position', ($(obj).offset().left) + 'x' + ($(obj).offset().top + obj.offsetHeight))
- .on('click', function (event) {
- if (event.stopPropagation) event.stopPropagation(); else event.cancelBubble = true;
- });
- // click anywhere else hides the drop down
- function hide () {
- var result;
- if (typeof options.onHide == 'function') result = options.onHide();
- if (result === false) return;
- $('#w2ui-overlay').remove();
- $(document).off('click', hide);
- }
- // need time to display
- setTimeout(fixSize, 0);
- return $(this);
- function fixSize () {
- $(document).on('click', hide);
- // if goes over the screen, limit height and width
- if ( $('#w2ui-overlay > div').length > 0) {
- var h = $('#w2ui-overlay > div').height();
- var w = $('#w2ui-overlay> div').width();
- // $(window).height() - has a problem in FF20
- var max = window.innerHeight - $('#w2ui-overlay > div').offset().top - 7;
- if (h > max) $('#w2ui-overlay> div').height(max).width(w + w2utils.scrollBarSize()).css({ 'overflow-y': 'auto' });
- // check width
- w = $('#w2ui-overlay> div').width();
- max = window.innerWidth - $('#w2ui-overlay > div').offset().left - 7;
- if (w > max) $('#w2ui-overlay> div').width(max).css({ 'overflow-x': 'auto' });
- // onShow event
- if (typeof options.onShow == 'function') options.onShow();
- }
- }
- }
- $.fn.w2menu = function (menu, options) {
- if (typeof options.select == 'undefined' && typeof options.onSelect == 'function') options.select = options.onSelect;
- if (typeof options.select != 'function') {
- console.log('ERROR: options.select is required to be a function, not '+ typeof options.select + ' in $().w2menu(menu, options)');
- return $(this);
- }
- if (!$.isArray(menu)) {
- console.log('ERROR: first parameter should be an array of objects or strings in $().w2menu(menu, options)');
- return $(this);
- }
- // since only one overlay can exist at a time
- $.fn.w2menuHandler = function (event, index) {
- options.select(menu[index], event, index);
- }
- return $(this).w2overlay(getMenuHTML(), options);
- function getMenuHTML () {
- var menu_html = '<table cellspacing="0" cellpadding="0" class="w2ui-drop-menu">';
- for (var f = 0; f < menu.length; f++) {
- var mitem = menu[f];
- if (typeof mitem == 'string') {
- var tmp = mitem.split('|');
- // 1 - id, 2 - text, 3 - image, 4 - icon
- mitem = { id: tmp[0], text: tmp[0], img: null, icon: null };
- if (tmp[1]) mitem.text = tmp[1];
- if (tmp[2]) mitem.img = tmp[2];
- if (tmp[3]) mitem.icon = tmp[3];
- } else {
- if (typeof mitem.text != 'undefined' && typeof mitem.id == 'undefined') mitem.id = mitem.text;
- if (typeof mitem.text == 'undefined' && typeof mitem.id != 'undefined') mitem.text = mitem.id;
- if (typeof mitem.caption != 'undefined') mitem.text = mitem.caption;
- if (typeof mitem.img == 'undefined') mitem.img = null;
- if (typeof mitem.icon == 'undefined') mitem.icon = null;
- }
- var img = '<td> </td>';
- if (mitem.img) img = '<td><div class="w2ui-tb-image w2ui-icon '+ mitem.img +'"></div></td>';
- if (mitem.icon) img = '<td align="center"><div class="w2ui-tb-image"><span class="'+ mitem.icon +'"></span></div></td>';
- menu_html +=
- '<tr onmouseover="$(this).addClass(\'w2ui-selected\');" onmouseout="$(this).removeClass(\'w2ui-selected\');" '+
- ' onclick="$(document).click(); $.fn.w2menuHandler(event, \''+ f +'\');">'+
- img +
- ' <td>'+ mitem.text +'</td>'+
- '</tr>';
- }
- menu_html += "</table>";
- return menu_html;
- }
- }
- })();
- /************************************************************************
- * Library: Web 2.0 UI for jQuery (using prototypical inheritance)
- * - Following objects defined
- * - w2grid - grid widget
- * - $().w2grid - jQuery wrapper
- * - Dependencies: jQuery, w2utils, w2toolbar, w2fields, w2alert, w2confirm
- *
- * == NICE TO HAVE ==
- * - global search apply types and drop downs
- * - editable fields (list) - better inline editing
- * - frozen columns
- * - column autosize based on largest content
- * - save grid state into localStorage and restore
- * - easy bubbles in the grid
- * - possibly add context menu similar to sidebar's
- * - Merged cells
- * - More than 2 layers of header groups
- * - for search fields one should be able to pass w2field options
- * - add enum to advanced search fields
- * - be able to attach events in advanced search dialog
- * - reorder columns/records
- * - hidden searches could not be clearned by the user
- *
- ************************************************************************/
- (function () {
- var w2grid = function(options) {
- // public properties
- this.name = null;
- this.box = null; // HTML element that hold this element
- this.header = '';
- this.url = '';
- this.columns = []; // { field, caption, size, attr, render, hidden, gridMinWidth, [editable: {type, inTag, outTag, style, items}] }
- this.columnGroups = []; // { span: int, caption: 'string', master: true/false }
- this.records = []; // { recid: int(requied), field1: 'value1', ... fieldN: 'valueN', style: 'string', editable: true/false, summary: true/false, changed: true/false, changes: object }
- this.summary = []; // arry of summary records, same structure as records array
- this.searches = []; // { type, caption, field, inTag, outTag, default, items, hidden }
- this.searchData = [];
- this.sortData = [];
- this.postData = {};
- this.toolbar = {}; // if not empty object; then it is toolbar object
- this.show = {
- header : false,
- toolbar : false,
- footer : false,
- columnHeaders : true,
- lineNumbers : false,
- expandColumn : false,
- selectColumn : false,
- emptyRecords : true,
- toolbarReload : true,
- toolbarColumns : true,
- toolbarSearch : true,
- toolbarAdd : false,
- toolbarEdit : false,
- toolbarDelete : false,
- toolbarSave : false,
- selectionBorder : true,
- recordTitles : true
- }
- this.autoLoad = true; // for infinite scroll
- this.fixedBody = true; // if false; then grid grows with data
- this.recordHeight = 24;
- this.keyboard = true;
- this.selectType = 'row'; // can be row|cell
- this.multiSearch = true;
- this.multiSelect = true;
- this.multiSort = true;
- this.markSearchResults = true;
- this.total = 0; // server total
- this.buffered = 0; // number of records in the records array
- this.limit = 100;
- this.offset = 0; // how many records to skip (for infinite scroll) when pulling from server
- this.style = '';
- this.ranges = [];
- // events
- this.onAdd = null;
- this.onEdit = null;
- this.onRequest = null; // called on any server event
- this.onLoad = null;
- this.onDelete = null;
- this.onDeleted = null
- this.onSave = null;
- this.onSaved = null;
- this.onSelect = null;
- this.onUnselect = null;
- this.onClick = null;
- this.onDblClick = null;
- this.onColumnClick = null;
- this.onColumnResize = null;
- this.onSort = null;
- this.onSearch = null;
- this.onChange = null; // called when editable record is changed
- this.onExpand = null;
- this.onCollapse = null;
- this.onError = null;
- this.onKeydown = null;
- this.onToolbar = null; // all events from toolbar
- this.onColumnOnOff = null;
- this.onCopy = null;
- this.onPaste = null;
- this.onSelectionExtend = null;
- this.onEditField = null;
- this.onRender = null;
- this.onRefresh = null;
- this.onReload = null;
- this.onResize = null;
- this.onDestroy = null;
- // internal
- this.last = {
- field : 'all',
- caption : w2utils.lang('All Fields'),
- logic : 'OR',
- search : '',
- searchIds : [],
- multi : false,
- scrollTop : 0,
- scrollLeft : 0,
- selected : [],
- sortData : null,
- sortCount : 0,
- xhr : null,
- range_start : null,
- range_end : null,
- sel_ind : null,
- sel_col : null,
- sel_type : null
- }
- this.isIOS = (navigator.userAgent.toLowerCase().indexOf('iphone') != -1 ||
- navigator.userAgent.toLowerCase().indexOf('ipod') != -1 ||
- navigator.userAgent.toLowerCase().indexOf('ipad') != -1) ? true : false;
- $.extend(true, this, w2obj.grid, options);
- };
- // ====================================================
- // -- Registers as a jQuery plugin
- $.fn.w2grid = function(method) {
- if (typeof method === 'object' || !method ) {
- // check required parameters
- if (!method || typeof method.name == 'undefined') {
- console.log('ERROR: The parameter "name" is required but not supplied in $().w2grid().');
- return;
- }
- if (typeof w2ui[method.name] != 'undefined') {
- console.log