[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/yui_editor/ -> yui_editor_admin.js (source)

   1  // $Id: yui_editor_admin.js,v 1.1.2.4.2.1 2008/11/21 22:54:27 jeffcd Exp $
   2  
   3  YAHOO.namespace('Drupal');
   4  var Dom = YAHOO.util.Dom,
   5      Event = YAHOO.util.Event;
   6  var DDM = YAHOO.util.DragDropMgr;
   7  
   8  editable = {
   9    config: {
  10      class_name: 'editable'
  11    },
  12    init: function() {
  13      this.clicked = false;
  14      this.contents = false;
  15      this.input = false;
  16  
  17      var _items = Dom.getElementsByClassName(this.config.class_name);
  18      Event.addListener(_items, 'dblclick', editable.dbl_click, editable, true);
  19    },
  20    dbl_click: function(ev) {
  21      var tar = Event.getTarget(ev);
  22      if (!tar) {
  23         return;
  24       }
  25       if (tar.tagName && (tar.tagName.toLowerCase() == 'input')) {
  26         return false;
  27       }
  28       this.check();
  29       this.clicked = tar;
  30       this.contents = this.clicked.innerHTML;
  31       this.make_input();
  32    },
  33    make_input: function() {
  34      this.input = Dom.generateId();
  35  
  36      new_input = document.createElement('input');
  37      new_input.setAttribute('type', 'text');
  38      new_input.setAttribute('id', this.input);
  39      if (this.contents == ' ') {
  40        new_input.value = '';
  41      }
  42      else {
  43        new_input.value = this.contents;
  44      }
  45      new_input.setAttribute('size', this.contents.length);
  46      new_input.className = 'editable_input';
  47  
  48      this.clicked.innerHTML = '';
  49      this.clicked.appendChild(new_input);
  50      new_input.select();
  51      Event.addListener(new_input, 'blur', editable.check, editable, true);
  52    },
  53    clear_input: function() {
  54      if (this.input) {
  55        if (Dom.get(this.input).value.length > 0) {
  56          this.clean_input();
  57          this.contents_new = Dom.get(this.input).value;
  58          this.clicked.innerHTML = this.contents_new;
  59        }
  60        else {
  61          this.contents_new = ' '
  62          this.clicked.innerHTML = this.contents_new;
  63        }
  64      }
  65      this.callback();
  66      this.clicked = false;
  67      this.contents = false;
  68      this.input = false;
  69     },
  70     clean_input: function() {
  71       checkText = new String(Dom.get(this.input).value);
  72       regEx1 = /\"/g;
  73       checkText = String(checkText.replace(regEx1, ''));
  74       Dom.get(this.input).value = checkText;
  75     },
  76     check: function(ev) {
  77       if (this.clicked) {
  78         this.clear_input();
  79       }
  80     },
  81     callback: function() {
  82   }
  83  }
  84  
  85  Event.addListener('edit-button-profile', 'change', function (e) {
  86    if (Dom.get('edit-button-profile').selectedIndex != (Dom.get('edit-button-profile').length - 1)) {
  87      var attr = { opacity: { to: 0 } };
  88      var anim = new YAHOO.util.Anim('custom_button_profile_wrapper', attr, 0.5);
  89      anim.animate();
  90      setTimeout("Dom.setStyle(Dom.get('custom_button_profile_wrapper'), 'display', 'none')", 1000);
  91    }
  92    else {
  93      Dom.setStyle(Dom.get('custom_button_profile_wrapper'), 'display', 'block');
  94      var attr = { opacity: { to: 1 } };
  95      var anim = new YAHOO.util.Anim('custom_button_profile_wrapper', attr, 0.5);
  96      anim.animate();
  97    }
  98  });
  99  
 100  Event.addListener('yui-editor-profile', 'submit', function (e) {
 101    var btn_groups_titles = Dom.get('custom_button_profile').getElementsByTagName('h3');
 102    var titles = '';
 103    for (var t = 0; t < (btn_groups_titles.length - 1); t++) {
 104      titles = titles + "{ group: 'foo', label: \'" + btn_groups_titles[t].innerHTML + "\', buttons: [";
 105      var g = Dom.getNextSibling(btn_groups_titles[t]).getElementsByTagName('li');
 106      var btns = '';
 107      for (var b = 0; b < g.length; b++) {
 108        var title = Dom.getFirstChild(g[b]).getAttribute('title');
 109        var value = Dom.getFirstChild(g[b]).getAttribute('value');
 110        var type = Dom.getFirstChild(g[b]).getAttribute('type');
 111        btns = btns + (b != 0 ? ',' : '');
 112        if (title == null) {
 113          btns = btns + "\n{ type: 'separator' }";
 114        }
 115        else if (type == 'spin') {
 116          var range = Dom.getFirstChild(g[b]).getAttribute('range');
 117          btns = btns + "\n{ type: '" + type + "', label: '" + title + "', value: '" + value + "', range: " + range + " }";
 118        }
 119        else if (type == 'select') {
 120          var menu = Dom.getFirstChild(g[b]).getAttribute('menu');
 121          btns = btns + "\n{ type: '" + type + "', label: '" + title + "', value: '" + value + "', menu: " + menu + " }";
 122        }
 123        else {
 124          btns = btns + "\n{ type: '" + type + "', label: '" + title + "', value: '" + value + "' }";
 125        }
 126      }
 127      titles = titles + btns + (t != (btn_groups_titles.length - 1) ? "\n] },\n { type: 'separator' }, \n" : '\n] }\n');
 128    }
 129    var btn_groups = Dom.getElementsByClassName('yui-toolbar-group', 'div', Dom.get('custom_button_profile'));
 130    Dom.getAncestorByTagName(btn_groups[btn_groups.length - 1], 'div').removeChild(Dom.getPreviousSibling(btn_groups[btn_groups.length - 1]));
 131    Dom.getAncestorByTagName(btn_groups[btn_groups.length - 1], 'div').removeChild(btn_groups[btn_groups.length - 1]);
 132    Dom.get('edit-custom').value = titles + " { group: 'plugins', label: 'Plugins', buttons: [ ] }";
 133    Dom.get('edit--custom-html').value = Dom.get('custom_button_profile_wrapper').innerHTML;
 134  });
 135  
 136  function yui_editor_add_group() {
 137    var btn_groups = Dom.getElementsByClassName('yui-toolbar-subcont', 'div', 'custom_button_profile');
 138    var span = document.createElement('span');
 139    var div = document.createElement('div');
 140    var h3 = document.createElement('h3');
 141    var ul = document.createElement('ul');
 142  
 143    Dom.addClass(span, 'yui-toolbar-separator');
 144    span.innerHTML = '|';
 145    Dom.addClass(div, 'yui-toolbar-group');
 146    h3.innerHTML = '[new group]';
 147    Dom.addClass(h3, 'editable');
 148    Event.addListener(h3, 'dblclick', editable.dbl_click, editable, true);
 149    groupCount++;
 150    ul.setAttribute('id', 'btngroup' + groupCount);
 151    Dom.setStyle(ul, 'height', '10px');
 152    div.appendChild(h3);
 153    div.appendChild(ul);
 154    btn_groups[0].appendChild(span);
 155    btn_groups[0].appendChild(div);
 156    new YAHOO.util.DDTarget('btngroup' + groupCount);
 157  }
 158  
 159  YAHOO.Drupal.DDApp = {
 160    init: function() {
 161      var btn_groups = Dom.get('custom_button_profile').getElementsByTagName('ul');
 162      var bc = 0;
 163      for (var g = 0; g < btn_groups.length; g++) {
 164        btn_groups[g].setAttribute('id', 'btngroup' + g);
 165        new YAHOO.util.DDTarget('btngroup' + g);
 166  
 167        var btns = Dom.get('btngroup' + g).getElementsByTagName('li');
 168        for (var b = 0; b < btns.length; b++, bc++) {
 169          btns[b].setAttribute('id', 'btn' + bc);
 170          new YAHOO.Drupal.DDList('btn' + bc);
 171        }
 172      }
 173      new YAHOO.util.DDTarget('holdingpen');
 174      var hp = Dom.get('holdingpen').getElementsByTagName('li');
 175      for (var h = 0; h < hp.length; h++, bc++) {
 176        hp[h].setAttribute('id', 'btn' + bc);
 177        new YAHOO.Drupal.DDList('btn' + bc);
 178      }
 179      groupCount = g;
 180      yui_editor_add_group();
 181    }
 182  };
 183  
 184  YAHOO.Drupal.DDList = function(id, sGroup, config) {
 185    YAHOO.Drupal.DDList.superclass.constructor.call(this, id, sGroup, config);
 186  
 187    this.logger = this.logger || YAHOO;
 188    var el = this.getDragEl();
 189    Dom.setStyle(el, "opacity", 0.67);
 190  
 191    this.goingUp = false;
 192    this.lastY = 0;
 193  };
 194  
 195  YAHOO.extend(YAHOO.Drupal.DDList, YAHOO.util.DDProxy, {
 196    startDrag: function(x, y) {
 197      var dragEl = this.getDragEl();
 198      var clickEl = this.getEl();
 199      Dom.setStyle(clickEl, "visibility", "hidden");
 200  
 201      dragEl.innerHTML = clickEl.innerHTML;
 202  
 203      Dom.setStyle(dragEl, "color", Dom.getStyle(clickEl, "color"));
 204      Dom.setStyle(dragEl, "backgroundColor", Dom.getStyle(clickEl, "backgroundColor"));
 205      Dom.setStyle(dragEl, "border", "2px solid gray");
 206    },
 207    endDrag: function(e) {
 208      var srcEl = this.getEl();
 209      var proxy = this.getDragEl();
 210  
 211      Dom.setStyle(proxy, "visibility", "");
 212      var a = new YAHOO.util.Motion(proxy, { points: { to: Dom.getXY(srcEl) } }, 0.2, YAHOO.util.Easing.easeOut);
 213      var proxyid = proxy.id;
 214      var thisid = this.id;
 215  
 216      a.onComplete.subscribe(function() {
 217        Dom.setStyle(proxyid, "visibility", "hidden");
 218        Dom.setStyle(thisid, "visibility", "");
 219      });
 220      a.animate();
 221      var btn_groups = Dom.getElementsByClassName('yui-toolbar-group', 'div', Dom.get('custom_button_profile'));
 222      for (var g = 0; g < (btn_groups.length - 1); g++) {
 223        var btns = btn_groups[g].getElementsByTagName('li');
 224        if (btns.length == 0) {
 225          if (g != 0) {
 226            Dom.getAncestorByTagName(btn_groups[g], 'div').removeChild(Dom.getPreviousSibling(btn_groups[g]));
 227          }
 228          Dom.getAncestorByTagName(btn_groups[g], 'div').removeChild(btn_groups[g]);
 229        }
 230      }
 231      if (btn_groups[btn_groups.length - 1].getElementsByTagName('li').length > 0) {
 232        yui_editor_add_group();
 233      }
 234    },
 235    onDragDrop: function(e, id) {
 236      if (DDM.interactionInfo.drop.length === 1) {
 237        var pt = DDM.interactionInfo.point;
 238        var region = DDM.interactionInfo.sourceRegion;
 239        if (!region.intersect(pt)) {
 240          var destEl = Dom.get(id);
 241          var destDD = DDM.getDDById(id);
 242          destEl.appendChild(this.getEl());
 243          destDD.isEmpty = false;
 244          DDM.refreshCache();
 245        }
 246      }
 247    },
 248    onDrag: function(e) {
 249      var y = Event.getPageY(e);
 250  
 251      if (y < this.lastY) {
 252        this.goingUp = true;
 253      }
 254      else if (y > this.lastY) {
 255        this.goingUp = false;
 256      }
 257      this.lastY = y;
 258    },
 259    onDragOver: function(e, id) {
 260      var srcEl = this.getEl();
 261      var destEl = Dom.get(id);
 262  
 263      if (destEl.nodeName.toLowerCase() == "li") {
 264        var orig_p = srcEl.parentNode;
 265        var p = destEl.parentNode;
 266  
 267        if (this.goingUp) {
 268          p.insertBefore(srcEl, destEl); // insert above
 269        }
 270        else {
 271          p.insertBefore(srcEl, destEl.nextSibling); // insert below
 272        }
 273        DDM.refreshCache();
 274      }
 275    }
 276  });
 277  
 278  Event.onAvailable('custom_button_profile', editable.init, editable, true);
 279  Event.onContentReady('custom_button_profile', YAHOO.Drupal.DDApp.init, YAHOO.Drupal.DDApp, true);


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7