| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224 |
- //桌面脚本
- var win8Desktop={ getType : function(object) {
- return Object.prototype.toString.call(object).match(
- /^\[object\s(.*)\]$/)[1];
- },
- isTypeOf : function(object, typeStr) {
- return this.getType(object) == typeStr;
- },
- textLength : function(text) {
- var intLength = 0;
- for ( var i = 0; i < text.length; i++) {
- if ((text.charCodeAt(i) < 0) || (text.charCodeAt(i) > 255)) {
- intLength = intLength + 2;
- } else {
- intLength = intLength + 1;
- }
- }
- return intLength
- },
- getImgWh : function(url, callback) {
- var width, height, intervalId, check, div, img = new Image(), body = document.body;
- img.src = url;
- if (img.complete) {
- return callback(img.width, img.height);
- }
- ;
- if (body) {
- div = document.createElement('div');
- div.style.cssText = 'visibility:hidden;position:absolute;left:0;top:0;width:1px;height:1px;overflow:hidden';
- div.appendChild(img)
- body.appendChild(div);
- width = img.offsetWidth;
- height = img.offsetHeight;
- check = function() {
- if (img.offsetWidth !== width || img.offsetHeight !== height) {
- clearInterval(intervalId);
- callback(img.offsetWidth, img.clientHeight);
- img.onload = null;
- div.innerHTML = '';
- div.parentNode.removeChild(div);
- }
- ;
- };
- intervalId = setInterval(check, 150);
- }
- ;
- img.onload = function() {
- callback(img.width, img.height);
- img.onload = img.onerror = null;
- clearInterval(intervalId);
- body && img.parentNode.removeChild(img);
- };
- },
- fullscreen : function() {
- var docElm = document.documentElement;
- if (docElm.requestFullscreen) {
- docElm.requestFullscreen();
- } else if (docElm.mozRequestFullScreen) {
- docElm.mozRequestFullScreen();
- } else if (docElm.webkitRequestFullScreen) {
- docElm.webkitRequestFullScreen();
- }
- },
- exitFullscreen : function() {
- if (document.exitFullscreen) {
- document.exitFullscreen();
- } else if (document.mozCancelFullScreen) {
- document.mozCancelFullScreen();
- } else if (document.webkitCancelFullScreen) {
- document.webkitCancelFullScreen();
- }
- },
- fullscreenIE : function() {
- if ($.browser.msie) {
- var wsh = new ActiveXObject("WScript.Shell");
- wsh.sendKeys("{F11}");
- }
- },
- includFile : function(includePath, file) {
- var files = typeof file == "string" ? [ file ] : file;
- for ( var i = 0; i < files.length; i++) {
- var name = files[i].replace(/^\s|\s$/g, "");
- var att = name.split('.');
- var ext = att[att.length - 1].toLowerCase();
- var isCSS = ext == "css";
- var tag = isCSS ? "link" : "script";
- var attr = isCSS ? " type='text/css' rel='stylesheet' "
- : " language='javascript' type='text/javascript' ";
- var link = (isCSS ? "href" : "src") + "='" + includePath + name
- + "'";
- if ($(tag + "[" + link + "]").length == 0)
- document.write("<" + tag + attr + link + "></" + tag + ">");
- }
- },
- trim : function(str) {
- if(str==null)return "";
- return str.replace(/^\s+|\s+$/g, "");
- }
- };
- win8Desktop.wallpaper = {
- init : function(imgUrl, type) {
- var _self = this;
- if (type != 3) {
- win8Desktop.getImgWh(imgUrl, function(imgWidth, imgHeight) {
- $("<img src='" + imgUrl + "' />").appendTo("#wallpaper");
- _self.setWallpaper(imgWidth, imgHeight, type);
- $(window).wresize(function() {
- _self.setWallpaper(imgWidth, imgHeight, type);
- });
- });
- } else {
- $("#wallpaper").css({
- "background" : "url(" + imgUrl + ") repeat 0 0"
- });
- }
- },
- setWallpaper : function(imgWidth, imgHeight, type) {
- var winW = $(window).width(), winH = $(window).height();
- if (type == 1) {
- $("#wallpaper").find("img").css({
- 'width' : winW,
- 'height' : winH
- });
- }
- if (type == 2) {
- if (imgWidth > winW) {
- $("#wallpaper").find("img").css({
- 'width' : imgWidth,
- 'height' : imgHeight,
- 'margin-left' : (imgWidth - winW) / 2 + "px",
- 'margin-top' : (imgHeight - winH) / 2 + "px"
- });
- } else {
- $("#wallpaper").find("img").css({
- 'width' : imgWidth,
- 'height' : imgHeight,
- 'margin-left' : -(imgWidth - winW) / 2 + "px",
- 'margin-top' : -(imgHeight - winH) / 2 + "px"
- });
- }
- }
- }
- };
- win8Desktop.myWindow = {
- init : function(options) {
- var wh = {
- "w" : $(window).width(),
- "h" : $(window).height()
- }, curWinNum = $("div.myWindow").size(), defaults = {
- windowTitle : null,
- windowsId : null,
- windowPositionTop : 0,
- windowPositionLeft : 0,
- windowWidth : Math.round(wh['w'] * 0.9),
- windowHeight : Math.round(wh['h'] * 0.8),
- windowMinWidth : 250,
- windowMinHeight : 250,
- iframSrc : null,
- windowResizable : true,
- windowMaximize : true,
- windowMinimize : true,
- windowClosable : true,
- windowDraggable : true,
- windowStatus : 'regular',
- windowAnimationSpeed : 500,
- windowAnimation : true,
- parentPanel : 'body'
- }, options = $.extend(defaults, options), $newWin = $("#win_"
- + options['windowsId']), winHtml = function(options) {
- var winHtml = "<div class='myWindow tc_b' id='win_" + options.windowsId
- + "' >";
- /* winHtml += "<div class='winTitle'>";
- // winHtml += "<span class='winTitleName'>"
- // + options.windowTitle+ "</span>";
- winHtml += "<span class='winControlBtn'>" +
- // "<a href='#' class='winMinBtn' title='最小化'></a>" +
- // "<a href='#' class='winMaxBtn' title='最大化'></a>" +
- // "<a href='#' class='winRestore' title='还原'></a>" +
- "<a href='#' class='winCloseBtn' title='关闭'></a>" +
- "</span></div>";*/
- winHtml += "<div class='winClose' style='cursor:pointer'></div>";
- winHtml += "<div class='winContent'>";
- winHtml += "<div class='loading'>正在加载中</div>";
- winHtml += "<iframe scrolling='auto' frameborder='no' class='iframeApp' name='iframeApp_"
- + options.windowsId
- + "' id='iframeApp_"
- + options.windowsId + "' src=''></iframe>";
- winHtml += "<div class='iframeFix' id='iframeFix_" + options.windowsId + "'></div>";
- winHtml += "</div>";
- winHtml += "<div class='win_bottom' title='双击放大/还原' id='win_bottom' style='text-align:center;padding-top:5px;'>" +
- "<a href='#' class='winMinBtn' title='home'>" +
- "<img src='/shares/images/master1/home_b.png' width='53px' height='56px' />" +
- "</a>" +
- "<a href='#' style='float:right;' class='winMaxBtn' title='最大化'></a>"+
- "<a href='#' style='float:right;' class='winRestore' title='还原'></a>"+
- "</div>";
- winHtml += "</div>";
- return winHtml;
- }, _self = this;
- if (!$newWin.size()) {
- $(winHtml(options)).appendTo(options.parentPanel);
- var $newWin = $("#win_" + options['windowsId']), $allWins = $("div.myWindow"), $iframe = $newWin
- .find("iframe"),
- $loading = $newWin.find("div.loading"),
- $wincontent = $newWin.find("div.winContent"),
- $winTitle = $newWin.find("div.winTitle"),
- winMaximize_btn = $newWin.find('a.winMaxBtn'),
- winMinimize_btn = $newWin.find('a.winMinBtn'),
- // winClose_btn = $newWin.find('a.winCloseBtn'),
- winClose_btn = $newWin.find('div.winClose'),
- winHyimize_btn = $newWin.find('a.winRestore');
- var $topWin = $("div.topWin,div.topWin:hidden"),
- // dx = Math.floor((Math.random() * 200))+ (wh['w'] - options['windowWidth']) / 2,
- dx = (wh['w'] - options['windowWidth']) / 2,
- // dy = Math.floor((Math.random() * 200))+ (wh['h'] - options['windowHeight']) / 2,
- dy = 100+(wh['h'] - options['windowHeight']) / 2,
- zindex = curWinNum ? parseInt($topWin.css("z-index")?$topWin.css("z-index"):"100") + 1: curWinNum + 100,
- //zindex = 100;
- wLeft = win8Desktop.isTypeOf(
- options['windowPositionLeft'], "Number") ? options['windowPositionLeft']
- + dx
- : dx, wTop = win8Desktop.isTypeOf(
- options['windowPositionTop'], "Number") ? options['windowPositionTop']
- + dy / 2
- : dy / 2,
- iframe_init = function() {
- $iframe.attr("src", options['iframSrc']).load(function() {
- $loading.hide();
- $(this).css("left", 0);
- });
- };
- wTop = wTop-40;
- $newWin.find("div.win_bottom img").hover(function(){
- $(this).attr("src","/shares/images/master1/home.png");
- },function(){
- $(this).attr("src","/shares/images/master1/home_b.png");
- });
- $newWin.find("div.winClose").css({
- "left" : options['windowWidth']-20,
- "top" : -20,
- "z-index" : zindex+1
- });
- $allWins.removeClass("topWin").find("div.iframeFix").show();
- $newWin.addClass("topWin").css({
- "width" : options['windowWidth'],
- "height" : options['windowHeight']+65,
- "left" : wLeft,
- "top" : wTop,
- "z-index" : zindex
- }).find("div.winContent").css({
- "width" : options['windowWidth'],
- "height" : options['windowHeight'] - $winTitle.height()
- }).end().find("div.iframeFix").hide();
- _self.mask($newWin);
- if (!options.windowMaximize) {
- winMaximize_btn.hide();
- }
- if (!options.windowMinimize) {
- winMinimize_btn.hide();
- }
- if (!options.windowClosable) {
- winClose_btn.hide();
- }
- winHyimize_btn.hide();
- if (!options.windowAnimation) {
- $newWin.show(options.windowAnimationSpeed, function() {
- iframe_init();
- });
- } else {
- var o = $("#" + options.windowsId), offset = o.offset();
- $newWin.css({
- "left" : 0,
- "top" : 0
- }).animate({
- top : wTop,
- left : wLeft
- }, options.windowAnimationSpeed, function() {
- iframe_init();
- });
- }
- $newWin.data('winLocation', {
- 'w' : options['windowWidth'],
- 'h' : options['windowHeight']+65,
- 'left' : wLeft,
- 'top' : wTop,
- 'ch':options['windowHeight'] - $winTitle.height(),
- "closeLeft" : options['windowWidth']-20,
- "closeTop" : -20
- });
- $allWins.mousedown(function(event) {
- event.stopPropagation();
- var $topWin = $("div.topWin,div.topWin:hidden"), id = this.id;
- if (!$topWin.is($(this))) {
- var maxZindx = $topWin.removeClass("topWin").find(
- "div.iframeFix").show().end().css("z-index");
- $(this).css("z-index", parseInt(maxZindx) + 1).find(
- "div.iframeFix").hide().end().addClass("topWin");
- win8Desktop.taskBar.upTaskTab(id);
- }
- });
- var type = loadBrowserType();
- if("win"==type){
- if (options.windowDraggable) {
- _self.winDrag($newWin);
- }
- if (options.windowResizable) {
- _self.winResize($newWin, [ options.windowMinWidth,
- options.windowMinHeight, wh['w'] - wLeft,
- wh['h'] - wTop ]);
- }
- }
- winClose_btn.click(function() {
- _self.winClose($newWin);
- });
- winMaximize_btn.click(function() {
- _self.winMaximize($newWin);
- });
- $newWin.find("div.win_bottom").dblclick(function(){
- if ($newWin.data('windowStatus') == "maximized"){
- _self.winHyimize($newWin);
- }else{
- _self.winMaximize($newWin);
- }
- });
- winMinimize_btn.click(function() {
- _self.winMinize($newWin);
- });
- winHyimize_btn.click(function() {
- _self.winHyimize($newWin);
- });
- $winTitle.dblclick(function() {
- var hasMaximizeBtn = $(this).find(winMaximize_btn);
- if (!hasMaximizeBtn.is(":hidden")) {
- winMaximize_btn.trigger("click");
- } else {
- winHyimize_btn.trigger("click");
- }
- });
- $(window).wresize(
- function() {
- if ($newWin.data('windowStatus') == "maximized") {
- _self.winMaximize($newWin);
- }
- _self.winResize($newWin, [ options.windowMinWidth,
- options.windowMinHeight, $(window).width(),
- $(window).height() ]);
- });
- } else {
- if ($newWin.data('windowStatus') == "minsize") {
- _self.mask($newWin);
- win8Desktop.taskBar.openDialog(options.windowsId);
- // $("#taskTab_" + options.windowsId).click();
- }
- }
- },
- mask:function($newWin){
- //mask遮罩层
- var index = 1;
- if($newWin&&$newWin[0].style.zIndex){
- index = $newWin[0].style.zIndex -1;
- }
- var newMask = document.createElement("div");
- newMask.id = "win_mask";
- if($("#win_mask").length>0){
- newMask.id = "win_mask"+index;
- }
- newMask.setAttribute("name", "win_mask");
- newMask.style.position = "absolute";
- newMask.style.zIndex = index;
- _scrollWidth = Math.max(document.body.scrollWidth, document.documentElement.scrollWidth);
- _scrollHeight = Math.max(document.body.scrollHeight, document.documentElement.scrollHeight);
- newMask.style.width = _scrollWidth + "px";
- newMask.style.height = _scrollHeight + "px";
- newMask.style.top = "0px";
- newMask.style.left = "0px";
- newMask.style.background = "#33393C";
- newMask.style.filter = "alpha(opacity=10)";
- newMask.style.opacity = "0.50";
- document.body.appendChild(newMask);
- },
- winDrag : function($newWin) {
- var winHeihgt = $newWin.height();
- var wh = {
- 'w' : $(window).width(),
- 'h' : $(window).height()
- }, _self = this;
- $newWin.draggable({
- handle : 'div.win_bottom',
- scroll : false
- }).bind("drag", function(event, ui) {
- $(this).find("div.iframeFix").show();
- }).bind("dragstop", function(event, ui) {
- $(this).find("div.iframeFix").hide();
- if (event.pageY > wh.h) {
- $(this).css("top", wh.h-winHeihgt);
- } else if (event.pageY < 0) {
- $(this).css("top", 0);
- }
- $newWin.data('winLocation', {
- 'w' : $(this).width(),
- 'h' : $(this).height(),
- 'left' : $(this).css("left"),
- 'top' : $(this).css("top")
- });
- });
- },
- winResize : function($newWin, arr) {
- var status = $newWin.data("windowStatus");
- var wh = {
- "w" : $(window).width(),
- "h" : $(window).height()
- };
- var w = Math.round(wh['w'] * 0.9);
- var h = Math.round(wh['h'] * 0.8);
- var dx = (wh['w'] - w) / 2;
- if("maximized" == status){
- w = wh['w'] - 2;
- h = wh['h'] - 60;
- dx = 0;
- $newWin.find("div.winClose").css({
- "left" : w-40,
- "top" : -10,
- });
- }else{
- $newWin.find("div.winClose").css({
- "left" : w-20,
- "top" : -20,
- });
- }
- if("minsize" == status){
- dx = -99999;
- }
- $newWin.css({
- "width" : w,
- "height" : h+65,
- "left" : dx
- }).find("div.winContent").css({
- "width" : w,
- "height" : h
- });
- },
- findTopWin : function($win, maxZ) {
- var topWin;
- $win.each(function(index) {
- if ($(this).css("z-index") == maxZ) {
- topWin = $(this);
- return false;
- }
- });
- return topWin;
- },
- findNextWin : function($win) {
- var nextWin;
- $win.each(function(index) {
- if (!$(this).hasClass("hideWin")) {
- var fix = $(this).find("div.iframeFix");
- if($(fix).css("display")=="block"){
- nextWin = $(this);
- }
- }
- });
- return nextWin;
- },
- winClose : function($newWin) {
- var $topWin = $("div.myWindow,div.myWindow:hidden"),
- nextWin = this.findNextWin($topWin);
- nextWin == undefined ? "" : nextWin.addClass("topWin");
- $newWin.remove();
- win8Desktop.taskBar.removeTaskTab($newWin.attr("id"));
- var winId = $newWin.attr("id");
- winId = winId.replace("win_","");
- win8Desktop.taskBar.removeTaskMap(winId);
- if (nextWin !== undefined) {
- nextWin.find("div.iframeFix").hide();
- }
- var winMask = $('[name="win_mask"]');
- let ix = 0;
- for(let i=0;i<winMask.length;i++){
- let maskId = winMask[i].id;
- let index = maskId.replace("win_mask", "");
- if(!index){
- continue;
- }
- if(parseInt(index) > ix){
- ix = index;
- }
- }
- if(ix === 0){
- $("#win_mask").remove();
- }else{
- $("#win_mask"+ix).remove();
- }
- },
- winMaximize : function($newWin) {
- var wh = {
- 'w' : $(window).width(),
- 'h' : $(window).height()
- }, winHyimize_btn = $newWin.find("a.winRestore"), winMaximize_btn = $newWin
- .find("a.winMaxBtn");
- $newWin.data("windowStatus", "maximized").removeClass("ui-state-disabled").css({
- "width" : wh['w'] - 2,
- "height" : wh['h'],
- "left" : 0,
- "top" : 0
- }).find("div.winContent").css({
- "width" : wh['w'] - 2,
- "height" : wh['h'] - 60
- });
- var closeObj = $newWin.find("div.winClose");
- $(closeObj).css({
- "left" : wh['w']-40,
- "top" : -10,
- });
- winMaximize_btn.hide();
- winHyimize_btn.css("display", "inline-block");
- },
- winHyimize : function($newWin) {
- var winInfo = $newWin.data("winLocation"), winHyimize_btn = $newWin
- .find("a.winRestore"), winMaximize_btn = $newWin
- .find("a.winMaxBtn");
- $newWin.data("windowStatus", "regular").css({
- "width" : winInfo.w,
- "height" : winInfo.h,
- "left" : winInfo.left,
- "top" : winInfo.top
- }).find("div.winContent").css({
- "width" : winInfo.w,
- "height" : winInfo.ch
- });
- $newWin.find("div.winClose").css({
- "left" : winInfo.closeLeft,
- "top" : winInfo.closeTop
- });
- winHyimize_btn.hide();
- winMaximize_btn.show();
- },
- winMinize : function($newWin) {
- var p = $("div.desktop").index($newWin.parent());
- $newWin.data({
- "oldLeft" : $newWin.css("left"),
- "index" : p
- }).css("left", -99999).addClass("hideWin");
- $newWin.data("windowStatus", "minsize");
- if ($("div.myWindow").size() > 1) {
- $newWin.removeClass("topWin");
- }
- nextWin = this.findNextWin($("div.myWindow,div.myWindow:hidden"));
- // nextWin = this.findTopWin($("div.myWindow,div.myWindow:hidden"),
- // parseInt($newWin.css("z-index")) - 1);
- if (nextWin !== undefined) {
- // nextWin.addClass("topWin").css("z-index",
- // parseInt($newWin.css("z-index")) + 1);
- // win8Desktop.taskBar.upTaskTab(nextWin.attr("id"));
- nextWin.find("div.iframeFix").hide();
- } else {
- $("div.taskTab").removeClass("taskCurrent");
- }
- $("#win_mask").remove();
- var winId = $newWin.attr("id");
- winId = winId.replace("win_","");
- var win = $("#"+winId);
- if(win.length==0){
- win = win8Desktop.taskMap.get(winId);
- }else{
- win = $(win).data("winAttrData");
- }
- if(win==null){
- var iframeName = "iframeApp_"+winId;
- var id = winId.split("_").slice(0);
- var deskWin = $("#"+id).data("winAttrData");
- var doc = window.frames[iframeName].document;
- var title = doc.title;
- if(!title){
- title = deskWin.title;
- }
- win = {"id":winId,"title":doc.title,"iconUrl":deskWin.iconUrl,"bgColor":deskWin.bgColor};
- }
- win8Desktop.taskBar.addNewTask(win.id, win.title,win.iconUrl,win.bgColor);
- }
- };
- win8Desktop.desktop = {
- init : function(data, options) {
- var defaults = {
- 'desktopMargin' : 70,
- 'iconMargin' : 7
- }, _self = this;
- var options = $.extend(defaults, options);
- $("body").data("desktopCofig", options);
- var desktopInner = $("#desktopInner"), desktop = $("div.desktop");
- $(desktopInner).css("left",0);
- _self.desktopIconInit(data);
- _self.iconSort();
- var innerWidth = $(desktopInner).width();
- $(window).wresize(function() {
- if($(".taskDesktop").length>0){
- win8Desktop.taskBar.showTask();
- return;
- }
- _self.desktopIconInit(data);
- _self.iconSort();
- _self.iconBehavior($("div.desktopIcon:not(.addIcon)"));
- _self.initDesktop();
- innerWidth = $(desktopInner).width();
- });
- _self.iconBehavior($("div.desktopIcon:not(.addIcon)"));
- if($.browser.msie&&$.browser.version == "8.0"){
- $(desktopInner).css({"background-image":"url(#)","filter":"alpha(opacity=0)","opacity":"0"});
- }
- desktopInner.bind("mousedown",function(e){
- var wh = $(window).width();
- var dx = e.pageX;
- if((wh-dx)<50){
- $(desktopInner).css({"width":"100%"});
- $(desktopInner).css({"overflow":"hidden"});
- }
- }).bind("mouseup",function(e){
- $(desktopInner).css({"width":innerWidth});
- });
- var type = loadBrowserType();
- if("ipad"==type){
- $.fn.draggable = function(action) {
- var start = function(e) {
- var orig = e.originalEvent;
- timeStart = new Date().getTime();
- dxStart = orig.changedTouches[0].pageX;
- };
- var move = function(e) {
- var orig = e.originalEvent;
- var wt = $(window).width()-80;
- var dx = orig.changedTouches[0].pageX;
- if(dx>wt){
- return false;
- }
- };
- var stop = function(e){
- var event = e.originalEvent;
- $(this).css("cursor", "inherit");
- timeEnd = new Date().getTime();
- desktop = $("div.desktop");
- dxEnd = event.changedTouches[0].pageX;
- var timeCha = (timeEnd - timeStart) > 2 ? 2: (timeEnd - timeStart),
- dxCha = dxEnd - dxStart,
- currDesktop = $(this).find("div.currDesktop"),
- deskIndex = desktop.index(currDesktop),
- moveDx = currDesktop.width()+ options.desktopMargin,
- dates = 1000 + timeCha;
- if (dxCha < -150 && deskIndex < desktop.size() - 1) {
- _self.desktopMove(dates, moveDx, deskIndex + 1);
- } else if (dxCha > 150 && deskIndex > 0) {
- _self.desktopMove(dates, moveDx, deskIndex - 1);
- } else {
- $(this).animate({
- left : -(deskIndex) * moveDx
- }, 500);
- }
- };
- this.bind("touchstart", start);
- this.bind("touchmove", move);
- this.bind("touchend", stop);
- };
- desktopInner.draggable();
- }else{
- desktopInner.draggable({
- axis : 'x',
- start : function(event, ui) {
- $(this).css("cursor", "move");
- timeStart = new Date().getTime();
- dxStart = event.pageX;
- },
- drag :function(event, ui){
- var wt = $(window).width()-80;
- var dx = event.pageX;
- if(dx>wt){
- return false;
- }
- },
- stop : function(event, ui) {
- $(this).css("cursor", "inherit");
- timeEnd = new Date().getTime();
- desktop = $("div.desktop");
- dxEnd = event.pageX;
- var timeCha = (timeEnd - timeStart) > 2 ? 2: (timeEnd - timeStart),
- dxCha = dxEnd - dxStart,
- currDesktop = $(this).find("div.currDesktop"),
- deskIndex = desktop.index(currDesktop),
- moveDx = currDesktop.width()+ options.desktopMargin,
- dates = 1000 + timeCha;
- if (dxCha < -150 && deskIndex < desktop.size() - 1) {
- _self.desktopMove(dates, moveDx, deskIndex + 1);
- } else if (dxCha > 150 && deskIndex > 0) {
- _self.desktopMove(dates, moveDx, deskIndex - 1);
- } else {
- $(this).animate({
- left : -(deskIndex) * moveDx
- }, 500);
- }
- }
- });
- }
- },
- desktopMove : function(dates, moveDx, nextIndex) {
- var desktopInner = $("#desktopInner"), desktop = desktopInner
- .find("div.desktop");
- desktopInner.stop().animate(
- {
- left : -nextIndex * moveDx
- },
- dates,
- function() {
- desktop.removeClass("currDesktop").eq(nextIndex).addClass(
- "currDesktop");
- var deskId = $(desktop).eq(nextIndex).attr("id");
- if(!deskId)return;
- var currentId = deskId.split("_");
- $(".pageCount img").attr("src","/shares/images/master1/ce_white.png");
- $("#pc_"+currentId[1]).find("img").attr("src","/shares/images/master1/ce_blue.png");
- });
- },
- initDesktop:function(){
- win8Desktop.desktop.desktopMove(1000,0,0);
- },
- changeDesktop:function(options,e){
- $(".pageCount img").attr("src","/shares/images/master1/ce_white.png");
- $("img",e).attr("src","/shares/images/master1/ce_blue.png");
- var clickDesk = $(e).attr("id");
- var clickId = clickDesk.split("_");
- var i = clickId[1];
- var currDesktop = $("div.currDesktop");
- var moveDx = currDesktop.width()+ options.desktopMargin;
- var nextIndex = i-1;
- var desktopInner = $("#desktopInner"), desktop = desktopInner
- .find("div.desktop");
- desktopInner.stop().animate(
- {
- left : -nextIndex * moveDx
- },
- 1000,
- function() {
- desktop.removeClass("currDesktop").eq(nextIndex).addClass(
- "currDesktop");
- });
- },
- iconBehavior : function(o) {
- var type = loadBrowserType();
- if("win"==type){
- o.hover(function() {
- $(this).append("<div class='hover'></div>");
- }, function() {
- $(this).find("div.hover").remove();
- }).on(
- "click",
- function() {
- var winData = $(this).data("winAttrData");
- var url = winData.url;
- var str = "?";
- if(url.indexOf("?")){
- str = "&";
- }
- url = url+str+"t="+new Date().getTime();
- win8Desktop.myWindow.init({
- windowTitle : winData.title,
- windowsId : winData.id+"_"+new Date().getTime(),
- // windowsId : winData.id,
- iframSrc : url,
- windowResizable:false
- });
- // if (!$("#taskTab_" + winData.id).size()) {
- // win8Desktop.taskBar.addTask(winData.id, winData.title,
- // winData.iconUrl);
- // }
- });
- }else{
- o.on("click",
- function() {
- var winData = $(this).data("winAttrData");
- var url = winData.url;
- var str = "?";
- if(url.indexOf("?")){
- str = "&";
- }
- url = url+str+"t="+new Date().getTime();
- win8Desktop.myWindow.init({
- windowTitle : winData.title,
- windowsId : winData.id+"_"+new Date().getTime(),
- iframSrc : url,
- windowResizable:false
- });
- });
- }
- },
- iconSort : function() {
- var desktopWrap = $("#desktopWrap"), desktopInner = $("#desktopInner"), desktop = $("div.desktop"),
- header = $("#header"),
- ww = $(window).width(),
- wh = $(window).height();
- var dh = wh * 0.6, opt = $("body").data("desktopCofig");
- dh = wh - (wh * 0.4 / 2)-155;
- var maxRows = Math.round(dh / (107 + opt.iconMargin)), dinnerWidth = 0;
- desktopWrap.css({
- "height" : dh,
- "top" : wh * 0.4 / 2
- });
- header.css("left", opt.desktopMargin);
- desktop.find("div.desktopIcon").css({
- "margin-left" : opt.iconMargin,
- "margin-top" : opt.iconMargin
- });
- desktop.eq(0).addClass("currDesktop");
- desktop.each(function() {
- var desktopIcon = $(this).find("div.desktopIcon"),
- iconNum = $(this).find(".minStyle").size()+ $(this).find(".bigStyle").size() * 2,
- tw = ww-(108 + opt.iconMargin);//Math.ceil(iconNum/maxRows)* (118 + opt.iconMargin);
- $(this).css({
- "width" : tw,
- "height" : dh,
- "margin-left" : opt.desktopMargin
- });
- dinnerWidth += tw + opt.desktopMargin;
- var bigIcon = $(this).find(".bigStyle").find(".iconText");
- var textHeight = bigIcon.height();
- bigIcon.css("padding-top", (107 - textHeight) / 2);
- });
- desktopInner.width(dinnerWidth);
- },
- desktopIconInit : function(data) {
- var opt = $("body").data("desktopCofig");
- $("#pageCount").empty();
- var ww = $(window).width();
- var deskWidth = ww-(108 + opt.iconMargin);
- var totleWidth = 0;
- var wh = $(window).height();
- var dh = wh * 0.6;
- dh = wh - (wh * 0.4 / 2)-155;
- var row = (Math.floor(dh/108));
- if(!row){
- $("#desktopInner").html("");
- return;
- }
- var j = 1;
- var d = 1;
- var html = "";
- var last = 0;
- for ( var a in data) {
- var arr = data[a];
- if(!arr){
- break;
- }
- for ( var i = 0; i < arr.length; i++) {
- var type = arr[i].iconType;
- if("bigStyle" == type){
- totleWidth += 230;
- last = 230;
- }else{
- totleWidth += 115;
- last = 115;
- }
- if(totleWidth>deskWidth){
- totleWidth = last;
- j++;
- }
- if(j > row){
- d++;
- html += "</div>";
- if(i!=arr.length){
- $("div#pc_1").show();
- $("#pageCount").append("<div class='pageCount' id='pc_"+d+"'></div>");
- $("div#pc_"+d).bind("click",function(){
- win8Desktop.desktop.changeDesktop(opt,this);
- }).html("<img src='/shares/images/master1/ce_white.png' />");
- html += "<div class='desktop' id='desktop_" + d + "'>";
- }
- j = 1;
- }
- if(i==0){
- $("#pageCount").append("<div class='pageCount currentPage' id='pc_"+d+"'></div>");
- $("div#pc_"+d).bind("click",function(){
- win8Desktop.desktop.changeDesktop(opt,this);
- }).html("<img src='/shares/images/master1/ce_blue.png' />").hide();
- html += "<div class='desktop' id='desktop_" + d + "'>";
- }
- html += "<div class='desktopIcon " + arr[i].iconType + "' id='"
- + arr[i].id + "' style='background-color:"
- + arr[i].bgColor + "'>";
- if (win8Desktop.trim(arr[i].iconUrl).length) {
- html += "<div class='iconImg'><img src='" + arr[i].iconUrl
- + "' title='" + arr[i].title
- + "'/></div><div class='iconText'>" + arr[i].title
- + "</div>";
- } else {
- html += "<div class='iconText_noIcon'>" + arr[i].title
- + "</div>";
- }
- var extHtml = arr[i].extHtml;
- if(extHtml){
- html += extHtml;
- }
- html += "</div>";
- }
- //html += "<div class='desktopIcon addIcon minStyle'><a class='iconImg'></a><div class='iconText'>添加应用</div></div>";
- html += "</div>";
- }
- $("#desktopInner").html(html);
- $("#desktopInner").css({"index":1});
- for ( var a in data) {
- var arr = data[a];
- if(!arr){
- break;
- }
- for ( var i = 0; i < arr.length; i++) {
- $("#" + arr[i].id).data("winAttrData", arr[i]);
- }
- }
- }
- };
- win8Desktop.taskMap = new map();
- win8Desktop.taskBar = {
- init : function() {
- this.taskData();
- var taskBarData = $("body").data("taskBar"), taskNextBox = taskBarData.taskNextBox, taskPreBox = taskBarData.taskPreBox, ww = taskBarData.ww, taskInnnerBlock = taskBarData.taskInnnerBlock, taskOuterBlock = taskBarData.taskOuterBlock, ow = ww
- - taskNextBox.outerWidth(true) * 2, _self = this;
- taskOuterBlock.width(ow);
- $(window).wresize(
- function() {
- taskOuterBlock.width($(window).width()
- - taskNextBox.outerWidth(true) * 2);
- });
- function taskMove(a) {
- taskInnnerBlock.animate({
- "margin-right" : '+=' + a
- }, 1000);
- }
- taskNextBox
- .on(
- "click",
- function() {
- var mr = taskInnnerBlock.css("margin-right"), mr = parseInt(mr), taskTabWidth = $(
- "body").data("tabWidth");
- if (Math.abs(mr) > taskTabWidth) {
- taskMove(taskTabWidth);
- } else {
- taskMove(Math.abs(mr));
- }
- });
- taskPreBox
- .on("click",
- function() {
- var ml = taskInnnerBlock.position(), ml = Math
- .abs(ml.left), taskTabWidth = $("body")
- .data("tabWidth");
- if (ml > taskTabWidth) {
- taskMove(taskTabWidth * -1);
- } else {
- taskMove(ml * -1);
- }
- });
- },
- taskData : function() {
- $("body").data("taskBar", {
- taskBlock : $("#taskBlock"),
- taskInnnerBlock : $("#taskInnnerBlock"),
- taskOuterBlock : $("#taskOuterBlock"),
- taskNextBox : $("#taskNextBox"),
- taskPreBox : $("#taskPreBox"),
- ww : $(window).width(),
- wh : $(window).height()
- });
- },
- upTaskTab : function(id) {
- var str = id.split("_").slice(1);
- $("div.taskTab").removeClass("taskCurrent");
- $("#taskTab_" + str).parent().addClass("taskCurrent");
- },
- removeTaskTab : function(id) {
- var str = id.replace("win_",""),
- taskBarData = $("body").data("taskBar"), taskTabWidth = $("body").data("tabWidth");
- $("#taskTab_" + str).remove();
- var taskTabNum = $("div.taskTab").size(), maxTabNum = $("body").data(
- "maxTabNum");
- taskBarData.taskInnnerBlock.width(taskTabNum * taskTabWidth);
- if (taskTabNum <= maxTabNum) {
- taskBarData.taskNextBox.hide();
- taskBarData.taskPreBox.hide();
- }
- },
- removeTaskMap:function(key){
- key = win8Desktop.trim(key);
- var taskMap = win8Desktop.taskMap;
- var tempTaskMap = new map();
- for (var i = 0; i < taskMap.arr.length; i++) {
- if (taskMap.arr[i].key !== key){
- tempTaskMap.put(taskMap.arr[i].key, taskMap.arr[i].value);
- }
- }
- win8Desktop.taskMap = tempTaskMap;
- win8Desktop.taskBar.taskCount();
- },
- removeCurrentTask:function(id){
- var winId = "win_"+id;
- winId = win8Desktop.trim(winId);
- win8Desktop.taskBar.removeTaskTab(winId);
- win8Desktop.taskBar.removeTaskMap(id);
- },
- removeAllTask:function(id){
- $(".taskTab").remove();
- win8Desktop.taskMap = new map();
- win8Desktop.taskBar.taskCount();
- },
- removeFirstTask:function(){
- var key = win8Desktop.taskMap.arr[0].key;
- var winId = "win_"+key;
- win8Desktop.taskBar.removeTaskTab(winId);
- win8Desktop.taskBar.removeTaskMap(key);
- win8Desktop.taskBar.taskCount();
- },
- addNewTask:function(id, text, icon,bgColor){
- var taks = {"id":id,"title":text,"iconUrl":icon,"bgColor":bgColor};
- win8Desktop.taskMap.put(id,taks);
- win8Desktop.taskBar.taskCount();
- },
- taskCount:function(){
- var taskLen = win8Desktop.taskMap.arr.length;
- if(taskLen==0){
- $(".task_count").hide();
- }else{
- $(".task_count").show();
- $(".task_count").html(taskLen);
- }
- },
- openDialog:function(id){
- var win = $("#win_" + id),
- des = $("#" + id).parents("div.desktop"),
- left = win.data("oldLeft");
- if (win.hasClass("hideWin")) {
- win.css("left", left).removeClass("hideWin");
- }
- win.data('windowStatus',"");
- win.trigger("mousedown");
- $("#taskBlock").hide();
- },
- showTask:function(){
- var map = win8Desktop.taskMap;
- var taskInnnerBlock = $("#desktopInner");
- $(taskInnnerBlock).addClass("taskDesktop");
- $(taskInnnerBlock).empty();
- var data = new Array();
- var desk = new Array();
- for(var i=0,j=map.arr.length;i<map.arr.length;i++,j--){
- data[i] = map.arr[j-1].value;
- data[i]["iconType"] = "minStyle";
- }
- desk[0] = data;
- var html = win8Desktop.taskBar.getTaskHtml(desk);
- $(taskInnnerBlock).append(html);
- win8Desktop.desktop.iconSort();
- win8Desktop.desktop.initDesktop();
- win8Desktop.taskBar.bindEventTask();
- var type = loadBrowserType();
- if("win"==type){
- $("#taskTab_clear").hover(function(){
- $(this).append("<div class='hover'></div>");
- }, function() {
- $(this).find("div.hover").remove();
- }).bind("click",function(){
- win8Desktop.taskBar.removeAllTask();
- $("#task_task").click();
- });
- }else{
- $("#taskTab_clear").bind("click",function(){
- win8Desktop.taskBar.removeAllTask();
- $("#task_task").click();
- });
- }
- },
- getTaskHtml :function(data){
- var opt = $("body").data("desktopCofig");
- $("#pageCount").empty();
- var ww = $(window).width();
- var deskWidth = ww-(108 + opt.iconMargin);
- var totleWidth = 0;
- var wh = $(window).height();
- var dh = wh * 0.6;
- dh = wh - (wh * 0.4 / 2)-155;
- var row = (Math.floor(dh/108));
- if(!row){
- $("#desktopInner").html("");
- return;
- }
- var j = 1;
- var d = 1;
- var html = "";
- var last = 0;
- var arr = data[0];
- for ( var i = 0; i < arr.length; i++) {
- var type = arr[i].iconType;
- if("bigStyle" == type){
- totleWidth += 230;
- last = 230;
- }else{
- totleWidth += 115;
- last = 115;
- }
- if(totleWidth>deskWidth){
- totleWidth = last;
- j++;
- }
- if(j > row){
- d++;
- html += "</div>";
- if(i!=arr.length){
- $("div#pc_1").show();
- $("#pageCount").append("<div class='pageCount' id='pc_"+d+"'></div>");
- $("div#pc_"+d).bind("click",function(){
- win8Desktop.desktop.changeDesktop(opt,this);
- }).html("<img src='/shares/images/master1/ce_white.png' />");
- html += "<div class='desktop' id='desktop_" + d + "'>";
- }
- j = 1;
- }
- if(i==0){
- $("#pageCount").append("<div class='pageCount currentPage' id='pc_"+d+"'></div>");
- $("div#pc_"+d).bind("click",function(){
- win8Desktop.desktop.changeDesktop(opt,this);
- }).html("<img src='/shares/images/master1/ce_blue.png' />").hide();
- html += "<div class='desktop currDesktop' id='desktop_" + d + "'>";
- }
- var taskTabHtml = '<div class="desktopIcon minStyle taskTab" id="taskTab_'+arr[i].id+'" style="margin-top: 7px; margin-left: 7px;background:'+arr[i].bgColor+'">';
- taskTabHtml += '<div class="task_remove" style="position:absolute;width:100px;display:none;color:red;z-index:999">';
- taskTabHtml += '<div class="task_remove_img" style=";width:12px;height:12px;float:right;margin-top:3px;" id="task_remove_'+arr[i].id+' ">';
- taskTabHtml += ' <span>';
- taskTabHtml += ' <img src="/shares/images/master1/app/icon_minus.png" />';
- taskTabHtml += ' </span>';
- taskTabHtml += '</div>';
- taskTabHtml += '</div>';
- taskTabHtml += '<div class="iconImg">';
- taskTabHtml += ' <img title="'+arr[i].title+'" src="'+arr[i].iconUrl+'">';
- taskTabHtml += '</div><div class="iconText">'+arr[i].title+'</div>';
- taskTabHtml += '</div>';
- html = html + taskTabHtml;
- }
- if(arr.length==0){
- html += "<div class='desktop currDesktop' id='desktop_" + d + "'>";
- }
- var clearTabHtml = '<div class="desktopIcon minStyle" id="taskTab_clear" style="margin-top: 7px; margin-left: 7px">';
- clearTabHtml += '<div id="task_remove_clear" class="task_remove" style="position:absolute;display:none;float:right;width:12px;height:12px;border:1px solid #ccc;color:red;z-index:999">-</div>';
- clearTabHtml += '<div class="iconImg">';
- clearTabHtml += ' <img title="清空" src="/shares/images/master1/icon/clear.png">';
- clearTabHtml += '</div><div class="iconText">清空</div>';
- clearTabHtml += '</div>';
- html = html + clearTabHtml;
- html += "</div>";
- return html;
- },
- bindEventTask : function() {
- var taskBarData = $("body").data("taskBar"),
- taskNextBox = taskBarData.taskNextBox,
- taskPreBox = taskBarData.taskPreBox,
- ww = taskBarData.ww;
- $("div.taskTab").removeClass("taskCurrent");
- $("div.task_remove_img").each(function(){
- $(this).bind("click",function(){
- var removeId = this.id;
- var tid = removeId.replace("task_remove_","");
- win8Desktop.taskBar.removeCurrentTask(tid);
- win8Desktop.taskBar.showTask();
- });
- });
- var taskTab = $("div.taskTab"),
- tabNum = taskTab.size(),
- tabWidth = taskTab.width();
- maxTabNum = Math.floor((ww - taskNextBox.outerWidth() * 2) / tabWidth);
- var type = loadBrowserType();
- if("win"==type){
- $(taskTab).hover(function(){
- $(this).append("<div class='hover'></div>");
- $(".task_remove",this).show();
- }, function() {
- $(".task_remove",this).hide();
- $(this).find("div.hover").remove();
- });
- }
- $("body").data({
- "tabWidth" : tabWidth,
- "maxTabNum" : maxTabNum
- });
- $(".taskTab").on("click",
- function() {
- var taskId = $(this).attr("id");
- var id = taskId.replace("taskTab_","");
- var win = $("#win_" + id);
- win8Desktop.myWindow.mask($(win));
- win8Desktop.taskBar.openDialog(id);
- });
- if (tabNum > maxTabNum) {
- taskNextBox.show();
- taskPreBox.show();
- }
- }
- };
|