Add link on feed items
This commit is contained in:
112
script/spot.js
112
script/spot.js
@@ -6,72 +6,72 @@ function Spot(asGlobals)
|
||||
this.consts.title = 'Spotty';
|
||||
this.consts.default_page = 'project';
|
||||
this.consts.timezone = Intl.DateTimeFormat().resolvedOptions().timeZone || this.consts.default_timezone;
|
||||
|
||||
|
||||
/* Initialization */
|
||||
|
||||
|
||||
this.init = function()
|
||||
{
|
||||
//Variables & constants from php
|
||||
self.vars('tmp', 'object');
|
||||
self.vars('page', 'string');
|
||||
self.updateVars(asGlobals.vars);
|
||||
|
||||
|
||||
//page elem
|
||||
self.elem = {};
|
||||
self.elem.container = $('#container');
|
||||
self.elem.main = $('#main');
|
||||
|
||||
|
||||
self.resetTmpFunctions();
|
||||
|
||||
|
||||
//On Key down
|
||||
$('html').on('keydown', function(oEvent){self.onKeydown(oEvent);});
|
||||
|
||||
|
||||
//on window resize
|
||||
$(window).on('resize', function(){self.onResize();});
|
||||
|
||||
|
||||
//Setup menu
|
||||
//self.initMenu();
|
||||
|
||||
|
||||
//Hash management
|
||||
$(window)
|
||||
.bind('hashchange', self.onHashChange)
|
||||
.trigger('hashchange');
|
||||
};
|
||||
|
||||
|
||||
this.updateVars = function(asVars)
|
||||
{
|
||||
$.each(asVars, function(sKey, oValue){self.vars(sKey, oValue)});
|
||||
};
|
||||
|
||||
|
||||
/* Variable Management */
|
||||
|
||||
|
||||
this.vars = function(oVarName, oValue)
|
||||
{
|
||||
var asVarName = (typeof oVarName == 'object')?oVarName:[oVarName];
|
||||
|
||||
|
||||
//Set, name & type / default value (init)
|
||||
if(typeof oValue !== 'undefined') setElem(self.vars, copyArray(asVarName), oValue);
|
||||
|
||||
//Get, only name parameter
|
||||
return getElem(self.vars, asVarName);
|
||||
};
|
||||
|
||||
|
||||
this.tmp = function(sVarName, oValue)
|
||||
{
|
||||
var asVarName = (typeof sVarName == 'object')?sVarName:[sVarName];
|
||||
asVarName.unshift('tmp');
|
||||
return self.vars(asVarName, oValue);
|
||||
};
|
||||
|
||||
|
||||
/* Interface with server */
|
||||
|
||||
|
||||
this.get = function(sAction, fOnSuccess, oVars, fOnError, fonProgress)
|
||||
{
|
||||
if(!oVars) oVars = {};
|
||||
fOnError = fOnError || function(sError) {console.log(sError);};
|
||||
fonProgress = fonProgress || function(sState){};
|
||||
fonProgress('start');
|
||||
|
||||
|
||||
oVars['a'] = sAction;
|
||||
oVars['t'] = self.consts.timezone;
|
||||
return $.ajax(
|
||||
@@ -84,7 +84,7 @@ function Spot(asGlobals)
|
||||
{
|
||||
fonProgress('done');
|
||||
if(oData.desc.substr(0, self.consts.lang_prefix.length)==self.consts.lang_prefix) oData.desc = self.lang(oData.desc.substr(5));
|
||||
|
||||
|
||||
if(oData.result==self.consts.error) fOnError(oData.desc);
|
||||
else fOnSuccess(oData.data, oData.desc);
|
||||
})
|
||||
@@ -94,31 +94,31 @@ function Spot(asGlobals)
|
||||
fOnError(textStatus+' '+errorThrown);
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
this.lang = function(sKey, asParams) {
|
||||
var sParamType = $.type(asParams);
|
||||
if(sParamType == 'undefined') asParams = [];
|
||||
else if($.type(asParams) != 'array') asParams = [asParams];
|
||||
var sLang = '';
|
||||
|
||||
|
||||
if(sKey in self.consts.lang) {
|
||||
sLang = self.consts.lang[sKey];
|
||||
for(i in asParams) sLang = sLang.replace('$'+i, asParams[i]);
|
||||
}
|
||||
else console.log('missing translation: '+sKey);
|
||||
|
||||
|
||||
return sLang;
|
||||
};
|
||||
|
||||
|
||||
/* Page Switch - Trigger & Event catching */
|
||||
|
||||
|
||||
this.onHashChange = function()
|
||||
{
|
||||
var asHash = self.getHash();
|
||||
if(asHash.hash !='' && asHash.page != '') self.switchPage(asHash); //page switching
|
||||
else if(self.vars('page')=='') self.setHash(self.consts.default_page); //first page
|
||||
};
|
||||
|
||||
|
||||
this.getHash = function()
|
||||
{
|
||||
var sHash = self.hash();
|
||||
@@ -126,7 +126,7 @@ function Spot(asGlobals)
|
||||
var sPage = asHash.shift() || '';
|
||||
return {hash:sHash, page:sPage, items:asHash};
|
||||
};
|
||||
|
||||
|
||||
this.setHash = function(sPage, asItems, bReboot)
|
||||
{
|
||||
bReboot = bReboot || false;
|
||||
@@ -139,18 +139,18 @@ function Spot(asGlobals)
|
||||
self.hash(sPage+sItems, bReboot);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.hash = function(hash, bReboot)
|
||||
{
|
||||
bReboot = bReboot || false;
|
||||
if(!hash) return window.location.hash.slice(1);
|
||||
else window.location.hash = '#'+hash;
|
||||
|
||||
|
||||
if(bReboot) location.reload();
|
||||
};
|
||||
|
||||
|
||||
/* Page Switch - DOM Replacement */
|
||||
|
||||
|
||||
this.getActionLink = function(sAction, oVars)
|
||||
{
|
||||
if(!oVars) oVars = {};
|
||||
@@ -161,7 +161,7 @@ function Spot(asGlobals)
|
||||
}
|
||||
return self.consts.process_page+'?a='+sAction+sVars;
|
||||
};
|
||||
|
||||
|
||||
this.resetTmpFunctions = function()
|
||||
{
|
||||
self.pageInit = function(asHash){console.log('no init for the page: '+asHash.page)};
|
||||
@@ -171,7 +171,7 @@ function Spot(asGlobals)
|
||||
self.onFeedback = function(sType, sMsg){};
|
||||
self.onKeydown = function(oEvent){};
|
||||
};
|
||||
|
||||
|
||||
this.switchPage = function(asHash)
|
||||
{
|
||||
var sPageName = asHash.page;
|
||||
@@ -180,17 +180,17 @@ function Spot(asGlobals)
|
||||
{
|
||||
//Delete tmp variables
|
||||
self.vars('tmp', {});
|
||||
|
||||
|
||||
//disable tmp functions
|
||||
self.resetTmpFunctions();
|
||||
|
||||
|
||||
//Officially a new page
|
||||
var bFirstPage = self.vars('page')=='';
|
||||
self.vars('page', sPageName);
|
||||
|
||||
|
||||
//Update Page Title
|
||||
this.setPageTitle(sPageName+' '+(asHash.items[0] || ''));
|
||||
|
||||
|
||||
//Replacing DOM
|
||||
var $Dom = $(self.consts.pages[sPageName]);
|
||||
if(bFirstPage)
|
||||
@@ -203,11 +203,11 @@ function Spot(asGlobals)
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
this.setPageTitle = function(sTitle) {
|
||||
document.title = self.consts.title+' - '+sTitle;
|
||||
};
|
||||
|
||||
|
||||
this.splash = function($Dom, asHash, bFirstPage)
|
||||
{
|
||||
//Switch main content
|
||||
@@ -215,7 +215,7 @@ function Spot(asGlobals)
|
||||
|
||||
//Page Bootstrap
|
||||
self.pageInit(asHash, bFirstPage);
|
||||
|
||||
|
||||
//Show main
|
||||
var $FadeInElem = bFirstPage?self.elem.container:self.elem.main;
|
||||
$FadeInElem.hide().fadeTo('slow', 1);
|
||||
@@ -277,7 +277,7 @@ $.prototype.addButton = function(sIcon, sText, sName, fOnClick, sClass)
|
||||
.addIcon('fa-'+sIcon, (sText != ''))
|
||||
.append(sText)
|
||||
.click(fOnClick);
|
||||
|
||||
|
||||
return $(this).append($Btn);
|
||||
};
|
||||
|
||||
@@ -333,13 +333,13 @@ $.prototype.hoverSwap = function(sDefault, sHover)
|
||||
var $This = $(this),
|
||||
sHover = $This.data('hover');
|
||||
sDefault = $This.data('default');
|
||||
|
||||
|
||||
if(sDefault!='' && sHover != '') {
|
||||
$This.fadeOut('fast', function() {
|
||||
var $This = $(this);
|
||||
$This.text((sDefault==$This.text())?sHover:sDefault).fadeIn('fast');
|
||||
});
|
||||
}
|
||||
}
|
||||
})
|
||||
.text(sDefault);
|
||||
};
|
||||
@@ -358,3 +358,35 @@ $.prototype.onSwipe = function(fCallBack){
|
||||
fCallBack({x:iDeltaX, y:iDeltaY});
|
||||
});
|
||||
};
|
||||
|
||||
function copyTextToClipboard(text) {
|
||||
if(!navigator.clipboard) {
|
||||
var textArea = document.createElement('textarea');
|
||||
textArea.value = text;
|
||||
|
||||
// Avoid scrolling to bottom
|
||||
textArea.style.top = '0';
|
||||
textArea.style.left = '0';
|
||||
textArea.style.position = 'fixed';
|
||||
|
||||
document.body.appendChild(textArea);
|
||||
textArea.focus();
|
||||
textArea.select();
|
||||
|
||||
try {
|
||||
var successful = document.execCommand('copy');
|
||||
if(!successful) console.error('Fallback: Oops, unable to copy', text);
|
||||
} catch (err) {
|
||||
console.error('Fallback: Oops, unable to copy', err);
|
||||
}
|
||||
|
||||
document.body.removeChild(textArea);
|
||||
return;
|
||||
}
|
||||
navigator.clipboard.writeText(text).then(
|
||||
function() {},
|
||||
function(err) {
|
||||
console.error('Async: Could not copy text: ', err);
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user