canvas.js 82 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010
  1. /* Contains all the Javascript logic of the canvas and its main features: save, export and share */
  2. $(document).ready(function() {
  3. /* ================================================
  4. Miscellaneous
  5. ================================================= */
  6. // Declare the currently loaded tags belonging to the user
  7. var tags;
  8. // Fixes bug when added item field zooms on tag click
  9. var tagWindowIsOpen = false;
  10. // This piece of code is for making the column-count and column-gap CSS to work in Firefox
  11. /*
  12. document.getElementById("7-5-col-layout").style.MozColumnCount = "7";
  13. document.getElementById("2-col-layout").style.MozColumnCount = "2";
  14. */
  15. // Prevent pressing ENTER on Project Title from submitting the form
  16. $('.proj_title').keydown(function(event){
  17. if(event.keyCode == 13) {
  18. event.preventDefault();
  19. return false;
  20. }
  21. });
  22. /* ================================================
  23. Rearrange fields numerically if 1 column is displayed
  24. ================================================= */
  25. // Declarations
  26. var groupOneLayout = $("#7-5-col-layout");
  27. var groupTwoLayout = $("#4-col-layout");
  28. var field01 = $("#panel_01");
  29. var field03 = $("#panel_03");
  30. var field04 = $("#panel_04");
  31. var field09 = $("#panel_09");
  32. var field05 = $("#panel_05");
  33. var field06 = $("#panel_06");
  34. var field02 = $("#panel_02");
  35. var field07 = $("#panel_07");
  36. var field08 = $("#panel_08");
  37. // var field10 = $("#panel_10");
  38. var isRearranged = false;
  39. // Rearrange the fields to suit mobile
  40. function rearrangeFields() {
  41. field01.detach();
  42. field03.detach();
  43. field04.detach();
  44. field09.detach();
  45. field05.detach();
  46. field06.detach();
  47. field02.detach();
  48. field07.detach();
  49. field08.detach();
  50. // field10.detach();
  51. groupOneLayout.append(field01);
  52. groupOneLayout.append(field02);
  53. groupOneLayout.append(field03);
  54. groupOneLayout.append(field04);
  55. groupOneLayout.append(field05);
  56. groupOneLayout.append(field06);
  57. groupOneLayout.append(field07);
  58. groupOneLayout.append(field08);
  59. groupOneLayout.append(field09);
  60. // groupOneLayout.append(field10);
  61. }
  62. // Rearrange the fields according to their original order
  63. function rearrangeFieldsOriginal() {
  64. field01.detach();
  65. field02.detach();
  66. field03.detach();
  67. field04.detach();
  68. field05.detach();
  69. field06.detach();
  70. field07.detach();
  71. field08.detach();
  72. field09.detach();
  73. // field10.detach();
  74. groupOneLayout.append(field01);
  75. groupOneLayout.append(field03);
  76. groupOneLayout.append(field04);
  77. groupOneLayout.append(field09);
  78. groupOneLayout.append(field05);
  79. groupOneLayout.append(field06);
  80. groupOneLayout.append(field02);
  81. groupTwoLayout.append(field07);
  82. groupTwoLayout.append(field08);
  83. // groupTwoLayout.append(field10);
  84. }
  85. // If the web page is opened on a mobile
  86. if ($(window).width() <= 499) {
  87. rearrangeFields();
  88. }
  89. // When resizing the window
  90. $(window).on("resize", function() {
  91. if (isRearranged === false && $(window).width() <= 499) {
  92. rearrangeFields();
  93. isRearranged = true;
  94. }
  95. else if(isRearranged === true && $(window).width() >= 500) {
  96. rearrangeFieldsOriginal();
  97. isRearranged = false;
  98. }
  99. });
  100. /* ================================================
  101. "Jump to" functions
  102. ================================================= */
  103. var hasScrolledDown = false;
  104. function showFixedJumpedTo() {
  105. // Add classes
  106. $("div.jump-to-click-area").addClass("jump-to-click-area-toggle");
  107. $("div.jump-to").addClass("jump-to-toggle");
  108. $("div.jump-to-list").addClass("jump-to-list-toggle");
  109. $("img.jump-to-img").addClass("jump-to-img-toggle");
  110. // If the user clicks on a link and scrolls up the page, hide list
  111. $("div.jump-to-list").hide();
  112. }
  113. function showInitialJumpedTo() {
  114. // Toggle classes
  115. $("div.jump-to-click-area").removeClass("jump-to-click-area-toggle");
  116. $("div.jump-to").removeClass("jump-to-toggle");
  117. $("div.jump-to-list").removeClass("jump-to-list-toggle");
  118. $("img.jump-to-img").removeClass("jump-to-img-toggle");
  119. // If the user clicks on a link and scrolls up the page, toggle list
  120. $("div.jump-to-list").show();
  121. hasScrolledDown = false;
  122. }
  123. // When the user scrolls down, change "position" to "fixed"
  124. $(window).scroll(function() {
  125. // If the web page is opened on a mobile
  126. if($(window).width() <= 499) {
  127. // Declarations
  128. var scrollPosition = $(window).scrollTop();
  129. var jumpToPosition = $("div.jump-to").offset().top;
  130. // If the user has scrolled down to "Jump To..."
  131. if(hasScrolledDown === false && scrollPosition >= jumpToPosition) {
  132. showFixedJumpedTo();
  133. // Update scroll position
  134. $(window).scrollTop($("div.saved-tags").offset().top - 360);
  135. hasScrolledDown = true;
  136. }
  137. // If the user has scrolled up to the top
  138. else if(hasScrolledDown === true && scrollPosition === 0) {
  139. showInitialJumpedTo();
  140. }
  141. }
  142. // If the web page is not open on a mobile
  143. else {
  144. showInitialJumpedTo();
  145. }
  146. });
  147. // If the user clicks on "Jump to", show menu
  148. $("div.jump-to-click-area").on("click", function() {
  149. // Toggle the menu
  150. $("div.jump-to div div").slideToggle(300);
  151. // Rotate arrow
  152. // $("div.jump-to span.jump-to-arrow").toggleClass("rotate-arrow-180");
  153. // $("div.jump-to span.jump-to-arrow").toggleClass("rotate-arrow-0");
  154. $("img.jump-to-img").toggleClass("jump-to-arrow-90");
  155. $("img.jump-to-img").toggleClass("jump-to-arrow-0");
  156. return false;
  157. });
  158. // If the user clicks on a menu item
  159. $("div.jump-to ul a").on("click", function() {
  160. // Declarations
  161. var chosenLiIndex = $(this).parent().index();
  162. var chosenFieldPosition;
  163. var scrollPositionNew;
  164. // Detect the scroll position of the chosen field
  165. // If the user has chosen the list item 0
  166. if(chosenLiIndex === 0) {
  167. chosenFieldPosition = $("div.saved-tags").offset().top;
  168. }
  169. // If the user has chosen the list item 1-9
  170. else if(chosenLiIndex >= 1 && chosenLiIndex <= 9) {
  171. chosenFieldPosition = $("div.field_0" + chosenLiIndex).offset().top;
  172. }
  173. // If the user has chosen the list item 10 or higher
  174. else {
  175. chosenFieldPosition = $("div.field_" + chosenLiIndex).offset().top;
  176. }
  177. // If the user hasn't scrolled down
  178. if(hasScrolledDown === false) {
  179. console.log(chosenLiIndex);
  180. // Set the new scroll position
  181. scrollPositionNew = chosenFieldPosition - $("div.jump-to").height() - 89;
  182. // Add classes
  183. showFixedJumpedTo();
  184. // Update scroll position
  185. hasScrolledDown = true;
  186. }
  187. // If the user has scrolled down to "Jump To..."
  188. else {
  189. // Set the new scroll position
  190. scrollPositionNew = chosenFieldPosition - 58;
  191. // Toggle the menu
  192. $("div.jump-to-list").slideToggle(300);
  193. // Rotate arrow
  194. // $("div.jump-to span.jump-to-arrow").toggleClass("rotate-arrow-90");
  195. // $("div.jump-to span.jump-to-arrow").toggleClass("rotate-arrow-0");
  196. $("img.jump-to-img").toggleClass("jump-to-arrow-90");
  197. $("img.jump-to-img").toggleClass("jump-to-arrow-0");
  198. }
  199. // Apply the new scroll position
  200. $(window).scrollTop(scrollPositionNew);
  201. return false;
  202. });
  203. /* ================================================
  204. Show tooltip for every category
  205. ================================================= */
  206. $("a[data-toggle='tooltip']").tooltip({container: "body"});
  207. $("a[data-toggle='tooltip']").on("click", function() {
  208. return false;
  209. });
  210. /* ================================================
  211. Remove all tags from all fields
  212. ================================================= */
  213. // Remove all tags from all fields
  214. function removeTags() {
  215. // AJAX
  216. $.ajax({
  217. type: "POST",
  218. url: "php/get-tags.php",
  219. dataType: "JSON",
  220. data: {
  221. "username": username
  222. },
  223. timeout: 5000,
  224. success: function(returnData) {
  225. // Declarations
  226. var loopCounter = 0;
  227. tags = returnData;
  228. // For every added item
  229. $("li.added_item .expandable").each(function() {
  230. var thisDiv = $(this); // Delete the declaration (because it's ugly!)
  231. // For every tag in the database that belongs to the active user
  232. for(t in tags) {
  233. // If the current tag exists in the textarea
  234. if(thisDiv.html().indexOf("</a>") != -1) { // Why not a while loop?
  235. // Delete the tag
  236. var text = thisDiv.html();
  237. text = thisDiv.text().replace("<a class='tag'>" + tags[loopCounter] + "</a>", tags[loopCounter]);
  238. thisDiv.html(text);
  239. }
  240. loopCounter++;
  241. }
  242. });
  243. if(tags.length === 0) {
  244. $("div.saved-tags p").html("You haven't added any tags yet.");
  245. }
  246. },
  247. error: function(xhr) {
  248. console.log(xhr.statusText);
  249. }
  250. });
  251. /*
  252. // The code below is much better than the code above, because no database connection is being called, but the "You haven't added any tags yet" text is not being reset
  253. // Declarations
  254. var loopCounter = 0;
  255. // For every added item
  256. $("li.added_item .expandable").each(function() {
  257. var thisDiv = $(this); // Delete the declaration (because it's ugly)
  258. // For every tag that belongs to the active user
  259. for(t in tags) {
  260. // If the current tag exists in the textarea
  261. if(thisDiv.html().indexOf("</a>") != -1) {
  262. // Delete the tag
  263. var text = thisDiv.html();
  264. text = thisDiv.text().replace("<a class='tag'>" + tags[loopCounter] + "</a>", tags[loopCounter]);
  265. thisDiv.html(text);
  266. }
  267. loopCounter++;
  268. }
  269. });
  270. console.log(tags);
  271. console.log(tags.length);
  272. if(tags.length === 0) {
  273. $("div.saved-tags p").html("You haven't added any tags yet.");
  274. }
  275. */
  276. }
  277. /* ================================================
  278. Get the user's tags from the database and apply them on the canvas
  279. ================================================= */
  280. // Apply tags (Incoming parameter is an array with every tag from the database belonging to the active user)
  281. function updateTags() {
  282. // Apply tags on the canvas
  283. /*
  284. IMPORTANT! A timer was needed in order to solve several bugs related to tags not being applied on the canvas.
  285. Should this still become an issue later on, try increasing the amount of milliseconds.
  286. */
  287. window.setTimeout(function() {
  288. // For every added item
  289. $("li.added_item .expandable").each(function() {
  290. // Declarations
  291. // var instanceCounter;
  292. var loopCounter = 0;
  293. var text = $(this).text();
  294. // instanceCounter = $(text + ":contains('test')").length;
  295. // $('#parentDiv').find(":contains('No Records Found')").length
  296. // console.log(instanceCounter);
  297. // For every tag in the database that belongs to the active user
  298. for(t in tags) {
  299. // instanceCounter = ($(this).text().match(/aaa/g) || []).length;
  300. // Apply the tag for every instance of the current term
  301. // instanceCounter = text.indexOf(tags[loopCounter]);
  302. // while(instanceCounter > -1) {
  303. // text = text.replace(tags[loopCounter], "<a class='tag' contenteditable='false'>" + tags[loopCounter] + "</a>");
  304. text = text.replace(tags[loopCounter], "<a class='tag'>" + tags[loopCounter] + "</a>");
  305. // instanceCounter = text.indexOf(tags[loopCounter], instanceCounter + 1);
  306. // }
  307. loopCounter++;
  308. }
  309. $(this).html(text);
  310. });
  311. // Show the tag window on tag click
  312. showTagWindowOnTagClick();
  313. }, 100);
  314. // Populate "Saved Tags"
  315. var loopCounter = 0;
  316. var savedTags = $("div.saved-tags p");
  317. savedTags.html("");
  318. for(t in tags) {
  319. if(savedTags.html() === "You haven't added any tags yet.") {
  320. savedTags.html("");
  321. }
  322. savedTags.append("<a href='#' class='tag'>" + tags[loopCounter] + "</a>").append("&nbsp;&nbsp; ");
  323. loopCounter++;
  324. }
  325. }
  326. // Get the tags from the database
  327. function getTags() {
  328. // Declarations
  329. var username = $("input[name='username']").val();
  330. // AJAX
  331. $.ajax({
  332. type: "POST",
  333. url: "php/get-tags.php",
  334. dataType: "JSON",
  335. data: {
  336. "username": username
  337. },
  338. timeout: 5000,
  339. success: function(returnData) {
  340. if(returnData.length > 0) {
  341. // Assign returnData to the tags variable
  342. tags = returnData;
  343. // Update tags on the canvas
  344. updateTags();
  345. }
  346. },
  347. error: function(xhr) {
  348. console.log(xhr.statusText);
  349. }
  350. });
  351. }
  352. /* ================================================
  353. Load tags if the user is logged in
  354. ================================================= */
  355. if($("input[name='name']").val() != "") {
  356. getTags();
  357. }
  358. /* ================================================
  359. Tag window functions
  360. ================================================= */
  361. // Declarations
  362. // var textarea = $("div#tag-window textarea#tag-description");
  363. var textareaHasBeenChanged = false;
  364. var tag;
  365. var tagIsNew = false;
  366. var username = $("input[name='username']").val();
  367. // Check if the tag is new
  368. function checkIfTagIsNew() {
  369. // Declarations
  370. var tagToAJAX = tag;
  371. // AJAX
  372. $.ajax({
  373. type: "POST",
  374. url: "php/check-if-tag-exists.php",
  375. dataType: "text",
  376. data: {
  377. "tag": tagToAJAX,
  378. "username": username
  379. },
  380. timeout: 5000,
  381. success: function(returnData) {
  382. // If the current tag does not exist in the database
  383. if(returnData === "") {
  384. // Hide "Delete tag" button
  385. $("div#tag-window button#delete-tag").css("display", "none");
  386. // Hide "Similar tags"
  387. $("div#tag-window h2.similar-tags").css("display", "none");
  388. // The tag is new
  389. tagIsNew = true;
  390. }
  391. // If the current tag exists in the database
  392. else {
  393. // Show "Delete tag" button
  394. $("div#tag-window button#delete-tag").css("display", "inline");
  395. // Show "Similar tags"
  396. $("div#tag-window h2.similar-tags").css("display", "block");
  397. }
  398. },
  399. error: function(xhr) {
  400. console.log(xhr.statusText);
  401. }
  402. });
  403. }
  404. // Updating the remaining characters information
  405. function updateRemainingCharacters() {
  406. // Declarations
  407. var length = $("div#tag-window textarea#tag-description").val().length; // Retrieving from "Please enter a description..."
  408. var maxLength = 200;
  409. /*
  410. var length;
  411. if(description != "") {
  412. length = description;
  413. }
  414. else {
  415. length = $("div#tag-window textarea#tag-description").val().length;
  416. }
  417. */
  418. // Update length
  419. length = maxLength - length;
  420. // Show the remaining characters
  421. $("div#tag-window span.chars").text(length);
  422. }
  423. // Get the description for the selected tag
  424. function getDescriptionForSelectedTag() {
  425. // Declarations
  426. var tagToAJAX = tag;
  427. // AJAX
  428. $.ajax({
  429. type: "POST",
  430. url: "php/get-description-for-selected-tag.php",
  431. dataType: "text",
  432. data: {
  433. "tag": tagToAJAX,
  434. "username": username
  435. },
  436. timeout: 5000,
  437. success: function(returnData) {
  438. if(returnData != "") {
  439. // Update description field with the description for the selected tag
  440. $("div#tag-window textarea#tag-description").val(returnData);
  441. // Update remaining characters
  442. updateRemainingCharacters();
  443. }
  444. textareaHasBeenChanged = true;
  445. },
  446. error: function(xhr) {
  447. console.log(xhr.statusText);
  448. }
  449. });
  450. }
  451. // Get similar tags by other users
  452. function getSimilarTags() {
  453. // Declarations
  454. var tagToAJAX = tag;
  455. // AJAX
  456. $.ajax({
  457. type: "POST",
  458. url: "php/get-similar-tags.php",
  459. dataType: "JSON",
  460. data: {
  461. "tag": tagToAJAX,
  462. "username": username
  463. },
  464. timeout: 5000,
  465. success: function(returnData) {
  466. // Reset similar tags if similar tags are to be showed again
  467. $("p.similar-tags-tag").remove();
  468. $("p.similar-tags-description").remove();
  469. $("p.similar-tags-username").remove();
  470. // Declarations
  471. var htmlToAppend = "";
  472. // If similar tags exist
  473. if(returnData.length > 0) {
  474. // Declarations
  475. var index = 0;
  476. // While there still are tags to append
  477. while(index < returnData.length) {
  478. htmlToAppend += "<p class='similar-tags-tag'><a class='tag'>" + returnData[index]["tag"] + "</a></p>"
  479. + "<p class='similar-tags-description'>" + returnData[index]["description"] + "</p>"
  480. + "<p class='similar-tags-username'>by <a href='#'>" + returnData[index]["username"] + "</a></p>";
  481. index++;
  482. }
  483. // Append tags
  484. $("div#tag-window h2.similar-tags").after(htmlToAppend);
  485. $("p.similar-tags-description-none").css("display", "none");
  486. // Update tags on the canvas
  487. // updateTags();
  488. }
  489. else {
  490. // If the tag isn't a new tag
  491. if(tagIsNew === false) {
  492. // Show the message saying that there are no similar tags to show
  493. $("p.similar-tags-description-none").css("display", "block");
  494. }
  495. }
  496. },
  497. error: function(xhr) {
  498. console.log(xhr.statusText);
  499. }
  500. });
  501. }
  502. // Close the tag window
  503. function closeTagWindow() {
  504. tagWindowIsOpen = false;
  505. $("div#shadow").css("display", "none");
  506. $("div#tag-window").css("display", "none");
  507. }
  508. // Show the tag window
  509. function showTagWindow() {
  510. // Show the tag window
  511. $("div#shadow").css("display", "block");
  512. $("div#tag-window").css("display", "block");
  513. // Move the window to the centre of the screen
  514. /*
  515. The code below should be working, but the height of the second selector seems completely wrong!
  516. var middle = (document.body.clientHeight / 2) - ($("div#tag-window").height() / 2);
  517. $("div#tag-window").css("top", middle);
  518. */
  519. // Check if the tag is new
  520. checkIfTagIsNew();
  521. // Get the description for the selected tag
  522. getDescriptionForSelectedTag();
  523. // Get tags by other users from the database
  524. // window.setTimeout(getSimilarTags(), 100);
  525. getSimilarTags();
  526. // Update remaining characters in case description is loaded
  527. updateRemainingCharacters();
  528. // If a description hasn't been entered
  529. if($("div#tag-window textarea#tag-description") !== "Please enter a description..." && textareaHasBeenChanged !== true) {
  530. // Reset the remaining characters information
  531. $("div#tag-window span.chars").text("200");
  532. }
  533. }
  534. // If the user presses a key in the description textarea
  535. $("div#tag-window textarea#tag-description").on("keyup", function() {
  536. // Update remaining characters
  537. updateRemainingCharacters();
  538. });
  539. // If the user clicks on the "Save tag" button
  540. $("div#tag-window #save-tag").on("click", function() {
  541. // Declarations
  542. var description = $("div#tag-window textarea#tag-description").val();
  543. var tagToAJAX = tag;
  544. // If a description has been entered
  545. if(description != "" && description != "Please enter a description...") {
  546. // AJAX
  547. $.ajax({
  548. timeout: 5000,
  549. dataType: "text",
  550. type: "post",
  551. data: {
  552. "tag": tagToAJAX,
  553. "description": description,
  554. "username": username
  555. },
  556. url: "php/save-tag.php",
  557. success: function() {
  558. textareaHasBeenChanged = true;
  559. // Get the user's tags from the database and apply them on the canvas
  560. getTags();
  561. },
  562. error: function(xhr) {
  563. console.log(xhr.statusText);
  564. }
  565. });
  566. // Close the tag window
  567. closeTagWindow();
  568. }
  569. tagIsNew = false;
  570. });
  571. // If the user clicks on the "Close" button
  572. $("div#tag-window button.close").on("click", function() {
  573. // Close the tag window
  574. closeTagWindow();
  575. });
  576. // If the user clicks on the "Delete tag" button
  577. $("div#tag-window #delete-tag").on("click", function() {
  578. // Declarations
  579. var tagToAJAX = tag;
  580. // AJAX
  581. $.ajax({
  582. timeout: 5000,
  583. dataType: "text",
  584. type: "post",
  585. data: {
  586. "tag": tagToAJAX,
  587. "username": username
  588. },
  589. url: "php/delete-tag.php",
  590. success: function() {
  591. // Remove all tags from all fields
  592. removeTags();
  593. // Get the user's tags from the database and apply them on the canvas
  594. getTags();
  595. },
  596. error: function(xhr) {
  597. console.log(xhr.statusText);
  598. }
  599. });
  600. // Close the tag window
  601. closeTagWindow();
  602. });
  603. // If the user focuses in the textarea
  604. $("div#tag-window textarea#tag-description").on("focusin", function() {
  605. // Declarations
  606. var description = $("div#tag-window textarea#tag-description").val();
  607. // If a description hasn't been entered
  608. // if(textareaHasBeenChanged === false) {
  609. if(description === "Please enter a description...") {
  610. // Empty the description textarea
  611. $("div#tag-window textarea#tag-description").val("");
  612. }
  613. });
  614. // If the user focuses out the textarea
  615. $("div#tag-window textarea#tag-description").on("focusout", function() {
  616. // Declarations
  617. var description = $("div#tag-window textarea#tag-description").val();
  618. // If a description hasn't been entered
  619. // if(textareaHasBeenChanged === false) {
  620. if(description === "") {
  621. // Reset the description textarea
  622. $("div#tag-window textarea#tag-description").val("Please enter a description...");
  623. }
  624. });
  625. /* ================================================
  626. If the user clicks on a tag, show the tag window
  627. ================================================= */
  628. // If the user clicks on a tag
  629. function showTagWindowOnTagClick() {
  630. $("a.tag").on("click", function() {
  631. // Declarations
  632. tag = $(this).text();
  633. // If the user is logged in
  634. if($("input[name='username']").val() != "") {
  635. tagWindowIsOpen = true;
  636. // Show the tag window
  637. showTagWindow();
  638. }
  639. else {
  640. // Show a dialog
  641. $("div#shadow").css("display", "block");
  642. $("div#dialog-log-in").css("display", "block");
  643. }
  644. });
  645. }
  646. /*
  647. // Mouse-enabled devices
  648. $("tag").mouseenter(function() {
  649. timer = setTimeout(function() {
  650. showTagWindow(); // showTagWindow needs a parameter!
  651. }, 400);
  652. }).mouseleave(function() {
  653. clearTimeout(timer);
  654. });
  655. // Touch devices
  656. try {
  657. document.createEvent("TouchEvent");
  658. $("a.tag").on("click", showTagWindow()); // showTagWindow needs a parameter!
  659. return true;
  660. }
  661. catch(e) {
  662. return false;
  663. }
  664. */
  665. /* ================================================
  666. Save added idea on Enter press
  667. ================================================= */
  668. function saveAddedIdeaOnEnterPress(li) {
  669. $("li.added_item textarea.expandable").on("keydown", function(event) {
  670. if(event.which === 13) {
  671. event.preventDefault();
  672. // Declarations
  673. var li = $(this).parent();
  674. var textElement;
  675. var textElementWidth;
  676. // Replace textarea with a div
  677. $(this).replaceWith(
  678. "<div class='expandable' name='" + $(this).attr("name") + "'>" + $(this).val() + "</div>"
  679. );
  680. // Remember the text element
  681. textElement = li.find(".expandable");
  682. // Remember the width of the text element
  683. textElementWidth = textElement.width();
  684. // Update tags on the canvas
  685. // window.setTimeout(updateTags(), 100);
  686. updateTags();
  687. // Zoom out animation
  688. if(textElementWidth >= 0 && textElementWidth <= 250) {
  689. textElement.addClass("zoom-out-regular");
  690. }
  691. else if(textElementWidth >= 251 && textElementWidth <= 500) {
  692. textElement.addClass("zoom-out-less");
  693. }
  694. else if(textElementWidth >= 501) {
  695. textElement.addClass("zoom-out-least");
  696. }
  697. textElement.css("background-color", "rgba(255, 255, 255, 0.75)");
  698. textElement.css("-ms-transform", "scale(1)");
  699. textElement.css("-webkit-transform", "scale(1)");
  700. textElement.css("transform", "scale(1)");
  701. toggleTextElementOnFocus();
  702. }
  703. });
  704. }
  705. /* ================================================
  706. Toggle textarea.expandable/div.expandable on edit
  707. ================================================= */
  708. function toggleTextElementOnFocus() {
  709. // If the user clicks on the added idea
  710. $("li.added_item .expandable").on("click", function() {
  711. if(tagWindowIsOpen === false) {
  712. var li = $(this).parent();
  713. var textElement;
  714. var textElementHTML;
  715. var textElementWidth;
  716. // Replace div with a textarea
  717. $(this).replaceWith(
  718. "<textarea maxlength='100' class='expandable' rows='3' data-limit-rows='true' data-autoresize name='" + $(this).attr("name") + "'>" + $(this).text() + "</textarea>"
  719. );
  720. // Remember the text element
  721. textElement = li.find(".expandable");
  722. // Fix the bug that tags still might appear
  723. textElementHTML = textElement.html();
  724. while(textElementHTML.indexOf("<a class='tag'>") != -1) {
  725. textElementHTML = textElementHTML.replace("<a class='tag'>", "");
  726. textElementHTML = textElementHTML.replace("</a>", "");
  727. }
  728. textElement.html(textElementHTML);
  729. // Remember the width of the text element
  730. textElementWidth = textElement.width();
  731. // Focus immediately on click instead of having to click on the element a second time
  732. textElement.focus();
  733. // Zoom in animation
  734. if(textElementWidth >= 0 && textElementWidth <= 250) {
  735. textElement.addClass("zoom-in-regular");
  736. textElement.css("background-color", "rgba(255, 255, 255, 1)");
  737. textElement.css("-ms-transform", "scale(1.02)");
  738. textElement.css("-webkit-transform", "scale(1.02)");
  739. textElement.css("transform", "scale(1.02)");
  740. }
  741. else if(textElementWidth >= 251 && textElementWidth <= 600) {
  742. textElement.addClass("zoom-in-less");
  743. textElement.css("background-color", "rgba(255, 255, 255, 1)");
  744. textElement.css("-ms-transform", "scale(1.01)");
  745. textElement.css("-webkit-transform", "scale(1.01)");
  746. textElement.css("transform", "scale(1.01)");
  747. }
  748. else if(textElementWidth >= 601) {
  749. textElement.addClass("zoom-in-least");
  750. textElement.css("background-color", "rgba(255, 255, 255, 1)");
  751. textElement.css("-ms-transform", "scale(1.005)");
  752. textElement.css("-webkit-transform", "scale(1.005)");
  753. textElement.css("transform", "scale(1.005)");
  754. }
  755. // Save added idea on Enter press
  756. saveAddedIdeaOnEnterPress(li);
  757. // Replace textarea with a div
  758. $("li.added_item textarea.expandable").on("focusout", function() {
  759. // Declarations
  760. var li = $(this).parent();
  761. var textElement;
  762. var textElementWidth;
  763. // Replace textarea with a div
  764. $(this).replaceWith(
  765. "<div class='expandable' name='" + $(this).attr("name") + "'>" + $(this).val() + "</div>"
  766. );
  767. // Remember the text element
  768. textElement = li.find(".expandable");
  769. // Remember the width of the text element
  770. textElementWidth = textElement.width();
  771. // Update tags on the canvas
  772. // window.setTimeout(updateTags(), 100);
  773. updateTags();
  774. // Zoom out animation
  775. if(textElementWidth >= 0 && textElementWidth <= 250) {
  776. textElement.addClass("zoom-out-regular");
  777. }
  778. else if(textElementWidth >= 251 && textElementWidth <= 500) {
  779. textElement.addClass("zoom-out-less");
  780. }
  781. else if(textElementWidth >= 501) {
  782. textElement.addClass("zoom-out-least");
  783. }
  784. textElement.css("background-color", "rgba(255, 255, 255, 0.75)");
  785. textElement.css("-ms-transform", "scale(1)");
  786. textElement.css("-webkit-transform", "scale(1)");
  787. textElement.css("transform", "scale(1)");
  788. toggleTextElementOnFocus();
  789. });
  790. }
  791. });
  792. }
  793. /*
  794. // ================================================
  795. If the user types a new character in the added idea field, add tag if a term could be found
  796. ================================================= //
  797. // 8an33j24
  798. function applyTagOnTypeMatch() {
  799. $("li.added_item .expandable").on("focusin", function() {
  800. // If the user presses a key in the description textarea
  801. $("li.added_item .expandable").on("keyup", function() {
  802. if(event.which !== 9 && // Tab
  803. event.which !== 16 && // Shift
  804. event.which !== 37 && // Left
  805. event.which !== 38 && // Up
  806. event.which !== 39 && // Right
  807. event.which !== 40) { // Down
  808. // Declarations
  809. var bugCounter = 0;
  810. var loopCounter = 0;
  811. var tagLinkToSearch;
  812. var tagLinkHits;
  813. var tagTextToSearch;
  814. var tagTextHits;
  815. var text = $(this).html();
  816. // Fix the bug that triggers the event twice
  817. if(!bugCounter > 0) {
  818. // console.log("tagTextHits: " + tagTextHits);
  819. // console.log("tagLinkHits: " + tagLinkHits);
  820. // For every tag that belongs to the active user
  821. for(t in tags) {
  822. if($(this).html().indexOf(tags[loopCounter]) != -1) {
  823. // Search for the tag inside the added idea as a link
  824. tagLinkToSearch = text.match(tags[loopCounter] + "</a>"); // match() can only count to one instance (67hi9nt3)
  825. // Search for the tag inside the added idea as plain text
  826. tagTextToSearch = text.match(tags[loopCounter]); // match() can only count to one instance (67hi9nt3)
  827. // If the tag exists inside the added idea as a link
  828. if(tagLinkToSearch !== null) {
  829. // tagLinkHits = 1
  830. tagLinkHits = tagLinkToSearch.length;
  831. }
  832. else {
  833. // tagLinkHits = 0
  834. tagLinkHits = 0;
  835. }
  836. // If the tag exists inside the added idea as plain text
  837. if(tagTextToSearch !== null) {
  838. // tagTextHits = 1
  839. tagTextHits = tagTextToSearch.length;
  840. }
  841. else {
  842. // tagTextHits = 0
  843. tagTextHits = 0;
  844. }
  845. // If there are more instances of the tag as plain text than the tag as links, and there is a maximum of 1 instances of the tag as plain text
  846. // Change "tagTextHits <= 1" to "tagLinkHits === 0"
  847. if(tagTextHits > tagLinkHits && tagLinkHits === 0) {
  848. // Apply the tag
  849. text = text.replace(tags[loopCounter], "<a class='tag' contenteditable='false'>" + tags[loopCounter] + "</a>");
  850. $(this).html(text);
  851. // Restore caret position // u78krf3t
  852. }
  853. }
  854. loopCounter++;
  855. }
  856. }
  857. bugCounter++;
  858. }
  859. });
  860. });
  861. };
  862. */
  863. /* ----------------------------------------------
  864. Limiting the number of characters the user is allowed to type
  865. ----------------------------------------------- */
  866. var maxLength = 100;
  867. $('.card').on('keyup', '.new_item', function() {
  868. var length = $(this).val().length;
  869. length = maxLength - length;
  870. // show the characters remaining only on this field
  871. $(this).closest('.user-input').find('.chars').text(length);
  872. });
  873. function limitLengthOnInput() {
  874. // Limit text on key press
  875. $("li.added_item .expandable").on("keypress", function(event) {
  876. // Declarations
  877. var numberOfTags = $(this).children().filter("a").length;
  878. var textLength = $(this).html().length;
  879. // Subtract 43 from textLength per tag (the tag HTML is 43 characters)
  880. $(this).each(function() {
  881. textLength -= 43 * numberOfTags;
  882. });
  883. if(textLength === 100) { // Windows menu/Right cmd
  884. event.preventDefault();
  885. }
  886. });
  887. // 28jek79t
  888. // Limit text on paste
  889. /*
  890. var pastedTextOriginal;
  891. $("li.added_item .expandable").on("paste", function(event) {
  892. pastedTextOriginal = event.originalEvent.clipboardData.getData("Text");
  893. if($(this).html().length + pastedTextOriginal > 100) {
  894. console.log("Too long!");
  895. event.preventDefault();
  896. // var caretPosition = the text position
  897. // Insert the text after caretPosition
  898. }
  899. // return false;
  900. });
  901. */
  902. }
  903. /* ================================================
  904. If the user closes a dialog
  905. ================================================= */
  906. $("div.dialog button").on("click", function() {
  907. $("div#shadow").css("display", "none");
  908. $("div.dialog").css("display", "none");
  909. });
  910. /* ================================================
  911. If the user clicks on the "Tag selected term" link
  912. ================================================= */
  913. // Declaration
  914. var selection = "";
  915. // var newRange = "";
  916. // Initiate tag
  917. tag = "";
  918. // Update the tag variable
  919. document.onselectionchange = function() {
  920. // if($("textarea").is(":focus")) {
  921. if($("li.added_item .expandable").is(":focus")) {
  922. selection = window.getSelection().toString();
  923. tag = selection.trim();
  924. }
  925. }
  926. // If the user clicks on the "Tag selected term" link
  927. $("p.tag-selected-term a").on("click", function() {
  928. // If the tag isn't empty
  929. if(tag != "") {
  930. // Show the tag window
  931. showTagWindow();
  932. }
  933. else {
  934. // Show a dialog
  935. $("div#shadow").css("display", "block");
  936. $("div#dialog-select-term").css("display", "block");
  937. }
  938. // Prevent the current view to jump to the top of the screen
  939. return false;
  940. });
  941. // If the user moves the focus from the added idea, reset variables
  942. $("li.added_item .expandable").on("focusout", function() {
  943. selection = "";
  944. tag = "";
  945. });
  946. /* ================================================
  947. Serialize Form to JSON
  948. ================================================= */
  949. $.fn.serializeObject = function() {
  950. var o = {};
  951. var a = this.serializeArray();
  952. $.each(a, function() {
  953. if (o[this.name]) {
  954. if (!o[this.name].push) {
  955. o[this.name] = [o[this.name]];
  956. }
  957. o[this.name].push(this.value || '');
  958. } else {
  959. o[this.name] = this.value || '';
  960. }
  961. });
  962. return o;
  963. };
  964. /* ================================================
  965. Getting the current date
  966. ================================================= */
  967. var fullDate = new Date();
  968. var twoDigitMonth = fullDate.getMonth() + "";
  969. if (twoDigitMonth.length == 1) twoDigitMonth = "0" + twoDigitMonth;
  970. var twoDigitDate = fullDate.getDate() + "";
  971. if (twoDigitDate.length == 1) twoDigitDate = "0" + twoDigitDate;
  972. var currentDate = fullDate.getFullYear() + "-" + twoDigitMonth + "-" + twoDigitDate;
  973. // set the currebt date in the date input field
  974. $('.proj_date').val(currentDate);
  975. /* ================================================
  976. USER LOGS OUT (dropdown menu)
  977. ================================================= */
  978. $('.user-profile').on('click', '#logout', function() {
  979. var url = 'php/logout.php';
  980. $.post(url, function(data, status) {
  981. if (data == 200) {
  982. $('.user-profile').hide();
  983. window.location.href="https://www.ethicscanvas.org";
  984. }
  985. });
  986. });
  987. /* ================================================
  988. When the page loads, Import the chosen canvas if the user has picked one from the dashbord,
  989. otherwise load an empty canvas
  990. ================================================= */
  991. // if a canvas is chosen by the user to be loaded
  992. if (current_canvas_id !== '') {
  993. var url = 'json/' + current_canvas_id + '.json';
  994. // var url= 'json/test_canvas.json';
  995. // get the saved ISON object in the sendJSON.text file
  996. $.getJSON(url, function(returnedObj) {
  997. // Display the json data in the html
  998. var itemListHTML = '';
  999. // iterate through the object
  1000. $.each(returnedObj, function(key, value) {
  1001. // project name and tem field
  1002. if (key === 'field_00[]') {
  1003. $('.form-header').find('input.proj_title').val(value[
  1004. 0]);
  1005. $('.form-header').find('input.proj_date').val(value[1]);
  1006. }
  1007. else if (key !== 'new_item') {
  1008. if ($.type(value) === "array") {
  1009. $.each(value, function(i, itm) {
  1010. /** FIX DUPLICATIONs in the canvas when importing
  1011. /* Importing will override the canvas content
  1012. clear the canvas by giving en emty content to the ul list (remove previous list items) */
  1013. $('.canvas-form').find('.card').filter('.' + key.substr(0, 8)).find('ul.item_list').html('');
  1014. /* Create a list item with each value item
  1015. and give it text area with the name attribute as the "key" (right field name) */
  1016. itemListHTML +=
  1017. // '<li class="added_item"><span class="handle glyphicon glyphicon-move"></span><textarea maxlength="100" class="expandable" rows="3" data-limit-rows="true" data-autoresize name="' + key + '">' + itm + '</textarea><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
  1018. '<li class="added_item"><div class="expandable" name="' + key + '">' + itm + '</div><br /><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
  1019. });
  1020. }
  1021. else { // a single value string
  1022. itemListHTML +=
  1023. // '<li class="added_item"><span class="handle glyphicon glyphicon-move"></span><textarea maxlength="100" class="expandable" rows="3" data-limit-rows="true" data-autoresize name="' + key + '">' + value + '</textarea><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
  1024. '<li class="added_item"><div class="expandable" name="' + key + '">' + value + '</div><br /><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>';
  1025. }
  1026. /* Append the created list items/textatreas to the right field based on the "key"*/
  1027. /* the str.substr(start,length)
  1028. is used to remove the [] from the end of the "key"name (for each field. also the name attributes accociated with each fiels) so that we can select the right class (right field) and append the created lists to the right field
  1029. so field names/key/name attribute will tuen into class names: ex: field_1[] becomes field_1
  1030. */
  1031. // find the field by its class names besed on the current key name
  1032. // append the created list of item values to that right field
  1033. $('.canvas-form').find('.card').filter('.' + key.substr(0, 8)).find('ul.item_list').append(itemListHTML);
  1034. /*$('form').find('.card').filter('.field_1').find('ul.item_list').append(itemListHTML); */
  1035. /* !! Empty the item list after each count of "key" so that the previous item lists from the other fields (associated with the previous key) don't get added up to the item list of other fields */
  1036. itemListHTML = '';
  1037. }
  1038. });
  1039. });
  1040. // Toggle textarea.expandable/div.expandable on edit
  1041. toggleTextElementOnFocus();
  1042. // Get the user's tags from the database and apply them on the canvas
  1043. getTags();
  1044. // Show "Tag selected term" link
  1045. if($(this).parent().parent().parent().prev().prev().children().length > 0) {
  1046. $(this).parent().parent().parent().prev().css("display", "block");
  1047. }
  1048. // Fix the heights after importing
  1049. // fixHeights();
  1050. }
  1051. /* ================================================
  1052. Toggle the introduction text in fields
  1053. ================================================= */
  1054. //$(selector).toggle(speed,easing,callback)
  1055. $('.card').on('click', '.intro-toggle', function() {
  1056. var $TogglingText = $($(this).closest('.card').find('.intro'));
  1057. var $Toggler = $($(this).closest('.card').find('.intro-toggle'));
  1058. $TogglingText.toggle('slow', function() {
  1059. // Do this when toggling:
  1060. // the boolean .is(':visible') of the current toggle state
  1061. if ($TogglingText.is(':visible')) {
  1062. // change the text of the toggle
  1063. $Toggler.find('.intro-toggle-text').text('Hide description');
  1064. // change the icon of the toggle
  1065. $Toggler.find('.intro-toggle-icon').switchClass("glyphicon-plus-sign", "glyphicon-minus-sign", 1000, "easeInOutQuad");
  1066. }
  1067. else {
  1068. $Toggler.find('.intro-toggle-text').text('Show description');
  1069. $Toggler.find('.intro-toggle-icon').switchClass("glyphicon-minus-sign", "glyphicon-plus-sign", 1000, "easeInOutQuad");
  1070. }
  1071. });
  1072. });
  1073. /* ================================================
  1074. Auto expand user input textareas
  1075. ================================================= */
  1076. /* Works for textareas already exsting in the html when the page loads -> User input
  1077. $.each($('textarea[data-autoresize]'), function() {
  1078. var offset = this.offsetHeight - this.clientHeight;
  1079. var resizeTextarea = function(el) {
  1080. $(el).css('height', 'auto').css('height', el.scrollHeight + offset);
  1081. };
  1082. $(this).on('keyup input', function() {
  1083. resizeTextarea(this);
  1084. }).removeAttr('data-autoresize');
  1085. });
  1086. /* ================================================
  1087. Limiting the number of lines in textareas
  1088. ================================================= */
  1089. // <textarea data-limit-rows="true" cols="60" rows="8"></textarea>
  1090. /*
  1091. $('.card').on('keypress', 'textarea[data-limit-rows=true]', function(event) {
  1092. var textarea = $(this),
  1093. text = textarea.val(),
  1094. // match() -> Searches a string for a match against a regular expression, and returns the matches, as an Array object.
  1095. numberOfLines = (text.match(/\n/g) || []).length + 1,
  1096. maxRows = parseInt(textarea.attr('rows'));
  1097. // if the number of lines have reached the max rows
  1098. if (numberOfLines === maxRows) {
  1099. return false;
  1100. }
  1101. });
  1102. */
  1103. /* ================================================
  1104. Handling user input, ADD items
  1105. A. Add button
  1106. B. Clicking enter
  1107. ================================================= */
  1108. /* ----------------------------------------------
  1109. add new idea slide effect
  1110. ----------------------------------------------- */
  1111. // When clicking on "add a new idea", Slide down and show the input field for adding a new item (from the begining, it is set to display:hidden with CSS). If clicked again, slide it up. After that, set the textarea in automatic focus
  1112. $('.card').on('click', 'a.add-idea', function(event) {
  1113. // stop the default behavior of the link (jumping back to the start of the page)
  1114. event.preventDefault();
  1115. // set the textarea automatically in focus
  1116. $(this).closest('.card').find('.user-input').slideToggle("slow", function() {
  1117. // When the toggle animation is complete:
  1118. // set the text area in focus
  1119. $(this).closest('.card').find('.new_item').val('');
  1120. $(this).closest('.card').find('.chars').text(maxLength);
  1121. $(this).closest('.card').find('.new_item').focus();
  1122. });
  1123. });
  1124. /* ----------------------------------------------
  1125. A. When we click the add btn to
  1126. add the item to the list
  1127. ----------------------------------------------- */
  1128. // event deligation to handle the present and future elements that are dynamically added
  1129. $('.card').on('click', '.add_btn', function() {
  1130. var new_item = $(this).closest('.card').find('.new_item').val();
  1131. var new_item_height = $(this).closest('.card').find('.new_item').height();
  1132. // number of items are in the list
  1133. var fieldItemCount = $(this).closest('.card').find('ul.item_list').find('li').length;
  1134. // new item added, increment the number of items
  1135. fieldItemCount++;
  1136. // add the input value as a textarea item
  1137. /* create a name attribute in the "field_nr[]" format to be able to tag each new item with the right field attr name (based on the field they are added to). This is to format the json file for each group of dynamically added items. We get the name attribute directly from the id attribute of the ul list in each card (the one we pressed the add button in) */
  1138. // if the new item input exist (is not empty), add the item
  1139. if (new_item) {
  1140. var field_attr = $(this).closest('.card').find('ul.item_list').attr('id') + '[]';
  1141. // The height of the newly added item = the height of the add new idea textarea
  1142. $(this).closest('.card').find('ul.item_list').append(
  1143. // '<li class="added_item"><span class="handle glyphicon glyphicon-move"></span><textarea maxlength="100" class="expandable" rows="3" data-limit-rows="true" data-autoresize name="' + field_attr + '">' + new_item + '</textarea><span class="remove glyphicon glyphicon-remove-circle"></span></li>'
  1144. '<li class="added_item"><div class="expandable" name="' + field_attr + '">' + new_item + '</div><br /><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>'
  1145. );
  1146. // Fix the heights only after a new item is added
  1147. // fixHeights();
  1148. }
  1149. // clear the new item the text area value
  1150. $(this).closest('.card').find('.new_item').val('');
  1151. /* When clicking on "add idea", hide the input field for adding a new item (slideUp() doesn't work nicely here)*/
  1152. $(this).closest('.card').find('.user-input').hide("fast", function() {
  1153. // Animation complete.
  1154. });
  1155. // Limit the text in the idea field if it reaches the max length
  1156. limitLengthOnInput();
  1157. // Apply event listener to the added idea handling the application of tags should the user writes one of the terms in it
  1158. // applyTagOnTypeMatch();
  1159. // Toggle textarea.expandable/div.expandable on edit
  1160. toggleTextElementOnFocus();
  1161. // Remove all tags from all fields
  1162. removeTags();
  1163. // Get the user's tags from the database and apply them on the canvas
  1164. getTags();
  1165. // Show "Tag selected term" link
  1166. if($(this).parent().parent().prev().prev().children().length > 0) {
  1167. $(this).parent().parent().prev().css("display", "block");
  1168. }
  1169. });
  1170. /* ----------------------------------------------
  1171. B. Clicking enter in the add idea textarea,
  1172. will add the new item to the card
  1173. ----------------------------------------------- */
  1174. $('.card').on('keypress', 'textarea[data-limit-rows=true]', function(event) {
  1175. var textarea = $(this);
  1176. var text = textarea.val();
  1177. /* The jQuery event.which -->
  1178. Returns which keyboard key was pressed: */
  1179. // if the enter is pressed, event.which === 13
  1180. if (event.which === 13 && !$("li.added_item .expandable").is(":focus")) {
  1181. var new_item = $(this).closest('.card').find('.new_item').val();
  1182. var new_item_height = $(this).closest('.card').find('.new_item').height();
  1183. // number of items are in the list
  1184. var fieldItemCount = $(this).closest('.card').find('ul.item_list')
  1185. .find('li').length;
  1186. // new item added, increment the number of items
  1187. fieldItemCount++;
  1188. // add the input value as a textarea item
  1189. /* create a name attribute in the "field_nr[]" format to be able to tag each new item with the right field attr name (based on the field they are added to). This is to format the json file for each group of dynamically added items. We get the name attribute directly from the id attribute of the ul list in each card (the one we pressed the add button in) */
  1190. // if the new item input exist (is not empty), add the item
  1191. if (new_item) {
  1192. var field_attr = $(this).closest('.card').find('ul.item_list').attr(
  1193. 'id') + '[]';
  1194. // The height of the newly added item = the height of the add new idea textarea
  1195. $(this).closest('.card').find('ul.item_list').append(
  1196. // '<li class="added_item"><span class="handle glyphicon glyphicon-move"></span><textarea maxlength="100" class="expandable" rows="3" data-limit-rows="true" data-autoresize name="' + field_attr + '">' + new_item + '</textarea><span class="remove glyphicon glyphicon-remove-circle"></span></li>');
  1197. '<li class="added_item"><div class="expandable" name="' + field_attr + '">' + new_item + '</div><br /><span class="handle glyphicon glyphicon-list"></span><span class="move-up glyphicon glyphicon-chevron-up"></span><span class="move-down glyphicon glyphicon-chevron-down"></span><span class="remove glyphicon glyphicon-remove-circle"></span></li>'
  1198. );
  1199. // Fix the heights only after a new item is added
  1200. // fixHeights();
  1201. }
  1202. // clear the new item the text area value
  1203. $(this).closest('.card').find('.new_item').val('');
  1204. /* When clicking on "add idea", hide the input field for adding a new item (slideUp() doesn't work nicely here)*/
  1205. $(this).closest('.card').find('.user-input').hide("fast", function() {
  1206. // Animation complete.
  1207. });
  1208. // Limit the text in the idea field if it reaches the max length
  1209. limitLengthOnInput();
  1210. // Apply event listener to the added idea handling the application of tags should the user writes one of the terms in it
  1211. // applyTagOnTypeMatch();
  1212. // Toggle textarea.expandable/div.expandable on edit
  1213. toggleTextElementOnFocus();
  1214. // Remove all tags from all fields
  1215. removeTags();
  1216. // Get the user's tags from the database and apply them on the canvas
  1217. getTags();
  1218. // Show "Tag selected term" link
  1219. if($(this).parent().parent().parent().prev().prev().children().length > 0) {
  1220. $(this).parent().parent().parent().prev().css("display", "block");
  1221. }
  1222. }
  1223. });
  1224. /* ================================================
  1225. Moving ideas to a different category
  1226. ================================================= */
  1227. // Declarations
  1228. // var categoryUl = $("div#move-window ul");
  1229. var categoryDestination;
  1230. var categoryLis = $("div#move-window ul").html();
  1231. var categoryAs = $("div#move-window ul a");
  1232. var categoryOrigin;
  1233. var ideaLi;
  1234. var linkLi;
  1235. var linkText;
  1236. // Remove the link to the current category, as the idea cannot be moved to its own category where it already is
  1237. function removeLinkToOriginCategory(text) {
  1238. // If the number of the category is between 10-99
  1239. if(text.substring(6, 7) != "0") {
  1240. categoryOrigin = text.substring(6, 9) - 1;
  1241. }
  1242. // If the number of the category is between 0-9
  1243. else {
  1244. categoryOrigin = text.substring(7, 9) - 1;
  1245. }
  1246. // Remove "a" tag
  1247. linkLi = $("div#move-window ul li").get(categoryOrigin);
  1248. linkText = categoryAs.get(categoryOrigin).innerHTML;
  1249. linkLi.innerHTML = linkText;
  1250. }
  1251. // When the user clicks on the "Move" icon, show the move window
  1252. $('.card').on('click', 'span.handle', function() {
  1253. // Show the move window
  1254. $("div#shadow").css("display", "block");
  1255. $("div#move-window").css("display", "block");
  1256. // Assign the idea that is going to be moved
  1257. ideaLi = $(this).parent();
  1258. // Remove the link to the current category, as the idea cannot be moved to its own category where it already is
  1259. removeLinkToOriginCategory($(this).parent().parent().attr("id"));
  1260. });
  1261. // Close the move window
  1262. function closeMoveWindow() {
  1263. // Close the move window
  1264. $("div#shadow").css("display", "none");
  1265. $("div#move-window").css("display", "none");
  1266. }
  1267. // When the user clicks on the "Close" button
  1268. $("div#move-window button.close").on("click", function() {
  1269. // Close the move window
  1270. closeMoveWindow();
  1271. });
  1272. // When the user clicks on a category, move the idea
  1273. function moveIdeaOnClick() {
  1274. $("div#move-window ul a").on("click", function() {
  1275. // If the number of the category is between 10-99
  1276. if($(this).parent().text().trim().substring(1, 2) != ".") {
  1277. categoryDestination = $(this).parent().text().trim().substring(0, 2);
  1278. }
  1279. // If the number of the category is between 0-9
  1280. else {
  1281. categoryDestination = $(this).parent().text().trim().substring(0, 1);
  1282. }
  1283. // Move the idea
  1284. // If the number of the category is between 10-99
  1285. if(categoryDestination > 9) {
  1286. $("ul#field_" + categoryDestination).append(ideaLi);
  1287. // $("ul#field_0" + (categoryOrigin + 1)).parent().find("p.tag-selected-term").css("display", "none");
  1288. }
  1289. // If the number of the category is between 0-9
  1290. else {
  1291. $("ul#field_0" + categoryDestination).append(ideaLi);
  1292. // $("ul#field_0" + (categoryOrigin + 1)).parent().find("p.tag-selected-term").css("display", "none");
  1293. }
  1294. // Close the move window
  1295. closeMoveWindow();
  1296. // Restore links in the move window
  1297. if($("div#move-window li").length > $("div#move-window a").length) {
  1298. $("div#move-window ul").children().remove()
  1299. $("div#move-window ul").append(categoryLis);
  1300. moveIdeaOnClick();
  1301. }
  1302. // Hide "Tag selected term" link in the origin category if there are no ideas left
  1303. if($("ul#field_0" + (categoryOrigin + 1)).children().length === 0) {
  1304. // If the number of the category is between 10-99
  1305. if((categoryOrigin + 1) > 9) {
  1306. $("ul#field_" + (categoryOrigin + 1)).parent().find("p.tag-selected-term").css("display", "none");
  1307. }
  1308. // If the number of the category is between 0-9
  1309. else {
  1310. $("ul#field_0" + (categoryOrigin + 1)).parent().find("p.tag-selected-term").css("display", "none");
  1311. }
  1312. }
  1313. // Show "Tag selected term" link in the destination category
  1314. // If the number of the category is between 10-99
  1315. if((categoryOrigin + 1) > 9) {
  1316. $("ul#field_" + categoryDestination).parent().find("p.tag-selected-term").css("display", "block");
  1317. }
  1318. // If the number of the category is between 0-9
  1319. else {
  1320. $("ul#field_0" + categoryDestination).parent().find("p.tag-selected-term").css("display", "block");
  1321. }
  1322. });
  1323. }
  1324. moveIdeaOnClick();
  1325. /* ================================================
  1326. Moving ideas up
  1327. ================================================= */
  1328. // When the user clicks on the "Up" button
  1329. $('.card').on('click', 'span.move-up', function() {
  1330. // Declarations
  1331. var ideaLiCurrent = $(this).parent();
  1332. var ideaLiPrevious = $(this).parent().prev();
  1333. // Move the idea
  1334. if(ideaLiPrevious.is("li")) {
  1335. ideaLiCurrent.detach();
  1336. ideaLiPrevious.before(ideaLiCurrent);
  1337. }
  1338. });
  1339. /* ================================================
  1340. Moving ideas down
  1341. ================================================= */
  1342. // When the user clicks on the "Down" button
  1343. $('.card').on('click', 'span.move-down', function() {
  1344. // Declarations
  1345. var ideaLiCurrent = $(this).parent();
  1346. var ideaLiNext = $(this).parent().next();
  1347. // Move the idea
  1348. if(ideaLiNext.is("li")) {
  1349. ideaLiCurrent.detach();
  1350. ideaLiNext.after(ideaLiCurrent);
  1351. }
  1352. });
  1353. /* ================================================
  1354. Deleting ideas
  1355. ================================================= */
  1356. // when the cross beside the textarea is clicked (span.remove)
  1357. // remove that list item
  1358. $('.card').on('click', 'span.remove', function() {
  1359. // If there are no ideas left, hide "Tag selected term" link
  1360. if($(this).prev().parent().parent().children().length === 1) {
  1361. $(this).prev().parent().parent().next().css("display", "none");
  1362. }
  1363. // Remove the list item
  1364. $(this).closest('li').remove();
  1365. });
  1366. /* ================================================
  1367. Sortable field ideas
  1368. ================================================= */
  1369. // make items sortable in their fields and between fields
  1370. /*
  1371. $('.sortable').sortable({
  1372. connectWith: '.connectedList',
  1373. placeholder: "sort-placeholder",
  1374. // revert: true
  1375. zIndex: 300 // Or greater than any other relative/absolute/fixed elements and droppables
  1376. });
  1377. */
  1378. /* ================================================
  1379. Sorting and Dragging events
  1380. ================================================= */
  1381. /* sortstart
  1382. sortover
  1383. sortstop */
  1384. // Every textarea in a item needs to get the right name attribute once they have been dropped in another field (so it ends up in the right place in the json file)
  1385. /*
  1386. // Dragging starts
  1387. $(".sortable").on("sortstart", function(event, ui) {
  1388. // WHEN WE SORT CARDS, $(this) ---> the "begining" ul with the class of .sortable
  1389. });
  1390. // Dragging ends: item dropped
  1391. $(".sortable").on("sortstop", function(event, ui) {
  1392. // get the id of the field ul (to set the name attribute of textareas)
  1393. // # mouseleave is the right event for when we release and leave a card mouseup doesn't work properly in this case
  1394. $('.card').on('mouseleave', 'li', function() {
  1395. //$(selector).attr(attribute,value)
  1396. var fieldAttr = $(this).closest('ul.item_list').attr('id');
  1397. // $(this).find('textarea').attr('name', fieldAttr + '[]');
  1398. $(this).find('li.added_item .expandable').attr('name', fieldAttr + '[]');
  1399. });
  1400. });
  1401. */
  1402. /* ================================================
  1403. SAVING THE CANVAS:
  1404. CLICK ON #EXPORT JSON# form button
  1405. ================================================= */
  1406. /* ----------------------------------------------
  1407. When the user clicks on the SAVE CANVAS button
  1408. ----------------------------------------------- */
  1409. $('.canvas-form').on('click', '.json_exp', function() {
  1410. /* ----------------------------------------------
  1411. A: saving the canvas
  1412. as a registered user
  1413. ----------------------------------------------- */
  1414. // php variables are retieved in the header of the canvas index.php as js variables -->
  1415. var name_save_canvas = $('.form-header').find('.proj_title').val();
  1416. var date_save_canvas = $('.form-header').find('.proj_date').val();
  1417. var save_canvas_obj = {
  1418. 'email_save_canvas': email_save_canvas,
  1419. 'name_save_canvas': name_save_canvas,
  1420. 'date_save_canvas': date_save_canvas
  1421. };
  1422. var save_canvas = $.param(save_canvas_obj);
  1423. /* Post the JSON stringified object to the php file
  1424. (the php script will save it in a .json file )*/
  1425. var save_reg_url = "php/save-canvas.php";
  1426. $.post(save_reg_url, { save_canvas: save_canvas }, function(data, status) {
  1427. //the returned data is successful, is the $canvas_id
  1428. var canvas_id = data;
  1429. // send this canvas_id with the next ajax requestedto the php/canvas.php file and use it as the name of the json file to be saved
  1430. // Give the user feedback that the canvas is saved
  1431. if (data !== 400 || data !== 401) {
  1432. if ($('.imp-exp-btn ').find(".save-canvas-feedback") !== null) {
  1433. $('.imp-exp-btn ').find(".save-canvas-feedback").remove();
  1434. }
  1435. $('.canvas-form').find('.imp-exp-btn ').append('<div class="save-canvas-feedback"><p><span class="glyphicon glyphicon-ok" aria-hidden="true"></span>Your canvas is saved in your dashbord</p></div>');
  1436. // remove the canvas is saves message as soon as user changes the canvas
  1437. // $('.canvas-form').on("change keyup", 'textarea', function() {
  1438. $('.canvas-form').on("change keyup", '.expandable', function() {
  1439. $('.imp-exp-btn ').find(".save-canvas-feedback").remove();
  1440. });
  1441. } else {
  1442. $('.canvas-form').find('.imp-exp-btn ').append('<div class="save-canvas-feedback-fail"><p>Oh! We could not save your canvas. Please try again or contact us at hello@ethicscanvas.org</p></div>');
  1443. }
  1444. // For the second AJAX request:
  1445. /* ----------------------------------------------
  1446. B: Exporing the form data json to a file
  1447. and save it on the server
  1448. ----------------------------------------------- */
  1449. // $('#result').text(JSON.stringify($('.canvas-form').serializeObject()));
  1450. // Make the JSON object into a JSON string
  1451. var JSONstrObj = JSON.stringify($('.canvas-form').serializeObject());
  1452. var url = "php/canvas.php";
  1453. /* Post the JSON stringified object to the php file
  1454. (the php script will save it in a .json file )*/
  1455. // also, send the canvas_id and use it for naming the file
  1456. $.post(url, {
  1457. JSONstrObj: JSONstrObj,
  1458. canvas_id: canvas_id
  1459. }, function(data, status) {
  1460. console.log(
  1461. 'Response from php when sending the form json object: \n' +
  1462. 'data:' + data + '\n status: ' + status);
  1463. }).fail(function(jqXHR) {
  1464. console.log("Error " + jqXHR.status + ' ' + jqXHR.statustext);
  1465. });
  1466. }).fail(function(jqXHR) {
  1467. console.log("Error " + jqXHR.status + ' ' + jqXHR.statustext);
  1468. });
  1469. // Prevent the card item list from reseting itself after clicking on the export button (submission). Because the type of the button is submit
  1470. return false;
  1471. });
  1472. /* ================================================
  1473. HANDLING CLICK ON : Share This Canvas BUTTON
  1474. ================================================= */
  1475. $('.canvas-form').on('click', '.share_canvas', function() {
  1476. $('.share_canvas_email').slideDown(1000, function() {
  1477. // SAVE THE PDF AS file
  1478. $.post('mpdf/canvas-pdf-save.php', function(data, status) { }); // save pdf as file
  1479. });
  1480. });
  1481. $('.canvas-form').on('click', '.share_canvas_send', function() {
  1482. var share_email = $('.share_canvas_email').find('input').serialize();
  1483. // This sends a serialized array share_email to the php file. Example: the value of this array will be: share-canvas-email=eternalflame.f%40gmail.com
  1484. $.post('php/share-canvas.php', {
  1485. share_email: share_email
  1486. }, function(data, status) {
  1487. if (data == 200) { // canvas successfully shared
  1488. $('.canvas-form').find('.imp-exp-btn ').append('<div class="save-canvas-feedback"><p><span class="glyphicon glyphicon-ok" aria-hidden="true"></span>Your canvas has been shared by email</p></div>')
  1489. }
  1490. else {
  1491. $('.canvas-form').find('.imp-exp-btn ').append('<div class="save-canvas-feedback"><p><span class="glyphicon glyphicon-ok" aria-hidden="true"></span>Your canvas could not be shared by email</p></div>')
  1492. }
  1493. });
  1494. // slide up the .share_canvas_email area
  1495. $('.share_canvas_email').slideUp();
  1496. });
  1497. /* ================================================
  1498. Controlling the height of divs dynamically
  1499. ================================================= */
  1500. // Call this function after adding a new item and importing
  1501. // $( window ).width(); ->Returns width of browser viewport
  1502. /*
  1503. function fixHeights() {
  1504. // Returns width of browser viewport
  1505. var screenSize = $(window).width();
  1506. //the longest card of the group 1 .masonry-layout7-5
  1507. var longest_1 = $('.masonry-layout7-5').height();
  1508. //the longest card of the group 2 .masonry-layout7-5
  1509. var longest_2 = $('.masonry-layout4').height();
  1510. // --- 5 COL Range ----
  1511. if (screenSize >= 1139) {
  1512. // inforcing a fixed height ".height(longest_1/2)" will create some layout issues when we try to add new items the add item area will go outside the box and the heights don't increase naturally
  1513. // card group 1:
  1514. // $('.field_05,.field_11, .field_07').css('min-height', longest_1 - longest_1 * 5 / 100);
  1515. // $('.field_06,.field_08, .field_12').css('min-height', longest_1 + longest_1 * 5 / 100);
  1516. // $('.field_01, .field_02').css('min-height', longest_1 * 2 + longest_1 * 1 / 100);
  1517. // card group 2:
  1518. // $('.field_03, .field_09, .field_10, .field_04').css('min-height', longest_2 * 2 - longest_2 * 20 / 100);
  1519. $('.field_05,.field_11, .field_07').css('min-height', longest_1 - longest_1 * 20 / 100);
  1520. $('.field_06,.field_08, .field_12').css('min-height', longest_1 - longest_1 * 20 / 100);
  1521. $('.field_01, .field_02').css('min-height', longest_1 + longest_1 * 40 / 100);
  1522. // card group 2:
  1523. $('.field_03, .field_09, .field_10, .field_04').css('min-height', longest_2 - longest_2 * 10 / 100);
  1524. }
  1525. // 4 COL Range //
  1526. else if (screenSize >= 977 && screenSize <= 1138) {
  1527. // card group 1:
  1528. // row 1
  1529. $('.field_01,.field_06, .field_12,.field_08 ').css('min-height', longest_1 + longest_2 * 20 / 100);
  1530. // row 2
  1531. $('.field_05,.field_11, .field_07,.field_02 ').css('min-height', longest_1 + longest_2 * 20 / 100);
  1532. // card group 2:
  1533. // row 3
  1534. $('.field_03, .field_09, .field_10, .field_04').css('min-height', longest_2 * 2 - longest_2 * 20 / 100);
  1535. } else if (screenSize >= 920 && screenSize <= 976) {
  1536. // card group 1:
  1537. // row 1
  1538. $('.field_01,.field_06, .field_12,.field_08 ').css('min-height', longest_1 + longest_2 * 20 / 100);
  1539. // row 2
  1540. $('.field_05,.field_11, .field_07,.field_02 ').css('min-height', longest_1 + longest_2 * 20 / 100);
  1541. // card group 2:
  1542. // row 3
  1543. $('.field_03, .field_09, .field_10, .field_04').css('min-height', longest_2 * 2 - longest_2 * 20 / 100);
  1544. } else if (screenSize >= 485 && screenSize <= 919) {
  1545. // else if (500 <= screenSize < 920) {
  1546. // card group 1:
  1547. $('.field_01,.field_06, .field_12,.field_08 ').css('min-height', longest_1 * 80 / 100);
  1548. $('.field_05,.field_11, .field_07,.field_02 ').css('min-height', longest_1 * 80 / 100);
  1549. // card group 2:
  1550. $('.field_03, .field_09, .field_10, .field_04').css('min-height', longest_2 * 80 / 100);
  1551. // --- 1 COL Range ----
  1552. } else {
  1553. // card group 1:
  1554. $('.field_01,.field_06, .field_12,.field_08 ').css('min-height', longest_1 * 20 / 100);
  1555. $('.field_05,.field_11, .field_07,.field_02 ').css('min-height', longest_1 * 20 / 100);
  1556. // card group 2:
  1557. $('.field_03, .field_09, .field_10, .field_04').css('min-height', longest_2 * 20 / 100);
  1558. }
  1559. }
  1560. function fixHeights() {
  1561. // Returns width of browser viewport
  1562. var screenSize = $(window).width();
  1563. var field01 = $("div.field_01");
  1564. var field02 = $("div.field_02");
  1565. var field03 = $("div.field_03");
  1566. var field04 = $("div.field_04");
  1567. var field05 = $("div.field_05");
  1568. var field06 = $("div.field_06");
  1569. var field07 = $("div.field_07");
  1570. var field08 = $("div.field_08");
  1571. var field09 = $("div.field_09");
  1572. // Set the height of every field
  1573. var heightOfField01 = field01.height();
  1574. var heightOfField03 = field03.height();
  1575. var heightOfField04 = field04.height();
  1576. var heightOfField03And04 = field03.height() + field04.height();
  1577. var heightOfField09 = field09.height();
  1578. var heightOfField05 = field05.height();
  1579. var heightOfField06 = field06.height();
  1580. var heightOfField05And06 = field05.height() + field06.height();
  1581. var heightOfField02 = field02.height();
  1582. // --- 5 COL Range ---
  1583. if (screenSize >= 935) {
  1584. var longestInGroup1 = Math.max(heightOfField01, heightOfField03, heightOfField04, heightOfField03And04, heightOfField09, heightOfField05, heightOfField06, heightOfField05And06, heightOfField02);
  1585. console.log(longestInGroup1);
  1586. // Field group 1
  1587. switch(longestInGroup1) {
  1588. case heightOfField01:
  1589. $(".field_04").css("min-height", longestInGroup1 + 10);
  1590. $(".field_09").css("min-height", longestInGroup1 + 448);
  1591. $(".field_06").css("min-height", longestInGroup1 + 10);
  1592. $(".field_02").css("min-height", longestInGroup1 + 448);
  1593. break;
  1594. case heightOfField03:
  1595. // Code goes here
  1596. break;
  1597. case heightOfField04:
  1598. // Code goes here
  1599. break;
  1600. case heightOfField03And04:
  1601. // Code goes here
  1602. break;
  1603. case heightOfField09:
  1604. // Code goes here
  1605. break;
  1606. case heightOfField05:
  1607. // Code goes here
  1608. break;
  1609. case heightOfField06:
  1610. // Code goes here
  1611. break;
  1612. case heightOfField05And06:
  1613. // Code goes here
  1614. break;
  1615. case heightOfField02:
  1616. // Code goes here
  1617. break;
  1618. default:
  1619. break;
  1620. }
  1621. }
  1622. // --- 4 COL Range ---
  1623. else if (screenSize >= 935 && screenSize <= 991) {
  1624. // Field group 1
  1625. // Code goes here
  1626. // Field group 2
  1627. // Code goes here
  1628. }
  1629. else if (screenSize >= 992 && screenSize <= 1153) {
  1630. // Field group 1
  1631. // Code goes here
  1632. // Field group 2
  1633. // Code goes here
  1634. }
  1635. // --- 2 COL Range ---
  1636. else if (screenSize >= 500 && screenSize <= 934) {
  1637. // Field group 1
  1638. // Code goes here
  1639. // Field group 2
  1640. // Code goes here
  1641. }
  1642. // --- 2-5 COL Range ---
  1643. if (screenSize >= 500) {
  1644. var longestInGroup2;
  1645. // Field group 2
  1646. // Determine the longest Field in group 2
  1647. if(field07.height() < field08.height()) {
  1648. longestInGroup2 = field08;
  1649. }
  1650. else {
  1651. longestInGroup2 = field07;
  1652. }
  1653. if(longestInGroup2 === field07) {
  1654. $(".field_08").css("min-height", longestInGroup2.height() + 10);
  1655. }
  1656. else {
  1657. $(".field_07").css("min-height", longestInGroup2.height() + 10);
  1658. }
  1659. }
  1660. // --- 1 COL Range ---
  1661. // Field group 1
  1662. // Code goes here
  1663. // Field group 2
  1664. // Code goes here
  1665. }
  1666. */
  1667. /*
  1668. new ResizeSensor($(".field_01, .field_02, .field_03, .field_04, .field_05, .field_06, .field_07, .field_08, .field_09"), function() {
  1669. // fixHeights();
  1670. });
  1671. */
  1672. });