2016-05-03 13 views
1

私はアプリケーションを作成しています。私はモバイルデバイスでスタンドアロンの外観をしたいと思います。スタンドアロンのWebアプリケーションでリンクを開くモバイルモーダルをレールで開くモバイルSafariを

私も自分のアプリケーションでのモーダルを使用しているしかし、私は

// Mobile Safari in standalone mode 
if(("standalone" in window.navigator) && window.navigator.standalone){ 

    // If you want to prevent remote links in standalone web apps opening Mobile Safari, change 'remotes' to true 
    var noddy, remotes = false; 

    document.addEventListener('click', function(event) { 

     noddy = event.target; 

     // Bubble up until we hit link or top HTML element. Warning: BODY element is not compulsory so better to stop on HTML 
     while(noddy.nodeName !== "A" && noddy.nodeName !== "HTML") { 
      noddy = noddy.parentNode; 
     } 

     if('href' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) 
     { 
      event.preventDefault(); 
      document.location.href = noddy.href; 
     } 

    },false); 
} 

を使用しました。前のJSはモーダルのコードを破っています。

JSモーダル:

$ -> 
    modal_holder_selector = '#modal-holder' 
    modal_selector = '.modal' 

    $(document).on 'click', 'a[data-modal]', -> 
    location = $(this).attr('href') 
    #Load modal dialog from server 
    $.get location, (data)-> 
     $(modal_holder_selector).html(data). 
     find(modal_selector).modal() 
    false 

    $(document).on 'ajax:success', 
    'form[data-modal]', (event, data, status, xhr)-> 
     url = xhr.getResponseHeader('Location') 
     if url 
     # Redirect to url 
     window.location = url 
     else 
     # Remove old modal backdrop 
     $('.modal-backdrop').remove() 

     # Replace old modal with new one 
     $(modal_holder_selector).html(data). 
     find(modal_selector).modal() 

     false 

誰かが私は、これら2つを組み合わせる助けてもらえますか?

+0

あなたもhtmlを追加できますか?あなたのJSモーダル 'クリック'はおそらくあなたの 'href'値に依存します –

答えて

1

が問題ではなく、そのページをモーダル内部で開かれている、あなたが直接ページにリダイレクトしてしまうことがあります。

あなたの現在の「スタンドアロン」のコードはかなりのカスタムに見えるので、私はあなたのニーズに合わせて、それを高めることができると仮定します。そうでない場合は、私に知らせてください。

data-modal属性をチェックして、リダイレクトをトリガーすること自分の条件を変更してみてください。(それを離れて、あなたは可能性が抽象的、

if('href' in noddy && !'data-modal' in noddy && noddy.href.indexOf('http') !== -1 && (noddy.href.indexOf(document.location.host) !== -1 || remotes)) 
{ 
    event.preventDefault(); 
    document.location.href = noddy.href; 
} 

条件がかなり長くなっているので(と変更することができます)shouldRedirect()またはisModal()または何か)、しかし私はあなたにそれを残します。

関連する問題