visibility.js 62 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417
  1. $axure.internal(function($ax) {
  2. var document = window.document;
  3. var _visibility = {};
  4. $ax.visibility = _visibility;
  5. var _defaultHidden = {};
  6. var _defaultLimbo = {};
  7. // ****************** Visibility and State Functions ****************** //
  8. var _pageNotesEnabled = true;
  9. $axure.messageCenter.addMessageListener(function (message, data) {
  10. if(message == 'annotationToggle') _pageNotesEnabled = data;
  11. });
  12. var _isIdVisible = $ax.visibility.IsIdVisible = function(id) {
  13. return $ax.visibility.IsVisible(window.document.getElementById(id));
  14. };
  15. $ax.visibility.IsVisible = function(element) {
  16. //cannot use css('visibility') because that gets the effective visiblity
  17. //e.g. won't be able to set visibility on panels inside hidden panels
  18. return element.style.visibility != 'hidden';
  19. };
  20. $ax.visibility.SetIdVisible = function(id, visible) {
  21. $ax.visibility.SetVisible(window.document.getElementById(id), visible);
  22. // Hide lightbox if necessary
  23. if(!visible) {
  24. $jobj($ax.repeater.applySuffixToElementId(id, '_lightbox')).remove();
  25. $ax.flyoutManager.unregisterPanel(id, true);
  26. }
  27. };
  28. var _setAllVisible = function(query, visible) {
  29. for(var i = 0; i < query.length; i++) {
  30. _visibility.SetVisible(query[i], visible);
  31. }
  32. }
  33. $ax.visibility.SetVisible = function (element, visible) {
  34. //not setting display to none to optimize measuring
  35. if (visible) {
  36. var jElement = $(element);
  37. if(jElement.hasClass(HIDDEN_CLASS)) jElement.removeClass(HIDDEN_CLASS);
  38. if(jElement.hasClass(UNPLACED_CLASS)) jElement.removeClass(UNPLACED_CLASS);
  39. element.style.display = '';
  40. element.style.visibility = 'inherit';
  41. if(jElement.hasClass(SELECTED_ClASS)) $ax.style.SetWidgetSelected(element.id, true);
  42. } else {
  43. element.style.display = 'none';
  44. element.style.visibility = 'hidden';
  45. }
  46. };
  47. var _setWidgetVisibility = $ax.visibility.SetWidgetVisibility = function (elementId, options) {
  48. var visible = $ax.visibility.IsIdVisible(elementId);
  49. // If limboed, just fire the next action then leave.
  50. if(visible == options.value || _limboIds[elementId]) {
  51. if(!_limboIds[elementId]) options.onComplete && options.onComplete();
  52. $ax.action.fireAnimationFromQueue(elementId, $ax.action.queueTypes.fade);
  53. return;
  54. }
  55. options.containInner = true;
  56. var query = $jobj(elementId);
  57. var parentId = query.parent().attr('id');
  58. var axObj = $obj(elementId);
  59. var preserveScroll = false;
  60. var isPanel = $ax.public.fn.IsDynamicPanel(axObj.type);
  61. var isLayer = $ax.public.fn.IsLayer(axObj.type);
  62. if(!options.noContainer && (isPanel || isLayer)) {
  63. //if dp has scrollbar, save its scroll position
  64. if(isPanel && axObj.scrollbars != 'none') {
  65. var shownState = $ax.dynamicPanelManager.getShownState(elementId);
  66. preserveScroll = true;
  67. //before hiding, try to save scroll location
  68. if(!options.value && shownState) {
  69. DPStateAndScroll[elementId] = {
  70. shownId: shownState.attr('id'),
  71. left: shownState.scrollLeft(),
  72. top: shownState.scrollTop()
  73. }
  74. }
  75. }
  76. _pushContainer(elementId, isPanel);
  77. if(isPanel && !options.value) _tryResumeScrollForDP(elementId);
  78. var complete = options.onComplete;
  79. options.onComplete = function () {
  80. if(complete) complete();
  81. _popContainer(elementId, isPanel);
  82. //using containers stops mouseleave from firing on IE/Edge and FireFox
  83. if(!options.value && $ax.event.mouseOverObjectId && (FIREFOX || $axure.browser.isEdge || IE)) {
  84. var mouseOveredElement = $('#' + $ax.event.mouseOverObjectId);
  85. if(mouseOveredElement && !mouseOveredElement.is(":visible")) {
  86. var axObj = $obj($ax.event.mouseOverObjectId);
  87. if(($ax.public.fn.IsDynamicPanel(axObj.type) || $ax.public.fn.IsLayer(axObj.type) || $ax.public.fn.IsRepeater(axObj.type)) && axObj.propagate) {
  88. mouseOveredElement.trigger('mouseleave');
  89. } else mouseOveredElement.trigger('mouseleave.ixStyle');
  90. }
  91. }
  92. //after showing dp, restore the scoll position
  93. if(isPanel && options.value) _tryResumeScrollForDP(elementId, true);
  94. }
  95. options.containerExists = true;
  96. }
  97. _setVisibility(parentId, elementId, options, preserveScroll);
  98. //set the visibility of the annotation box as well if it exists
  99. var ann = document.getElementById(elementId + "_ann");
  100. if(ann) {
  101. _visibility.SetVisible(ann, options.value);
  102. var jAnn = $("#" + elementId + "_ann");
  103. if(_pageNotesEnabled) jAnn.show();
  104. else jAnn.hide();
  105. }
  106. //set ref visibility for ref of flow shape, if that exists
  107. var ref = document.getElementById(elementId + '_ref');
  108. if(ref) _visibility.SetVisible(ref, options.value);
  109. if(options.value && !MOBILE_DEVICE && $ax.adaptive.isDeviceMode()) _updateMobileScrollForWidgetShown(axObj);
  110. };
  111. var _updateMobileScrollForWidgetShown = function(widget) {
  112. var isPanel = $ax.public.fn.IsDynamicPanel(widget.type);
  113. var isLayer = $ax.public.fn.IsLayer(widget.type);
  114. if (isPanel) {
  115. var elementId = $id(widget);
  116. var stateId = $ax.repeater.applySuffixToElementId(elementId, '_state0');
  117. $ax.dynamicPanelManager.updateMobileScroll(elementId, stateId, true);
  118. if (!widget.diagrams) return;
  119. for (var i = 0; i < widget.diagrams.length; ++i) {
  120. var diagram = widget.diagrams[i];
  121. if (!diagram.objects) continue;
  122. for (var j = 0; j < diagram.objects.length; ++j) {
  123. _updateMobileScrollForWidgetShown(diagram.objects[j]);
  124. }
  125. }
  126. } else if (isLayer) {
  127. for (var i = 0; i < widget.objs.length; ++i) {
  128. _updateMobileScrollForWidgetShown(widget.objs[i]);
  129. }
  130. }
  131. }
  132. var _setVisibility = function(parentId, childId, options, preserveScroll) {
  133. var wrapped = $jobj(childId);
  134. var completeTotal = 1;
  135. var visible = $ax.visibility.IsIdVisible(childId);
  136. if(visible == options.value) {
  137. options.onComplete && options.onComplete();
  138. $ax.action.fireAnimationFromQueue(childId, $ax.action.queueTypes.fade);
  139. return;
  140. }
  141. var child = $jobj(childId);
  142. var size = options.size || (options.containerExists ? $(child.children()[0]) : child);
  143. var isIdFitToContent = $ax.dynamicPanelManager.isIdFitToContent(parentId);
  144. //fade and resize won't work together when there is a container... but we still needs the container for fit to content DPs
  145. var needContainer = options.easing && options.easing != 'none' && ((options.easing != 'fade' && options.easing != 'scale' && options.easing != 'fadeAndScale') || isIdFitToContent);
  146. var cullPosition = options.cull ? options.cull.css('position') : '';
  147. var containerExists = options.containerExists;
  148. var isFullWidth = $ax.dynamicPanelManager.isPercentWidthPanel($obj(childId));
  149. // If fixed fit to content panel, then we must set size on it. It will be size of 0 otherwise, because container in it is absolute position.
  150. var needSetSize = false;
  151. var sizeObj = {};
  152. if(needContainer) {
  153. var sizeId = '';
  154. if($ax.dynamicPanelManager.isIdFitToContent(childId)) sizeId = childId;
  155. else {
  156. var panelId = $ax.repeater.removeSuffixFromElementId(childId);
  157. if($ax.dynamicPanelManager.isIdFitToContent(panelId)) sizeId = panelId;
  158. }
  159. if(sizeId) {
  160. needSetSize = true;
  161. sizeObj = $jobj(sizeId);
  162. var newSize = options.cull || sizeObj;
  163. var newAxSize = $ax('#' + newSize.attr('id'));
  164. sizeObj.width(newAxSize.width());
  165. sizeObj.height(newAxSize.height());
  166. }
  167. }
  168. var wrappedOffset = { left: 0, top: 0 };
  169. var visibleWrapped = wrapped;
  170. if(needContainer) {
  171. var childObj = $obj(childId);
  172. if (options.cull) {
  173. var axCull = $ax('#' + options.cull.attr('id'));
  174. var containerWidth = axCull.width();
  175. var containerHeight = axCull.height();
  176. } else {
  177. if (childObj && ($ax.public.fn.IsLayer(childObj.type))) {// || childObj.generateCompound)) {
  178. var boundingRectangle = $ax('#' + childId).offsetBoundingRect();
  179. //var boundingRectangle = $ax.public.fn.getWidgetBoundingRect(childId);
  180. wrappedOffset.left = boundingRectangle.left;
  181. wrappedOffset.top = boundingRectangle.top;
  182. containerWidth = boundingRectangle.width;
  183. containerHeight = boundingRectangle.height;
  184. } else if (childObj && childObj.generateCompound) {
  185. var image = $jobj(childId + '_img');
  186. containerWidth = $ax.getNumFromPx(image.css('width'));
  187. containerHeight = $ax.getNumFromPx(image.css('height'));
  188. wrappedOffset.left = $ax.getNumFromPx(image.css('left'));
  189. wrappedOffset.top = $ax.getNumFromPx(image.css('top'));
  190. } else {
  191. containerWidth = $ax('#' + childId).width();
  192. containerHeight = $ax('#' + childId).height();
  193. }
  194. }
  195. var containerId = $ax.visibility.applyWidgetContainer(childId);
  196. // var container = _makeContainer(containerId, options.cull || boundingRectangle, isFullWidth, options.easing == 'flip', wrappedOffset, options.containerExists);
  197. var container = _makeContainer(containerId, containerWidth, containerHeight, isFullWidth, options.easing == 'flip', wrappedOffset, options.containerExists);
  198. if(options.containInner) {
  199. wrapped = _wrappedChildren(containerExists ? $(child.children()[0]) : child);
  200. // Filter for visibile wrapped children
  201. visibleWrapped = [];
  202. for (var i = 0; i < wrapped.length; i++) if($ax.visibility.IsVisible(wrapped[i])) visibleWrapped.push(wrapped[i]);
  203. visibleWrapped = $(visibleWrapped);
  204. completeTotal = visibleWrapped.length;
  205. if(!containerExists) container.prependTo(child);
  206. // Offset items if necessary
  207. if(!containerExists && (wrappedOffset.left != 0 || wrappedOffset.top != 0)) {
  208. for(var i = 0; i < wrapped.length; i++) {
  209. var inner = $(wrapped[i]);
  210. inner.css('left', $ax.getNumFromPx(inner.css('left')) - wrappedOffset.left);
  211. inner.css('top', $ax.getNumFromPx(inner.css('top')) - wrappedOffset.top);
  212. // Parent layer is now size 0, so have to have to use conatiner since it's the real size.
  213. // Should we use container all the time? This may make things easier for fit panels too.
  214. size = container;
  215. }
  216. }
  217. } else if(!containerExists) container.insertBefore(child);
  218. if(!containerExists) wrapped.appendTo(container);
  219. if (options.value && options.containInner) {
  220. //has to set children first because flip to show needs children invisible
  221. _setAllVisible(visibleWrapped, false);
  222. //_updateChildAlignment(childId);
  223. _setAllVisible(child, true);
  224. }
  225. }
  226. var completeCount = 0;
  227. var onComplete = function () {
  228. completeCount++;
  229. if (needContainer && completeCount == completeTotal) {
  230. if ($ax.public.fn.isCompoundVectorHtml(container.parent()[0])) {
  231. wrappedOffset.left = $ax.getNumFromPx(container.css('left'));
  232. wrappedOffset.top = $ax.getNumFromPx(container.css('top'));
  233. }
  234. if (options.containInner && !containerExists) {
  235. if (wrappedOffset.left != 0 || wrappedOffset.top != 0) {
  236. for (i = 0; i < wrapped.length; i++) {
  237. inner = $(wrapped[i]);
  238. if (!inner.hasClass('text')) {
  239. inner.css('left', $ax.getNumFromPx(inner.css('left')) + wrappedOffset.left);
  240. inner.css('top', $ax.getNumFromPx(inner.css('top')) + wrappedOffset.top);
  241. }
  242. }
  243. }
  244. wrapped.filter('.text').css({ 'left': '', 'top': '' });
  245. }
  246. if(options.containInner && !options.value) {
  247. _setAllVisible(child, false);
  248. _setAllVisible(visibleWrapped, true);
  249. }
  250. if(containerExists) {
  251. if(!options.settingChild) container.css('position', 'relative;');
  252. } else {
  253. wrapped.insertBefore(container);
  254. container.remove();
  255. }
  256. if(childObj && $ax.public.fn.IsDynamicPanel(childObj.type) && window.modifiedDynamicPanleParentOverflowProp) {
  257. child.css('overflow', 'hidden');
  258. window.modifiedDynamicPanleParentOverflowProp = false;
  259. }
  260. }
  261. //if(options.value) _updateChildAlignment(childId);
  262. if(!needContainer || completeTotal == completeCount) {
  263. if(options.cull) options.cull.css('position', cullPosition);
  264. if(needSetSize) {
  265. sizeObj.css('width', 'auto');
  266. sizeObj.css('height', 'auto');
  267. }
  268. options.onComplete && options.onComplete();
  269. if(options.fire) {
  270. $ax.event.raiseSyntheticEvent(childId, options.value ? 'onShow' : 'onHide');
  271. $ax.action.fireAnimationFromQueue(childId, $ax.action.queueTypes.fade);
  272. }
  273. }
  274. };
  275. // Nothing actually being animated, all wrapped elements invisible
  276. if(!visibleWrapped.length) {
  277. if(!options.easing || options.easing == 'none') {
  278. $ax.visibility.SetIdVisible(childId, options.value);
  279. completeTotal = 1;
  280. onComplete();
  281. } else {
  282. window.setTimeout(function() {
  283. completeCount = completeTotal - 1;
  284. onComplete();
  285. },options.duration);
  286. }
  287. return;
  288. }
  289. if (!options.easing || options.easing == 'none') {
  290. $ax.visibility.SetIdVisible(childId, options.value);
  291. completeTotal = 1;
  292. onComplete();
  293. } else if (options.easing == 'scale' || options.easing == 'fadeAndScale') {
  294. var withFade = options.easing == 'fadeAndScale';
  295. var transformOrigin = visibleWrapped.css('transform-origin');
  296. var transform = visibleWrapped.css('transform');
  297. var opacity = visibleWrapped.css('opacity');
  298. visibleWrapped.css('transform-origin', options.scaleAnchor);
  299. if (options.value) {
  300. visibleWrapped.css('visibility', 'inherit');
  301. visibleWrapped.css('display', 'flex');
  302. }
  303. $({ offset: 0 }).animate({ offset: 1 }, {
  304. duration: options.duration,
  305. easing: options.animation,
  306. queue: false,
  307. step: function (now, fx) {
  308. var scale;
  309. if (options.value) scale = now + options.scale - now * options.scale;
  310. else scale = 1 - now + now * options.scale;
  311. visibleWrapped.css('transform', 'scale(' + scale + ')');
  312. if (withFade) {
  313. var opacity;
  314. if (options.value) opacity = now;
  315. else opacity = 1 - now;
  316. visibleWrapped.css('opacity', opacity);
  317. }
  318. },
  319. complete: function () {
  320. $ax.visibility.SetIdVisible(childId, options.value);
  321. visibleWrapped.css('transform', transform);
  322. visibleWrapped.css('opacity', opacity);
  323. visibleWrapped.css('transform-origin', transformOrigin);
  324. onComplete();
  325. },
  326. });
  327. } else if (options.easing == 'fade') {
  328. if(options.value) {
  329. if(preserveScroll) {
  330. visibleWrapped.css('opacity', 0);
  331. visibleWrapped.css('visibility', 'inherit');
  332. visibleWrapped.css('display', 'block');
  333. //was hoping we could just use fadein here, but need to set display before set scroll position
  334. _tryResumeScrollForDP(childId);
  335. visibleWrapped.animate({ opacity: 1 }, {
  336. duration: options.duration,
  337. easing: options.animation,
  338. queue: false,
  339. complete: function() {
  340. $ax.visibility.SetIdVisible(childId, true);
  341. visibleWrapped.css('opacity', '');
  342. onComplete();
  343. }
  344. });
  345. } else {
  346. // Can't use $ax.visibility.SetIdVisible, because we only want to set visible, we don't want to set display, fadeIn will handle that.
  347. visibleWrapped.css('visibility', 'inherit');
  348. visibleWrapped.fadeIn({
  349. queue: false,
  350. duration: options.duration,
  351. easing: options.animation,
  352. complete: onComplete
  353. });
  354. }
  355. } else {
  356. // Fading here is being strange...
  357. visibleWrapped.animate({ opacity: 0 }, {
  358. duration: options.duration,
  359. easing: options.animation,
  360. queue: false,
  361. complete: function () {
  362. $ax.visibility.SetIdVisible(childId, false);
  363. visibleWrapped.css('opacity', '');
  364. onComplete();
  365. }
  366. });
  367. }
  368. } else if (options.easing == 'flip') {
  369. //this container will hold
  370. var trapScroll = _trapScrollLoc(parentId);
  371. var innerContainer = $('<div></div>');
  372. innerContainer.attr('id', containerId + "_inner");
  373. innerContainer.data('flip', options.direction == 'left' || options.direction == 'right' ? 'y' : 'x');
  374. innerContainer.css({
  375. position: 'relative',
  376. 'width': containerWidth,
  377. 'height': containerHeight,
  378. 'display': 'flex'
  379. });
  380. innerContainer.appendTo(container);
  381. wrapped.appendTo(innerContainer);
  382. if(childObj && $ax.public.fn.IsDynamicPanel(childObj.type)) var containerDiv = child;
  383. else containerDiv = parentId ? $jobj(parentId) : child.parent();
  384. completeTotal = 1;
  385. var flipdegree;
  386. var originForFlip = containerWidth / 2 + 'px ' + containerHeight / 2 + 'px';
  387. if (options.value) {
  388. innerContainer.css({
  389. '-webkit-transform-origin': originForFlip,
  390. '-ms-transform-origin': originForFlip,
  391. 'transform-origin': originForFlip,
  392. });
  393. //options.value == true means in or show, note to get here, the element must be currently hidden to show,
  394. // we need to first flip it +/- 90deg without animation (180 if we want to show the back of the flip)
  395. switch(options.direction) {
  396. case 'right':
  397. case 'left':
  398. _setRotateTransformation(innerContainer, _getRotateString(true, options.direction === 'right', options.showFlipBack));
  399. flipdegree = 'rotateY(0deg)';
  400. break;
  401. case 'up':
  402. case 'down':
  403. _setRotateTransformation(innerContainer, _getRotateString(false, options.direction === 'up', options.showFlipBack));
  404. flipdegree = 'rotateX(0deg)';
  405. break;
  406. }
  407. var onFlipShowComplete = function () {
  408. // return the scroll position to the correct location after unexpected reset of the scroll to the top after multiple flip-animation compliting. RP-2192
  409. var preventNextScroll = function () {
  410. var preventFunc = function (e) {
  411. trapScroll();
  412. e.preventDefault();
  413. window.removeEventListener("scroll", preventFunc);
  414. }
  415. window.addEventListener("scroll", preventFunc);
  416. }
  417. var trapScroll = _trapScrollLoc(parentId);
  418. $ax.visibility.SetIdVisible(childId, true);
  419. wrapped.insertBefore(innerContainer);
  420. innerContainer.remove();
  421. trapScroll();
  422. onComplete();
  423. preventNextScroll();
  424. };
  425. innerContainer.css({
  426. '-webkit-backface-visibility': 'hidden',
  427. 'backface-visibility': 'hidden'
  428. });
  429. child.css({
  430. 'display': '',
  431. 'visibility': 'inherit'
  432. });
  433. visibleWrapped.css({
  434. 'display': '',
  435. 'visibility': 'inherit'
  436. });
  437. innerContainer.css({
  438. '-webkit-transition-duration': options.duration + 'ms',
  439. 'transition-duration': options.duration + 'ms'
  440. });
  441. if(preserveScroll) _tryResumeScrollForDP(childId);
  442. _setRotateTransformation(innerContainer, flipdegree, containerDiv, onFlipShowComplete, options.duration, true);
  443. } else { //hide or out
  444. innerContainer.css({
  445. '-webkit-transform-origin': originForFlip,
  446. '-ms-transform-origin': originForFlip,
  447. 'transform-origin': originForFlip,
  448. });
  449. switch(options.direction) {
  450. case 'right':
  451. case 'left':
  452. flipdegree = _getRotateString(true, options.direction !== 'right', options.showFlipBack);
  453. break;
  454. case 'up':
  455. case 'down':
  456. flipdegree = _getRotateString(false, options.direction !== 'up', options.showFlipBack);
  457. break;
  458. }
  459. var onFlipHideComplete = function() {
  460. var trapScroll = _trapScrollLoc(parentId);
  461. wrapped.insertBefore(innerContainer);
  462. $ax.visibility.SetIdVisible(childId, false);
  463. innerContainer.remove();
  464. trapScroll();
  465. onComplete();
  466. };
  467. innerContainer.css({
  468. '-webkit-backface-visibility': 'hidden',
  469. 'backface-visibility': 'hidden',
  470. '-webkit-transition-duration': options.duration + 'ms',
  471. 'transition-duration': options.duration + 'ms'
  472. });
  473. if(preserveScroll) _tryResumeScrollForDP(childId);
  474. _setRotateTransformation(innerContainer, flipdegree, containerDiv, onFlipHideComplete, options.duration, true);
  475. }
  476. trapScroll();
  477. } else {
  478. // Because the move is gonna fire on annotation and ref too, need to update complete total
  479. completeTotal = $addAll(visibleWrapped, childId).length;
  480. if(options.value) {
  481. _slideStateIn(childId, childId, options, size, false, onComplete, visibleWrapped, preserveScroll);
  482. } else {
  483. var tops = [];
  484. var lefts = [];
  485. for(var i = 0; i < visibleWrapped.length; i++) {
  486. var currWrapped = $(visibleWrapped[i]);
  487. tops.push(fixAuto(currWrapped, 'top'));
  488. lefts.push(fixAuto(currWrapped, 'left'));
  489. }
  490. var onOutComplete = function () {
  491. //bring back SetIdVisible on childId for hiding lightbox
  492. $ax.visibility.SetIdVisible(childId, false);
  493. for(i = 0; i < visibleWrapped.length; i++) {
  494. currWrapped = $(visibleWrapped[i]);
  495. $ax.visibility.SetVisible(currWrapped[0], false);
  496. currWrapped.css('top', tops[i]);
  497. currWrapped.css('left', lefts[i]);
  498. }
  499. onComplete();
  500. };
  501. _slideStateOut(size, childId, options, onOutComplete, visibleWrapped);
  502. }
  503. }
  504. // If showing, go through all rich text objects inside you, and try to redo alignment of them
  505. //if(options.value && !options.containInner) {
  506. // _updateChildAlignment(childId);
  507. //}
  508. };
  509. // IE/Safari are giving auto here instead of calculating to for us. May need to calculate this eventually, but for now we can assume auto === 0px for the edge case found
  510. var fixAuto = function (jobj, prop) {
  511. var val = jobj.css(prop);
  512. return val == 'auto' ? '0px' : val;
  513. };
  514. var _getRotateString = function (y, neg, showFlipBack) {
  515. // y means flip on y axis, or left/right, neg means flipping it left/down, and show back is for set panel state
  516. // and will show the back of the widget (transparent) for the first half of a show, or second half of a hide.
  517. return 'rotate' + (y ? 'Y' : 'X') + '(' + (neg ? '-' : '') + (showFlipBack ? 180 : IE ? 91 : 90) + 'deg)';
  518. }
  519. //var _updateChildAlignment = function(childId) {
  520. // var descendants = $jobj(childId).find('.text');
  521. // for(var i = 0; i < descendants.length; i++) $ax.style.updateTextAlignmentForVisibility(descendants[i].id);
  522. //};
  523. var _wrappedChildren = function (child) {
  524. return child.children();
  525. //var children = child.children();
  526. //var valid = [];
  527. //for(var i = 0; i < children.length; i++) if($ax.visibility.IsVisible(children[i])) valid.push(children[i]);
  528. //return $(valid);
  529. };
  530. var requestAnimationFrame = window.requestAnimationFrame ||
  531. window.webkitRequestAnimationFrame ||
  532. window.mozRequestAnimationFrame || window.msRequestAnimationFrame ||
  533. function (callback) {
  534. window.setTimeout(callback, 1000 / 60);
  535. };
  536. var _setRotateTransformation = function(elementsToSet, transformValue, elementParent, flipCompleteCallback, flipDurationMs, useAnimationFrame) {
  537. if(flipCompleteCallback) {
  538. //here we didn't use 'transitionend' event to fire callback
  539. //when show/hide on one element, changing transition property will stop the event from firing
  540. window.setTimeout(flipCompleteCallback, flipDurationMs);
  541. }
  542. var trasformCss = {
  543. '-webkit-transform': transformValue,
  544. '-moz-transform': transformValue,
  545. '-ms-transform': transformValue,
  546. '-o-transform': transformValue,
  547. 'transform': transformValue
  548. };
  549. if(useAnimationFrame) {
  550. if(FIREFOX || CHROME) $('body').hide().show(0); //forces FF to render the animation
  551. requestAnimationFrame(function() {
  552. elementsToSet.css(trasformCss);
  553. });
  554. } else elementsToSet.css(trasformCss);
  555. //when deal with dynamic panel, we need to set it's parent's overflow to visible to have the 3d effect
  556. //NOTE: we need to set this back when both flips finishes in DP, to prevents one animation finished first and set this back
  557. if(elementParent && elementParent.css('overflow') === 'hidden') {
  558. elementParent.css('overflow', 'visible');
  559. window.modifiedDynamicPanleParentOverflowProp = true;
  560. }
  561. };
  562. $ax.visibility.GetPanelState = function(id) {
  563. var children = $ax.visibility.getRealChildren($jobj(id).children());
  564. for(var i = 0; i < children.length; i++) {
  565. if(children[i].style && $ax.visibility.IsVisible(children[i])) return children[i].id;
  566. }
  567. return '';
  568. };
  569. $ax.visibility.GetCurrentPanelDiagram = function (id) {
  570. var obj = $obj(id);
  571. if ($ax.public.fn.IsDynamicPanel(obj.type) && obj.diagrams && obj.diagrams.length > 0) {
  572. var stateId = $ax.visibility.GetPanelState(id);
  573. var stateLabel = $jobj(stateId).data('label');
  574. return obj.diagrams.find(x => x.label === stateLabel);
  575. }
  576. return null;
  577. };
  578. var containerCount = {};
  579. $ax.visibility.SetPanelState = function(id, stateId, animationOutInfo, animationInInfo, showWhenSet) {
  580. var show = !$ax.visibility.IsIdVisible(id) && showWhenSet;
  581. if(show) $ax.visibility.SetIdVisible(id, true);
  582. // Exit here if already at desired state.
  583. if($ax.visibility.IsIdVisible(stateId)) {
  584. if(show) {
  585. $ax.event.raiseSyntheticEvent(id, 'onShow');
  586. // If showing size changes and need to update parent panels
  587. $ax.dynamicPanelManager.fitParentPanel(id);
  588. }
  589. $ax.action.fireAnimationFromQueue(id, $ax.action.queueTypes.setState);
  590. return;
  591. }
  592. var hasEasing = animationInInfo.easingType != 'none' || animationOutInfo.easingType != 'none';
  593. if(hasEasing) _pushContainer(id, true);
  594. var state = $jobj(stateId);
  595. var oldStateId = $ax.visibility.GetPanelState(id);
  596. var oldState = $jobj(oldStateId);
  597. var isFixed = $jobj(id).css('position') == 'fixed';
  598. //pin to browser
  599. if(isFixed) $ax.dynamicPanelManager.adjustFixed(id, oldState.width(), oldState.height(), state.width(), state.height());
  600. _bringPanelStateToFront(id, stateId, oldStateId, animationInInfo.easingType == 'none' || animationInInfo.duration == '0');
  601. var fitToContent = $ax.dynamicPanelManager.isIdFitToContent(id);
  602. var resized = false;
  603. if(fitToContent) {
  604. // Set resized
  605. //var width = state.width();
  606. //var height = state.height();
  607. var newBoundingRect = $ax('#' + stateId).childrenBoundingRect();
  608. var width = newBoundingRect.right;
  609. var height = newBoundingRect.bottom;
  610. var oldBoundingRect = $ax('#' + id).offsetBoundingRect();
  611. var oldWidth = oldBoundingRect.right;
  612. var oldHeight = oldBoundingRect.bottom;
  613. resized = width != oldWidth || height != oldHeight;
  614. //resized = width != oldState.width() || height != oldState.height();
  615. $ax.visibility.setResizedSize(id, $obj(id).percentWidth ? oldWidth : width, height);
  616. $ax.visibility.setResizingRect(id, oldBoundingRect);
  617. }
  618. //edge case for sliding
  619. var movement = (animationOutInfo.direction == 'left' || animationOutInfo.direction == 'up' || state.children().length == 0) && oldState.children().length != 0 ? oldState : state;
  620. var onCompleteCount = 0;
  621. var onComplete = function () {
  622. //move this call from _setVisibility() for animate out.
  623. //Because this will make the order of dp divs consistence: the showing panel is always in front after both animation finished
  624. //tested in the cases where one panel is out/show slower/faster/same time/instantly.
  625. _bringPanelStateToFront(id, stateId, oldStateId, false);
  626. if (window.modifiedDynamicPanleParentOverflowProp) {
  627. var parent = id ? $jobj(id) : child.parent();
  628. parent.css('overflow', 'hidden');
  629. window.modifiedDynamicPanleParentOverflowProp = false;
  630. }
  631. $ax.dynamicPanelManager.fitParentPanel(id);
  632. $ax.dynamicPanelManager.updatePanelPercentWidth(id);
  633. $ax.dynamicPanelManager.updatePanelContentPercentWidth(id);
  634. $ax.action.fireAnimationFromQueue(id, $ax.action.queueTypes.setState);
  635. $ax.event.raiseSyntheticEvent(id, "onPanelStateChange");
  636. $ax.event.leavingState(oldStateId);
  637. if (hasEasing) _popContainer(id, true);
  638. $ax.dynamicPanelManager.updateMobileScroll(id, stateId, true);
  639. };
  640. // Must do state out first, so if we cull by new state, location is correct
  641. _setVisibility(id, oldStateId, {
  642. value: false,
  643. easing: animationOutInfo.easingType,
  644. direction: animationOutInfo.direction,
  645. duration: animationOutInfo.duration,
  646. animation: animationOutInfo.animation,
  647. scale: animationOutInfo.scale,
  648. scaleAnchor: animationOutInfo.scaleAnchor,
  649. containerExists: true,
  650. onComplete: function() {
  651. if (++onCompleteCount == 2) onComplete();
  652. },
  653. settingChild: true,
  654. size: movement,
  655. //cull for
  656. cull: animationOutInfo.easingType == 'none' || state.children().length == 0 ? oldState : state,
  657. showFlipBack: true
  658. });
  659. _setVisibility(id, stateId, {
  660. value: true,
  661. easing: animationInInfo.easingType,
  662. direction: animationInInfo.direction,
  663. duration: animationInInfo.duration,
  664. animation: animationInInfo.animation,
  665. scale: animationInInfo.scale,
  666. scaleAnchor: animationInInfo.scaleAnchor,
  667. containerExists: true,
  668. onComplete: function () {
  669. if (++onCompleteCount == 2) onComplete();
  670. },
  671. settingChild: true,
  672. //size for offset
  673. size: movement,
  674. showFlipBack: true
  675. });
  676. if(show) $ax.event.raiseSyntheticEvent(id, 'onShow');
  677. if(resized) $ax.event.raiseSyntheticEvent(id, 'onResize');
  678. };
  679. var containedFixed = {};
  680. var _pushContainer = _visibility.pushContainer = function(id, panel) {
  681. var count = containerCount[id];
  682. if(count) containerCount[id] = count + 1;
  683. else {
  684. var trapScroll = _trapScrollLoc(id);
  685. var jobj = $jobj(id);
  686. var children = jobj.children();
  687. var css = {
  688. position: 'relative',
  689. top: 0,
  690. left: 0
  691. };
  692. if(!panel) {
  693. var boundingRect = $ax('#' + id).offsetBoundingRect();
  694. //var boundingRect = $axure.fn.getWidgetBoundingRect(id);
  695. css.top = boundingRect.top;
  696. css.left = boundingRect.left;
  697. }
  698. var container = $('<div></div>');
  699. container.attr('id', ''); // Placeholder id, so we won't try to recurse the container until it is ready
  700. container.css(css);
  701. //container.append(jobj.children());
  702. jobj.append(container);
  703. containerCount[id] = 1;
  704. // Panel needs to wrap children
  705. if(panel) {
  706. for(var i = 0; i < children.length; i++) {
  707. var child = $(children[i]);
  708. var childContainer = $('<div></div>');
  709. childContainer.attr('id', $ax.visibility.applyWidgetContainer(child.attr('id')));
  710. childContainer.css(css);
  711. child.after(childContainer);
  712. childContainer.append(child);
  713. container.append(childContainer);
  714. }
  715. } else {
  716. var focus = _getCurrFocus();
  717. if(focus) $ax.event.addSuppressedEvent($ax.repeater.removeSuffixFromElementId(focus), 'OnLostFocus');
  718. // Layer needs to fix top left
  719. var childIds = $ax('#' + id).getChildren()[0].children;
  720. for(var i = 0; i < childIds.length; i++) {
  721. var childId = childIds[i];
  722. var childObj = $jobj(childId);
  723. var fixedInfo = $ax.dynamicPanelManager.getFixedInfo(childId);
  724. if(fixedInfo.fixed) {
  725. var axObj = $ax('#' + childId);
  726. var viewportLocation = axObj.viewportLocation();
  727. var left = viewportLocation.left;
  728. var top = viewportLocation.top;
  729. //var left = axObj.left();
  730. //var top = axObj.top();
  731. containedFixed[childId] = { left: left, top: top, fixed: fixedInfo };
  732. childObj.css('left', left);
  733. childObj.css('top', top);
  734. childObj.css('margin-left', 0);
  735. childObj.css('margin-top', 0);
  736. childObj.css('right', 'auto');
  737. childObj.css('bottom', 'auto');
  738. childObj.css('position', 'absolute');
  739. }
  740. var cssChange = {
  741. left: '-=' + css.left,
  742. top: '-=' + css.top
  743. };
  744. if($ax.public.fn.IsLayer($ax.getTypeFromElementId(childId))) {
  745. _pushContainer(childId, false);
  746. $ax.visibility.applyWidgetContainer(childId, true).css(cssChange);
  747. } else {
  748. //if ($ax.public.fn.isCompoundVectorHtml(jobj[0])) {
  749. // var grandChildren = jobj[0].children;
  750. // //while (grandChildren.length > 0 && grandChildren[0].id.indexOf('container') >= 0) grandChildren = grandChildren[0].children;
  751. // for (var j = 0; j < grandChildren.length; j++) {
  752. // var grandChildId = grandChildren[j].id;
  753. // if (grandChildId.indexOf(childId + 'p') >= 0 || grandChildId.indexOf('_container') >= 0) $jobj(grandChildId).css(cssChange);
  754. // }
  755. //} else
  756. // Need to include ann and ref in move.
  757. childObj = $addAll(childObj, childId);
  758. childObj.css(cssChange);
  759. }
  760. container.append(childObj);
  761. }
  762. _setCurrFocus(focus);
  763. }
  764. container.attr('id', $ax.visibility.applyWidgetContainer(id)); // Setting the correct final id for the container
  765. trapScroll();
  766. }
  767. };
  768. var _popContainer = _visibility.popContainer = function (id, panel) {
  769. var count = containerCount[id];
  770. if(!count) return;
  771. count--;
  772. containerCount[id] = count;
  773. if(count != 0) return;
  774. var trapScroll = _trapScrollLoc(id);
  775. var jobj = $jobj(id);
  776. var container = $ax.visibility.applyWidgetContainer(id, true);
  777. // If layer is at bottom or right of page, unwrapping could change scroll by temporarily reducting page size.
  778. // To avoid this, we let container persist on page, with the size it is at this point, and don't remove container completely
  779. // until the children are back to their proper locations.
  780. var size = $ax('#' + id).size();
  781. container.css('width', size.width);
  782. container.css('height', size.height);
  783. var focus = _getCurrFocus();
  784. if(focus) $ax.event.addSuppressedEvent($ax.repeater.removeSuffixFromElementId(focus), 'OnLostFocus');
  785. jobj.append(container.children());
  786. _setCurrFocus(focus);
  787. $('body').first().append(container);
  788. // Layer doesn't have children containers to clean up
  789. if(panel) {
  790. var children = jobj.children();
  791. for(var i = 0; i < children.length; i++) {
  792. var childContainer = $(children[i]);
  793. var child = $(childContainer.children()[0]);
  794. childContainer.after(child);
  795. childContainer.remove();
  796. }
  797. } else {
  798. var left = container.css('left');
  799. var top = container.css('top');
  800. var childIds = $ax('#' + id).getChildren()[0].children;
  801. for (var i = 0; i < childIds.length; i++) {
  802. var childId = childIds[i];
  803. var cssChange = {
  804. left: '+=' + left,
  805. top: '+=' + top
  806. };
  807. if($ax.public.fn.IsLayer($ax.getTypeFromElementId(childId))) {
  808. $ax.visibility.applyWidgetContainer(childId, true).css(cssChange);
  809. _popContainer(childId, false);
  810. } else {
  811. var childObj = $jobj(childId);
  812. // if ($ax.public.fn.isCompoundVectorHtml(jobj[0])) {
  813. // var grandChildren = jobj[0].children;
  814. // //while (grandChildren.length > 0 && grandChildren[0].id.indexOf('container') >= 0) grandChildren = grandChildren[0].children;
  815. // for (var j = 0; j < grandChildren.length; j++) {
  816. // var grandChildId = grandChildren[j].id;
  817. // if (grandChildId.indexOf(childId + 'p') >= 0 || grandChildId.indexOf('_container') >= 0) $jobj(grandChildId).css(cssChange);
  818. // }
  819. //} else
  820. var allObjs = $addAll(childObj, childId); // Just include other objects for initial css. Fixed panels need to be dealt with separately.
  821. allObjs.css(cssChange);
  822. var fixedInfo = containedFixed[childId];
  823. if(fixedInfo) {
  824. delete containedFixed[childId];
  825. childObj.css('position', 'fixed');
  826. var deltaX = $ax.getNumFromPx(childObj.css('left')) - fixedInfo.left;
  827. var deltaY = $ax.getNumFromPx(childObj.css('top')) - fixedInfo.top;
  828. fixedInfo = fixedInfo.fixed;
  829. if(fixedInfo.horizontal == 'left') childObj.css('left', fixedInfo.x + deltaX);
  830. else if(fixedInfo.horizontal == 'center') {
  831. childObj.css('left', '50%');
  832. childObj.css('margin-left', fixedInfo.x + deltaX);
  833. } else {
  834. childObj.css('left', 'auto');
  835. childObj.css('right', fixedInfo.x - deltaX);
  836. }
  837. if(fixedInfo.vertical == 'top') childObj.css('top', fixedInfo.y + deltaY);
  838. else if(fixedInfo.vertical == 'middle') {
  839. childObj.css('top', '50%');
  840. childObj.css('margin-top', fixedInfo.y + deltaY);
  841. } else {
  842. childObj.css('top', 'auto');
  843. childObj.css('bottom', fixedInfo.y - deltaY);
  844. }
  845. $ax.dynamicPanelManager.updatePanelPercentWidth(childId);
  846. $ax.dynamicPanelManager.updatePanelContentPercentWidth(childId);
  847. }
  848. }
  849. }
  850. }
  851. container.remove();
  852. trapScroll();
  853. };
  854. var _trapScrollLoc = function (id) {
  855. var jWindow = $(window);
  856. var windowLoc = {
  857. x: jWindow.scrollLeft(),
  858. y: jWindow.scrollTop()
  859. }
  860. var locs = {};
  861. var states = $jobj(id).find('.panel_state');
  862. for(var i = 0; i < states.length; i++) {
  863. var state = $(states[i]);
  864. locs[state.attr('id')] = { x: state.scrollLeft(), y: state.scrollTop() };
  865. }
  866. return function() {
  867. for(var key in locs) {
  868. var state = $jobj(key);
  869. state.scrollLeft(locs[key].x);
  870. state.scrollTop(locs[key].y);
  871. }
  872. jWindow.scrollLeft(windowLoc.x);
  873. jWindow.scrollTop(windowLoc.y);
  874. };
  875. }
  876. var _getCurrFocus = function () {
  877. // Only care about focused a tags and inputs
  878. var id = window.lastFocusedClickable && window.lastFocusedClickable.id;
  879. if(!id) return id;
  880. var jobj = $(window.lastFocusedClickable);
  881. return jobj.is('a') || jobj.is('input') ? id : '';
  882. }
  883. var _setCurrFocus = function(id) {
  884. if(id) {
  885. // This is really just needed for IE, so if this causes issues on other browsers, try adding that check here
  886. var trap = $ax.event.blockEvent($ax.repeater.removeSuffixFromElementId(id), 'OnFocus');
  887. window.setTimeout(function () {
  888. $jobj(id).focus();
  889. trap();
  890. }, 0);
  891. }
  892. }
  893. //use this to save & restore DP's scroll position when show/hide
  894. //key => dp's id (not state's id, because it seems we can change state while hiding)
  895. //value => first state's id & scroll position
  896. //we only need to store one scroll position for one DP, and remove the key after shown.
  897. var DPStateAndScroll = {}
  898. var _tryResumeScrollForDP = function (dpId, deleteId) {
  899. var scrollObj = DPStateAndScroll[dpId];
  900. if(scrollObj) {
  901. var shownState = document.getElementById(scrollObj.shownId);
  902. if(scrollObj.left) shownState.scrollLeft = scrollObj.left;
  903. if(scrollObj.top) shownState.scrollTop = scrollObj.top;
  904. if(deleteId) delete DPStateAndScroll[dpId];
  905. }
  906. };
  907. // var _makeContainer = function (containerId, rect, isFullWidth, isFlip, offset, containerExists) {
  908. var _makeContainer = function (containerId, width, height, isFullWidth, isFlip, offset, containerExists) {
  909. if(containerExists) var container = $jobj(containerId);
  910. else {
  911. container = $('<div></div>');
  912. container.attr('id', containerId);
  913. }
  914. var css = {
  915. position: 'absolute',
  916. width: width,
  917. height: height,
  918. display: 'flex'
  919. };
  920. if(!containerExists) {
  921. // If container exists, may be busy updating location. Will init and update it correctly.
  922. css.top = offset.top;
  923. css.left = offset.left;
  924. }
  925. if(isFlip) {
  926. css.perspective = '800px';
  927. css.webkitPerspective = "800px";
  928. css.mozPerspective = "800px";
  929. //adding this to make Edge happy
  930. css['transform-style'] = 'preserve-3d';
  931. } else css.overflow = 'hidden';
  932. //perspective on container will give us 3d effect when flip
  933. //if(!isFlip) css.overflow = 'hidden';
  934. // Rect should be a jquery not axquery obj
  935. //_getFixedCss(css, rect.$ ? rect.$() : rect, fixedInfo, isFullWidth);
  936. container.css(css);
  937. return container;
  938. };
  939. var CONTAINER_SUFFIX = _visibility.CONTAINER_SUFFIX = '_container';
  940. var CONTAINER_INNER = CONTAINER_SUFFIX + '_inner';
  941. _visibility.getWidgetFromContainer = function(id) {
  942. var containerIndex = id.indexOf(CONTAINER_SUFFIX);
  943. if(containerIndex == -1) return id;
  944. return id.substr(0, containerIndex) + id.substr(containerIndex + CONTAINER_SUFFIX.length);
  945. };
  946. // Apply container to widget id if necessary.
  947. // returnJobj: True if you want the jquery object rather than id returned
  948. // skipCheck: True if you want the query returned reguardless of container existing
  949. // checkInner: True if inner container should be checked
  950. _visibility.applyWidgetContainer = function (id, returnJobj, skipCheck, checkInner) {
  951. // If container exists, just return (return query if requested)
  952. if(id.indexOf(CONTAINER_SUFFIX) != -1) return returnJobj ? $jobj(id) : id;
  953. // Get desired id, and return it if query is not desired
  954. var containerId = $ax.repeater.applySuffixToElementId(id, checkInner ? CONTAINER_INNER : CONTAINER_SUFFIX);
  955. if(!returnJobj) return containerId;
  956. // If skipping check or container exists, just return innermost container requested
  957. var container = $jobj(containerId);
  958. if(skipCheck || container.length) return container;
  959. // If inner container was not checked, then no more to check, return query for widget
  960. if(!checkInner) return $jobj(id);
  961. // If inner container was checked, check for regular container still
  962. container = $jobj($ax.repeater.applySuffixToElementId(id, CONTAINER_SUFFIX));
  963. return container.length ? container : $jobj(id);
  964. };
  965. _visibility.isContainer = function(id) {
  966. return id.indexOf(CONTAINER_SUFFIX) != -1;
  967. };
  968. _visibility.getRealChildren = function(query) {
  969. while(query.length && $(query[0]).attr('id').indexOf(CONTAINER_SUFFIX) != -1) query = query.children();
  970. return query;
  971. };
  972. //var _getFixedCss = function(css, rect, fixedInfo, isFullWidth) {
  973. // // todo: **mas** make sure this is ok
  974. // if(fixedInfo.fixed) {
  975. // css.position = 'fixed';
  976. // if(fixedInfo.horizontal == 'left') css.left = fixedInfo.x;
  977. // else if(fixedInfo.horizontal == 'center') {
  978. // css.left = isFullWidth ? '0px' : '50%';
  979. // css['margin-left'] = fixedInfo.x;
  980. // } else if(fixedInfo.horizontal == 'right') {
  981. // css.left = 'auto';
  982. // css.right = fixedInfo.x;
  983. // }
  984. // if(fixedInfo.vertical == 'top') css.top = fixedInfo.y;
  985. // else if(fixedInfo.vertical == 'middle') {
  986. // css.top = '50%';
  987. // css['margin-top'] = fixedInfo.y;
  988. // } else if(fixedInfo.vertical == 'bottom') {
  989. // css.top = 'auto';
  990. // css.bottom = fixedInfo.y;
  991. // }
  992. // } else {
  993. // css.left = Number(rect.css('left').replace('px', '')) || 0;
  994. // css.top = Number(rect.css('top').replace('px', '')) || 0;
  995. // }
  996. //};
  997. var _slideStateOut = function (container, stateId, options, onComplete, jobj) {
  998. var directionOut = options.direction;
  999. var axObject = $ax('#' + container.attr('id'));
  1000. var width = axObject.width();
  1001. var height = axObject.height();
  1002. _blockSetMoveIds = true;
  1003. if(directionOut == "right") {
  1004. $ax.move.MoveWidget(stateId, width, 0, options, false, onComplete, false, jobj, true);
  1005. } else if(directionOut == "left") {
  1006. $ax.move.MoveWidget(stateId, -width, 0, options, false, onComplete, false, jobj, true);
  1007. } else if(directionOut == "up") {
  1008. $ax.move.MoveWidget(stateId, 0, -height, options, false, onComplete, false, jobj, true);
  1009. } else if(directionOut == "down") {
  1010. $ax.move.MoveWidget(stateId, 0, height, options, false, onComplete, false, jobj, true);
  1011. }
  1012. _blockSetMoveIds = false;
  1013. };
  1014. var _slideStateIn = function (id, stateId, options, container, makePanelVisible, onComplete, jobj, preserveScroll) {
  1015. var directionIn = options.direction;
  1016. var axObject = $ax('#' +container.attr('id'));
  1017. var width = axObject.width();
  1018. var height = axObject.height();
  1019. if (makePanelVisible) $ax.visibility.SetIdVisible(id, true);
  1020. for (i = 0; i < jobj.length; i++) $ax.visibility.SetVisible(jobj[i], true);
  1021. for(var i = 0; i < jobj.length; i++) {
  1022. var child = $(jobj[i]);
  1023. var oldTop = $ax.getNumFromPx(fixAuto(child, 'top'));
  1024. var oldLeft = $ax.getNumFromPx(fixAuto(child, 'left'));
  1025. if (directionIn == "right") {
  1026. child.css('left', oldLeft - width + 'px');
  1027. } else if(directionIn == "left") {
  1028. child.css('left', oldLeft + width + 'px');
  1029. } else if(directionIn == "up") {
  1030. child.css('top', oldTop + height + 'px');
  1031. } else if(directionIn == "down") {
  1032. child.css('top', oldTop - height + 'px');
  1033. }
  1034. }
  1035. if(preserveScroll) _tryResumeScrollForDP(id);
  1036. _blockSetMoveIds = true;
  1037. if(directionIn == "right") {
  1038. $ax.move.MoveWidget(stateId, width, 0, options, false, onComplete, false, jobj, true);
  1039. } else if(directionIn == "left") {
  1040. $ax.move.MoveWidget(stateId, -width, 0, options, false, onComplete, false, jobj, true);
  1041. } else if(directionIn == "up") {
  1042. $ax.move.MoveWidget(stateId, 0, -height, options, false, onComplete, false, jobj, true);
  1043. } else if(directionIn == "down") {
  1044. $ax.move.MoveWidget(stateId, 0, height, options, false, onComplete, false, jobj, true);
  1045. }
  1046. _blockSetMoveIds = false;
  1047. };
  1048. $ax.visibility.GetPanelStateId = function(dpId, index) {
  1049. var itemNum = $ax.repeater.getItemIdFromElementId(dpId);
  1050. var panelStateId = $ax.repeater.getScriptIdFromElementId(dpId) + '_state' + index;
  1051. return $ax.repeater.createElementId(panelStateId, itemNum);
  1052. };
  1053. $ax.visibility.GetPanelStateCount = function(id) {
  1054. return $ax.visibility.getRealChildren($jobj(id).children()).filter("[id*='_state']").length;
  1055. };
  1056. var _bringPanelStateToFront = function (dpId, stateId, oldStateId, oldInFront) {
  1057. var panel = $jobj(dpId);
  1058. var frontId = oldInFront ? oldStateId : stateId;
  1059. if(containerCount[dpId]) {
  1060. frontId = $ax.visibility.applyWidgetContainer(frontId);
  1061. panel = $ax.visibility.applyWidgetContainer(dpId, true, false, true);
  1062. }
  1063. $jobj(frontId).appendTo(panel);
  1064. //when bring a panel to front, it will be focused, and the previous front panel should fire blur event if it's lastFocusedClickableSelector
  1065. //ie(currently 11) and firefox(currently 34) doesn't fire blur event, this is the hack to fire it manually
  1066. if((IE || FIREFOX) && window.lastFocusedClickable && $ax.event.getFocusableWidgetOrChildId(window.lastFocusedControl) == window.lastFocusedClickable.id) {
  1067. // Only need to do this if the currently focused widget is in the panel state that is being hidden.
  1068. if($jobj(oldStateId).find('#' + window.lastFocusedClickable.id.split('_')[0]).length) $(window.lastFocusedClickable).triggerHandler('blur');
  1069. }
  1070. };
  1071. var _limboIds = _visibility.limboIds = {};
  1072. // limboId's is a dictionary of id->true, essentially a set.
  1073. var _addLimboAndHiddenIds = $ax.visibility.addLimboAndHiddenIds = function(newLimboIds, newHiddenIds, query, skipRepeater) {
  1074. var limboedByMaster = {};
  1075. for(var key in newLimboIds) {
  1076. if (!$ax.public.fn.IsReferenceDiagramObject($ax.getObjectFromElementId(key).type)) continue;
  1077. var ids = $ax.model.idsInRdoToHideOrLimbo(key);
  1078. for(var i = 0; i < ids.length; i++) limboedByMaster[ids[i]] = true;
  1079. }
  1080. //var hiddenByMaster = {};
  1081. //for(key in newHiddenIds) {
  1082. // if (!$ax.public.fn.IsReferenceDiagramObject($ax.getObjectFromElementId(key).type)) continue;
  1083. // ids = $ax.model.idsInRdoToHideOrLimbo(key);
  1084. // for(i = 0; i < ids.length; i++) hiddenByMaster[ids[i]] = true;
  1085. //}
  1086. // Extend with children of rdos
  1087. newLimboIds = $.extend(newLimboIds, limboedByMaster);
  1088. //newHiddenIds = $.extend(newHiddenIds, hiddenByMaster);
  1089. // something is only visible if it's not hidden and limboed
  1090. query.each(function(diagramObject, elementId) {
  1091. // Rdos already handled, contained widgets are limboed by the parent, and sub menus should be ignored
  1092. if(diagramObject.isContained || $ax.public.fn.IsTableCell(diagramObject.type) || $jobj(elementId).hasClass('sub_menu')) return;
  1093. if(diagramObject.type == 'table' && $jobj(elementId).parent().hasClass('ax_menu')) return;
  1094. if(skipRepeater) {
  1095. // Any item in a repeater should return
  1096. if($ax.getParentRepeaterFromElementIdExcludeSelf(elementId)) return;
  1097. }
  1098. var scriptId = $ax.repeater.getScriptIdFromElementId(elementId);
  1099. var shouldBeVisible = Boolean(!newLimboIds[scriptId] && !newHiddenIds[scriptId]);
  1100. var isVisible = Boolean(_isIdVisible(elementId));
  1101. if(shouldBeVisible != isVisible) {
  1102. _setWidgetVisibility(elementId, { value: shouldBeVisible, noContainer: true });
  1103. }
  1104. });
  1105. _limboIds = _visibility.limboIds = $.extend(_limboIds, newLimboIds);
  1106. };
  1107. var _clearLimboAndHidden = $ax.visibility.clearLimboAndHidden = function(ids) {
  1108. _limboIds = _visibility.limboIds = {};
  1109. };
  1110. $ax.visibility.clearLimboAndHiddenIds = function(ids) {
  1111. for(var i = 0; i < ids.length; i++) {
  1112. var scriptId = $ax.repeater.getScriptIdFromElementId(ids[i]);
  1113. delete _limboIds[scriptId];
  1114. }
  1115. };
  1116. $ax.visibility.resetLimboAndHiddenToDefaults = function (query) {
  1117. if(!query) query = $ax('*');
  1118. _clearLimboAndHidden();
  1119. _addLimboAndHiddenIds(_defaultLimbo, _defaultHidden, query);
  1120. };
  1121. $ax.visibility.isScriptIdLimbo = function(scriptId) {
  1122. if(_limboIds[scriptId]) return true;
  1123. var repeater = $ax.getParentRepeaterFromScriptId(scriptId);
  1124. if(!repeater) return false;
  1125. var itemId = $ax.getItemIdsForRepeater(repeater)[0];
  1126. return _limboIds[$ax.repeater.createElementId(scriptId, itemId)];
  1127. }
  1128. $ax.visibility.isElementIdLimboOrInLimboContainer = function (elementId) {
  1129. var parent = document.getElementById(elementId);
  1130. while(parent) {
  1131. var scriptId = $ax.repeater.getScriptIdFromElementId($(parent).attr('id'));
  1132. if(_limboIds[scriptId]) return true;
  1133. parent = parent.parentElement;
  1134. }
  1135. return false;
  1136. }
  1137. var _blockSetMoveIds = false;
  1138. var _movedIds = _visibility.movedIds = {};
  1139. var _resizedIds = _visibility.resizedIds = {};
  1140. var _rotatedIds = _visibility.rotatedIds = {};
  1141. var _resizingIds = _visibility.resizingIds = {};
  1142. $ax.visibility.getMovedLocation = function(scriptId) {
  1143. return _movedIds[scriptId];
  1144. //var repeater = $ax.getParentRepeaterFromScriptId(scriptId);
  1145. //if (!repeater) return false;
  1146. //var itemId = $ax.getItemIdsForRepeater(repeater)[0];
  1147. //return _movedIds[$ax.repeater.createElementId(scriptId, itemId)];
  1148. };
  1149. $ax.visibility.setMovedLocation = function (scriptId, left, top) {
  1150. if ($jobj(scriptId).css('position') == 'fixed') return;
  1151. _movedIds[scriptId] = { left: left, top: top };
  1152. };
  1153. $ax.visibility.moveMovedLocation = function (scriptId, deltaLeft, deltaTop) {
  1154. if(_blockSetMoveIds) return false;
  1155. var offsetLocation = $ax('#' + scriptId).offsetLocation();
  1156. $ax.visibility.setMovedLocation(scriptId, offsetLocation.x + deltaLeft, offsetLocation.y + deltaTop);
  1157. if($ax.public.fn.IsLayer($ax.getTypeFromElementId(scriptId))) {
  1158. var childIds = $ax('#' + scriptId).getChildren()[0].children;
  1159. for (var i = 0; i < childIds.length; i++) {
  1160. $ax.visibility.moveMovedLocation(childIds[i], deltaLeft, deltaTop);
  1161. }
  1162. }
  1163. };
  1164. $ax.visibility.getResizedSize = function(scriptId) {
  1165. return _resizedIds[scriptId];
  1166. //var repeater = $ax.getParentRepeaterFromScriptId(scriptId);
  1167. //if (!repeater) return false;
  1168. //var itemId = $ax.getItemIdsForRepeater(repeater)[0];
  1169. //return _resizedIds[$ax.repeater.createElementId(scriptId, itemId)];
  1170. };
  1171. $ax.visibility.setResizedSize = function(scriptId, width, height) {
  1172. _resizedIds[scriptId] = { width: width, height: height };
  1173. };
  1174. $ax.visibility.getResizingRect = function (scriptId) {
  1175. return _resizingIds[scriptId];
  1176. }
  1177. $ax.visibility.setResizingRect = function (scriptId, offsetBoundingRect) {
  1178. _resizingIds[scriptId] = offsetBoundingRect;
  1179. }
  1180. $ax.visibility.clearResizingRects = function () {
  1181. _resizingIds = _visibility.resizingIds = {};
  1182. }
  1183. $ax.visibility.getRotatedAngle = function (scriptId) {
  1184. return _rotatedIds[scriptId];
  1185. };
  1186. $ax.visibility.setRotatedAngle = function (scriptId, rotation) {
  1187. _rotatedIds[scriptId] = rotation;
  1188. };
  1189. $ax.visibility.clearMovedAndResized = function () {
  1190. _movedIds = _visibility.movedIds = {};
  1191. _resizedIds = _visibility.resizedIds = {};
  1192. _rotatedIds = _visibility.rotatedIds = {};
  1193. _resizingIds = _visibility.resizingIds = {};
  1194. };
  1195. $ax.visibility.clearMovedAndResizedIds = function (elementIds) {
  1196. for (var i = 0; i < elementIds.length; i++) {
  1197. var id = elementIds[i];
  1198. delete _movedIds[id];
  1199. delete _resizedIds[id];
  1200. delete _rotatedIds[id];
  1201. delete _resizingIds[id];
  1202. }
  1203. };
  1204. $ax.visibility.initialize = function() {
  1205. // initialize initial visible states
  1206. $('.' + HIDDEN_CLASS).each(function (index, diagramObject) {
  1207. _defaultHidden[$ax.repeater.getScriptIdFromElementId(diagramObject.id)] = true;
  1208. });
  1209. $('.' + UNPLACED_CLASS).each(function (index, diagramObject) {
  1210. _defaultLimbo[$ax.repeater.getScriptIdFromElementId(diagramObject.id)] = true;
  1211. });
  1212. _addLimboAndHiddenIds(_defaultLimbo, _defaultHidden, $ax('*'), true);
  1213. };
  1214. _visibility.initRepeater = function(repeaterId) {
  1215. var html = $('<div></div>');
  1216. html.append($jobj(repeaterId + '_script').html());
  1217. html.find('.' + HIDDEN_CLASS).each(function (index, element) {
  1218. _defaultHidden[$ax.repeater.getScriptIdFromElementId(element.id)] = true;
  1219. });
  1220. html.find('.' + UNPLACED_CLASS).each(function (index, element) {
  1221. _defaultLimbo[$ax.repeater.getScriptIdFromElementId(element.id)] = true;
  1222. });
  1223. }
  1224. var HIDDEN_CLASS = _visibility.HIDDEN_CLASS = 'ax_default_hidden';
  1225. var UNPLACED_CLASS = _visibility.UNPLACED_CLASS = 'ax_default_unplaced';
  1226. var SELECTED_ClASS = 'selected';
  1227. });