Hello2all,
I've just installed Flickr module that lets you add filtered text like [flickr-photo:id=230452326,size=s]
Now I would build a small JS interface that shows a form asking for id and size (in a select/radio manner) any hint?

Comments

ufku’s picture

Status: Active » Fixed

Try this. It parses the selected text and extract values into the form and also supports additional propert=value pairs.

js:
var regExp = new RegExp('^\\[(flickr-photo(?:set)?)\\:(.+)\\]$');
var M = regExp.exec(E.getSelection()) || ['', 'flickr-photo', 'id=,size='];
var form = [
  {name: 'type', type: 'select', options: {'flickr-photo': 'Photo', 'flickr-photoset': 'Photo set'}, value: M[1]},
  {name: 'id', required: 1},
  {name: 'size', type: 'select', options: {s: 'Square', t: 'Thumbnail', m: 'Small', '-': 'Medium', b: 'Large', o: 'Original'}}
];
$.each($.trim(M[2]).split(','), function(i, prop) {
  var parts = prop.split('=');
  if (parts.length != 2) return;
  var name = $.trim(parts[0]), value = $.trim(parts[1]);
  if (name == 'id') form[1].value = value;
  else if (name == 'size') form[2].value = value;
  else if (name) form.push({name: name, value: value});
});
E.tagDialog('flickr', form, {title: 'Insert Flickr Photo', submit: function(tag, form) {
  for (var el, props = [], els = form.elements, i = 1; el = els[i]; i++) {
    if (el.name.substr(0, 5) == 'attr_') {
      props.push(el.name.substr(5) + '=' + el.value);
    }
  }
  E.replaceSelection('[' + els[0].value + ':' + props.join(',') + ']');
}});

---

A simpler one without parsing.

js:
var form = [
  {name: 'type', type: 'select', options: {'flickr-photo': 'Photo', 'flickr-photoset': 'Photo set'}},
  {name: 'id', required: 1},
  {name: 'size', type: 'select', options: {s: 'Square', t: 'Thumbnail', m: 'Small', '-': 'Medium', b: 'Large', o: 'Original'}}
];
E.tagDialog('flickr', form, {title: 'Insert Flickr Photo', submit: function(tag, form) {
  var el = form.elements;
  E.replaceSelection('[' + el[0].value + ':id=' + el[1].value + ',size=' + el[2].value + ']');
}});

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.