mirror of
https://github.com/wailsapp/wails.git
synced 2025-05-16 17:09:28 +08:00
fix: linting for hound
This commit is contained in:
parent
b0a075cdf2
commit
f6ff7d7b16
@ -15,66 +15,66 @@ window.backend = {};
|
|||||||
|
|
||||||
// Determines if the given identifier is valid Javascript
|
// Determines if the given identifier is valid Javascript
|
||||||
function isValidIdentifier(name) {
|
function isValidIdentifier(name) {
|
||||||
// Don't xss yourself :-)
|
// Don't xss yourself :-)
|
||||||
try {
|
try {
|
||||||
new Function('var ' + name);
|
new Function('var ' + name);
|
||||||
return true;
|
return true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// eslint-disable-next-line max-lines-per-function
|
// eslint-disable-next-line max-lines-per-function
|
||||||
export function NewBinding(bindingName) {
|
export function NewBinding(bindingName) {
|
||||||
|
|
||||||
// Get all the sections of the binding
|
// Get all the sections of the binding
|
||||||
var bindingSections = [].concat(bindingName.split('.').splice(1));
|
var bindingSections = [].concat(bindingName.split('.').splice(1));
|
||||||
var pathToBinding = window.backend;
|
var pathToBinding = window.backend;
|
||||||
|
|
||||||
// Check if we have a path (IE Struct)
|
// Check if we have a path (IE Struct)
|
||||||
if (bindingSections.length > 1) {
|
if (bindingSections.length > 1) {
|
||||||
// Iterate over binding sections, adding them to the window.backend object
|
// Iterate over binding sections, adding them to the window.backend object
|
||||||
for (let index = 0; index < bindingSections.length - 1; index += 1) {
|
for (let index = 0; index < bindingSections.length - 1; index += 1) {
|
||||||
const name = bindingSections[index];
|
const name = bindingSections[index];
|
||||||
// Is name a valid javascript identifier?
|
// Is name a valid javascript identifier?
|
||||||
if (!isValidIdentifier(name)) {
|
if (!isValidIdentifier(name)) {
|
||||||
return new Error(`${name} is not a valid javascript identifier.`);
|
return new Error(`${name} is not a valid javascript identifier.`);
|
||||||
}
|
}
|
||||||
pathToBinding[name] = {};
|
pathToBinding[name] = {};
|
||||||
pathToBinding = pathToBinding[name];
|
pathToBinding = pathToBinding[name];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the actual function/method call name
|
// Get the actual function/method call name
|
||||||
const name = bindingSections.pop();
|
const name = bindingSections.pop();
|
||||||
|
|
||||||
// Is name a valid javascript identifier?
|
// Is name a valid javascript identifier?
|
||||||
if (!isValidIdentifier(name)) {
|
if (!isValidIdentifier(name)) {
|
||||||
return new Error(`${name} is not a valid javascript identifier.`);
|
return new Error(`${name} is not a valid javascript identifier.`);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add binding call
|
// Add binding call
|
||||||
pathToBinding[name] = function () {
|
pathToBinding[name] = function () {
|
||||||
|
|
||||||
// No timeout by default
|
// No timeout by default
|
||||||
var timeout = 0;
|
var timeout = 0;
|
||||||
|
|
||||||
// Actual function
|
// Actual function
|
||||||
function dynamic() {
|
function dynamic() {
|
||||||
var args = [].slice.call(arguments);
|
var args = [].slice.call(arguments);
|
||||||
return Call(bindingName, args, timeout);
|
return Call(bindingName, args, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow setting timeout to function
|
// Allow setting timeout to function
|
||||||
dynamic.setTimeout = function (newTimeout) {
|
dynamic.setTimeout = function (newTimeout) {
|
||||||
timeout = newTimeout;
|
timeout = newTimeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Allow getting timeout to function
|
// Allow getting timeout to function
|
||||||
dynamic.getTimeout = function () {
|
dynamic.getTimeout = function () {
|
||||||
return timeout;
|
return timeout;
|
||||||
};
|
};
|
||||||
|
|
||||||
return dynamic;
|
return dynamic;
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
@ -12,9 +12,9 @@ The lightweight framework for web-like apps
|
|||||||
import { SystemCall } from './calls';
|
import { SystemCall } from './calls';
|
||||||
|
|
||||||
export function OpenURL(url) {
|
export function OpenURL(url) {
|
||||||
return SystemCall('Browser.OpenURL', url);
|
return SystemCall('Browser.OpenURL', url);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function OpenFile(filename) {
|
export function OpenFile(filename) {
|
||||||
return SystemCall('Browser.OpenFile', filename);
|
return SystemCall('Browser.OpenFile', filename);
|
||||||
}
|
}
|
||||||
|
@ -16,21 +16,21 @@ var callbacks = {};
|
|||||||
|
|
||||||
// AwesomeRandom
|
// AwesomeRandom
|
||||||
function cryptoRandom() {
|
function cryptoRandom() {
|
||||||
var array = new Uint32Array(1);
|
var array = new Uint32Array(1);
|
||||||
return window.crypto.getRandomValues(array)[0];
|
return window.crypto.getRandomValues(array)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
// LOLRandom
|
// LOLRandom
|
||||||
function basicRandom() {
|
function basicRandom() {
|
||||||
return Math.random() * 9007199254740991;
|
return Math.random() * 9007199254740991;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Pick one based on browser capability
|
// Pick one based on browser capability
|
||||||
var randomFunc;
|
var randomFunc;
|
||||||
if (window.crypto) {
|
if (window.crypto) {
|
||||||
randomFunc = cryptoRandom;
|
randomFunc = cryptoRandom;
|
||||||
} else {
|
} else {
|
||||||
randomFunc = basicRandom;
|
randomFunc = basicRandom;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -43,47 +43,47 @@ if (window.crypto) {
|
|||||||
|
|
||||||
export function Call(bindingName, data, timeout) {
|
export function Call(bindingName, data, timeout) {
|
||||||
|
|
||||||
// Timeout infinite by default
|
// Timeout infinite by default
|
||||||
if (timeout == null || timeout == undefined) {
|
if (timeout == null || timeout == undefined) {
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a promise
|
// Create a promise
|
||||||
return new Promise(function (resolve, reject) {
|
return new Promise(function (resolve, reject) {
|
||||||
|
|
||||||
// Create a unique callbackID
|
// Create a unique callbackID
|
||||||
var callbackID;
|
var callbackID;
|
||||||
do {
|
do {
|
||||||
callbackID = bindingName + '-' + randomFunc();
|
callbackID = bindingName + '-' + randomFunc();
|
||||||
} while (callbacks[callbackID]);
|
} while (callbacks[callbackID]);
|
||||||
|
|
||||||
// Set timeout
|
// Set timeout
|
||||||
if (timeout > 0) {
|
if (timeout > 0) {
|
||||||
var timeoutHandle = setTimeout(function () {
|
var timeoutHandle = setTimeout(function () {
|
||||||
reject(Error('Call to ' + bindingName + ' timed out. Request ID: ' + callbackID));
|
reject(Error('Call to ' + bindingName + ' timed out. Request ID: ' + callbackID));
|
||||||
}, timeout);
|
}, timeout);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Store callback
|
// Store callback
|
||||||
callbacks[callbackID] = {
|
callbacks[callbackID] = {
|
||||||
timeoutHandle: timeoutHandle,
|
timeoutHandle: timeoutHandle,
|
||||||
reject: reject,
|
reject: reject,
|
||||||
resolve: resolve
|
resolve: resolve
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const payload = {
|
const payload = {
|
||||||
bindingName: bindingName,
|
bindingName: bindingName,
|
||||||
data: JSON.stringify(data),
|
data: JSON.stringify(data),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Make the call
|
// Make the call
|
||||||
SendMessage('call', payload, callbackID)
|
SendMessage('call', payload, callbackID)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -91,37 +91,37 @@ export function Call(bindingName, data, timeout) {
|
|||||||
// binding invocation
|
// binding invocation
|
||||||
export function Callback(incomingMessage) {
|
export function Callback(incomingMessage) {
|
||||||
|
|
||||||
// Decode the message - Credit: https://stackoverflow.com/a/13865680
|
// Decode the message - Credit: https://stackoverflow.com/a/13865680
|
||||||
incomingMessage = decodeURIComponent(incomingMessage.replace(/\s+/g, '').replace(/[0-9a-f]{2}/g, '%$&'));
|
incomingMessage = decodeURIComponent(incomingMessage.replace(/\s+/g, '').replace(/[0-9a-f]{2}/g, '%$&'));
|
||||||
|
|
||||||
// Parse the message
|
// Parse the message
|
||||||
var message;
|
var message;
|
||||||
try {
|
try {
|
||||||
message = JSON.parse(incomingMessage);
|
message = JSON.parse(incomingMessage);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
const error = `Invalid JSON passed to callback: ${e.message}. Message: ${incomingMessage}`;
|
const error = `Invalid JSON passed to callback: ${e.message}. Message: ${incomingMessage}`;
|
||||||
Debug(error);
|
Debug(error);
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
var callbackID = message.callbackid;
|
var callbackID = message.callbackid;
|
||||||
var callbackData = callbacks[callbackID];
|
var callbackData = callbacks[callbackID];
|
||||||
if (!callbackData) {
|
if (!callbackData) {
|
||||||
// eslint-disable-next-line
|
// eslint-disable-next-line
|
||||||
const error = `Callback '${callbackID}' not registed!!!`;
|
const error = `Callback '${callbackID}' not registed!!!`;
|
||||||
console.error(error);
|
console.error(error);
|
||||||
throw new Error(error);
|
throw new Error(error);
|
||||||
}
|
}
|
||||||
clearTimeout(callbackData.timeoutHandle);
|
clearTimeout(callbackData.timeoutHandle);
|
||||||
|
|
||||||
delete callbacks[callbackID];
|
delete callbacks[callbackID];
|
||||||
|
|
||||||
if (message.error) {
|
if (message.error) {
|
||||||
return callbackData.reject(message.error);
|
return callbackData.reject(message.error);
|
||||||
}
|
}
|
||||||
return callbackData.resolve(message.data);
|
return callbackData.resolve(message.data);
|
||||||
}
|
}
|
||||||
|
|
||||||
// systemCall is used to call wails methods from the frontend
|
// systemCall is used to call wails methods from the frontend
|
||||||
export function SystemCall(method, data) {
|
export function SystemCall(method, data) {
|
||||||
return Call('.wails.' + method, data);
|
return Call('.wails.' + method, data);
|
||||||
}
|
}
|
@ -14,92 +14,92 @@ import { SendMessage } from './ipc';
|
|||||||
|
|
||||||
// Defines a single listener with a maximum number of times to callback
|
// Defines a single listener with a maximum number of times to callback
|
||||||
class Listener {
|
class Listener {
|
||||||
constructor(callback, maxCallbacks) {
|
constructor(callback, maxCallbacks) {
|
||||||
// Default of -1 means infinite
|
// Default of -1 means infinite
|
||||||
maxCallbacks = maxCallbacks || -1;
|
maxCallbacks = maxCallbacks || -1;
|
||||||
// Callback invokes the callback with the given data
|
// Callback invokes the callback with the given data
|
||||||
// Returns true if this listener should be destroyed
|
// Returns true if this listener should be destroyed
|
||||||
this.Callback = (data) => {
|
this.Callback = (data) => {
|
||||||
callback.apply(null, data);
|
callback.apply(null, data);
|
||||||
// If maxCallbacks is infinite, return false (do not destroy)
|
// If maxCallbacks is infinite, return false (do not destroy)
|
||||||
if (maxCallbacks === -1) {
|
if (maxCallbacks === -1) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// Decrement maxCallbacks. Return true if now 0, otherwise false
|
// Decrement maxCallbacks. Return true if now 0, otherwise false
|
||||||
maxCallbacks -= 1;
|
maxCallbacks -= 1;
|
||||||
return maxCallbacks === 0;
|
return maxCallbacks === 0;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var eventListeners = {};
|
var eventListeners = {};
|
||||||
|
|
||||||
// Registers an event listener that will be invoked `maxCallbacks` times before being destroyed
|
// Registers an event listener that will be invoked `maxCallbacks` times before being destroyed
|
||||||
export function OnMultiple(eventName, callback, maxCallbacks) {
|
export function OnMultiple(eventName, callback, maxCallbacks) {
|
||||||
eventListeners[eventName] = eventListeners[eventName] || [];
|
eventListeners[eventName] = eventListeners[eventName] || [];
|
||||||
const thisListener = new Listener(callback, maxCallbacks);
|
const thisListener = new Listener(callback, maxCallbacks);
|
||||||
eventListeners[eventName].push(thisListener);
|
eventListeners[eventName].push(thisListener);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers an event listener that will be invoked every time the event is emitted
|
// Registers an event listener that will be invoked every time the event is emitted
|
||||||
export function On(eventName, callback) {
|
export function On(eventName, callback) {
|
||||||
OnMultiple(eventName, callback);
|
OnMultiple(eventName, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Registers an event listener that will be invoked once then destroyed
|
// Registers an event listener that will be invoked once then destroyed
|
||||||
export function Once(eventName, callback) {
|
export function Once(eventName, callback) {
|
||||||
OnMultiple(eventName, callback, 1);
|
OnMultiple(eventName, callback, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Notify informs frontend listeners that an event was emitted with the given data
|
// Notify informs frontend listeners that an event was emitted with the given data
|
||||||
export function Notify(eventName, data) {
|
export function Notify(eventName, data) {
|
||||||
|
|
||||||
// Check if we have any listeners for this event
|
// Check if we have any listeners for this event
|
||||||
if (eventListeners[eventName]) {
|
if (eventListeners[eventName]) {
|
||||||
|
|
||||||
// Keep a list of listener indexes to destroy
|
// Keep a list of listener indexes to destroy
|
||||||
const newEventListenerList = eventListeners[eventName].slice();
|
const newEventListenerList = eventListeners[eventName].slice();
|
||||||
|
|
||||||
// Iterate listeners
|
// Iterate listeners
|
||||||
for (let count = 0; count < eventListeners[eventName].length; count += 1) {
|
for (let count = 0; count < eventListeners[eventName].length; count += 1) {
|
||||||
|
|
||||||
// Get next listener
|
// Get next listener
|
||||||
const listener = eventListeners[eventName][count];
|
const listener = eventListeners[eventName][count];
|
||||||
|
|
||||||
// Parse data if we have it
|
// Parse data if we have it
|
||||||
var parsedData = [];
|
var parsedData = [];
|
||||||
if (data) {
|
if (data) {
|
||||||
try {
|
try {
|
||||||
parsedData = JSON.parse(data);
|
parsedData = JSON.parse(data);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
Error('Invalid JSON data sent to notify. Event name = ' + eventName);
|
Error('Invalid JSON data sent to notify. Event name = ' + eventName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Do the callback
|
// Do the callback
|
||||||
const destroy = listener.Callback(parsedData);
|
const destroy = listener.Callback(parsedData);
|
||||||
if (destroy) {
|
if (destroy) {
|
||||||
// if the listener indicated to destroy itself, add it to the destroy list
|
// if the listener indicated to destroy itself, add it to the destroy list
|
||||||
newEventListenerList.splice(count, 1);
|
newEventListenerList.splice(count, 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update callbacks with new list of listners
|
// Update callbacks with new list of listners
|
||||||
eventListeners[eventName] = newEventListenerList;
|
eventListeners[eventName] = newEventListenerList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Emit an event with the given name and data
|
// Emit an event with the given name and data
|
||||||
export function Emit(eventName) {
|
export function Emit(eventName) {
|
||||||
|
|
||||||
// Calculate the data
|
// Calculate the data
|
||||||
var data = JSON.stringify([].slice.apply(arguments).slice(1));
|
var data = JSON.stringify([].slice.apply(arguments).slice(1));
|
||||||
|
|
||||||
// Notify backend
|
// Notify backend
|
||||||
const payload = {
|
const payload = {
|
||||||
name: eventName,
|
name: eventName,
|
||||||
data: data,
|
data: data,
|
||||||
}
|
}
|
||||||
SendMessage('event', payload)
|
SendMessage('event', payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
const heartbeatCallbacks = {};
|
const heartbeatCallbacks = {};
|
||||||
@ -108,32 +108,32 @@ const heartbeatCallbacks = {};
|
|||||||
// the event is acknowledged via `Event.Acknowledge`. Once this happens, `callback` is invoked ONCE
|
// the event is acknowledged via `Event.Acknowledge`. Once this happens, `callback` is invoked ONCE
|
||||||
export function Heartbeat(eventName, timeInMilliseconds, callback) {
|
export function Heartbeat(eventName, timeInMilliseconds, callback) {
|
||||||
|
|
||||||
// Declare interval variable
|
// Declare interval variable
|
||||||
let interval = null;
|
let interval = null;
|
||||||
|
|
||||||
// Setup callback
|
// Setup callback
|
||||||
function dynamicCallback() {
|
function dynamicCallback() {
|
||||||
// Kill interval
|
// Kill interval
|
||||||
clearInterval(interval);
|
clearInterval(interval);
|
||||||
// Callback
|
// Callback
|
||||||
callback();
|
callback();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register callback
|
// Register callback
|
||||||
heartbeatCallbacks[eventName] = dynamicCallback;
|
heartbeatCallbacks[eventName] = dynamicCallback;
|
||||||
|
|
||||||
// Start emitting the event
|
// Start emitting the event
|
||||||
interval = setInterval(function () {
|
interval = setInterval(function () {
|
||||||
Emit(eventName);
|
Emit(eventName);
|
||||||
}, timeInMilliseconds);
|
}, timeInMilliseconds);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Acknowledge(eventName) {
|
export function Acknowledge(eventName) {
|
||||||
// If we are waiting for acknowledgement for this event type
|
// If we are waiting for acknowledgement for this event type
|
||||||
if (heartbeatCallbacks[eventName]) {
|
if (heartbeatCallbacks[eventName]) {
|
||||||
// Acknowledge!
|
// Acknowledge!
|
||||||
heartbeatCallbacks[eventName]();
|
heartbeatCallbacks[eventName]();
|
||||||
} else {
|
} else {
|
||||||
throw new Error(`Cannot acknowledge unknown heartbeat '${eventName}'`);
|
throw new Error(`Cannot acknowledge unknown heartbeat '${eventName}'`);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -10,20 +10,20 @@ The lightweight framework for web-like apps
|
|||||||
/* jshint esversion: 6 */
|
/* jshint esversion: 6 */
|
||||||
|
|
||||||
function Invoke(message) {
|
function Invoke(message) {
|
||||||
if (window && window.external && window.external.invoke) {
|
if (window && window.external && window.external.invoke) {
|
||||||
window.external.invoke(message);
|
window.external.invoke(message);
|
||||||
} else {
|
} else {
|
||||||
//eslint-disable-line
|
//eslint-disable-line
|
||||||
console.log(`[No external.invoke] ${message}`);
|
console.log(`[No external.invoke] ${message}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function SendMessage(type, payload, callbackID) {
|
export function SendMessage(type, payload, callbackID) {
|
||||||
const message = {
|
const message = {
|
||||||
type,
|
type,
|
||||||
callbackID,
|
callbackID,
|
||||||
payload
|
payload
|
||||||
};
|
};
|
||||||
|
|
||||||
Invoke(JSON.stringify(message));
|
Invoke(JSON.stringify(message));
|
||||||
}
|
}
|
||||||
|
@ -15,31 +15,31 @@ import { SendMessage } from './ipc';
|
|||||||
// level + message
|
// level + message
|
||||||
function sendLogMessage(level, message) {
|
function sendLogMessage(level, message) {
|
||||||
|
|
||||||
// Log Message
|
// Log Message
|
||||||
const payload = {
|
const payload = {
|
||||||
level: level,
|
level: level,
|
||||||
message: message,
|
message: message,
|
||||||
}
|
}
|
||||||
SendMessage('log', payload)
|
SendMessage('log', payload)
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Debug(message) {
|
export function Debug(message) {
|
||||||
sendLogMessage('debug', message);
|
sendLogMessage('debug', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Info(message) {
|
export function Info(message) {
|
||||||
sendLogMessage('info', message);
|
sendLogMessage('info', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Warning(message) {
|
export function Warning(message) {
|
||||||
sendLogMessage('warning', message);
|
sendLogMessage('warning', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Error(message) {
|
export function Error(message) {
|
||||||
sendLogMessage('error', message);
|
sendLogMessage('error', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Fatal(message) {
|
export function Fatal(message) {
|
||||||
sendLogMessage('fatal', message);
|
sendLogMessage('fatal', message);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,23 +12,23 @@ The lightweight framework for web-like apps
|
|||||||
import { Emit } from './events';
|
import { Emit } from './events';
|
||||||
|
|
||||||
export function AddScript(js, callbackID) {
|
export function AddScript(js, callbackID) {
|
||||||
var script = document.createElement('script');
|
var script = document.createElement('script');
|
||||||
script.text = js;
|
script.text = js;
|
||||||
document.body.appendChild(script);
|
document.body.appendChild(script);
|
||||||
if (callbackID) {
|
if (callbackID) {
|
||||||
Emit(callbackID);
|
Emit(callbackID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Adapted from webview - thanks zserge!
|
// Adapted from webview - thanks zserge!
|
||||||
export function InjectCSS(css) {
|
export function InjectCSS(css) {
|
||||||
var elem = document.createElement('style');
|
var elem = document.createElement('style');
|
||||||
elem.setAttribute('type', 'text/css');
|
elem.setAttribute('type', 'text/css');
|
||||||
if (elem.styleSheet) {
|
if (elem.styleSheet) {
|
||||||
elem.styleSheet.cssText = css;
|
elem.styleSheet.cssText = css;
|
||||||
} else {
|
} else {
|
||||||
elem.appendChild(document.createTextNode(css));
|
elem.appendChild(document.createTextNode(css));
|
||||||
}
|
}
|
||||||
var head = document.head || document.getElementsByTagName('head')[0];
|
var head = document.head || document.getElementsByTagName('head')[0];
|
||||||
head.appendChild(elem);
|
head.appendChild(elem);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user