Skip to content
This repository has been archived by the owner on Mar 29, 2021. It is now read-only.

Commit

Permalink
Merge pull request #190 from Idrinth/idrinth
Browse files Browse the repository at this point in the history
Idrinth
  • Loading branch information
w20k authored Oct 9, 2016
2 parents 3d58749 + da0d31a commit 39a89a5
Show file tree
Hide file tree
Showing 9 changed files with 219 additions and 936 deletions.
746 changes: 0 additions & 746 deletions src/libs/clipboard.js

This file was deleted.

27 changes: 15 additions & 12 deletions src/mods/chat.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ idrinth.chat = {
}
];
for (var chatId in idrinth.chat.chatRank) {
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
} );
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;
Expand All @@ -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',
Expand Down Expand Up @@ -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: [
Expand All @@ -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: [
Expand Down Expand Up @@ -900,7 +903,7 @@ idrinth.chat = {
],
attributes: [ {
name: 'style',
value: idrinth.ui.getPosition ( element )
value: idrinth.ui.getElementPositioning ( element, 0, 0 )
} ]
} ) );
},
Expand Down
66 changes: 37 additions & 29 deletions src/mods/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.' );
};
Expand All @@ -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 ) ) {
Expand Down Expand Up @@ -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 );
},
Expand All @@ -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 () );
}
}
};
Expand Down
19 changes: 12 additions & 7 deletions src/mods/land.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand Down Expand Up @@ -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;
Expand All @@ -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 );
},
Expand Down
25 changes: 20 additions & 5 deletions src/mods/raids.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
Expand Down
Loading

0 comments on commit 39a89a5

Please sign in to comment.