Skip to content

Instantly share code, notes, and snippets.

@smithcommajoseph
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save smithcommajoseph/e7515e618cf31daa92e7 to your computer and use it in GitHub Desktop.

Select an option

Save smithcommajoseph/e7515e618cf31daa92e7 to your computer and use it in GitHub Desktop.
a hack 'n slash svg solution
var $el = $('.'+element.attr('class')),
anchors = $el.find('.navbar-right');
// this is a symptom of the SVG api combined w/ bootstrap's plugin,
// recommending swapping bootstrap w/ a custom directive and/or using an ng-click
// on the affected elements
anchors.on('click', function(e) {
var target = $(e.target),
actualTarget;
if (typeof target[0].correspondingUseElement === 'undefined') { return; }
e.preventDefault();
actualTarget = $(target[0].correspondingUseElement).parents('a');
// this is targeting the dropdown 'gear' icon nav
if (actualTarget.parents('.open').length === 0) {
setTimeout(function() {actualTarget.trigger('click');}, 0);
}
});
'use strict';
var fs = require('fs'),
xml2js = require('xml2js'),
parser = new xml2js.Parser(),
builder = new xml2js.Builder(),
filesArr = [],
svgBuffer = [],
SVG_SRC = '',
SVG_DEST = '';
filesArr = fs.readdirSync(SVG_SRC);
function getSvgId(fileName) {
return fileName.replace('.svg', '').replace(/\_/g, '-');
}
function getWrappedStr() {
return '<svg height="0" width="0" style="position:absolute;margin-left: -100%;">\r\n' + svgBuffer.join('') + '\r\n</svg>';
}
filesArr.forEach(function(file) {
var fileLoc,
contents,
svg,
wrapG;
fileLoc = SVG_SRC + '/' + file;
contents = fs.readFileSync(fileLoc, {encoding: 'utf8'});
parser.parseString(contents, function(err, res) {
svg = res.svg;
delete svg.$;
if (!svg.g) {
wrapG = {g: [svg]};
svg = wrapG;
}
svg.g = svg.g[0];
svg.g.$ = {id: getSvgId(file)};
svgBuffer.push(
builder
.buildObject(svg)
.replace('<?xml version="1.0" encoding="UTF-8" standalone="yes"?>', '') + '\r\n'
);
});
fs.writeFileSync(SVG_DEST, getWrappedStr());
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment