mirror of
https://github.com/pulsar-edit/pulsar.git
synced 2025-01-07 23:59:22 +03:00
Open http/https links in an external browser
Listen for all links being clicked and open any http/https hrefs by spawning a call to the 'open' command. Closes #531
This commit is contained in:
parent
ca4cfe358f
commit
4dce9d659f
@ -230,3 +230,25 @@ describe "Window", ->
|
||||
event = buildDragEvent("drop", [])
|
||||
window.onDrop(event)
|
||||
expect(atom.open).not.toHaveBeenCalled()
|
||||
|
||||
describe "when a link is clicked", ->
|
||||
it "opens the http/https links in an external application", ->
|
||||
ChildProcess = require 'child_process'
|
||||
spyOn(ChildProcess, 'spawn')
|
||||
|
||||
$("<a href='http://github.com'>the website</a>").appendTo(document.body).click().remove()
|
||||
expect(ChildProcess.spawn).toHaveBeenCalled()
|
||||
expect(ChildProcess.spawn.argsForCall[0][1][0]).toBe "http://github.com"
|
||||
|
||||
ChildProcess.spawn.reset()
|
||||
$("<a href='https://github.com'>the website</a>").appendTo(document.body).click().remove()
|
||||
expect(ChildProcess.spawn).toHaveBeenCalled()
|
||||
expect(ChildProcess.spawn.argsForCall[0][1][0]).toBe "https://github.com"
|
||||
|
||||
ChildProcess.spawn.reset()
|
||||
$("<a href=''>the website</a>").appendTo(document.body).click().remove()
|
||||
expect(ChildProcess.spawn).not.toHaveBeenCalled()
|
||||
|
||||
ChildProcess.spawn.reset()
|
||||
$("<a href='#scroll-me'>link</a>").appendTo(document.body).click().remove()
|
||||
expect(ChildProcess.spawn).not.toHaveBeenCalled()
|
||||
|
@ -27,6 +27,15 @@ window.setUpEnvironment = ->
|
||||
window.pasteboard = new Pasteboard
|
||||
window.keymap = new Keymap()
|
||||
$(document).on 'keydown', keymap.handleKeyEvent
|
||||
|
||||
$(document).on 'click', 'a', (e) ->
|
||||
location = $(e.target).attr('href')
|
||||
return unless location or location[0] is '#'
|
||||
|
||||
if location.indexOf('https://') is 0 or location.indexOf('http://') is 0
|
||||
require('child_process').spawn('open', [location]) if location
|
||||
false
|
||||
|
||||
keymap.bindDefaultKeys()
|
||||
|
||||
requireStylesheet 'atom'
|
||||
|
Loading…
Reference in New Issue
Block a user