var g_support_html5 = 0; var g_reload_page = 1; var m = new lang(); var g_storage = new myStorage(); var g_listview = (g_storage.get('listview') == undefined) ? 0 : g_storage.get('listview'); var g_modal_url; var g_modal_window_width = 200; var g_modal_window_height = 80; var timer_idle; var g_show_modal = 0; var g_time_out = 900000; //- 15min var g_time_count = 0; var g_select_mode = 0; var g_select_array; var g_upload_mode = 0; var g_folder_array; var g_file_array; var g_opening_uid = ''; var g_on_button_animation = 0; var g_on_rescan_samba = 0; var g_rescan_samba_timer = 0; var g_rescan_samba_count = 0; var g_aidisk_name = "usbdisk"; var g_enable_aidisk = 0; var g_support_lan = new Array('en-us', 'zh-tw', 'zh-cn', 'cz', 'pl', 'ru', 'de', 'fr', 'tr', 'th', 'ms', 'no', 'fi', 'da', 'sv', 'br', 'jp', 'es', 'it', 'uk'); var g_bInitialize = false; var g_showAudioList = false; var g_jplayer_solution = "html"; var g_jplayer_supplied = "mp3"; var g_audio_playlist = []; var g_current_index = 0; var g_timer_filelist; var newMenu = null; //variable to store menu instance var client = new davlib.DavClient(); client.initialize(); // Check for the various File API support. if (window.File && window.FileReader && window.FileList && window.Blob) { // Great success! All the File APIs are supported. g_support_html5 = 1; } else { g_support_html5 = 0; } function openImageViewer(loc){ var image_array = new Array(); for(var i=0;i'; div_html += '
'; for(var i=0;i'; else div_html += ''; } div_html += '
'; div_html += '
'; div_html += '
'; for(var i=0;i'; div_html += '
'; } div_html += '
'; div_html += ''; div_html += ''; div_html += ''; $(div_html) .animate({width:"100%", height:"100%", left:"0px", top:"0px"},200, null, null ) .appendTo("body"); var close_handler = function(){ self.file_array = null; self.settings = null; }; var init_handler = function(settings){ self.settings = settings; }; $('#image_slide_show').barousel({ name: 'image_slide_show', manualCarousel: 1, contentResize:0, startIndex:default_index, storage: g_storage, stringTable: m, enableExifFunc: 0, enableShareFunc: 0, closeHandler: null, initCompleteHandler: null }); /* $('#image_slide_show').barousel({ navType: 2, manualCarousel: 1, contentResize:0, startIndex:default_index }); */ image_array = null; } function openDialog(effect, role_target){ $.mobile.changePage('#dialog', {transition: effect, role: role_target}); } function closeDialog(){ $.mobile.changePage('#mainpage', "popup", true, true); } function openLoginWindow(open_url){ var dialog_title = ""; var dologin = function(){ var user = $('#table_content input#username').val(); var pass = $('#table_content input#password').val(); var auth = "Basic " + Base64.encode(user + ":" + pass); closeDialog(); doLOGIN(open_url, auth); }; if(open_url=='/') dialog_title = m.getString('title_login') + " - AiCloud"; else dialog_title = m.getString('title_login') + " - " + open_url.substring(0, 35); $("#dialog").remove(); var dialog_html = ''; dialog_html += "
"; dialog_html += "
"; dialog_html += "

" + dialog_title + "

"; dialog_html += "
"; dialog_html += "
"; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += '
'; dialog_html += '
'; dialog_html += '
'; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += '
'; dialog_html += '
'; dialog_html += '
'; dialog_html += '
'; dialog_html += ''; dialog_html += '
'; dialog_html += "
"; dialog_html += "
"; $("body").append(dialog_html); $('#table_content input#password').keydown(function(e){ if(e.keyCode==13){ dologin(); } }); $("#table_content #ok").click(function(){ dologin(); }); $("#table_content #cancel").click(function(){ closeDialog(); }); openDialog("pop", "dialog"); } function openShareWindow(open_url){ var dialog_title = ""; $("#dialog").remove(); var share_array = open_url.split(";"); var dialog_html = ''; dialog_html += "
"; dialog_html += "
"; dialog_html += "

" + m.getString('btn_sharelink') + "

