so://phie

outline

A web-based drawing app
git clone git://soophie.de/outline

blob: bd0c0b9c68f707b198e352c1140a433d99e97539 (1427 bytes)[doc][blame][raw]

1export function uuid() {

2 return new Date().valueOf();

3}

4

5export function html(callback) {

6 return {

7 build: function(args) {

8 let template = document.createElement('template');

9 template.innerHTML = callback(args);

10 let fragment = template.content.cloneNode(true);

11 return {

12 element: fragment.firstElementChild,

13 render: function(parent) {

14 parent.appendChild(fragment);

15 }

16 };

17 }

18 };

19}

20

21export function query(args) {

22 let result = {};

23 if(typeof args === 'object') {

24 for(let entry of Object.entries(args)) {

25 let [ key, value ] = entry;

26 if(typeof value === 'string') {

27 result[key] = document.querySelector(value);

28 }

29 if(typeof value === 'object') {

30 let { query, all = false, parent = document } = value;

31 if(typeof query === 'string') {

32 if(typeof parent === 'string') {

33 parent = document.querySelector(parent);

34 }

35 result[key] = all

36 ? Array.from(parent.querySelectorAll(query))

37 : parent.querySelector(query);

38 }

39 }

40 }

41 return result;

42 }

43}

44

45export function prevent(event) {

46 event.preventDefault();

47}

48

49export function support(object) {

50 return typeof object !== 'undefined';

51}

52

53export function isApp() {

54 return window.location.pathname === '/app';

55}

56

57export function isStandalone() {

58 return ['fullscreen', 'standalone', 'minimal-ui'].some(function(display) {

59 return window.matchMedia('(display-mode: ' + display + ')').matches;

60 });

61}