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 showInfoDialog(content) {
33 $('#tic-info-content').html(content);
34 $('#tic-info-dialog').modal('show');
37 function showConfirmDialog(content) {
38 return new Promise(function (resolve, reject) {
39 $('#tic-confirm-content').html(content);
40 $('#tic-confirm-ok').on('click', function () {
43 $('#tic-confirm-cancel').on('click', function () {
46 $('#tic-confirm-dialog').modal('show');
50 function bytesToSize(bytes) {
51 var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
55 var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
56 return Math.round(bytes / Math.pow(1024, i), 2) + ' ' + sizes[i];
59 function validateURL(url) {
60 var urlRegex = /(file|ftp|http|https):\/\/(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-\/]))?/;
61 return urlRegex.test(url);
64 function POST(url, postData) {
65 return new Promise(function (resolve, reject) {
68 contentType: 'application/json; charset=UTF-8',
70 data: JSON.stringify(postData),
73 success: function (result) {
76 error: function (err) {
83 function getAppConfig() {
84 return new Promise(function (resolve, reject) {
85 socket.emit('ws/app/config/from');
86 socket.on('ws/app/config/to', function (data) {
92 function getWebSocket() {
97 socket = io.connect();
104 * Set smooth scrolling, one page websites
105 * @method setAnimateScroll
107 setAnimateScroll: setAnimateScroll,
110 * Display or hide the loading dialog.
111 * @method showLoadingDialog
112 * @param {boolean} display flag
114 showLoadingDialog: showLoadingDialog,
117 * Display the info dialog.
118 * @method showInfoDialog
119 * @param {string} content in dialog
121 showInfoDialog: showInfoDialog,
124 * Display the alert dialog.
125 * @method showAlertDialog
126 * @param {string} content in dialog
128 showAlertDialog: showAlertDialog,
131 * Display the confirm dialog.
132 * @method showLoadingDialog
133 * @param {string} content in dialog
136 showConfirmDialog: showConfirmDialog,
139 * Convert size in bytes to KB, MB, GB, TB
140 * {@link http://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript}
141 * @method bytesToSize
142 * @param {number} byte number
144 bytesToSize: bytesToSize,
147 * Makes the element require a valid url.
148 * @method validateURL
149 * @param {string} url - A string containing the URL.
150 * @return {boolean} Return true, if the value is a valid url.
152 validateURL: validateURL,
155 * Load data from the server using a HTTP POST request.
157 * @param {string} url - A string containing the URL to which the request is sent.
158 * @param {object} data - A plain object or string that is sent to the server with the request.
164 * Get WebSocket client
165 * @method getWebSocket
166 * @return {object} socket
168 getWebSocket: getWebSocket,
171 * Load app configuration from config.json of root
172 * @method getAppConfig
175 getAppConfig: getAppConfig,