axQuery.std.js.orig 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. // ******* AxQuery Plugins ******** //
  2. $axure.internal(function($ax) {
  3. var DYNAMIC_PANEL_TYPE = 'dynamicPanel';
  4. var TEXT_BOX_TYPE = 'textBox';
  5. var TEXT_AREA_TYPE = 'textArea';
  6. var LIST_BOX_TYPE = 'listBox';
  7. var COMBO_BOX_TYPE = 'comboBox';
  8. var CHECK_BOX_TYPE = 'checkbox';
  9. var RADIO_BUTTON_TYPE = 'radioButton';
  10. var BUTTON_TYPE = 'button';
  11. var IMAGE_MAP_REGION_TYPE = 'imageMapRegion';
  12. var IMAGE_BOX_TYPE = 'imageBox';
  13. var BUTTON_SHAPE_TYPE = 'buttonShape';
  14. var FLOW_SHAPE_TYPE = 'flowShape';
  15. var TREE_NODE_OBJECT_TYPE = 'treeNodeObject';
  16. var TABLE_CELL_TYPE = 'tableCell';
  17. var PLAIN_TEXT_TYPES = [TEXT_BOX_TYPE, TEXT_AREA_TYPE, LIST_BOX_TYPE, COMBO_BOX_TYPE, CHECK_BOX_TYPE, RADIO_BUTTON_TYPE, BUTTON_TYPE];
  18. var _addJQueryFunction = function(name) {
  19. $ax.public.fn[name] = function() {
  20. var val = $.fn[name].apply(this.jQuery(), arguments);
  21. return arguments[0] ? this : val;
  22. };
  23. };
  24. var _jQueryFunctionsToAdd = ['text', 'val', 'css'];
  25. for(var i = 0; i < _jQueryFunctionsToAdd.length; i++) _addJQueryFunction(_jQueryFunctionsToAdd[i]);
  26. // var _addJQueryEventFunction = function(name) {
  27. // $ax.public.fn[name] = function() {
  28. // $.fn[name].apply(this.jQuery(), arguments);
  29. // return this;
  30. // };
  31. // };
  32. // var _addJQueryEventFunction = function(name) {
  33. // $ax.public.fn[name] = (function(nn) {
  34. // return function() {
  35. // $.fn[nn].apply(this.jQuery(), arguments);
  36. // return this;
  37. // };
  38. // })(name);
  39. // };
  40. var _addJQueryEventFunction = function(name) {
  41. $ax.public.fn[name] = function() {
  42. //With Martin - No idea why this is necessary. We tried encapsulating the function thinking it was related to closure (above),
  43. //but that didn't fix the problem. If we don't add this Repeaters will give "Uncaught TypeError: Object #<Object> has no method 'apply'"
  44. //here (but Indeterminately, often on larger/slower Repeaters) because it is Undefined. However it seems the catch is never hit
  45. //if we surround the statement with the try/catch. Perhaps the try/catch block creates a scope or closure.
  46. try {
  47. $.fn[name].apply(this.jQuery(), arguments);
  48. } catch(e) {
  49. console.log("Couldn't find the event: " + name);
  50. }
  51. return this;
  52. };
  53. };
  54. var _jQueryEventFunctionsToAdd = ['click', 'mouseenter', 'mouseleave', 'bind'];
  55. for(var i = 0; i < _jQueryEventFunctionsToAdd.length; i++) _addJQueryEventFunction(_jQueryEventFunctionsToAdd[i]);
  56. $ax.public.fn.openLink = function(url, includeVariables) {
  57. this.jQuery().each(function() {
  58. if(!($(this).is('iframe'))) {
  59. return;
  60. }
  61. var objIframe = $(this).get(0);
  62. $ax.navigate({
  63. url: url,
  64. target: "frame",
  65. includeVariables: includeVariables,
  66. frame: objIframe
  67. });
  68. });
  69. return this;
  70. };
  71. $ax.public.fn.SetPanelState = function(stateNumber, options, showWhenSet) {
  72. var easingIn = 'none';
  73. var easingOut = 'none';
  74. var directionIn = '';
  75. var directionOut = '';
  76. var durationIn = 500;
  77. var durationOut = 500;
  78. if(options && options.animateIn) {
  79. easingIn = 'fade';
  80. directionIn = _getEasingDirection(options.animateIn);
  81. if(directionIn != '') easingIn = 'swing';
  82. if(options.animateIn.duration) {
  83. durationIn = options.animateIn.duration;
  84. }
  85. }
  86. if(options && options.animateOut) {
  87. easingOut = 'fade';
  88. directionOut = _getEasingDirection(options.animateOut);
  89. if(directionOut != '') easingOut = 'swing';
  90. if(options.animateOut.duration) {
  91. durationOut = options.animateOut.duration;
  92. }
  93. }
  94. var elementIds = this.getElementIds();
  95. for(var index = 0; index < elementIds.length; index++) {
  96. var elementId = elementIds[index];
  97. if($ax.getTypeFromElementId(elementId) == DYNAMIC_PANEL_TYPE) {
  98. var stateName = $ax.visibility.GetPanelStateId(elementId, Number(stateNumber) - 1);
  99. var wasVisible = $ax.visibility.IsIdVisible(elementId);
  100. // If compressing because you are fit to content and the change of state may change size, must be before the change.
  101. if(options.compress && $ax.dynamicPanelManager.isIdFitToContent(elementId) && wasVisible) {
  102. $ax.dynamicPanelManager.compressDelta(elementId, $ax.visibility.GetPanelState(elementId), stateName, options.vertical, options.compressEasing, options.compressDuration);
  103. }
  104. $ax.visibility.SetPanelState(elementId, stateName, easingOut, directionOut, durationOut, easingIn, directionIn, durationIn, showWhenSet);
  105. // If compressing because of a show, must be after state is set.
  106. if(options.compress && !wasVisible && showWhenSet) {
  107. $ax.dynamicPanelManager.compressToggle(elementId, options.vertical, true, options.compressEasing, options.compressDuration);
  108. }
  109. }
  110. }
  111. return this;
  112. };
  113. $ax.public.fn.show = function(options, eventInfo) {
  114. var elementIds = this.getElementIds();
  115. for(var index = 0; index < elementIds.length; index++) {
  116. var elementId = elementIds[index];
  117. var lightboxId = $ax.repeater.applySuffixToElementId(elementId, '_lightbox');
  118. var lightbox = $jobj(lightboxId);
  119. if(options && options.showType == 'lightbox') {
  120. $ax.flyoutManager.unregisterPanel(elementId, true);
  121. // Add lightbox if there isn't one
  122. if(lightbox.length == 0) {
  123. lightbox = $('<div></div>');
  124. lightbox.attr('id', lightboxId);
  125. var color = 'rgb(' + options.lightbox.r + ',' + options.lightbox.g + ',' + options.lightbox.b + ')';
  126. lightbox.css({
  127. position: 'fixed',
  128. left: '0px',
  129. top: '0px',
  130. width: '10000px',
  131. height: '10000px',
  132. 'background-color': color,
  133. opacity: options.lightbox.a / 255
  134. });
  135. var parents = $ax('#' + elementId).getParents(true)[0];
  136. var fixedParentPanelId = undefined;
  137. for(var j = 0; j < parents.length; j++) {
  138. var parentId = parents[j].split('_')[0];
  139. var parentObj = $obj(parentId);
  140. if(parentObj.type == 'dynamicPanel' && $jobj(parentId).css('z-index') != 'auto') {
  141. fixedParentPanelId = parentId;
  142. break;
  143. }
  144. }
  145. if(!fixedParentPanelId) $('#base').append(lightbox);
  146. else $jobj(fixedParentPanelId).append(lightbox);
  147. var wasVisible = $ax.visibility.IsIdVisible(elementId);
  148. (function(lightbox, query) {
  149. $ax.event.attachClick(lightbox, function() {
  150. $ax.action.addAnimation(elementId, function() {
  151. if(!wasVisible) query.hide();
  152. else $ax.action.fireAnimationFromQueue(elementId);
  153. lightbox.remove();
  154. });
  155. });
  156. })(lightbox, this);
  157. }
  158. $ax.legacy.BringToFront(lightboxId, true);
  159. $ax.legacy.BringToFront(elementId, true);
  160. } else if(options && options.showType == 'flyout') {
  161. // Remove lightbox if there is one
  162. lightbox.remove();
  163. var src = eventInfo.thiswidget;
  164. var target = $ax.getWidgetInfo(elementId);
  165. var rects = {};
  166. if(src.valid) rects.src = $ax.geometry.genRect(src);
  167. if(target.valid) rects.target = $ax.geometry.genRect(target);
  168. $ax.flyoutManager.registerFlyout(rects, elementId, eventInfo.srcElement);
  169. $ax.style.AddRolloverOverride(elementId);
  170. $ax.legacy.BringToFront(elementId);
  171. } else {
  172. // Remove lightbox, unregister flyout
  173. lightbox.remove();
  174. $ax.flyoutManager.unregisterPanel(elementId, true);
  175. _setVisibility(elementId, true, options);
  176. if(options && options.showType == 'front') $ax.legacy.BringToFront(elementId);
  177. continue;
  178. }
  179. _setVisibility(elementId, true, options);
  180. }
  181. return this;
  182. };
  183. var _getEasingDirection = function(options) {
  184. if(options && options.easing) {
  185. if(options.easing == 'slideLeft') {
  186. return 'left';
  187. } else if(options.easing == 'slideRight') {
  188. return 'right';
  189. } else if(options.easing == 'slideUp') {
  190. return 'up';
  191. } else if(options.easing == 'slideDown') {
  192. return 'down';
  193. }
  194. }
  195. return '';
  196. };
  197. $ax.public.fn.hide = function(options) {
  198. var elementIds = this.getElementIds();
  199. for(var index = 0; index < elementIds.length; index++) {
  200. var elementId = elementIds[index];
  201. var wasShown = $ax.visibility.IsIdVisible(elementId);
  202. _setVisibility(elementId, false, options);
  203. }
  204. return this;
  205. };
  206. $ax.public.fn.toggleVisibility = function(options) {
  207. var easing = options && options.easing || 'none';
  208. var duration = options && options.duration || 0;
  209. var direction = _getEasingDirection(options);
  210. if(direction != '') easing = 'swing';
  211. var elementIds = this.getElementIds();
  212. for(var index = 0; index < elementIds.length; index++) {
  213. var elementId = elementIds[index];
  214. var show = !$ax.visibility.IsIdVisible(elementId);
  215. _setVisibility(elementId, show, options);
  216. }
  217. return this;
  218. };
  219. var _setVisibility = function(elementId, value, options) {
  220. var easing = options && options.easing || 'none';
  221. var duration = options && options.duration || 0;
  222. var direction = _getEasingDirection(options);
  223. if(direction != '') easing = 'swing';
  224. var wasShown = $ax.visibility.IsIdVisible(elementId);
  225. var compress = options && options.showType == 'compress' && wasShown != value;
  226. var compressed = false;
  227. var onComplete = function() {
  228. if(compress && !compressed) $ax.dynamicPanelManager.compressToggle(elementId, options.vertical, value, options.compressEasing, options.compressDuration);
  229. compressed = true;
  230. $ax.dynamicPanelManager.fitParentPanel(elementId);
  231. };
  232. $ax.visibility.SetWidgetVisibility(elementId, {
  233. value: value,
  234. easing: easing,
  235. direction: direction,
  236. duration: duration,
  237. fire: true,
  238. onComplete: onComplete
  239. });
  240. if(compress && !compressed) $ax.dynamicPanelManager.compressToggle(elementId, options.vertical, value, options.compressEasing, options.compressDuration);
  241. compressed = true;
  242. };
  243. $ax.public.fn.moveTo = function(x, y, options) {
  244. var easing = 'none';
  245. var duration = 500;
  246. if(options && options.easing) {
  247. easing = options.easing;
  248. if(options.duration) {
  249. duration = options.duration;
  250. }
  251. }
  252. var elementIds = this.getElementIds();
  253. for(var index = 0; index < elementIds.length; index++) {
  254. var elementId = elementIds[index];
  255. $ax.move.MoveWidget(elementId, x, y, easing, duration, true, function() { $ax.dynamicPanelManager.fitParentPanel(elementId); }, true);
  256. }
  257. return this;
  258. };
  259. $ax.public.fn.moveBy = function(x, y, options) {
  260. var elementIds = this.getElementIds();
  261. if(x == 0 && y == 0) {
  262. for(var i = 0; i < elementIds.length; i++) {
  263. var id = this.getElementIds()[i];
  264. $ax.move.nopMove(id);
  265. $ax.event.raiseSyntheticEvent(id, "onMove");
  266. $ax.action.fireAnimationFromQueue(id);
  267. }
  268. return this;
  269. }
  270. var easing = 'none';
  271. var duration = 500;
  272. if(options && options.easing) {
  273. easing = options.easing;
  274. if(options.duration) {
  275. duration = options.duration;
  276. }
  277. }
  278. for(var index = 0; index < elementIds.length; index++) {
  279. var elementId = elementIds[index];
  280. $ax.move.MoveWidget(elementId, x, y, easing, duration, false, function() { $ax.dynamicPanelManager.fitParentPanel(elementId); }, true);
  281. }
  282. return this;
  283. };
  284. $ax.public.fn.bringToFront = function() {
  285. var elementIds = this.getElementIds();
  286. for(var index = 0; index < elementIds.length; index++) {
  287. $ax.legacy.BringToFront(elementIds[index]);
  288. }
  289. return this;
  290. };
  291. $ax.public.fn.sendToBack = function() {
  292. var elementIds = this.getElementIds();
  293. for(var index = 0; index < elementIds.length; index++) {
  294. $ax.legacy.SendToBack(elementIds[index]);
  295. }
  296. return this;
  297. };
  298. $ax.public.fn.text = function() {
  299. if(arguments[0] == undefined) {
  300. var firstId = this.getElementIds()[0];
  301. if(!firstId) {
  302. return undefined;
  303. }
  304. return getWidgetText(firstId);
  305. } else {
  306. var elementIds = this.getElementIds();
  307. for(var index = 0; index < elementIds.length; index++) {
  308. var currentItem = elementIds[index];
  309. var widgetType = $ax.getTypeFromElementId(currentItem);
  310. if(widgetType == TEXT_BOX_TYPE || widgetType == TEXT_AREA_TYPE) { //For non rtf
  311. SetWidgetFormText(currentItem, arguments[0]);
  312. } else {
  313. var idRtf = '#' + currentItem;
  314. if($(idRtf).length == 0) idRtf = '#u' + (Number(currentItem.substring(1)) + 1);
  315. if($(idRtf).length != 0) {
  316. //If the richtext div already has some text in it,
  317. //preserve only the first style and get rid of the rest
  318. //If no pre-existing p-span tags, don't do anything
  319. if($(idRtf).find('p').find('span').length > 0) {
  320. $(idRtf).find('p:not(:first)').remove();
  321. $(idRtf).find('p').find('span:not(:first)').remove();
  322. //Replace new-lines with NEWLINE token, then html encode the string,
  323. //finally replace NEWLINE token with linebreak
  324. var textWithLineBreaks = arguments[0].replace(/\n/g, '--NEWLINE--');
  325. var textHtml = $('<div/>').text(textWithLineBreaks).html();
  326. $(idRtf).find('span').html(textHtml.replace(/--NEWLINE--/g, '<br>'));
  327. }
  328. }
  329. }
  330. }
  331. return this;
  332. }
  333. };
  334. var getWidgetText = function(id) {
  335. var idQuery = $('#' + id);
  336. if(idQuery.is('input') && (idQuery.attr('type') == 'checkbox' || idQuery.attr('type') == 'radio')) {
  337. idQuery = idQuery.parent().find('label').find('div');
  338. }
  339. if(idQuery.is('div')) {
  340. var $rtfObj = idQuery.hasClass('text') ? idQuery : idQuery.find('.text');
  341. if($rtfObj.length == 0) return undefined;
  342. var textOut = '';
  343. $rtfObj.children('p').each(function(index) {
  344. if(index != 0) textOut += '\n';
  345. //Replace line breaks (set in SetWidgetRichText) with newlines and nbsp's with regular spaces.
  346. var htmlContent = $(this).html().replace(/<br[^>]*>/ig, '\n').replace(/&nbsp;/ig, ' ');
  347. textOut += $(htmlContent).text();
  348. });
  349. return textOut;
  350. } else {
  351. return idQuery.val();
  352. }
  353. };
  354. $ax.public.fn.setRichTextHtml = function() {
  355. if(arguments[0] == undefined) {
  356. //No getter function, so just return undefined
  357. return undefined;
  358. } else {
  359. var elementIds = this.getElementIds();
  360. for(var index = 0; index < elementIds.length; index++) {
  361. var currentItem = elementIds[index];
  362. var widgetType = $ax.getTypeFromElementId(currentItem);
  363. if(widgetType == TEXT_BOX_TYPE || widgetType == TEXT_AREA_TYPE) { //Do nothing for non rtf
  364. continue;
  365. } else {
  366. //TODO -- [mas] fix this!
  367. var idRtf = '#' + currentItem;
  368. if($(idRtf).length == 0) idRtf = '#u' + (parseInt(currentItem.substring(1)) + 1);
  369. if($(idRtf).length != 0) SetWidgetRichText(idRtf, arguments[0]);
  370. }
  371. }
  372. return this;
  373. }
  374. };
  375. $ax.public.fn.value = function() {
  376. if(arguments[0] == undefined) {
  377. var firstId = this.getElementIds()[0];
  378. if(!firstId) {
  379. return undefined;
  380. }
  381. var widgetType = $ax.getTypeFromElementId(firstId);
  382. if(widgetType == COMBO_BOX_TYPE || widgetType == LIST_BOX_TYPE) { //for select lists and drop lists
  383. return $('#' + firstId + ' :selected').text();
  384. } else if(widgetType == CHECK_BOX_TYPE || widgetType == RADIO_BUTTON_TYPE) { //for radio/checkboxes
  385. return $('#' + firstId + '_input').is(':checked');
  386. } else if(widgetType == TEXT_BOX_TYPE) { //for text box
  387. return $('#' + firstId + '_input').val();
  388. } else { //for text based form elements
  389. return this.jQuery().first().val();
  390. }
  391. } else {
  392. var elementIds = this.getElementIds();
  393. for(var index = 0; index < elementIds.length; index++) {
  394. var widgetType = $ax.getTypeFromElementId(elementIds[index]);
  395. var elementIdQuery = $('#' + elementIds[index]);
  396. if(widgetType == CHECK_BOX_TYPE || widgetType == RADIO_BUTTON_TYPE) { //for radio/checkboxes
  397. if(arguments[0] == true) {
  398. elementIdQuery.attr('checked', true);
  399. } else if(arguments[0] == false) {
  400. elementIdQuery.removeAttr('checked');
  401. }
  402. } else { //For select lists, drop lists, text based form elements
  403. elementIdQuery.val(arguments[0]);
  404. }
  405. }
  406. return this;
  407. }
  408. };
  409. $ax.public.fn.checked = function() {
  410. if(arguments[0] == undefined) {
  411. return this.selected();
  412. } else {
  413. this.selected(arguments[0]);
  414. return this;
  415. }
  416. };
  417. var _getRelativeLeft = function(node, parent) {
  418. var currentNode = node;
  419. var left = 0;
  420. while(currentNode != null && currentNode.tagName != "BODY") {
  421. left += currentNode.offsetLeft;
  422. currentNode = currentNode.offsetParent;
  423. if(currentNode == parent) break;
  424. }
  425. return left;
  426. };
  427. var _getRelativeTop = function(node, parent) {
  428. var currentNode = node;
  429. var top = 0;
  430. while(currentNode != null && currentNode.tagName != "BODY") {
  431. top += currentNode.offsetTop;
  432. currentNode = currentNode.offsetParent;
  433. if(currentNode == parent) break;
  434. }
  435. return top;
  436. };
  437. var _scrollHelper = function(id, scrollX, scrollY, easing, duration) {
  438. var target = window.document.getElementById(id);
  439. var scrollable = $ax.legacy.GetScrollable(target);
  440. var targetLeft = _getRelativeLeft(target, scrollable);
  441. var targetTop = _getRelativeTop(target, scrollable);
  442. if(!scrollX) targetLeft = scrollable.scrollLeft;
  443. if(!scrollY) targetTop = scrollable.scrollTop;
  444. var $scrollable = $(scrollable);
  445. if($scrollable.is('body')) {
  446. $scrollable = $('html,body');
  447. }
  448. if(easing == 'none') {
  449. if(scrollY) $scrollable.scrollTop(targetTop);
  450. if(scrollX) $scrollable.scrollLeft(targetLeft);
  451. } else {
  452. if(!scrollX) {
  453. $scrollable.animate({ scrollTop: targetTop }, duration, easing);
  454. } else if(!scrollY) {
  455. $scrollable.animate({ scrollLeft: targetLeft }, duration, easing);
  456. } else {
  457. $scrollable.animate({ scrollTop: targetTop, scrollLeft: targetLeft }, duration, easing);
  458. }
  459. }
  460. };
  461. $ax.public.fn.scroll = function(scrollOption) {
  462. var easing = 'none';
  463. var duration = 500;
  464. if(scrollOption && scrollOption.easing) {
  465. easing = scrollOption.easing;
  466. if(scrollOption.duration) {
  467. duration = scrollOption.duration;
  468. }
  469. }
  470. var scrollX = true;
  471. var scrollY = true;
  472. if(scrollOption.direction == 'vertical') {
  473. scrollX = false;
  474. } else if(scrollOption.direction == 'horizontal') {
  475. scrollY = false;
  476. }
  477. var elementIds = this.getElementIds();
  478. for(var index = 0; index < elementIds.length; index++) {
  479. // if($ax.getTypeFromElementId(elementIds[index]) == IMAGE_MAP_REGION_TYPE) {
  480. _scrollHelper(elementIds[index], scrollX, scrollY, easing, duration);
  481. // }
  482. }
  483. return this;
  484. };
  485. $ax.public.fn.enabled = function() {
  486. if(arguments[0] == undefined) {
  487. var firstId = this.getElementIds()[0];
  488. if(!firstId) return undefined;
  489. var widgetType = $ax.getTypeFromElementId(firstId);
  490. if(widgetType == IMAGE_BOX_TYPE || widgetType == BUTTON_SHAPE_TYPE || widgetType == FLOW_SHAPE_TYPE) return !$ax.style.IsWidgetDisabled(firstId);
  491. else return this.jQuery().first().not(':disabled').length > 0;
  492. } else {
  493. var elementIds = this.getElementIds();
  494. for(var index = 0; index < elementIds.length; index++) {
  495. var elementId = elementIds[index];
  496. var widgetType = $ax.getTypeFromElementId(elementId);
  497. var enabled = arguments[0];
  498. if(widgetType == IMAGE_BOX_TYPE || widgetType == BUTTON_SHAPE_TYPE || widgetType == FLOW_SHAPE_TYPE) $ax.style.SetWidgetEnabled(elementId, enabled);
  499. if(widgetType == DYNAMIC_PANEL_TYPE) {
  500. $ax.style.SetWidgetEnabled(elementId, enabled);
  501. var children = this.getChildren()[index].children;
  502. for(var i = 0; i < children.length; i++) {
  503. var childId = children[i];
  504. // Need to check this because of radio button and checkbox
  505. var end = '_container';
  506. if(childId.length > end.length && childId.substring(childId.length - end.length) == end) {
  507. childId = childId.substring(0, childId.length - end.length);
  508. }
  509. $axure('#' + childId).enabled(enabled);
  510. }
  511. }
  512. var obj = $obj(elementId);
  513. var images = obj.images;
  514. if(PLAIN_TEXT_TYPES.indexOf(widgetType) != -1 && images) {
  515. var img = $jobj($ax.repeater.applySuffixToElementId(elementId, '_image_sketch'));
  516. var key = (enabled ? 'normal~' : 'disabled~') + ($ax.adaptive.currentViewId || '');
  517. img.attr('src', images[key]);
  518. }
  519. var jobj = $jobj(elementId);
  520. var input = $jobj($ax.INPUT(elementId));
  521. if(input.length) jobj = input;
  522. if(enabled) jobj.removeAttr('disabled');
  523. else jobj.attr('disabled', 'disabled');
  524. }
  525. return this;
  526. }
  527. };
  528. $ax.public.fn.visible = function() {
  529. var ids = this.getElementIds();
  530. for(var index = 0; index < ids.length; index++) $ax.visibility.SetIdVisible(ids[index], arguments[0]);
  531. return this;
  532. };
  533. $ax.public.fn.selected = function() {
  534. if(arguments[0] == undefined) {
  535. var firstId = this.getElementIds()[0];
  536. if(!firstId) return undefined;
  537. var widgetType = $ax.getTypeFromElementId(firstId);
  538. if(widgetType == TREE_NODE_OBJECT_TYPE) {
  539. var treeNodeButtonShapeId = '';
  540. var allElementIds = $ax.getAllElementIds();
  541. for(var i = 0; i < allElementIds.length; i++) {
  542. var elementId = allElementIds[i];
  543. var currObj = $ax.getObjectFromElementId(elementId);
  544. if(currObj.type == BUTTON_SHAPE_TYPE && currObj.parent && currObj.parent.scriptIds && currObj.parent.scriptIds[0] == firstId) {
  545. treeNodeButtonShapeId = elementId;
  546. break;
  547. }
  548. }
  549. if(treeNodeButtonShapeId == '') return undefined;
  550. return $ax.style.IsWidgetSelected(treeNodeButtonShapeId);
  551. } else if(widgetType == IMAGE_BOX_TYPE || widgetType == BUTTON_SHAPE_TYPE || widgetType == FLOW_SHAPE_TYPE || widgetType == TABLE_CELL_TYPE | widgetType == DYNAMIC_PANEL_TYPE) {
  552. return $ax.style.IsWidgetSelected(firstId);
  553. } else if(widgetType == CHECK_BOX_TYPE || widgetType == RADIO_BUTTON_TYPE) {
  554. return $jobj($ax.INPUT(firstId)).prop('checked');
  555. }
  556. return this;
  557. }
  558. var elementIds = this.getElementIds();
  559. var func = typeof (arguments[0]) === 'function' ? arguments[0] : null;
  560. var enabled = arguments[0]; // If this is a function it will be overridden with the return value;
  561. for(var index = 0; index < elementIds.length; index++) {
  562. var elementId = elementIds[index];
  563. if(func) {
  564. enabled = func($axure('#' + elementId));
  565. }
  566. var widgetType = $ax.getTypeFromElementId(elementId);
  567. if(widgetType == TREE_NODE_OBJECT_TYPE) { //for tree node
  568. var treeRootId = $('#' + elementIds[index]).parents('.treeroot').attr('id');
  569. var treeNodeButtonShapeId = '';
  570. var childElementIds = $jobj(elementId).children();
  571. for(var i = 0; i < childElementIds.length; i++) {
  572. var elementId = childElementIds[i].id;
  573. var currObj = $ax.getObjectFromElementId(elementId);
  574. if(currObj && currObj.type == BUTTON_SHAPE_TYPE && currObj.parent &&
  575. currObj.parent.scriptIds && currObj.parent.scriptIds[0] == elementIds[index]) {
  576. treeNodeButtonShapeId = elementId;
  577. break;
  578. }
  579. }
  580. if(treeNodeButtonShapeId == '') continue;
  581. $ax.tree.SelectTreeNode(elementId, enabled);
  582. } else if(widgetType == IMAGE_BOX_TYPE || widgetType == BUTTON_SHAPE_TYPE || widgetType == FLOW_SHAPE_TYPE || widgetType == TABLE_CELL_TYPE || widgetType == DYNAMIC_PANEL_TYPE) {
  583. $ax.style.SetWidgetSelected(elementIds[index], enabled);
  584. } else if(widgetType == CHECK_BOX_TYPE || widgetType == RADIO_BUTTON_TYPE) {
  585. var query = $jobj($ax.INPUT(elementId));
  586. var curr = query.prop('checked');
  587. if(curr != enabled) {
  588. query.prop('checked', enabled);
  589. $ax.event.TryFireCheckChanged(elementId, enabled);
  590. }
  591. }
  592. }
  593. return this;
  594. };
  595. $ax.public.fn.focus = function() {
  596. var firstId = this.getElementIds()[0];
  597. var focusableId = $ax.event.getFocusableWidgetOrChildId(firstId);
  598. $('#' + focusableId).focus();
  599. return this;
  600. };
  601. $ax.public.fn.expanded = function() {
  602. if(arguments[0] == undefined) {
  603. var firstId = this.getElementIds()[0];
  604. return firstId && $ax.getTypeFromElementId(firstId) !== TREE_NODE_OBJECT_TYPE && $ax.visibility.IsIdVisible(firstId + '_children');
  605. } else {
  606. var elementIds = this.getElementIds();
  607. for(var index = 0; index < elementIds.length; index++) {
  608. if($ax.getTypeFromElementId(elementIds[index]) == TREE_NODE_OBJECT_TYPE) {
  609. var treeNodeId = elementIds[index];
  610. var childContainerId = treeNodeId + '_children';
  611. var scriptId = $ax.repeater.getScriptIdFromElementId(treeNodeId);
  612. var itemId = $ax.repeater.getItemIdFromElementId(treeNodeId);
  613. var plusMinusId = 'u' + (parseInt(scriptId.substring(1)) + 1);
  614. if(itemId) plusMinusId = $ax.repeater.createElementId(plusMinusId, itemId);
  615. if($('#' + childContainerId).length == 0 || !$jobj(plusMinusId).hasClass('ax_image'))
  616. plusMinusId = '';
  617. if(arguments[0] == true) {
  618. $ax.tree.ExpandNode(treeNodeId, childContainerId, plusMinusId);
  619. } else if(arguments[0] == false) {
  620. $ax.tree.CollapseNode(treeNodeId, childContainerId, plusMinusId);
  621. }
  622. }
  623. }
  624. return this;
  625. }
  626. };
  627. });