axplayer.js 113 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611
  1. var PAGE_ID_NAME = 'id';
  2. var PAGE_URL_NAME = 'p';
  3. var SITEMAP_COLLAPSE_VAR_NAME = 'c';
  4. var PLUGIN_VAR_NAME = 'g';
  5. var FOOTNOTES_VAR_NAME = 'fn';
  6. var ADAPTIVE_VIEW_VAR_NAME = 'view';
  7. var SCALE_VAR_NAME = 'sc';
  8. var DIM_VAR_NAME = 'dm';
  9. var ROT_VAR_NAME = 'r';
  10. var CLOUD_VAR_NAME = 'cl';
  11. var TRACE_VAR_NAME = 'tr';
  12. var RP_VERSION = 9;
  13. var lastLeftPanelWidth = 220;
  14. var lastRightPanelWidth = 220;
  15. var lastLeftPanelWidthDefault = 220;
  16. var lastRightPanelWidthDefault = 220;
  17. var toolBarOnly = true;
  18. // TODO: need to find a way to get rid of iphone X hacks!!!
  19. // - could possibly have app detect iphone and send information back to player, but currently, that information would arrive too late
  20. var iphoneX = false;
  21. var iphoneXFirstPass = true;
  22. // isolate scope
  23. (function () {
  24. if (!window.$axure) window.$axure = function () { };
  25. if (typeof console == 'undefined') console = {
  26. log: function () { }
  27. };
  28. if (window._axUtils) $axure.utils = _axUtils;
  29. setUpController();
  30. var getHashStringVar = $axure.player.getHashStringVar = function (query) {
  31. var qstring = self.location.href.split("#");
  32. if (qstring.length < 2) return "";
  33. return GetParameter(qstring, query);
  34. }
  35. var isCloud = $axure.player.isCloud = getHashStringVar(CLOUD_VAR_NAME);
  36. if (isCloud) {
  37. $("#topPanel").css('display', 'none');
  38. lastRightPanelWidthDefault = 290;
  39. }else {
  40. $("#topPanel").css('display', '');
  41. }
  42. $axure.loadDocument = function (document) {
  43. $axure.document = document;
  44. var configuration = $axure.document.configuration;
  45. var _settings = {};
  46. _settings.projectId = configuration.prototypeId;
  47. _settings.projectName = configuration.projectName;
  48. _settings.isAxshare = configuration.isAxshare;
  49. _settings.isExpo = configuration.isExpo == null ? false : configuration.isExpo;
  50. _settings.loadSitemap = configuration.loadSitemap;
  51. _settings.loadFeedbackPlugin = configuration.loadFeedbackPlugin;
  52. var cHash = getHashStringVar(SITEMAP_COLLAPSE_VAR_NAME);
  53. _settings.startCollapsed = cHash == "1";
  54. if (cHash == "2") closePlayer();
  55. var gHash = getHashStringVar(PLUGIN_VAR_NAME);
  56. _settings.startPluginGid = gHash;
  57. $axure.player.settings = _settings;
  58. var additionalJs = $axure.document.additionalJs;
  59. if (additionalJs != null) {
  60. var total = additionalJs.length;
  61. if (total > 0) $.holdReady(true);
  62. $.each(additionalJs, function (index, value) {
  63. var script = window.document.createElement("script");
  64. script.type = "text/javascript";
  65. script.src = value;
  66. script.async = false;
  67. script.onload = script.onreadystatechange = function (e) {
  68. if (!script.readyState || /loaded|complete/.test(script.readyState)) {
  69. script.onload = script.onreadystatechange = null;
  70. script = undefined;
  71. }
  72. if (--total == 0) $.holdReady(false);
  73. }
  74. window.document.head.appendChild(script);
  75. });
  76. }
  77. var additionalCss = $axure.document.additionalCss;
  78. if(additionalCss != null) {
  79. $.each(additionalCss, function(index, value) {
  80. var style = window.document.createElement('link');
  81. style.type = "text/css";
  82. style.rel = "stylesheet";
  83. style.href = value;
  84. window.document.head.appendChild(style);
  85. });
  86. }
  87. if(_settings.isExpo && configuration.isMobile) {
  88. initializeDeviceFrame();
  89. }
  90. // Pseudo-indicator that the document has been loaded
  91. $axure.document.isLoaded = true;
  92. };
  93. $(window).bind('load', function () {
  94. if ((CHROME && BROWSER_VERSION < 64) || // First 2018 release
  95. (SAFARI && BROWSER_VERSION < 602) || // Minor version 10
  96. (FIREFOX && BROWSER_VERSION < 57) || // Support Quantum
  97. ($axure.browser.isEdge && BROWSER_VERSION < 15) || // 15 for mobile devices (else could go 16, possibly 17)
  98. (!$axure.browser.isEdge && IE)) {
  99. if (!QQ && !UC) appendOutOfDateNotification();
  100. }
  101. if (CHROME_5_LOCAL && !$('body').attr('pluginDetected')) {
  102. window.location = 'resources/chrome/chrome.html';
  103. }
  104. });
  105. function appendOutOfDateNotification() {
  106. var toAppend = '';
  107. toAppend += '<div id="browserOutOfDateNotification">';
  108. toAppend += ' <div style="font-size: 24px; text-align: center; color: #FFFFFF;">LOOKS LIKE YOUR BROWSER IS OUT OF DATE</div>';
  109. toAppend += ' <div style="font-size: 14px; text-align: center; color: #FFFFFF; margin-bottom: 16px;">This prototype may not look or function correctly until you update your browser</div>';
  110. toAppend += ' <div id="supportedBrowsersListContainer">';
  111. toAppend += ' <div class="browserContainer">';
  112. toAppend += ' <div class="browserName">Google Chrome</div><div class="browserSupportedVersion">v64 and later</div>';
  113. toAppend += ' </div>';
  114. toAppend += ' <div class="browserContainer">';
  115. toAppend += ' <div class="browserName">Mozilla Firefox</div><div class="browserSupportedVersion">v57 and later</div>';
  116. toAppend += ' </div>';
  117. toAppend += ' <div class="browserContainer">';
  118. toAppend += ' <div class="browserName">Microsoft Edge</div><div class="browserSupportedVersion">v15 and later</div>';
  119. toAppend += ' </div>';
  120. toAppend += ' <div class="browserContainer">';
  121. toAppend += ' <div class="browserName">Apple Safari</div><div class="browserSupportedVersion">v10 and later</div>';
  122. toAppend += ' </div>';
  123. toAppend += ' </div>';
  124. toAppend += ' <div id="browserOutOfDateNotificationButtons">'
  125. if (!MOBILE_DEVICE) {
  126. toAppend += ' <div style="margin-right: 36px"><a href="http://outdatedbrowser.com/en" id="updateBrowserButton">UPDATE BROWSER</a></div>';
  127. toAppend += ' <div style="flex: 0 1 45%;"><a id="continueToPrototypeButton">Continue viewing prototype anyway</a></div>';
  128. } else {
  129. toAppend += ' <div style="width: 100%; text-align:center"><a id="continueToPrototypeButton">Continue viewing prototype anyway</a></div>';
  130. }
  131. toAppend += ' </div>';
  132. toAppend += '</div>';
  133. $('body').prepend(toAppend);
  134. $('#continueToPrototypeButton').on('click', function () {
  135. var $message = $('#browserOutOfDateNotification');
  136. $message.children().hide();
  137. $message.css('padding-top', '0px');
  138. $message.animate({ 'height': '0px' }, { duration: 400, complete: function () { $message.hide(); } });
  139. });
  140. }
  141. $axure.page.bind('load.start', mainFrame_onload);
  142. $axure.messageCenter.addMessageListener(messageCenter_message);
  143. var suppressPluginVarUpdate = false;
  144. $(document).on('pluginShown', function (event, data) {
  145. if (!suppressPluginVarUpdate) $axure.player.setVarInCurrentUrlHash(PLUGIN_VAR_NAME, data ? data : '');
  146. });
  147. $(document).on('pluginCreated', function (event, data) {
  148. if (!$axure.player.isMobileMode() && $axure.player.settings.startPluginGid.indexOf(data) > -1) {
  149. suppressPluginVarUpdate = true;
  150. $axure.player.showPlugin(data);
  151. suppressPluginVarUpdate = false;
  152. }
  153. if (data == '1') {
  154. $('#interfaceControlFrame').animate({ opacity: 1 }, 200);
  155. }
  156. if ($axure.player.settings.isExpo) {
  157. // TODO: Do this only if expo is a mobile device
  158. // TODO: Figure out better way to deal with this issue
  159. $axure.messageCenter.postMessage('setDeviceMode', { device: false });
  160. $axure.messageCenter.postMessage('setDeviceMode', { device: true });
  161. //$axure.player.refreshViewPort();
  162. }
  163. });
  164. function initializeEvents() {
  165. $('#interfaceControlFrameMinimizeContainer').on('click', collapse);
  166. $('#interfaceControlFrameCloseButton').on('click', closePlayer);
  167. $('#interfacePageNameContainer').on($axure.eventNames.mouseDownName, toggleSitemap);
  168. $('#interfaceAdaptiveViewsContainer').on($axure.eventNames.mouseDownName, toggleAdaptiveViewsPopup);
  169. $('#overflowMenuButton').on($axure.eventNames.mouseDownName, toggleOverflowMenuPopup);
  170. if (!MOBILE_DEVICE) {
  171. $('#maximizePanel').mouseenter(function () {
  172. $(this).addClass('maximizePanelOver');
  173. });
  174. $('#maximizePanel').mouseleave(function () {
  175. if ($(this).hasClass('maximizePanelOver')) {
  176. $(this).animate(isMobileMode() ? {
  177. top: '-' + $('#maximizePanel').height() + 'px'
  178. } : {
  179. left: '-' + $('#maximizePanel').width() + 'px'
  180. }, 300);
  181. }
  182. $(this).removeClass('maximizePanelOver');
  183. });
  184. $('#maximizePanelOver').mouseenter(function () {
  185. $('#maximizePanel').animate(isMobileMode() ? {
  186. top: '0px'
  187. } : {
  188. left: '0px'
  189. }, 100);
  190. });
  191. }
  192. $minimizeContainer = $('#interfaceControlFrameMinimizeContainer');
  193. $minimizeContainer.mouseenter(function () { $minimizeContainer.addClass('collapseHovered') });
  194. $minimizeContainer.mouseleave(function () { $minimizeContainer.removeClass('collapseHovered') });
  195. $maximizeContainer = $('#maximizePanelContainer');
  196. $maximizeContainer.mouseenter(function () { if(!MOBILE_DEVICE) $minimizeContainer.addClass('expandHovered') });
  197. $maximizeContainer.mouseleave(function () { if(!MOBILE_DEVICE) $minimizeContainer.removeClass('expandHovered') });
  198. $('#maximizePanel').click(function () {
  199. $(this).removeClass('maximizePanelOver');
  200. $('#maximizePanelContainer').hide();
  201. $axure.messageCenter.postMessage('expandFrame');
  202. });
  203. $('#mHideSidebar').on($axure.eventNames.mouseDownName, function (e) { startM(e); });
  204. $('#lsplitbar').on($axure.eventNames.mouseDownName, startLeftSplit);
  205. $('#rsplitbar').on($axure.eventNames.mouseDownName, startRightSplit);
  206. if ($axure.mobileSupport.mobile) {
  207. var touchCount = 0;
  208. var lastTouch = Date.now();
  209. $('#mainPanel').on('touchstart',
  210. (function (e) {
  211. var now = Date.now();
  212. if (now - lastTouch < 375) {
  213. if (++touchCount === 3) {
  214. if ($axure.player.isMobileMode() || MOBILE_DEVICE) expand();
  215. touchCount = 0;
  216. e.preventDefault();
  217. };
  218. } else {
  219. touchCount = 1;
  220. }
  221. lastTouch = now;
  222. }));
  223. }
  224. $(window).resize(function () {
  225. $axure.player.resizeContent();
  226. });
  227. $(window).on("orientationchange", function () {
  228. // IOS often does not complete updating innerHeight and innerWidth
  229. // until after calling orientation changed and resized window
  230. // Also, cannot use $(window).height() call since iOS11 needs padding amount
  231. iphoneXFirstPass = false
  232. if (IOS && isMobileMode()) setTimeout(function () { $axure.player.resizeContent(true); }, 250);
  233. });
  234. $('#mainPanel').scroll(function () {
  235. repositionClippingBoundsScroll();
  236. });
  237. }
  238. function initializeMainFrame() {
  239. var legacyQString = getQueryString("Page");
  240. if (legacyQString.length > 0) {
  241. location.href = location.href.substring(0, location.href.indexOf("?")) + "#" + PAGE_URL_NAME + "=" + legacyQString;
  242. return;
  243. }
  244. var mainFrame = document.getElementById("mainFrame");
  245. //if it's local file on safari, test if we can access mainframe after its loaded
  246. if (SAFARI && document.location.href.indexOf('file://') >= 0) {
  247. $(mainFrame).on('load', function () {
  248. var canAccess;
  249. try {
  250. var mainFrameWindow = mainFrame.contentWindow || mainFrame.contentDocument;
  251. mainFrameWindow['safari_file_CORS'] = 'Y';
  252. canAccess = mainFrameWindow['safari_file_CORS'] === 'Y';
  253. } catch (err) {
  254. canAccess = false;
  255. }
  256. if (!canAccess) window.location = 'resources/chrome/safari.html';
  257. });
  258. }
  259. if($axure.player.settings != null && !$axure.player.settings.isExpo) {
  260. mainFrame.contentWindow.location.href = getInitialUrl();
  261. }
  262. }
  263. function initializeDeviceFrame() {
  264. // TODO: Load device bezel and necessary overlays if applicable
  265. // - Need to determine if device has a frame/overlay
  266. // - Determine where to store said assets
  267. // - Determine sizing, positioning, orientation, and styling for HTML containers
  268. // - Verify that it stays consistent for every state (expo)
  269. var expo = $axure.expo;
  270. var project = expo.project;
  271. var device = project.Platform.Device;
  272. // in expo.ts, Web is 12
  273. if (device === 12) {
  274. // Hide containers
  275. $('#deviceFrameContainer').hide();
  276. $('#bezelOverlay').hide();
  277. return;
  278. }
  279. // map devices to their corresponding frame/bezel/overlays
  280. }
  281. var wasMobile = false;
  282. var isMobileMode = $axure.player.isMobileMode = function () { return isShareApp() || (MOBILE_DEVICE && $(window).width() < 420); }
  283. var isMobileTextEntry = false;
  284. var isViewOverridden = $axure.player.isViewOverridden = function() {
  285. return getHashStringVar(ADAPTIVE_VIEW_VAR_NAME).length > 0;
  286. }
  287. function toggleSitemapMobileMode() {
  288. var $container = $('#sitemapHost');
  289. if (!$container.length) return;
  290. var $header = $container.find('.pluginNameHeader');
  291. var projectName = $axure.player.getProjectName();
  292. if (isMobileMode()) {
  293. $header.text('PROJECT PAGES');
  294. $container.addClass('mobileMode');
  295. $container.find('.sitemapPageName').addClass('mobileText');
  296. // Give sitemapHost left-margin so it does not collide with projectOptionsHost
  297. if (MOBILE_DEVICE) $container.css('margin-left', '13px');
  298. } else {
  299. $container.removeClass('mobileMode');
  300. $header.text(projectName ? projectName : 'Pages');
  301. $container.find('.sitemapPageName').removeClass('mobileText');
  302. if (MOBILE_DEVICE) $container.css('margin-left', '');
  303. }
  304. }
  305. function togglePageNotesMobileMode() {
  306. var $container = $('#pageNotesHost');
  307. if (!$container.length) return;
  308. if (isMobileMode()) {
  309. $container.addClass('mobileMode');
  310. $('#pageNotesSectionHeader').text('PAGE NOTES');
  311. $('#widgetNotesSectionHeader').text('WIDGET NOTES');
  312. $container.find('.notesPageNameHeader').addClass('mobileSubHeader');
  313. $container.find('.pageNote').addClass('mobileText');
  314. $container.find('.emptyStateTitle').addClass('mobileSubHeader');
  315. $container.find('.emptyStateContent').addClass('mobileText');
  316. } else {
  317. $container.removeClass('mobileMode');
  318. $('#pageNotesSectionHeader').text('Page Notes');
  319. $('#widgetNotesSectionHeader').text('Widget Notes');
  320. $container.find('.notesPageNameHeader').removeClass('mobileSubHeader');
  321. $container.find('.pageNote').removeClass('mobileText');
  322. $container.find('.emptyStateTitle').removeClass('mobileSubHeader');
  323. $container.find('.emptyStateContent').removeClass('mobileText');
  324. }
  325. }
  326. function toggleFeedbackMobileMode() {
  327. var $container = $('#feedbackHost');
  328. if (!$container.length) return;
  329. if (isMobileMode()) {
  330. $container.addClass('mobileMode');
  331. $('.noDiscussionText span').text('Comments added in Axure Cloud will appear here');
  332. } else {
  333. $container.removeClass('mobileMode');
  334. $('.noDiscussionText span').text('Either select the button above to post to a location on the page, or use the field to post without location.');
  335. }
  336. }
  337. $axure.player.updatePlugins = function updatePlugins() {
  338. if (MOBILE_DEVICE && !isShareApp()) {
  339. var hostPanelPadding = isMobileMode() ? '8px 15px 0px 15px' : '';
  340. $('.rightPanel .leftPanel .mobileOnlyPanel').css('padding', hostPanelPadding);
  341. }
  342. if (isMobileMode()) {
  343. $('body').addClass('mobileMode');
  344. if ($('#debugHost').length) $('#debugHost').hide();
  345. if ($('#handoffHost').length) $('#handoffHost').hide();
  346. } else $('body').removeClass('mobileMode');
  347. toggleSitemapMobileMode();
  348. togglePageNotesMobileMode();
  349. toggleFeedbackMobileMode();
  350. }
  351. // TODO: this is done for IOS and Android (check what can be done for Pixel, etc)
  352. $axure.player.setIsMobileModeTextEntry = function (isTextEntry) {
  353. isMobileTextEntry = isTextEntry;
  354. if (IOS && isTextEntry) {
  355. activateMobileTextEntry()
  356. } else if (IOS) {
  357. setTimeout(deactivateMobileTextEntry, 150);
  358. }
  359. }
  360. function deactivateMobileTextEntry() {
  361. newHeight = window.innerHeight;
  362. var newControlHeight = newHeight - (!isShareApp() ? 140 : IOS ? 157 : 138);
  363. if (!$('.leftPanel').hasClass('popup')) {
  364. $('.leftPanel').height(newControlHeight);
  365. }
  366. $('.rightPanel').height(newControlHeight);
  367. $('.mobileOnlyPanel').height(newControlHeight);
  368. $('#mobileControlFrameContainer').show();
  369. }
  370. function activateMobileTextEntry() {
  371. $('#mobileControlFrameContainer').hide();
  372. newHeight = window.innerHeight;
  373. var newControlHeight = newHeight - (!isShareApp() ? 140 : IOS ? 157 : 138);
  374. newControlHeight = newControlHeight + (!isShareApp() ? 61 : IOS ? 72 : 60);
  375. if (!$('.leftPanel').hasClass('popup')) {
  376. $('.leftPanel').height(newControlHeight);
  377. }
  378. $('.rightPanel').height(newControlHeight);
  379. $('.mobileOnlyPanel').height(newControlHeight);
  380. }
  381. function setAdaptiveView() {
  382. if (typeof noViewport == 'undefined') {
  383. // Block during animation -- end of animation will call resizeContent once completed with isAnimating equal to false
  384. if (!isViewOverridden() && !isAnimating) $axure.messageCenter.postMessage('setAdaptiveViewForSize', { 'width': $('#mainPanel').width(), 'height': $('#mainPanel').height() });
  385. //if (!isViewOverridden()) $axure.messageCenter.postMessage('setAdaptiveViewForSize', { 'width': $('#mainPanel').width(), 'height': $('#mainPanel').height() });
  386. $axure.player.refreshViewPort();
  387. if ($axure.player.updateAdaptiveViewHeader != null) $axure.player.updateAdaptiveViewHeader();
  388. }
  389. }
  390. $axure.player.resizeContent = function (noViewport) {
  391. var isMobile = isMobileMode();
  392. var $left = $('.leftPanel');
  393. var $right= $('.rightPanel');
  394. if (wasMobile && !isMobile) {
  395. $('#clippingBoundsScrollContainer').show();
  396. $('#outerContainer').prepend($('.leftPanel'));
  397. $('#outerContainer').append($('.rightPanel'));
  398. $axure.player.updatePlugins();
  399. $('#mHideSidebar').hide();
  400. $('#mobileBrowserControlFrame').hide();
  401. $('#nativeAppControlFrame').hide();
  402. if ($('#topPanel').is(':visible')) {
  403. $('#maximizePanelContainer').hide();
  404. $axure.player.restorePlugins();
  405. } else {
  406. $('.leftPanel').hide();
  407. $('.rightPanel').hide();
  408. if (!MOBILE_DEVICE) $('#maximizePanelContainer').show();
  409. }
  410. $('.leftPanel').css({ 'top': '', 'left': '' });
  411. $('.rightPanel').css({ 'top': '', 'left': '' });
  412. } else if (!wasMobile && isMobile) {
  413. $('#clippingBoundsScrollContainer').hide();
  414. $axure.player.closePopup();
  415. $('#lsplitbar').hide();
  416. $('#rsplitbar').hide();
  417. $('.leftPanel').show();
  418. $('.rightPanel').show();
  419. $axure.player.updatePlugins();
  420. $('#mHideSidebar').append($('.leftPanel'));
  421. $('#mHideSidebar').append($('.rightPanel'));
  422. if (MOBILE_DEVICE) $('#maximizePanelContainer').hide();
  423. $axure.messageCenter.postMessage('collapseFrameOnLoad');
  424. }
  425. var newHeight = 0;
  426. var newWidth = 0;
  427. if (iphoneX && isShareApp()) {
  428. // Hack for Iphone X
  429. newHeight = $(window).height() - ((!isMobile && $('#topPanel').is(':visible')) ? $('#topPanel').height() : 0);
  430. newWidth = $(window).width();
  431. // This does not need to make sense, since it is Iphone X
  432. var notchAndHomeOffsetPortrait = iphoneXFirstPass ? 35 : 5;
  433. var notchOffsetLandscape = iphoneXFirstPass ? 45 : 10;
  434. var homeButtonOffsetLandscape = iphoneXFirstPass ? 21 : 10;
  435. if (newHeight > newWidth) {
  436. newHeight = newHeight + notchAndHomeOffsetPortrait;
  437. } else {
  438. newWidth = newWidth + notchOffsetLandscape * 2;
  439. newHeight = newHeight + homeButtonOffsetLandscape;
  440. }
  441. } else {
  442. // innerHeight includes padding for window -- needed in iOS 11 to have prototype stretch to bottom of screen (could put in -- if (iOS) -- block if needed)
  443. //var newHeight = $(window).height() - ((!isMobile && $('#topPanel').is(':visible'))? $('#topPanel').height() : 0);
  444. newHeight = window.innerHeight - ((!isMobile && $('#topPanel').is(':visible')) ? $('#topPanel').height() : 0);
  445. newWidth = $(window).width();
  446. }
  447. $('#outerContainer').height(newHeight).width(newWidth);
  448. $('#mainPanel').height(newHeight);
  449. $('#clippingBounds').height(newHeight);
  450. if (isMobile) {
  451. $('#mobileControlFrameContainer').height(newHeight);
  452. $('#mobileControlFrameContainer').width(newWidth);
  453. var newControlHeight = newHeight - (!MOBILE_DEVICE ? 112 : !isShareApp() ? 140 : IOS ? 157 : 138);
  454. // Screen resize is only way through browser to catch mobile device keyboard expand and collapse
  455. if ($('#mHideSidebar').is(':visible') && !$('#mobileControlFrameContainer').is(':visible')) {
  456. $('#mobileControlFrameContainer').delay(150).show();
  457. } else if (isMobileTextEntry) {
  458. newControlHeight = newControlHeight + (!isShareApp() ? 61 : IOS ? 72 : 60);
  459. $('#mobileControlFrameContainer').hide();
  460. }
  461. if(!$('.leftPanel').hasClass('popup')) {
  462. $('.leftPanel').height(newControlHeight);
  463. }
  464. $('.rightPanel').height(newControlHeight);
  465. $('.mobileOnlyPanel').height(newControlHeight);
  466. } else {
  467. if (!$('.leftPanel').hasClass('popup')) {
  468. $('.leftPanel').css('height','');
  469. }
  470. $('.rightPanel').css('height', '');
  471. if ($('.rightPanel').is(':visible')) {
  472. var lastRightPanelWidthDefaultSub = ($(window).width() - lastRightPanelWidthDefault || 0);
  473. var rightPanelWidth = ($('.rightPanel').width() || 0);
  474. var leftPanelPanelWidthSub = ($(window).width() - $('.leftPanel').width()) || 0;
  475. var newWidth = Math.min(lastRightPanelWidthDefaultSub, rightPanelWidth, leftPanelPanelWidthSub);
  476. lastRightPanelWidth = Math.max(lastRightPanelWidthDefault, newWidth);
  477. $('.rightPanel').width(lastRightPanelWidth ? lastRightPanelWidth : lastRightPanelWidthDefault);
  478. $('#rsplitbar').css('left', $(window).width() - $('.rightPanel').width());
  479. }
  480. if ($('.leftPanel').is(':visible')) {
  481. var lastLeftPanelWidthSub = ($(window).width() - lastLeftPanelWidthDefault || 0);
  482. var leftPanelWidth = ($('.leftPanel').width() || 0);
  483. var rightPanelWidthSub = ($(window).width() - $('.rightPanel').width()) || 0;
  484. var newWidth = Math.min(lastLeftPanelWidthSub, leftPanelWidth, rightPanelWidthSub);
  485. lastLeftPanelWidth = Math.max(lastLeftPanelWidthDefault, newWidth);
  486. $('.leftPanel').width(lastLeftPanelWidth ? lastLeftPanelWidth : lastLeftPanelWidthDefault);
  487. $('#lsplitbar').css('left', $('.leftPanel').width() - 4);
  488. }
  489. }
  490. if (isMobile) {
  491. var newControlWidth = newWidth - 80;
  492. $('.leftPanel').css({ 'width': newControlWidth + 'px' });
  493. $('.rightPanel').css({ 'width': newControlWidth + 'px' });
  494. $('.mobileOnlyPanel').css({ 'width': newControlWidth + 'px' });
  495. adjustM('left');
  496. }
  497. updateClippingBoundsWidth();
  498. repositionClippingBoundsScroll();
  499. setAdaptiveView();
  500. wasMobile = isMobile;
  501. }
  502. function contentDocument_onload() {
  503. (function setRepositionWhenReady() {
  504. var $iframe = $('#mainPanel').find('iframe')[0];
  505. if ($($iframe.contentWindow.document.body).length === 0 || $iframe.contentWindow.document.URL === "about:blank") {
  506. setTimeout(setRepositionWhenReady, 50);
  507. } else {
  508. var $iframe = $($('#mainPanel').find('iframe')[0].contentWindow.document);
  509. $iframe.scroll(function () {
  510. repositionClippingBoundsScroll();
  511. });
  512. }
  513. })();
  514. }
  515. // This is the full width and height of the prototype (beyond the window width and height)
  516. var determineIframeDimensions = function () {
  517. var $iframe = $($('#mainPanel').find('iframe')[0].contentWindow);
  518. return {
  519. width: $iframe.width(),
  520. height: $iframe.height()
  521. };
  522. };
  523. // Position of this (upper left hand corner) should match the existingPinPanel position
  524. var determineIframePosition = function () {
  525. var dimensions = determineIframeDimensions();
  526. var $iframe = $($('#mainPanel').find('iframe')[0].contentWindow);
  527. var $body = $($iframe[0].document.body);
  528. var bodyWidth = $body.offset().left !== 0 ? $body.width() : dimensions.width;
  529. if (FIREFOX) {
  530. var left = $body[0].getBoundingClientRect().left;
  531. bodyWidth = left !== 0 ? $body.width() : dimensions.width;
  532. }
  533. return {
  534. top: 0,// Math.max(0, (dimensions.height - $($iframe[0].document.body).height()) / 2),
  535. left: Math.max(0, (dimensions.width - bodyWidth) / 2)
  536. };
  537. };
  538. // Return iframe scroll top and scroll left
  539. var determineIframeScroll = function () {
  540. var $iframe = $($('#mainPanel').find('iframe')[0].contentWindow);
  541. return {
  542. scrollTop: $iframe.scrollTop(),
  543. scrollLeft: $iframe.scrollLeft()
  544. };
  545. };
  546. function calculateClippingBoundsWidth(panelSize, isLeftPanel) {
  547. var $leftPanel = $('.leftPanel:visible');
  548. var leftPanelOffset = (!isMobileMode() && $leftPanel.length > 0 && !$leftPanel.hasClass('popup')) ? $leftPanel.width() : 0;
  549. var $rightPanel = $('.rightPanel:visible');
  550. var rightPanelOffset = (!isMobileMode() && $rightPanel.length > 0) ? $rightPanel.width() : 0;
  551. // Replace current panel size with panel size after animation for expand or collapse completes
  552. if (typeof panelSize !== 'undefined') {
  553. if (isLeftPanel) leftPanelOffset = panelSize;
  554. else rightPanelOffset = panelSize;
  555. }
  556. return $(window).width() - rightPanelOffset - leftPanelOffset;
  557. }
  558. var updateClippingBoundsWidth = $axure.player.updateClippingBoundsWidth = function () {
  559. if ($('.leftPanel').is(':visible')) $('#clippingBounds').css('left', $('.leftPanel').width());
  560. else $('#clippingBounds').css('left', '0px');
  561. $('#clippingBounds').width(calculateClippingBoundsWidth());
  562. }
  563. var contentLeftOfOriginOffset = 0;
  564. function calculateClippingBoundsScrollPosition() {
  565. // Adjust for mainPanelContainer scaling (scale should be "none" for scaleVal == 0 or scaleVal == 1)
  566. var $iframe = $($('#mainPanel').find('iframe')[0].contentWindow);
  567. var selectedScale = $('.vpScaleOption').find('.selectedRadioButton');
  568. var scaleVal = $(selectedScale).parent().attr('val');
  569. var dimStr = $('.currentAdaptiveView').attr('data-dim');
  570. var dim = dimStr ? dimStr.split('x') : { w: '0', h: '0' };
  571. var isDevice = dim[1] != '0' ? true : false;
  572. // This line is necessary for right handling DEFAULT SCALE
  573. // Because default scale relates to scale-to-fit item for device projects
  574. if (scaleVal == '0' && isDevice) scaleVal = 2;
  575. var scale = $('#mainPanelContainer').css('transform');;
  576. scale = (scale == "none") ? 1 : Number(scale.substring(scale.indexOf('(') + 1, scale.indexOf(',')));
  577. // Iframe and Main Panel Positioning
  578. var iframeScroll = determineIframeScroll();
  579. var iframePos = determineIframePosition();
  580. var viewablePanelLeftMargin = parseInt($('#mainPanelContainer').css('margin-left'));
  581. var viewablePanelTop = parseInt($('#mainPanelContainer').css('top'));
  582. if (isNaN(viewablePanelTop)) viewablePanelTop = 0;
  583. if (scaleVal == 2) {
  584. // Scale to Fit (account for main panel container scale) -- needed for device mode in Scale to Fit
  585. viewablePanelLeftMargin = ($('#mainPanel').width() - ($('#mainPanelContainer').width() * scale)) / 2
  586. viewablePanelTop = ($('#mainPanel').height() - ($('#mainPanelContainer').height() * scale)) / 2
  587. }
  588. // left and top positioning
  589. var leftPos = viewablePanelLeftMargin + (iframePos.left - iframeScroll.scrollLeft) * scale;
  590. var topPos = viewablePanelTop - iframeScroll.scrollTop * scale;
  591. // Special cases for Centered Page
  592. var isCentered = $($iframe[0].document.body).css('position') == 'relative';
  593. if (isCentered && scaleVal == 1) leftPos = 0;
  594. else if (isCentered && scaleVal == 2) leftPos = $('#mainPanelContainer').width() * scale / 2.0 - contentLeftOfOriginOffset;
  595. // Include clipFrameScroll offset in mainPanelContainer
  596. topPos += (parseFloat($('#clipFrameScroll').css("top")) || 0) * scale;
  597. return {
  598. left: leftPos,
  599. top: topPos
  600. }
  601. }
  602. function repositionClippingBoundsScroll() {
  603. if (!$axure.player.settings.isAxshare) return;
  604. (function repositionWhenReady() {
  605. if ($($('#mainPanel').find('iframe')[0].contentWindow.document.body).length === 0) {
  606. setTimeout(repositionWhenReady, 50);
  607. } else {
  608. var position = calculateClippingBoundsScrollPosition();
  609. // Adding mainPanel scroll here, since it does not work well with calculating animation left position
  610. position.left = position.left - $('#mainPanel').scrollLeft() - $('#clipFrameScroll').scrollLeft();
  611. position.top = position.top - $('#mainPanel').scrollTop() - $('#clipFrameScroll').scrollTop();
  612. $('#clippingBoundsScrollContainer').css('left', position.left + 'px');
  613. $('#clippingBoundsScrollContainer').css('top', position.top + 'px');
  614. }
  615. })();
  616. }
  617. function calculateScrollLeftWithOffset(offset, isLeftPanel) {
  618. if (!$axure.player.settings.isAxshare) return;
  619. if ($($('#mainPanel').find('iframe')[0].contentWindow.document.body).length === 0) return;
  620. var scaleVal = $('.vpScaleOption').find('.selectedRadioButton').parent().attr('val');
  621. if (scaleVal == 2) return;
  622. var $iframe = $($('#mainPanel').find('iframe')[0].contentWindow);
  623. var $body = $($iframe[0].document.body);
  624. var dimStr = $('.currentAdaptiveView').attr('data-dim');
  625. var hasFrame = (!dimStr ? false : dimStr.split('x')[1] != '0') && !$axure.player.noFrame;
  626. var isCentered = $body.css('position') == 'relative'; //body position is always static while page is still loading (thus false, if called on intial load)
  627. var isCollapsing = offset > 0; //offset is positive when collapsing since we are gaining offset more space for content viewing
  628. // Base case left positioning
  629. var leftPos = calculateClippingBoundsScrollPosition().left;
  630. // If maintaining view options requires a left adjustment not equivalent to panel size (which has already being added in leftPos above)
  631. var viewAdjustment = 0;
  632. // Mobile Frame adjustment
  633. if (hasFrame) {
  634. var viewablePanelLeftMargin = parseInt($('#mainPanelContainer').css('margin-left'));
  635. var viewablePanelRightMargin = parseInt($('#mainPanelContainer').css('margin-right'));
  636. // Cases
  637. // 0) Adaptive view frame doesn't fit in viewable bounds (viewablePanelLeftMargin is zero) -- use entire offset of panel (no adjustment needed)
  638. // 1) Adaptive view frame fits in bounds -- then half of incoming panel will be split left and half right (offset / 2)
  639. // 2) and 3) View Frame either fits in bounds before animation and no longer will after, or vice versa. Mix of previous two cases
  640. if (isCollapsing) {
  641. if (viewablePanelLeftMargin != 0) {
  642. viewAdjustment = offset / 2;
  643. } else if (-viewablePanelRightMargin < offset) {
  644. viewAdjustment = ((offset + viewablePanelRightMargin) / 2);
  645. }
  646. } else if (viewablePanelLeftMargin != 0) {
  647. viewAdjustment = Math.max(offset / 2, -viewablePanelLeftMargin)
  648. }
  649. }
  650. // Centered Page adjustment
  651. if (isCentered) {
  652. // Width of content not able to fit inside current viewable frame
  653. var clippedContentWidth = $body.width() - calculateClippingBoundsWidth(Math.abs(offset), isLeftPanel);
  654. // Cases
  655. // 0) Content never fits in bounds -- then entire offset of panel will move content left value (no adjustment needed as already handled)
  656. // 1) Content fits in bounds -- then half of incoming panel offset will be split left and half right (offset / 2)
  657. // 2) and 3) Content either fits in bounds before animation and no longer will after, or vice versa. Mix of previous two cases
  658. if (clippedContentWidth <= 0) {
  659. viewAdjustment = offset / 2;
  660. } else if (isCollapsing && clippedContentWidth < offset) {
  661. viewAdjustment = (offset - clippedContentWidth) / 2;
  662. } else if (!isCollapsing && clippedContentWidth < -offset) {
  663. viewAdjustment = (clippedContentWidth + offset) / 2;
  664. }
  665. }
  666. return leftPos + viewAdjustment;
  667. }
  668. // Set to true when left panel or right panel are being expanded/collapsed
  669. // returns to false when lsplitbar (switched to clippingBounds) finishes animation (thus panels will be fully expanded or retracted at this point)
  670. var isAnimating = $axure.player.isAnimating = false;
  671. $axure.player.collapseToBar = function (context, hostId) {
  672. lastLeftPanelWidth = $('.leftPanel').width();
  673. lastRightPanelWidth = $('.rightPanel').width();
  674. if (context === 'project' || context === 'all') {
  675. if(!isMobileMode()) {
  676. isAnimating = true;
  677. var newWidth = lastLeftPanelWidth != 0 ? lastLeftPanelWidth : lastLeftPanelWidthDefault;
  678. var clippingWidth = calculateClippingBoundsWidth(0, true);
  679. var newLeft = calculateScrollLeftWithOffset(newWidth, true);
  680. $('.leftPanel').animate({ 'margin-left': -newWidth + 'px' },
  681. { duration: 200, complete: function() { $('.leftPanel').width(0).hide().css({ 'margin-left': '' }); } });
  682. $('#lsplitbar').animate({ left: '-4px' },
  683. { duration: 200, complete: function() { $('#lsplitbar').hide(); } });
  684. $('#clippingBounds').animate({ left: '', width: clippingWidth + 'px' }, { duration: 200 });
  685. $('#clippingBoundsScrollContainer').animate({ left: newLeft + 'px' },
  686. { duration: 200, complete: function () {
  687. isAnimating = false;
  688. $axure.player.resizeContent();
  689. $axure.player.pluginVisibleChanged(hostId, false);
  690. }});
  691. } else {
  692. $('.leftPanel').width(0);
  693. $('#lsplitbar').hide();
  694. }
  695. }
  696. if (context === 'inspect' || context === 'all') {
  697. if (!isMobileMode()) {
  698. isAnimating = true;
  699. var newWidth = lastRightPanelWidth != 0 ? lastRightPanelWidth : lastRightPanelWidthDefault;
  700. var clippingWidth = calculateClippingBoundsWidth(0, false);
  701. var newLeft = calculateScrollLeftWithOffset(newWidth, false);
  702. $('.rightPanel').animate({ 'margin-right': -newWidth + 'px' },
  703. { duration: 200, complete: function () { $('.rightPanel').width(0).hide().css({ 'margin-right': '' }); } });
  704. $('#rsplitbar').animate({ left: $(window).width() + 'px' },
  705. { duration: 200, complete: function () { $('#rsplitbar').hide(); } });
  706. $('#clippingBounds').animate({ width: clippingWidth + 'px' }, { duration: 200 });
  707. $('#clippingBoundsScrollContainer').animate({ left: newLeft + 'px' },
  708. { duration: 200, complete: function () {
  709. isAnimating = false;
  710. $axure.player.resizeContent();
  711. $axure.player.pluginVisibleChanged(hostId, false);
  712. }});
  713. } else {
  714. $('.rightPanel').width(0);
  715. $('#rsplitbar').hide();
  716. }
  717. }
  718. $(window).resize();
  719. toolBarOnly = true;
  720. }
  721. $axure.player.expandFromBar = function (hostId, context, isFinalPluginToRestore) {
  722. if (context === 'project') {
  723. if ($('#lsplitbar').is(':visible')) return;
  724. $('.leftPanel').removeClass('popup');
  725. if(!isMobileMode()) {
  726. isAnimating = true;
  727. var newWidth = (lastLeftPanelWidth ? lastLeftPanelWidth : lastLeftPanelWidthDefault);
  728. var clippingWidth = calculateClippingBoundsWidth(newWidth, true);
  729. var newLeft = calculateScrollLeftWithOffset(-newWidth, true);
  730. $('.leftPanel').width(newWidth);
  731. $('.leftPanel').css('margin-left', -newWidth + 'px').show();
  732. $('.leftPanel').animate({ 'margin-left': '0px' }, { duration: 200, complete: function () { $('.leftPanel').css({ 'margin-left': '' }); } });
  733. $('#lsplitbar').css('left', '-4px');
  734. $('#lsplitbar').show();
  735. $('#lsplitbar').animate({ left: newWidth - 4 + 'px' }, { duration: 200 });
  736. $('#clippingBounds').animate({ left: newWidth + 'px', width: clippingWidth + 'px' }, { duration: 200 });
  737. $('#clippingBoundsScrollContainer').animate({ left: newLeft + 'px' },
  738. { duration: 200, complete: function () {
  739. isAnimating = false;
  740. $axure.player.resizeContent();
  741. if (isFinalPluginToRestore) $('#clippingBoundsScrollContainer').show();
  742. $axure.player.pluginVisibleChanged(hostId, true);
  743. }});
  744. }
  745. } else {
  746. if ($('#rsplitbar').is(':visible')) {
  747. // update width of rightPanel plugin
  748. var newWidth = lastRightPanelWidth ? lastRightPanelWidth : lastRightPanelWidthDefault;
  749. $('#' + hostId).width(newWidth);
  750. $('#' + hostId).show();
  751. $axure.player.pluginVisibleChanged(hostId, true);
  752. return;
  753. }
  754. if (!isMobileMode()) {
  755. isAnimating = true;
  756. var newWidth = lastRightPanelWidth ? lastRightPanelWidth : lastRightPanelWidthDefault;
  757. var clippingWidth = calculateClippingBoundsWidth(newWidth, false);
  758. var newLeft = calculateScrollLeftWithOffset(-newWidth, false);
  759. $('.rightPanel').width(newWidth);
  760. $('.rightPanel').css('margin-right', -newWidth + 'px');
  761. $('#' + hostId).show();
  762. $('.rightPanel').animate({ 'margin-right': '0px' }, { duration: 200, complete: function () { $('.rightPanel').css({ 'margin-right': '' }); } });
  763. $('#rsplitbar').css('left', $(window).width());
  764. $('#rsplitbar').show();
  765. $('#rsplitbar').animate({ left: $(window).width() - $('.rightPanel').width() + 'px' }, { duration: 200 });
  766. $('#clippingBounds').animate({ width: clippingWidth + 'px' }, { duration: 200 });
  767. $('#clippingBoundsScrollContainer').animate({ left: newLeft + 'px' },
  768. { duration: 200, complete: function () {
  769. isAnimating = false;
  770. $axure.player.resizeContent();
  771. if (isFinalPluginToRestore) $('#clippingBoundsScrollContainer').show();
  772. $axure.player.pluginVisibleChanged(hostId, true);
  773. }});
  774. }
  775. }
  776. $(window).resize();
  777. toolBarOnly = false;
  778. if (isMobileMode()) {
  779. $('#mHideSidebar').show();
  780. $('#nativeAppControlFrame').show();
  781. }
  782. }
  783. var suspendRefreshViewPort = $axure.player.suspendRefreshViewPort = false;
  784. $axure.player.refreshViewPort = function () {
  785. if (suspendRefreshViewPort) return;
  786. var dimStr = $('.currentAdaptiveView').attr('data-dim');
  787. var dim = dimStr ? dimStr.split('x') : { w: '0', h: '0' };
  788. var w = dim[0] != '0' ? dim[0] : '';
  789. var h = dim[1] != '0' ? dim[1] : '';
  790. var scaleVal = $('.vpScaleOption').find('.selectedRadioButton').parent().attr('val');
  791. var selectedScaleValue = scaleVal;
  792. $axure.player.noFrame = false;
  793. if (h && scaleVal == 1) $axure.player.noFrame = true;
  794. $('#mainPanelContainer').attr({
  795. "data-scale-n": scaleVal,
  796. "data-page-dimensions-type": h ? "device" : w ? "web" : "auto",
  797. "data-scale-shift-x": null,
  798. "data-scale-shift-y": null,
  799. });
  800. var clipToView = h && !$axure.player.noFrame;
  801. var isDevice = h;
  802. var mainPanelWidth = $('#mainPanel').width();
  803. var mainPanelHeight = $('#mainPanel').height();
  804. if (!w || !clipToView) w = mainPanelWidth;
  805. if (!h || !clipToView) h = mainPanelHeight;
  806. if (MOBILE_DEVICE && h > mainPanelHeight) h = mainPanelHeight;
  807. if (MOBILE_DEVICE && w > mainPanelWidth) w = mainPanelWidth;
  808. if (clipToView) {
  809. if (!MOBILE_DEVICE && scaleVal == '0') scaleVal = 2;
  810. w = Number(w);
  811. h = Number(h);
  812. $('#mainFrame').width(w);
  813. $('#clipFrameScroll').width(w);
  814. $('#mainFrame').height(h);
  815. $('#clipFrameScroll').height(h);
  816. var topPadding = MOBILE_DEVICE ? 0 : 10;
  817. var leftPadding = 0;
  818. var rightPadding = 0;
  819. var bottomPadding = MOBILE_DEVICE ? 0 : 10;
  820. w = w + leftPadding + rightPadding;
  821. h = h + topPadding + bottomPadding;
  822. var x = (mainPanelWidth - w) / 2;
  823. var y = (mainPanelHeight - h) / 2 - 1;
  824. x = Math.max(0, x);
  825. if (scaleVal != 2) y = Math.max(0, y);
  826. $('#mainPanelContainer').attr({
  827. "data-scale-shift-x": x,
  828. "data-scale-shift-y": y,
  829. });
  830. $('#mainPanelContainer').css({
  831. 'margin': 'auto',
  832. 'top': y + 'px'
  833. });
  834. $('#clipFrameScroll').css({
  835. 'left': leftPadding + 'px',
  836. 'top': topPadding + 'px'
  837. });
  838. $('#mainPanelContainer').width(w);
  839. $('#mainPanelContainer').height(h);
  840. } else {
  841. $('#mainFrame').width('100%');
  842. $('#mainFrame').height(h);
  843. $('#clipFrameScroll').width('100%');
  844. $('#clipFrameScroll').height(h);
  845. $('#clipFrameScroll').css({ 'left': '', 'top': '' });
  846. $('#mainPanelContainer').width('100%');
  847. $('#mainPanelContainer').height(h);
  848. $('#mainPanelContainer').css({
  849. 'left': '',
  850. 'margin': '',
  851. 'top': ''
  852. });
  853. }
  854. $axure.messageCenter.postMessage('setDeviceMode', { device: isDevice, width: w, scaleToWidth: (scaleVal == "1") });
  855. $(".vpScaleOption").show();
  856. var prevScaleN = $('#mainPanelContainer').css('transform');
  857. prevScaleN = (prevScaleN == "none") ? 1 : Number(prevScaleN.substring(prevScaleN.indexOf('(') + 1, prevScaleN.indexOf(',')));
  858. var newScaleN = 1;
  859. $('#mainPanelContainer').css({
  860. 'transform': '',
  861. 'transform-origin': ''
  862. });
  863. var $leftPanel = $('.leftPanel:visible');
  864. var leftPanelOffset = (!isMobileMode() && $leftPanel.length > 0) ? $leftPanel.width() : 0;
  865. var $rightPanel = $('.rightPanel:visible');
  866. var rightPanelOffset = (!isMobileMode() && $rightPanel.length > 0) ? $rightPanel.width() : 0;
  867. var vpScaleData = {
  868. scale: scaleVal,
  869. prevScaleN: prevScaleN,
  870. viewportHeight: h,
  871. viewportWidth: w,
  872. panelWidthOffset: leftPanelOffset + rightPanelOffset,
  873. clipToView: clipToView
  874. };
  875. $axure.messageCenter.postMessage('getScale', vpScaleData);
  876. $axure.messageCenter.postMessage('cloud_ScaleValueChanged', {
  877. scale: selectedScaleValue,
  878. });
  879. if (scaleVal == '0' && clipToView) $('#mainPanel').css('overflow', 'auto');
  880. else $('#mainPanel').css('overflow', '');
  881. }
  882. $axure.player.getProjectName = function getProjectName() {
  883. if (typeof PREVIEW_INFO !== 'undefined') {
  884. return PREVIEW_INFO.fileName;
  885. } else if(typeof $axure.player.settings.projectName !== 'undefined') {
  886. return $axure.player.settings.projectName;
  887. } else return false;
  888. }
  889. function initializeLogo() {
  890. if(typeof PREVIEW_INFO !== 'undefined') {
  891. $('#previewNotice').show();
  892. }
  893. //if (typeof PREVIEW_INFO !== 'undefined') {
  894. // $('#interfaceControlFrameLogoCaptionContainer').html(PREVIEW_INFO.fileName);
  895. //} else if (typeof $axure.player.settings.projectName !== 'undefined') {
  896. // $('#interfaceControlFrameLogoCaptionContainer').html($axure.player.settings.projectName);
  897. //} else {
  898. // $('#interfaceControlFrameLogoCaptionContainer').hide();
  899. //}
  900. //if ($axure.document.configuration.logoImagePath) {
  901. // var image = new Image();
  902. // //image.onload = function () {
  903. // // //$('#logoImage').css('max-width', this.width + 'px');
  904. // // $('#interfaceControlFrameContainer').css('margin-left', '-' + $('#logoImage').width() / 2 + 'px');
  905. // // //$axure.player.resizeContent();
  906. // //};
  907. // image.src = $axure.document.configuration.logoImagePath;
  908. // $('#interfaceControlFrameLogoImageContainer').html('<img id="logoImage" src="" />');
  909. // $('#logoImage').attr('src', $axure.document.configuration.logoImagePath);//.on('load', function () { $axure.player.resizeContent(); });
  910. //} else $('#interfaceControlFrameLogoImageContainer').hide();
  911. //if ($axure.document.configuration.logoImageCaption) {
  912. // $('#interfaceControlFrameLogoCaptionContainer').html($axure.document.configuration.logoImageCaption);
  913. //} else $('#interfaceControlFrameLogoCaptionContainer').hide();
  914. //if(!$('#interfaceControlFrameLogoImageContainer').is(':visible') && !$('#interfaceControlFrameLogoCaptionContainer').is(':visible')) {
  915. // $('#interfaceControlFrameLogoContainer').hide();
  916. //}
  917. }
  918. function initializePreview() {
  919. if (typeof PREVIEW_INFO !== 'undefined') {
  920. $('#separatorContainer').addClass('hasLeft');
  921. $('#overflowMadeWith').addClass('preview');
  922. var callback = undefined;
  923. $('#publishButton').click(function () {
  924. $.ajax({
  925. type: 'GET',
  926. url: 'publish',
  927. data: {},
  928. success: function (response) {
  929. if (callback) callback(response);
  930. },
  931. error: function (response) {
  932. if (callback) callback(response);
  933. },
  934. dataType: 'jsonp'
  935. });
  936. });
  937. }
  938. }
  939. var userAcct = {
  940. userId: '',
  941. userName: '',
  942. userEmail: '',
  943. userProfileImg: '',
  944. isUsingAxureAcct: false,
  945. }
  946. var authCookieValue = null;
  947. var userCookieValue = null;
  948. var isSubInstance = false;
  949. //var readOnlyMode = false;
  950. //var readOnlyMessage = '';
  951. // Watermark hints
  952. // NOTE: The trailing characters serve to be a distinguishing element in case the user actually does use text similar to the hint.
  953. var emailHint = "Email ";
  954. var passHint = "Password ";
  955. var feedbackServiceUrl = (window.AXSHARE_HOST_SECURE_URL || 'https://share.axure.com') + '/issue';
  956. // Look at creating a new location to have GetShareStatus(FbEnabled replacement) and SafariAuth since they are more general calls that are not solely for feedback now
  957. //var prototypeControlUrl = (window.AXSHARE_HOST_SECURE_URL || 'https://share.axure.com') + '/prototype';
  958. // Checks if the browser is Safari 3.0+
  959. // https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
  960. function isSafari() {
  961. // Safari 3.0+ "[object HTMLElementConstructor]"
  962. var liveSafari = /constructor/i.test(window.HTMLElement) || (function (p) { return p.toString() === "[object SafariRemoteNotification]"; })(!window['safari'] || (typeof safari !== 'undefined' && safari.pushNotification));
  963. return liveSafari || SAFARI || (IOS && isShareApp());
  964. };
  965. function includeTokens(ajaxData, excludeUser) {
  966. //If the authCookieValue is set (a password-protected local prototype), then send the
  967. //token as well (because cookies don't always get sent to external domains)
  968. if (authCookieValue) {
  969. $.extend(ajaxData, { token: authCookieValue });
  970. }
  971. if (!excludeUser && userCookieValue) {
  972. $.extend(ajaxData, { utoken: userCookieValue });
  973. }
  974. }
  975. function setUserLoggedInStatus(response, safariAuthResponseProfile) {
  976. if (!response.success) {
  977. userAcct.isUsingAxureAcct = false;
  978. } else {
  979. if (safariAuthResponseProfile) response = safariAuthResponseProfile;
  980. userAcct.userId = response.userId;
  981. if (safariAuthResponseProfile)
  982. userAcct.userName = response.username == null || response.username.trim() === '' ? response.userEmail : decodeURIComponent(response.username.trim());
  983. else
  984. userAcct.userName = response.nickname == null || response.nickname.trim() === '' ? response.userEmail : decodeURIComponent(response.nickname.trim());
  985. userAcct.userEmail = response.userEmail;
  986. userAcct.userProfileImg = response.profileImageUrl;
  987. userAcct.isUsingAxureAcct = true;
  988. if (response.authToken != null) {
  989. $axshare.setAuthCookie(response.authToken);
  990. userCookieValue = response.authToken;
  991. }
  992. }
  993. // If feedback is loaded, update feedback with new account information
  994. if (typeof feedback !== 'undefined') feedback.updateUserAccountInfo(userAcct, authCookieValue, userCookieValue);
  995. }
  996. // TODO: for on prem, we need to use an ajax call directly to share instead of accounts
  997. // Verify authentication against axure accounts
  998. $axure.player.axureAuth = function axureAuth(callback) {
  999. if (window.$axshare != null) {
  1000. $axshare.auth(function (response) {
  1001. if (response.success) {
  1002. setUserLoggedInStatus(response);
  1003. } else {
  1004. if (isSafari()) {
  1005. var ajaxData = {
  1006. userId: userAcct.isUsingAxureAcct ? userAcct.userId : ""
  1007. };
  1008. includeTokens(ajaxData);
  1009. $.ajax({
  1010. type: 'GET',
  1011. url: feedbackServiceUrl + '/safariAuth',
  1012. data: ajaxData,
  1013. success: function (response) {
  1014. if (!response.success) {
  1015. setUserLoggedInStatus(response);
  1016. } else {
  1017. setUserLoggedInStatus(response, response.data.profile[userAcct.userId]);
  1018. if (callback != null) {
  1019. callback(response);
  1020. }
  1021. }
  1022. },
  1023. dataType: 'jsonp'
  1024. });
  1025. } else {
  1026. setUserLoggedInStatus(response);
  1027. }
  1028. }
  1029. if (callback != null) {
  1030. callback(response);
  1031. }
  1032. });
  1033. }
  1034. }
  1035. // TODO: for on prem, we need to use an ajax call directly to share instead of accounts
  1036. // Log into axure accounts
  1037. $axure.player.axureLogin = function axureLogin(email, password, success, failure, saml) {
  1038. if (window.$axshare != null) {
  1039. password = password === passHint ? "" : password;
  1040. $axshare.login(email, password, false, function (response) {
  1041. if (response.redirecturl !== "" && response.redirecturl != null) {
  1042. saml(response);
  1043. return;
  1044. }
  1045. if (response.success && (response.verified || isSubInstance)) {
  1046. if (isSafari()) setUserLoggedInStatus(response);
  1047. $axure.player.axureAuth(success);
  1048. } else {
  1049. failure(response);
  1050. }
  1051. });
  1052. // TODO: add ldap authentication
  1053. //}, window.ON_PREM_LDAP_ENABLED);
  1054. } else {
  1055. failure();
  1056. }
  1057. }
  1058. function playerLogout() {
  1059. userAcct.isUsingAxureAcct = false;
  1060. userAcct.userId = '';
  1061. userAcct.userProfileImg = '';
  1062. // If feedback is loaded, update feedback with new account information
  1063. if (typeof feedback !== 'undefined') feedback.updateUserAccountInfo(userAcct);
  1064. }
  1065. $axure.player.logout = function (feedbackLogout) {
  1066. var completeLogout = playerLogout;
  1067. if (feedbackLogout) {
  1068. completeLogout = function () {
  1069. feedbackLogout();
  1070. playerLogout();
  1071. }
  1072. }
  1073. if (window.$axshare != null) {
  1074. $axshare.logout(completeLogout);
  1075. } else {
  1076. completeLogout();
  1077. }
  1078. }
  1079. /*
  1080. * TODO: Start of Login/Account Mgmt UI, which will need to be updated (currenly uses feedback9.css often)
  1081. */
  1082. function buildAccountLoginPopup() {
  1083. return [
  1084. '<div class="axClearMsgBubble_Player axureLoginBubble_Player">',
  1085. ' <div class="axureLoginBubbleContainer_Player">',
  1086. ' <span style="font-weight: bold; font-size: 10px;">Login into your Axure Cloud account</span>',
  1087. ' <input type="text" autocapitalize="none" name="email" class="axureEmail" style="margin-top: 7px;"/>',
  1088. ' <input name="password" autocapitalize="none" class="axurePassword" />',
  1089. ' <div class="feedbackGreenBtn_Player">LOG IN</div>',
  1090. ' <div class="errorMessage"></div>',
  1091. ' <div id="playerSignUpLink" style="text-align: right; margin-top: 5px; font-size: 10px;">',
  1092. ' <span>No account? <a class="axureSignUpLink" href="', window.AXSHARE_HOST_SECURE_URL, '" target="_blank">Sign Up</a></span>',
  1093. ' </div>',
  1094. ' </div>',
  1095. '</div>'
  1096. ].join("");
  1097. }
  1098. // Bind events to axure login speech bubble (watermark, login, errors, click outside)
  1099. function bindAxureLoginContainerEvent() {
  1100. var $container = $("#accountLoginContainer");
  1101. $container.find('input[name="email"]').addClass("watermark").val(emailHint).focus(function () {
  1102. if ($(this).val() === emailHint) {
  1103. $(this).removeClass("watermark").val("");
  1104. }
  1105. }).blur(function () {
  1106. if ($(this).val() === "") {
  1107. $(this).addClass("watermark").val(emailHint);
  1108. }
  1109. $container.find('.errorMessage').text('');
  1110. $container.find('.errorMessage').hide();
  1111. }).keyup(function (event) {
  1112. if (event.keyCode == 13) {
  1113. $container.find('.feedbackGreenBtn').click();
  1114. }
  1115. });
  1116. $container.find('input[name="password"]').addClass("watermark").val(passHint).focus(function () {
  1117. if ($(this).val() === passHint) {
  1118. $(this).removeClass("watermark").val("");
  1119. //$(this).removeClass("watermark").val("").attr("type", "password");
  1120. // Note: this might be an issue since jquery doesn't like it. Test in IE
  1121. $(this)[0].setAttribute('type', 'password');
  1122. }
  1123. }).blur(function () {
  1124. if ($(this).val() === "") {
  1125. $(this).val(passHint).addClass("watermark");
  1126. //$(this).val(passHint).addClass("watermark").removeAttr("type");
  1127. // Note: this might be an issue since jquery doesn't like it. Test in IE
  1128. $(this)[0].setAttribute('type', 'text');
  1129. }
  1130. $container.find('.errorMessage').text('');
  1131. $container.find('.errorMessage').hide();
  1132. }).keyup(function (event) {
  1133. if (event.keyCode == 13) {
  1134. $container.find('.feedbackGreenBtn_Player').click();
  1135. }
  1136. });
  1137. // Login Submit Event
  1138. $container.find('.feedbackGreenBtn_Player').click(function (e) {
  1139. var email = $container.find('.axureEmail').val();
  1140. var password = $container.find('.axurePassword').val();
  1141. $axure.player.axureLogin(email, password, function (response) {
  1142. // Success
  1143. // Clear out fields
  1144. $container.find('.axureEmail').val(emailHint).addClass("watermark");
  1145. $container.find('.axurePassword').val(passHint).addClass("watermark");
  1146. $container.find('.axurePassword')[0].setAttribute('type', 'text');
  1147. closePopup();
  1148. }, function (response) {
  1149. // Failure
  1150. $container.find('.errorMessage').text(response != null && response.message ? response.message : "There was an error connecting to the server, please try again later.");
  1151. $container.find('.errorMessage').show();
  1152. }, function (response) {
  1153. // SAML User
  1154. $container.find('.errorMessage').empty();
  1155. $container.find('.errorMessage').append("Please <a class='refreshLink' style='text-decoration: underline;'>refresh</a> this page after logging in via your identity provider.");
  1156. $container.find('.errorMessage').show();
  1157. window.open(response.redirecturl, '_blank');
  1158. $container.find('.errorMessage').find('.refreshLink').click(function () {
  1159. location.reload(true);
  1160. });
  1161. });
  1162. });
  1163. };
  1164. function initializeSignIn() {
  1165. if (typeof PREVIEW_INFO === 'undefined' && $axure.player.settings.isAxshare) {
  1166. (function finishInit() {
  1167. if (window.$axshare == null || $axshare.auth == null || $axshare.login == null) {
  1168. setTimeout(finishInit, 50);
  1169. } else {
  1170. // Call to set readOnlyMode, readOnlyMessage, and isSubinstance (readOnlyMode/Message currently only used for feedback9)
  1171. $.ajax({
  1172. type: 'GET',
  1173. url: feedbackServiceUrl + '/GetShareStatus',
  1174. data: {},
  1175. success: function (response) {
  1176. //readOnlyMode = response.readOnlyMode;
  1177. //readOnlyMessage = response.readOnlyMessage;
  1178. isSubInstance = response.isSubInstance;
  1179. if (isSubInstance) $('#accountLoginContainer').find("#playerSignUpLink").hide();
  1180. // For now, calling methods to set these values in feedback on start (could later make a general method to retrieve these values from player)
  1181. if (typeof feedback !== 'undefined') {
  1182. feedback.setReadOnlyModeAndMessage(response.readOnlyMode, response.readOnlyMessage);
  1183. feedback.setIsSubInstance(isSubInstance);
  1184. }
  1185. },
  1186. dataType: 'jsonp'
  1187. });
  1188. // Login container
  1189. $("#accountLoginContainer").append(buildAccountLoginPopup());
  1190. bindAxureLoginContainerEvent();
  1191. // Attempt to auth and acquire account information, then update top panel
  1192. $axure.player.axureAuth();
  1193. }
  1194. })();
  1195. }
  1196. }
  1197. function overflowIsHidden(node) {
  1198. var style = getComputedStyle(node);
  1199. return style.overflow === 'hidden' || style.overflowX === 'hidden' || style.overflowY === 'hidden';
  1200. }
  1201. function findNearestScrollableParent(firstNode) {
  1202. var node = firstNode;
  1203. var scrollable = null;
  1204. while (!scrollable && node) {
  1205. if (node.scrollWidth > node.clientWidth || node.scrollHeight > node.clientHeight) {
  1206. if (!overflowIsHidden(node) || $(node).css('-webkit-overflow-scrolling') === 'touch') {
  1207. scrollable = node;
  1208. }
  1209. }
  1210. node = node.parentNode;
  1211. }
  1212. return scrollable;
  1213. }
  1214. function getScrollOwner(target) {
  1215. var owner = findNearestScrollableParent(target);
  1216. if (!owner || owner === document.documentElement || owner === document.body || $(owner).parents('#topPanel').length || owner == document.getElementById('forwardSlash')) {
  1217. return null;
  1218. }
  1219. return owner;
  1220. }
  1221. function removeElasticScrollFromIframe() {
  1222. var $iframe = $($('#mainPanel').find('iframe')[0].contentWindow);
  1223. $iframe[0].document.body.addEventListener('touchmove', function (event) {
  1224. if (!getScrollOwner(event.target)) {
  1225. event.preventDefault();
  1226. }
  1227. }, { passive: false });
  1228. }
  1229. $(document).ready(function () {
  1230. (function finishPlayerInit() {
  1231. if ($axure.player.settings.isAxshare) {
  1232. $axure.page.bind('load.start', contentDocument_onload);
  1233. if ($axure.player.settings.loadFeedbackPlugin) {
  1234. $axure.utils.loadJS('/Scripts/plugins/feedback/feedback9.js');
  1235. /******* DEBUG: Allows for debugging/viewing feedback9.js in browser inspect mode ******/
  1236. //var hdr = document.createElement('script');
  1237. //hdr.type = "text/javascript"
  1238. //hdr.src = '/Scripts/plugins/feedback/feedback9.js';
  1239. //document.head.appendChild(hdr);
  1240. }
  1241. }
  1242. initializeEvents();
  1243. initializeMainFrame();
  1244. $('.leftPanel').width(0);
  1245. $('#maximizePanelContainer').hide();
  1246. if ($axure.player.settings.startCollapsed) {
  1247. collapse();
  1248. $('.leftPanel').width(0);
  1249. var maxPanelWidth = $('#maximizePanel').width();
  1250. setTimeout(function() {
  1251. $('#maximizePanel').animate({
  1252. left:'-' + maxPanelWidth + 'px'
  1253. }, 300);
  1254. }, 2000);
  1255. }
  1256. if (MOBILE_DEVICE) {
  1257. $('body').removeClass('hashover');
  1258. if (SAFARI) {
  1259. // Stop pinch zoom (stopping all gestures for now)
  1260. // Gesturestart is only supported in Safari
  1261. document.addEventListener("gesturestart", function (e) {
  1262. e.preventDefault();
  1263. });
  1264. }
  1265. if (IOS) {
  1266. // Attempt at removing elastic scroll while in mobile menu
  1267. var touching = false;
  1268. var pageYStart = 0;
  1269. var pageYOffset = 0;
  1270. document.body.addEventListener('touchend', function (event) {
  1271. if (getScrollOwner(event.target)) {
  1272. touching = false;
  1273. }
  1274. }, { passive: false });
  1275. document.body.addEventListener('touchmove', function (event) {
  1276. var owner = getScrollOwner(event.target)
  1277. if (!owner) {
  1278. event.preventDefault();
  1279. } else {
  1280. if ($(owner).scrollTop() == 0) {
  1281. if (touching) {
  1282. if (event.pageY >= pageYStart) {
  1283. event.preventDefault();
  1284. }
  1285. }
  1286. }
  1287. if ($(owner).scrollTop() + $(owner).height() == owner.scrollHeight) {
  1288. if (touching) {
  1289. if (event.pageY <= pageYStart) {
  1290. event.preventDefault();
  1291. }
  1292. }
  1293. }
  1294. }
  1295. }, { passive: false });
  1296. document.body.addEventListener('touchstart', function (event) {
  1297. var owner = getScrollOwner(event.target);
  1298. if (owner) {
  1299. if ($(owner).scrollTop() == 0) {
  1300. touching = true;
  1301. pageYStart = event.pageY;
  1302. pageYOffset = event.pageY;
  1303. }
  1304. if ($(owner).scrollTop() + $(owner).height() == owner.scrollHeight) {
  1305. touching = true;
  1306. pageYStart = event.pageY;
  1307. pageYOffset = event.pageY;
  1308. }
  1309. }
  1310. }, { passive: false });
  1311. removeElasticScrollFromIframe();
  1312. $('html').css('-webkit-tap-highlight-color', 'transparent');
  1313. // Stop iOS from automatically scaling parts of the mobile player
  1314. // Could stop automatic scaling on Ipads as well that we actually want, but for now, seems fine
  1315. $('body').css('-webkit-text-size-adjust', '100%');
  1316. // Prepare for Iphone X hacks
  1317. // Link for dimensions: https://kapeli.com/cheat_sheets/iOS_Design.docset/Contents/Resources/Documents/index
  1318. var ratio = window.devicePixelRatio || 1;
  1319. // Regular iphoneX
  1320. if (IOS && window.screen.width * ratio == 1125 && window.screen.height * ratio === 2436) {
  1321. iphoneX = true;
  1322. }
  1323. // Iphone XS Max and Iphone XR
  1324. if (IOS && window.screen.width == 414 && window.screen.height === 896) {
  1325. iphoneX = true;
  1326. }
  1327. window.addEventListener("orientationchange", function () {
  1328. var viewport = document.querySelector("meta[name=viewport]");
  1329. //so iOS doesn't zoom when switching back to portrait
  1330. if (iphoneX) {
  1331. viewport.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0, viewport-fit=cover');
  1332. viewport.setAttribute('content', 'width=device-width, initial-scale=1.0, viewport-fit=cover');
  1333. } else {
  1334. viewport.setAttribute('content', 'width=device-width, initial-scale=1.0, maximum-scale=1.0');
  1335. viewport.setAttribute('content', 'width=device-width, initial-scale=1.0');
  1336. }
  1337. $axure.player.resizeContent();
  1338. }, false);
  1339. $axure.page.bind('load.start', function () {
  1340. $axure.player.resizeContent();
  1341. });
  1342. }
  1343. // Always append both mobile browser menu and native menu, as app might not have returned value signifying native at this point
  1344. appendNativePrototypeControlFrame();
  1345. appendMobileBrowserControlFrame();
  1346. appendProjectOptions();
  1347. }
  1348. initializeLogo();
  1349. initializePreview();
  1350. $axure.player.resizeContent(true);
  1351. // Has timeout to keep waiting to build sign in controls while axAccount is still loading
  1352. initializeSignIn();
  1353. })();
  1354. });
  1355. function appendProjectOptions() {
  1356. var toAppend = '';
  1357. toAppend += '<div id="projectOptionsHost" class="mobileOnlyPanel mobileMode">';
  1358. toAppend += ' <div class="pluginNameHeader">PROJECT OPTIONS</div>';
  1359. toAppend += ' <div id="projectOptionsScrollContainer">';
  1360. toAppend += ' <div class="mobileSubHeader">Hotspots</div>';
  1361. toAppend += ' <div id="projectOptionsShowHotspots" class="mobileText projectOptionsHotspotsRow" style="border-bottom: solid 1px #c7c7c7">';
  1362. toAppend += ' <div id="projectOptionsHotspotsCheckbox"></div>';
  1363. toAppend += ' Show Hotspots</div> ';
  1364. toAppend += ' <div class="mobileSubHeader" style="margin-top: 16px">Scale</div>';
  1365. toAppend += ' <div id="projectOptionsScaleContainer" class="mobileText"></div>';
  1366. toAppend += ' <div id="projectOptionsAdaptiveViewsHeader" class="mobileSubHeader" style="margin-top: 16px">Adaptive Views</div>';
  1367. toAppend += ' <div id="projectOptionsAdaptiveViewsContainer" class="mobileText"></div>'
  1368. toAppend += ' </div>'
  1369. toAppend += '</div>';
  1370. $('#mHideSidebar').prepend(toAppend);
  1371. $(('#projectOptionsHost')).click(function (e) { e.stopPropagation(); });
  1372. if (isMobileMode()) $axure.player.resizeContent();
  1373. }
  1374. function appendMobileBrowserControlFrame() {
  1375. var toAppend = "";
  1376. toAppend += '<div id="mobileBrowserControlFrame" class="mobilePrototypeControlFrame">';
  1377. toAppend += ' <div id="return" style="width:100%; position:relative; top:-15px; float:left">';
  1378. toAppend += ' <div id="closeBackground" class="circleBackground">';
  1379. toAppend += ' <div id="forwardSlash" class="closeIconSlash"><div id="backwardSlash" class="closeIconSlash"></div></div>';
  1380. toAppend += ' </div>';
  1381. toAppend += ' </div>';
  1382. toAppend += '</div>';
  1383. $('#mobileControlFrameContainer').append(toAppend);
  1384. $('#closeBackground').click(collapse);
  1385. // iOS will do incorrect click position / content bounds calculation which results in scroll getting reset to (0, 0)
  1386. if (IOS) $('#mobileControlFrameContainer').on($axure.eventNames.mouseDownName, function (e) { e.stopPropagation(); });
  1387. }
  1388. function appendNativePrototypeControlFrame() {
  1389. var toAppend = "";
  1390. toAppend += '<div id="nativeAppControlFrame" class="mobilePrototypeControlFrame">';
  1391. toAppend += ' <ul id="nativeMenuBlueBackground">';
  1392. toAppend += ' <li style="width:30%; float:left;">';
  1393. toAppend += ' <div id="exit" class="nativePrototypeButton" >';
  1394. toAppend += ' <div>';
  1395. toAppend += ' <div id="exitIcon"></div>';
  1396. toAppend += ' <div id="exitText" class="nativeMenuText">Exit</div>';
  1397. toAppend += ' </div>';
  1398. toAppend += ' </div>';
  1399. toAppend += ' </li>';
  1400. toAppend += ' <li id="return" style="width:40%; position:relative; top:-15px; float:left">';
  1401. toAppend += ' <div id="returnBackground" class="circleBackground">';
  1402. toAppend += ' <div id="returnIcon"></div>';
  1403. toAppend += ' </div>';
  1404. toAppend += ' <div id="returnText" class="nativeMenuText">Return to Prototype</div>';
  1405. toAppend += ' </li>';
  1406. toAppend += ' <li style="width:30%; float:right;">';
  1407. toAppend += ' <div id="refresh" class="nativePrototypeButton" >';
  1408. toAppend += ' <div>';
  1409. toAppend += ' <div id="refreshIcon"></div>';
  1410. toAppend += ' <div id="refreshText" class="nativeMenuText">Refresh</div>';
  1411. toAppend += ' </div>';
  1412. toAppend += ' </div>';
  1413. toAppend += ' </li>';
  1414. toAppend += ' </ul>';
  1415. toAppend += '</div>';
  1416. $('#mobileControlFrameContainer').append(toAppend);
  1417. var barHeight = IOS ? (iphoneX ? '82px' : '72px') : '60px';
  1418. var returnIconDisplacement = IOS ? '-15px': '-20px';
  1419. var iconTopMargin = IOS ? '14px': '7px';
  1420. var returnTextTopMargin = IOS ? '9px': '7px';
  1421. document.getElementById('nativeAppControlFrame').style.height = barHeight;
  1422. document.getElementById('nativeMenuBlueBackground').style.height = barHeight;
  1423. document.getElementById('return').style.top = returnIconDisplacement;
  1424. document.getElementById('returnText').style.marginTop = returnTextTopMargin;
  1425. document.getElementById('refreshIcon').style.marginTop = iconTopMargin;
  1426. document.getElementById('exitIcon').style.marginTop = iconTopMargin;
  1427. addAppButtonClickListener("exit");
  1428. addAppButtonClickListener("refresh");
  1429. $('#returnBackground').click(collapse);
  1430. $('#nativeAppControlFrame').on('touchmove', function (e) {
  1431. e.stopPropagation();
  1432. }, false);
  1433. }
  1434. function addAppButtonClickListener(id) {
  1435. var func = function () { IOS ? window.webkit.messageHandlers.prototypeMenuButtonClick.postMessage(id) : ShareApp.PrototypeMenuButtonClick(id); };
  1436. document.getElementById(id).addEventListener("click", func, false);
  1437. }
  1438. function toggleSitemap() {
  1439. $axure.player.showPlugin(1);
  1440. }
  1441. function closePopup() {
  1442. var $container = $('.popup');
  1443. var isLeftPanel = $container.hasClass('leftPanel');
  1444. $container.removeClass('popup');
  1445. $('#overflowMenuButton').removeClass('selected');
  1446. $('#interfaceAdaptiveViewsContainer').removeClass('selected');
  1447. $container.hide();
  1448. $('div.splitterMask').unbind($axure.eventNames.mouseDownName, closePopup);
  1449. $('div.splitterMask').remove();
  1450. }
  1451. $axure.player.closePopup = closePopup;
  1452. function showPopup($container) {
  1453. if ($('#browserOutOfDateNotification').is(":visible")) return;
  1454. $container.addClass('popup');
  1455. $container.show();
  1456. $('<div class="splitterMask"></div>').insertAfter($container);
  1457. $('div.splitterMask').bind($axure.eventNames.mouseDownName, closePopup);
  1458. }
  1459. $axure.player.showPopup = showPopup;
  1460. function toggleAdaptiveViewsPopup() {
  1461. if (($('#interfaceAdaptiveViewsListContainer').hasClass('popup'))) {
  1462. closePopup();
  1463. } else {
  1464. $('#interfaceAdaptiveViewsContainer').addClass('selected');
  1465. showPopup($('#interfaceAdaptiveViewsListContainer'));
  1466. }
  1467. }
  1468. function toggleOverflowMenuPopup() {
  1469. if (($('#overflowMenuContainer').hasClass('popup'))) {
  1470. closePopup();
  1471. } else {
  1472. $('#overflowMenuButton').addClass('selected');
  1473. showPopup($('#overflowMenuContainer'));
  1474. }
  1475. }
  1476. var startSplitX;
  1477. var startSplitWidth;
  1478. function startLeftSplit() {
  1479. startSplitX = window.event.pageX;
  1480. startSplitWidth = lastLeftPanelWidth;
  1481. var $left = $('#lsplitbar');
  1482. $left.addClass('active');
  1483. $('<div class="splitterMask"></div>').insertAfter($left);
  1484. $(document).bind($axure.eventNames.mouseMoveName, doLeftSplitMove).bind($axure.eventNames.mouseUpName, endLeftSplitMove);
  1485. }
  1486. function startRightSplit() {
  1487. startSplitX = window.event.pageX;
  1488. startSplitWidth = lastRightPanelWidth;
  1489. var $left = $('#rsplitbar');
  1490. $left.addClass('active');
  1491. $('<div class="splitterMask"></div>').insertAfter($left);
  1492. $(document).bind($axure.eventNames.mouseMoveName, doRightSplitMove).bind($axure.eventNames.mouseUpName, endRightSplitMove);
  1493. }
  1494. function doLeftSplitMove() {
  1495. var currentX = window.event.pageX;
  1496. var newWidth = Math.min(startSplitWidth + currentX - startSplitX, $(window).width() - $('.rightPanel').width(), $(window).width() - lastRightPanelWidthDefault);
  1497. lastLeftPanelWidth = Math.max(lastLeftPanelWidthDefault, newWidth);
  1498. $('.leftPanel').width(lastLeftPanelWidth ? lastLeftPanelWidth : lastLeftPanelWidthDefault);
  1499. $('#lsplitbar').css('left', $('.leftPanel').width() - 4);
  1500. $axure.player.updateClippingBoundsWidth();
  1501. $axure.player.refreshViewPort();
  1502. }
  1503. function doRightSplitMove() {
  1504. var currentX = window.event.pageX;
  1505. var newWidth = Math.min(startSplitWidth - currentX + startSplitX, $(window).width() - $('.leftPanel').width(), $(window).width() - lastLeftPanelWidthDefault);
  1506. lastRightPanelWidth = Math.max(lastRightPanelWidthDefault, newWidth);
  1507. $('.rightPanel').width(lastRightPanelWidth ? lastRightPanelWidth : lastRightPanelWidthDefault);
  1508. $('#rsplitbar').css('left', $(window).width() - $('.rightPanel').width());
  1509. $axure.player.updateClippingBoundsWidth();
  1510. $axure.player.refreshViewPort();
  1511. }
  1512. function endLeftSplitMove() {
  1513. $('div.splitterMask').remove();
  1514. var $left = $('#lsplitbar');
  1515. $left.removeClass('active');
  1516. $(document).unbind($axure.eventNames.mouseMoveName, doLeftSplitMove).unbind($axure.eventNames.mouseUpName, endLeftSplitMove);
  1517. setAdaptiveView()
  1518. }
  1519. function endRightSplitMove() {
  1520. $('div.splitterMask').remove();
  1521. var $left = $('#rsplitbar');
  1522. $left.removeClass('active');
  1523. $(document).unbind($axure.eventNames.mouseMoveName, doRightSplitMove).unbind($axure.eventNames.mouseUpName, endRightSplitMove);
  1524. setAdaptiveView()
  1525. }
  1526. var startMX;
  1527. var startMLeft;
  1528. var startMElement;
  1529. var maxMLeft;
  1530. var getMaxMLeft = function () {
  1531. if ($('.rightPanel.mobileMode').length == 0) return $('.leftPanel.mobileMode').last().position().left + 100;
  1532. return $('.rightPanel.mobileMode').last().position().left + 100;
  1533. }
  1534. function startM(e) {
  1535. // Android touch event does not define pageX directly
  1536. if(window.event.pageX) {
  1537. startMX = window.event.pageX;
  1538. } else {
  1539. startMX = window.event.touches[0].pageX;
  1540. }
  1541. startMElement = window.event.target.id;
  1542. var $m = $('#mHideSidebar');
  1543. startMLeft = Number($m.css('left').replace('px', ''));
  1544. $(document).bind($axure.eventNames.mouseMoveName, doMMove).bind($axure.eventNames.mouseUpName, endMMove);
  1545. // Must stop propagation on iOS; otherwise scroll position of content will be reset to (0, 0)
  1546. // (likely due to position of click being calculated as out of bounds for outerContainer -- iOS is not adding scroll offset to bounds)
  1547. if (IOS) { e.stopPropagation() };
  1548. }
  1549. function doMMove() {
  1550. var $m = $('#mHideSidebar');
  1551. if(window.event.pageX) {
  1552. currentX = window.event.pageX;
  1553. } else {
  1554. currentX = window.event.touches[0].pageX;
  1555. }
  1556. var deltaX = currentX - startMX;
  1557. if (Math.abs(deltaX) > 0 && $('.splitterMask').length == 0) {
  1558. $('<div class="splitterMask"></div>').insertAfter($m);
  1559. }
  1560. var newLeft = startMLeft + deltaX;
  1561. newLeft = Math.min(0, newLeft);
  1562. newLeft = Math.max(-getMaxMLeft(), newLeft);
  1563. $m.css('left', newLeft + 'px');
  1564. }
  1565. function endMMove(e) {
  1566. $('div.splitterMask').remove();
  1567. $(document).unbind($axure.eventNames.mouseMoveName, doMMove).unbind($axure.eventNames.mouseUpName, endMMove);
  1568. e.stopPropagation();
  1569. var $m = $('#mHideSidebar');
  1570. if(window.event.pageX) {
  1571. currentX = window.event.pageX;
  1572. } else {
  1573. currentX = window.event.changedTouches[0].pageX;
  1574. }
  1575. var deltaX = currentX - startMX;
  1576. if (deltaX != 0 || startMElement != 'mHideSidebar') {
  1577. adjustM(currentX < startMX ? 'left' : 'right', true);
  1578. }
  1579. }
  1580. function adjustM(direction, animate) {
  1581. var $m = $('#mHideSidebar');
  1582. var duration = animate ? 100 : 0;
  1583. var newLeft = Number($m.css('left').replace('px', ''));
  1584. if (!$m.is(':visible') || newLeft > -100) {
  1585. $m.animate({ 'left': '-60px' }, duration);
  1586. } else if (newLeft < -getMaxMLeft() + 100) {
  1587. $m.animate({ 'left': (-getMaxMLeft() + 125) + 'px' }, duration);
  1588. } else if (direction == 'left') {
  1589. var handled = false;
  1590. var $panels = $('.rightPanel.mobileMode, .leftPanel.mobileMode');
  1591. $panels.each(function () {
  1592. var panelX = $(this).position().left;
  1593. if (panelX > -newLeft) {
  1594. $m.animate({ 'left': (-panelX + 25) + 'px' }, duration);
  1595. handled = true;
  1596. return false;
  1597. }
  1598. });
  1599. if (!handled) {
  1600. $m.animate({ 'left': (-$panels.last().position().left + 25) + 'px' }, duration);
  1601. }
  1602. } else if (direction == 'right') {
  1603. var handled = false;
  1604. var $panels = $('.rightPanel.mobileMode, .leftPanel.mobileMode');
  1605. $($panels.get().reverse()).each(function () {
  1606. var panelRight = $(this).position().left + $(this).width();
  1607. if (panelRight < -newLeft + $(window).width()) {
  1608. $m.animate({ 'left': (-$(this).position().left + 25) + 'px' }, duration);
  1609. handled = true;
  1610. return false;
  1611. }
  1612. });
  1613. if (!handled) {
  1614. $m.animate({ 'left': '-60px' }, duration);
  1615. }
  1616. }
  1617. }
  1618. function repositionPinsOnScaleChange(data) {
  1619. var $pins = $('#existingPinsOverlay').children();
  1620. for (var i = 0; i < $pins.length; i++) {
  1621. // calculate new position of pin
  1622. const left = parseFloat($($pins[i]).attr('data-x'));
  1623. const top = parseFloat($($pins[i]).attr('data-y'));
  1624. const width = $($pins[i]).width();
  1625. const height = $($pins[i]).height();
  1626. // Get current scale of mainPanelContainer
  1627. // MainPanelContainer scaled without setContentScale message
  1628. var scale = $('#mainPanelContainer').css('transform');;
  1629. scale = (scale == "none") ? 1 : Number(scale.substring(scale.indexOf('(') + 1, scale.indexOf(',')));
  1630. const scaledLeft = (left * scale) - (width / 2);
  1631. const scaledTop = (top * scale) - (height / 2);
  1632. $($pins[i]).css('left', scaledLeft + 'px');
  1633. $($pins[i]).css('top', scaledTop + 'px');
  1634. }
  1635. // Distance from left of project content to origin (used for pins positioning when on a centered page in Scale to Fit mode)
  1636. if (typeof data.contentOriginOffset !== "undefined") contentLeftOfOriginOffset = data.contentOriginOffset;
  1637. }
  1638. function messageCenter_message(message, data) {
  1639. if (message == 'expandFrame') expand();
  1640. else if (message == 'getCollapseFrameOnLoad' && $axure.player.settings.startCollapsed && !MOBILE_DEVICE) $axure.messageCenter.postMessage('collapseFrameOnLoad');
  1641. else if (message == 'tripleClick') {
  1642. if ($axure.player.isMobileMode() || MOBILE_DEVICE) expand();
  1643. } else if (message == 'setContentScale') {
  1644. if (data.clipToView) {
  1645. var scaleVal = $('.vpScaleOption').find('.selectedRadioButton').parent().attr('val');
  1646. if (scaleVal == '2' || (!MOBILE_DEVICE && scaleVal == '0')) {
  1647. var scaleN = newScaleN = $('#mainPanel').width() / data.viewportWidth;
  1648. var hScaleN = ($('#mainPanel').height()) / data.viewportHeight;
  1649. if (hScaleN < scaleN) scaleN = newScaleN = hScaleN;
  1650. if(scaleVal == '0') scaleN = Math.min(1, scaleN);
  1651. var scale = 'scale(' + scaleN + ')';
  1652. $('#mainPanelContainer').css({
  1653. 'transform': scale,
  1654. 'transform-origin': ''
  1655. });
  1656. }
  1657. } else {
  1658. if (data.scaleN != 1) {
  1659. var scale = 'scale(' + data.scaleN + ')';
  1660. var width = 100 / data.scaleN + '%';
  1661. var height = Number($('#mainPanelContainer').css('height').replace('px', '')) / data.scaleN + 'px';
  1662. $('#mainPanelContainer').css({
  1663. 'transform': scale,
  1664. 'transform-origin': '0px 0px',
  1665. 'width': width,
  1666. 'height': height
  1667. });
  1668. //$('#clipFrameScroll').css('height' , height + 'px');
  1669. //$('#mainFrame').css('height' , height + 'px');
  1670. $('#clipFrameScroll').height(height);
  1671. $('#mainFrame').height(height);
  1672. }
  1673. }
  1674. repositionPinsOnScaleChange(data);
  1675. repositionClippingBoundsScroll();
  1676. // Fix for edge not redrawing content after scale change
  1677. if ($axure.browser.isEdge) {
  1678. newHeight = window.innerHeight - ((!isMobileMode() && $('#topPanel').is(':visible')) ? $('#topPanel').height() : 0);
  1679. newWidth = $(window).width();
  1680. $('#outerContainer').height(newHeight).width(newWidth);
  1681. $('#mainPanel').height(newHeight);
  1682. $('#clippingBounds').height(newHeight);
  1683. }
  1684. }
  1685. }
  1686. function getInitialUrl() {
  1687. var shortId = getHashStringVar(PAGE_ID_NAME);
  1688. var foundById = [];
  1689. if (shortId.length > 0) {
  1690. getPageUrlsById(shortId, foundById, undefined);
  1691. if (foundById.length == 1) return foundById[0];
  1692. }
  1693. var pageName = getHashStringVar(PAGE_URL_NAME);
  1694. if (pageName.length > 0) return pageName + ".html";
  1695. else {
  1696. if (foundById.length > 0) return foundById[0];
  1697. var url = getFirstPageUrl($axure.document.sitemap.rootNodes);
  1698. return (url ? url : "about:blank");
  1699. }
  1700. }
  1701. var getPageUrlsById = $axure.player.getPageUrlsById = function (packageId, foundById, nodes) {
  1702. if (!nodes) nodes = $axure.document.sitemap.rootNodes;
  1703. for (var i = 0; i < nodes.length; i++) {
  1704. var node = nodes[i];
  1705. if (node.id == packageId) foundById.push(node.url);
  1706. var hasChildren = (node.children && node.children.length > 0);
  1707. if (hasChildren) {
  1708. getPageUrlsById(packageId, foundById, node.children);
  1709. }
  1710. }
  1711. }
  1712. var getPageIdByUrl = $axure.player.getPageIdByUrl = function(url, nodes) {
  1713. if (!nodes) nodes = $axure.document.sitemap.rootNodes;
  1714. for (var i = 0; i < nodes.length; i++) {
  1715. var node = nodes[i];
  1716. if (node.url == url) return node.id;
  1717. else {
  1718. var hasChildren = (node.children && node.children.length > 0);
  1719. if (hasChildren) {
  1720. var id = getPageIdByUrl(url, node.children);
  1721. if (id) return id;
  1722. }
  1723. }
  1724. }
  1725. return null;
  1726. }
  1727. function getFirstPageUrl(nodes) {
  1728. for (var i = 0; i < nodes.length; i++) {
  1729. var node = nodes[i];
  1730. if (node.url) return node.url;
  1731. else {
  1732. var hasChildren = (node.children && node.children.length > 0);
  1733. if (hasChildren) {
  1734. var url = getFirstPageUrl(node.children);
  1735. if (url) return url;
  1736. }
  1737. }
  1738. }
  1739. return null;
  1740. }
  1741. function closePlayer() {
  1742. if ($axure.page.location) window.location.href = $axure.page.location;
  1743. else {
  1744. var pageFile = getInitialUrl();
  1745. var currentLocation = window.location.toString();
  1746. window.location.href = currentLocation.substr(0, currentLocation.lastIndexOf("/") + 1) + pageFile;
  1747. }
  1748. }
  1749. function replaceHash(newHash) {
  1750. var currentLocWithoutHash = window.location.toString().split('#')[0];
  1751. //We use replace so that every hash change doesn't get appended to the history stack.
  1752. //We use replaceState in browsers that support it, else replace the location
  1753. if (typeof window.history.replaceState != 'undefined') {
  1754. try {
  1755. //Chrome 45 (Version 45.0.2454.85 m) started throwing an error here when generated locally (this only happens with sitemap open) which broke all interactions.
  1756. //try catch breaks the url adjusting nicely when the sitemap is open, but all interactions and forward and back buttons work.
  1757. //Uncaught SecurityError: Failed to execute 'replaceState' on 'History': A history state object with URL 'file:///C:/Users/Ian/Documents/Axure/HTML/Untitled/start.html#p=home' cannot be created in a document with origin 'null'.
  1758. window.history.replaceState(null, null, currentLocWithoutHash + newHash);
  1759. } catch (ex) { }
  1760. } else {
  1761. window.location.replace(currentLocWithoutHash + newHash);
  1762. }
  1763. }
  1764. function collapse() {
  1765. if (IOS) {
  1766. $('body').off('touchstart');
  1767. $('body').off('touchend');
  1768. }
  1769. if ($axure.player.isMobileMode()) {
  1770. $('#mHideSidebar').hide();
  1771. $('#nativeAppControlFrame').hide();
  1772. $('#mobileBrowserControlFrame').hide();
  1773. } else {
  1774. $axure.player.deleteVarFromCurrentUrlHash('g');
  1775. $axure.player.setVarInCurrentUrlHash('c', 1);
  1776. if (!MOBILE_DEVICE) $('#maximizePanelContainer').show();
  1777. lastLeftPanelWidth = $('.leftPanel').width();
  1778. lastRightPanelWidth = $('.rightPanel').width();
  1779. $('.leftPanel').hide();
  1780. $('.rightPanel').hide();
  1781. $('#topPanel').hide();
  1782. $('.splitbar').hide();
  1783. $('#mainPanel').width($(window).width());
  1784. $('#clippingBounds').width($(window).width());
  1785. $('#clippingBounds').css('left', '0px');
  1786. $(window).resize();
  1787. $(document).trigger('sidebarCollapse');
  1788. $('#maximizeButton').addClass('rotated');
  1789. }
  1790. }
  1791. // This will return true if prototype is opened from version of app after update with code that sets this value
  1792. // (won't be able to distinguish between browser and outdated app)
  1793. var isShareApp = function () { return /ShareApp/.test(navigator.userAgent); }
  1794. function expand() {
  1795. if ($axure.player.isMobileMode()) {
  1796. $('#mHideSidebar').show();
  1797. $('#mobileControlFrameContainer').show();
  1798. isShareApp() ? $('#nativeAppControlFrame').show() : $('#mobileBrowserControlFrame').show();
  1799. } else {
  1800. $minimizeContainer = $('#interfaceControlFrameMinimizeContainer');
  1801. $minimizeContainer.removeClass('collapseHovered');
  1802. $axure.player.deleteVarFromCurrentUrlHash('c');
  1803. $('#maximizeButton').removeClass('rotated');
  1804. $('#maximizePanelContainer').hide();
  1805. $axure.player.restorePlugins();
  1806. $('#topPanel').show();
  1807. $(window).resize();
  1808. $(document).trigger('sidebarExpanded');
  1809. }
  1810. }
  1811. function mainFrame_onload() {
  1812. if ($axure.page.pageName) document.title = $axure.page.pageName;
  1813. }
  1814. function getQueryString(query) {
  1815. var qstring = self.location.href.split("?");
  1816. if (qstring.length < 2) return "";
  1817. return GetParameter(qstring, query);
  1818. }
  1819. function GetParameter(qstring, query) {
  1820. var prms = qstring[1].split("&");
  1821. var frmelements = new Array();
  1822. var currprmeter, querystr = "";
  1823. for (var i = 0; i < prms.length; i++) {
  1824. currprmeter = prms[i].split("=");
  1825. frmelements[i] = new Array();
  1826. frmelements[i][0] = currprmeter[0];
  1827. frmelements[i][1] = currprmeter[1];
  1828. }
  1829. for (j = 0; j < frmelements.length; j++) {
  1830. if (frmelements[j][0].toLowerCase() == query.toLowerCase()) {
  1831. querystr = frmelements[j][1];
  1832. break;
  1833. }
  1834. }
  1835. return querystr;
  1836. }
  1837. function setHashStringVar(currentHash, varName, varVal) {
  1838. var varWithEqual = varName + '=';
  1839. var poundVarWithEqual = varVal === '' ? '' : '#' + varName + '=' + varVal;
  1840. var ampVarWithEqual = varVal === '' ? '' : '&' + varName + '=' + varVal;
  1841. var hashToSet = '';
  1842. var pageIndex = currentHash.indexOf('#' + varWithEqual);
  1843. if (pageIndex == -1) pageIndex = currentHash.indexOf('&' + varWithEqual);
  1844. if (pageIndex != -1) {
  1845. var newHash = currentHash.substring(0, pageIndex);
  1846. newHash = newHash == '' ? poundVarWithEqual : newHash + ampVarWithEqual;
  1847. var ampIndex = currentHash.indexOf('&', pageIndex + 1);
  1848. if (ampIndex != -1) {
  1849. newHash = newHash == '' ? '#' + currentHash.substring(ampIndex + 1) : newHash + currentHash.substring(ampIndex);
  1850. }
  1851. hashToSet = newHash;
  1852. } else if (currentHash.indexOf('#') != -1) {
  1853. hashToSet = currentHash + ampVarWithEqual;
  1854. } else {
  1855. hashToSet = poundVarWithEqual;
  1856. }
  1857. if (hashToSet != '' || varVal == '') {
  1858. return hashToSet;
  1859. }
  1860. return null;
  1861. }
  1862. $axure.player.setVarInCurrentUrlHash = function(varName, varVal) {
  1863. var newHash = setHashStringVar(window.location.hash, varName, varVal);
  1864. if (newHash != null) {
  1865. replaceHash(newHash);
  1866. }
  1867. }
  1868. function deleteHashStringVar(currentHash, varName) {
  1869. var varWithEqual = varName + '=';
  1870. var pageIndex = currentHash.indexOf('#' + varWithEqual);
  1871. if (pageIndex == -1) pageIndex = currentHash.indexOf('&' + varWithEqual);
  1872. if (pageIndex != -1) {
  1873. var newHash = currentHash.substring(0, pageIndex);
  1874. var ampIndex = currentHash.indexOf('&', pageIndex + 1);
  1875. //IF begin of string....if none blank, ELSE # instead of & and rest
  1876. //IF in string....prefix + if none blank, ELSE &-rest
  1877. if (newHash == '') { //beginning of string
  1878. newHash = ampIndex != -1 ? '#' + currentHash.substring(ampIndex + 1) : '';
  1879. } else { //somewhere in the middle
  1880. newHash = newHash + (ampIndex != -1 ? currentHash.substring(ampIndex) : '');
  1881. }
  1882. return newHash;
  1883. }
  1884. return null;
  1885. }
  1886. $axure.player.deleteVarFromCurrentUrlHash = function(varName) {
  1887. var newHash = deleteHashStringVar(window.location.hash, varName);
  1888. if (newHash != null) {
  1889. replaceHash(newHash);
  1890. }
  1891. }
  1892. function setUpController() {
  1893. //$axure.utils = _axUtils;
  1894. var _page = {};
  1895. $axure.page = _page;
  1896. $axure.utils.makeBindable(_page, ['load']);
  1897. var _player = function () {
  1898. };
  1899. $axure.player = _player;
  1900. //-----------------------------------------
  1901. //Global Var array, getLinkUrl function and setGlobalVar listener are
  1902. //for use in setting global vars in page url string when clicking a
  1903. //page in the sitemap
  1904. //-----------------------------------------
  1905. var _globalVars = {};
  1906. //-----------------------------------------
  1907. //Used by getLinkUrl below to check if local server is running
  1908. //in order to send back the global variables as a query string
  1909. //in the page url
  1910. //-----------------------------------------
  1911. var _shouldSendVarsToServer = function () {
  1912. //If exception occurs (due to page in content frame being from a different domain, etc)
  1913. //then run the check without the url (which will end up checking against sitemap url)
  1914. try {
  1915. var mainFrame = document.getElementById("mainFrame");
  1916. return $axure.shouldSendVarsToServer(mainFrame.contentWindow.location.href);
  1917. } catch (e) {
  1918. return $axure.shouldSendVarsToServer();
  1919. }
  1920. };
  1921. var _getLinkUrl = function (baseUrl) {
  1922. var toAdd = '';
  1923. for (var globalVarName in _globalVars) {
  1924. var val = _globalVars[globalVarName];
  1925. if (val != null) {
  1926. if (toAdd.length > 0) toAdd += '&';
  1927. toAdd += globalVarName + '=' + encodeURIComponent(val);
  1928. }
  1929. }
  1930. return toAdd.length > 0 ? baseUrl + (_shouldSendVarsToServer() ? '?' : '#') + toAdd + "&CSUM=1" : baseUrl;
  1931. };
  1932. $axure.getLinkUrlWithVars = _getLinkUrl;
  1933. $axure.messageCenter.addMessageListener(function (message, data) {
  1934. if (message == 'setGlobalVar') {
  1935. _globalVars[data.globalVarName] = data.globalVarValue;
  1936. }
  1937. });
  1938. $axure.messageCenter.addStateListener('page.data', function (key, value) {
  1939. for (var subKey in value) {
  1940. _page[subKey] = value[subKey];
  1941. }
  1942. $axure.page.triggerEvent('load');
  1943. });
  1944. // ---------------------------------------------
  1945. // Navigates the main frame (setting the currently visible page). If the link is relative,
  1946. // this method should test if it is actually a axure rp page being loaded and properly set
  1947. // up all the controller for the page if it is
  1948. // ---------------------------------------------
  1949. _page.navigate = function (url, includeVariables) {
  1950. var mainFrame = document.getElementById("mainFrame");
  1951. //var mainFrame = window.parent.mainFrame;
  1952. // if this is a relative url...
  1953. var urlToLoad;
  1954. if (url.indexOf(':') < 0 || url[0] == '/') {
  1955. var winHref = window.location.href;
  1956. var page = winHref.substring(0, winHref.lastIndexOf('/') + 1) + url;
  1957. urlToLoad = page;
  1958. } else {
  1959. urlToLoad = url;
  1960. }
  1961. if (!includeVariables) {
  1962. mainFrame.contentWindow.location.href = urlToLoad;
  1963. return;
  1964. }
  1965. var urlWithVars = $axure.getLinkUrlWithVars(urlToLoad);
  1966. var currentData = $axure.messageCenter.getState('page.data');
  1967. var currentUrl = currentData && currentData.location;
  1968. if (currentUrl && currentUrl.indexOf('#') != -1) currentUrl = currentUrl.substring(0, currentUrl.indexOf('#'))
  1969. // this is so we can make sure the current frame reloads if the variables have changed
  1970. // by default, if the location is the same but the hash code is different, the browser will not
  1971. // trigger a reload
  1972. mainFrame.contentWindow.location.href =
  1973. currentUrl && urlToLoad.toLowerCase() != currentUrl.toLowerCase()
  1974. ? urlWithVars
  1975. : 'resources/reload.html#' + encodeURI(urlWithVars);
  1976. };
  1977. var pluginIds = [];
  1978. var plugins = {};
  1979. var currentVisibleHostId = {};
  1980. // ---------------------------------------------
  1981. // Adds a tool box frame from a url to the interface. This is useful for loading plugins
  1982. // settings is an object that supports the following properties:
  1983. // - id : the id of the element for the plugin
  1984. // - context : the context to create the plugin host for
  1985. // - title : the user-visible caption for the plugin
  1986. // ---------------------------------------------
  1987. _player.createPluginHost = function (settings) {
  1988. if (!settings.context || !(settings.context === 'project' || settings.context === 'inspect')) {
  1989. //throw ('unknown context type');
  1990. return false;
  1991. }
  1992. if (settings.id == 'feedbackHost')
  1993. $('#overflowMenuContainer').prepend('<div id="showCommentsOption" class="showOption" style="order: 2"><div class="overflowOptionCheckbox"></div>Show Comments</div>');
  1994. if (!settings.id) throw ('each plugin host needs an id');
  1995. if (typeof PREVIEW_INFO === 'undefined') {
  1996. // Share-Hosted Prototype
  1997. if (settings.id == 'debugHost') { return false; }
  1998. if (settings.id == 'handoffHost') { $('#handoffControlFrameHeaderContainer').show(); }
  1999. } else {
  2000. // Preview Mode
  2001. if (settings.id == 'handoffHost') { return false; }
  2002. }
  2003. pluginIds[pluginIds.length] = settings.id;
  2004. plugins[settings.id] = settings;
  2005. var hostContainerId = settings.context + 'ControlFrameHostContainer';
  2006. hostContainerId = _player.isMobileMode() ? 'mHideSidebar' : 'outerContainer';
  2007. var panelClass = 'rightPanel';
  2008. var host;
  2009. if (settings.context == 'project') {
  2010. panelClass = 'leftPanel';
  2011. if (_player.isMobileMode() && $('#' + hostContainerId).find('#projectOptionsHost').length > 0) {
  2012. host = $('<div id="' + settings.id + '" class="' + panelClass + '"></div>')
  2013. .insertAfter('#projectOptionsHost');
  2014. } else {
  2015. host = $('<div id="' + settings.id + '" class="' + panelClass + '"></div>')
  2016. .prependTo('#' + hostContainerId);
  2017. }
  2018. } else {
  2019. if (!$('#separatorContainer').hasClass('hasLeft')) $('#separatorContainer').addClass('hasLeft');
  2020. host = $('<div id="' + settings.id + '" class="' + panelClass + '"></div>')
  2021. .appendTo('#' + hostContainerId);
  2022. }
  2023. $(('#' + settings.id)).click(function (e) { e.stopPropagation(); });
  2024. var controlContainerId = getControlContainerId(settings.id);
  2025. if (!_player.isMobileMode()) host.hide();
  2026. else _player.updatePlugins();
  2027. // TODO: border radius in ie and edge causes image to be blurry (for now, just remove border-radius)
  2028. var style = (IE || $axure.browser.isEdge) ? '" style="border-radius: 0': '';
  2029. var headerLink = $('<a pluginId="' + settings.id + '" title="' + settings.title + style + '" >' + (settings.context === 'inspect' ? ('<span>' + '</span>'): '&nbsp;') + '</a>');
  2030. headerLink.mousedown($axure.utils.curry(interfaceControlHeaderButton_click, settings.id)).wrap('<li id="' + settings.id + 'Btn"' + (settings.id == "handoffHost" ? ' style="display: none"' : '') + '>');
  2031. headerLink.parent().appendTo('#' + controlContainerId);
  2032. if (_player.isMobileMode()) $axure.player.resizeContent();
  2033. $(document).trigger('pluginCreated', [settings.gid]);
  2034. };
  2035. var getControlContainerId = function (id) {
  2036. return plugins[id].context + 'ControlFrameHeader';
  2037. }
  2038. var getVisiblePlugins = function () {
  2039. var ids = '';
  2040. for (var id in plugins) {
  2041. var context = plugins[id].context;
  2042. if (currentVisibleHostId[context] == id) {
  2043. ids += plugins[id].gid;
  2044. }
  2045. }
  2046. return ids;
  2047. }
  2048. _player.pluginVisibleChanged = function(hostId, visible) {
  2049. if ($axure.player.isCloud && plugins[hostId]) {
  2050. $axure.messageCenter.postMessage('pluginVisibleChanged', { id: hostId, gid: plugins[hostId].gid, visible: visible });
  2051. }
  2052. }
  2053. var interfaceControlHeaderButton_click = function (id) {
  2054. if (_player.isAnimating) { return; }
  2055. $axure.player.closePopup();
  2056. var controlContainerId = getControlContainerId(id);
  2057. var context = plugins[id].context;
  2058. var clickedPlugin = $('#' + controlContainerId + ' a[pluginId=' + id + ']');
  2059. if (currentVisibleHostId[context] == id) {
  2060. clickedPlugin.removeClass('selected');
  2061. if (id == "sitemapHost") { $('#sitemapControlFrameContainer').removeClass('selected'); }
  2062. currentVisibleHostId[context] = -1;
  2063. _player.collapseToBar(context, id);
  2064. $(document).trigger('pluginShown', [getVisiblePlugins()]);
  2065. } else {
  2066. $('#' + controlContainerId + ' a').removeClass('selected');
  2067. clickedPlugin.addClass('selected');
  2068. if (id == "sitemapHost") { $('#sitemapControlFrameContainer').addClass('selected'); }
  2069. $('#' + currentVisibleHostId[context]).hide();
  2070. $axure.player.pluginVisibleChanged(currentVisibleHostId[context], false);
  2071. currentVisibleHostId[context] = id;
  2072. _player.expandFromBar(id, context);
  2073. $(document).trigger('pluginShown', [getVisiblePlugins()]);
  2074. }
  2075. };
  2076. _player.pluginClose = function (id) {
  2077. var controlContainerId = getControlContainerId(id);
  2078. var context = plugins[id].context;
  2079. var clickedPlugin = $('#' + controlContainerId + ' a[pluginId=' + id + ']');
  2080. if (!clickedPlugin.hasClass('selected')) { return; }
  2081. clickedPlugin.removeClass('selected');
  2082. currentVisibleHostId[context] = -1;
  2083. _player.collapseToBar(context, id);
  2084. $(document).trigger('pluginShown', [getVisiblePlugins()]);
  2085. };
  2086. _player.showPlugin = function (gid) {
  2087. for (var id in plugins) {
  2088. if (plugins[id].gid == gid) {
  2089. interfaceControlHeaderButton_click(id);
  2090. break;
  2091. }
  2092. }
  2093. };
  2094. _player.restorePlugins = function () {
  2095. var selectedPluginsCount = 0;
  2096. for (var id in plugins) {
  2097. var clickedPlugin = $('#' + getControlContainerId(id) + ' a[pluginId=' + id + ']');
  2098. if (clickedPlugin.hasClass('selected')) selectedPluginsCount++;
  2099. }
  2100. if ($axure.player.settings.isAxshare && selectedPluginsCount != 0) $('#clippingBoundsScrollContainer').hide();
  2101. var selectedPluginsSeen = 0;
  2102. for (var id in plugins) {
  2103. var controlContainerId = getControlContainerId(id);
  2104. var context = plugins[id].context;
  2105. var clickedPlugin = $('#' + controlContainerId + ' a[pluginId=' + id + ']');
  2106. if (clickedPlugin.hasClass('selected')) {
  2107. //_player.showPlugin(id);
  2108. // TODO: handoffHost would need center inspect icon highlighted and rightFrameIcon set to visible
  2109. //if (id == 'handoffHost') { }
  2110. //$('#' + id).show();
  2111. selectedPluginsSeen++;
  2112. _player.expandFromBar(id, context, selectedPluginsCount == selectedPluginsSeen);
  2113. } else {
  2114. $('#' + id).hide();
  2115. }
  2116. }
  2117. $(document).trigger('pluginShown', [getVisiblePlugins()]);
  2118. };
  2119. }
  2120. $axure.player.hideAllPlayerControllers = function(isVisible) {
  2121. // TOOD: Verify that the containers are set to the right state after re-enabling them
  2122. if(isVisible) {
  2123. $('#topPanel').css('display', '');
  2124. $('#popupContainer').css('display', '');
  2125. $('#maximizePanelContainer').css('display', '');
  2126. $('#mobileControlFrameContainer').css('display', '');
  2127. } else {
  2128. $('#topPanel').hide();
  2129. $('#popupContainer').hide();
  2130. $('#maximizePanelContainer').hide(); // TODO: This needs to have a function where it prevents itself from showing up externally
  2131. $('#mobileControlFrameContainer').hide();
  2132. }
  2133. }
  2134. // TODO: General function to add bezels/overlays if applicable
  2135. $axure.player.addDeviceFraming = function (project, isEdit) {
  2136. // Temporary
  2137. var devices = {
  2138. iPhone8: 0,
  2139. iPhone8Plus: 1,
  2140. iPhoneSE: 2,
  2141. iPhoneX: 3,
  2142. iPad4: 4,
  2143. GalaxyS8: 5,
  2144. Pixel2: 6,
  2145. Pixel2XL: 7,
  2146. Mobile: 8,
  2147. Tablet9: 9,
  2148. Tablet7: 10,
  2149. Custom: 11,
  2150. Web: 12
  2151. };
  2152. // TODO: Need to bring over some platform functionality -> function might not be present
  2153. if (!$axure.player.settings.isExpo || project.Platform.Device === 12) { return; }
  2154. // TODO: Generate html for overlay and bezel containers
  2155. // TODO: Determine if preview player or full prototype player to establish where containers will be stored
  2156. var currDevice = project.Platform.Device;
  2157. var rootPath = '../../Scripts/Expo/StaticContent/resources/images/mobile/';
  2158. var framePath, overlayPath;
  2159. var $overlayParent = $(window.parent.parent.document).find('#previewPlayerDiv');
  2160. $overlayParent = isEdit && $overlayParent.length !== 0 ? $overlayParent : $('#mainPanelContainer');
  2161. $overlayParent.css('overflow', 'visible');
  2162. // TODO: Import enum of Device types -> import via TS definitions. WILL NEED TO REMEMBER THAT WE NEED TO SYNC SERVER AND CLIENT SIDE
  2163. // TODO: Create mapping of required images to device type
  2164. // images will be stored in ../../images/mobile
  2165. // TODO: Manage resizing
  2166. // TODO: Manage pointer clicks
  2167. // TODO: Status bar -> Default or via settings
  2168. // TODO: Establish img paths
  2169. switch (currDevice) {
  2170. case devices.iPhone8:
  2171. case devices.iPhone8Plus:
  2172. framePath = rootPath + 'iphone.svg';
  2173. overlayPath = "";
  2174. break;
  2175. case devices.iPhoneSE:
  2176. break;
  2177. case devices.iPhoneX:
  2178. framePath = "";
  2179. overlayPath = "";
  2180. break;
  2181. case devices.iPad4:
  2182. break;
  2183. case devices.Pixel2:
  2184. break;
  2185. case devices.Pixel2XL:
  2186. break;
  2187. case devices.GalaxyS8:
  2188. break;
  2189. case devices.Mobile:
  2190. case devices.Tablet7:
  2191. case devices.Tablet9:
  2192. case devices.Custom:
  2193. default:
  2194. break;
  2195. }
  2196. // TODO: Append images
  2197. // TODO: Position and initial dimensions
  2198. // TODO: Add resize handlers (?)
  2199. // TODO: Add pointer event handers (?)
  2200. if (framePath != undefined) {
  2201. $overlayParent.prepend(genFrameContainer());
  2202. var $fContainer = $overlayParent.find('#deviceFrameContainer');
  2203. var $frame = $fContainer.find('#deviceFrame');
  2204. $frame.css('background-image', "url('" + framePath + "')");
  2205. $frame.css('height', '');
  2206. $frame.css('width', '');
  2207. $frame.css('top', '');
  2208. $frame.css('left', '');
  2209. if(isEdit) {
  2210. $fContainer.css('z-index', -1);
  2211. }
  2212. }
  2213. if (overlayPath != undefined) {
  2214. // TODO: Update for edit mode
  2215. // $overlayParent.append(genOverlayContainer());
  2216. var $oContainer = $overlayParent.find('#deviceOverlayContainer');
  2217. var $overlay = $oContainer.find('#deviceOverlay');
  2218. $overlay.css('background-image', "url('" + overlayPath + "')");
  2219. }
  2220. }
  2221. function genFrameContainer(bezelPath) {
  2222. var container = [
  2223. '<div id="deviceFrameContainer">',
  2224. ' <div id="deviceFrame">',
  2225. ' </div>',
  2226. '</div>'
  2227. ].join("");
  2228. return container;
  2229. }
  2230. })();