]> khamidou — GitHub mirrors - electron.git/commitdiff
Fix window.open options parsing:
authorBundyo <bundyo@gmail.com>
Wed, 18 Feb 2015 12:36:05 +0000 (14:36 +0200)
committerBundyo <bundyo@gmail.com>
Wed, 18 Feb 2015 12:36:05 +0000 (14:36 +0200)
remove excessive whitespace (gets inserted in property names),
avoid creating dummy properties if not needed,
turn 1/0 to true/false, convert integer strings to strings (fixes width/height).

atom/renderer/lib/override.coffee

index 43ae271fb1d0c7d387145adc4a1af34126f0e540..c61cce889040aec4c8fbcdb76d56d78e9330ddfe 100644 (file)
@@ -26,21 +26,25 @@ unless process.guestInstanceId?
 # Make the browser window or guest view emit "new-window" event.
 window.open = (url, frameName='', features='') ->
   options = {}
-  for feature in features.split ','
-    [name, value] = feature.split '='
+  ints = [ 'x', 'y', 'width', 'height', 'min-width', 'max-width', 'min-height', 'max-height', 'zoom-factor' ]
+  # Make sure to get rid of excessive whitespace in the property name
+  for feature in features.split /,\s*/
+    [name, value] = feature.split /\s*=/
     options[name] =
-      if value is 'yes'
+      if value is 'yes' or value is '1'
         true
-      else if value is 'no'
+      else if value is 'no' or value is '0'
         false
       else
         value
-  options.x ?= options.left
-  options.y ?= options.top
+  options.x ?= options.left if options.left
+  options.y ?= options.top if options.top
   options.title ?= name
   options.width ?= 800
   options.height ?= 600
 
+  (options[name] = parseInt(options[name], 10) if options[name]?) for name in ints
+
   guestId = ipc.sendSync 'ATOM_SHELL_GUEST_WINDOW_MANAGER_WINDOW_OPEN', url, frameName, options
   if guestId
     new FakeWindow(guestId)