diff --git a/Account/AccountManager.js b/Account/AccountManager.js index a6c2b3d..f3a829b 100644 --- a/Account/AccountManager.js +++ b/Account/AccountManager.js @@ -12,67 +12,70 @@ jsOMS.Autoloader.defineNamespace('jsOMS.Account'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Account.AccountManager = function () - { - this.accounts = []; - }; + + jsOMS.Account.AccountManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () + { + this.accounts = []; + }; - /** - * Add account. - * - * @param {Object} account Account - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Account.AccountManager.prototype.add = function (account) - { - this.accounts[account.getId()] = account; - }; + /** + * Add account. + * + * @param {Object} account Account + * + * @method + * + * @since 1.0.0 + */ + add (account) + { + this.accounts[account.getId()] = account; + }; - /** - * Remove account. - * - * @param {int} id Account id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Account.AccountManager.prototype.remove = function (id) - { - if (typeof this.accounts[id] !== 'undefined') { - delete this.accounts[id]; + /** + * Remove account. + * + * @param {int} id Account id + * + * @method + * + * @since 1.0.0 + */ + remove (id) + { + if (typeof this.accounts[id] !== 'undefined') { + delete this.accounts[id]; - return true; - } + return true; + } - return false; - }; + return false; + }; - /** - * Get account by id. - * - * @param {int} id Account id - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Account.AccountManager.prototype.get = function (id) - { - if (this.accounts[id]) { - return this.accounts[id]; - } + /** + * Get account by id. + * + * @param {int} id Account id + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + get (id) + { + if (this.accounts[id]) { + return this.accounts[id]; + } - return undefined; - }; + return undefined; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Animation/Canvas/Particle.js b/Animation/Canvas/Particle.js index e6d11c4..cde4317 100644 --- a/Animation/Canvas/Particle.js +++ b/Animation/Canvas/Particle.js @@ -13,117 +13,119 @@ /** @namespace jsOMS.Animation.Canvas */ jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Canvas'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.Particle = function (posX, posY, velX, velY, radius) - { - this.posX = posX; - this.posY = posY; - this.velX = velX; - this.velY = velY; + jsOMS.Animation.Canvas.Particle = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (posX, posY, velX, velY, radius) + { + this.posX = posX; + this.posY = posY; + this.velX = velX; + this.velY = velY; - this.radius = radius; + this.radius = radius; - this.color = {r: 255, g: 255, b: 255, a: 0.5}; - }; + this.color = {r: 255, g: 255, b: 255, a: 0.5}; + }; - /** - * Get particle radius - * - * @return {int} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.Particle.prototype.getRadius = function () - { - return this.radius; - }; + /** + * Get particle radius + * + * @return {int} + * + * @method + * + * @since 1.0.0 + */ + getRadius () + { + return this.radius; + }; - /** - * Set particle position - * - * @param {int} posX Position x - * @param {int} posY Position y - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.Particle.prototype.setPosition = function (posX, posY) - { - this.posX = posX; - this.posY = posY; - }; + /** + * Set particle position + * + * @param {int} posX Position x + * @param {int} posY Position y + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + setPosition (posX, posY) + { + this.posX = posX; + this.posY = posY; + }; - /** - * Get position - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.Particle.prototype.getPosition = function () - { - return {x: this.posX, y: this.posY}; - }; + /** + * Get position + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getPosition () + { + return {x: this.posX, y: this.posY}; + }; - /** - * Set particle velocity - * - * @param {float} velX Velocity x - * @param {float} velY Velocity y - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.Particle.prototype.setVelocity = function (velX, velY) - { - this.velX = velX; - this.velY = velY; - }; + /** + * Set particle velocity + * + * @param {float} velX Velocity x + * @param {float} velY Velocity y + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + setVelocity (velX, velY) + { + this.velX = velX; + this.velY = velY; + }; - /** - * Get velocity - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.Particle.prototype.getVelocity = function () - { - return {x: this.velX, y: this.velY}; - }; + /** + * Get velocity + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getVelocity () + { + return {x: this.velX, y: this.velY}; + }; - /** - * Draw particle to canvas - * - * @param {object} ctx Canvas - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.Particle.prototype.draw = function (ctx) - { - ctx.fillStyle = 'rgba(' + this.color.r + ', ' + this.color.g + ', ' + this.color.b + ', ' + this.color.a + ')'; - ctx.beginPath(); - ctx.arc(this.posX, this.posY, this.radius, 0, Math.PI * 2, false); - ctx.fill(); - }; + /** + * Draw particle to canvas + * + * @param {object} ctx Canvas + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + draw (ctx) + { + ctx.fillStyle = 'rgba(' + this.color.r + ', ' + this.color.g + ', ' + this.color.b + ', ' + this.color.a + ')'; + ctx.beginPath(); + ctx.arc(this.posX, this.posY, this.radius, 0, Math.PI * 2, false); + ctx.fill(); + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Animation/Canvas/ParticleAnimation.js b/Animation/Canvas/ParticleAnimation.js index 4e53ed7..2637d09 100644 --- a/Animation/Canvas/ParticleAnimation.js +++ b/Animation/Canvas/ParticleAnimation.js @@ -13,176 +13,178 @@ /** @namespace jsOMS.Animation.Canvas */ jsOMS.Autoloader.defineNamespace('jsOMS.Animation.Canvas'); - /** - * - * @param {object} canvas Canvas - * - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.ParticleAnimation = function (canvas) - { - this.canvas = canvas; - this.ctx = canvas.getContext('2d'); - - /** global: screen */ - this.width = screen.width; - this.height = screen.height; - - this.canvas.width = this.width; - this.canvas.height = this.height; - - this.particles = []; - this.maxDistance = 70; - this.gravitation = 10000000; - - for (let i = 0; i < this.width * this.height / 3000; ++i) { - this.particles.push(new jsOMS.Animation.Canvas.Particle( - Math.random() * this.width, - Math.random() * this.height, - -1 + Math.random() * 2, - -1 + Math.random() * 2, - 1 - )); - } - }; - - /** - * Draw everything - * - * @param {object} self Object reference for self invoke - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.ParticleAnimation.prototype.draw = function (self) - { - self = typeof self !== 'undefined' ? self : this; - self.invalidate(); - - const length = self.particles.length; - - for (let i = 0; i < length; ++i) { - self.particles[i].draw(self.ctx); - } - - self.updateParticles(); - jsOMS.Animation.Animation.requestAnimationFrame.call(window, function () + jsOMS.Animation.Canvas.ParticleAnimation = class { + /** + * + * @param {object} canvas Canvas + * + * @constructor + * + * @since 1.0.0 + */ + constructor (canvas) { - self.draw(self); - }); - }; + this.canvas = canvas; + this.ctx = canvas.getContext('2d'); - /** - * Invalidate/clean canvas - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.ParticleAnimation.prototype.invalidate = function () - { - this.ctx.clearRect(0, 0, this.width, this.height); - }; + /** global: screen */ + this.width = screen.width; + this.height = screen.height; - /** - * Update particle - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.ParticleAnimation.prototype.updateParticles = function () - { - let particle, - pos, - vel, - radius; + this.canvas.width = this.width; + this.canvas.height = this.height; - const length = this.particles.length; + this.particles = []; + this.maxDistance = 70; + this.gravitation = 10000000; - for (let i = 0; i < length; ++i) { - particle = this.particles[i]; - pos = particle.getPosition(); - vel = particle.getVelocity(); - radius = particle.getRadius(); + for (let i = 0; i < this.width * this.height / 3000; ++i) { + this.particles.push(new jsOMS.Animation.Canvas.Particle( + Math.random() * this.width, + Math.random() * this.height, + -1 + Math.random() * 2, + -1 + Math.random() * 2, + 1 + )); + } + }; - pos.x += vel.x; - pos.y += vel.y; + /** + * Draw everything + * + * @param {object} self Object reference for self invoke + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + draw (self) + { + self = typeof self !== 'undefined' ? self : this; + self.invalidate(); - // Change on wall hit - if (pos.x + radius > this.width) { - pos.x = radius; - } else if (pos.x - radius < 0) { - pos.x = this.width - radius; + const length = self.particles.length; + + for (let i = 0; i < length; ++i) { + self.particles[i].draw(self.ctx); } - if (pos.y + radius > this.height) { - pos.y = radius; - } else if (pos.y - radius < 0) { - pos.y = this.height - radius; + self.updateParticles(); + jsOMS.Animation.Animation.requestAnimationFrame.call(window, function () + { + self.draw(self); + }); + }; + + /** + * Invalidate/clean canvas + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + invalidate () + { + this.ctx.clearRect(0, 0, this.width, this.height); + }; + + /** + * Update particle + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + updateParticles () + { + let particle, + pos, + vel, + radius; + + const length = this.particles.length; + + for (let i = 0; i < length; ++i) { + particle = this.particles[i]; + pos = particle.getPosition(); + vel = particle.getVelocity(); + radius = particle.getRadius(); + + pos.x += vel.x; + pos.y += vel.y; + + // Change on wall hit + if (pos.x + radius > this.width) { + pos.x = radius; + } else if (pos.x - radius < 0) { + pos.x = this.width - radius; + } + + if (pos.y + radius > this.height) { + pos.y = radius; + } else if (pos.y - radius < 0) { + pos.y = this.height - radius; + } + + particle.setPosition(pos.x, pos.y); + particle.setVelocity(vel.x, vel.y); + + for (let j = i + 1; j < length; ++j) { + this.updateDistance(particle, this.particles[j]); + } } + }; - particle.setPosition(pos.x, pos.y); - particle.setVelocity(vel.x, vel.y); + /** + * Handle distance between particles + * + * @param {Particle} p1 Particle + * @param {Particle} p2 Particle + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + updateDistance (p1, p2) + { + const pos1 = p1.getPosition(), + pos2 = p2.getPosition(), + dx = pos1.x - pos2.x, + dy = pos1.y - pos2.y, + dist = Math.sqrt(dx * dx + dy * dy); - for (let j = i + 1; j < length; ++j) { - this.updateDistance(particle, this.particles[j]); + let vel1 = p1.getVelocity(), + vel2 = p2.getVelocity(); + + // Draw line if particles are close + if (dist <= this.maxDistance) { + this.ctx.beginPath(); + this.ctx.strokeStyle = 'rgba(255, 255, 255, ' + ((1.2 - dist / this.maxDistance) * 0.5) + ')'; + this.ctx.moveTo(pos1.x, pos1.y); + this.ctx.lineTo(pos2.x, pos2.y); + this.ctx.stroke(); + this.ctx.closePath(); + + // Accelerate based on distance (no acceleration yet) + let ax = dx / this.gravitation, + ay = dy / this.gravitation; + + vel1.x -= ax; + vel1.y -= ay; + p1.setVelocity(vel1.x, vel1.y); + + vel2.x -= ax; + vel2.y -= ay; + p2.setVelocity(vel2.x, vel2.y); } - } - }; - - /** - * Handle distance between particles - * - * @param {Particle} p1 Particle - * @param {Particle} p2 Particle - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Animation.Canvas.ParticleAnimation.prototype.updateDistance = function (p1, p2) - { - const pos1 = p1.getPosition(), - pos2 = p2.getPosition(), - dx = pos1.x - pos2.x, - dy = pos1.y - pos2.y, - dist = Math.sqrt(dx * dx + dy * dy); - - let vel1 = p1.getVelocity(), - vel2 = p2.getVelocity(); - - // Draw line if particles are close - if (dist <= this.maxDistance) { - this.ctx.beginPath(); - this.ctx.strokeStyle = 'rgba(255, 255, 255, ' + ((1.2 - dist / this.maxDistance) * 0.5) + ')'; - this.ctx.moveTo(pos1.x, pos1.y); - this.ctx.lineTo(pos2.x, pos2.y); - this.ctx.stroke(); - this.ctx.closePath(); - - // Accelerate based on distance (no acceleration yet) - let ax = dx / this.gravitation, - ay = dy / this.gravitation; - - vel1.x -= ax; - vel1.y -= ay; - p1.setVelocity(vel1.x, vel1.y); - - vel2.x -= ax; - vel2.y -= ay; - p2.setVelocity(vel2.x, vel2.y); - } - }; + }; + } }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Asset/AssetManager.js b/Asset/AssetManager.js index 16865bf..fc9d61d 100644 --- a/Asset/AssetManager.js +++ b/Asset/AssetManager.js @@ -12,157 +12,159 @@ jsOMS.Asset = {}; - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Asset.AssetManager = function () - { - this.assets = {}; - this.registerLoadedAssets(); - }; + jsOMS.Asset.AssetManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () + { + this.assets = {}; + this.registerLoadedAssets(); + }; - /** - * Register all loaded assets. - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Asset.AssetManager.prototype.registerLoadedAssets = function () - { - const scripts = document.getElementsByTagName('script'), - length = !scripts ? 0 : scripts.length; + /** + * Register all loaded assets. + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + registerLoadedAssets () + { + const scripts = document.getElementsByTagName('script'), + length = !scripts ? 0 : scripts.length; - this.assets = {}; + this.assets = {}; - for (let i = 0; i < length; ++i) { - this.assets[jsOMS.hash(scripts[i].src)] = scripts[i].src; - } - }; + for (let i = 0; i < length; ++i) { + this.assets[jsOMS.hash(scripts[i].src)] = scripts[i].src; + } + }; - /** - * Load asset. - * - * @param {string} path Asset path - * @param {string} filetype Filetype of the asset - * @param {requestCallback} [callback] Callback after load - * - * @return {string|boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Asset.AssetManager.prototype.load = function (path, filetype, callback) - { - let hash; + /** + * Load asset. + * + * @param {string} path Asset path + * @param {string} filetype Filetype of the asset + * @param {requestCallback} [callback] Callback after load + * + * @return {string|boolean} + * + * @method + * + * @since 1.0.0 + */ + load (path, filetype, callback) + { + let hash; - if (!this.assets[(hash = jsOMS.hash(path))]) { - let fileref = null; + if (!this.assets[(hash = jsOMS.hash(path))]) { + let fileref = null; - if (filetype === 'js') { - fileref = document.createElement('script'); - fileref.setAttribute('type', 'text/javascript'); - fileref.setAttribute('src', path); + if (filetype === 'js') { + fileref = document.createElement('script'); + fileref.setAttribute('type', 'text/javascript'); + fileref.setAttribute('src', path); - if (typeof fileref !== 'undefined') { - const head = document.getElementsByTagName('head'); + if (typeof fileref !== 'undefined') { + const head = document.getElementsByTagName('head'); - if (head) { - head[0].appendChild(fileref); + if (head) { + head[0].appendChild(fileref); + } } + + this.assets[hash] = path; + } else if (filetype === 'css') { + fileref = document.createElement('link'); + fileref.setAttribute('rel', 'stylesheet'); + fileref.setAttribute('type', 'text/css'); + fileref.setAttribute('href', path); + + if (typeof fileref !== 'undefined') { + const head = document.getElementsByTagName('head'); + + if (head) { + head[0].appendChild(fileref); + } + } + + this.assets[hash] = path; + } else if (filetype === 'img') { + /** global: Image */ + this.assets[hash] = new Image(); + this.assets[hash].src = path; + } else if (filetype === 'audio') { + // TODO: implement audio asset + } else if (filetype === 'video') { + // TODO: implement video asset } - this.assets[hash] = path; - } else if (filetype === 'css') { - fileref = document.createElement('link'); - fileref.setAttribute('rel', 'stylesheet'); - fileref.setAttribute('type', 'text/css'); - fileref.setAttribute('href', path); + if (callback) { + fileref.onreadystatechange () + { + if (this.readyState === 'complete') { + callback(); + } + }; - if (typeof fileref !== 'undefined') { - const head = document.getElementsByTagName('head'); - - if (head) { - head[0].appendChild(fileref); - } + fileref.onload = callback(); } - this.assets[hash] = path; - } else if (filetype === 'img') { - /** global: Image */ - this.assets[hash] = new Image(); - this.assets[hash].src = path; - } else if (filetype === 'audio') { - // TODO: implement audio asset - } else if (filetype === 'video') { - // TODO: implement video asset + return hash; } - if (callback) { - fileref.onreadystatechange = function () - { - if (this.readyState === 'complete') { - callback(); - } - }; + return false; + }; - fileref.onload = callback(); + /** + * Get asset. + * + * @param {string} key Key of the asset + * + * @return + * + * @method + * + * @since 1.0.0 + */ + get (key) + { + key = jsOMS.hash(key); + + if (this.assets[key]) { + return this.assets[key]; } - return hash; - } + return null; + }; - return false; - }; + /** + * Remove asset. + * + * @param {string} key Key of the asset + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + remove (key) + { + key = jsOMS.hash(key); - /** - * Get asset. - * - * @param {string} key Key of the asset - * - * @return - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Asset.AssetManager.prototype.get = function (key) - { - key = jsOMS.hash(key); + if (typeof this.assets[key] !== 'undefined') { + delete this.assets[key]; - if (this.assets[key]) { - return this.assets[key]; - } + return true; + } - return null; - }; - - /** - * Remove asset. - * - * @param {string} key Key of the asset - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Asset.AssetManager.prototype.remove = function (key) - { - key = jsOMS.hash(key); - - if (typeof this.assets[key] !== 'undefined') { - delete this.assets[key]; - - return true; - } - - return false; + return false; + }; }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Auth/Auth.js b/Auth/Auth.js index 2b9f09a..8bf9913 100644 --- a/Auth/Auth.js +++ b/Auth/Auth.js @@ -12,88 +12,90 @@ jsOMS.Autoloader.defineNamespace('jsOMS.Auth'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Auth.Auth = function (uri) - { - this.account = null; - this.uri = uri; - }; - - /** - * Set account for authentication. - * - * @param {Object} account Account - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Auth.Auth.prototype.setAccount = function (account) - { - this.account = account; - }; - - /** - * Get account. - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Auth.Auth.prototype.getAccount = function () - { - return this.account; - }; - - /** - * Login account. - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Auth.Auth.prototype.login = function () - { - const authRequest = new jsOMS.Message.Request.Request(); - authRequest.setUri(this.uri); - authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST); - authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON); - authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); - authRequest.setSuccess(function (xhr) + jsOMS.Auth.Auth = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (uri) { - this.loginResult(xhr); - }); + this.account = null; + this.uri = uri; + }; - authRequest.send(); - }; + /** + * Set account for authentication. + * + * @param {Object} account Account + * + * @method + * + * @since 1.0.0 + */ + setAccount (account) + { + this.account = account; + }; - /** - * Logout account. - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Auth.Auth.prototype.logout = function () - { - location.reload(); - }; + /** + * Get account. + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getAccount () + { + return this.account; + }; - /** - * Handle login result. - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Auth.Auth.prototype.loginResult = function (xhr) - { - location.reload(); + /** + * Login account. + * + * @method + * + * @since 1.0.0 + */ + login () + { + const authRequest = new jsOMS.Message.Request.Request(); + authRequest.setUri(this.uri); + authRequest.setMethod(jsOMS.Message.Request.RequestMethod.POST); + authRequest.setResponseType(jsOMS.Message.Request.RequestType.JSON); + authRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); + authRequest.setSuccess(function (xhr) + { + this.loginResult(xhr); + }); + + authRequest.send(); + }; + + /** + * Logout account. + * + * @method + * + * @since 1.0.0 + */ + logout () + { + location.reload(); + }; + + /** + * Handle login result. + * + * @method + * + * @since 1.0.0 + */ + loginResult (xhr) + { + location.reload(); + }; }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Config/Options.js b/Config/Options.js index 56eb7f7..83bc3d4 100644 --- a/Config/Options.js +++ b/Config/Options.js @@ -16,79 +16,81 @@ /** @namespace jsOMS.Config */ jsOMS.Autoloader.defineNamespace('jsOMS.Config'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Config.Options = function () - { - this.options = {}; - }; + jsOMS.Config.Options = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () + { + this.options = {}; + }; - /** - * Set option. - * - * @param {int|string} key Option key - * @param {boolean|int|float|string|Array} value Option value - * @param {boolean} [overwrite] Overwrite value - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Config.Options.prototype.set = function (key, value, overwrite = false) - { - if (overwrite || typeof this.options[key] === 'undefined') { - this.options[key] = value; + /** + * Set option. + * + * @param {int|string} key Option key + * @param {boolean|int|float|string|Array} value Option value + * @param {boolean} [overwrite] Overwrite value + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + set (key, value, overwrite = false) + { + if (overwrite || typeof this.options[key] === 'undefined') { + this.options[key] = value; - return true; - } + return true; + } - return false; - }; + return false; + }; - /** - * Get option. - * - * @param {int|string} key Option key - * - * @return {boolean|int|float|string|Array} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Config.Options.prototype.get = function (key) - { - if (typeof this.options[key] !== 'undefined') { - return this.options[key]; - } + /** + * Get option. + * + * @param {int|string} key Option key + * + * @return {boolean|int|float|string|Array} + * + * @method + * + * @since 1.0.0 + */ + get (key) + { + if (typeof this.options[key] !== 'undefined') { + return this.options[key]; + } - return null; - }; + return null; + }; - /** - * Remove option. - * - * @param {int|string} key Option key - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Config.Options.prototype.remove = function (key) - { - if (typeof this.options[key] !== 'undefined') { - delete this.options[key]; + /** + * Remove option. + * + * @param {int|string} key Option key + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + remove (key) + { + if (typeof this.options[key] !== 'undefined') { + delete this.options[key]; - return true; - } + return true; + } - return false; - }; + return false; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/DataStorage/CacheManager.js b/DataStorage/CacheManager.js index 27eeae6..f4d2eae 100644 --- a/DataStorage/CacheManager.js +++ b/DataStorage/CacheManager.js @@ -4,7 +4,11 @@ jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); // TODO: create comments - jsOMS.DataStorage.CacheManager = function () - { + + jsOMS.DataStorage.CacheManager = class { + constructor () + { + + } }; }(window.jsOMS = window.jsOMS || {})); diff --git a/DataStorage/CookieJar.js b/DataStorage/CookieJar.js index dd8b06e..207205b 100644 --- a/DataStorage/CookieJar.js +++ b/DataStorage/CookieJar.js @@ -17,71 +17,73 @@ * * @since 1.0.0 */ - jsOMS.DataStorage.CookieJar = function () - { - }; - - /** - * Saving data to cookie - * - * @param {string} cName Cookie name - * @param {string} value Value to save - * @param {number} exdays Lifetime for the cookie - * @param {string} domain Domain for the cookie - * @param {string} path Path for the cookie - * - * @return array - * - * @method - * - * @since 1.0.0 - */ - jsOMS.DataStorage.CookieJar.prototype.setCookie = function (cName, value, exdays, domain, path) - { - const exdate = new Date(); - exdate.setDate(exdate.getDate() + exdays); - - const cValue = encodeURI(value) - + ((exdays === null) ? "" : "; expires=" - + exdate.toUTCString()) + ";domain=" - + domain + ";path=" - + path; - - document.cookie = cName + "=" + cValue; - }; - - /** - * Loading cookie data - * - * @param {string} cName Cookie name - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.DataStorage.CookieJar.prototype.getCookie = function (cName) - { - let cValue = document.cookie, - cStart = cValue.indexOf(" " + cName + "="); - - if (cStart === -1) { - cStart = cValue.indexOf(cName + "="); + jsOMS.DataStorage.CookieJar = class { + constructor () + { } - if (cStart === -1) { - cValue = null; - } else { - cStart = cValue.indexOf("=", cStart) + 1; - let cEnd = cValue.indexOf(";", cStart); + /** + * Saving data to cookie + * + * @param {string} cName Cookie name + * @param {string} value Value to save + * @param {number} exdays Lifetime for the cookie + * @param {string} domain Domain for the cookie + * @param {string} path Path for the cookie + * + * @return array + * + * @method + * + * @since 1.0.0 + */ + setCookie (cName, value, exdays, domain, path) + { + const exdate = new Date(); + exdate.setDate(exdate.getDate() + exdays); - if (cEnd === -1) { - cEnd = cValue.length; + const cValue = encodeURI(value) + + ((exdays === null) ? "" : "; expires=" + + exdate.toUTCString()) + ";domain=" + + domain + ";path=" + + path; + + document.cookie = cName + "=" + cValue; + }; + + /** + * Loading cookie data + * + * @param {string} cName Cookie name + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getCookie (cName) + { + let cValue = document.cookie, + cStart = cValue.indexOf(" " + cName + "="); + + if (cStart === -1) { + cStart = cValue.indexOf(cName + "="); } - cValue = decodeURI(cValue.substring(cStart, cEnd)); - } - return cValue; + if (cStart === -1) { + cValue = null; + } else { + cStart = cValue.indexOf("=", cStart) + 1; + let cEnd = cValue.indexOf(";", cStart); + + if (cEnd === -1) { + cEnd = cValue.length; + } + + cValue = decodeURI(cValue.substring(cStart, cEnd)); + } + return cValue; + }; }; }(window.jsOMS = window.jsOMS || {})); diff --git a/DataStorage/LocalStorage.js b/DataStorage/LocalStorage.js index 139950c..9e790cb 100644 --- a/DataStorage/LocalStorage.js +++ b/DataStorage/LocalStorage.js @@ -12,30 +12,32 @@ jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.DataStorage.LocalStorage = function () - { - }; + jsOMS.DataStorage.LocalStorage = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () + { + }; - /** - * Is local storage available? - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.DataStorage.LocalStorage.prototype.available = function () - { - try { - return 'localStorage' in window && window.localStorage !== null; - } catch (e) { - return false; - } - }; + /** + * Is local storage available? + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + available () + { + try { + return 'localStorage' in window && window.localStorage !== null; + } catch (e) { + return false; + } + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/DataStorage/StorageManager.js b/DataStorage/StorageManager.js index 269b3ce..94e4501 100644 --- a/DataStorage/StorageManager.js +++ b/DataStorage/StorageManager.js @@ -3,7 +3,9 @@ jsOMS.Autoloader.defineNamespace('jsOMS.DataStorage'); - jsOMS.DataStorage.StorageManager = function () - { - }; + jsOMS.DataStorage.StorageManager = class { + constructor () + { + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Dispatcher/Dispatcher.js b/Dispatcher/Dispatcher.js index 173c876..0d5ea62 100644 --- a/Dispatcher/Dispatcher.js +++ b/Dispatcher/Dispatcher.js @@ -3,7 +3,9 @@ jsOMS.Autoloader.defineNamespace('jsOMS.Dispatcher'); - jsOMS.Dispatcher.Dispatcher = function () - { - }; + jsOMS.Dispatcher.Dispatcher = class { + constructor () + { + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Event/EventManager.js b/Event/EventManager.js index b856cc2..5698eb9 100644 --- a/Event/EventManager.js +++ b/Event/EventManager.js @@ -14,179 +14,181 @@ jsOMS.Autoloader.defineNamespace('jsOMS.Event'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Event.EventManager = function () - { - this.logger = jsOMS.Log.Logger.getInstance(); - this.groups = {}; - this.callbacks = {}; - }; + jsOMS.Event.EventManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () + { + this.logger = jsOMS.Log.Logger.getInstance(); + this.groups = {}; + this.callbacks = {}; + }; - /** - * Add event group (element) - * - * Adding the same event overwrites the existing one as "waiting" - * - * @param {string|int} group Group id - * @param {string|int} id Event id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Event.EventManager.prototype.addGroup = function (group, id) - { - if (typeof this.groups[group] === 'undefined') { - this.groups[group] = {}; - } - - this.groups[group][id] = false; - }; - - /** - * Resets the group status - * - * @param {string|int} group Group id - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Event.EventManager.prototype.reset = function (group) - { - for (let id in this.groups[group]) { - if (this.groups[group].hasOwnProperty(id)) { - this.groups[group][id] = false; + /** + * Add event group (element) + * + * Adding the same event overwrites the existing one as "waiting" + * + * @param {string|int} group Group id + * @param {string|int} id Event id + * + * @method + * + * @since 1.0.0 + */ + addGroup (group, id) + { + if (typeof this.groups[group] === 'undefined') { + this.groups[group] = {}; } - } - }; - /** - * Does group have outstanding events - * - * @param {string|int} group Group id - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Event.EventManager.prototype.hasOutstanding = function (group) - { - if (typeof this.groups[group] === 'undefined') { - return false; - } + this.groups[group][id] = false; + }; - for (let id in this.groups[group]) { - if (!this.groups[group].hasOwnProperty(id) || !this.groups[group][id]) { - return true; + /** + * Resets the group status + * + * @param {string|int} group Group id + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + reset (group) + { + for (let id in this.groups[group]) { + if (this.groups[group].hasOwnProperty(id)) { + this.groups[group][id] = false; + } } - } + }; - return false; - }; - - /** - * Trigger event finished - * - * Executes the callback specified for this group if all events are finished - * - * @param {string|int} group Group id - * @param {string|int} [id] Event id - * @param {Object} [data] Data for event - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Event.EventManager.prototype.trigger = function (group, id, data) - { - id = typeof id !== 'undefined' ? id : 0; - - if (!this.callbacks.hasOwnProperty(group)) { - return false; - } - - if (typeof this.groups[group] !== 'undefined') { - this.groups[group][id] = true; - } - - if (!this.hasOutstanding(group)) { - // todo if it is route then call dispatcher? - this.callbacks[group].func(data); - - if (this.callbacks[group].remove) { - this.detach(group); - } else if (this.callbacks[group].reset) { - this.reset(group); + /** + * Does group have outstanding events + * + * @param {string|int} group Group id + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + hasOutstanding (group) + { + if (typeof this.groups[group] === 'undefined') { + return false; } - } - return true; - }; + for (let id in this.groups[group]) { + if (!this.groups[group].hasOwnProperty(id) || !this.groups[group][id]) { + return true; + } + } - /** - * Detach event - * - * @param {string|int} group Group id - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Event.EventManager.prototype.detach = function (group) - { - delete this.callbacks[group]; - delete this.groups[group]; - }; - - /** - * Attach callback to event group - * - * @param {string|int} group Group id - * @param {function} callback Callback or route for the event - * @param {boolean} [remove] Should be removed after execution - * @param {boolean} [reset] Reset after triggering - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Event.EventManager.prototype.attach = function (group, callback, remove = false, reset = false) - { - if (this.callbacks.hasOwnProperty(group)) { return false; - } + }; - this.callbacks[group] = {remove: remove, reset: reset, func: callback}; + /** + * Trigger event finished + * + * Executes the callback specified for this group if all events are finished + * + * @param {string|int} group Group id + * @param {string|int} [id] Event id + * @param {Object} [data] Data for event + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + trigger (group, id, data) + { + id = typeof id !== 'undefined' ? id : 0; - return true; - }; + if (!this.callbacks.hasOwnProperty(group)) { + return false; + } - /** - * Count events - * - * @return {int} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Event.EventManager.prototype.count = function () - { - return this.callbacks.length; - }; + if (typeof this.groups[group] !== 'undefined') { + this.groups[group][id] = true; + } + + if (!this.hasOutstanding(group)) { + // todo if it is route then call dispatcher? + this.callbacks[group].func(data); + + if (this.callbacks[group].remove) { + this.detach(group); + } else if (this.callbacks[group].reset) { + this.reset(group); + } + } + + return true; + }; + + /** + * Detach event + * + * @param {string|int} group Group id + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + detach (group) + { + delete this.callbacks[group]; + delete this.groups[group]; + }; + + /** + * Attach callback to event group + * + * @param {string|int} group Group id + * @param {function} callback Callback or route for the event + * @param {boolean} [remove] Should be removed after execution + * @param {boolean} [reset] Reset after triggering + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + attach (group, callback, remove = false, reset = false) + { + if (this.callbacks.hasOwnProperty(group)) { + return false; + } + + this.callbacks[group] = {remove: remove, reset: reset, func: callback}; + + return true; + }; + + /** + * Count events + * + * @return {int} + * + * @method + * + * @since 1.0.0 + */ + count () + { + return this.callbacks.length; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Log/Logger.js b/Log/Logger.js index a87e220..133b7c5 100644 --- a/Log/Logger.js +++ b/Log/Logger.js @@ -12,331 +12,332 @@ /** @namespace jsOMS.Log */ jsOMS.Autoloader.defineNamespace('jsOMS.Log'); - /** - * @constructor - * - * @param {boolean} verbose Verbose logging - * @param {boolean} ui Ui logging - * @param {boolean} remote Remote logging - * - * @since 1.0.0 - */ - jsOMS.Log.Logger = function (verbose, ui, remote) - { - this.verbose = typeof verbose !== 'undefined' ? verbose : true; - this.ui = typeof ui !== 'undefined' ? ui : true; - this.remote = typeof remote !== 'undefined' ? remote : false; - }; + jsOMS.Log.Logger = class { + /** + * @constructor + * + * @param {boolean} verbose Verbose logging + * @param {boolean} ui Ui logging + * @param {boolean} remote Remote logging + * + * @since 1.0.0 + */ + constructor (verbose, ui, remote) + { + this.verbose = typeof verbose !== 'undefined' ? verbose : true; + this.ui = typeof ui !== 'undefined' ? ui : true; + this.remote = typeof remote !== 'undefined' ? remote : false; + }; + + /** + * Get logging instance + * + * @param {boolean} [verbose] Verbose logging + * @param {boolean} [ui] Ui logging + * @param {boolean} [remote] Remote logging + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + static getInstance (verbose, ui, remote) + { + if(!jsOMS.Log.Logger.instance) { + jsOMS.Log.Logger.instance = new jsOMS.Log.Logger(verbose, ui, remote); + } + + return jsOMS.Log.Logger.instance; + }; + + /** + * Interpolate message + * + * @param {string} message Message structure + * @param {Object} [context] Context to put into message + * @param {string} [level] Log level + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + interpolate (message, context, level) + { + let newMessage = jsOMS.Log.Logger.MSG_FULL; + + for (let replace in context) { + if (context.hasOwnProperty(replace)) { + newMessage = newMessage.replace('{' + replace + '}', context[replace]); + } + } + + return newMessage; + }; + + /** + * Create context + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * @param {string} level Log level + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + createContext (message, context, level) + { + context.datetime = (new Date()).toISOString(); + context.version = '1.0.0'; + context.os = jsOMS.Message.Request.Request.getOS(); + context.browser = jsOMS.Message.Request.Request.getBrowser(); + context.path = window.location.href; + context.level = level; + context.message = message; + + return context; + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * @param {string} level Log level + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + write (message, context, level) + { + context = this.createContext(message, context, level); + + if (this.verbose) { + let color = '000'; + + switch (level) { + case 'info': + case 'notice': + case 'log': + color = '000'; + break; + case 'debug': + color = '289E39'; + break; + case 'warning': + case 'alert': + color = 'FFA600'; + break; + case 'error': + case 'critical': + case 'emergency': + color = 'CF304A'; + break; + default: + } + + console.log('%c' + this.interpolate(message, context, level), 'color: #' + color); + } + + if (this.ui) { + // todo: fill log box, set class and initiate animation + } + + if (this.remote) { + let request = new jsOMS.Message.Request.Request(); + request.setData(context); + request.setType(jsOMS.Message.Response.Response.ResponseType.JSON); + request.setUri('/{/lang}/api/log'); + request.setMethod(jsOMS.Message.Request.Request.RequestMethod.POST); + request.setRequestHeader('Content-Type', 'application/json'); + request.setSuccess(function (xhr) + { + }); + request.send(); + } + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + emergency (message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY); + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + alert (message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.ALERT); + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + critical (message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.CRITICAL); + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + error (message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.ERROR); + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + warning (message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.WARNING); + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + notice (message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.NOTICE); + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + info (message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.INFO); + }; + + /** + * Create log message + * + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + debug (message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.DEBUG); + }; + + /** + * Create log message + * + * @param {string} level Log level + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + log (level, message, context = {}) + { + this.write(message, context, level); + }; + + /** + * Create log message + * + * @param {string} level Log level + * @param {string} message Message to display + * @param {Object} [context] Context to put into message + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + console (level, message, context = {}) + { + this.write(message, context, jsOMS.Log.LogLevel.INFO); + }; + } jsOMS.Log.Logger.instance = null; - - /** - * Get logging instance - * - * @param {boolean} [verbose] Verbose logging - * @param {boolean} [ui] Ui logging - * @param {boolean} [remote] Remote logging - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.getInstance = function(verbose, ui, remote) - { - if(!jsOMS.Log.Logger.instance) { - jsOMS.Log.Logger.instance = new jsOMS.Log.Logger(verbose, ui, remote); - } - - return jsOMS.Log.Logger.instance; - }; - jsOMS.Log.Logger.MSG_FULL = '{datetime}; {level}; {version}; {os}; {browser}; {path}; {message}'; - - /** - * Interpolate message - * - * @param {string} message Message structure - * @param {Object} [context] Context to put into message - * @param {string} [level] Log level - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.interpolate = function (message, context, level) - { - let newMessage = jsOMS.Log.Logger.MSG_FULL; - - for (let replace in context) { - if (context.hasOwnProperty(replace)) { - newMessage = newMessage.replace('{' + replace + '}', context[replace]); - } - } - - return newMessage; - }; - - /** - * Create context - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * @param {string} level Log level - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.createContext = function (message, context, level) - { - context.datetime = (new Date()).toISOString(); - context.version = '1.0.0'; - context.os = jsOMS.Message.Request.Request.getOS(); - context.browser = jsOMS.Message.Request.Request.getBrowser(); - context.path = window.location.href; - context.level = level; - context.message = message; - - return context; - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * @param {string} level Log level - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.write = function (message, context, level) - { - context = this.createContext(message, context, level); - - if (this.verbose) { - let color = '000'; - - switch (level) { - case 'info': - case 'notice': - case 'log': - color = '000'; - break; - case 'debug': - color = '289E39'; - break; - case 'warning': - case 'alert': - color = 'FFA600'; - break; - case 'error': - case 'critical': - case 'emergency': - color = 'CF304A'; - break; - default: - } - - console.log('%c' + this.interpolate(message, context, level), 'color: #' + color); - } - - if (this.ui) { - // todo: fill log box, set class and initiate animation - } - - if (this.remote) { - let request = new jsOMS.Message.Request.Request(); - request.setData(context); - request.setType(jsOMS.Message.Response.Response.ResponseType.JSON); - request.setUri('/{/lang}/api/log'); - request.setMethod(jsOMS.Message.Request.Request.RequestMethod.POST); - request.setRequestHeader('Content-Type', 'application/json'); - request.setSuccess(function (xhr) - { - }); - request.send(); - } - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.emergency = function (message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.EMERGENCY); - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.alert = function (message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.ALERT); - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.critical = function (message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.CRITICAL); - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.error = function (message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.ERROR); - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.warning = function (message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.WARNING); - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.notice = function (message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.NOTICE); - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.info = function (message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.INFO); - }; - - /** - * Create log message - * - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.debug = function (message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.DEBUG); - }; - - /** - * Create log message - * - * @param {string} level Log level - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.log = function (level, message, context = {}) - { - this.write(message, context, level); - }; - - /** - * Create log message - * - * @param {string} level Log level - * @param {string} message Message to display - * @param {Object} [context] Context to put into message - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Log.Logger.prototype.console = function (level, message, context = {}) - { - this.write(message, context, jsOMS.Log.LogLevel.INFO); - }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Message/Notification/App/AppNotification.js b/Message/Notification/App/AppNotification.js index 858704b..b0b3c2c 100644 --- a/Message/Notification/App/AppNotification.js +++ b/Message/Notification/App/AppNotification.js @@ -13,39 +13,41 @@ /** @namespace jsOMS.Message.Notification.App */ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification.App'); - jsOMS.Message.Notification.App.AppNotification = function() - { - this.status = 0; - }; - - jsOMS.Message.Notification.App.AppNotification.prototype.setStatus = function(status) - { - this.status = status; - }; - - jsOMS.Message.Notification.App.AppNotification.prototype.requestPermission = function() - { - const self = this; - }; - - jsOMS.Message.Notification.App.AppNotification.prototype.send = function(msg) - { - const tpl = document.getElementById('app-message'); - - if (tpl === null) { - return; - } - - let output = document.importNode(tpl.content, true); - output.querySelector('.log-msg').classList.add('log-msg-status-' + msg.status); - output.querySelector('.log-msg-title').innerHTML = msg.title; - output.querySelector('.log-msg-content').innerHTML = msg.message; - - tpl.parentNode.appendChild(output); - - setTimeout(function () + jsOMS.Message.Notification.App.AppNotification = class { + constructor () { - document.getElementsByClassName('log-msg')[0].remove(); - }, 3000); - }; + this.status = 0; + }; + + setStatus (status) + { + this.status = status; + }; + + requestPermission () + { + const self = this; + }; + + send (msg) + { + const tpl = document.getElementById('app-message'); + + if (tpl === null) { + return; + } + + let output = document.importNode(tpl.content, true); + output.querySelector('.log-msg').classList.add('log-msg-status-' + msg.status); + output.querySelector('.log-msg-title').innerHTML = msg.title; + output.querySelector('.log-msg-content').innerHTML = msg.message; + + tpl.parentNode.appendChild(output); + + setTimeout(function () + { + document.getElementsByClassName('log-msg')[0].remove(); + }, 3000); + }; + } }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Message/Notification/Browser/BrowserNotification.js b/Message/Notification/Browser/BrowserNotification.js index 494dd54..f248b6a 100644 --- a/Message/Notification/Browser/BrowserNotification.js +++ b/Message/Notification/Browser/BrowserNotification.js @@ -13,35 +13,37 @@ /** @namespace jsOMS.Message.Notification.Browser */ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification.Browser'); - jsOMS.Message.Notification.Browser.BrowserNotification = function() - { - this.status = 0; - }; + jsOMS.Message.Notification.Browser.BrowserNotification = class { + constructor() + { + this.status = 0; + }; - jsOMS.Message.Notification.Browser.BrowserNotification.prototype.setStatus = function(status) - { - this.status = status; - }; + setStatus (status) + { + this.status = status; + }; - jsOMS.Message.Notification.Browser.BrowserNotification.prototype.requestPermission = function() - { - const self = this; + requestPermission () + { + const self = this; - /** global: Notification */ - if(Notification.permission !== 'granted' && Notification.permission !== 'denied') { - Notification.requestPermission(function(permission) { - if(permission === 'granted') { - let msg = new jsOMS.Message.Notification.NotificationMessage(); + /** global: Notification */ + if(Notification.permission !== 'granted' && Notification.permission !== 'denied') { + Notification.requestPermission(function(permission) { + if(permission === 'granted') { + let msg = new jsOMS.Message.Notification.NotificationMessage(); - self.send(msg); - } - }); - } - }; + self.send(msg); + } + }); + } + }; - jsOMS.Message.Notification.Browser.BrowserNotification.prototype.send = function(msg) - { - /** global: Notification */ - let n = new Notification(/* ... */); - }; + send (msg) + { + /** global: Notification */ + let n = new Notification(/* ... */); + }; + } }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Message/Notification/NotificationManager.js b/Message/Notification/NotificationManager.js index 2b16fdb..d7b8658 100644 --- a/Message/Notification/NotificationManager.js +++ b/Message/Notification/NotificationManager.js @@ -13,28 +13,30 @@ /** @namespace jsOMS.Message.Notification */ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification'); - jsOMS.Message.Notification.NotificationManager = function() - { - this.appNotifier = new jsOMS.Message.Notification.App.AppNotification(); - this.browserNotifier = new jsOMS.Message.Notification.Browser.BrowserNotification(); - }; + jsOMS.Message.Notification.NotificationManager = class { + constructor() + { + this.appNotifier = new jsOMS.Message.Notification.App.AppNotification(); + this.browserNotifier = new jsOMS.Message.Notification.Browser.BrowserNotification(); + }; - jsOMS.Message.Notification.NotificationManager.prototype.send = function(message, type) - { - if (jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION === type) { - this.appNotifier.send(message); - } else { - this.browserNotifier.send(message); - } - }; + send (message, type) + { + if (jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION === type) { + this.appNotifier.send(message); + } else { + this.browserNotifier.send(message); + } + }; - jsOMS.Message.Notification.NotificationManager.prototype.getAppNotifier = function() - { - return this.appNotifier; - }; + getAppNotifier () + { + return this.appNotifier; + }; - jsOMS.Message.Notification.NotificationManager.prototype.getBrowserNotifier = function() - { - return this.browserNotifier; - }; + getBrowserNotifier () + { + return this.browserNotifier; + }; + } }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Message/Notification/NotificationMessage.js b/Message/Notification/NotificationMessage.js index 89ba7db..dc5d250 100644 --- a/Message/Notification/NotificationMessage.js +++ b/Message/Notification/NotificationMessage.js @@ -12,10 +12,12 @@ /** @namespace jsOMS.Message.Notification.App */ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Notification'); - jsOMS.Message.Notification.NotificationMessage = function (status, title, message) - { - this.status = status; - this.title = title; - this.message = message; - }; + jsOMS.Message.Notification.NotificationMessage = class { + constructor(status, title, message) + { + this.status = status; + this.title = title; + this.message = message; + }; + } }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Message/Request/Request.js b/Message/Request/Request.js index c5153ef..3fc9e2b 100644 --- a/Message/Request/Request.js +++ b/Message/Request/Request.js @@ -13,369 +13,371 @@ /** @namespace jsOMS.Message.Request */ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Request'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request = function (uri, method, type) - { - this.uri = typeof uri !== 'undefined' ? uri : null; - this.method = typeof method !== 'undefined' ? method : jsOMS.Message.Request.RequestMethod.GET; - this.requestHeader = []; - this.result = {}; - this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON; - this.data = {}; - - // todo: create log; - this.result[0] = function () + jsOMS.Message.Request.Request = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (uri, method, type) { - //console.log('invalid response'); + this.uri = typeof uri !== 'undefined' ? uri : null; + this.method = typeof method !== 'undefined' ? method : jsOMS.Message.Request.RequestMethod.GET; + this.requestHeader = []; + this.result = {}; + this.type = typeof type !== 'undefined' ? type : jsOMS.Message.Response.ResponseType.JSON; + this.data = {}; + + // todo: create log; + this.result[0] = function() + { + //console.log('invalid response'); + }; + + /** global: XMLHttpRequest */ + this.xhr = new XMLHttpRequest(); }; - /** global: XMLHttpRequest */ - this.xhr = new XMLHttpRequest(); - }; - - /** - * Get browser. - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.getBrowser = function () - { - /** global: InstallTrigger */ - /** global: navigator */ - if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { - return jsOMS.Message.Request.BrowserType.OPERA; - } else if (typeof InstallTrigger !== 'undefined') { - return jsOMS.Message.Request.BrowserType.FIREFOX; - } else if (Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0) { - return jsOMS.Message.Request.BrowserType.SAFARI; - } else if (/*@cc_on!@*/false || !!document.documentMode) { - return jsOMS.Message.Request.BrowserType.IE; - } else if (!!window.StyleMedia) { - return jsOMS.Message.Request.BrowserType.EDGE; - } else if (!!window.chrome && !!window.chrome.webstore) { - return jsOMS.Message.Request.BrowserType.CHROME; - } else if ((isChrome || isOpera) && !!window.CSS) { - return jsOMS.Message.Request.BrowserType.BLINK; - } - - return jsOMS.Message.Request.BrowserType.UNKNOWN; - }; - - /** - * Get os. - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.getOS = function () - { - for (let os in jsOMS.Message.Request.OSType) { - if (jsOMS.Message.Request.OSType.hasOwnProperty(os)) { - /** global: navigator */ - if (navigator.appVersion.toLowerCase().indexOf(jsOMS.Message.Request.OSType[os]) !== -1) { - return jsOMS.Message.Request.OSType[os]; - } - } - } - - return jsOMS.Message.Request.OSType.UNKNOWN; - }; - - /** - * Set request method. - * - * EnumRequestMethod - * - * @param {string} method Method type - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.setMethod = function (method) - { - this.method = method; - }; - - /** - * Get request method. - * - * EnumRequestMethod - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.getMethod = function () - { - return this.method; - }; - - /** - * Set response type. - * - * EnumResponseType - * - * @param {string} type Method type - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.setResponseType = function (type) - { - this.xhr.responseType = type; - }; - - /** - * Get response type. - * - * EnumResponseType - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.getResponseType = function () - { - return this.responseType; - }; - - /** - * Set request header. - * - * @param {string} type Request type - * @param {string} header Request header - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.setRequestHeader = function (type, header) - { - this.requestHeader[type] = header; - }; - - /** - * Get request header. - * - * @return {Array} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.getRequestHeader = function () - { - return this.requestHeader; - }; - - /** - * Set request uri. - * - * @param {string} uri Request uri - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.setUri = function (uri) - { - this.uri = uri; - }; - - /** - * Get request uri. - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.getUri = function () - { - return this.uri; - }; - - /** - * Set success callback. - * - * @callback requestCallback - * @param {requestCallback} callback - Success callback - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.setSuccess = function (callback) - { - this.result[200] = callback; - }; - - /** - * Set result callback. - * - * @param {int} status Http response status - * @param {function} callback Callback - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.setResultCallback = function (status, callback) - { - this.result[status] = callback; - }; - - /** - * Set request data. - * - * @param {Array} data Request data - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.setData = function (data) - { - this.data = data; - }; - - /** - * Get request data. - * - * @return {Array} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.getData = function () - { - return this.data; - }; - - /** - * Set request type. - * - * EnumRequestType - * - * @param {string} type Method type - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.setType = function (type) - { - this.type = type; - }; - - /** - * Get request type. - * - * EnumRequestType - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.getType = function () - { - return this.type; - }; - - /** - * Create query from object. - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.queryfy = function (obj) - { - const str = []; - for (let p in obj) { - if (obj.hasOwnProperty(p)) { - str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); - } - } - - return str.join("&"); - }; - - /** - * Get request data. - * - * @return {Array} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Request.Request.prototype.send = function () - { - const self = this; - - if (this.xhr.readyState !== 1) { - this.xhr.open(this.method, jsOMS.Uri.UriFactory.build(this.uri)); - - for (let p in this.requestHeader) { - if (this.requestHeader.hasOwnProperty(p)) { - this.xhr.setRequestHeader(p, this.requestHeader[p]); - } - } - } - - this.xhr.onreadystatechange = function () + /** + * Get browser. + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + static getBrowser() { - switch (self.xhr.readyState) { - case 4: - if (typeof self.result[self.xhr.status] === 'undefined') { - self.result[0](self.xhr); - } else { - self.result[self.xhr.status](self.xhr); + /** global: InstallTrigger */ + /** global: navigator */ + if ((!!window.opr && !!opr.addons) || !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0) { + return jsOMS.Message.Request.BrowserType.OPERA; + } else if (typeof InstallTrigger !== 'undefined') { + return jsOMS.Message.Request.BrowserType.FIREFOX; + } else if (Object.toString.call(window.HTMLElement).indexOf('Constructor') > 0) { + return jsOMS.Message.Request.BrowserType.SAFARI; + } else if (/*@cc_on!@*/false || !!document.documentMode) { + return jsOMS.Message.Request.BrowserType.IE; + } else if (!!window.StyleMedia) { + return jsOMS.Message.Request.BrowserType.EDGE; + } else if (!!window.chrome && !!window.chrome.webstore) { + return jsOMS.Message.Request.BrowserType.CHROME; + } else if ((isChrome || isOpera) && !!window.CSS) { + return jsOMS.Message.Request.BrowserType.BLINK; + } + + return jsOMS.Message.Request.BrowserType.UNKNOWN; + }; + + /** + * Get os. + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + static getOS() + { + for (let os in jsOMS.Message.Request.OSType) { + if (jsOMS.Message.Request.OSType.hasOwnProperty(os)) { + /** global: navigator */ + if (navigator.appVersion.toLowerCase().indexOf(jsOMS.Message.Request.OSType[os]) !== -1) { + return jsOMS.Message.Request.OSType[os]; } - break; - case 2: - // todo: handle server received request - break; - case 3: - // todo: server is handling request - break; - default: - // todo: create handler for error returns + } } + + return jsOMS.Message.Request.OSType.UNKNOWN; }; - if (this.type === jsOMS.Message.Request.RequestType.JSON) { - if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') { - this.xhr.send(JSON.stringify(this.data)); - } else { - this.xhr.send(this.queryfy(this.data)); + /** + * Set request method. + * + * EnumRequestMethod + * + * @param {string} method Method type + * + * @method + * + * @since 1.0.0 + */ + setMethod(method) + { + this.method = method; + }; + + /** + * Get request method. + * + * EnumRequestMethod + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getMethod() + { + return this.method; + }; + + /** + * Set response type. + * + * EnumResponseType + * + * @param {string} type Method type + * + * @method + * + * @since 1.0.0 + */ + setResponseType(type) + { + this.xhr.responseType = type; + }; + + /** + * Get response type. + * + * EnumResponseType + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getResponseType() + { + return this.responseType; + }; + + /** + * Set request header. + * + * @param {string} type Request type + * @param {string} header Request header + * + * @method + * + * @since 1.0.0 + */ + setRequestHeader(type, header) + { + this.requestHeader[type] = header; + }; + + /** + * Get request header. + * + * @return {Array} + * + * @method + * + * @since 1.0.0 + */ + getRequestHeader() + { + return this.requestHeader; + }; + + /** + * Set request uri. + * + * @param {string} uri Request uri + * + * @method + * + * @since 1.0.0 + */ + setUri(uri) + { + this.uri = uri; + }; + + /** + * Get request uri. + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getUri() + { + return this.uri; + }; + + /** + * Set success callback. + * + * @callback requestCallback + * @param {requestCallback} callback - Success callback + * + * @method + * + * @since 1.0.0 + */ + setSuccess(callback) + { + this.result[200] = callback; + }; + + /** + * Set result callback. + * + * @param {int} status Http response status + * @param {function} callback Callback + * + * @method + * + * @since 1.0.0 + */ + setResultCallback(status, callback) + { + this.result[status] = callback; + }; + + /** + * Set request data. + * + * @param {Array} data Request data + * + * @method + * + * @since 1.0.0 + */ + setData(data) + { + this.data = data; + }; + + /** + * Get request data. + * + * @return {Array} + * + * @method + * + * @since 1.0.0 + */ + getData() + { + return this.data; + }; + + /** + * Set request type. + * + * EnumRequestType + * + * @param {string} type Method type + * + * @method + * + * @since 1.0.0 + */ + setType(type) + { + this.type = type; + }; + + /** + * Get request type. + * + * EnumRequestType + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getType() + { + return this.type; + }; + + /** + * Create query from object. + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + queryfy(obj) + { + const str = []; + for (let p in obj) { + if (obj.hasOwnProperty(p)) { + str.push(encodeURIComponent(p) + "=" + encodeURIComponent(obj[p])); + } } - } else if (this.type === jsOMS.Message.Request.RequestType.RAW) { - this.xhr.send(this.data); - } - }; + + return str.join("&"); + }; + + /** + * Get request data. + * + * @return {Array} + * + * @method + * + * @since 1.0.0 + */ + send() + { + const self = this; + + if (this.xhr.readyState !== 1) { + this.xhr.open(this.method, jsOMS.Uri.UriFactory.build(this.uri)); + + for (let p in this.requestHeader) { + if (this.requestHeader.hasOwnProperty(p)) { + this.xhr.setRequestHeader(p, this.requestHeader[p]); + } + } + } + + this.xhr.onreadystatechange = function() + { + switch (self.xhr.readyState) { + case 4: + if (typeof self.result[self.xhr.status] === 'undefined') { + self.result[0](self.xhr); + } else { + self.result[self.xhr.status](self.xhr); + } + break; + case 2: + // todo: handle server received request + break; + case 3: + // todo: server is handling request + break; + default: + // todo: create handler for error returns + } + }; + + if (this.type === jsOMS.Message.Request.RequestType.JSON) { + if (typeof this.requestHeader !== 'undefined' && this.requestHeader['Content-Type'] === 'application/json') { + this.xhr.send(JSON.stringify(this.data)); + } else { + this.xhr.send(this.queryfy(this.data)); + } + } else if (this.type === jsOMS.Message.Request.RequestType.RAW) { + this.xhr.send(this.data); + } + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Message/Response/Response.js b/Message/Response/Response.js index c67f617..907d66f 100644 --- a/Message/Response/Response.js +++ b/Message/Response/Response.js @@ -15,23 +15,25 @@ /** @namespace jsOMS.Message.Response */ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); - jsOMS.Message.Response.Response = function (data) - { - this.responses = data; - }; + jsOMS.Message.Response.Response = class { + constructor (data) + { + this.responses = data; + }; - jsOMS.Message.Response.Response.prototype.get = function (id) - { - return this.responses[id]; - }; + get (id) + { + return this.responses[id]; + }; - jsOMS.Message.Response.Response.prototype.getByIndex = function (index) - { - return this.responses[index]; - }; + getByIndex (index) + { + return this.responses[index]; + }; - jsOMS.Message.Response.Response.prototype.count = function () - { - return this.responses.length; - }; + count () + { + return this.responses.length; + }; + } }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/Message/Response/ResponseManager.js b/Message/Response/ResponseManager.js index 2dbcbf0..e5f8894 100644 --- a/Message/Response/ResponseManager.js +++ b/Message/Response/ResponseManager.js @@ -15,60 +15,62 @@ /** @namespace jsOMS.Message.Response */ jsOMS.Autoloader.defineNamespace('jsOMS.Message.Response'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Message.Response.ResponseManager = function () - { - this.messages = {}; - }; + jsOMS.Message.Response.ResponseManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor() + { + this.messages = {}; + }; - /** - * Add response handler. - * - * This allows the response handler to generally handle responses and also handle specific requests if defined. - * - * @param {string} key Response key - * @param {requestCallback} message Callback for message - * @param {string} [request] Request id in order to only handle a specific request - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Response.ResponseManager.prototype.add = function (key, message, request) - { - request = typeof request !== 'undefined' ? request : 'any'; - if (typeof this.messages[key] === 'undefined') { - this.messages[key] = []; - } + /** + * Add response handler. + * + * This allows the response handler to generally handle responses and also handle specific requests if defined. + * + * @param {string} key Response key + * @param {requestCallback} message Callback for message + * @param {string} [request] Request id in order to only handle a specific request + * + * @method + * + * @since 1.0.0 + */ + add(key, message, request) + { + request = typeof request !== 'undefined' ? request : 'any'; + if (typeof this.messages[key] === 'undefined') { + this.messages[key] = []; + } - this.messages[key][request] = message; - }; + this.messages[key][request] = message; + }; - /** - * Execute a predefined callback. - * - * Tries to execute a request specific callback or otherwise a general callback if defined. - * - * @param {string} key Response key - * @param {Array|Object} data Date to use in callback - * @param {jsOMS.Message.Request.Request} [request] Request id for request specific execution - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Message.Response.ResponseManager.prototype.run = function (key, data, request) - { - if (typeof request !== 'undefined' && typeof this.messages[key] !== 'undefined' && typeof this.messages[key][request] !== 'undefined') { - this.messages[key][request](data); - } else if (typeof this.messages[key] !== 'undefined') { - this.messages[key].any(data); - } else { - jsOMS.Log.Logger.instance.warning('Undefined type: ' + key); - } - }; + /** + * Execute a predefined callback. + * + * Tries to execute a request specific callback or otherwise a general callback if defined. + * + * @param {string} key Response key + * @param {Array|Object} data Date to use in callback + * @param {jsOMS.Message.Request.Request} [request] Request id for request specific execution + * + * @method + * + * @since 1.0.0 + */ + run(key, data, request) + { + if (typeof request !== 'undefined' && typeof this.messages[key] !== 'undefined' && typeof this.messages[key][request] !== 'undefined') { + this.messages[key][request](data); + } else if (typeof this.messages[key] !== 'undefined') { + this.messages[key].any(data); + } else { + jsOMS.Log.Logger.instance.warning('Undefined type: ' + key); + } + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Module/ModuleFactory.js b/Module/ModuleFactory.js index 469e2c9..0d1ba8e 100644 --- a/Module/ModuleFactory.js +++ b/Module/ModuleFactory.js @@ -12,29 +12,31 @@ jsOMS.Autoloader.defineNamespace('jsOMS.Module'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Module.ModuleFactory = function () - { - }; + jsOMS.Module.ModuleFactory = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () + { + }; - /** - * Get module instance. - * - * @param {string} module Module name - * @param {Object} app Application reference - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Module.ModuleFactory.getInstance = function (module, app) - { - return new jsOMS.Modules[module](app); - }; + /** + * Get module instance. + * + * @param {string} module Module name + * @param {Object} app Application reference + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + static getInstance (module, app) + { + return new jsOMS.Modules[module](app); + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Module/ModuleManager.js b/Module/ModuleManager.js index 458ef63..992c5c0 100644 --- a/Module/ModuleManager.js +++ b/Module/ModuleManager.js @@ -13,34 +13,36 @@ /** @namespace jsOMS.Module */ jsOMS.Autoloader.defineNamespace('jsOMS.Module'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Module.ModuleManager = function (app) - { - this.modules = {}; - this.app = app; - }; + jsOMS.Module.ModuleManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor(app) + { + this.modules = {}; + this.app = app; + }; - /** - * Get module. - * - * @param {string} module Module name - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Module.ModuleManager.prototype.get = function (module) - { - if (typeof this.modules[module] === 'undefined') { - this.modules[module] = jsOMS.Module.ModuleFactory.getInstance(module, this.app); - } + /** + * Get module. + * + * @param {string} module Module name + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + get (module) + { + if (typeof this.modules[module] === 'undefined') { + this.modules[module] = jsOMS.Module.ModuleFactory.getInstance(module, this.app); + } - return this.modules[module]; - }; + return this.modules[module]; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Route/Route.js b/Route/Route.js index 817fe8f..445e009 100644 --- a/Route/Route.js +++ b/Route/Route.js @@ -3,17 +3,19 @@ jsOMS.Autoloader.defineNamespace('jsOMS.Route'); - // TODO: create comments - jsOMS.Route.Route = function () - { - this.routes = null; - }; + jsOMS.Route.Route = class { + // TODO: create comments + constructor () + { + this.routes = null; + }; - // TODO: create comments - jsOMS.Route.prototype.add = function (path, callback, exact) - { - exact = typeof exact !== 'undefined' ? exact : true; + // TODO: create comments + add (path, callback, exact) + { + exact = typeof exact !== 'undefined' ? exact : true; - // todo: create array key path like i did for php - }; + // todo: create array key path like i did for php + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/ActionManager.js b/UI/ActionManager.js index 7f122e2..adda6f6 100644 --- a/UI/ActionManager.js +++ b/UI/ActionManager.js @@ -96,6 +96,7 @@ for (let j = 0; j < length; ++j) { self.bindListener(data.addedNodes[j].id, listeners[i], true); + // todo only make removable if action itself is defined as auto removable } }); @@ -127,13 +128,14 @@ for (let j = 1; j < actionLength; ++j) { if (typeof id === 'undefined' || typeof listener.key === 'undefined') { - throw 'Invalid element id/key.' + jsOMS.Log.Logger.instance.error('Invalid element id/key: ' + id + '/' + listener.key); + return; } this.app.eventManager.attach(id + '-' + listener.key + '-' + listener.action[j - 1].key, function (data) { self.runAction(id, listener, listener.action[j], data); - }, removable, true); // todo: make actions removable e.g. in case of child elements getting removed = tag list + }, removable, true); } // todo: the true here is a memory leak since it should be removed at some point?! // todo: handle onload action right after registering everything. this will be used for onload api calls in order to get content such as lists or models. Maybe in the main application after registering a invoke('onload') should be called if the application wants to execute the onload elements diff --git a/UI/Component/Form.js b/UI/Component/Form.js index e14f06e..5821141 100644 --- a/UI/Component/Form.js +++ b/UI/Component/Form.js @@ -13,258 +13,258 @@ /** @namespace jsOMS.UI */ jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form = function (app) - { - this.app = app; - this.forms = {}; - this.ignore = {}; - }; + jsOMS.UI.Component.Form = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (app) + { + this.app = app; + this.forms = {}; + this.ignore = {}; + }; - /** - * Get form - * - * @param {string} id Form Id - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.get = function (id) - { - return this.forms[id]; - }; + /** + * Get form + * + * @param {string} id Form Id + * + * @since 1.0.0 + */ + get (id) + { + return this.forms[id]; + }; - /** - * Is form ignored? - * - * @param {string} id Form Id - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.isIgnored = function (id) - { - return this.ignore.indexOf(id) !== -1; - }; + /** + * Is form ignored? + * + * @param {string} id Form Id + * + * @since 1.0.0 + */ + isIgnored (id) + { + return this.ignore.indexOf(id) !== -1; + }; - /** - * Unbind form - * - * @param {string} id Form Id - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.unbind = function (id) - { + /** + * Unbind form + * + * @param {string} id Form Id + * + * @since 1.0.0 + */ + unbind (id) + { - }; + }; - /** - * Bind form - * - * @param {string} id Form Id (optional) - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.bind = function (id) - { - if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') { - this.bindForm(id); - } else { - const forms = document.getElementsByTagName('form'), - length = !forms ? 0 : forms.length; + /** + * Bind form + * + * @param {string} id Form Id (optional) + * + * @since 1.0.0 + */ + bind (id) + { + if (typeof id !== 'undefined' && typeof this.ignore[id] === 'undefined') { + this.bindForm(id); + } else { + const forms = document.getElementsByTagName('form'), + length = !forms ? 0 : forms.length; + + for (let i = 0; i < length; ++i) { + if (typeof forms[i].getAttribute('id') !== 'undefined' && forms[i].getAttribute('id') !== null && typeof this.ignore[forms[i].getAttribute('id')] === 'undefined') { + this.bindForm(forms[i].getAttribute('id')); + } + } + } + }; + + /** + * Bind form + * + * @param {string} id Form Id + * + * @since 1.0.0 + */ + bindForm (id) + { + if (typeof id === 'undefined' || !id) { + jsOMS.Log.Logger.instance.info('A form doesn\'t have an ID.'); + return; + } + + const self = this; + this.forms[id] = new jsOMS.Views.FormView(id); + + this.unbind(id); + + const submits = this.forms[id].getSubmit(), + length = submits.length; for (let i = 0; i < length; ++i) { - if (typeof forms[i].getAttribute('id') !== 'undefined' && forms[i].getAttribute('id') !== null && typeof this.ignore[forms[i].getAttribute('id')] === 'undefined') { - this.bindForm(forms[i].getAttribute('id')); - } + submits[i].addEventListener('click', function (event) + { + jsOMS.preventAll(event); + self.submit(self.forms[id]); + }); } - } - }; + }; - /** - * Bind form - * - * @param {string} id Form Id - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.bindForm = function (id) - { - if (typeof id === 'undefined' || !id) { - jsOMS.Log.Logger.instance.info('A form doesn\'t have an ID.'); - return; - } + /** + * Unbind form + * + * @param {string} id Form Id + * + * @since 1.0.0 + */ + unbindForm (id) + { + // todo: do i need the findex? can't i just use id? + let findex = 0; - const self = this; - this.forms[id] = new jsOMS.Views.FormView(id); + if ((findex = this.forms[id]) !== 'undefined') { + this.forms[id].unbind(); + this.forms.splice(findex, 1); - this.unbind(id); + return true; + } - const submits = this.forms[id].getSubmit(), - length = submits.length; + return false; + }; - for (let i = 0; i < length; ++i) { - submits[i].addEventListener('click', function (event) + /** + * Submit form + * + * Calls injections first befor executing the actual form submit + * + * @param {Object} form Form object + * + * @since 1.0.0 + */ + submit (form) + { + /* Handle injects */ + const self = this, + injects = form.getSubmitInjects(); + let counter = 0; + + // todo: test if attach necessary (maybe already attached in event manager) + // Register normal form behavior + this.app.eventManager.attach(form.getId(), function () { - jsOMS.preventAll(event); - self.submit(self.forms[id]); + self.submitForm(form); }); - } - }; - /** - * Unbind form - * - * @param {string} id Form Id - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.unbindForm = function (id) - { - // todo: do i need the findex? can't i just use id? - let findex = 0; + // Run all injects first + for (let property in injects) { + if (injects.hasOwnProperty(property)) { + counter++; + //this.app.eventManager.addGroup(form.getId(), counter); + const result = injects[property](form, form.getId()); - if ((findex = this.forms[id]) !== 'undefined') { - this.forms[id].unbind(); - this.forms.splice(findex, 1); - - return true; - } - - return false; - }; - - /** - * Submit form - * - * Calls injections first befor executing the actual form submit - * - * @param {Object} form Form object - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.submit = function (form) - { - /* Handle injects */ - const self = this, - injects = form.getSubmitInjects(); - let counter = 0; - - // todo: test if attach necessary (maybe already attached in event manager) - // Register normal form behavior - this.app.eventManager.attach(form.getId(), function () - { - self.submitForm(form); - }); - - // Run all injects first - for (let property in injects) { - if (injects.hasOwnProperty(property)) { - counter++; - //this.app.eventManager.addGroup(form.getId(), counter); - const result = injects[property](form, form.getId()); - - if (result === false) { - return; + if (result === false) { + return; + } + } else { + jsOMS.Log.Logger.instance.warning('Invalid property.'); } - } else { - jsOMS.Log.Logger.instance.warning('Invalid property.'); } - } - this.app.eventManager.trigger(form.getId()); - }; + this.app.eventManager.trigger(form.getId()); + }; - /** - * Submit form data - * - * Submits the main form data - * - * @param {Object} form Form object - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.submitForm = function (form) - { - if (!form.isValid()) { - jsOMS.Log.Logger.instance.debug('Form "' + form.getId() + '" has invalid values.'); - return; - } - - if (form.getMethod() !== jsOMS.Message.Request.RequestMethod.GET - && Math.floor(Date.now()) - form.getLastSubmit() < 500 - ) { - return; - } - - form.updateLastSubmit(); - - /* Handle default submit */ - const request = new jsOMS.Message.Request.Request(), - self = this; - - request.setData(form.getData()); - request.setType(jsOMS.Message.Response.ResponseType.JSON); - request.setUri(form.getAction()); - request.setMethod(form.getMethod()); - request.setRequestHeader('Content-Type', 'application/json'); - request.setSuccess(function (xhr) + /** + * Submit form data + * + * Submits the main form data + * + * @param {Object} form Form object + * + * @since 1.0.0 + */ + submitForm (form) { - console.log(xhr.response); + if (!form.isValid()) { + jsOMS.Log.Logger.instance.debug('Form "' + form.getId() + '" has invalid values.'); + return; + } - try { - const o = JSON.parse(xhr.response), - response = new jsOMS.Message.Response.Response(o); - let successInject = null; + if (form.getMethod() !== jsOMS.Message.Request.RequestMethod.GET + && Math.floor(Date.now()) - form.getLastSubmit() < 500 + ) { + return; + } - if (typeof o.status !== 'undefined') { - self.app.notifyManager.send( - new jsOMS.Message.Notification.NotificationMessage(o.status, o.title, o.message), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION + form.updateLastSubmit(); + + /* Handle default submit */ + const request = new jsOMS.Message.Request.Request(), + self = this; + + request.setData(form.getData()); + request.setType(jsOMS.Message.Response.ResponseType.JSON); + request.setUri(form.getAction()); + request.setMethod(form.getMethod()); + request.setRequestHeader('Content-Type', 'application/json'); + request.setSuccess(function (xhr) + { + console.log(xhr.response); + + try { + const o = JSON.parse(xhr.response), + response = new jsOMS.Message.Response.Response(o); + let successInject = null; + + if (typeof o.status !== 'undefined') { + self.app.notifyManager.send( + new jsOMS.Message.Notification.NotificationMessage(o.status, o.title, o.message), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION + ); + } + + if ((successInject = form.getSuccess()) !== null) { + successInject(response); + } + } catch (e) { + console.log(e); + + jsOMS.Log.Logger.instance.error('Invalid form response. \n' + + 'URL: ' + form.getAction() + '\n' + + 'Request: ' + JSON.stringify(form.getData()) + '\n' + + 'Response: ' + xhr.response ); } + }); - if ((successInject = form.getSuccess()) !== null) { - successInject(response); - } else { - self.app.responseManager.run(response.get(0).type, response.get(0), request); - } - } catch (e) { - console.log(e); - - jsOMS.Log.Logger.instance.error('Invalid form response. \n' - + 'URL: ' + form.getAction() + '\n' - + 'Request: ' + JSON.stringify(form.getData()) + '\n' - + 'Response: ' + xhr.response + request.setResultCallback(0, function (xhr) + { + self.app.notifyManager.send( + new jsOMS.Message.Notification.NotificationMessage( + jsOMS.Message.Notification.NotificationLevel.ERROR, + 'Failure', + 'Some failure happend' + ), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION ); - } - }); + }); - request.setResultCallback(0, function (xhr) + request.send(); + }; + + /** + * Count the bound forms + * + * @return {number} + * + * @since 1.0.0 + */ + count () { - self.app.notifyManager.send( - new jsOMS.Message.Notification.NotificationMessage( - jsOMS.Message.Notification.NotificationLevel.ERROR, - 'Failure', - 'Some failure happend' - ), jsOMS.Message.Notification.NotificationType.APP_NOTIFICATION - ); - }); - - request.send(); - }; - - /** - * Count the bound forms - * - * @return {number} - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Form.prototype.count = function () - { - return this.forms.length; - }; + return this.forms.length; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Component/Input.js b/UI/Component/Input.js index 6ed4cfa..9968159 100644 --- a/UI/Component/Input.js +++ b/UI/Component/Input.js @@ -13,146 +13,148 @@ /** @namespace jsOMS.UI.Input*/ jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input'); - /** - * Unbind input element - * - * @param {Object} input Input element - * - * @since 1.0.0 - */ - jsOMS.UI.Input.unbind = function (input) - { - this.app.inputManager.getKeyboardManager().unbind(input); - /** global: changeBind */ - input.removeEventListener('change', changeBind, false); - }; - - /** - * Bind input elment - * - * @param {Object} input Input elment - * - * @since 1.0.0 - */ - jsOMS.UI.Input.bindElement = function (input) - { - if (typeof input === 'undefined') { - throw 'Input element required' - } - - const self = this; - - input.addEventListener('change', function changeBind(event) + jsOMS.UI.Input = class { + /** + * Unbind input element + * + * @param {Object} input Input element + * + * @since 1.0.0 + */ + static unbind = function (input) { - /* Handle remote datalist/autocomplete input element */ - let listId, list; - if (typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { - self.addRemoteDatalistOptions(this, list); + this.app.inputManager.getKeyboardManager().unbind(input); + /** global: changeBind */ + input.removeEventListener('change', changeBind, false); + }; + + /** + * Bind input elment + * + * @param {Object} input Input elment + * + * @since 1.0.0 + */ + static bindElement = function (input) + { + if (typeof input === 'undefined') { + throw 'Input element required' } - /* Handle html defined functions */ - let change; - if (typeof (change = this.getAttribute('data-change-func')) !== 'undefined') { - change(this); - } + const self = this; - /* Handle pre-defined dynamic change events */ - let ref; - if (typeof (ref = this.getAttribute('data-ref')) !== 'undefined') { - let e = document.getElementById(ref); - - if (!e) { - return; - } - - switch (e.tagName) { - case 'ul': - break; - case 'table': - break; - default: - } - } - }); - - let dataButton; - if (typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') { - this.app.inputManager.getKeyboardManager().bind(input, 13, function () + input.addEventListener('change', function changeBind(event) { - const db = document.getElementById(dataButton); - - if (db) { - db.click(); + /* Handle remote datalist/autocomplete input element */ + let listId, list; + if (typeof (listId = this.getAttribute('list')) !== 'undefined' && (list = document.getElementById(listId)).getAttribute('data-list-src') !== 'undefined') { + self.addRemoteDatalistOptions(this, list); } - }); - } - }; - /** - * Add remote datalist options - * - * This only applies for datalists that have remote options - * - * @param {Object} input Input elment - * @param {Object} datalist Datalist elment - * - * @since 1.0.0 - */ - jsOMS.UI.Input.addRemoteDatalistOptions = function (input, datalist) - { - this.clearDatalistOptions(datalist); + /* Handle html defined functions */ + let change; + if (typeof (change = this.getAttribute('data-change-func')) !== 'undefined') { + change(this); + } - const request = new jsOMS.Message.Request(); - request.setData(input.value); - request.setType(jsOMS.Message.Response.ResponseType.JSON); - request.setUri(datalist.getAttribute('data-list-src')); - request.setMethod(jsOMS.Message.Request.RequestMethod.POST); - request.setRequestHeader('Content-Type', 'application/json'); - request.setSuccess(function (xhr) - { - try { - const o = JSON.parse(xhr.response), - response = new jsOMS.Message.Response(o), - responseLength = response.count(); - let tempResponse = null, - success = null; + /* Handle pre-defined dynamic change events */ + let ref; + if (typeof (ref = this.getAttribute('data-ref')) !== 'undefined') { + let e = document.getElementById(ref); - for (let k = 0; k < responseLength; ++k) { - tempResponse = response.getByIndex(k); + if (!e) { + return; + } - let option = null, - data = tempResponse.getData(), - length = data.length; - - for (let i = 0; i < length; ++i) { - option = document.createElement('option'); - option.value = tempResponse.value; - option.text = tempResponse.text; - - datalist.appendChild(option); + switch (e.tagName) { + case 'ul': + break; + case 'table': + break; + default: } } - } catch (exception) { - jsOMS.Log.Logger.instance.error('Invalid JSON object: ' + xhr, 'FormManager'); + }); + + let dataButton; + if (typeof (dataButton = input.getAttribute('data-button')) !== 'undefined') { + this.app.inputManager.getKeyboardManager().bind(input, 13, function () + { + const db = document.getElementById(dataButton); + + if (db) { + db.click(); + } + }); } - }); + }; - request.send(); - }; + /** + * Add remote datalist options + * + * This only applies for datalists that have remote options + * + * @param {Object} input Input elment + * @param {Object} datalist Datalist elment + * + * @since 1.0.0 + */ + static addRemoteDatalistOptions = function (input, datalist) + { + this.clearDatalistOptions(datalist); - /** - * Remove all datalist options from datalist - * - * @param {Object} datalist Datalist elment - * - * @since 1.0.0 - */ - jsOMS.UI.Input.clearDatalistOptions = function (datalist) - { - const length = datalist.options.length; + const request = new jsOMS.Message.Request(); + request.setData(input.value); + request.setType(jsOMS.Message.Response.ResponseType.JSON); + request.setUri(datalist.getAttribute('data-list-src')); + request.setMethod(jsOMS.Message.Request.RequestMethod.POST); + request.setRequestHeader('Content-Type', 'application/json'); + request.setSuccess(function (xhr) + { + try { + const o = JSON.parse(xhr.response), + response = new jsOMS.Message.Response(o), + responseLength = response.count(); + let tempResponse = null, + success = null; - for (let i = 0; i < length; ++i) { - datalist.remove(0); - } - }; + for (let k = 0; k < responseLength; ++k) { + tempResponse = response.getByIndex(k); + + let option = null, + data = tempResponse.getData(), + length = data.length; + + for (let i = 0; i < length; ++i) { + option = document.createElement('option'); + option.value = tempResponse.value; + option.text = tempResponse.text; + + datalist.appendChild(option); + } + } + } catch (exception) { + jsOMS.Log.Logger.instance.error('Invalid JSON object: ' + xhr, 'FormManager'); + } + }); + + request.send(); + }; + + /** + * Remove all datalist options from datalist + * + * @param {Object} datalist Datalist elment + * + * @since 1.0.0 + */ + static clearDatalistOptions = function (datalist) + { + const length = datalist.options.length; + + for (let i = 0; i < length; ++i) { + datalist.remove(0); + } + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Component/Tab.js b/UI/Component/Tab.js index bc509aa..3be4a22 100644 --- a/UI/Component/Tab.js +++ b/UI/Component/Tab.js @@ -12,70 +12,72 @@ jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Tab = function (responseManager) - { - this.responseManager = responseManager; - }; - - /** - * Bind & rebind UI elements. - * - * @param {string} [id] Element id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Tab.prototype.bind = function (id) - { - if (typeof id !== 'undefined') { - const e = document.getElementById(id); - - if (e) { - this.bindElement(); - } - } else { - const tabs = document.querySelectorAll('.tabview'), - length = !tabs ? 0 : tabs.length; - - for (let i = 0; i < length; ++i) { - this.bindElement(tabs[i]); - } - } - }; - - /** - * Bind & rebind UI element. - * - * @param {Object} [e] Element id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Tab.prototype.bindElement = function (e) - { - const nodes = e.querySelectorAll('.tab-links a'); - - nodes.addEventListener('click', function (evt) + jsOMS.UI.Component.Tab = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (responseManager) { - /* Change Tab */ - const attr = this.getAttribute('href').substring(1), - cont = this.parentNode.parentNode.parentNode.children[1]; + this.responseManager = responseManager; + }; - jsOMS.removeClass(jsOMS.getByClass(this.parentNode.parentNode, 'active'), 'active'); - jsOMS.addClass(this.parentNode, 'active'); - jsOMS.removeClass(jsOMS.getByClass(cont, 'active'), 'active'); - jsOMS.addClass(jsOMS.getByClass(cont, attr), 'active'); + /** + * Bind & rebind UI elements. + * + * @param {string} [id] Element id + * + * @method + * + * @since 1.0.0 + */ + bind (id) + { + if (typeof id !== 'undefined') { + const e = document.getElementById(id); - /* Modify url */ + if (e) { + this.bindElement(); + } + } else { + const tabs = document.querySelectorAll('.tabview'), + length = !tabs ? 0 : tabs.length; - jsOMS.preventAll(evt); - }); - }; + for (let i = 0; i < length; ++i) { + this.bindElement(tabs[i]); + } + } + }; + + /** + * Bind & rebind UI element. + * + * @param {Object} [e] Element id + * + * @method + * + * @since 1.0.0 + */ + bindElement (e) + { + const nodes = e.querySelectorAll('.tab-links a'); + + nodes.addEventListener('click', function (evt) + { + /* Change Tab */ + const attr = this.getAttribute('href').substring(1), + cont = this.parentNode.parentNode.parentNode.children[1]; + + jsOMS.removeClass(jsOMS.getByClass(this.parentNode.parentNode, 'active'), 'active'); + jsOMS.addClass(this.parentNode, 'active'); + jsOMS.removeClass(jsOMS.getByClass(cont, 'active'), 'active'); + jsOMS.addClass(jsOMS.getByClass(cont, attr), 'active'); + + /* Modify url */ + + jsOMS.preventAll(evt); + }); + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Component/Table.js b/UI/Component/Table.js index df824df..276197d 100644 --- a/UI/Component/Table.js +++ b/UI/Component/Table.js @@ -12,53 +12,55 @@ jsOMS.Autoloader.defineNamespace('jsOMS.UI.Component'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Table = function (responseManager) - { - this.responseManager = responseManager; - }; + jsOMS.UI.Component.Table = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor(responseManager) + { + this.responseManager = responseManager; + }; - /** - * Bind & rebind UI elements. - * - * @param {string} [id] Element id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Table.prototype.bind = function (id) - { - if (typeof id !== 'undefined') { - const e = document.getElementById(id); + /** + * Bind & rebind UI elements. + * + * @param {string} [id] Element id + * + * @method + * + * @since 1.0.0 + */ + bind (id) + { + if (typeof id !== 'undefined') { + const e = document.getElementById(id); - if (e) { - this.bindElement(e); + if (e) { + this.bindElement(e); + } + } else { + const tables = document.getElementsByTagName('table'), + length = !tables ? 0 : tables.length; + + for (let i = 0; i < length; ++i) { + this.bindElement(tables[i]); + } } - } else { - const tables = document.getElementsByTagName('table'), - length = !tables ? 0 : tables.length; + }; - for (let i = 0; i < length; ++i) { - this.bindElement(tables[i]); - } - } - }; - - /** - * Bind & rebind UI element. - * - * @param {Object} [e] Element id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.Component.Table.prototype.bindElement = function (e) - { - }; + /** + * Bind & rebind UI element. + * + * @param {Object} [e] Element id + * + * @method + * + * @since 1.0.0 + */ + bindElement (e) + { + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/DragNDrop.js b/UI/DragNDrop.js index e226674..833245e 100644 --- a/UI/DragNDrop.js +++ b/UI/DragNDrop.js @@ -13,115 +13,116 @@ /** @namespace jsOMS.UI.DragNDrop*/ jsOMS.Autoloader.defineNamespace('jsOMS.UI.DragNDrop'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.DragNDrop = function (app) - { - this.app = app; - this.draggable = {}; - this.dragging = null; - }; + jsOMS.UI.DragNDrop = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (app) + { + this.app = app; + this.draggable = {}; + this.dragging = null; + }; - /** - * Unbind element - * - * @param {Object} element DOM element - * - * @since 1.0.0 - */ - jsOMS.UI.DragNDrop.prototype.unbind = function (element) - { - }; + /** + * Unbind element + * + * @param {Object} element DOM element + * + * @since 1.0.0 + */ + unbind (element) + { + }; - /** - * Bind element - * - * @param {Object} id DOM element - * - * @since 1.0.0 - */ - jsOMS.UI.DragNDrop.prototype.bind = function (id) - { - if (typeof id !== 'undefined') { - this.bindElement(id); - } else { - const elements = document.querySelectorAll('[draggable]'), - length = !elements ? 0 : elements.length; + /** + * Bind element + * + * @param {Object} id DOM element + * + * @since 1.0.0 + */ + bind (id) + { + if (typeof id !== 'undefined') { + this.bindElement(id); + } else { + const elements = document.querySelectorAll('[draggable]'), + length = !elements ? 0 : elements.length; - for (let i = 0; i < length; ++i) { - if (typeof elements[i].getAttribute('id') !== 'undefined' && elements[i].getAttribute('id') !== null) { - this.bindElement(elements[i].getAttribute('id')); + for (let i = 0; i < length; ++i) { + if (typeof elements[i].getAttribute('id') !== 'undefined' && elements[i].getAttribute('id') !== null) { + this.bindElement(elements[i].getAttribute('id')); + } } } - } - }; + }; - /** - * Bind DOM elment - * - * @param {string} id DOM elment - * - * @since 1.0.0 - */ - jsOMS.UI.DragNDrop.prototype.bindElement = function (id) - { - const element = document.getElementById(id), - self = this; + /** + * Bind DOM elment + * + * @param {string} id DOM elment + * + * @since 1.0.0 + */ + bindElement (id) + { + const element = document.getElementById(id), + self = this; - if (!element) { - return; - } - - element.addEventListener('dragstart', function(e) { - if (self.dragging === null) { - self.dragging = this; - e.dataTransfer.effectAllowed = 'move'; - e.dataTransfer.setData('text/html', this.innerHTML); - } - }, false); - - element.addEventListener('dragenter', function(e) { - // todo: highlight - }, false); - - element.addEventListener('dragover', function(e) { - e.preventDefault(); - - e.dataTransfer.dropEffect = 'move'; - }, false); - - element.addEventListener('dragleave', function(e) { - e.preventDefault(); - - // todo: don't highlight - }, false); - - element.addEventListener('dragend', function(e) { - e.preventDefault(); - - // todo: reset all changes - }, false); - - //element.addEventListener('drag', function(e) {}); - element.addEventListener('drop', function(e) { - e.stopPropagation(); - e.preventDefault(); - - if (self.dragging === this) { + if (!element) { return; } - self.dragging.innerHTML = this.innerHTML; - this.innerHTML = e.dataTransfer.getData('text/html'); + element.addEventListener('dragstart', function(e) { + if (self.dragging === null) { + self.dragging = this; + e.dataTransfer.effectAllowed = 'move'; + e.dataTransfer.setData('text/html', this.innerHTML); + } + }, false); - // todo: add to now destination - // todo: remove from old destination + element.addEventListener('dragenter', function(e) { + // todo: highlight + }, false); - self.dragging = null; - }, false); + element.addEventListener('dragover', function(e) { + e.preventDefault(); + + e.dataTransfer.dropEffect = 'move'; + }, false); + + element.addEventListener('dragleave', function(e) { + e.preventDefault(); + + // todo: don't highlight + }, false); + + element.addEventListener('dragend', function(e) { + e.preventDefault(); + + // todo: reset all changes + }, false); + + //element.addEventListener('drag', function(e) {}); + element.addEventListener('drop', function(e) { + e.stopPropagation(); + e.preventDefault(); + + if (self.dragging === this) { + return; + } + + self.dragging.innerHTML = this.innerHTML; + this.innerHTML = e.dataTransfer.getData('text/html'); + + // todo: add to now destination + // todo: remove from old destination + + self.dragging = null; + }, false); + } } - }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/UI/GeneralUI.js b/UI/GeneralUI.js index eefa2c3..591ff4e 100644 --- a/UI/GeneralUI.js +++ b/UI/GeneralUI.js @@ -13,93 +13,94 @@ /** @namespace jsOMS.UI */ jsOMS.Autoloader.defineNamespace('jsOMS.UI'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.GeneralUI = function () - { + jsOMS.UI.GeneralUI = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () + { + this.visObs = null; + }; - this.visObs = null; - }; - - /** - * Bind button. - * - * @param {string} [id] Button id (optional) - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.GeneralUI.prototype.bind = function (id) - { - let e = null; - if (typeof id !== 'undefined') { - e = document.getElementById(id); - } - - this.bindHref(e); - this.bindLazyLoad(e); - }; - - /** - * Bind & rebind UI element. - * - * @param {Object} [e] Element id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.GeneralUI.prototype.bindHref = function (e) - { - e = e !== null ? e.querySelectorAll('[data-href]') : document.querySelectorAll('[data-href]'); - const length = e.length; - - for (let i = 0; i < length; ++i) { - e[i].addEventListener('click', function(event) { - jsOMS.preventAll(event); - window.location = jsOMS.Uri.UriFactory.build(this.getAttribute('data-href')); - }); - } - }; - - /** - * Bind & rebind UI element. - * - * @param {Object} [e] Element id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.GeneralUI.prototype.bindLazyLoad = function (e) - { - e = e !== null ? e.querySelectorAll('[data-lazyload]') : document.querySelectorAll('[data-lazyload]'); - const length = e.length; - - /** global: IntersectionObserver */ - if (!this.visObs && window.IntersectionObserver) { - this.visObs = new IntersectionObserver(function(eles, obs) { - eles.forEach(ele => { - if (ele.intersectionRatio > 0) { - obs.unobserve(ele.target); - ele.target.src = ele.target.dataset.lazyload; - delete ele.target.dataset.lazyload; - } - }); - }); - } - - for (let i = 0; i < length; ++i) { - if (!this.visObs) { - e[i].src = e[i].dataset.lazyload; - delete e[i].dataset.lazyload; - } else { - this.visObs.observe(e[i]); + /** + * Bind button. + * + * @param {string} [id] Button id (optional) + * + * @method + * + * @since 1.0.0 + */ + bind (id) + { + let e = null; + if (typeof id !== 'undefined') { + e = document.getElementById(id); } - } - }; + + this.bindHref(e); + this.bindLazyLoad(e); + }; + + /** + * Bind & rebind UI element. + * + * @param {Object} [e] Element id + * + * @method + * + * @since 1.0.0 + */ + bindHref (e) + { + e = e !== null ? e.querySelectorAll('[data-href]') : document.querySelectorAll('[data-href]'); + const length = e.length; + + for (let i = 0; i < length; ++i) { + e[i].addEventListener('click', function(event) { + jsOMS.preventAll(event); + window.location = jsOMS.Uri.UriFactory.build(this.getAttribute('data-href')); + }); + } + }; + + /** + * Bind & rebind UI element. + * + * @param {Object} [e] Element id + * + * @method + * + * @since 1.0.0 + */ + bindLazyLoad (e) + { + e = e !== null ? e.querySelectorAll('[data-lazyload]') : document.querySelectorAll('[data-lazyload]'); + const length = e.length; + + /** global: IntersectionObserver */ + if (!this.visObs && window.IntersectionObserver) { + this.visObs = new IntersectionObserver(function(eles, obs) { + eles.forEach(ele => { + if (ele.intersectionRatio > 0) { + obs.unobserve(ele.target); + ele.target.src = ele.target.dataset.lazyload; + delete ele.target.dataset.lazyload; + } + }); + }); + } + + for (let i = 0; i < length; ++i) { + if (!this.visObs) { + e[i].src = e[i].dataset.lazyload; + delete e[i].dataset.lazyload; + } else { + this.visObs.observe(e[i]); + } + } + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Input/InputManager.js b/UI/Input/InputManager.js index 1b1fc22..06dd1b6 100644 --- a/UI/Input/InputManager.js +++ b/UI/Input/InputManager.js @@ -13,51 +13,53 @@ /** @namespace jsOMS.UI.Input */ jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.Input.InputManager = function (app) - { - this.keyboardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager(); - this.mouseManager = new jsOMS.UI.Input.Mouse.MouseManager(); - this.voiceManager = new jsOMS.UI.Input.Voice.VoiceManager(app); - }; + jsOMS.UI.Input.InputManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor(app) + { + this.keyboardManager = new jsOMS.UI.Input.Keyboard.KeyboardManager(); + this.mouseManager = new jsOMS.UI.Input.Mouse.MouseManager(); + this.voiceManager = new jsOMS.UI.Input.Voice.VoiceManager(app); + }; - /** - * Get keyboard manager. - * - * @return {Object} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.InputManager.prototype.getKeyboardManager = function () - { - return this.keyboardManager; - }; + /** + * Get keyboard manager. + * + * @return {Object} + * + * @since 1.0.0 + */ + getKeyboardManager () + { + return this.keyboardManager; + }; - /** - * Get mouse manager. - * - * @return {Object} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.InputManager.prototype.getMouseManager = function () - { - return this.mouseManager; - }; + /** + * Get mouse manager. + * + * @return {Object} + * + * @since 1.0.0 + */ + getMouseManager () + { + return this.mouseManager; + }; - /** - * Get voice manager. - * - * @return {Object} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.InputManager.prototype.getVoiceManager = function () - { - return this.voiceManager; - }; + /** + * Get voice manager. + * + * @return {Object} + * + * @since 1.0.0 + */ + getVoiceManager () + { + return this.voiceManager; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Input/Keyboard/KeyboardManager.js b/UI/Input/Keyboard/KeyboardManager.js index 3ee4432..c21c102 100644 --- a/UI/Input/Keyboard/KeyboardManager.js +++ b/UI/Input/Keyboard/KeyboardManager.js @@ -13,99 +13,101 @@ /** @namespace jsOMS.UI.Input.Keyboard */ jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Keyboard'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Keyboard.KeyboardManager = function () - { - this.elements = {}; - this.down = []; - }; - - /** - * Add input listener. - * - * @param {string} element Container id - * @param {Array} keys Keyboard keys - * @param {callback} callback Callback - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.add = function (element, keys, callback) - { - if (typeof this.elements[element] === 'undefined') { - this.elements[element] = []; - - this.bind(element); - } - - this.elements[element].push({keys: keys, callback: callback}); - }; - - /** - * Bind container for keyboard input. - * - * @param {string} element Container id - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.bind = function (element) - { - const self = this; - - // todo: implement keyboard for selected elements right now only global hotkeys possible - document.addEventListener('keydown', function keyBind(event) + jsOMS.UI.Input.Keyboard.KeyboardManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () { - self.down.push(event.keyCode); - }); + this.elements = {}; + this.down = []; + }; - document.addEventListener('keyup', function keyBind(event) + /** + * Add input listener. + * + * @param {string} element Container id + * @param {Array} keys Keyboard keys + * @param {callback} callback Callback + * + * @since 1.0.0 + */ + add (element, keys, callback) { - if (self.down.length > 0) { - self.run(element, event); - self.down = []; + if (typeof this.elements[element] === 'undefined') { + this.elements[element] = []; + + this.bind(element); } - }); - }; - /** - * Execute callback based on key presses. - * - * @param {string} element Container id - * @param {Object} event Key event - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Keyboard.KeyboardManager.prototype.run = function (element, event) - { - if (typeof this.elements[element] === 'undefined') { - throw 'Unexpected elmenet!'; - } + this.elements[element].push({keys: keys, callback: callback}); + }; - const actions = this.elements[element], - length = actions.length, - keyLength = this.down.length; - let match = false; + /** + * Bind container for keyboard input. + * + * @param {string} element Container id + * + * @since 1.0.0 + */ + bind (element) + { + const self = this; - for (let i = 0; i < length; ++i) { - for (let j = 0; j < keyLength; ++j) { - if (actions[i].keys.indexOf(this.down[j]) === -1) { - match = false; + // todo: implement keyboard for selected elements right now only global hotkeys possible + document.addEventListener('keydown', function keyBind(event) + { + self.down.push(event.keyCode); + }); + + document.addEventListener('keyup', function keyBind(event) + { + if (self.down.length > 0) { + self.run(element, event); + self.down = []; + } + }); + }; + + /** + * Execute callback based on key presses. + * + * @param {string} element Container id + * @param {Object} event Key event + * + * @since 1.0.0 + */ + run (element, event) + { + if (typeof this.elements[element] === 'undefined') { + throw 'Unexpected elmenet!'; + } + + const actions = this.elements[element], + length = actions.length, + keyLength = this.down.length; + let match = false; + + for (let i = 0; i < length; ++i) { + for (let j = 0; j < keyLength; ++j) { + if (actions[i].keys.indexOf(this.down[j]) === -1) { + match = false; + + break; + } + + match = true; + } + + if (match) { + jsOMS.preventAll(event); + actions[i].callback(); break; } - - match = true; } - - if (match) { - jsOMS.preventAll(event); - actions[i].callback(); - - break; - } - } - }; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Input/Mouse/MouseManager.js b/UI/Input/Mouse/MouseManager.js index 654d5ab..e4569b9 100644 --- a/UI/Input/Mouse/MouseManager.js +++ b/UI/Input/Mouse/MouseManager.js @@ -13,108 +13,110 @@ /** @namespace jsOMS.UI.Input.Mouse */ jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Mouse'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Mouse.MouseManager = function () - { - this.elements = {}; - this.click = {time: 0}; - }; + jsOMS.UI.Input.Mouse.MouseManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor () + { + this.elements = {}; + this.click = {time: 0}; + }; - /** - * Add input listener. - * - * @param {string} element Container id - * @param {int} type Action type - * @param {int} button Button - * @param {callback} callback Callback - * @param {bool} exact ??? todo: can't remember why this was important oO!!! - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Mouse.MouseManager.prototype.add = function (element, type, button, callback, exact) - { - if (typeof this.elements[element] === 'undefined') { - this.elements[element] = []; - } - - this.bind(element, type); - this.elements[element].push({callback: callback, type: type, button: button, exact: exact}); - }; - - /** - * Add input listener. - * - * @param {string} element Element id - * @param {int} type Action type - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Mouse.MouseManager.prototype.bind = function (element, type) - { - const self = this, - e = document.getElementById(element); - - if (!e) { - return; - } - - if (type === jsOMS.UI.Input.Mouse.EventType.CONTEXT) { - e.addEventListener('contextmenu', function (event) - { - self.run(element, event); - }, false); - } else if (type === jsOMS.UI.Input.Mouse.EventType.LONGPRESS) { - e.addEventListener('mousedown', function (event) - { - self.click.time = new Date().getTime(); - }, false); - - e.addEventListener('mouseup', function (event) - { - const duration = new Date().getTime() - self.click.time; - - if (duration > 650) { - self.run(element, event); - } - - self.click.time = 0; - }, false); - } else if (type === jsOMS.UI.Input.Mouse.EventType.CLICK) { - e.addEventListener('click', function (event) - { - self.run(element, event); - }, false); - } - }; - - /** - * Run mouse input callback. - * - * @param {string} element Element id - * @param {Object} event Click event - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Mouse.MouseManager.prototype.run = function (element, event) - { - if (typeof this.elements[element] === 'undefined') { - throw 'Unexpected elmenet!'; - } - - const actions = this.elements[element], - length = actions.length; - - for (let i = 0; i < length; ++i) { - if ((!actions[i].exact || event.target.getAttribute('id') === element) - && actions[i].button === event.button - ) { - jsOMS.preventAll(event); - actions[i].callback(); + /** + * Add input listener. + * + * @param {string} element Container id + * @param {int} type Action type + * @param {int} button Button + * @param {callback} callback Callback + * @param {bool} exact ??? todo: can't remember why this was important oO!!! + * + * @since 1.0.0 + */ + add (element, type, button, callback, exact) + { + if (typeof this.elements[element] === 'undefined') { + this.elements[element] = []; } - } - }; + + this.bind(element, type); + this.elements[element].push({callback: callback, type: type, button: button, exact: exact}); + }; + + /** + * Add input listener. + * + * @param {string} element Element id + * @param {int} type Action type + * + * @since 1.0.0 + */ + bind (element, type) + { + const self = this, + e = document.getElementById(element); + + if (!e) { + return; + } + + if (type === jsOMS.UI.Input.Mouse.EventType.CONTEXT) { + e.addEventListener('contextmenu', function (event) + { + self.run(element, event); + }, false); + } else if (type === jsOMS.UI.Input.Mouse.EventType.LONGPRESS) { + e.addEventListener('mousedown', function (event) + { + self.click.time = new Date().getTime(); + }, false); + + e.addEventListener('mouseup', function (event) + { + const duration = new Date().getTime() - self.click.time; + + if (duration > 650) { + self.run(element, event); + } + + self.click.time = 0; + }, false); + } else if (type === jsOMS.UI.Input.Mouse.EventType.CLICK) { + e.addEventListener('click', function (event) + { + self.run(element, event); + }, false); + } + }; + + /** + * Run mouse input callback. + * + * @param {string} element Element id + * @param {Object} event Click event + * + * @since 1.0.0 + */ + run (element, event) + { + if (typeof this.elements[element] === 'undefined') { + throw 'Unexpected elmenet!'; + } + + const actions = this.elements[element], + length = actions.length; + + for (let i = 0; i < length; ++i) { + if ((!actions[i].exact || event.target.getAttribute('id') === element) + && actions[i].button === event.button + ) { + jsOMS.preventAll(event); + actions[i].callback(); + } + } + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Input/Touch/TouchManager.js b/UI/Input/Touch/TouchManager.js index e50ac26..74703ef 100644 --- a/UI/Input/Touch/TouchManager.js +++ b/UI/Input/Touch/TouchManager.js @@ -13,113 +13,115 @@ /** @namespace jsOMS.UI.Input.Touch */ jsOMS.Autoloader.defineNamespace('jsOMS.UI.Input.Touch'); - /** - * @constructor - * - * @param {Object} app Application - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Touch.TouchManager = function (app) - { - this.app = app; - this.activeSwipe = {}; - this.resetSwipe(); - }; - - /** - * Reset swipe data. - * - * This is called in between swipes in order to reset previous swipe data. - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Touch.TouchManager.prototype.resetSwipe = function () - { - this.activeSwipe = {'startX': null, 'startY': null, 'time': null}; - }; - - /** - * Adding swipe functionality. - * - * Forwarding swipe to arrow keyes. - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Touch.TouchManager.prototype.add = function (surface) - { - const e = document.getElementById(surface), - self = this; - - if (!e) { - return; - } - - e.addEventListener('touchstart', function (event) + jsOMS.UI.Input.Touch.TouchManager = class { + /** + * @constructor + * + * @param {Object} app Application + * + * @since 1.0.0 + */ + constructor (app) { - const touch = this.changedTouches[0]; + this.app = app; + this.activeSwipe = {}; + this.resetSwipe(); + }; - self.activeSwipe.startX = touch.pageX; - self.activeSwipe.startY = touch.pageY; - self.activeSwipe.time = new Date().getTime(); - - jsOMS.preventAll(event); - }); - - e.addEventListener('touchmove', function (event) + /** + * Reset swipe data. + * + * This is called in between swipes in order to reset previous swipe data. + * + * @since 1.0.0 + */ + resetSwipe () { - jsOMS.preventAll(event); - }); + this.activeSwipe = {'startX': null, 'startY': null, 'time': null}; + }; - e.addEventListener('touchend', function (event) + /** + * Adding swipe functionality. + * + * Forwarding swipe to arrow keyes. + * + * @since 1.0.0 + */ + add (surface) { - const touch = this.changedTouches[0], - distX = touch.pageX - self.activeSwipe.startX, - distY = touch.pageY - self.activeSwipe.startY, - elapsedTime = new Date().getTime() - self.activeSwipe.time; + const e = document.getElementById(surface), + self = this; - self.resetSwipe(); - // todo: only prevent all if success - jsOMS.preventAll(event); - - if (elapsedTime > 300 && distY < 3 && distX < 3) { - let rightClick = MouseEvent('click', - { - bubbles: true, - cancelable: true, - view: window, - screenX: touch.pageX, - screenY: touch.pageY, - clientX: touch.pageX, - clientY: touch.pageY, - ctrlKey: false, - altKey: false, - shiftKey: false, - metaKey: false, - button: 2, - relatedTarget: null - } - ); - - document.dispatchEvent(rightClick); - } else if (elapsedTime < 500) { - /** global: Event */ - const e = new Event('keyup'); - - if (distY > 100) { - e.keyCode = 38; - document.dispatchEvent(e); - } else if (distX > 100) { - e.keyCode = 39; - document.dispatchEvent(e); - } else if (distY < -100) { - e.keyCode = 40; - document.dispatchEvent(e); - } else if (distX < -100) { - e.keyCode = 37; - document.dispatchEvent(e); - } + if (!e) { + return; } - }); - }; + + e.addEventListener('touchstart', function (event) + { + const touch = this.changedTouches[0]; + + self.activeSwipe.startX = touch.pageX; + self.activeSwipe.startY = touch.pageY; + self.activeSwipe.time = new Date().getTime(); + + jsOMS.preventAll(event); + }); + + e.addEventListener('touchmove', function (event) + { + jsOMS.preventAll(event); + }); + + e.addEventListener('touchend', function (event) + { + const touch = this.changedTouches[0], + distX = touch.pageX - self.activeSwipe.startX, + distY = touch.pageY - self.activeSwipe.startY, + elapsedTime = new Date().getTime() - self.activeSwipe.time; + + self.resetSwipe(); + // todo: only prevent all if success + jsOMS.preventAll(event); + + if (elapsedTime > 300 && distY < 3 && distX < 3) { + let rightClick = MouseEvent('click', + { + bubbles: true, + cancelable: true, + view: window, + screenX: touch.pageX, + screenY: touch.pageY, + clientX: touch.pageX, + clientY: touch.pageY, + ctrlKey: false, + altKey: false, + shiftKey: false, + metaKey: false, + button: 2, + relatedTarget: null + } + ); + + document.dispatchEvent(rightClick); + } else if (elapsedTime < 500) { + /** global: Event */ + const e = new Event('keyup'); + + if (distY > 100) { + e.keyCode = 38; + document.dispatchEvent(e); + } else if (distX > 100) { + e.keyCode = 39; + document.dispatchEvent(e); + } else if (distY < -100) { + e.keyCode = 40; + document.dispatchEvent(e); + } else if (distX < -100) { + e.keyCode = 37; + document.dispatchEvent(e); + } + } + }); + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/UI/Input/Voice/ReadManager.js b/UI/Input/Voice/ReadManager.js index 2ba1613..ca0fb6a 100644 --- a/UI/Input/Voice/ReadManager.js +++ b/UI/Input/Voice/ReadManager.js @@ -26,97 +26,99 @@ /** global: SpeechRecognitionEvent */ var SpeechRecognitionEvent = typeof SpeechRecognitionEvent !== 'undefined' ? SpeechRecognitionEvent : typeof webkitSpeechRecognitionEvent !== 'undefined' ? webkitSpeechRecognitionEvent : null; - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.ReadManager = function (lang = 'en-US') - { - this.pitch = 1; - this.rate = 1; - this.lang = lang; - this.voices = []; - this.voice = null; + jsOMS.UI.Input.Voice.ReadManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor (lang = 'en-US') + { + this.pitch = 1; + this.rate = 1; + this.lang = lang; + this.voices = []; + this.voice = null; - if (SpeechRecognition !== null) { - this.voices = window.speechSynthesis.getVoices(); - this.voice = this.voices[0]; - } - }; + if (SpeechRecognition !== null) { + this.voices = window.speechSynthesis.getVoices(); + this.voice = this.voices[0]; + } + }; - /** - * Read text. - * - * @param {string} text Text to read - * - * @return {void} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.ReadManager.prototype.read = function(text) - { - /** global: SpeechSynthesisUtterance */ - let utter = new SpeechSynthesisUtterance(text); - utter.lang = this.lang; - utter.voice = this.voice; - utter.pitch = this.pitch; - utter.rate = this.rate; + /** + * Read text. + * + * @param {string} text Text to read + * + * @return {void} + * + * @since 1.0.0 + */ + read (text) + { + /** global: SpeechSynthesisUtterance */ + let utter = new SpeechSynthesisUtterance(text); + utter.lang = this.lang; + utter.voice = this.voice; + utter.pitch = this.pitch; + utter.rate = this.rate; - window.speechSynthesis.speak(utter); - }; + window.speechSynthesis.speak(utter); + }; - /** - * Set Language. - * - * @param {string} lang Language id (e.g. en-US) - * - * @return {void} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.ReadManager.prototype.setLanguage = function(lang) - { - this.lang = lang; - }; + /** + * Set Language. + * + * @param {string} lang Language id (e.g. en-US) + * + * @return {void} + * + * @since 1.0.0 + */ + setLanguage (lang) + { + this.lang = lang; + }; - /** - * Set pitch. - * - * @param {int} pitch Pitch - * - * @return {void} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.ReadManager.prototype.setPitch = function(pitch) - { - this.pitch = pitch; - }; + /** + * Set pitch. + * + * @param {int} pitch Pitch + * + * @return {void} + * + * @since 1.0.0 + */ + setPitch (pitch) + { + this.pitch = pitch; + }; - /** - * Set rate. - * - * @param {int} rate Rate - * - * @return {void} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.ReadManager.prototype.setRate = function(rate) - { - this.rate = rate; - }; + /** + * Set rate. + * + * @param {int} rate Rate + * + * @return {void} + * + * @since 1.0.0 + */ + setRate (rate) + { + this.rate = rate; + }; - /** - * Get supported voices. - * - * @return {Array} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.ReadManager.prototype.getVoices = function() - { - return this.voices; - }; + /** + * Get supported voices. + * + * @return {Array} + * + * @since 1.0.0 + */ + getVoices () + { + return this.voices; + }; + } }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/UI/Input/Voice/VoiceManager.js b/UI/Input/Voice/VoiceManager.js index 2266c0b..84db38c 100644 --- a/UI/Input/Voice/VoiceManager.js +++ b/UI/Input/Voice/VoiceManager.js @@ -26,146 +26,148 @@ /** global: SpeechRecognitionEvent */ var SpeechRecognitionEvent = typeof SpeechRecognitionEvent !== 'undefined' ? SpeechRecognitionEvent : typeof webkitSpeechRecognitionEvent !== 'undefined' ? webkitSpeechRecognitionEvent : null; - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.VoiceManager = function (app, commands = {}, lang = 'en-US') - { - this.app = app; - this.commands = commands; - this.lang = lang; - this.recognition = null; - this.speechRecognitionList = null; - - if (SpeechRecognition !== null) { - this.recognition = new SpeechRecognition(); - this.speechRecognitionList = new SpeechGrammarList(); - } - }; - - /** - * Setup or re-initialize voice manager. - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.VoiceManager.prototype.setup = function() - { - if (SpeechRecognition === null) { - return; - } - - const self = this; - this.recognition.lang = this.lang; - this.recognition.interimResults = false; - this.recognition.maxAlternatives = 1; - this.recognition.continuous = true; - this.recognition.lang = this.lang; - - if (typeof this.commands !== 'undefined') { - this.speechRecognitionList.addFromString(this.getCommandsString(), 1); - this.recognition.grammars = this.speechRecognitionList; - } - - this.recognition.onstart = function() {}; - this.recognition.onresult = function(event) + jsOMS.UI.Input.Voice.VoiceManager = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor(app, commands = {}, lang = 'en-US') { - let result = jsOMS.trim(event.results[event.resultIndex][0].transcript); + this.app = app; + this.commands = commands; + this.lang = lang; + this.recognition = null; + this.speechRecognitionList = null; - if (self.commands.hasOwnProperty(result)) { - self.commands[result](); + if (SpeechRecognition !== null) { + this.recognition = new SpeechRecognition(); + this.speechRecognitionList = new SpeechGrammarList(); } }; - this.recognition.onspeechend = function() + /** + * Setup or re-initialize voice manager. + * + * @method + * + * @since 1.0.0 + */ + setup() { + if (SpeechRecognition === null) { + return; + } + + const self = this; + this.recognition.lang = this.lang; + this.recognition.interimResults = false; + this.recognition.maxAlternatives = 1; + this.recognition.continuous = true; + this.recognition.lang = this.lang; + + if (typeof this.commands !== 'undefined') { + this.speechRecognitionList.addFromString(this.getCommandsString(), 1); + this.recognition.grammars = this.speechRecognitionList; + } + + this.recognition.onstart = function() {}; + this.recognition.onresult = function(event) + { + let result = jsOMS.trim(event.results[event.resultIndex][0].transcript); + + if (self.commands.hasOwnProperty(result)) { + self.commands[result](); + } + }; + + this.recognition.onspeechend = function() + { + }; + + this.recognition.onnomatch = function(event) + { + jsOMS.Log.Logger.instance.warning('Couldn\'t recognize speech'); + }; + + this.recognition.onerror = function(event) + { + jsOMS.Log.Logger.instance.warning('Error during speech recognition: ' + event.error); + }; }; - this.recognition.onnomatch = function(event) + /** + * Create commands/grammar string from commands + * + * @return {string} + * + * @since 1.0.0 + */ + getCommandsString() { - jsOMS.Log.Logger.instance.warning('Couldn\'t recognize speech'); + return '#JSGF V1.0; grammar phrase; public = ' + Object.keys(this.commands).join(' | ') + ' ;'; }; - this.recognition.onerror = function(event) + /** + * Set language + * + * @param {string} lang Language code (e.g. en-US) + * + * @return {void} + * + * @since 1.0.0 + */ + setLanguage(lang) { - jsOMS.Log.Logger.instance.warning('Error during speech recognition: ' + event.error); + // todo: eventually restart + this.recognition.lang = lang; }; - }; - /** - * Create commands/grammar string from commands - * - * @return {string} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.VoiceManager.prototype.getCommandsString = function() - { - return '#JSGF V1.0; grammar phrase; public = ' + Object.keys(this.commands).join(' | ') + ' ;'; - }; + /** + * Add command/grammar and callback. + * + * @param {string} command Command id + * @param {callback} callback Callback for command + * + * @return {void} + * + * @since 1.0.0 + */ + add(command, callback) + { + this.commands[command] = callback; + }; - /** - * Set language - * - * @param {string} lang Language code (e.g. en-US) - * - * @return {void} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.VoiceManager.prototype.setLanguage = function(lang) - { - // todo: eventually restart - this.recognition.lang = lang; - }; + /** + * Start voice listener. + * + * @return {void} + * + * @since 1.0.0 + */ + start() + { + if (SpeechRecognition === null) { + return; + } - /** - * Add command/grammar and callback. - * - * @param {string} command Command id - * @param {callback} callback Callback for command - * - * @return {void} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.VoiceManager.prototype.add = function(command, callback) - { - this.commands[command] = callback; - }; + this.recognition.start(); + }; - /** - * Start voice listener. - * - * @return {void} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.VoiceManager.prototype.start = function() - { - if (SpeechRecognition === null) { - return; - } + /** + * Stop voice listener. + * + * @return {void} + * + * @since 1.0.0 + */ + stop() + { + if (SpeechRecognition === null) { + return; + } - this.recognition.start(); - }; - - /** - * Stop voice listener. - * - * @return {void} - * - * @since 1.0.0 - */ - jsOMS.UI.Input.Voice.VoiceManager.prototype.stop = function() - { - if (SpeechRecognition === null) { - return; - } - - this.recognition.stop(); - }; + this.recognition.stop(); + }; + } }(window.jsOMS = window.jsOMS || {})); \ No newline at end of file diff --git a/UI/UIManager.js b/UI/UIManager.js index bfff542..8e41dc0 100644 --- a/UI/UIManager.js +++ b/UI/UIManager.js @@ -13,168 +13,170 @@ /** @namespace jsOMS.UI */ jsOMS.Autoloader.defineNamespace('jsOMS.UI'); - /** - * @constructor - * - * @param {Object} app Application object - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager = function (app) - { - this.app = app; - this.formManager = new jsOMS.UI.Component.Form(this.app); - this.tabManager = new jsOMS.UI.Component.Tab(this.app.responseManager); - this.tableManager = new jsOMS.UI.Component.Table(this.app.responseManager); - this.actionManager = new jsOMS.UI.ActionManager(this.app); - this.dragNDrop = new jsOMS.UI.DragNDrop(this.app); - this.generalUI = new jsOMS.UI.GeneralUI(); + jsOMS.UI.UIManager = class { + /** + * @constructor + * + * @param {Object} app Application object + * + * @since 1.0.0 + */ + constructor(app) + { + this.app = app; + this.formManager = new jsOMS.UI.Component.Form(this.app); + this.tabManager = new jsOMS.UI.Component.Tab(this.app.responseManager); + this.tableManager = new jsOMS.UI.Component.Table(this.app.responseManager); + this.actionManager = new jsOMS.UI.ActionManager(this.app); + this.dragNDrop = new jsOMS.UI.DragNDrop(this.app); + this.generalUI = new jsOMS.UI.GeneralUI(); - const self = this; - /** global: MutationObserver */ - this.domObserver = new MutationObserver(function(mutations) { - const length = mutations.length; + const self = this; + /** global: MutationObserver */ + this.domObserver = new MutationObserver(function(mutations) { + const length = mutations.length; - for(let i = 0; i < length; i++) { - self.app.eventManager.trigger(mutations[i].target.id + '-' + mutations[i].type, 0, mutations[i]); + for(let i = 0; i < length; i++) { + self.app.eventManager.trigger(mutations[i].target.id + '-' + mutations[i].type, 0, mutations[i]); + } + }); + }; + + /** + * Bind & rebind UI elements. + * + * @param {string} [id] Element id + * + * @method + * + * @since 1.0.0 + */ + bind(id) + { + if (typeof id === 'undefined') { + this.formManager.bind(); + this.tabManager.bind(); + this.tableManager.bind(); + this.actionManager.bind(); + this.dragNDrop.bind(); + this.generalUI.bind(); + } else { + const tag = document.getElementById(id); + this.generalUI.bind(tag); + + if(!tag) { + return; + } + + switch (tag.tagName) { + case 'form': + this.formManager.bind(id); + break; + case 'table': + this.tableManager.bind(id); + break; + default: + this.actionManager.bind(tag); + } } - }); - }; + }; - /** - * Bind & rebind UI elements. - * - * @param {string} [id] Element id - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager.prototype.bind = function (id) - { - if (typeof id === 'undefined') { - this.formManager.bind(); - this.tabManager.bind(); - this.tableManager.bind(); - this.actionManager.bind(); - this.dragNDrop.bind(); - this.generalUI.bind(); - } else { - const tag = document.getElementById(id); - this.generalUI.bind(tag); + /** + * Get tab manager. + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getFormManager() + { + return this.formManager; + }; - if(!tag) { - return; - } + /** + * Get action manager. + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getActionManager() + { + return this.actionManager; + }; - switch (tag.tagName) { - case 'form': - this.formManager.bind(id); - break; - case 'table': - this.tableManager.bind(id); - break; - default: - this.actionManager.bind(tag); - } - } - }; + /** + * Get drag and drop manager. + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getDragNDrop() + { + return this.dragNDrop; + }; - /** - * Get tab manager. - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager.prototype.getFormManager = function () - { - return this.formManager; - }; + /** + * Get tab manager. + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getTabManager() + { + return this.tabManager; + }; - /** - * Get action manager. - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager.prototype.getActionManager = function () - { - return this.actionManager; - }; + /** + * Get table manager. + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getTableManager() + { + return this.tabManager; + }; - /** - * Get drag and drop manager. - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager.prototype.getDragNDrop = function () - { - return this.dragNDrop; - }; + /** + * Get DOM observer + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getDOMObserver() + { + return this.domObserver; + }; - /** - * Get tab manager. - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager.prototype.getTabManager = function () - { - return this.tabManager; - }; - - /** - * Get table manager. - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager.prototype.getTableManager = function () - { - return this.tabManager; - }; - - /** - * Get DOM observer - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager.prototype.getDOMObserver = function () - { - return this.domObserver; - }; - - /** - * Get general UI - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.UI.UIManager.prototype.getGeneralUI = function () - { - return this.generalUI; - }; + /** + * Get general UI + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + getGeneralUI() + { + return this.generalUI; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Uri/Http.js b/Uri/Http.js index 3e3803c..23baed7 100644 --- a/Uri/Http.js +++ b/Uri/Http.js @@ -15,342 +15,344 @@ /** @namespace jsOMS.Uri.UriFactory */ jsOMS.Autoloader.defineNamespace('jsOMS.Uri.Http'); - /** - * @constructor - * - * @since 1.0.0 - */ - jsOMS.Uri.Http = function (uri) - { - this.uri = ''; - this.scheme = ''; - this.host = ''; - this.port = ''; - this.user = ''; - this.pass = ''; - this.query = null; - this.queryString = ''; - this.fragment = ''; - this.base = ''; - this.root = '/'; + jsOMS.Uri.Http = class { + /** + * @constructor + * + * @since 1.0.0 + */ + constructor(uri) + { + this.uri = ''; + this.scheme = ''; + this.host = ''; + this.port = ''; + this.user = ''; + this.pass = ''; + this.query = null; + this.queryString = ''; + this.fragment = ''; + this.base = ''; + this.root = '/'; - this.set(uri); - }; + this.set(uri); + }; - /** - * Parse uri - * - * @param {string} str Url to parse - * @param {string} [mode] Parsing mode - * - * @return {Object} - * - * @throws {Error} - * - * @function - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.parseUrl = function (str, mode = 'php') - { - const key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', - 'relative', 'path', 'directory', 'file', 'query', 'fragment' - ], - parser = { - php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, - strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, - loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) - }; + /** + * Parse uri + * + * @param {string} str Url to parse + * @param {string} [mode] Parsing mode + * + * @return {Object} + * + * @throws {Error} + * + * @function + * + * @since 1.0.0 + */ + static parseUrl (str, mode = 'php') + { + const key = ['source', 'scheme', 'authority', 'userInfo', 'user', 'pass', 'host', 'port', + 'relative', 'path', 'directory', 'file', 'query', 'fragment' + ], + parser = { + php: /^(?:([^:\/?#]+):)?(?:\/\/()(?:(?:()(?:([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?()(?:(()(?:(?:[^?#\/]*\/)*)()(?:[^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, + strict: /^(?:([^:\/?#]+):)?(?:\/\/((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?))?((((?:[^?#\/]*\/)*)([^?#]*))(?:\?([^#]*))?(?:#(.*))?)/, + loose: /^(?:(?![^:@]+:[^:@\/]*@)([^:\/?#.]+):)?(?:\/\/\/?)?((?:(([^:@]*):?([^:@]*))?@)?([^:\/?#]*)(?::(\d*))?)(((\/(?:[^?#](?![^?#\/]*\.[^?#\/.]+(?:[?#]|$)))*\/?)?([^?#\/]*))(?:\?([^#]*))?(?:#(.*))?)/ // Added one optional slash to post-scheme to catch file:/// (should restrict this) + }; - if (!parser.hasOwnProperty(mode)) { - throw new Error('Unexpected parsing mode.', 'UriFactory', 52); - } - - const m = parser[mode].exec(str), - uri = {}; - let i = 14; - - while (i--) { - if (m[i]) { - uri[key[i]] = m[i]; + if (!parser.hasOwnProperty(mode)) { + throw new Error('Unexpected parsing mode.', 'UriFactory', 52); } - } - delete uri.source; + const m = parser[mode].exec(str), + uri = {}; + let i = 14; - return uri; - }; - - /** - * Get Uri query parameters. - * - * @param {string} query Uri query - * @param {string} name Name of the query to return - * - * @return {null|string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.getUriQueryParameter = function (query, name) - { - name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); - - const regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"), - results = regex.exec(query); - - return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); - }; - - /** - * Get all uri query parameters. - * - * @param {string} query Uri query - * - * @return {Object} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.getAllUriQueryParameters = function (query) - { - const params = {}; - let keyValPairs = [], - pairNum = null; - - if (query.length) { - keyValPairs = query.split('&'); - - for (pairNum in keyValPairs) { - if (!keyValPairs.hasOwnProperty(pairNum)) { - continue; + while (i--) { + if (m[i]) { + uri[key[i]] = m[i]; } - - const key = keyValPairs[pairNum].split('=')[0]; - - if (!key.length) { - continue; - } - - if (typeof params[key] === 'undefined') { - params[key] = []; - } - - params[key].push(keyValPairs[pairNum].split('=')[1]); } - } - return params; - }; + delete uri.source; - /** - * Set uri. - * - * @param {string} uri Uri string - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.set = function (uri) - { - this.uri = uri; + return uri; + }; - const parsed = jsOMS.Uri.Http.parseUrl(this.uri, 'php'); + /** + * Get Uri query parameters. + * + * @param {string} query Uri query + * @param {string} name Name of the query to return + * + * @return {null|string} + * + * @method + * + * @since 1.0.0 + */ + static getUriQueryParameter (query, name) + { + name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]"); - this.scheme = parsed['scheme']; - this.host = parsed['host']; - this.port = parsed['port']; - this.user = parsed['user']; - this.pass = parsed['pass']; - this.path = parsed['path']; + const regex = new RegExp("[\\?&]*" + name + "=([^&#]*)"), + results = regex.exec(query); - if (this.path.endsWith('.php')) { - this.path = this.path.substr(0, -4); - } + return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' ')); + }; - this.queryString = typeof parsed['query'] !== 'undefined' ? parsed['query'] : []; + /** + * Get all uri query parameters. + * + * @param {string} query Uri query + * + * @return {Object} + * + * @method + * + * @since 1.0.0 + */ + static getAllUriQueryParameters (query) + { + const params = {}; + let keyValPairs = [], + pairNum = null; - if (this.queryString !== null) { - this.query = jsOMS.Uri.Http.getAllUriQueryParameters(this.queryString); - } + if (query.length) { + keyValPairs = query.split('&'); - this.fragment = typeof parsed['fragment'] !== 'undefined' ? parsed['fragment'] : ''; - this.base = this.scheme + '://' + this.host + this.root; - }; + for (pairNum in keyValPairs) { + if (!keyValPairs.hasOwnProperty(pairNum)) { + continue; + } - /** - * Set root path. - * - * @param {string} rootPath Uri root path - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.setRootPath = function(rootPath) - { - this.root = rootPath; - this.set(this.uri); - }; + const key = keyValPairs[pairNum].split('=')[0]; - /** - * Get Uri base - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getBase = function() - { - return this.base; - }; + if (!key.length) { + continue; + } - /** - * Get Uri scheme - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getScheme = function() - { - return this.scheme; - }; + if (typeof params[key] === 'undefined') { + params[key] = []; + } - /** - * Get Uri host - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getHost = function() - { - return this.host; - }; + params[key].push(keyValPairs[pairNum].split('=')[1]); + } + } - /** - * Get Uri port - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getPort = function() - { - return this.port; - }; + return params; + }; - /** - * Get Uri user - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getUser = function() - { - return this.user; - }; + /** + * Set uri. + * + * @param {string} uri Uri string + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + set (uri) + { + this.uri = uri; - /** - * Get Uri pass - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getPass = function() - { - return this.pass; - }; + const parsed = jsOMS.Uri.Http.parseUrl(this.uri, 'php'); - /** - * Get Uri query - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getQuery = function() - { - return this.queryString; - }; + this.scheme = parsed['scheme']; + this.host = parsed['host']; + this.port = parsed['port']; + this.user = parsed['user']; + this.pass = parsed['pass']; + this.path = parsed['path']; - /** - * Get Uri - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getUri = function() - { - return this.uri; - }; + if (this.path.endsWith('.php')) { + this.path = this.path.substr(0, -4); + } - /** - * Get Uri fragment - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getFragment = function() - { - return this.fragment; - }; + this.queryString = typeof parsed['query'] !== 'undefined' ? parsed['query'] : []; - /** - * Get Uri path - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getPath = function() - { - return this.path; - }; + if (this.queryString !== null) { + this.query = jsOMS.Uri.Http.getAllUriQueryParameters(this.queryString); + } - /** - * Get Uri path offset - * - * @return {int} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.Http.prototype.getPathOffset = function() - { - return jsOMS.substr_count(this.root, '/') - 1; - }; + this.fragment = typeof parsed['fragment'] !== 'undefined' ? parsed['fragment'] : ''; + this.base = this.scheme + '://' + this.host + this.root; + }; + + /** + * Set root path. + * + * @param {string} rootPath Uri root path + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + setRootPath(rootPath) + { + this.root = rootPath; + this.set(this.uri); + }; + + /** + * Get Uri base + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getBase() + { + return this.base; + }; + + /** + * Get Uri scheme + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getScheme() + { + return this.scheme; + }; + + /** + * Get Uri host + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getHost() + { + return this.host; + }; + + /** + * Get Uri port + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getPort() + { + return this.port; + }; + + /** + * Get Uri user + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getUser() + { + return this.user; + }; + + /** + * Get Uri pass + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getPass() + { + return this.pass; + }; + + /** + * Get Uri query + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getQuery() + { + return this.queryString; + }; + + /** + * Get Uri + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getUri() + { + return this.uri; + }; + + /** + * Get Uri fragment + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getFragment() + { + return this.fragment; + }; + + /** + * Get Uri path + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + getPath() + { + return this.path; + }; + + /** + * Get Uri path offset + * + * @return {int} + * + * @method + * + * @since 1.0.0 + */ + getPathOffset() + { + return jsOMS.substr_count(this.root, '/') - 1; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Uri/UriFactory.js b/Uri/UriFactory.js index 4a9ac91..b5c533f 100644 --- a/Uri/UriFactory.js +++ b/Uri/UriFactory.js @@ -13,6 +13,248 @@ /** @namespace jsOMS.Uri.UriFactory */ jsOMS.Autoloader.defineNamespace('jsOMS.Uri.UriFactory'); + jsOMS.Uri.UriFactory = class { + /** + * Set uri query + * + * @param {string} key Query key + * @param {string} value Query value + * @param {boolean} [overwrite] Overwrite if already exists? + * + * @return {boolean} + * + * @function + * + * @since 1.0.0 + */ + static setQuery (key, value, overwrite) + { + overwrite = typeof overwrite !== 'undefined' ? overwrite : true; + + if (overwrite || !jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) { + jsOMS.Uri.UriFactory.uri[key] = value; + + return true; + } + + return false; + }; + + /** + * Get query + * + * @param {string} key + * + * @return {string} + * + * @method + * + * @since 1.0.0 + */ + static getQuery (key) + { + if (!jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) { + return ''; + } + + return jsOMS.Uri.UriFactory.uri[key]; + }; + + /** + * Clear all uri components + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + static clearAll () + { + jsOMS.Uri.UriFactory.uri = {}; + + return true; + }; + + /** + * Clear uri component + * + * @param {string} key Uri key for component + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + static clear (key) + { + if (jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) { + delete jsOMS.Uri.UriFactory.uri[key]; + + return true; + } + + return false; + }; + + /** + * Clear uri components that follow a certain pattern + * + * @param {string} pattern Uri key pattern to remove + * + * @return {boolean} + * + * @method + * + * @since 1.0.0 + */ + static clearLike (pattern) + { + let success = false; + const regexp = new RegExp(pattern); + + for (let key in jsOMS.Uri.UriFactory.uri) { + if (jsOMS.Uri.UriFactory.uri.hasOwnProperty(key) && regexp.test(key)) { + delete jsOMS.Uri.UriFactory.uri[key]; + success = true; + } + } + + return success; + }; + + /** + * Remove multiple definitions of the same parameter + * + * The parameters will be recognized from right to left since it's easier to push at the end. + * + * @param {string} url Url + * + * @return {string} + * + * @function + * + * @since 1.0.0 + */ + static unique (url) + { + const parts = url.split('?'); + + if (parts.length >= 2) { + let full = parts[1], + pars = full.split('&'), + comps = {}, + spl = null, + length = pars.length; + + for (let i = 0; i < length; ++i) { + spl = pars[i].split('='); + comps[spl[0]] = spl[1]; + } + + pars = []; + for (let a in comps) { + if (comps.hasOwnProperty(a)) { + pars.push(a + '=' + comps[a]); + } + } + + url = parts[0] + '?' + pars.join('&'); + } + + return url; + }; + + /** + * Build uri + * + * # = DOM id + * . = DOM class + * / = Current path + * ? = Current query + * @ = + * $ = Other data + * % = Current url + * + * @param {string} uri Raw uri + * @param {Object} [toMatch] Key/value pair to replace in raw + * + * @function + * + * @since 1.0.0 + */ + static build (uri, toMatch) + { + const current = jsOMS.Uri.Http.parseUrl(window.location.href); + let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$][a-zA-Z0-9\-]*\}', 'g'), function (match) + { + match = match.substr(1, match.length - 2); + + if (typeof toMatch !== 'undefined' && toMatch.hasOwnProperty(match)) { + return toMatch[match]; + } else if (typeof jsOMS.Uri.UriFactory.uri[match] !== 'undefined') { + return jsOMS.Uri.UriFactory.uri[match]; + } else if (match.indexOf('#') === 0) { + const e = document.getElementById(match.substr(1)); + + if (e) { + return e.value; + } + + return ''; + } else if (match.indexOf('?') === 0) { + return jsOMS.Uri.Http.getUriQueryParameter(current.query, match.substr(1)); + } else if (match.indexOf('/') === 0) { + // todo: second match should return second path + return 'ERROR PATH'; + } else if (match === '%') { + return window.location.href; + } else { + return match; + } + }); + + if (parsed.indexOf('?') === -1) { + parsed = parsed.replace('&', '?'); + } + + parsed = jsOMS.Uri.UriFactory.unique(parsed); + + return parsed; + }; + + /** + * Set uri builder components. + * + * @return {void} + * + * @method + * + * @since 1.0.0 + */ + static setupUriBuilder (uri) + { + jsOMS.Uri.UriFactory.setQuery('/scheme', uri.getScheme()); + jsOMS.Uri.UriFactory.setQuery('/host', uri.getHost()); + jsOMS.Uri.UriFactory.setQuery('/base', jsOMS.rtrim(uri.getBase(), '/')); + jsOMS.Uri.UriFactory.setQuery('?', uri.getQuery()); + jsOMS.Uri.UriFactory.setQuery('%', uri.getUri()); + jsOMS.Uri.UriFactory.setQuery('#', uri.getFragment()); + jsOMS.Uri.UriFactory.setQuery('/', uri.getPath()); + jsOMS.Uri.UriFactory.setQuery(':user', uri.getUser()); + jsOMS.Uri.UriFactory.setQuery(':pass', uri.getPass()); + + const query = uri.getQuery(); + + for (let key in query) { + if (query.hasOwnProperty(key)) { + jsOMS.Uri.UriFactory.setQuery('?' + key, query[key]); + } + } + }; + } + /** * Uri values * @@ -20,244 +262,4 @@ * @since 1.0.0 */ jsOMS.Uri.UriFactory.uri = {}; - - /** - * Set uri query - * - * @param {string} key Query key - * @param {string} value Query value - * @param {boolean} [overwrite] Overwrite if already exists? - * - * @return {boolean} - * - * @function - * - * @since 1.0.0 - */ - jsOMS.Uri.UriFactory.setQuery = function (key, value, overwrite) - { - overwrite = typeof overwrite !== 'undefined' ? overwrite : true; - - if (overwrite || !jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) { - jsOMS.Uri.UriFactory.uri[key] = value; - - return true; - } - - return false; - }; - - /** - * Get query - * - * @param {string} key - * - * @return {string} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.UriFactory.getQuery = function (key) - { - if (!jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) { - return ''; - } - - return jsOMS.Uri.UriFactory.uri[key]; - }; - - /** - * Clear all uri components - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.UriFactory.clearAll = function() - { - jsOMS.Uri.UriFactory.uri = {}; - - return true; - }; - - /** - * Clear uri component - * - * @param {string} key Uri key for component - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.UriFactory.clear = function(key) - { - if (jsOMS.Uri.UriFactory.uri.hasOwnProperty(key)) { - delete jsOMS.Uri.UriFactory.uri[key]; - - return true; - } - - return false; - }; - - /** - * Clear uri components that follow a certain pattern - * - * @param {string} pattern Uri key pattern to remove - * - * @return {boolean} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.UriFactory.clearLike = function(pattern) - { - let success = false; - const regexp = new RegExp(pattern); - - for (let key in jsOMS.Uri.UriFactory.uri) { - if (jsOMS.Uri.UriFactory.uri.hasOwnProperty(key) && regexp.test(key)) { - delete jsOMS.Uri.UriFactory.uri[key]; - success = true; - } - } - - return success; - }; - - /** - * Remove multiple definitions of the same parameter - * - * The parameters will be recognized from right to left since it's easier to push at the end. - * - * @param {string} url Url - * - * @return {string} - * - * @function - * - * @since 1.0.0 - */ - jsOMS.Uri.UriFactory.unique = function (url) - { - const parts = url.split('?'); - - if (parts.length >= 2) { - let full = parts[1], - pars = full.split('&'), - comps = {}, - spl = null, - length = pars.length; - - for (let i = 0; i < length; ++i) { - spl = pars[i].split('='); - comps[spl[0]] = spl[1]; - } - - pars = []; - for (let a in comps) { - if (comps.hasOwnProperty(a)) { - pars.push(a + '=' + comps[a]); - } - } - - url = parts[0] + '?' + pars.join('&'); - } - - return url; - }; - - /** - * Build uri - * - * # = DOM id - * . = DOM class - * / = Current path - * ? = Current query - * @ = - * $ = Other data - * % = Current url - * - * @param {string} uri Raw uri - * @param {Object} [toMatch] Key/value pair to replace in raw - * - * @function - * - * @since 1.0.0 - */ - jsOMS.Uri.UriFactory.build = function (uri, toMatch) - { - const current = jsOMS.Uri.Http.parseUrl(window.location.href); - let parsed = uri.replace(new RegExp('\{[\/#\?%@\.\$][a-zA-Z0-9\-]*\}', 'g'), function (match) - { - match = match.substr(1, match.length - 2); - - if (typeof toMatch !== 'undefined' && toMatch.hasOwnProperty(match)) { - return toMatch[match]; - } else if (typeof jsOMS.Uri.UriFactory.uri[match] !== 'undefined') { - return jsOMS.Uri.UriFactory.uri[match]; - } else if (match.indexOf('#') === 0) { - const e = document.getElementById(match.substr(1)); - - if (e) { - return e.value; - } - - return ''; - } else if (match.indexOf('?') === 0) { - return jsOMS.Uri.Http.getUriQueryParameter(current.query, match.substr(1)); - } else if (match.indexOf('/') === 0) { - // todo: second match should return second path - return 'ERROR PATH'; - } else if (match === '%') { - return window.location.href; - } else { - return match; - } - }); - - if (parsed.indexOf('?') === -1) { - parsed = parsed.replace('&', '?'); - } - - parsed = jsOMS.Uri.UriFactory.unique(parsed); - - return parsed; - }; - - /** - * Set uri builder components. - * - * @return {void} - * - * @method - * - * @since 1.0.0 - */ - jsOMS.Uri.UriFactory.setupUriBuilder = function (uri) - { - jsOMS.Uri.UriFactory.setQuery('/scheme', uri.getScheme()); - jsOMS.Uri.UriFactory.setQuery('/host', uri.getHost()); - jsOMS.Uri.UriFactory.setQuery('/base', jsOMS.rtrim(uri.getBase(), '/')); - jsOMS.Uri.UriFactory.setQuery('?', uri.getQuery()); - jsOMS.Uri.UriFactory.setQuery('%', uri.getUri()); - jsOMS.Uri.UriFactory.setQuery('#', uri.getFragment()); - jsOMS.Uri.UriFactory.setQuery('/', uri.getPath()); - jsOMS.Uri.UriFactory.setQuery(':user', uri.getUser()); - jsOMS.Uri.UriFactory.setQuery(':pass', uri.getPass()); - - const query = uri.getQuery(); - - for (let key in query) { - if (query.hasOwnProperty(key)) { - jsOMS.Uri.UriFactory.setQuery('?' + key, query[key]); - } - } - }; }(window.jsOMS = window.jsOMS || {})); diff --git a/Views/FormView.js b/Views/FormView.js index 9cf6f35..a9ddd1d 100644 --- a/Views/FormView.js +++ b/Views/FormView.js @@ -16,364 +16,366 @@ /** @namespace jsOMS.Views */ jsOMS.Autoloader.defineNamespace('jsOMS.Views'); - /** - * @constructor - * - * @param {string} id Form id - * - * @since 1.0.0 - */ - jsOMS.Views.FormView = function (id) - { - this.id = id; + jsOMS.Views.FormView = class { + /** + * @constructor + * + * @param {string} id Form id + * + * @since 1.0.0 + */ + constructor (id) + { + this.id = id; - this.initializeMembers(); - this.bind(); + this.initializeMembers(); + this.bind(); - this.success = null; - this.lastSubmit = 0; - }; + this.success = null; + this.lastSubmit = 0; + }; - /** - * Initialize members - * - * Pulled out since this is used in a cleanup process - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.initializeMembers = function () - { - this.submitInjects = []; - this.method = 'POST'; - this.action = ''; - }; + /** + * Initialize members + * + * Pulled out since this is used in a cleanup process + * + * @since 1.0.0 + */ + initializeMembers () + { + this.submitInjects = []; + this.method = 'POST'; + this.action = ''; + }; - /** - * Get method - * - * @return {string} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getMethod = function () - { - return this.method; - }; + /** + * Get method + * + * @return {string} + * + * @since 1.0.0 + */ + getMethod () + { + return this.method; + }; - /** - * Get action - * - * @return {string} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getAction = function () - { - return this.action; - }; + /** + * Get action + * + * @return {string} + * + * @since 1.0.0 + */ + getAction () + { + return this.action; + }; - jsOMS.Views.FormView.prototype.getLastSubmit = function () - { - return this.lastSubmit; - }; + getLastSubmit () + { + return this.lastSubmit; + }; - jsOMS.Views.FormView.prototype.updateLastSubmit = function () - { - this.lastSubmit = Math.floor(Date.now()); - }; + updateLastSubmit () + { + this.lastSubmit = Math.floor(Date.now()); + }; - /** - * Get submit elements - * - * @return {Object} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getSubmit = function () - { - return document.querySelectorAll('#' + this.id + ' input[type=submit], button[form=' + this.id + '][type=submit]'); - }; + /** + * Get submit elements + * + * @return {Object} + * + * @since 1.0.0 + */ + getSubmit () + { + return document.querySelectorAll('#' + this.id + ' input[type=submit], button[form=' + this.id + '][type=submit]'); + }; - /** - * Get success callback - * - * @return {callback} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getSuccess = function () - { - return this.success; - }; + /** + * Get success callback + * + * @return {callback} + * + * @since 1.0.0 + */ + getSuccess () + { + return this.success; + }; - /** - * Set success callback - * - * @param {callback} callback Callback - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.setSuccess = function (callback) - { - this.success = callback; - }; + /** + * Set success callback + * + * @param {callback} callback Callback + * + * @since 1.0.0 + */ + setSuccess (callback) + { + this.success = callback; + }; - /** - * Inject submit with post callback - * - * @param {callback} callback Callback - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.injectSubmit = function (callback) - { - this.submitInjects.push(callback); - }; + /** + * Inject submit with post callback + * + * @param {callback} callback Callback + * + * @since 1.0.0 + */ + injectSubmit (callback) + { + this.submitInjects.push(callback); + }; - /** - * Get form elements - * - * @return {Array} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getFormElements = function () - { - const form = document.getElementById(this.id); + /** + * Get form elements + * + * @return {Array} + * + * @since 1.0.0 + */ + getFormElements () + { + const form = document.getElementById(this.id); - if (!form) { - return []; - } - - const selects = form.getElementsByTagName('select'), - textareas = form.getElementsByTagName('textarea'), - inputs = form.getElementsByTagName('input'), - canvas = form.getElementsByTagName('canvas'), - external = document.querySelectorAll('[form=' + this.id + ']'); - - return this.getUniqueFormElements( - Array.prototype.slice.call(inputs).concat( - Array.prototype.slice.call(selects), - Array.prototype.slice.call(textareas), - Array.prototype.slice.call(external) - ) - ); - }; - - /** - * Get unique form elements - * - * @param {Array} arr Form element array - * - * @return {Array} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getUniqueFormElements = function (arr) - { - let seen = {}; - - return arr.filter(function(item) { - return seen.hasOwnProperty(item.name) ? false : (seen[item.name] = true); - }); - }; - - /** - * Get form data - * - * @return {Object} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getData = function () - { - const data = {}, - elements = this.getFormElements(), - length = elements.length; - - let value = null; - - for (let i = 0; i < length; ++i) { - if (elements[i].tagName.toLowerCase() === 'canvas') { - value = elements[i].toDataURL('image/png'); - } else { - value = elements[i].value; + if (!form) { + return []; } - data[jsOMS.Views.FormView.getElementId(elements[i])] = value; - } + const selects = form.getElementsByTagName('select'), + textareas = form.getElementsByTagName('textarea'), + inputs = form.getElementsByTagName('input'), + canvas = form.getElementsByTagName('canvas'), + external = document.querySelectorAll('[form=' + this.id + ']'); - return data; - }; + return this.getUniqueFormElements( + Array.prototype.slice.call(inputs).concat( + Array.prototype.slice.call(selects), + Array.prototype.slice.call(textareas), + Array.prototype.slice.call(external) + ) + ); + }; - /** - * Get form id - * - * @return {string} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getId = function () - { - return this.id; - }; + /** + * Get unique form elements + * + * @param {Array} arr Form element array + * + * @return {Array} + * + * @since 1.0.0 + */ + getUniqueFormElements (arr) + { + let seen = {}; - /** - * Validate form - * - * @return {boolean} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.isValid = function () - { - const elements = this.getFormElements(), - length = elements.length; + return arr.filter(function(item) { + return seen.hasOwnProperty(item.name) ? false : (seen[item.name] = true); + }); + }; + + /** + * Get form data + * + * @return {Object} + * + * @since 1.0.0 + */ + getData () + { + const data = {}, + elements = this.getFormElements(), + length = elements.length; + + let value = null; - try { for (let i = 0; i < length; ++i) { - if ((elements[i].required && elements[i].value === '') - || (typeof elements[i].pattern !== 'undefined' - && elements[i].pattern !== '' - && !(new RegExp(elements[i].pattern)).test(elements[i].value)) - ) { - return false; + if (elements[i].tagName.toLowerCase() === 'canvas') { + value = elements[i].toDataURL('image/png'); + } else { + value = elements[i].value; + } + + data[jsOMS.Views.FormView.getElementId(elements[i])] = value; + } + + return data; + }; + + /** + * Get form id + * + * @return {string} + * + * @since 1.0.0 + */ + getId () + { + return this.id; + }; + + /** + * Validate form + * + * @return {boolean} + * + * @since 1.0.0 + */ + isValid () + { + const elements = this.getFormElements(), + length = elements.length; + + try { + for (let i = 0; i < length; ++i) { + if ((elements[i].required && elements[i].value === '') + || (typeof elements[i].pattern !== 'undefined' + && elements[i].pattern !== '' + && !(new RegExp(elements[i].pattern)).test(elements[i].value)) + ) { + return false; + } + } + } catch (e) { + jsOMS.Log.Logger.instance.error(e); + } + + return true; + }; + + /** + * Get form element + * + * @return {Object} + * + * @since 1.0.0 + */ + getElement () + { + return document.getElementById(this.getId()); + }; + + /** + * Get form element id + * + * @return {string} + * + * @since 1.0.0 + */ + static getElementId (e) + { + let id = e.getAttribute('name'); + + if (!id) { + id = e.getAttribute('id'); + } else { + return id; + } + + if (!id) { + id = e.getAttribute('type'); + } else { + return id; + } + + return id; + }; + + /** + * Get submit injects + * + * @return {Object} + * + * @since 1.0.0 + */ + getSubmitInjects () + { + return this.submitInjects; + }; + + /** + * Bind form + * + * @since 1.0.0 + */ + bind () + { + this.clean(); + + const e = document.getElementById(this.id); + + if (!e) { + return; + } + + this.method = e.attributes['method'].value; + this.action = e.action; + + const elements = this.getFormElements(), + length = elements.length; + + for (let i = 0; i < length; ++i) { + switch (elements[i].tagName) { + case 'input': + jsOMS.UI.Input.bind(elements[i]); + break; + case 'select': + this.bindSelect(elements[i]); + break; + case 'textarea': + this.bindTextarea(elements[i]); + break; + case 'button': + this.bindButton(elements[i]); + break; + default: } } - } catch (e) { - jsOMS.Log.Logger.instance.error(e); - } + }; - return true; - }; + /** + * Unbind form + * + * @since 1.0.0 + */ + unbind () + { + const elements = this.getFormElements(), + length = elements.length; - /** - * Get form element - * - * @return {Object} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getElement = function () - { - return document.getElementById(this.getId()); - }; - - /** - * Get form element id - * - * @return {string} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.getElementId = function (e) - { - let id = e.getAttribute('name'); - - if (!id) { - id = e.getAttribute('id'); - } else { - return id; - } - - if (!id) { - id = e.getAttribute('type'); - } else { - return id; - } - - return id; - }; - - /** - * Get submit injects - * - * @return {Object} - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.getSubmitInjects = function () - { - return this.submitInjects; - }; - - /** - * Bind form - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.bind = function () - { - this.clean(); - - const e = document.getElementById(this.id); - - if (!e) { - return; - } - - this.method = e.attributes['method'].value; - this.action = e.action; - - const elements = this.getFormElements(), - length = elements.length; - - for (let i = 0; i < length; ++i) { - switch (elements[i].tagName) { - case 'input': - jsOMS.UI.Input.bind(elements[i]); - break; - case 'select': - this.bindSelect(elements[i]); - break; - case 'textarea': - this.bindTextarea(elements[i]); - break; - case 'button': - this.bindButton(elements[i]); - break; - default: + for (let i = 0; i < length; ++i) { + switch (elements[i].tagName) { + case 'input': + jsOMS.UI.Input.unbind(elements[i]); + break; + case 'select': + this.bindSelect(elements[i]); + break; + case 'textarea': + this.bindTextarea(elements[i]); + break; + case 'button': + this.bindButton(elements[i]); + break; + default: + } } - } - }; + }; - /** - * Unbind form - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.unbind = function () - { - const elements = this.getFormElements(), - length = elements.length; - - for (let i = 0; i < length; ++i) { - switch (elements[i].tagName) { - case 'input': - jsOMS.UI.Input.unbind(elements[i]); - break; - case 'select': - this.bindSelect(elements[i]); - break; - case 'textarea': - this.bindTextarea(elements[i]); - break; - case 'button': - this.bindButton(elements[i]); - break; - default: - } - } - }; - - /** - * Clean form - * - * @since 1.0.0 - */ - jsOMS.Views.FormView.prototype.clean = function () - { - this.unbind(); - this.initializeMembers(); - }; + /** + * Clean form + * + * @since 1.0.0 + */ + clean () + { + this.unbind(); + this.initializeMembers(); + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Views/TableView.js b/Views/TableView.js index 69fa6ae..6fb6c18 100644 --- a/Views/TableView.js +++ b/Views/TableView.js @@ -1,38 +1,40 @@ (function (jsOMS) { "use strict"; - jsOMS.TableView = function () { - this.table = null; - }; + jsOMS.TableView = class { + constructor () { + this.table = null; + }; - /** - * None, Pagination, Infinite - */ - jsOMS.TableView.prototype.setExtensible = function () { + /** + * None, Pagination, Infinite + */ + setExtensible () { - }; + }; - jsOMS.TableView.prototype.add = function (element) { + add (element) { - }; + }; - jsOMS.TableView.prototype.addCollection = function (collection) { + addCollection (collection) { - }; + }; - jsOMS.TableView.prototype.remove = function (id) { + remove (id) { - }; + }; - jsOMS.TableView.prototype.get = function (id) { + get (id) { - }; + }; - jsOMS.TableView.prototype.filter = function (id) { + filter (id) { - }; + }; - jsOMS.TableView.prototype.request = function (filter) { + request (filter) { - }; + }; + } }(window.jsOMS = window.jsOMS || {})); diff --git a/Views/ViewAbstract.js b/Views/ViewAbstract.js index facf332..b7ac24d 100644 --- a/Views/ViewAbstract.js +++ b/Views/ViewAbstract.js @@ -1,32 +1,34 @@ (function (jsOMS) { "use strict"; - jsOMS.ViewAbstract = function () - { - this.element = null; - this.data = []; - }; + jsOMS.ViewAbstract = class { + constructor () + { + this.element = null; + this.data = []; + }; - jsOMS.ViewAbstract.prototype.bind = function (node) - { - this.element = node; - }; + bind (node) + { + this.element = node; + }; - jsOMS.ViewAbstract.prototype.addData = function(id, data, overwrite) - { - overwrite = typeof overwrite !== 'undefined' ? overwrite : false; + addData(id, data, overwrite) + { + overwrite = typeof overwrite !== 'undefined' ? overwrite : false; - if (typeof this.data[id] === 'undefined' || overwrite) { - this.data[id] = data; + if (typeof this.data[id] === 'undefined' || overwrite) { + this.data[id] = data; - return true; - } + return true; + } - return false; - }; + return false; + }; - jsOMS.ViewAbstract.prototype.getData = function(id) - { - return typeof this.data[id] !== 'undefined' ? this.data[id] : undefined; - }; + getData(id) + { + return typeof this.data[id] !== 'undefined' ? this.data[id] : undefined; + }; + } }(window.jsOMS = window.jsOMS || {}));