-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
nest options #103
nest options #103
Changes from 3 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,23 +9,33 @@ function(require, bonzo, qwery, bean) { | |
|
||
//convert data-sqwidget to dictionary | ||
SqwidgetCore.prototype.getWidgetParams = function($el) { | ||
var data, key, val, _ref; | ||
data = {}; | ||
_ref = $el.data(); | ||
|
||
for (key in _ref) { | ||
val = _ref[key]; | ||
if (!(key.match("sqwidget"))) { | ||
continue; | ||
var key, val, | ||
data = {}, | ||
elData = $el.data(); | ||
|
||
if(elData.sqwidget) { | ||
elData.sqwidgetUrl = elData.sqwidget; | ||
delete elData.sqwidget; | ||
} | ||
|
||
var nest = function( names, data, val ) { | ||
for( var i = 0; i < names.length; i++ ) { | ||
data = data[ names[i].toLowerCase() ] = | ||
i === names.length - 1 ? val : data[ names[i] ] || {}; | ||
} | ||
key = key.replace("sqwidget", "").toLowerCase(); | ||
data[key || "url"] = val; | ||
}; | ||
|
||
for (key in elData) { | ||
val = elData[key]; | ||
if (!(key.match("^sqwidget"))) { continue; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm thinking if we should make all the data attributes available to the config? There's no harm in it and may keep embed codes shorter for someone. I won't want to use something that's not prefixed for my own projects - but someone may. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. w3c recommends prefixing. On 7 November 2013 at 17:27:17, Adhip Gupta ([email protected]) wrote:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So should we make this prefix a little more configurable? #97 |
||
nest(key.match(/([A-Z]?[^A-Z]*)/g).slice(0,-1), data, val); | ||
} | ||
return data; | ||
|
||
return data.sqwidget; | ||
}; | ||
|
||
SqwidgetCore.prototype.guid = function() { | ||
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
return 'sqwidget-xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) { | ||
var r = Math.random()*16|0, v = c == 'x' ? r : (r&0x3|0x8); | ||
return v.toString(16); | ||
}); | ||
|
@@ -34,10 +44,11 @@ function(require, bonzo, qwery, bean) { | |
SqwidgetCore.prototype.register = function(el) { | ||
var opts, | ||
_this = this, | ||
$el = bonzo(el).addClass('sqwidget'); | ||
id = this.guid(), | ||
$el = bonzo(el).addClass('sqwidget').addClass(id); | ||
opts = this.getWidgetParams($el); | ||
opts.el = $el; | ||
opts.id = this.guid(); | ||
opts.id = id; | ||
|
||
if (!opts.url) { | ||
throw new Error("No widget source defined (set data-sqwidget-url)"); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This definitely needs to be documented.