1. 程式人生 > >ArtDialog簡單使用示例

ArtDialog簡單使用示例

像dojo一樣,artdialog也是在網上無意間搜出來的,可惜後來發現它和dojo衝突(最後都是用的dojo的dialog),沒辦法只有忍痛割愛了。今天花了些時間把http://code.google.com/p/artdialog/downloads/list上的demo整理了一下,把demo.js裡的程式碼都抽出來加到jsp程式碼中了,這樣更直觀。程式碼如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>art</title>
    <link id="artDialogSkin" href="skins/default.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="artDialog.js"></script>
<script type="text/javascript" src="artDialog.iframeTools.js"></script> <!-- 對iframe的新工具 -->

</head>
<body >
<script type="text/javascript">
    function a(){    
               art.dialog({content:'hello world!歷史'})
              }
    function b(){ 
       art.dialog(
        {
            content:'歡迎你來到對話方塊世界!',
            lock:true,
            style:'succeed noClose'
        },
        function(){
            alert('你點了確定'); //不管點了確定還是取消預設都會關閉artdialog,除非在這裡面返回false
        },
        function(){
            alert('你點了取消');
        }
                 );
               }
    function c(){
    art.dialog(
    {
    title:'圖片檢視',
    fixed:true,
      content:'<img width="817" height="479" src="butterfly.jpg" />'
                 });
    //return false;
   };
    function d(){
   // art.dialog({title:'dialog內嵌iframe', iframe:'http://www.baidu.com', width:'900', height:'500'});

   //已經沒有了直接的iframe屬性  通過下面的方式內嵌iframe  第二種效果不佳
   art.dialog.open("http://www.baidu.com", {width: 320, height: 400});
   // art.dialog({title:'dialog內嵌iframe', width:'900px',height:'500px', content:"<iframe align='right' src='http://www.baidu.com' width:'100%' height:'100%' />"});
    return false;
   };
    function e(){
    art.dialog(
    {
    title:'動畫',
    fixed:true,
      content:'<embed src="ddd.rm" type="audio/x-pn-realaudio-plugin" autostart="true" width="420" height="363"></embed>'
                 });
  
   }; //播放avi總是隻有聲音,沒有畫面,哎!
function f(){
    art.dialog({content:'你人品穩定麼?', fixed:true, yesText:'我很穩定', style:'confirm', id:'bnt4_test'},
    function(){
           art.dialog({id:'bnt4_test'}).content('你騙人!');
          return false;//這樣對話方塊才不會關閉
        },
     function(){alert('你是壞人');}//按右上角的叉關閉對話方塊也會執行這個函式
     );
   };
   function g(){
    art.dialog({mouse:true, id:'dg_test34243', content:'您收到 <strong>2</strong> 條訊息',left:'right',width:'15em', top:'bottom', fixed:true});
   };
   function h(){
    art.dialog({id:'dg_test34243'}).close();
   };
   function i(){
          var _this = document.getElementById('btn7');
          if (document.getElementById('menu_4834783')) {//如果已經打開了對話方塊,按這個按鈕還能把它關閉
                                                        art.dialog({id:'menu_4834783'}).close();
                                                        _this.innerHTML = '彈出選單'; //button上顯示的內容
                                                        return;
                                                       };
    art.dialog({id:'menu_4834783', title:'選單', content:'請輸入:<input style="width:200px;" id="M_dfd" type="text" value="hello world!" />',
               button:[{name:'確定',callback:function(){ 
                                                      var a=document.getElementById('M_dfd').value;
                                                      art.dialog({content:a, lock:true, time:1});
                                                     }
                        },
                       {name:'關閉我',callback:function(){_this.innerHTML = '彈出選單';}}
                       ]
              }
              ); 
    _this.innerHTML = '關閉選單';
    return false;
    };                     
    </script>
<input type="button" style="width: 100px" onClick="a()" value="最簡單的對話方塊"/><br/>
<button id="btn0" onClick="b()">基本示例</button><br/>
<button id="btn1" onClick="c()">顯示圖片</button><br/>
<button id="btn2" onClick="d()">外部頁面</button><br/>
<button id="btn3" onClick="e()">視訊</button><br/>
<button id="btn4" onClick="f()">詢問</button><br/>
<button id="btn5" onClick="g()">廣告</button>
<button id="btn6" onClick="h()">關閉</button><br/>
<button id="btn7" onClick="i()">彈出選單</button><br/>
</body>
</html>

上面沒有用的特性art.dialog({id:'testDialog'}).data.iframe.document.getElementById('test'),也就是說如果在dialog裡面嵌入的iframe,parent頁面可以通過這種方式取到裡面的控制元件。PS:iframe支援已經改變,沒細研究。

在對話方塊裡新增視訊的時候,avi格式的總是隻有聲音沒有畫面,氣死我了!基本上典型應用都有了,以後看一下就會用了,這就是目的,哈哈。還有,artDialg的屬性如下(也就是Demo網頁上的那幾個):

content: {訊息內容,支援HTML}

title: {標題.預設:'提示'} iframe: {嵌入外部頁面. 存在content引數時候,此引數無效} yesText: {確定按鈕文字. 預設:'確定'} noText: {取消按鈕文字. 預設:'取消'} width: {寬度,支援em等單位. 預設:'auto'}
height: {高度,支援em等單位. 預設:'auto'}
left: {x座標,可以使用關鍵字,如:'left'、'right'. 預設:居中}
top: {y座標,可以使用關鍵字,如:'top'、'bottom'. 預設:居中(注: 小對話方塊採用黃金比例垂直居中)}
menuBtn: {讓對話方塊在指定元素附近彈出, 存在menuBtn引數則讓left、top引數失效}
fixed: {是否啟用靜止定位. 預設:false}
style: {對話方塊風格擴充套件引數,寫入自定義className,詳情見面板css檔案的定義,多個用空格隔開}
lock: {是否鎖定螢幕, 中斷使用者操作頁面. 預設:false}
id: {給對話方塊定義唯一標識id名稱. 可以防止重複彈出對話方塊}
time: {多少秒自動關閉}

上面的屬性有些已經不支援,屬性已經改變更新了好多,詳細參見最新下載的doc說明!!