axplayer.js 115 KB

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