Skip to content
Browse files

Support @ in image URLs (retina images).

  • Loading branch information...
1 parent 0b64b24 commit f147712caee427608519b3086d27e779903917df @tonistiigi committed Oct 16, 2012
View
2 lib/public/lib/editor/mousecommands.js
@@ -106,7 +106,7 @@
return this.showCmdHighlight(coord, match, 'numeric');
} else if (match = this.checkValidPattern(coord, /#[0-9a-f]{3,6}(?:\b|;|$)/ig)) {
return this.showCmdHighlight(coord, match, 'color');
- } else if (match = this.checkValidPattern(coord, /url\([a-z0-9"'\/\\\._-]+\)/ig)) {
+ } else if (match = this.checkValidPattern(coord, /url\([a-z0-9"'\/\\\.@_-]+\)/ig)) {
return this.showCmdHighlight(coord, match, 'url');
} else if (this.visible) {
return this.stopCommand();
View
2 lib/public/lib/views/ui/styleinfo.js
@@ -144,7 +144,7 @@
"class": 'style-prop-value'
});
i = 0;
- value.replace(/#[a-f\d]{3,6}|rgba?\([\d,\.\s]{5,}\)|url\([\w'":\/\.\?-]{5,}\)|'.*?'|".*?"|-?[\d\.]+(?:px|em|ex|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|\%)(?:\b|;)/gi, function(match, offset) {
+ value.replace(/#[a-f\d]{3,6}|rgba?\([\d,\.\s]{5,}\)|url\([\w'":\/\.\?_@-]{5,}\)|'.*?'|".*?"|-?[\d\.]+(?:px|em|ex|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|\%)(?:\b|;)/gi, function(match, offset) {
var num, spanurl, valuePart, _ref2;
if (i < offset) {
fragment.appendChild(node('span', value.substring(i, offset)));
View
46 src/public/lib/editor/mousecommands.coffee
@@ -3,16 +3,16 @@ define (require, exports, module) ->
ua = require 'ace/lib/useragent'
{combineUrl, node, hexToRgb} = require 'lib/utils'
{listenKey} = require 'lib/keyboard'
-
+
MouseCommands = Backbone.View.extend
-
+
className: 'editor-command-highlight'
-
+
initialize: (opt) ->
_.bindAll @, 'onActivationKeyDown', 'onActivationKeyUp', 'onContainerMouseMove', 'onMouseDown', 'onNumericMouseMove', 'onNumericMouseUp', 'onMouseMove', 'onMouseWheel'
-
+
@editor = opt.editor
-
+
@editor.navigateUpDown = (delta) ->
document = @getSession()?.doc
return unless document
@@ -34,7 +34,7 @@ define (require, exports, module) ->
@editor.navigateDown = (times) ->
times = times || 1
@navigateUpDown times
-
+
listenKey 'editor', 'numeric-increment', exec: => @offsetNumeric 1
listenKey 'editor', 'numeric-decrement', exec: => @offsetNumeric -1
listenKey 'editor', 'numeric-increment-many', exec: => @offsetNumeric 10
@@ -43,16 +43,16 @@ define (require, exports, module) ->
@commandKey = (if ua.isMac then (if ua.isGecko then 224 else 91) else 17)
@activated = false
@action = {}
-
+
$(window).on('keydown', @onActivationKeyDown).on('keyup', @onActivationKeyUp)
-
+
@$el.on('mousedown', @onMouseDown).on('mousemove', @onMouseMove)
-
+
@editor.addEventListener 'mousewheel', @onMouseWheel
-
+
onActivationKeyDown: (e) ->
if e.keyCode == @commandKey && app.isEditorMode && !@activated
- @activated = true
+ @activated = true
$(@editor.container).on 'mousemove', @onContainerMouseMove
onActivationKeyUp: (e) ->
@@ -73,18 +73,18 @@ define (require, exports, module) ->
height: @editor.renderer.lineHeight
display: 'block'
@visible = true
- @lastUrl = null if type != 'url'
-
+ @lastUrl = null if type != 'url'
+
startCommand: (coord) ->
if match = @checkValidNumeric coord
@showCmdHighlight coord, match, 'numeric'
else if match = @checkValidPattern coord, /#[0-9a-f]{3,6}(?:\b|;|$)/ig
@showCmdHighlight coord, match, 'color'
- else if match = @checkValidPattern coord, /url\([a-z0-9"'\/\\\._-]+\)/ig
+ else if match = @checkValidPattern coord, /url\([a-z0-9"'\/\\\.@_-]+\)/ig
@showCmdHighlight coord, match, 'url'
else if @visible
@stopCommand()
-
+
onMouseWheel: (e) ->
if e.domEvent.target == @el && @action.type == 'numeric'
unless @action.wheelDelta?
@@ -95,7 +95,7 @@ define (require, exports, module) ->
e.stop()
else
@stopCommand()
-
+
stopCommand: ->
@action = {}
@lastUrl = null
@@ -153,7 +153,7 @@ define (require, exports, module) ->
replaced = @replaceNumeric coord, match, newValue
@editor.session.$syncInformUndoManager()
@$el.css width: replaced.length * @editor.renderer.characterWidth
-
+
startColorPicker: (match, coord) ->
stackPosition = @editor.session.getUndoManager().$undoStack.length
popup = window.open '', 'colorpicker', 'width=410,height=300,resizable=no,scrollbars=no'
@@ -165,7 +165,7 @@ define (require, exports, module) ->
if match == false
match = @checkValidPattern coord, /[^\s;]+/ig
match = match: '', offset: coord.column unless match
-
+
require ['vendor/colorpicker'], (colorPicker) =>
colorPicker.cP = null
colorPicker.exportColor = =>
@@ -191,7 +191,7 @@ define (require, exports, module) ->
.on 'keydown', (e) =>
if e.keyCode == 27
@editor.session.getUndoManager().undo(true) while stackPosition < @editor.session.getUndoManager().$undoStack.length
- popup.close()
+ popup.close()
popup.close() if e.keyCode == 13
onMouseMove: (e) ->
@@ -209,7 +209,7 @@ define (require, exports, module) ->
ImagePreview.getPreviewElement url, 120, 70, (err, el) ->
return if err
cb el
-
+
when 'color'
color = @action.match.match
require ['lib/views/ui/infotip', 'vendor/colorpicker'], (infoTip, colorPicker) =>
@@ -222,7 +222,7 @@ define (require, exports, module) ->
node 'div', 'R: ' + rgb[0]
node 'div', 'G: ' + rgb[1]
node 'div', 'B: ' + rgb[2]
-
+
offsetNumeric: (delta=1) ->
@@ -262,8 +262,8 @@ define (require, exports, module) ->
newValue += match.match.substr match.len
session.doc.replace new Range(cursor.row, match.offset, cursor.row, match.offset + match.match.length), newValue
return newValue
-
+
destroy: ->
-
+
module.exports = MouseCommands
View
24 src/public/lib/views/ui/styleinfo.coffee
@@ -58,7 +58,7 @@ define (require, exports, module) ->
@infoTip?.hide()
require ['lib/views/ui/imagepreview'], (ImagePreview) ->
new ImagePreview url
-
+
showImageInfo: (urlvalue, e) ->
url = (urlvalue.match /^url\(['"]?(.*)["']?\)$/i)[1]
require ['lib/views/ui/infotip', 'lib/views/ui/imagepreview'], (infoTip, ImagePreview) =>
@@ -71,8 +71,8 @@ define (require, exports, module) ->
createValueElement: (value) ->
fragment = node 'span', class: 'style-prop-value'
i = 0
-
- value.replace /#[a-f\d]{3,6}|rgba?\([\d,\.\s]{5,}\)|url\([\w'":\/\.\?-]{5,}\)|'.*?'|".*?"|-?[\d\.]+(?:px|em|ex|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|\%)(?:\b|;)/gi, (match, offset) =>
+
+ value.replace /#[a-f\d]{3,6}|rgba?\([\d,\.\s]{5,}\)|url\([\w'":\/\.\?_@-]{5,}\)|'.*?'|".*?"|-?[\d\.]+(?:px|em|ex|cm|mm|in|pt|pc|deg|rad|grad|ms|s|hz|khz|\%)(?:\b|;)/gi, (match, offset) =>
fragment.appendChild node 'span', (value.substring i, offset) if i < offset
valuePart = value.substr offset, match.length
if match[..2].toLowerCase() == 'url'
@@ -83,7 +83,7 @@ define (require, exports, module) ->
else if match[0] in ['"', "'"]
fragment.appendChild node 'span', class: 'quoted', valuePart
else if num = match.match /^[\d-\.]+/
- fragment.appendChild node 'span', class: 'numeric',
+ fragment.appendChild node 'span', class: 'numeric',
node 'span', class: 'value', (value.substr offset, num[0].length)
(value.substr offset + num[0].length, match.length - num[0].length)
else
@@ -92,7 +92,7 @@ define (require, exports, module) ->
i = offset + match.length
fragment.appendChild node 'span', (value.substring i, value.length) if i < value.length
fragment
-
+
focusSelector: (sel, force=false) ->
return if sel == @lastFocus && !force
@$('.name').each (i, el) =>
@@ -102,15 +102,15 @@ define (require, exports, module) ->
_onInheritedElementClick: (id) ->
app.console?.outline.select id
-
+
getFilename: (url) ->
sources = app.console.project.get 'files'
- source = _.find sources, (source) -> 0 == url.indexOf source.url
+ source = _.find sources, (source) -> 0 == url.indexOf source.url
name = basename url
if source?.type == 'stylus'
name = name.replace /\.css$/i, '.styl'
name
-
+
setStyleData: (id = 0, data = [], nearby = [], elinfo = null) ->
@$el.toggleClass 'has-items', !!data.length
@@ -145,7 +145,7 @@ define (require, exports, module) ->
item.appendChild node 'div', class: 'media',
node 'span', class: 'label', '@media'
node 'span', class: 'value', (sdata.media)
-
+
item.sdata = sdata
item.appendChild properties = node 'div', class: 'properties'
@@ -180,9 +180,9 @@ define (require, exports, module) ->
nearbyEl.appendChild item = node 'div', class: 'item', (highlightSelector rule.selector)
$(item).bind 'click', _.bind @onFileClick, @, rule.file, rule.selector
fragment.appendChild nearbyEl
-
+
$(@items).append fragment
-
+
if @lastId==id
@focusSelector @lastFocus, true
else
@@ -202,7 +202,7 @@ define (require, exports, module) ->
@$('.is-focused').removeClass 'is-focused'
$el.closest('.style-item').addClass 'is-focused'
@highlightElement = el
-
+
styleItem = $el.closest('.style-item')[0]
if styleItem.scrollIntoViewIfNeeded
styleItem.scrollIntoViewIfNeeded()

0 comments on commit f147712

Please sign in to comment.
Something went wrong with that request. Please try again.