1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
| <link rel="stylesheet" href="/css/right_click_style.css"> <script src='https://s1.pstatp.com/cdn/expire-1-M/jquery/1.10.2/jquery.min.js'></script>
<script> (function(){var that;var arr=new Array();var html="";!function(e){e.RMenu={init:function(per){if(typeof(per)!="object"&&!per.hasOwnProperty('area')&&!per.hasOwnProperty('items')&&!per.hasOwnProperty('callback'))throw"json 数据错误";that=this;this.showmenu(per);var areaHeight=$(per.area).height();var areaWidth=$(per.area).width();var menuHeight=$('.RCM-Main').height();var menuWidth=$('.RCM-Main').width();$(per.area).bind('contextmenu',function(event){
if (event.ctrlKey) { console.log("test"); return true; } else { var xPos=parseInt(event.pageX+10);var yPos=event.pageY;if(areaWidth-xPos<menuWidth){xPos=(xPos-menuWidth-20);$('.RCM-container').css({left:(xPos-menuWidth-20)+"px",top:yPos+"px"}).show(); } } if(areaHeight-yPos<menuHeight){yPos=(yPos-menuHeight-20);} $('.RCM-Main').css({left:xPos+"px",top:yPos+"px"}).show();return false;}) $(per.area).on('click',function(){$('.RCM-container').hide();});$('.RCM-container li').on('click',function(){var content=$(this).data('content');$('.RCM-container').hide();per.callback({event:'click',data:content});});$('.RCM-container ul li,.RCM-child li').mouseover(function(e){if($(this).find('i').hasClass('fa-align-right')){var width=$(this).find('i').next('.RCM-child').width();$(this).find('i').next('.RCM-child').css('left',width).show();}});$('.RCM-container ul li,.RCM-child li').mouseout(function(){$('.RCM-child').hide();});},contextMenu:function(per,key){var key=key?key:"Main";html+='<div class="RCM-container RCM-'+key+'"><ul>';$.each(per.items,function(item,val){var icon=val.icon?'<i class="fa fa-'+val.icon+' fa-fw "> ':'' var center=val.icon?'nocenter':'textcenter';var iconAfter=val.items?'<i class="fa fa-chevron-right fa-fw fa-align-right"> ':'';html+='<li data-content='+item+' class="'+center+'">'+icon+'</i>'+val.name+iconAfter+'</i>';if(val.hasOwnProperty('items')){that.contextMenu(val,'child');} html+='</li>';});html+="</ul></div>";return html;},showmenu:function(per){var ce=this.contextMenu(per);$(per.area).append(ce);$('.RCM-container').hide();}};}(window)})();
</script>
<script> $(document).ready(function(){ var rcm = window.RMenu; rcm.init({ area:'body', items:{ "edit":{name:"编辑",icon:'edit'}, "del":{name:"删除",icon:'trash-o'}, "add":{name:"添加",icon:'plus',items:{ "new-text":{name:"添加文件",icon:'file-text'}, "new-zip":{name:"添加ZIP",icon:'file-zip-o'} }}, "refresh":{name:"刷新",icon:'refresh'}, "down":{name:"下载按钮",icon:'cloud-download'}, "new":{name:"新建",icon:'file',items:{ "new-text":{name:"新建文件",icon:'file-text'}, "new-zip":{name:"新建ZIP",icon:'file-zip-o'} }} }, callback:function(res){ if(res.data == 'edit'){ console.log('点击了edit'); }else if(res.data == 'del'){ console.log('点击了del'); }else if(res.data == 'add'){ console.log('点击了add'); }else if(res.data == 'refresh'){ window.location.reload(); }else if(res.data == 'down'){ console.log('点击了download'); } } }) }); </script>
|