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.

99 lines
4.4 KiB

3 years ago
  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. // TODO: [ben] To continue from above, added a filter to filter out problem keys. Will need a better way of sorting this out eventually.
  5. var _deepCopy = function (original, trackCopies, filter) {
  6. if(trackCopies) {
  7. var index = _getCopyIndex(original);
  8. if(index != -1) return _originalToCopy[index][1];
  9. }
  10. var isArray = original instanceof Array;
  11. var isObject = !(original instanceof Function) && !(original instanceof Date) && (original instanceof Object);
  12. if(!isArray && !isObject) return original;
  13. var copy = isArray ? [] : { };
  14. if(trackCopies) _originalToCopy.push([original, copy]);
  15. isArray ? deepCopyArray(original, trackCopies, copy, filter) : deepCopyObject(original, trackCopies, copy, filter);
  16. return copy;
  17. };
  18. $ax.deepCopy = _deepCopy;
  19. // Hacky way to copy event info. Copying dragInfo causes major issues due to infinite loops
  20. // Hashmap doesn't map objects well. It just toStrings them, making them all the same key. This has to be slow...
  21. var _originalToCopy = [];
  22. var _getCopyIndex = function(original) {
  23. for(var i = 0; i < _originalToCopy.length; i++) if(original === _originalToCopy[i][0]) return i;
  24. return -1;
  25. };
  26. $ax.eventCopy = function(eventInfo) {
  27. var copy = _deepCopy(eventInfo, true, ['dragInfo', 'elementQuery', 'obj']);
  28. // reset the map. TODO: May need to reset elsewhere too, but this is the only way it's used currently
  29. _originalToCopy = [];
  30. return copy;
  31. };
  32. var deepCopyArray = function(original, trackCopies, copy, filter) {
  33. for(var i = 0; i < original.length; i++) {
  34. copy[i] = _deepCopy(original[i], trackCopies, filter);
  35. }
  36. };
  37. var deepCopyObject = function(original, trackCopies, copy, filter) {
  38. for(var key in original) {
  39. if(!original.hasOwnProperty(key)) continue; // Continue if the prop was not put there like a dictionary, but just a native part of the object
  40. if(filter && filter.indexOf[key] != -1) copy[key] = original[key]; // If that key is filtered out, skip recursion on it.
  41. else copy[key] = _deepCopy(original[key], trackCopies, filter);
  42. }
  43. };
  44. // Our implementation of splice because it is broken in IE8...
  45. $ax.splice = function(array, startIndex, count) {
  46. var retval = [];
  47. if(startIndex >= array.length || startIndex < 0 || count == 0) return retval;
  48. if(!count || startIndex + count > array.length) count = array.length - startIndex;
  49. for(var i = 0; i < count; i++) retval[i] = array[startIndex + i];
  50. for(i = startIndex + count; i < array.length; i++) array[i - count] = array[i];
  51. for(i = 0; i < count; i++) array.pop();
  52. return retval;
  53. };
  54. });
  55. // ******* Flow Shape Links ******** //
  56. $axure.internal(function($ax) {
  57. $(window.document).ready(function() {
  58. if (!$ax.document.configuration.linkFlowsToPages && !$ax.document.configuration.linkFlowsToPagesNewWindow) return;
  59. $ax(function (dObj) { return ($ax.public.fn.IsVector(dObj.type) || $ax.public.fn.IsSnapshot(dObj.type)) && dObj.referencePageUrl; }).each(function (dObj, elementId) {
  60. var elementIdQuery = $('#' + elementId);
  61. if($ax.document.configuration.linkFlowsToPages && !$ax.event.HasClick(dObj)) {
  62. elementIdQuery.css("cursor", "pointer");
  63. elementIdQuery.click(function() {
  64. $ax.navigate({
  65. url: dObj.referencePageUrl,
  66. target: "current",
  67. includeVariables: true
  68. });
  69. });
  70. }
  71. if($ax.document.configuration.linkFlowsToPagesNewWindow) {
  72. $('#' + elementId + "_ref").append("<div id='" + elementId + "PagePopup' class='refpageimage'></div>");
  73. $('#' + elementId + "PagePopup").click(function() {
  74. $ax.navigate({
  75. url: dObj.referencePageUrl,
  76. target: "new",
  77. includeVariables: true
  78. });
  79. });
  80. }
  81. });
  82. });
  83. });