2014-11-21 82 views
0

我讀引導的modal.js,哪裏有這樣的片段:引導模式選項

$(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) { 
    var $this = $(this) 
    var href = $this.attr('href') 
    var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) // strip for ie7 
    var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data()) 

    if ($this.is('a')) e.preventDefault() 

    $target.one('show.bs.modal', function (showEvent) { 
     if (showEvent.isDefaultPrevented()) return // only register focus restorer if modal will actually get shown 
     $target.one('hidden.bs.modal', function() { 
     $this.is(':visible') && $this.trigger('focus') 
     }) 
    }) 
    Plugin.call($target, option, this) 
    }) 

}(jQuery); 

任何人都知道是什麼行var option = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())的意思,尤其是這部分remote: !/#/.test(href) && href

回答

1
  • /#/是一個搜索散列的正則表達式。
  • /#/.test(href)返回true如果href包含散列。
  • !/#/.test(href)反轉結果;如果href不包含散列,這是真的。
  • !/#/.test(href) && href是一個布爾AND哈克。如果左邊是true,它將返回href;否則將返回false

因此,如果href包含哈希,然後將其輸出:

{ remote: false } 

如果href不包含哈希,它輸出:

{ remote: href }