+/*
+* Copyright 2013 Samsung Electronics Co., Ltd
+*
+* Licensed under the Flora License, Version 1.1 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+* http://floralicense.org/license/
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
/*jslint devel: true*/
-/*global $ */
+/*global tizen, $*/
/**
- * @class Helpers
- */
+* @class Helpers
+*/
function Helpers() {
- 'use strict';
+ 'use strict';
}
(function () { // strict mode wrapper
- 'use strict';
- Helpers.prototype = {
-
- /**
- * Returns date in format YYYY/MM/DD
- * @param dateObj
- * @returns {String} formatted
- */
- getShortDate: function Helpers_getShortDate(dateObj) {
- var dd, mm, yyyy;
+ 'use strict';
- try {
- yyyy = dateObj.getFullYear().toString();
- mm = (dateObj.getMonth() + 1).toString(); // getMonth() is zero-based
- dd = dateObj.getDate().toString();
- } catch (e) {
- console.error('error', e);
- }
+ Helpers.prototype = {
- return yyyy + '/' + (mm[1] ? mm : '0' + mm[0]) + '/' + (dd[1] ? dd : '0' + dd[0]);
- },
- /**
- * Returns date in format DD short_month YYYY
- * @param dateObj
- * @returns {String} formatted
- */
- toNativeDate: function Helpers_toNativeDate(dateObj) {
- var date = dateObj.toDateString().split(" ");
+ /**
+ * Returns date in format YYYY/MM/DD
+ * @param dateObj
+ * @returns {String} formatted
+ */
+ getShortDate: function Helpers_getShortDate(dateObj) {
+ var dd, mm, yyyy;
- return date[2] + ' ' + date[1] + ' ' + date[3];
- },
- /**
- * Returns time in format HH:mm or hh:mm ap
- * @param dateObj
- * @returns {String} formatted
- */
- toNativeTime: function Helpers_toNativeDate(dateObj) {
- var hours, apHours;
+ try {
+ yyyy = dateObj.getFullYear().toString();
+ mm = (dateObj.getMonth() + 1).toString(); // January === 0
+ dd = dateObj.getDate().toString();
+ } catch (e) {
+ console.error('error', e);
+ }
- if (tizen.time.getTimeFormat().indexOf('ap') != -1) {
- hours = dateObj.getHours();
- apHours = hours % 12 < 10 ? '0' + hours % 12 : hours % 12;
+ // return in format yyyy/mm/dd
+ return yyyy + '/' + (mm[1] ?
+ mm :
+ '0' + mm[0]) + '/' + (dd[1] ? dd : '0' + dd[0]);
+ },
+ /**
+ * Returns date in format DD short_month YYYY
+ * @param dateObj
+ * @returns {String} formatted
+ */
+ toNativeDate: function Helpers_toNativeDate(dateObj) {
+ var date = dateObj.toDateString().split(" ");
+ return date[2] + ' ' + date[1] + ' ' + date[3];
+ },
+ /**
+ * Returns time in format HH:mm or hh:mm ap
+ * @param dateObj
+ * @returns {String} formatted
+ */
+ toNativeTime: function Helpers_toNativeDate(dateObj) {
+ var hours, apHours;
+ if (tizen.time.getTimeFormat().indexOf('ap') !== -1) {
+ hours = dateObj.getHours();
+ apHours = hours % 12 < 10 ? '0' + hours % 12 : hours % 12;
- return apHours.toString().replace("00", "12") + ':' +
- (dateObj.getMinutes() < 10 ? "0" + dateObj.getMinutes() :
- dateObj.getMinutes()) + (hours > 11 ? ' PM' : ' AM');
- }
+ return apHours.toString().replace("00", "12") + ':' +
+ (dateObj.getMinutes() < 10 ? "0" + dateObj.getMinutes() :
+ dateObj.getMinutes()) + (hours > 11 ? ' PM' : ' AM');
+ }
+ return dateObj.toTimeString().substring(0, 5);
+ },
+ /**
+ * Seconds to hours converter
+ *
+ * @param seconds
+ * @returns {string}
+ */
+ secondsToHours: function Helpers_secondsToHours(seconds) {
+ var str = '';
+ str = ((seconds % 60 < 10) ? '0' : '') + (seconds % 60);
+ seconds = parseInt(seconds / 60, 10);
+ str = ':' + str;
+ str = ((seconds % 60 < 10) ? '0' : '') + (seconds % 60) + str;
+ seconds = parseInt(seconds / 60, 10);
+ str = ':' + str;
+ str = ((seconds % 24 < 10) ? '0' : '') + (seconds % 24) + str;
+ seconds = parseInt(seconds / 24, 10);
+ return str;
+ },
- return dateObj.toTimeString().substring(0, 5);
- },
- /**
- * Seconds to hours converter
- *
- * @param seconds
- * @returns {string}
- */
- secondsToHours: function Helpers_secondsToHours(seconds) {
- var str = '';
- str = ((seconds % 60 < 10) ? '0' : '') + (seconds % 60);
- seconds = parseInt(seconds / 60, 10);
- str = ':' + str;
- str = ((seconds % 60 < 10) ? '0' : '') + (seconds % 60) + str;
- seconds = parseInt(seconds / 60, 10);
- str = ':' + str;
- str = ((seconds % 24 < 10) ? '0' : '') + (seconds % 24) + str;
- seconds = parseInt(seconds / 24, 10);
- return str;
- },
+ /**
+ * Returns scroll position of the given scroll view.
+ * @param {object} element ScrollView element
+ * @returns {number} scroll position
+ */
+ getScrollPosition: function Helpers_getScrollPosition(element) {
+ return element.scrollview('getScrollPosition').y;
+ },
- /**
- * Returns scroll position of the given scroll view.
- * @param {object} element ScrollView element
- * @returns {number} scroll position
- */
- getScrollPosition: function Helpers_getScrollPosition(element) {
- return element.scrollview('getScrollPosition').y;
- },
+ /**
+ * Scrolls given jQuery ScrollView to given Y position.
+ * @param {object} element ScrollView element to be scrolled.
+ * @param {number} position Y position to scroll to
+ */
+ scrollTo: function Helpers_scrollTo(element, position) {
+ // don't allow scrolling too much
+ var maxPosition =
+ element.children().first().outerHeight(true) -
+ element.height();
+ if (maxPosition < 0) {
+ maxPosition = 0;
+ }
+ if (position > maxPosition) {
+ position = maxPosition;
+ }
+ if (position < 0) {
+ position = 0;
+ }
+ // scroll
+ element.scrollview('scrollTo', 0, -position);
+ }
- /**
- * Scrolls given jQuery ScrollView to given Y position.
- * @param {object} element ScrollView element to be scrolled.
- * @param {number} position Y position to scroll to
- */
- scrollTo: function Helpers_scrollTo(element, position) {
- // don't allow scrolling too much
- var maxPosition = element.children().first().outerHeight(true) - element.height();
- if (maxPosition < 0) {
- maxPosition = 0;
- }
- if (position > maxPosition) {
- position = maxPosition;
- }
- if (position < 0) {
- position = 0;
- }
- // scroll
- element.scrollview('scrollTo', 0, -position);
- }
+ };
- };
}());