Skip to content
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

Merged
merged 4 commits into from
Nov 7, 2013
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Copy link
Collaborator

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.

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; }
Copy link
Collaborator

Choose a reason for hiding this comment

The 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.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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:

}

  • key = key.replace("sqwidget", "").toLowerCase();
  • data[key || "url"] = val;
  • };
    +
  • for (key in elData) {
  • val = elData[key];
  • if (!(key.match("^sqwidget"))) { continue; }

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.


Reply to this email directly or view it on GitHub:
https://github.com/premasagar/sqwidget/pull/103/files#r7502938

Copy link
Collaborator

Choose a reason for hiding this comment

The 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);
});
Expand All @@ -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)");
Expand Down
2 changes: 1 addition & 1 deletion sqwidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
baseUrl: './sqwidget',
//preloads: ['curl/plugin/css','curl/plugin/i18n', 'curl/plugin/domReady'],
paths: {
underscore: { location: '//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.2.1/lodash.underscore.min.js' },
//underscore: { location: '//cdnjs.cloudflare.com/ajax/libs/lodash.js/2.2.1/lodash.underscore.min.js' },
bean: { location: '//cdnjs.cloudflare.com/ajax/libs/bean/1.0.3/bean.min.js' },
moment: { location: '//cdnjs.cloudflare.com/ajax/libs/moment.js/2.4.0/moment.min.js' },
},
Expand Down