Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

createlink-base-debug.js 3.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /*
  2. Copyright (c) 2010, Yahoo! Inc. All rights reserved.
  3. Code licensed under the BSD License:
  4. http://developer.yahoo.com/yui/license.html
  5. version: 3.4.0
  6. build: nightly
  7. */
  8. YUI.add('createlink-base', function(Y) {
  9. /**
  10. * Adds prompt style link creation. Adds an override for the <a href="Plugin.ExecCommand.html#method_COMMANDS.createlink">createlink execCommand</a>.
  11. * @class Plugin.CreateLinkBase
  12. * @static
  13. * @submodule createlink-base
  14. * @module editor
  15. */
  16. var CreateLinkBase = {};
  17. /**
  18. * Strings used by the plugin
  19. * @property STRINGS
  20. * @static
  21. */
  22. CreateLinkBase.STRINGS = {
  23. /**
  24. * String used for the Prompt
  25. * @property PROMPT
  26. * @static
  27. */
  28. PROMPT: 'Please enter the URL for the link to point to:',
  29. /**
  30. * String used as the default value of the Prompt
  31. * @property DEFAULT
  32. * @static
  33. */
  34. DEFAULT: 'http://'
  35. };
  36. Y.namespace('Plugin');
  37. Y.Plugin.CreateLinkBase = CreateLinkBase;
  38. Y.mix(Y.Plugin.ExecCommand.COMMANDS, {
  39. /**
  40. * Override for the createlink method from the <a href="Plugin.CreateLinkBase.html">CreateLinkBase</a> plugin.
  41. * @for ExecCommand
  42. * @method COMMANDS.createlink
  43. * @static
  44. * @param {String} cmd The command executed: createlink
  45. * @return {Node} Node instance of the item touched by this command.
  46. */
  47. createlink: function(cmd) {
  48. var inst = this.get('host').getInstance(), out, a, sel, holder,
  49. url = prompt(CreateLinkBase.STRINGS.PROMPT, CreateLinkBase.STRINGS.DEFAULT);
  50. if (url) {
  51. holder = inst.config.doc.createElement('div');
  52. url = url.replace(/"/g, '').replace(/'/g, ''); //Remove single & double quotes
  53. url = inst.config.doc.createTextNode(url);
  54. holder.appendChild(url);
  55. url = holder.innerHTML;
  56. Y.log('Adding link: ' + url, 'info', 'createLinkBase');
  57. this.get('host')._execCommand(cmd, url);
  58. sel = new inst.Selection();
  59. out = sel.getSelected();
  60. if (!sel.isCollapsed && out.size()) {
  61. //We have a selection
  62. a = out.item(0).one('a');
  63. if (a) {
  64. out.item(0).replace(a);
  65. }
  66. if (Y.UA.gecko) {
  67. if (a.get('parentNode').test('span')) {
  68. if (a.get('parentNode').one('br.yui-cursor')) {
  69. a.get('parentNode').insert(a, 'before');
  70. }
  71. }
  72. }
  73. } else {
  74. //No selection, insert a new node..
  75. this.get('host').execCommand('inserthtml', '<a href="' + url + '">' + url + '</a>');
  76. }
  77. }
  78. return a;
  79. }
  80. });
  81. }, '3.4.0' ,{skinnable:false, requires:['editor-base']});