Skip to content

Commit

Permalink
Add skewer-css-clear-all command (#42).
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeto committed Feb 13, 2014
1 parent 9c36e27 commit cd54357
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
8 changes: 7 additions & 1 deletion skewer-css.el
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,20 @@
(interactive)
(skewer-css (buffer-substring-no-properties (point-min) (point-max))))

(defun skewer-css-clear-all ()
"Remove *all* Skewer-added styles from the document."
(interactive)
(skewer-eval nil nil :type "cssClearAll"))

;; Minor mode definition

(defvar skewer-css-mode-map
(let ((map (make-sparse-keymap)))
(prog1 map
(define-key map (kbd "C-x C-e") 'skewer-css-eval-current-declaration)
(define-key map (kbd "C-M-x") 'skewer-css-eval-current-rule)
(define-key map (kbd "C-c C-k") 'skewer-css-eval-buffer)))
(define-key map (kbd "C-c C-k") 'skewer-css-eval-buffer)
(define-key map (kbd "C-c C-c") 'skewer-css-clear-all)))
"Keymap for skewer-css-mode.")

;;;###autoload
Expand Down
12 changes: 12 additions & 0 deletions skewer.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ skewer.fn.ping = function(request) {
skewer.fn.css = function(request) {
var style = document.createElement('style');
style.type = 'text/css';
style.className = 'skewer';
if (style.styleSheet) { // < IE9
style.styleSheet.cssText = request.eval;
} else {
Expand All @@ -177,6 +178,17 @@ skewer.fn.css = function(request) {
return {};
};

/**
* Remove all of Skewer's style tags from the document.
*/
skewer.fn.cssClearAll = function(request) {
var styles = document.body.querySelectorAll('style.skewer');
for (var i = 0; i < styles.length; i++) {
styles[i].parentNode.removeChild(styles[i]);
}
return {};
};

/**
* HTML evaluator, appends or replaces a selection with given HTML.
*/
Expand Down

0 comments on commit cd54357

Please sign in to comment.