Requires

Provides

Target.js

Functions to fetch and parse targets

License:
Public domain (http://unlicense.org).
Authors:
Yaroslaff Fedin
  1. 22
  2. 23
  3. 24
  4. 25
  5. 26
  6. 27
  7. 28
  8. 29
  9. 30
  10. 31
  11. 32
  12. 33
  13. 34
  14. 35
  15. 36
  16. 37
  17. 38
  18. 39
  19. 40
  20. 41
  21. 42
  22. 43
  23. 44
  24. 45
  25. 46
  26. 47
  27. 48
  28. 49
  29. 50
  30. 51
  31. 52
  32. 53
  33. 54
  34. 55
  35. 56
  36. 57
  37. 58
  38. 59
  39. 60
  40. 61
  41. 62
  42. 63
  43. 64
  44. 65
  45. 66
  46. 67
  47. 68
  48. 69
  49. 70
  50. 71
  51. 72
  52. 73
  53. 74
  54. 75
  55. 76
  56. 77
  57. 78
  58. 79
  59. 80
  60. 81
  61. 82
  62. 83
  63. 84
  64. 85
  65. 86
  66. 87
  67. 88
  68. 89
  69. 90
  70. 91
  71. 92
  72. 93
  73. 94
  74. 95
  75. 96
  76. 97
  77. 98
  78. 99
  79. 100
  80. 101
  81. 102
  82. 103
  83. 104
  84. 105
  85. 106
!function() { var cache = {}; LSD.Module.Target = new Class({ behaviour: '[target][target!=_blank][target!=false]', options: { chain: { target: function() { var action = this.getTargetAction(); if (action) return {name: action, target: this.getTarget, arguments: this.getTargetArguments} } } }, getTarget: function(target, anchor) { if (!target && !(target = this.attributes.target)) return false; var parsed = this.parseTargetSelector(target); results = []; parsed.each(function(expression) { if (!anchor) anchor = expression.anchor ? expression.anchor.call(this) : (this.document || document.body); if (expression.selector) results.push.apply(results, Slick.search(anchor, expression.selector)); else if (anchor) results.push(anchor) }, this); return results.length > 0 && results.map(function(result) { if (result.localName) { var widget = Element.retrieve(result, 'widget'); if (widget && widget.element == result) return widget } return result; }); }, parseTargetSelector: function(target) { if (cache[target]) return cache[target]; var parsed = target.Slick ? target : Slick.parse(target); cache[target] = parsed.expressions.map(this.parseTarget.bind(this)); return cache[target]; }, parseTarget: function(expression) { var pseudos = expression[0].pseudos; var pseudo = pseudos && pseudos[0]; var result = {} if (pseudo && pseudo.type == 'element') { if (Pseudo[pseudo.key]) { result.anchor = function() { return Pseudo[pseudo.key].call(this, pseudo.value); } expression = expression.slice(1); } } if (expression.length > 0) result.selector = {Slick: true, expressions: [expression], length: 1}; return result; }, getTargetAction: function() { return this.attributes.interaction || this.options.targetAction; } }); var Pseudo = LSD.Module.Target.Pseudo = { document: function() { return this.document; }, body: function() { return this.document.element; }, page: function() { return document.body; }, self: function() { return this; }, parent: function() { return this.parentNode }, element: function() { return this.element; }, 'parent-element': function() { return this.element.parentNode } } }();