diff --git a/src/libs/clipboard.js b/src/libs/clipboard.js deleted file mode 100644 index 478338e..0000000 --- a/src/libs/clipboard.js +++ /dev/null @@ -1,746 +0,0 @@ - -/*! - * clipboard.js v1.5.5 - * https://zenorocha.github.io/clipboard.js - * - * Licensed MIT © Zeno Rocha - */ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Clipboard = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o 1 && !( user in idrinth.chat.chatRank[chatId] ) ) { - promotionModes.push ( { - chat: chatId, - label: 'Invite to Chat ' + document.getElementById ( 'idrinth-chat-tab-click-' + chatId ).innerHTML, - rank: 'User', - requiredRank: 1 - } ); + if ( idrinth.chat.chatRank.hasOwnProperty ( chatId ) ) { + var intChatId = parseInt ( chatId, 10 ); + if ( document.getElementById ( 'idrinth-chat-tab-click-' + chatId ) && intChatId !== chat && intChatId > 1 && !( user in idrinth.chat.chatRank[chatId] ) ) { + promotionModes.push ( { + chat: chatId, + label: 'Invite to Chat ' + document.getElementById ( 'idrinth-chat-tab-click-' + chatId ).innerHTML, + rank: 'User', + requiredRank: 1 + } ); + } } } return promotionModes; @@ -100,8 +102,9 @@ idrinth.chat = { if ( !hasRights ( node.requiredRank, ownRank ) ) { return; } + var translation = idrinth.text.get ( config.label ); return { - content: node.label, + content: translation === idrinth.text.data.default ? config.label : translation, type: 'li', attributes: [ { name: 'onclick', @@ -493,7 +496,7 @@ idrinth.chat = { start: function () { var build = function () { var makeInput = function ( label ) { - var translation = idrinth.text.get( label ); + var translation = idrinth.text.get ( label ); return { type: 'li', children: [ @@ -518,7 +521,7 @@ idrinth.chat = { }; }; var makeButton = function ( label, onclick ) { - var translation = idrinth.text.get( label ); + var translation = idrinth.text.get ( label ); return { type: 'li', children: [ @@ -900,7 +903,7 @@ idrinth.chat = { ], attributes: [ { name: 'style', - value: idrinth.ui.getPosition ( element ) + value: idrinth.ui.getElementPositioning ( element, 0, 0 ) } ] } ) ); }, diff --git a/src/mods/core.js b/src/mods/core.js index 295427b..8fcc7ed 100644 --- a/src/mods/core.js +++ b/src/mods/core.js @@ -37,7 +37,9 @@ idrinth.core = { requestHandler.timeout = 30000; requestHandler.ontimeout = function ( event ) { var request = ( event || window.event ).target; - timeout.bind ( request ); + if ( typeof timeout === 'function' ) { + timeout.bind ( request ); + } delete idrinth.core.ajax.active[request._url]; idrinth.core.log ( 'Request to ' + request._url + ' failed.' ); }; @@ -59,23 +61,34 @@ idrinth.core = { idrinth.core.ajax.active[url].send ( ); } }, - copyToClipboard: function ( text ) { - var success; - try { - var textAreaElement = idrinth.ui.buildElement ( { - type: 'textarea', - id: "idrinth-copy-helper" - } ); - textAreaElement.value = text; - idrinth.ui.body.appendChild ( textAreaElement ); - textAreaElement.select ( ); - success = document.execCommand ( 'copy' ); - } catch ( exception ) { - idrinth.core.log ( exception.getMessage ( ) ); - success = false; + copyToClipboard: { + text: function ( text ) { + var success; + try { + var textAreaElement = idrinth.ui.buildElement ( { + type: 'textarea', + id: "idrinth-copy-helper" + } ); + textAreaElement.value = text; + idrinth.ui.body.appendChild ( textAreaElement ); + textAreaElement.select ( ); + success = document.execCommand ( 'copy' ); + } catch ( exception ) { + idrinth.core.log ( exception.getMessage ( ) ); + success = false; + } + idrinth.ui.removeElement ( "idrinth-copy-helper" ); + return success; + }, + element: function ( element ) { + if ( element.hasAttribute ( 'data-clipboard-text' ) ) { + return idrinth.core.copyToClipboard.text ( element.getAttribute ( 'data-clipboard-text' ) ); + } + if ( element.value ) { + return idrinth.core.copyToClipboard.text ( element.value ); + } + return idrinth.core.copyToClipboard.text ( element.innerHTML ); } - idrinth.ui.removeElement ( "idrinth-copy-helper" ); - return success; }, sendNotification: function ( title, content ) { if ( !( "Notification" in window ) ) { @@ -110,16 +123,11 @@ idrinth.core = { idrinth.core.multibind.events[event][selector] = idrinth.core.multibind.events[event][selector] ? idrinth.core.multibind.events[event][selector] : [ ]; idrinth.core.multibind.events[event][selector].push ( method ); }; - if ( idrinth.core.multibind.events[event] ) { - var attribute = 'idrinth.core.triggered(this,\'' + event + '\');'; - //trying not to break all old code there - if ( idrinth.ui.body.getAttribute ( 'on' + event ) ) { - attribute += idrinth.ui.body.getAttribute ( 'on' + event ); - } - if ( idrinth.ui.body['on' + event] && typeof idrinth.ui.body['on' + event] === 'function' ) { - bind ( event, 'body', idrinth.ui.body['on' + event] ); - } - idrinth.ui.body.setAttribute ( 'on' + event, attribute ); + if ( !idrinth.core.multibind.events[event] ) { + idrinth.ui.body.addEventListener ( event, function ( e ) { + e = e || window.event; + idrinth.core.multibind.triggered ( e.target, e.type ); + } ); } bind ( event, selector, method ); }, @@ -130,9 +138,9 @@ idrinth.core = { } for (var pos = 0; pos < idrinth.core.multibind.events[event][selector].length; pos++) { try { - idrinth.core.multibind.events[event][selector][pos].bind ( el, event ); + idrinth.core.multibind.events[event][selector][pos] ( el, event ); } catch ( exception ) { - idrinth.core.log ( exception.getMessage () ); + idrinth.core.log ( exception.message ? exception.message : exception.getMessage () ); } } }; diff --git a/src/mods/land.js b/src/mods/land.js index ba5217b..b84dcc5 100644 --- a/src/mods/land.js +++ b/src/mods/land.js @@ -6,10 +6,11 @@ idrinth.land = { return ( 10 + idrinth.settings.land[building] ) * idrinth.land.data[building].base; }; var results = { }; - var applyResult = function ( res, factor, nextPrice ) { - idrinth.settings.land.gold = idrinth.settings.land.gold - nextPrice () * factor / 10; + var applyResult = function ( results, res, factor, nextPrice ) { + idrinth.settings.land.gold = idrinth.settings.land.gold - nextPrice ( res.key ) * factor / 10; results[res.key] = ( results[res.key] === undefined ? 0 : results[res.key] ) + factor; idrinth.settings.land[res.key] = idrinth.settings.land[res.key] + factor; + return results; }; var processBuildings = function ( checkElementFunc, factor, nextPrice ) { var check = function ( checkElementFunc, building, factor, res, nextPrice ) { @@ -39,7 +40,7 @@ idrinth.land = { if ( res.key === null ) { return results; } - applyResult ( res, factor, nextPrice ); + results = applyResult ( results, res, factor, nextPrice ); } idrinth.settings.save (); return results; @@ -59,18 +60,22 @@ idrinth.land = { }; var putResults = function ( results ) { for (var key in results) { - document.getElementById ( 'idrinth-land-' + key ).value = idrinth.settings.land[key]; - document.getElementById ( 'idrinth-land-' + key ).parentNode.nextSibling.innerHTML = '+' + results[key]; + if ( results.hasOwnProperty ( key ) ) { + document.getElementById ( 'idrinth-land-' + key ).value = idrinth.settings.land[key]; + document.getElementById ( 'idrinth-land-' + key ).parentNode.nextSibling.innerHTML = '+' + results[key]; + } } document.getElementById ( 'idrinth-land-gold' ).value = idrinth.settings.land.gold; idrinth.settings.save (); }; for (var key in idrinth.settings.land) { - idrinth.settings.change ( 'land-' + key, parseInt ( document.getElementById ( 'idrinth-land-' + key ).value, 10 ) ); + if ( idrinth.settings.land.hasOwnProperty ( key ) ) { + idrinth.settings.change ( 'land#' + key, parseInt ( document.getElementById ( 'idrinth-land-' + key ).value, 10 ) ); + } } var results = baseCalculator ( getRequirements () ); if ( Object.keys ( results ).length === 0 ) { - idrinth.core.alert ( idrinth.text.get ( "land.lackgold" ) ); + idrinth.core.alert ( idrinth.text.get ( "land.lackGold" ) ); } putResults ( results ); }, diff --git a/src/mods/raids.js b/src/mods/raids.js index cf0fb2c..40d99c4 100644 --- a/src/mods/raids.js +++ b/src/mods/raids.js @@ -250,11 +250,26 @@ idrinth.raids = { var postLink = function ( key ) { 'use strict'; if ( !document.getElementById ( 'idrinth-raid-link-' + key ) ) { - var span = document.createElement ( 'span' ); - span.id = 'idrinth-raid-link-' + key; - span.setAttribute ( 'data-clipboard-text', idrinth.raids.join.getServerLink ( key ) ); - span.appendChild ( document.createTextNode ( idrinth.raids.list[key].name + '\'s ' + idrinth.raids.list[key].raid ) ); - document.getElementById ( 'idrinth-raid-link-list' ).appendChild ( span ); + document.getElementById ( 'idrinth-raid-link-list' ).appendChild ( + idrinth.ui.buildElement ( + { + children: [ + { + type: 'span', + css: 'clipboard-copy', + id: 'idrinth-raid-link-' + key, + attributes: [ + { + name: 'data-clipboard-text', + value: idrinth.raids.join.getServerLink ( key ) + } + ], + content: idrinth.raids.list[key].name + '\'s ' + idrinth.raids.list[key].raid + } + ] + } + ) + ); } }; var options = [ postLink ]; diff --git a/src/mods/settings.js b/src/mods/settings.js index f87f30c..ad3ee84 100644 --- a/src/mods/settings.js +++ b/src/mods/settings.js @@ -1,103 +1,126 @@ -idrinth.settings = { - raids: false, - favs: '', - factor: true, - moveLeft: false, - minimalist: false, - chatHiddenOnStart: true, - names: true, - timeout: 5000, - loadtime: 5000, - windows: 3, - warBottom: false, - landMax: true, - chatting: true, - chatuser: '', - newgroundLoad: 30, - chatpass: '', - isWorldServer: false, - alarmTime: '8:0', - alarmActive: false, - bannedRaids: { }, - notification: { - mention: true, - message: true, - raid: true - }, - land: { - cornfield: 0, - stable: 0, - barn: 0, - store: 0, - pub: 0, - inn: 0, - tower: 0, - fort: 0, - castle: 0, - gold: 0 - }, - save: function ( ) { - 'use strict'; - var store = function ( prefix, list, store ) { - for (var key in list) { - if ( list.hasOwnProperty ( key ) && typeof list[key] !== 'object' && typeof list[key] !== 'function' ) { - window.localStorage.setItem ( prefix + key, list[key] ); - } else if ( list.hasOwnProperty ( key ) && typeof list[key] === 'object' ) { - store ( prefix + key + '-', list[key], store ); - } - } - }; - store ( 'idrinth-dotd-', idrinth.settings, store ); - }, - change: function ( field, value ) { - 'use strict'; - var setValue = function ( parent, field, value ) { - if ( idrinth.core.fieldIsSetting ( parent, field ) ) { - parent[field] = value; - idrinth.settings.save ( ); - return true; - } - return false; - }; - if ( !field ) { - return; - } - if ( setValue ( idrinth.settings, field, value ) ) { - return; - } - field = field.split ( '#' ); - if ( !idrinth.settings[field[0]] || !field[1] ) { - return; - } - if ( setValue ( idrinth.settings[field[0]], field[1], value ) ) { - return; - } - }, - start: function ( ) { - 'use strict'; - if ( window.localStorage ) { - var itemHandler = function ( prefix, key, item ) { - if ( typeof item !== 'function' ) { - var tmp = window.localStorage.getItem ( 'idrinth-dotd-' + prefix + key ); - if ( tmp ) { - if ( tmp === 'false' ) { - tmp = false; - } else if ( tmp === 'true' ) { - tmp = true; - } - item = tmp; - } - } - return item; - }; - for (var key in idrinth.settings) { - if ( key !== 'land' ) { - idrinth.settings[key] = itemHandler ( '', key, idrinth.settings[key] ); - } - } - for (var building in idrinth.settings.land) { - idrinth.settings.land[building] = itemHandler ( 'land-', building, idrinth.settings.land[building] ); - } - } - } +idrinth.settings = { + raids: false, + favs: '', + factor: true, + moveLeft: false, + minimalist: false, + chatHiddenOnStart: true, + names: true, + timeout: 5000, + loadtime: 5000, + windows: 3, + warBottom: false, + landMax: true, + chatting: true, + chatuser: '', + newgroundLoad: 30, + chatpass: '', + isWorldServer: false, + alarmTime: '8:0', + alarmActive: false, + bannedRaids: { }, + notification: { + mention: true, + message: true, + raid: true + }, + land: { + cornfield: 0, + stable: 0, + barn: 0, + store: 0, + pub: 0, + inn: 0, + tower: 0, + fort: 0, + castle: 0, + gold: 0 + }, + save: function ( ) { + 'use strict'; + var store = function ( prefix, list, store ) { + for (var key in list) { + if ( list.hasOwnProperty ( key ) && typeof list[key] !== 'object' && typeof list[key] !== 'function' ) { + window.localStorage.setItem ( prefix + key, list[key] ); + } else if ( list.hasOwnProperty ( key ) && typeof list[key] === 'object' ) { + store ( prefix + key + '-', list[key], store ); + } + } + }; + store ( 'idrinth-dotd-', idrinth.settings, store ); + }, + get: function ( field ) { + 'use strict'; + var getValue = function ( parent, field ) { + if ( idrinth.core.fieldIsSetting ( parent, field ) ) { + return parent[field]; + } + return null; + }; + if ( !field ) { + return; + } + var value = getValue ( idrinth.settings, field ); + if ( value !== null && typeof value !== 'object' ) { + return value; + } + field = field.split ( '#' ); + return getValue ( idrinth.settings[field[0]], field[1] ); + }, + change: function ( field, value ) { + 'use strict'; + var setValue = function ( parent, field, value ) { + if ( idrinth.core.fieldIsSetting ( parent, field ) ) { + parent[field] = value; + idrinth.settings.save ( ); + return true; + } + return false; + }; + if ( !field ) { + return; + } + if ( setValue ( idrinth.settings, field, value ) ) { + return; + } + field = field.split ( '#' ); + if ( !idrinth.settings[field[0]] || !field[1] ) { + return; + } + if ( setValue ( idrinth.settings[field[0]], field[1], value ) ) { + return; + } + }, + start: function ( ) { + 'use strict'; + if ( window.localStorage ) { + var objectIterator = function ( object, prefix, objectIterator ) { + var itemHandler = function ( prefix, key, item ) { + if ( typeof item !== 'function' ) { + var tmp = window.localStorage.getItem ( 'idrinth-dotd-' + prefix + key ); + if ( tmp ) { + if ( tmp === 'false' ) { + tmp = false; + } else if ( tmp === 'true' ) { + tmp = true; + } + item = tmp; + } + } + return item; + }; + for (var key in object) { + if ( object.hasOwnProperty ( key ) ) { + if ( typeof object[key] !== 'object' ) { + object[key] = itemHandler ( prefix, key, object[key] ); + } else { + object[key] = objectIterator ( object[key], prefix + key + '-', itemHandler, objectIterator ); + } + } + } + return object; + }; + objectIterator ( idrinth.settings, '', objectIterator ); + } + } }; \ No newline at end of file diff --git a/src/mods/tier.js b/src/mods/tier.js index b887e25..243c04c 100644 --- a/src/mods/tier.js +++ b/src/mods/tier.js @@ -220,15 +220,15 @@ idrinth.tier = { }, { type: 'th', - content: idrinth.text.get ( "tier.diff.normal" ) + content: idrinth.text.get ( "tier.diff.hard" ) }, { type: 'th', - content: idrinth.text.get ( "tier.diff.normal" ) + content: idrinth.text.get ( "tier.diff.legend" ) }, { type: 'th', - content: idrinth.text.get ( "tier.diff.normal" ) + content: idrinth.text.get ( "tier.diff.night" ) } ] } diff --git a/src/mods/ui.js b/src/mods/ui.js index 2c0325f..6173217 100644 --- a/src/mods/ui.js +++ b/src/mods/ui.js @@ -143,29 +143,11 @@ idrinth.ui = { } return list.indexOf ( value ) > -1; }; - var get = function ( field ) { - 'use strict'; - var getValue = function ( parent, field ) { - if ( idrinth.core.fieldIsSetting ( parent, field ) ) { - return parent[field]; - } - return null; - }; - if ( !field ) { - return; - } - var value = getValue ( idrinth.settings, field ); - if ( value !== null ) { - return value; - } - field = field.split ( '#' ); - return getValue ( idrinth.settings[field[0]], field[1] ); - }; var input = [ { name: 'type', value: config.type } ]; - if ( get ( config.name ) && config.type === 'checkbox' ) { + if ( idrinth.settings.get ( config.name ) && config.type === 'checkbox' ) { input.push ( { name: 'checked', value: 'checked' @@ -174,7 +156,7 @@ idrinth.ui = { if ( config.type !== 'checkbox' ) { input.push ( { name: 'value', - value: get ( config.name ) + value: idrinth.settings.get ( config.name ) } ); input.push ( { name: 'onchange', @@ -762,7 +744,7 @@ idrinth.ui = { }; var buildRaidJoinList = function () { return [ { - content: idrinth.text.get ( "ui.setting.clickCopy" ), + content: idrinth.text.get ( "ui.clickCopy" ), type: 'strong' }, { id: 'idrinth-raid-link-list' diff --git a/src/stable.js b/src/stable.js index 07548fe..8d55b6a 100644 --- a/src/stable.js +++ b/src/stable.js @@ -138,17 +138,10 @@ var idrinth = { } startModules (); window.setTimeout ( function () { - var clipboard = new Clipboard ( '#idrinth-raid-link-list span' ); - clipboard.on ( 'success', function ( e ) { - e = e || window.event; - e.trigger.parentNode.removeChild ( e.trigger ); - } ); - }, 1000 ); - window.setTimeout ( function () { - var clipboard = new Clipboard ( '.clipboard-copy' ); - clipboard.on ( 'success', function ( e ) { - e = e || window.event; - e.trigger.parentNode.parentNode.removeChild ( e.trigger.parentNode ); + idrinth.core.multibind.add ( 'click', '.clipboard-copy', function ( element, event ) { + idrinth.core.copyToClipboard.element ( element ); + element.parentNode.parentNode.removeChild ( element.parentNode ); + idrinth.core.log ( event + ' fired on ' + element ); } ); }, 1000 ); delete idrinth['start'];