$(function(){
var a,
one,
two,
three,
four,
oneh,
onet;
/*$(document).on("touchmove","nav_expand",function(event){
event.preventDefault();
event.stopPropagation();
});*/
$(document).on("touchend",".navmore",function(){
var h = $(window).height(),
navt = $(".nav_expand").css("top"),
navn = navt.substring(0,2),
navh = $(".nav_expand .nav_expand_head").height(),
bnavh = $(".tabs-bottom .tab-nav").outerHeight(true);
$(".nav_expand").slideDown()
$(".nav_expand .nav_expand_body").css({"height":h - navn- navh - bnavh});
openSelectPage=true;
$nav_expand_no();
});
$(document).on("touchend",".nav_expand .ico_nav_return,.nav_expand .nav_expand_head > h1",function(){
nav_return()
});
$(document).on("touchend",".nav_expand .sort_delete",function(){
var has = $(this).hasClass("active");
if(has == true){
$(this).removeClass("active").html("排序删除");
$(".nav_column").removeClass("active");
$(".nav_column ul").removeClass("sortable");
$(".nav_column li .close_delete").hide();
$(".nav_add").show();
$add_Unfinished("complete");
$(".nav_column ul li").removeAttr("style");
$ui_sortable();
$(".sortable ul").sortable("destroy");
$nav_expand_no();
/*var sl = $("#sliderSegmentedControl .mui-scroll a").length;
$("#sliderSegmentedControl .mui-scroll a").each(function(){
var h = $(this).text(),
i = $(this).index();
if(h == "" && i != sl-1){
$(this).remove();
}
})*/
}else{
$(".nav_add").show();
$(this).addClass("active").html("完成");
$(".nav_column").addClass("active sortable");
$.getScript("trsTop/js/jquery-ui.js");
$.getScript("trsTop/js/jquery-ui-mobile.js",function(){
//var items = $(".sortable ul").sortable("option", "items");
//$(".sortable ul").sortable("option", "items", "> li");
$(".sortable ul").sortable({items: "> li.port"});
$(".sortable ul").disableSelection();
});
$.getScript("trsTop/images/mui.min.js");
$(".nav_column li .close_delete").show();
$(".nav_add").hide();
}
});
$(document).on("touchend",".mui-scroll iframe",function(){
console.log(2)
});
$(document).on("mouseup",".nav_add li",function(event){
//event.preventDefault();
//event.stopPropagation();
var text = $(this).text(),
num = parseInt(Math.random()*(1000-10+1)+10,10),
leng = $("#sliderSegmentedControl .mui-scroll a").length,
url = $(this).find("h1").attr("data-active-url");
text = text.substr(1,100);
$(this).remove();
$add_info(text,num,leng,url);
$nav_expand_no();
});
$(document).on("touchend",".nav_column li .close_delete",function(){
var text = $(this).parent().find("h1").text(),
url = $(this).parent().find("h1").attr("data-active-url");
mui.fire(plus.webview.currentWebview(),'alte',{id:url});
$(this).parent().hide();
$(".nav_add ul").prepend("
+"+text+"
");
$("#sliderSegmentedControl .mui-scroll a").each(function(){
var t = $(this).text();
if(t == text){
var i = $(this).index();
$(this).addClass("Unfinished");
$(".mui-slider-group .mui-slider-item").eq(i).addClass("Unfinished");
}
});
});
/* setInterval(function(){
$("#mainFarm1").contents().find("head").append('');
},300)*/
});
function $ui_sortable(){
$(".ui-sortable li").each(function(){
var t = $(this).find("h1").text();
//console.log(t);
$("#sliderSegmentedControl .mui-scroll a").each(function(){
var uit = $(this).text(),
href = $(this).attr("href"),
index = $(this).index(),
has = $(this).hasClass("mui-active");
//读取配置表
var curl = dicContainer['sy_tab'].toValue(uit);
//console.log(uit);
if(t == uit && has == true){
$("#sliderSegmentedControl .mui-scroll").append("" + uit + "");
$(this).remove();
}
if(t == uit && has != true){
$("#sliderSegmentedControl .mui-scroll").append("" + uit + "");
$(this).remove();
}
$(".mui-slider-group .mui-slider-item").each(function(){
var ut = $(this).attr("id"),
uh = $(this).html(),
has = $(this).hasClass("mui-active");
if(ut == uit && has == true){
$(".mui-slider-group").append("" + uh + "
");
$(this).remove();
}
if(ut == uit && has != true){
$(".mui-slider-group").append("" + uh + "
");
$(this).remove();
}
});
});
});
var l = $("#sliderSegmentedControl .mui-scroll a").length;
$("#sliderSegmentedControl .mui-scroll a").each(function(){
var uit = $(this).attr("data-active-id");
if(uit == "占位"){
console.log(uit)
$(this).remove();
$("#sliderSegmentedControl .mui-scroll a").eq(l-2).after(" ");
}
});
}
function $add_Unfinished(b){
$(".nav_add ul li").each(function(){
var has = $(this).hasClass("Unfinished");
if(has == true && b == "return"){
$(this).remove();
}
if(has == true && b == "complete"){
$(this).removeClass("Unfinished");
}
});
$("#sliderSegmentedControl .mui-scroll a").each(function(){
var has = $(this).hasClass("Unfinished");
if(has == true && b == "return"){
$(this).removeClass("Unfinished");
console.log(1)
}
if(has == true && b == "complete"){
$(this).remove();
console.log(2)
}
});
$(".mui-slider-group .mui-slider-item").each(function(){
var has = $(this).hasClass("Unfinished"),
$mg = $("#slider .mui-slider-group");
if(has == true && b == "return"){
$(this).removeClass("Unfinished");
console.log(1)
}
if(has == true && b == "complete"){
$(this).remove();
var i = $(this).hasClass("mui-active")
if(i == true){
$("#sliderSegmentedControl a").removeClass("mui-active").eq(0).addClass("mui-active");
$mg.css({"transform":"translate3d(0px,0,0) translateZ(0px)"});
}
}
});
$(".nav_column ul li").each(function(){
var vis = $(this).is(":visible");
// console.log(vis)
if(vis == false && b == "complete"){
$(this).remove();
}
});
}
function $add_info(a,b,c,d){
var itemStr = getItemStr();
re = new RegExp('"', "g");
var tempArr = itemStr.replace(re,'').split(",");
var inArrIndex = $.inArray(d, tempArr);
if(inArrIndex<0){
tempArr.push(d);
//alert(tempArr);
localStorage.setItem("initItem",tempArr);
}
var height_jquery = $("#mainFarm1").height();
//$(".nav_column ul").append("x"+a+"
");
$(".nav_column ul").append("x");
var sl = $(".nav_column ul li").length;
$(".nav_column ul li").eq(sl-1).find("h1").html(a);
//$("#sliderSegmentedControl .mui-scroll a").eq(c - 2).after(""+a+"");
$("#sliderSegmentedControl .mui-scroll a").eq(c - 2).after("");
$("#sliderSegmentedControl .mui-scroll a").eq(c - 1).html(a);
/*$("#sliderSegmentedControl .mui-scroll a").each(function(){
var h = $(this).text(),
i = $(this).index();
if(h == "" && i != sl-1){
$(this).remove();
}
})*/
$(".mui-slider-group").append("");
}
function nav_return(){
//隐藏webview
mui.fire(plus.webview.currentWebview(),'openWvg');
$(".nav_expand").slideUp();
$(".nav_expand .sort_delete").removeClass("active").html("排序删除");
$(".nav_column").removeClass("active");
$(".nav_column li .close_delete").hide();
$(".nav_add").show();
$(".nav_column ul li").removeAttr("style");
$add_Unfinished("return");
}
function $nav_expand_no(){
//显示webview
mui.fire(plus.webview.currentWebview(),'closeWvg');
// mui.fire(plus.webview.currentWebview(),'alte',{id:'l'});
var l = $(".nav_add ul li").length;
if(l > 0){
$(".nav_add > h1").html("点击添加更多栏目");
}else{
$(".nav_add > h1").html("无更多栏目");
}
}