so://phie

outline

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

blob: 5d2e305ccd09aa0a4bb69fdf9c971542a534ff14 (2068 bytes)[doc][blame][raw]

1/**

2 Creates a unique identifier based on the current date.

3

4 @function uuid

5 @return {number} The unique identifier.

6*/

7function uuid() {

8 return new Date().valueOf();

9}

10

11/**

12 Creates a template Object to create HTMLElements.

13

14 @function html

15 @callback callback

16 @return {Object} The template object.

17*/

18function html(callback) {

19 return {

20 build: function(args) {

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

22 template.innerHTML = callback(args);

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

24 return {

25 element: fragment.firstElementChild,

26 render: function(parent) {

27 parent.appendChild(fragment);

28 }

29 };

30 }

31 };

32}

33

34/**

35 Creates an object which contains the queried HTMLElements.

36

37 @function query

38 @param {Object} args - The query object.

39 @return {Object} The object containing node elements.

40*/

41function query(args) {

42 let result = {};

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

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

45 let [ key, value ] = entry;

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

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

48 }

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

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

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

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

53 parent = document.querySelector(parent);

54 }

55 result[key] = all

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

57 : parent.querySelector(query);

58 }

59 }

60 }

61 return result;

62 }

63}

64

65/**

66 Prevents an event.

67

68 @function prevent

69 @param {Event} event - The event to prevent.

70*/

71function prevent(event) {

72 event.preventDefault();

73}

74

75/**

76 Check if object variable is defined.

77

78 @function support

79 @param {Object} object - The object to check for.

80 @return {boolean} The result of the validation.

81*/

82function support(object) {

83 return typeof object !== 'undefined';

84}

85

86/**

87 Check if current page is the App page.

88

89 @function isApp

90 @return {boolean} The result of the validation.

91*/

92function isApp() {

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

94}

95

96export {

97 uuid,

98 html,

99 query,

100 prevent,

101 support,

102 isApp

103};