10 function setAnimateScroll() {
11 $('a.tic-page-scroll').bind('click', function(event) {
12 var body = $('html, body');
13 var $anchor = $(this);
14 body.stop().animate({scrollTop: $($anchor.attr('href')).offset().top}, 300, 'swing');
15 event.preventDefault();
19 function showLoadingDialog(display) {
21 $('#tic-load-dialog').modal('show');
23 $('#tic-load-dialog').modal('hide');
27 function showAlertDialog(content) {
28 $('#tic-alert-content').html(content);
29 $('#tic-alert-dialog').modal('show');
32 function showConfirmDialog(content) {
33 return new Promise(function (resolve, reject) {
34 $('#tic-confirm-content').html(content);
35 $('#tic-confirm-ok').on('click', function () {
38 $('#tic-confirm-cancel').on('click', function () {
41 $('#tic-confirm-dialog').modal('show');
45 function bytesToSize(bytes) {
46 var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
50 var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
51 return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
54 function validateURL(url) {
55 var urlRegex = /(file|ftp|http|https):\/\/(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
56 return urlRegex.test(url);
59 function POST(url, postData) {
60 return new Promise(function (resolve, reject) {
63 contentType: 'application/json; charset=UTF-8',
65 data: JSON.stringify(postData),
68 success: function (result) {
71 error: function (err) {
78 function getAppConfig() {
79 return new Promise(function (resolve, reject) {
80 socket.emit('ws/app/config/from');
81 socket.on('ws/app/config/to', function (data) {
87 function getWebSocket() {
92 socket = io.connect();
99 * Set smooth scrolling, one page websites
100 * @method setAnimateScroll
102 setAnimateScroll: setAnimateScroll,
105 * Display or hide the loading dialog.
106 * @method showLoadingDialog
107 * @param {boolean} display flag
109 showLoadingDialog: showLoadingDialog,
112 * Display the alert dialog.
113 * @method showAlertDialog
114 * @param {string} content in dialog
116 showAlertDialog: showAlertDialog,
119 * Display the confirm dialog.
120 * @method showLoadingDialog
121 * @param {string} content in dialog
124 showConfirmDialog: showConfirmDialog,
127 * Convert size in bytes to KB, MB, GB, TB
128 * {@link http://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript}
129 * @method bytesToSize
130 * @param {number} byte number
132 bytesToSize: bytesToSize,
135 * Makes the element require a valid url.
136 * @method validateURL
137 * @param {string} url - A string containing the URL.
138 * @return {boolean} Return true, if the value is a valid url.
140 validateURL: validateURL,
143 * Load data from the server using a HTTP POST request.
145 * @param {string} url - A string containing the URL to which the request is sent.
146 * @param {object} data - A plain object or string that is sent to the server with the request.
152 * Get WebSocket client
153 * @method getWebSocket
154 * @return {object} socket
156 getWebSocket: getWebSocket,
159 * Load app configuration from config.json of root
160 * @method getAppConfig
163 getAppConfig: getAppConfig,