diff options
author | Thiago Fernando <thiagofernando@outlook.com> | 2019-05-10 14:54:25 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-05-10 14:54:25 -0300 |
commit | ce0473480bab3fc621d4baecfff0f413e21b5e2c (patch) | |
tree | 06d724b4f80885bdd13137f7977d7a914cca0138 /client/lib/utils.js | |
parent | c43508cacbd64357409a3de114db9dab2ae59a9d (diff) | |
parent | 7ff4067e88ed59686c86d81447fa2ce550032034 (diff) | |
download | wekan-ce0473480bab3fc621d4baecfff0f413e21b5e2c.tar.gz wekan-ce0473480bab3fc621d4baecfff0f413e21b5e2c.tar.bz2 wekan-ce0473480bab3fc621d4baecfff0f413e21b5e2c.zip |
Merge pull request #1 from wekan/devel
ldap changes
Diffstat (limited to 'client/lib/utils.js')
-rw-r--r-- | client/lib/utils.js | 153 |
1 files changed, 149 insertions, 4 deletions
diff --git a/client/lib/utils.js b/client/lib/utils.js index 1f44c60d..e2339763 100644 --- a/client/lib/utils.js +++ b/client/lib/utils.js @@ -39,11 +39,11 @@ Utils = { if (!prevData && !nextData) { base = 0; increment = 1; - // If we drop the card in the first position + // If we drop the card in the first position } else if (!prevData) { base = nextData.sort - 1; increment = -1; - // If we drop the card in the last position + // If we drop the card in the last position } else if (!nextData) { base = prevData.sort + 1; increment = 1; @@ -71,11 +71,11 @@ Utils = { if (!prevCardDomElement && !nextCardDomElement) { base = 0; increment = 1; - // If we drop the card in the first position + // If we drop the card in the first position } else if (!prevCardDomElement) { base = Blaze.getData(nextCardDomElement).sort - 1; increment = -1; - // If we drop the card in the last position + // If we drop the card in the last position } else if (!nextCardDomElement) { base = Blaze.getData(prevCardDomElement).sort + 1; increment = 1; @@ -95,6 +95,151 @@ Utils = { increment, }; }, + + // Detect touch device + isTouchDevice() { + const isTouchable = (() => { + const prefixes = ' -webkit- -moz- -o- -ms- '.split(' '); + const mq = function(query) { + return window.matchMedia(query).matches; + }; + + if (('ontouchstart' in window) || window.DocumentTouch && document instanceof window.DocumentTouch) { + return true; + } + + // include the 'heartz' as a way to have a non matching MQ to help terminate the join + // https://git.io/vznFH + const query = ['(', prefixes.join('touch-enabled),('), 'heartz', ')'].join(''); + return mq(query); + })(); + Utils.isTouchDevice = () => isTouchable; + return isTouchable; + }, + + calculateTouchDistance(touchA, touchB) { + return Math.sqrt( + Math.pow(touchA.screenX - touchB.screenX, 2) + + Math.pow(touchA.screenY - touchB.screenY, 2) + ); + }, + + enableClickOnTouch(selector) { + let touchStart = null; + let lastTouch = null; + + $(document).on('touchstart', selector, function(e) { + touchStart = e.originalEvent.touches[0]; + }); + $(document).on('touchmove', selector, function(e) { + const touches = e.originalEvent.touches; + lastTouch = touches[touches.length - 1]; + }); + $(document).on('touchend', selector, function(e) { + if (touchStart && lastTouch && Utils.calculateTouchDistance(touchStart, lastTouch) <= 20) { + e.preventDefault(); + const clickEvent = document.createEvent('MouseEvents'); + clickEvent.initEvent('click', true, true); + e.target.dispatchEvent(clickEvent); + } + }); + }, + + manageCustomUI(){ + Meteor.call('getCustomUI', (err, data) => { + if (err && err.error[0] === 'var-not-exist'){ + Session.set('customUI', false); // siteId || address server not defined + } + if (!err){ + Utils.setCustomUI(data); + } + }); + }, + + setCustomUI(data){ + const currentBoard = Boards.findOne(Session.get('currentBoard')); + if (currentBoard) { + DocHead.setTitle(`${currentBoard.title } - ${ data.productName}`); + } else { + DocHead.setTitle(`${data.productName}`); + } + }, + + setMatomo(data){ + window._paq = window._paq || []; + window._paq.push(['setDoNotTrack', data.doNotTrack]); + if (data.withUserName){ + window._paq.push(['setUserId', Meteor.user().username]); + } + window._paq.push(['trackPageView']); + window._paq.push(['enableLinkTracking']); + + (function() { + window._paq.push(['setTrackerUrl', `${data.address}piwik.php`]); + window._paq.push(['setSiteId', data.siteId]); + + const script = document.createElement('script'); + Object.assign(script, { + id: 'scriptMatomo', + type: 'text/javascript', + async: 'true', + defer: 'true', + src: `${data.address}piwik.js`, + }); + + const s = document.getElementsByTagName('script')[0]; + s.parentNode.insertBefore(script, s); + })(); + + Session.set('matomo', true); + }, + + manageMatomo() { + const matomo = Session.get('matomo'); + if (matomo === undefined){ + Meteor.call('getMatomoConf', (err, data) => { + if (err && err.error[0] === 'var-not-exist'){ + Session.set('matomo', false); // siteId || address server not defined + } + if (!err){ + Utils.setMatomo(data); + } + }); + } else if (matomo) { + window._paq.push(['trackPageView']); + } + }, + + getTriggerActionDesc(event, tempInstance) { + const jqueryEl = tempInstance.$(event.currentTarget.parentNode); + const triggerEls = jqueryEl.find('.trigger-content').children(); + let finalString = ''; + for (let i = 0; i < triggerEls.length; i++) { + const element = tempInstance.$(triggerEls[i]); + if (element.hasClass('trigger-text')) { + finalString += element.text().toLowerCase(); + } else if (element.hasClass('user-details')) { + let username = element.find('input').val(); + if(username === undefined || username === ''){ + username = '*'; + } + finalString += `${element.find('.trigger-text').text().toLowerCase() } ${ username}`; + } else if (element.find('select').length > 0) { + finalString += element.find('select option:selected').text().toLowerCase(); + } else if (element.find('input').length > 0) { + let inputvalue = element.find('input').val(); + if(inputvalue === undefined || inputvalue === ''){ + inputvalue = '*'; + } + finalString += inputvalue; + } + // Add space + if (i !== length - 1) { + finalString += ' '; + } + } + return finalString; + }, }; // A simple tracker dependency that we invalidate every time the window is |