Skip to content

Commit

Permalink
Adds icons on the fly to minimize page load
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanbc committed Apr 21, 2017
1 parent ade08be commit 6732444
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .eslintrc.js
Expand Up @@ -73,6 +73,6 @@ module.exports = {
'require-yield': 'error',
'space-before-function-paren': ['error', { anonymous: 'always', named: 'never', asyncArrow: 'always' }],
'object-shorthand': ['error', 'always', { avoidExplicitReturnArrows: true }],
'no-console': ["error", { allow: ["warn", "error"] }]
'no-console': ["warn", { allow: ["warn", "error"] }]
}
};
35 changes: 34 additions & 1 deletion app/helpers/actions.js
@@ -1,5 +1,6 @@
const _ = require('lodash');
const $ = require('jquery');
const octicons = require("octicons");
const common = require('./common');

/**
Expand All @@ -21,10 +22,42 @@ module.exports = {
* @param {String} selector
*/
copy(selector) {
$(selector).find('.copy-action').on('click', function () {
let actionIcon = $(selector).find('.copy-action');

actionIcon.on('click', () => {
let element = $(this).parent().find('.output');

common.copyToClipboard(element[0]);
});

this.insertIcon(selector, 'copy', 'clippy');
},

/**
* Inserts an icon within the desired element
* @param {Object} selector
* @param {String} action
* @param {String} icon
*/
insertIcon(selector, action, icon) {
let actionIcon = $(selector).find(`.${action}-action`);

$(selector).on('mouseenter mouseleave', (ev) => {
let type = ev.type;

if (type === 'mouseenter') {
actionIcon.append(this.generateIcon(icon));
} else if (type === 'mouseleave') {
actionIcon.find('.icon').remove();
}
});
},

/**
* Outputs the correct markup for the oction
* @param {String} icon
*/
generateIcon(icon) {
return `<span class="icon">${octicons[icon].toSVG()}</span>`;
}
};
4 changes: 1 addition & 3 deletions app/routes/index.js
Expand Up @@ -3,7 +3,6 @@
*/
const router = require('express').Router();
const basic = require('../models/basic');
const octicons = require("octicons");

/* GET home page. */
router.get('/', function (req, res, next) {
Expand All @@ -14,8 +13,7 @@ router.get('/', function (req, res, next) {
layoutId : 'index',
data : basic.gatherData({
location
}),
octicons
})
});

}, next);
Expand Down
7 changes: 1 addition & 6 deletions app/templates/scaffolding/mixins.pug
Expand Up @@ -49,10 +49,5 @@ mixin list(id = '', output, enableCopy, ...listItems)
+output(item)
if enableCopy
span.action.copy-action.ml-10.tooltip.tooltip-right(data-tooltip="Copy")
+icon('clippy')
else
li=item

//- Mixin for generating an icon element
mixin icon(icon)
span.icon!=octicons[icon].toSVG()
li=item
10 changes: 6 additions & 4 deletions public/scripts/uptimey.min.js

Large diffs are not rendered by default.

0 comments on commit 6732444

Please sign in to comment.