Permalink
Browse files

Basic Firefox support

  • Loading branch information...
1 parent 5e90bc1 commit 74035003e65947f6a7cb30dcdbef70c291f80163 @jxnblk committed Sep 16, 2014
Showing with 4 additions and 23 deletions.
  1. +1 −1 dist/fitter-happier-text.js
  2. +0 −18 gulpfile.js
  3. +0 −1 index.html
  4. +2 −2 index.js
  5. +1 −1 package.json
@@ -1 +1 @@
-!function(t){if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.fitterHappierText=t()}}(function(){return function t(e,r,n){function i(f,u){if(!r[f]){if(!e[f]){var s="function"==typeof require&&require;if(!u&&s)return s(f,!0);if(o)return o(f,!0);throw new Error("Cannot find module '"+f+"'")}var a=r[f]={exports:{}};e[f][0].call(a.exports,function(t){var r=e[f][1][t];return i(r?r:t)},a,a.exports,t,e,r,n)}return r[f].exports}for(var o="function"==typeof require&&require,f=0;f<n.length;f++)i(n[f]);return i}({1:[function(t,e){e.exports=function(t,e){for(var e=e||{},r=e.baseline||16,n=e.paddingY||0,i=e.doc||document,o=0;o<t.length;o++){var f,u,s=t[o].textContent,a=i.createElementNS("http://www.w3.org/2000/svg","svg"),l=i.createElementNS("http://www.w3.org/2000/svg","text");l.textContent=s,l.setAttribute("y",r),l.setAttribute("font-family","inherit"),l.setAttribute("font-size","1rem"),l.setAttribute("font-weight","inherit");for(var d=0;d<t[o].attributes.length;d++)a.setAttribute(t[o].attributes[d].name,t[o].attributes[d].value);a.setAttribute("width","100%"),a.setAttribute("style","max-height:100%"),a.setAttribute("fill","currentcolor"),a.appendChild(l),t[o].parentNode.replaceChild(a,t[o]),f=l.offsetWidth,u=l.offsetHeight,a.setAttribute("viewBox","0 0 "+f+" "+(u+n))}}},{}]},{},[1])(1)});
+!function(t){if("object"==typeof exports)module.exports=t();else if("function"==typeof define&&define.amd)define(t);else{var e;"undefined"!=typeof window?e=window:"undefined"!=typeof global?e=global:"undefined"!=typeof self&&(e=self),e.fitterHappierText=t()}}(function(){return function t(e,r,n){function i(f,u){if(!r[f]){if(!e[f]){var s="function"==typeof require&&require;if(!u&&s)return s(f,!0);if(o)return o(f,!0);throw new Error("Cannot find module '"+f+"'")}var a=r[f]={exports:{}};e[f][0].call(a.exports,function(t){var r=e[f][1][t];return i(r?r:t)},a,a.exports,t,e,r,n)}return r[f].exports}for(var o="function"==typeof require&&require,f=0;f<n.length;f++)i(n[f]);return i}({1:[function(t,e){e.exports=function(t,e){for(var e=e||{},r=e.baseline||16,n=e.paddingY||0,i=e.doc||document,o=0;o<t.length;o++){var f,u,s=t[o].textContent,a=i.createElementNS("http://www.w3.org/2000/svg","svg"),l=i.createElementNS("http://www.w3.org/2000/svg","text");l.textContent=s,l.setAttribute("y",r),l.setAttribute("font-family","inherit"),l.setAttribute("font-size","1rem"),l.setAttribute("font-weight","inherit");for(var d=0;d<t[o].attributes.length;d++)a.setAttribute(t[o].attributes[d].name,t[o].attributes[d].value);a.setAttribute("width","100%"),a.setAttribute("style","max-height:100%"),a.setAttribute("fill","currentcolor"),a.appendChild(l),t[o].parentNode.replaceChild(a,t[o]),f=l.offsetWidth||l.getComputedTextLength(),u=l.offsetHeight||24,a.setAttribute("viewBox","0 0 "+f+" "+(u+n))}}},{}]},{},[1])(1)});
View
@@ -4,9 +4,6 @@ var rename = require('gulp-rename');
var uglify = require('gulp-uglify');
var browserify = require('gulp-browserify');
-var cheerio = require('gulp-cheerio');
-
-
gulp.task('compile', function() {
gulp.src('index.js')
.pipe(browserify({ standalone: 'fitterHappierText' }))
@@ -20,18 +17,3 @@ gulp.task('default', ['compile'], function() {
});
-
-// Testing
-var dom = require('gulp-dom');
-var fht = require('./dist/fitter-happier-text.js');
-gulp.task('fitter', function() {
- gulp.src('./demo.html')
- .pipe(dom(function() {
- var nodes = this.querySelectorAll('.js-fht');
- console.log(nodes[0]._ownerDocument._documentElement);
- fht(nodes, { doc: this });
- }))
- .pipe(rename('output.html'))
- .pipe(gulp.dest('.'));
-});
-
View
@@ -15,7 +15,6 @@
margin: 0 auto;
max-width: 76rem;
color: rgba(255,255,255,.8);
- background-color: tomato;
background-color: #f40;
background-image: linear-gradient(#f40, #f37);
}
View
@@ -31,8 +31,8 @@ module.exports = function(elements, options) {
svg.appendChild(text);
elements[i].parentNode.replaceChild(svg, elements[i]);
- width = text.offsetWidth;
- height = text.offsetHeight;
+ width = text.offsetWidth || text.getComputedTextLength();
+ height = text.offsetHeight || 24;
svg.setAttribute('viewBox', '0 0 ' + width + ' ' + (height + paddingY));
View
@@ -1,6 +1,6 @@
{
"name": "fitter-happier-text",
- "version": "0.0.2",
+ "version": "0.0.3",
"description": "Fit text to the width of its container",
"main": "index.js",
"homepage": "http://jxnblk.github.com/fitter-happier-text",

0 comments on commit 7403500

Please sign in to comment.