See09/utils.js
changeset 19 f3521a11d878
equal deleted inserted replaced
18:b73e6caf0031 19:f3521a11d878
       
     1 // ////////////////////////////////////////////////////////////////////////////
       
     2 // Symbian Foundation Example Code
       
     3 //
       
     4 // This software is in the public domain. No copyright is claimed, and you 
       
     5 // may use it for any purpose without license from the Symbian Foundation.
       
     6 // No warranty for any purpose is expressed or implied by the authors or
       
     7 // the Symbian Foundation. 
       
     8 // ////////////////////////////////////////////////////////////////////////////
       
     9 
       
    10 // Loads widget preferences.
       
    11 function loadPreferences() {
       
    12     if (window.widget) {
       
    13         // load settings from widget preferences store
       
    14         data = widget.preferenceForKey("data");
       
    15     }
       
    16 }
       
    17 
       
    18 // Loads widget preferences.
       
    19 function savePreferences() {
       
    20     if (window.widget) {
       
    21         // save settings in widget preferences store
       
    22         widget.setPreferenceForKey(data, "data");
       
    23     }
       
    24 }
       
    25 
       
    26 
       
    27 
       
    28 function nocache(url) {
       
    29     if (url.indexOf("?") == -1) {
       
    30         url += "?";
       
    31     } else {
       
    32         url += "&";
       
    33     }
       
    34     url += "nocache=" + (new Date().getTime());
       
    35 	return url;
       
    36 }
       
    37 
       
    38 
       
    39 function sessionMatches(session, startDate) {
       
    40 	var m_date = session.getDate()==startDate.getDate();
       
    41 	var m_year = session.getFullYear()==startDate.getFullYear();
       
    42 	var m_month = session.getMonth()==startDate.getMonth();
       
    43 	var m_hour = session.getHours()==startDate.getHours();
       
    44 	var m_minute = session.getMinutes()==startDate.getMinutes();
       
    45 	return m_date && m_month && m_year && m_hour && m_minute; 
       
    46 }
       
    47 
       
    48 function dayToString(day) {
       
    49 	return day.toDateString(); 	
       
    50 }
       
    51 
       
    52 function dayMatches(day, startDate){
       
    53 	var m_date = day.getDate()==startDate.getDate();
       
    54 	var m_year = day.getFullYear()==startDate.getFullYear();
       
    55 	var m_month = day.getMonth()==startDate.getMonth();
       
    56 	return m_date && m_month && m_year; 
       
    57 }
       
    58 
       
    59 function sessionTimeToString(session) {
       
    60 	return ""+session.getHours()+":"+pad(session.getMinutes(),2); 	
       
    61 }
       
    62 
       
    63 function dateToString(day) {
       
    64 	var full = day.toDateString();
       
    65 	// remove year as it doesn't fit on small screens
       
    66 	return full.substring(0, full.length-4); 	
       
    67 }
       
    68 
       
    69 function pad(num, digits) {
       
    70 	var str = "" + num;
       
    71 	while ( str.length < digits ) {
       
    72 		str = "0" + str;
       
    73 	}
       
    74 	return str;
       
    75 }
       
    76 
       
    77 // Opens a URL in a separate browser window
       
    78 function openURL(url) {
       
    79     if (window.widget) {
       
    80         // in WRT
       
    81         widget.openURL(url);
       
    82     } else {
       
    83         // outside WRT
       
    84         window.open(url, "NewWindow");
       
    85     }
       
    86 }
       
    87 
       
    88 function setDefaultFontSizeForScreenSize(){
       
    89 	// no preference available, check screen size
       
    90 	if (window.innerWidth > 400 || window.innerHeight > 400) {
       
    91 		// hi res screen, use large font
       
    92 		setLargeView();
       
    93 	}
       
    94 	else {
       
    95 		// lo res screen, use small font
       
    96 		setSmallView();
       
    97 	}
       
    98 }
       
    99 
       
   100 function setLargeView(){
       
   101 	document.getElementById('stylesheet').href = 'WRTKit/Resources/UI-large.css';
       
   102 }
       
   103 
       
   104 function setSmallView(){
       
   105 	document.getElementById('stylesheet').href = 'WRTKit/Resources/UI.css';
       
   106 }
       
   107