Welcome, guest | Sign In | My Account | Store | Cart

Simple macro to add vendor prefixes to a CSS declaration under the cursor. Isn't smart and doesn't know what needs a prefix and what doesn't, just adds all the prefixes.

JavaScript, 38 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(function () {

var koView = ko.views.manager.currentView.scimoz;
var currentPos = koView.currentPos;

try {
    // Group operations into a single undo
    koView.beginUndoAction();

	var prefixes = [ '', '-o-', '-ms-', '-moz-', '-webkit-' ];

    var addPrefixes = function (line) {
		var build = '';
		for ( var i = 0, len = prefixes.length; i < len; i++ ) {
			ko.commands.doCommand('cmd_lineOrSelectionDuplicate');
			ko.commands.doCommand('cmd_home');
			ko.commands.doCommand('cmd_selectEnd');
			build = prefixes[i] + line;
			koView.replaceSel( build );
		}
    };

	ko.commands.doCommand('cmd_home');
	ko.commands.doCommand('cmd_selectEnd');

    if ( !!koView.selText ) {
       addPrefixes( koView.selText );
    }

}
catch (e) {
    alert(e);
}
finally {
    // Must end undo action or may corrupt edit buffer
    koView.endUndoAction();
}
})();
Created by Keegan Brown on Fri, 25 May 2012 (MIT)
JavaScript recipes (69)
Keegan Brown's recipes (2)

Required Modules

  • (none specified)

Other Information and Tasks