ソースを参照

#2648 Update plugins: loadCSS

Alex Trofimov 6 年 前
親
コミット
e098ff5bac
1 ファイル変更、10 行追加、1 行削除
  1. 10 1
      plugins_public/loadCSS.js

+ 10 - 1
plugins_public/loadCSS.js

@@ -2,12 +2,13 @@
 (function(w){
 	"use strict";
 	/* exported loadCSS */
-	var loadCSS = function( href, before, media ){
+	var loadCSS = function( href, before, media, attributes ){
 		// Arguments explained:
 		// `href` [REQUIRED] is the URL for your CSS file.
 		// `before` [OPTIONAL] is the element the script should use as a reference for injecting our stylesheet <link> before
 		// By default, loadCSS attempts to inject the link after the last stylesheet or script in the DOM. However, you might desire a more specific location in your document.
 		// `media` [OPTIONAL] is the media type or query of the stylesheet. By default it will be 'all'
+		// `attributes` [OPTIONAL] is the Object of attribute name/attribute value pairs to set on the stylesheet's DOM Element.
 		var doc = w.document;
 		var ss = doc.createElement( "link" );
 		var ref;
@@ -20,6 +21,14 @@
 		}
 
 		var sheets = doc.styleSheets;
+		// Set any of the provided attributes to the stylesheet DOM Element.
+		if( attributes ){
+			for( var attributeName in attributes ){
+				if( attributes.hasOwnProperty( attributeName ) ){
+					ss.setAttribute( attributeName, attributes[attributeName] );
+				}
+			}
+		}
 		ss.rel = "stylesheet";
 		ss.href = href;
 		// temporarily set media to something inapplicable to ensure it'll fetch without blocking render