utils.temp.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. // ******* Deep Copy ******** //
  2. $axure.internal(function($ax) {
  3. // TODO: [ben] Ah, infinite loops cause major issues here. Tried saving objects we've already hit, but that didn't seem to work (at least at my first shot).
  4. var _deepCopy = function(original, trackCopies) {
  5. if(trackCopies) {
  6. var index = _getCopyIndex(original);
  7. if(index != -1) return _originalToCopy[index][1];
  8. }
  9. var isArray = original instanceof Array;
  10. var isObject = !(original instanceof Function) && !(original instanceof Date) && (original instanceof Object);
  11. if(!isArray && !isObject) return original;
  12. var copy = isArray ? [] : { };
  13. if(trackCopies) _originalToCopy.push([original, copy]);
  14. isArray ? deepCopyArray(original, trackCopies, copy) : deepCopyObject(original, trackCopies, copy);
  15. return copy;
  16. };
  17. $ax.deepCopy = _deepCopy;
  18. // Hacky way to copy event info. Copying dragInfo causes major issues due to infinite loops
  19. // Hashmap doesn't map objects well. It just toStrings them, making them all the same key. This has to be slow...
  20. var _originalToCopy = [];
  21. var _getCopyIndex = function(original) {
  22. for(var i = 0; i < _originalToCopy.length; i++) if(original === _originalToCopy[i][0]) return i;
  23. return -1;
  24. };
  25. $ax.eventCopy = function(eventInfo) {
  26. var dragInfo = eventInfo.dragInfo;
  27. delete eventInfo.dragInfo;
  28. var copy = _deepCopy(eventInfo, true);
  29. copy.dragInfo = dragInfo;
  30. eventInfo.dragInfo = dragInfo;
  31. // reset the map.
  32. _originalToCopy = [];
  33. return copy;
  34. };
  35. var deepCopyArray = function(original, trackCopies, copy) {
  36. for(var i = 0; i < original.length; i++) {
  37. copy[i] = _deepCopy(original[i], trackCopies);
  38. }
  39. };
  40. var deepCopyObject = function(original, trackCopies, copy) {
  41. for(var key in original) {
  42. if(!original.hasOwnProperty(key)) continue;
  43. copy[key] = _deepCopy(original[key], trackCopies);
  44. }
  45. };
  46. // Our implementation of splice because it is broken in IE8...
  47. $ax.splice = function(array, startIndex, count) {
  48. var retval = [];
  49. if(startIndex >= array.length || startIndex < 0 || count == 0) return retval;
  50. if(!count || startIndex + count > array.length) count = array.length - startIndex;
  51. for(var i = 0; i < count; i++) retval[i] = array[startIndex + i];
  52. for(i = startIndex + count; i < array.length; i++) array[i - count] = array[i];
  53. for(i = 0; i < count; i++) array.pop();
  54. return retval;
  55. };
  56. });
  57. // ******* Flow Shape Links ******** //
  58. $axure.internal(function($ax) {
  59. if(!$ax.document.configuration.linkFlowsToPages && !$ax.document.configuration.linkFlowsToPagesNewWindow) return;
  60. $(window.document).ready(function() {
  61. $ax(function (dObj) { return ($ax.public.fn.IsVector(dObj.type) || $ax.public.fn.IsSnapshot(dObj.type)) && dObj.referencePageUrl; }).each(function (dObj, elementId) {
  62. var elementIdQuery = $('#' + elementId);
  63. if($ax.document.configuration.linkFlowsToPages && !$ax.event.HasClick(dObj)) {
  64. elementIdQuery.css("cursor", "pointer");
  65. elementIdQuery.click(function() {
  66. $ax.navigate({
  67. url: dObj.referencePageUrl,
  68. target: "current",
  69. includeVariables: true
  70. });
  71. });
  72. }
  73. if($ax.document.configuration.linkFlowsToPagesNewWindow) {
  74. $('#' + elementId + "_ref").append("<div id='" + elementId + "PagePopup' class='refpageimage'></div>");
  75. $('#' + elementId + "PagePopup").click(function() {
  76. $ax.navigate({
  77. url: dObj.referencePageUrl,
  78. target: "new",
  79. includeVariables: true
  80. });
  81. });
  82. }
  83. });
  84. });
  85. });