"; dialog_html += "
"; dialog_html += "
"; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += '
'; dialog_html += ''; dialog_html += '
'; dialog_html += ''; dialog_html += '
'; dialog_html += "
"; dialog_html += "
"; $("body").append(dialog_html); $("#table_content #email-sharelink").click(function(){ var sMailTo = "mailto:"; var sBody = ""; var newline = "%0D%0A%0D%0A"; sBody += m.getString('msg_sharelink_desc1'); sBody += newline; for(var i=0; i" + share_array[i] + ""; sBody += newline; } sBody += m.getString('msg_sharelink_desc2'); sMailTo += "?subject=" + m.getString('email_subject') + "&body=" + sBody; document.location.href = sMailTo; }); $("#table_content #sms-sharelink").click(function(){ var sSMSTo = "sms:"; var sBody = ""; var newline = "%0D%0A%0D%0A"; sBody += m.getString('msg_sharelink_desc1'); sBody += newline; for(var i=0; i" + share_array[i] + ""; sBody += newline; } sBody += m.getString('msg_sharelink_desc2'); sSMSTo += "?subject=" + m.getString('email_subject') + "&body=" + sBody; document.location.href = sSMSTo; }); $("textarea#share_link").click(function(){ $(this).select(); }); $("#table_content #cancel").click(function(){ closeDialog(); }); openDialog("pop", "dialog"); } function getLatestVersion(){ if(client==null) return; $("#update").text(m.getString('msg_check_latest_ver')); client.GETLATESTVER("/", function(error, content, statusstring){ if(error==200){ var data = parseXml(statusstring); var x = $(data); var ver = x.find("version").text(); var a = ver.split("_"); var build_no = a[1]; var cur_ver = g_storage.get('router_version'); var b = cur_ver.split("."); var cur_build_no = b[3]; if(build_no>cur_build_no) $("#update").text(m.getString('msg_update_latest_ver')); else $("#update").text(m.getString('msg_latest_ver')); } else{ $("#update").text(m.getString('msg_check_latest_ver_error')); } }); } function refreshShareLinkList(){ if(client==null) return; client.GSLL("/", function(error, content, statusstring){ if(error==200){ var data = parseXml(statusstring); $(".sharelink").empty(); var encode_filename = parseInt($(data).find('encode_filename').text()); var table_html = "" var i = 0; $(data).find('sharelink').each(function(){ var filename = ""; var filetitle = ""; if(encode_filename==1){ filename = $(this).attr("filename"); filetitle = decodeURIComponent(filename); } else{ filetitle = $(this).attr("filename"); filename = encodeURIComponent($(this).attr("filename")); } var url = window.location.protocol + "//" + window.location.host + "/" + $(this).attr("url") + "/" + filename; var createtime = $(this).attr("createtime"); var expiretime = $(this).attr("expiretime"); var lefttime = parseFloat($(this).attr("lefttime")); var hour = parseInt(lefttime/3600); var minute = parseInt(lefttime%3600/60); table_html = "
  • "; table_html += "

    " + filetitle + "

    "; //table_html += "
    test"; table_html += "

    "; table_html += m.getString('table_createtime') + ": "; table_html += createtime; table_html += "

    "; table_html += "

    "; table_html += m.getString('table_expiretime') + ": "; if(expiretime==0) table_html += m.getString('title_unlimited'); else table_html += expiretime; table_html += "

    "; table_html += "

    "; table_html += m.getString('table_lefttime') + ": "; if(expiretime==0) table_html += m.getString('title_unlimited'); else table_html += hour + " hours " + minute + " mins"; table_html += "

    "; table_html += "
  • "; $("ul.sharelink").append(table_html).find("li:last").hide(); $('ul.sharelink').listview('refresh'); $("ul.sharelink").find("li:last").slideDown(300); }); $(".dellink").click(function(){ var r=confirm(m.getString('msg_confirm_delete_sharelink')); if (r==true){ client.REMOVESL("/", $(this).attr("link"), function(error, content, statusstring){ if(error==200){ refreshShareLinkList(); } else alert("Fail to delete sharelink!"); }); } }); } }); } function openSettingWindow(){ var dialog_title = ""; var loc_lan = String(window.navigator.userLanguage || window.navigator.language).toLowerCase(); var lan = ( g_storage.get('lan') == undefined ) ? loc_lan : g_storage.get('lan'); $("#dialog").remove(); var dialog_html = ''; dialog_html += "
    "; dialog_html += "
    "; dialog_html += "

    " + m.getString('title_setting') + "

    "; dialog_html += "" + m.getString("btn_prevpage") + ""; dialog_html += "
    "; dialog_html += "
    "; dialog_html += "
    "; //- ShareLink manager dialog_html += "
    "; dialog_html += "

    " + m.getString('title_sharelink') + "

    "; dialog_html += ""; dialog_html += "
    "; //- Version dialog_html += "
    "; dialog_html += "

    " + m.getString('title_version') + "

    "; dialog_html += "AiCloud " + m.getString('title_version') + ": " + g_storage.get('aicloud_version') + ""; dialog_html += "
    FW " + m.getString('title_version') + ": " + g_storage.get('router_version') + ""; dialog_html += "
    "; dialog_html += "
    "; //- Language dialog_html += "
    "; dialog_html += "

    " + m.getString('title_language') + "

    "; dialog_html += "
    "; for( var i = 0; i < g_support_lan.length; i++ ){ dialog_html += ""; dialog_html += ""; //- Desktop View dialog_html += "" + m.getString('title_desktop_view') + ""; dialog_html += "
    "; dialog_html += "
    "; dialog_html += "
    "; $("body").append(dialog_html); //getLatestVersion(); refreshShareLinkList(); $("#rescan").click(function(){ var r=confirm(m.getString('title_desc_rescan')); if (r==true) doRescanSamba(); }); $("#desktop_view").click(function(){ var url = window.location.href; url = url.substr(0, url.lastIndexOf("?")); window.location = url + '?desktop=1'; }); $("#back").click(function(){ closeDialog(); }); $("input[type=radio]").click(function(){ var lan = $(this).attr("id"); g_storage.set('lan', lan); window.location.reload(); }); openDialog("flip", "page"); } function showHideAudioList(bshow){ if(bshow){ $(".jp-playlist").css("display", "block"); } else{ $(".jp-playlist").css("display", "none"); } g_showAudioList = bshow; } function showHideAudioInterface(bshow){ if(bshow){ $("#jp_interface_1").css("display","block"); } else{ $("#jp_interface_1").css("display","none"); } } function openAudioPlayer(loc){ var audio_array = new Array(); for(var i=0;ithis_audio_list.length-1){ clearInterval(timer); initJPlayer(); showHideLoadStatus(false); $.mobile.changePage('#audio_dialog', {transition: 'pop', role: 'dialog'}); return; } var this_audio = this_audio_list[current_query_index]; var this_file_name = this_audio.substring( this_audio.lastIndexOf("/")+1, this_audio.length ); var this_url = this_audio.substring(0, this_audio.lastIndexOf('/')); on_query = true; client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){ if(error==200){ var data = parseXml(statusstring); var share_link = $(data).find('sharelink').text(); share_link = media_hostName + share_link; on_query = false; var obj = []; obj['name'] = mydecodeURI(this_file_name); obj['mp3'] = share_link; g_audio_playlist.push(obj); current_query_index++; } }); } }, 100); } else{ for(var i=0; i < this_audio_list.length;i++){ var this_audio = this_audio_list[i]; var this_file_name = this_audio.substring( this_audio.lastIndexOf("/")+1, this_audio.length ); var this_url = this_audio.substring(0, this_audio.lastIndexOf('/')); var obj = []; obj['name'] = mydecodeURI(this_file_name); obj['mp3'] = this_audio; g_audio_playlist.push(obj); } initJPlayer(); showHideLoadStatus(false); $.mobile.changePage('#audio_dialog', {transition: 'pop', role: 'dialog'}); } } function doRescanSamba(){ var openurl = addPathSlash(g_storage.get('openurl')); closeDialog(); showHideLoadStatus(true); client.RESCANSMBPC(openurl, function(error){ if(error[0]==2){ g_storage.setl("onRescanSamba", 1); g_storage.setl("onRescanSambaCount", 0); g_storage.set("HostList", ""); doPROPFIND("/"); } }); } function doMKDIR(name){ var openurl = addPathSlash(g_storage.get('openurl')); var this_url = openurl + myencodeURI(name); var already_exists = 0; $('li#list_item').each(function(index) { if($(this).attr("isdir")=="1"){ if(name==$(this).attr("title")){ already_exists = 1; alert(m.getString('folder_already_exist_msg')); return; } } }); if(already_exists==1) return; client.MKCOL(this_url, function(error){ if(error[0]==2){ doPROPFIND(openurl); } else alert(m.getString(error)); }); } function doRENAME(old_name, new_name){ var already_exists = 0; var openurl = addPathSlash(g_storage.get('openurl')); var this_url = openurl + new_name; $('li#list_item').each(function(index) { if(new_name==myencodeURI($(this).attr("title"))){ already_exists = 1; if($(this).attr("isdir")=="1") alert(m.getString('folder_already_exist_msg')); else alert(m.getString('file_already_exist_msg')); return; } }); if(already_exists==1) return; //alert(old_name + '-> ' + this_url); client.MOVE(old_name, this_url, function(error){ if(error[0]==2){ doPROPFIND(openurl); } else alert(m.getString(error) + " : " + decodeURI(old_name)); }, null, false); } function getFileViewHeight(){ return $("#fileview").height(); } function closeUploadPanel(v){ g_upload_mode = 0; g_reload_page=v; g_storage.set('stopLogoutTimer', "0"); $("div#btnNewDir").css("display", "block"); if(g_support_html5==1) $("div#btnUpload").css("display", "block"); $("div#btnSelect").css("display", "block"); $("#btnPlayImage").css("display", "block"); $("div#btnCancelUpload").css("display", "none"); $("#function_help").text(""); $("#upload_panel").animate({left:"1999px"},"slow", null, function(){ $("#upload_panel").css("display", "none"); adjustLayout(); }); if(v==1){ var openurl = addPathSlash(g_storage.get('openurl')); doPROPFIND(openurl); } } function openSelectMode(){ if(g_select_mode==1) return; $("li#list_item").removeClass("ui-btn-active"); $("li#list_item").removeClass("selected"); $("li#list_item #icon").addClass("selectmode"); $("#navbar").css("display","none"); $("#navbar2").css("display","block"); $('#btn-delete').addClass('ui-disabled'); $('#btn-rename').addClass('ui-disabled'); $('#btn-share').addClass('ui-disabled'); g_select_mode = 1; } function cancelSelectMode(){ if(g_select_mode==0) return; $("#navbar").css("display","block"); $("#navbar2").css("display","none"); $("li#list_item #icon").removeClass("selectmode"); $("li#list_item #icon").removeClass("checked"); $("li#list_item").removeClass("ui-btn-active"); $("li#list_item").removeClass("selected"); g_select_mode = 0; } function adjustLayout(){ var page_size = getPageSize(); var page_width = page_size[0]; var page_height = page_size[1]; var page_width = $(".ui-mobile-viewport").width(); var page_height = $(".ui-mobile-viewport").height(); $("div#content").css("height", page_height - $("#header").height() - $("#footer").height() - $("#btnParent").height() - parseInt($("#content").css("padding"))*2 ); } function closeJqmWindow(v){ g_reload_page=v; var $modalWindow = $('div#modalWindow'); var $modalContainer = $('iframe', $modalWindow); $modalContainer.attr('src', ''); if($modalWindow) $modalWindow.jqmHide(); showHideLoadStatus(false); } function resizeJqmWindow(w,h){ var $modalWindow = $('.jqmWindow'); if($modalWindow){ $modalWindow.css("width", w + "px"); $modalWindow.css("height", h + "px"); } } function fullscreenJqmWindow(v){ var $modalWindow = $('div#modalWindow'); if($modalWindow){ $modalWindow.css("left", "0px"); $modalWindow.css("top", "0px"); $modalWindow.css("width", window.width + "px"); $modalWindow.css("height", window.height + "px"); } } function doLOGOUT(){ doPROPFIND("/", function(){ var openurl = addPathSlash(g_storage.get('openurl')); client.LOGOUT("/", function(error){ if(error[0]==2){ g_storage.set('openhostuid', '0'); window.location.reload(); } }); }, 0); } function resetTimer(){ clearInterval(timer_idle); g_time_count = 0; timer_idle = setInterval( function(){ if(g_storage.get('stopLogoutTimer')=="1"||g_show_modal==1){ g_time_count = 0; return; } g_time_count++; if( (g_time_count*1000) > g_time_out){ g_time_count=0; doLOGOUT(); } }, 1000 ); } function createOpenUrlUI(open_url){ if(open_url==undefined) open_url = "/"; var s = mydecodeURI(open_url); var b = ""; var c = ""; var tmp = ""; var urlregion_width = $("#urlregion-url").width(); if(s!="/"){ var aa = s.split('/'); var bb = open_url.split('/'); for(var i=0; i" + aa[i] + ""; var cur_width = String(tmp).width($("p#openurl").css('font')); if(cur_width>urlregion_width){ b += " / ..."; break; } if(aa[1]==g_aidisk_name&&g_enable_aidisk==1) b += " / " + aa[i] + ""; else b += " / " + aa[i] + ""; tmp = b; } } $("p#openurl").empty(); $("p#openurl").append(b); $("a#url_path").click(function(){ doPROPFIND($(this).attr("uhref")); }); } function doPROPFIND(open_url, complete_handler, auth){ if(client==null) return; showHideLoadStatus(true); try{ client.PROPFIND(open_url, auth, function(error, statusstring, content){ if(error){ if(error==207){ cancelSelectMode(); closeUploadPanel(); var parser; var xmlDoc; g_folder_array = new Array(); g_file_array = new Array(); if (window.DOMParser){ parser=new DOMParser(); xmlDoc=parser.parseFromString(content,"text/xml"); } else { // Internet Explorer xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc.async="false"; xmlDoc.loadXML(content); if(!xmlDoc.documentElement){ alert("Fail to load xml!"); showHideLoadStatus(false); return; } } var i, j, k, l, n; var x = xmlDoc.documentElement.childNodes; var this_query_type = xmlDoc.documentElement.getAttribute('qtype'); //- 2: query host, 1: query share, 0: query file var this_folder_readonly = xmlDoc.documentElement.getAttribute('readonly'); var this_router_username = xmlDoc.documentElement.getAttribute('ruser'); var this_computer_name = xmlDoc.documentElement.getAttribute('computername'); var this_isusb = xmlDoc.documentElement.getAttribute('isusb'); //- D:Response for (i=0;ilen){ this_short_name = this_short_name.substring(0, len) + "..."; } */ } else{ this_href=""; } } else{ this_href=""; } } } if(this_href!=""){ if( this_contenttype=="httpd/unix-directory" ){ g_folder_array.push({ contenttype: this_contenttype, href: this_href, name: this_name, uname: this_uncode_name, shortname: this_short_name, online: this_online, time: this_lastmodified, size: this_contentlength, ip: this_ip, mac: this_mac, uid: this_uniqueid, type: this_type, freadonly: this_attr_readonly, fhidden: this_attr_hidden, routersyncfolder: this_router_sync_folder }); } else{ g_file_array.push({ contenttype: this_contenttype, href: this_href, name: this_name, uname: this_uncode_name, shortname: this_short_name, online: this_online, time: this_lastmodified, size: this_contentlength, ip: this_ip, mac: this_mac, uid: this_uniqueid, type: this_type, freadonly: this_attr_readonly, fhidden: this_attr_hidden, routersyncfolder: this_router_sync_folder }); } } } //- Sort By Name g_folder_array.sort(sortByName); g_file_array.sort(sortByName); //- Move the usbdisk to first var index; for(index=0; index'; html += m.getString("btn_prevpage"); html += '
    '; $('#content').before(html); } //- Folder List for(var i=0; i5)file_ext=""; var html = ""; html += '
  • '; html += "
    "; //- ICON if(file_ext=="jpg"||file_ext=="jpeg"||file_ext=="png"||file_ext=="gif"||file_ext=="bmp") html += ""; else if(file_ext=="mp3"||file_ext=="m4a"||file_ext=="m4r"||file_ext=="wav") html += ""; else if(file_ext=="mp4"||file_ext=="rmvb"||file_ext=="m4v"||file_ext=="wmv"||file_ext=="avi"||file_ext=="mpg"|| file_ext=="mpeg"||file_ext=="mkv"||file_ext=="mov"||file_ext=="flv"||file_ext=="3gp"||file_ext=="m2v"||file_ext=="rm") html += ""; else if(file_ext=="doc"||file_ext=="docx") html += ""; else if(file_ext=="ppt"||file_ext=="pptx") html += ""; else if(file_ext=="xls"||file_ext=="xlsx") html += ""; else if(file_ext=="pdf") html += ""; else html += ""; html += file_array[i].shortname; html += "
    "; html += '
  • '; $("ul#list").append(html).find("li:last").hide(); $('ul#list').listview('refresh'); $("ul#list").find("li:last").slideDown(300); } */ var current_list_index = 0; g_timer_filelist = setInterval(function(){ if(current_list_index<0||current_list_index>file_array.length-1){ clearInterval(g_timer_filelist); return; } var i = current_list_index; var this_title = m.getString("table_time") + ": " + file_array[i].time + "\n" + m.getString("table_size") + ": " + file_array[i].size; //- get file ext var file_path = String(file_array[i].href); var file_ext = getFileExt(file_path); if(file_ext.length>5)file_ext=""; var html = ""; html += '
  • '; //- ICON if(file_ext=="jpg"||file_ext=="jpeg"||file_ext=="png"||file_ext=="gif"||file_ext=="bmp") html += ""; html += "
    "; html += "

    " + file_array[i].shortname + "

    "; html += "

    "; html += m.getString("table_time") + ": " + file_array[i].time; html += "

    "; html += "

    "; html += m.getString("table_size") + ": " + file_array[i].size; html += "

    "; html += "
    "; html += '
  • '; $("ul#list").append(html).find("li:last").hide(); $('ul#list').listview('refresh'); $("ul#list").find("li:last").slideDown(300); current_list_index++; }, 200); } function sortByName(a, b) { var x = a.name.toLowerCase(); var y = b.name.toLowerCase(); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); } function arraymove(arr, fromIndex, toIndex) { var element = arr[fromIndex]; arr.splice(fromIndex,1); arr.splice(toIndex,0,element); } function showHideLoadStatus(bshow){ if(bshow) $.mobile.showPageLoadingMsg(); else $.mobile.hidePageLoadingMsg(); } function openSelItem(item){ var loc = item.attr("uhref"); var qtype = item.attr("qtype"); var isdir = item.attr("isdir"); var isusb = item.attr("isusb"); var this_full_url = item.attr("uhref"); var this_file_name = item.attr("title"); g_storage.set('openuid', item.attr("uid")); g_storage.set('opentype', isusb); if(qtype==2){ var online = item.attr("online"); if(online==0){ var r=confirm(m.getString('wol_msg')); if (r==true){ var this_mac = item.attr("mac"); client.WOL("/", this_mac, function(error){ if(error==200) alert(m.getString('wol_ok_msg')); else alert(m.getString('wol_fail_msg')); }); } return; } } if(isdir=="1"){ doPROPFIND(loc, null, null); return; } var fileExt = getFileExt(loc); var webdav_mode = g_storage.get('webdav_mode'); /* if( fileExt=="mp4" || fileExt=="m4v" || fileExt=="wmv" || fileExt=="avi" || fileExt=="rmvb"|| fileExt=="rm" || fileExt=="mpg" || fileExt=="mpeg"|| fileExt=="mkv" || fileExt=="mov" || fileExt=="flv" ) { //- webdav_mode=0-->enable http, webdav_mode=2-->both enable http and https if( webdav_mode==0 || webdav_mode==2 ){ if( isWinOS() ){ if( isBrowser("msie") && getInternetExplorerVersion() <= 7 ){ //- The VLC Plugin doesn't support IE 7 or less alert(m.getString('msg_vlcsupport')); } else{ var $modalWindow = $("div#modalWindow"); this_file_name = myencodeURI(this_file_name); this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/')); var media_hostName = window.location.host; if(media_hostName.indexOf(":")!=-1) media_hostName = media_hostName.substring(0, media_hostName.indexOf(":")); media_hostName = "http://" + media_hostName + ":" + g_storage.get("http_port") + "/"; client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){ if(error==200){ var data = parseXml(statusstring); var share_link = $(data).find('sharelink').text(); var open_url = ""; share_link = media_hostName + share_link; open_url = '/smb/css/vlc_video.html?v=' + share_link; open_url += '&showbutton=1'; g_modal_url = open_url; g_modal_window_width = 655; g_modal_window_height = 500; $('#jqmMsg').css("display", "none"); $('#jqmTitleText').text(m.getString('title_videoplayer')); if($modalWindow){ $modalWindow.jqmShow(); } } }); return; } } } } */ if( fileExt=="mp3" ) { openAudioPlayer(loc); return; } if( fileExt=="doc" || fileExt=="docx" || fileExt=="ppt" || fileExt=="pptx" || fileExt=="xls" || fileExt=="xlsx" || fileExt=="pdf") { var location_host = window.location.host; //- It will open with google doc viewer when OS is window or mac and using public ip. if( ( isWinOS() || isMacOS() ) && !isPrivateIP() ){ this_file_name = myencodeURI(this_file_name); this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/')); client.GSL(this_url, this_url, this_file_name, 0, 0, function(error, content, statusstring){ if(error==200){ var data = parseXml(statusstring); var share_link = $(data).find('sharelink').text(); var open_url = ""; share_link = window.location.protocol + "//" + window.location.host+ "/" + share_link; open_url = 'https://docs.google.com/viewer?url=' + share_link; window.open(open_url); } }); return; } } if( fileExt=="jpg" || fileExt=="jpeg"|| fileExt=="png" || fileExt=="gif" ){ openImageViewer(loc); return; } window.open(loc); } function createLayout(){ var loc_lan = String(window.navigator.userLanguage || window.navigator.language).toLowerCase(); var lan = ( g_storage.get('lan') == undefined ) ? loc_lan : g_storage.get('lan'); m.setLanguage(lan); $("#btn-home .ui-btn-text").text(m.getString('btn_homepage')); $("#btn-refresh .ui-btn-text").text(m.getString('btn_refresh')); $("#btn-logout .ui-btn-text").text(m.getString('title_logout')); $("#btn-setting .ui-btn-text").text(m.getString('title_setting')); $("#btn-delete .ui-btn-text").text(m.getString('btn_delselect')); $("#btn-rename .ui-btn-text").text(m.getString('btn_rename')); $("#btn-share .ui-btn-text").text(m.getString('btn_sharelink')); $("#btn-createfolder .ui-btn-text").text(m.getString('btn_newdir')); $("#btn-changeuser").hide(); $("#btn-select").hide(); } function addtoFavorite(){ var favorite_title = "AiCloud"; var favorite_url = "https://" + g_storage.get('ddns_host_name'); var isIEmac = false; var isMSIE = isBrowser("msie"); if(favorite_url==""||favorite_url==undefined){ favorite_url="https://router.asus.com/"; } if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) { window.sidebar.addPanel(favorite_title, favorite_url, ""); return false; } else if (isMSIE && typeof window.external == "object") { window.external.AddFavorite(favorite_url, favorite_title); return false; } else { window.location = favorite_url; var ua = navigator.userAgent.toLowerCase(); var str = ''; var isWebkit = (ua.indexOf('webkit') != - 1); var isMac = (ua.indexOf('mac') != - 1); if (ua.indexOf('konqueror') != - 1) { str = 'CTRL + B'; // Konqueror } else if (window.home || isWebkit || isIEmac || isMac) { str = (isMac ? 'Command/Cmd' : 'CTRL') + ' + D'; // Netscape, Safari, iCab, IE5/Mac } str = ((str) ? m.getString('msg_add_favorite1') + str + m.getString('msg_add_favorite2') : str); alert(str); } } function getRouterInfo(){ client.GETROUTERINFO("/", function(error, statusstring, content){ if(error==200){ var data = parseXml(content); var x = $(data); g_storage.set('webdav_mode', x.find("webdav_mode").text()); g_storage.set('http_port', x.find("http_port").text()); g_storage.set('https_port', x.find("https_port").text()); g_storage.set('misc_http_enable', x.find("misc_http_enable").text()); g_storage.set('misc_http_port', String(x.find("misc_http_port").text()).replace("\n","")); g_storage.set('last_login_info', x.find("last_login_info").text()); g_storage.set('ddns_host_name', x.find("ddns_host_name").text()); g_storage.set('router_version', x.find("version").text()); g_storage.set('aicloud_version', x.find("aicloud_version").text()); g_storage.set('modalname', x.find("modalname").text()); var login_info = g_storage.get('last_login_info'); if(login_info!=""&&login_info!=undefined){ var login_info_array = String(login_info).split(">"); var info = m.getString('title_logininfo')+ login_info_array[1] + ", " + m.getString('title_ip') + login_info_array[2]; $("#login_info").text(info); } } }); } function createMenu(menuId, parentId, options, menuHandler){ //create a containing div var div = $("").appendTo("#"+parentId).show(); //create select tag var menuElm = $("").appendTo(div); //var menuElm = $("").appendTo("#"+parentId).hide(); //add options var optionsArray = options.split(","); for (var i = 0; i < optionsArray.length; i++) $("").appendTo("#"+menuId); //convert to JQueryMobile menu $("#" + menuId).selectmenu(); //find custom menu that JQM creates var menus = $(".ui-selectmenu"); for (var i = 0; i < menus.length; i++) { if ($(menus[i]).children("ul:#" + menuId + "-menu").length > 0) { newMenu = $(menus[i]); break; } } if (newMenu == null) { alert("Error creating menu"); return; } //Associate click handler with menu items, i.e. anchor tags $(newMenu).find(".ui-selectmenu-list li a").click(menuHandler); //Add Close option var menuHeader = $(newMenu).find(".ui-header"); var closeLinkId = menuId + "_close_id"; menuHeader.prepend("" + "X"); $("#" + closeLinkId).click(function(e){ newMenu.hide(); }); return newMenu.hide(); } function showMenu(menu){ if (menu == null) return; //show menu at center of the window var left = ($(window).width() - $(menu).width()) / 2; //consider vertical scrolling when calculating top var top = (($(window).height() - $(menu).height()) / 2) + $(window).scrollTop(); left = 0; top = 0; $(menu).css({ left: left, top: top }); $(menu).show(); } //Callback handler when menu item is clicked function menuHandler(event){ if (newMenu != null) $(newMenu).hide(); alert(event.srcElement.text); } //document.addEventListener("touchmove", function(e){ //e.preventDefault(); //}, false); (function($) { $.widget('mobile.tabbar', $.mobile.navbar, { _create: function() { // Set the theme before we call the prototype, which will // ensure buttonMarkup() correctly grabs the inheritied theme. // We default to the "a" swatch if none is found var theme = this.element.jqmData('theme') || "a"; this.element.addClass('ui-footer ui-footer-fixed ui-bar-' + theme); // Make sure the page has padding added to it to account for the fixed bar this.element.closest('[data-role="page"]').addClass('ui-page-footer-fixed'); // Call the NavBar _create prototype $.mobile.navbar.prototype._create.call(this); }, // Set the active URL for the Tab Bar, and highlight that button on the bar setActive: function(url) { // Sometimes the active state isn't properly cleared, so we reset it ourselves this.element.find('a').removeClass('ui-btn-active ui-state-persist'); this.element.find('a[href="' + url + '"]').addClass('ui-btn-active ui-state-persist'); } }); $(document).bind('pagecreate create', function(e) { return $(e.target).find(":jqmData(role='tabbar')").tabbar(); }); $(document).bind('pageinit', function(e) { if(!g_bInitialize){ $.mobile.selectmenu.prototype.options.nativeMenu = false; createLayout(); getRouterInfo(); $.mobile.activeBtnClass = 'unused'; $.mobile.touchOverflowEnabled = true; //createMenu("dynamicMenu1","mainpage","Menus,menu1,menu2,menu3",menuHandler); //createMenu("dynamicMenu1", "select", "Menus,menu1,menu2,menu3", menuHandler); g_bInitialize = true; } }); $(":jqmData(role='page')").live('pageshow', function(e) { // Grab the id of the page that's showing, and select it on the Tab Bar on the page var tabBar, id = $(e.target).attr('id'); if(id=="mainpage"){ var loc = g_storage.get('openurl'); loc = (loc==undefined) ? "/" : loc; var curPath = $(".ui-listview").attr("path"); if(loc!=curPath){ doPROPFIND( loc, function(){ adjustLayout(); }, 0); } } tabBar = $.mobile.activePage.find(':jqmData(role="tabbar")'); if(tabBar.length) { tabBar.tabbar('setActive', '#' + id); } }); $("li#list_item").live("click", function() { if(g_select_mode==1){ if($(this).hasClass("ui-btn-active")){ $(this).removeClass("ui-btn-active"); $(this).removeClass("selected"); $(this).find("#icon").removeClass("checked"); } else{ $(this).addClass("ui-btn-active"); $(this).addClass("selected"); $(this).find("#icon").addClass("checked"); } var select_count = $("li#list_item.selected").size(); if(select_count>0){ $('#btn-delete').removeClass('ui-disabled'); $('#btn-share').removeClass('ui-disabled'); } else{ $('#btn-delete').addClass('ui-disabled'); $('#btn-share').addClass('ui-disabled'); } if(select_count==1) $('#btn-rename').removeClass('ui-disabled'); else $('#btn-rename').addClass('ui-disabled'); return; } $("li#list_item").removeClass("ui-btn-active"); $(this).addClass("ui-btn-active"); openSelItem($(this)); }); $("#btnParent").live("click", function() { //$("li#list_item").removeClass("ui-btn-active"); //$(this).addClass("ui-btn-active"); openSelItem($(this)); }); $("a#btn-home").live("click", function() { doPROPFIND( "/", function(){ $("a#btn-home").removeClass("ui-btn-active"); }, 0); }); $("a#btn-refresh").live("click", function() { var loc = g_storage.get('openurl'); loc = (loc==undefined) ? "/" : loc; doPROPFIND( loc, function(){ $("a#btn-refresh").removeClass("ui-btn-active"); }, 0); }); $("a#btn-setting").live("click", function() { openSettingWindow(); }); $("a#btn-share").live("click", function() { //$("a#btn-share").removeClass("ui-btn-active"); $(this).removeClass("ui-btn-active"); var share_link_array = new Array(); var complete_count = 0; var eml = ""; var subj = "?subject=" + m.getString('email_subject'); var bod = ""; var selectURL = ""; var selectFiles = ""; $("li#list_item.selected").each(function(){ var this_file_name = $(this).attr("title"); var this_full_url = $(this).attr("uhref"); var this_isdir = $(this).attr("isdir"); var this_url = window.location.href; this_url = this_full_url.substring(0, this_full_url.lastIndexOf('/')); selectURL = this_url; selectFiles += encodeURI(this_file_name); selectFiles += ";"; }); if(selectFiles==""){ alert("Please select files first."); return; } var webdav_mode = g_storage.get('webdav_mode'); var ddns_host_name = g_storage.get('ddns_host_name'); var cur_host_name = window.location.host; var hostName = ""; if(!isPrivateIP(cur_host_name)) hostName = cur_host_name; else hostName = (ddns_host_name=="") ? cur_host_name : ddns_host_name; if(hostName.indexOf(":")!=-1) hostName = hostName.substring(0, hostName.indexOf(":")); var is_private_ip = isPrivateIP(hostName); if( webdav_mode == 0 ) //- Only enable http hostName = "http://" + hostName + ":" + g_storage.get("http_port"); else hostName = "https://" + hostName; //alert(selectURL + ", " + selectFiles); client.GSL(selectURL, selectURL, selectFiles, 86400, 1, function(error, content, statusstring){ if(error==200){ var data = parseXml(statusstring); var result = $(data).find('sharelink').text(); if(result==''){ alert("Fail to parse xml!"); return; } var aa = result.split(";"); var len = aa.length; for(var i=0; i"; dialog_html += "
    "; dialog_html += "
    "; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += '
    '; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += '
    '; dialog_html += ''; dialog_html += '
    '; dialog_html += "
    "; dialog_html += ""; $("body").append(dialog_html); $("#table_content #ok").click(function(){ var oldFile = $('input#source').val(); var newName = $('input#filename').val(); var this_isdir = parseInt($('input#isdir').val()); if(newName==''){ alert(m.getString('blankchar')); return; } var regex = /[|\/\\?*"<>:`]/g; if(this_isdir==1) regex = /[|\/\\?*"<>:`.]/g; if(newName.match(regex)) { alert(m.getString('illegalchar')); return; } if(this_isdir==1){ if(oldFile.lastIndexOf('/')==oldFile.length-1) oldFile = oldFile.substring(0, oldFile.length-1); } doRENAME(oldFile, myencodeURI(newName)); }); $("#table_content #cancel").click(function(){ closeDialog(); }); openDialog("pop"); }); $("a#btn-createfolder").live("click", function() { $("#dialog").remove(); var dialog_html = ''; dialog_html += "
    "; dialog_html += "
    "; dialog_html += "

    " + m.getString('title_newdir') +"

    "; dialog_html += "
    "; dialog_html += "
    "; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += ''; dialog_html += '
    '; dialog_html += ''; dialog_html += '
    '; dialog_html += ''; dialog_html += '
    '; dialog_html += "
    "; dialog_html += "
    "; $("body").append(dialog_html); $("#table_content #ok").click(function(){ var name = $('input#dir_name').val(); if(name==''){ alert(m.getString('blankchar')); return; } var regex = /[|~\/\\?*"<>:`.]/g; if(name.match(regex)) { alert(m.getString('illegalchar')); return; } doMKDIR(name); }); $("#table_content #cancel").click(function(){ closeDialog(); }); openDialog("pop"); }); $("#btn-select").live("click", function() { if(g_select_mode==0){ openSelectMode(); $(this).addClass("click"); } else if(g_select_mode==1){ cancelSelectMode(); $(this).removeClass("click"); } }); $("#btn-changeuser").live("click", function() { var r=confirm(m.getString('msg_changeuser_confirm')); if (r!=true){ return; } var loc = g_storage.get('openurl'); client.LOGOUT(loc, function(error){ if(error==200){ doPROPFIND(loc); } }); }); $("div#select").live("click", function() { showMenu(newMenu); //showMenu($("#dynamicMenu1")); /* if(g_select_mode==0) openSelectMode(); else if(g_select_mode==1) cancelSelectMode(); */ }); $("#select-choice-custom-button").live("click", function() { //alert("click"); //alert($("#select-choice-custom").val()); if(g_select_mode==0) openSelectMode(); else if(g_select_mode==1) cancelSelectMode(); }); $("#btn-logout").live("click", function() { var r=confirm(m.getString('msg_logout_confirm')); if (r!=true){ return; } doLOGOUT(); }); $(window).resize(adjustLayout); })(jQuery);