Overriding drawLineText method of CreateJS

I needed to superscript some specific characters in a dynamic text field in CreateJS , so I built a prototype function to do just that.

createjs.Text.prototype._drawTextLine = function (ctx, text, y) {
    // Chrome 17 will fail to draw the text if the last param is included but null, so we feed it a large value instead:
    if (this.outline) {
        ctx.strokeText(text, 0, y, this.maxWidth || 0xFFFF);
    } else {
        var x = 0;
        if (/(®|†)/.test(text)) {
            var textArr = text.split(/(®|†)/g);
           
            var pxInd = this.font.search(/px/);
            var fntSz = this.font.substring(pxInd - 2, pxInd);
            var fntFc = this.font.substring(pxInd + 2);
            var supSz = Math.round(fntSz * 0.5);
            var supFont = supSz + "px " + fntFc;
           
            var div = (this.textAlign == "center") ? 2 : 1;  // to fix placement with "center" aligned text
           
            for (var t = 0, l = textArr.length; t < l; t++) {
                if (/(®|†)/.test(textArr[t])) {
                    ctx.font = supFont;
                    ctx.fillText(textArr[t], x, y, this.maxWidth || 0xFFFF);
                } else {
                    ctx.font = this.font;
                    ctx.fillText(textArr[t], x, y, this.maxWidth || 0xFFFF);
                }
                x += ctx.measureText(textArr[t]).width / div;
            }
        } else {
            ctx.fillText(text, x, y, this.maxWidth || 0xFFFF);
        }
    }
};

 

Memory limit uploading media in wordpress

I was having issues figuring out why we were reaching a hard limit on upload size even after doing all of the normal fixes though wp-config, .htaccess and apache. We found out the issue was with the all-in-one-security plugin. The all-in-one plugin overrides the apache limit size on instantiation. line 332-333 of  wp-security-utility-htaccess.php

//limit file uploads to 10mb 
$rules .= 'LimitRequestBody 10240000' . PHP_EOL;

Add Google Analytics to multiple Vimeo videos

I was working on a page earlier this week that had a number of Vimeo videos embedded within a scroller. Each video needed to have a unique identifier submitted with the analytics event tracking. The event was to be submitted only when any video started being played. Here is the small chunk of code I used for this. Don’t forget to include the Froogaloop library to access the vimeo player’s events.

var iframes = $('iframe.vimeovideo'); 
    iframes.each(function(i, obj) { 
    $(obj).load(function() { 
     var txt = $(obj).next().text(); // text from an h1 element
     var player=$f(this);
     player.addEvent('ready', function() {
       player.addEvent('play', function(data) {
         _gaq.push(['_trackEvent', 'Video', 'Start', txt,, false]);
       });
     });
   });
});