<!doctype html>
<html>
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="renderer" content="webkit"> 
  <title>编辑html元素</title>
  <link type="text/css" rel="Stylesheet" href="/admin/drag/css/drag.base.css">
  <link type="text/css" rel="Stylesheet" href="/admin/drag/css/kesion.form.css">
  <link type="text/css" rel="Stylesheet" href="/admin/drag/css/label.css">
 
</head>
<body style="overflow:hidden;">
   
   	
    <div class="ks-tab">
    	<ul>
        	<li class="active"><span>新增标签</span></li>
        	<li onClick="selectLabel()"><span>选择现有标签</span></li>
        </ul>
    </div>
   	
    <div id="Content">
    	<div class="tab-box iframe-box">
    		           
        </div>
        <div class="tab-box d-none">
        	<div class="label-box" style="overflow:hidden; overflow-y:auto;">
                <div class="label-sc-box"><input name="" type="text" class="ks-text" id="labelSearch" placeholder="快速搜索标签" ></div>
                <ul>
                    <li class="li-head"><span>更新时间</span>标签名称</li>
                </ul>
            </div>
            
            <div class="ks-btn-center" style="border-top:1px solid #ebebeb; padding:20px 0;">
              <button class="ks-btn ks-btn-normal" onClick="Save()" id="btn-save">确定</button>
              &nbsp;
              <button class="ks-btn" onClick="parent.closeWindow(window.name)">取消</button>
            
            </div>
           
        </div>
	</div>
    
    <script src="/admin/drag/js/utils.js"></script>
    <script>utils.loadJs(['jquery','nicescroll'])</script>
   
	<script>
		
		var locationDataReg = location.href.match(/\w+=[^?&]+/g);
		var locationData = {};
		for(var i=0;i<locationDataReg.length;i++){
			var locationDataNodeName = locationDataReg[i].split('=')[0];
			var locationDataNodeValue = locationDataReg[i].split('=')[1];
			locationData[locationDataNodeName] = locationDataNodeValue
		}

		var labelStr = locationData.labeltype;
		var skinId = locationData.templateId;
		var labelUrl = locationData.labelUrl;
		
		$('.iframe-box').append('<iframe name="label" id="labelIframe" src="'+labelUrl+'?from=drag"></iframe>');
		
		$('#labelIframe').load(function(){
			$('.iframe-box').css({background:'none'});
			$(this).contents().find('.content-area').css({border:'0',padding:'0'})
		});
		
   		$(function(){			
			tabHeight();			
			
		});
		$(window).resize(function(){
			tabHeight();
		});
		
		function tabHeight(){
			var tabHeight = $(window).height()-$('.ks-tab').outerHeight();
			var boxHeight = tabHeight - 79;
			$('.iframe-box').height(tabHeight);
			
			$('.label-box').height(boxHeight);
			
			
		};
		$('.label-box').on('click','li:not(".li-head")',function(){
			$(this).addClass('active').siblings().removeClass('active');
			
		});
		
		$('.ks-tab').on('click','li',function(){
			$(this).addClass('active').siblings().removeClass('active');
			$('.tab-box').eq($(this).index()).fadeIn(300).siblings('.tab-box').hide();	
		});
		
		$('#labelSearch').keyup(function(){
			var key = $(this).val();
			$.ajax({
					url:"/plus/ajaxlabel.aspx?action=labellist&labelflag="+labelStr+"&skinid="+skinId+"&key="+key,
					success:function(data){
						$('.label-box').find('li:not(".li-head"),.empty').remove();
						if(data==''){
							$('.label-box').find('ul').append('<p class="empty">没有找到标签数据</p>');
						}else{
							$('.label-box').find('ul').append(data);
						};
					}
			});
		});
		
		//现有标签请求
		var labelFlag = true;
		function selectLabel(){
			$.ajax({
					url:"/plus/ajaxlabel.aspx?action=labellist&labelflag="+labelStr+"&skinid="+skinId,
					success:function(data){
						if(labelFlag === true){
							$('.label-box').find('ul').append(data);
							if(data==''){
								$('.label-box').find('ul').append('<p class="empty">没有找到标签数据</p>');
							};
							labelFlag = false;
							
						};
					}
			});
					
		};
		
		function Save(){
			var labelName = $('.label-box').find('.active').attr('data-value');
			if(!labelName){
				parent.popup.tips({
					title:'请先选择标签'
				})
			}else{
				parent.LabelBack(labelName,window.name);
			};
		};
		
		function LabelBack(labelName,windowName,labelType){
			parent.LabelBack(labelName,window.name,labelType);
		};
		function closeWindow(){
			parent.closeWindow(window.name);
		};
		
		

    </script>


</body>
</html>