Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

tm_editable.js 29KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647
  1. var Global_tm_array = [];
  2. var tm_counter = -1;
  3. (function ( $ ) {
  4. $.fn.tm_editbale = function(option,new_obj) {
  5. this.each(function(){
  6. $this = $(this);
  7. var i_class_name = new_obj.hasOwnProperty('iclass') ? new_obj.iclass:$this.data('iclass');
  8. var i_placeholder = new_obj.hasOwnProperty('iplaceholder') ? new_obj.iclass:$this.data('iplaceholder');
  9. var i_validate = new_obj.hasOwnProperty('ivalidate') ? new_obj.iclass:$this.data('ivalidate');
  10. var i_error = new_obj.hasOwnProperty('ierror') ? new_obj.iclass:$this.data('ierror');
  11. var i_remover = new_obj.hasOwnProperty('remover') ? new_obj.iclass:$this.data('remover');
  12. var i_removerclass = new_obj.hasOwnProperty('removerclass') ? new_obj.iclass:$this.data('removerclass');
  13. var i_date = new_obj.hasOwnProperty('date') ? new_obj.iclass:$this.data('date');
  14. var theme_name = new_obj.hasOwnProperty('theme') ? new_obj.theme:$this.data('theme');
  15. //get full_length
  16. var full_length = {
  17. 'inside':true,
  18. 'outside':true
  19. }
  20. if(new_obj.hasOwnProperty('full_length')){
  21. if(new_obj.full_length.hasOwnProperty('inside'))
  22. full_length.inside = new_obj.full_length.inside
  23. if(new_obj.full_length.hasOwnProperty('outside'))
  24. full_length.outside = new_obj.full_length.outside
  25. }
  26. //get outside btn
  27. var outside_btn = {
  28. new_line:false,
  29. pull:'right',
  30. onshow:"&nbsp;&nbsp;<i class='fa fa-pencil'></i>",
  31. removebtn:"&nbsp;&nbsp;<i class='fa fa-times'></i>",
  32. onhover:"&nbsp;Edit"
  33. }
  34. if(new_obj.hasOwnProperty('outside_btn')){
  35. if(new_obj.outside_btn.hasOwnProperty('new_line'))
  36. outside_btn.new_line = new_obj.outside_btn.new_line
  37. if(new_obj.outside_btn.hasOwnProperty('pull'))
  38. outside_btn.pull = new_obj.outside_btn.pull
  39. if(new_obj.outside_btn.hasOwnProperty('onshow'))
  40. outside_btn.onshow = new_obj.outside_btn.onshow
  41. if(new_obj.outside_btn.hasOwnProperty('removebtn'))
  42. outside_btn.removebtn = new_obj.outside_btn.removebtn
  43. if(new_obj.outside_btn.hasOwnProperty('onhover'))
  44. outside_btn.onhover = new_obj.outside_btn.onhover
  45. }
  46. //get inside btn
  47. var inside_btn = {
  48. new_line:false,
  49. pull:'right',
  50. ok:"<i class='fa fa-check'></i>",
  51. cancel:"<i class='fa fa-times'></i>"
  52. }
  53. if(new_obj.hasOwnProperty('inside_btn')){
  54. if(new_obj.inside_btn.hasOwnProperty('new_line'))
  55. inside_btn.new_line = new_obj.inside_btn.new_line
  56. if(new_obj.inside_btn.hasOwnProperty('pull'))
  57. inside_btn.pull = new_obj.inside_btn.pull
  58. if(new_obj.inside_btn.hasOwnProperty('ok'))
  59. inside_btn.ok = new_obj.inside_btn.ok
  60. if(new_obj.inside_btn.hasOwnProperty('cancel'))
  61. inside_btn.cancel = new_obj.inside_btn.cancel
  62. }
  63. //Global Variable
  64. $this.Global_tm =
  65. {
  66. //Users Settings
  67. user_settings:
  68. {
  69. theme:theme_name,
  70. placeholder:i_placeholder,
  71. validate:i_validate,
  72. error_text:i_error,
  73. target_div:'just_edit',
  74. remover:i_remover,
  75. remover_class:i_removerclass,
  76. date:i_date,
  77. full_length:full_length,
  78. inside_btn:inside_btn,
  79. outside_btn:outside_btn,
  80. width:$this.width(),
  81. init:{
  82. before:function(){},
  83. after:function(){}
  84. },
  85. ok:{
  86. before:function(){
  87. var deferred = $.Deferred();
  88. deferred.resolve();
  89. return deferred.promise();
  90. },
  91. after:function(){}
  92. },
  93. remove:{
  94. before:function(){
  95. var deferred = $.Deferred();
  96. deferred.resolve();
  97. return deferred.promise();
  98. },
  99. after:function(){}
  100. }
  101. },
  102. //Default Settings
  103. default_settings:
  104. {
  105. theme:'basic-theme',
  106. class_name:'',
  107. placeholder:'',
  108. validate:'nullable',
  109. error_text:'',
  110. target_div:'just_edit',
  111. val:'',
  112. remover:false,
  113. remover_class:'.tm_editable_container',
  114. date:false,
  115. width:'auto',
  116. full_length:true
  117. },
  118. //Already exists
  119. already_exists : $this.hasClass('has_tm_editable_container'),
  120. counter:tm_counter++
  121. };
  122. //set before after methods
  123. if(new_obj.hasOwnProperty('init'))
  124. {
  125. if(new_obj.init.hasOwnProperty('before'))
  126. $this.Global_tm.user_settings.init.before = new_obj.init.before;
  127. if(new_obj.init.hasOwnProperty('after'))
  128. $this.Global_tm.user_settings.init.after = new_obj.init.after;
  129. }
  130. if(new_obj.hasOwnProperty('ok'))
  131. {
  132. if(new_obj.ok.hasOwnProperty('before'))
  133. $this.Global_tm.user_settings.ok.before = new_obj.ok.before;
  134. if(new_obj.ok.hasOwnProperty('after'))
  135. $this.Global_tm.user_settings.ok.after = new_obj.ok.after;
  136. }
  137. if(new_obj.hasOwnProperty('remove'))
  138. {
  139. if(new_obj.remove.hasOwnProperty('before'))
  140. $this.Global_tm.user_settings.remove.before = new_obj.remove.before;
  141. if(new_obj.remove.hasOwnProperty('after'))
  142. $this.Global_tm.user_settings.remove.after = new_obj.remove.after;
  143. }
  144. //Set FInal Settings
  145. $this.Global_tm.final_settings = $.extend($this.Global_tm.default_settings, $this.Global_tm.user_settings)
  146. //Find type of element
  147. $this.Global_tm.final_settings.hunt_type = hunt_type();
  148. $this.Global_tm.final_settings.val = $this.Global_tm.final_settings.hunt_type['value'];
  149. if(option == 'init')
  150. {
  151. if(!$this.Global_tm.already_exists)
  152. init_method();
  153. //console.log($this.Global_tm);
  154. }
  155. //ALL METHODS
  156. //Init method START
  157. function init_method(){
  158. $this.Global_tm.final_settings.init.before();
  159. $this.html('');
  160. $this.addClass('has_tm_editable_container '+$this.Global_tm.final_settings.theme).attr('my_rank',Global_tm_array.length);
  161. $this.Global_tm.counter++;
  162. $this.Global_tm.final_settings.final_val = make_my_clone()['value'];
  163. //**** UI *****
  164. make_my_clone = make_my_clone();
  165. //outside_btn
  166. var outside_btn_html = $this.Global_tm.final_settings.outside_btn.onshow+'<span class="i_edit_text">'+
  167. $this.Global_tm.final_settings.outside_btn.onhover
  168. +'</span>';
  169. var edit_btn = $('<a>').addClass('i_edit ').html(outside_btn_html);
  170. //outside text
  171. var input_field = $('<span>').addClass('i_text').html(make_my_clone['final_val']).attr('selected_val',make_my_clone['selected_val']);
  172. var just_edit = $('<div>').addClass('just_edit full_row');
  173. $this.Global_tm.final_settings.just_edit = just_edit;
  174. var i_loading = $('<div>').addClass('i_loading').css('display','none').html('<div class="vertical0"><div class="vertical1"><i class="fa fa-spinner fa-spin"></i>&nbsp;&nbsp;Loading</div></div>');
  175. //inside btn
  176. var ok_i = $('<span>').html($this.Global_tm.final_settings.inside_btn.ok);
  177. var cancel_i = $('<span>').html($this.Global_tm.final_settings.inside_btn.cancel);
  178. var ok_btn = $('<a>').addClass('btn btn-primary waves-effect waves-light m-l-5 m-r-10').append(ok_i);
  179. var cancel_btn = $('<a>').addClass('btn btn-warning waves-effect waves-light').append(cancel_i);
  180. var btn_container = $('<span>').addClass('ibtn_container '+$this.Global_tm.final_settings.inside_btn.pull).append(ok_btn).append(cancel_btn);
  181. //inside text
  182. var single_input = make_my_clone['my_clone'];
  183. var error = $('<span>').addClass('error-text smg-text full_row').text($this.Global_tm.final_settings.error_text);
  184. //remover button
  185. if($this.Global_tm.final_settings.remover)
  186. var remover_btn = $('<a>').addClass('i_remover').html($this.Global_tm.final_settings.outside_btn.removebtn).attr('removerclass',$this.Global_tm.final_settings.removerclass);
  187. else
  188. var remover_btn = '';
  189. var outside_btncontainer = $('<span>').addClass('outside_btncontainer '+$this.Global_tm.final_settings.outside_btn.pull).append(edit_btn).append(remover_btn);
  190. //attach UI
  191. var no_edit = $('<div>').addClass('no_edit full_row').append(input_field).append(outside_btncontainer);
  192. $this.append(no_edit).append(just_edit).attr('id','tm-edit-'+$this.Global_tm.counter);
  193. var template_input = $('<div>').addClass('input-group full_row md-input-wrapper').append(single_input).append('<span class="md-line"></span>').append(error);
  194. $($this.Global_tm.final_settings.just_edit).append(i_loading).append(template_input).append(btn_container);
  195. //attach events
  196. //Edit Button
  197. $(input_field).click(function(){
  198. $(no_edit).slideToggle(1);
  199. $(just_edit).slideToggle(100);
  200. $closest_tm = $(this).closest('.tm_editable_container');
  201. $closest_tm.find('input').select();
  202. $closest_tm.find('textarea').select();
  203. $closest_tm.find('select').focus();
  204. });
  205. $(edit_btn).click(function(){
  206. $(no_edit).slideToggle(1);
  207. $(just_edit).slideToggle(100);
  208. $closest_tm = $(this).closest('.tm_editable_container');
  209. $closest_tm.find('input').select();
  210. $closest_tm.find('textarea').select();
  211. $closest_tm.find('select').focus();
  212. });
  213. //Remover Button
  214. $(remover_btn).click(function(){
  215. remover(this);
  216. });
  217. //Ok Button
  218. $(ok_btn).click(function(){
  219. my_rank = get_rank(this);
  220. after_ok(my_rank);
  221. });
  222. //On Enter
  223. $(single_input).keypress(function(event){
  224. if(event.keycode == 13 || event.which == 13)
  225. {
  226. my_rank = get_rank(this);
  227. after_ok(my_rank);
  228. }
  229. });
  230. //Cancel Button
  231. $(cancel_btn).click(function(){
  232. $(no_edit).slideToggle(100);
  233. $(just_edit).slideToggle(1);
  234. my_rank = get_rank(this);
  235. cancel_update(my_rank,this);
  236. });
  237. //Make my clone
  238. function make_my_clone(){
  239. my_type = $this.Global_tm.final_settings.hunt_type['type'];
  240. switch(my_type)
  241. {
  242. case 'text':
  243. my_clone = $this.Global_tm.final_settings.hunt_type.my_clone.attr({
  244. placeholder:$this.Global_tm.final_settings['placeholder'],
  245. value:$this.Global_tm.final_settings['val']
  246. }).data('validate',$this.Global_tm.final_settings['validate']);
  247. final_val = $this.Global_tm.final_settings.val == '' ? 'N/A' : $this.Global_tm.final_settings.val;
  248. selected_val = '';
  249. break;
  250. case 'select':
  251. my_clone = $this.Global_tm.final_settings.hunt_type.my_clone;
  252. final_val = $this.Global_tm.final_settings.hunt_type['my_text'];
  253. selected_val = $this.Global_tm.final_settings.val;
  254. break;
  255. case 'checkbox_container':
  256. my_clone = $this.Global_tm.final_settings.hunt_type.my_clone;
  257. final_val = $this.Global_tm.final_settings.hunt_type['my_text'];
  258. selected_val = $this.Global_tm.final_settings.hunt_type['value'];
  259. break;
  260. case 'checkbox':
  261. my_clone = $this.Global_tm.final_settings.hunt_type.my_clone;
  262. label = my_clone.find('label').text();
  263. final_val = '<label>'+label+'</label> : '+$this.Global_tm.final_settings.hunt_type['my_text'];
  264. selected_val = $this.Global_tm.final_settings.val;
  265. break;
  266. case 'radio':
  267. my_clone = $this.Global_tm.final_settings.hunt_type.my_clone;
  268. final_val = $this.Global_tm.final_settings.hunt_type['my_text'];
  269. selected_val = $this.Global_tm.final_settings.val;
  270. break;
  271. case 'textarea':
  272. my_clone = $this.Global_tm.final_settings.hunt_type.my_clone.attr({
  273. placeholder:$this.Global_tm.final_settings['placeholder'],
  274. value:$this.Global_tm.final_settings['val']
  275. }).data('validate',$this.Global_tm.final_settings['validate']);
  276. final_val = $this.Global_tm.final_settings.val == '' ? 'N/A' : $this.Global_tm.final_settings.val;
  277. selected_val = '';
  278. break;
  279. }
  280. return {
  281. my_clone:my_clone,
  282. final_val:final_val,
  283. selected_val:selected_val
  284. };
  285. }
  286. function set_width(){
  287. rank = Global_tm_array.length;
  288. theme_class = '.'+$this.Global_tm.final_settings.theme;
  289. $tm_selector = $('.tm_editable_container[my_rank="'+rank+'"]');
  290. $btn_container = $tm_selector.find('.ibtn_container');
  291. eve_width = $(no_edit).width();
  292. //if fulllength is true on outsides
  293. if($this.Global_tm.final_settings.full_length.outside){
  294. if($this.Global_tm.final_settings.outside_btn.new_line){
  295. outside_btn_width = 0;
  296. }
  297. else{
  298. if($this.Global_tm.final_settings.remover)
  299. outside_btn_width = $(edit_btn).outerWidth() + realWidth($(edit_btn).find('.i_edit_text'), theme_class) + 15 + realWidth($(remover_btn), theme_class);
  300. else
  301. outside_btn_width = $(edit_btn).outerWidth() + realWidth($(edit_btn).find('.i_edit_text'), theme_class) + 5;
  302. }
  303. $(input_field).css('width',eve_width - outside_btn_width);
  304. }
  305. else{
  306. $(no_edit).css('width','auto');
  307. $(input_field).css('width','auto');
  308. }
  309. //if fulllength is true on inside
  310. if($this.Global_tm.final_settings.full_length.inside){
  311. if($this.Global_tm.final_settings.inside_btn.new_line){
  312. inside_btn_width = 0;
  313. }
  314. else{
  315. inside_btn_width = realWidth($btn_container, theme_class) +5;
  316. }
  317. $(template_input).css('width',eve_width - inside_btn_width);
  318. }
  319. else{
  320. $(template_input).css('width','auto');
  321. }
  322. }
  323. set_width();
  324. //Before Init
  325. $this.Global_tm.final_settings.init.after();
  326. }
  327. Global_tm_array.push($this);
  328. //Init method END
  329. //Find Input Type
  330. function hunt_type(){
  331. if($this.children('input[type="text"]').length || $this.children('input[type="number"]').length || $this.children('input[type="email"]').length || $this.children('input[type="password"]').length)
  332. {
  333. my_type = 'text';
  334. my_clone = $this.children('input').clone(true);
  335. my_val = my_clone.val().trim();
  336. my_text = my_val;
  337. }
  338. else if($this.children('select').length)
  339. {
  340. my_type = 'select';
  341. my_clone = $this.children('select').clone(true);
  342. my_val = $this.find("option:selected").val();
  343. my_text = $this.find("option:selected").text();
  344. }
  345. else if($this.children('.checkbox_container').length)
  346. {
  347. my_type = 'checkbox_container';
  348. my_clone = $this.children('.checkbox_container').clone(true);
  349. my_val_array = [];
  350. my_text_array = [];
  351. my_clone.find('.single_checkbox').each(function(k2,v2){
  352. //alert($(v2).find('input').length);
  353. if($(v2).find('input:checked').length)
  354. {
  355. val1 = $(v2).find('input:checked').attr('value');
  356. text1 = $(v2).find('label').text().trim();
  357. my_val_array.push(val1);
  358. my_text_array.push(text1);
  359. }
  360. });
  361. my_val = my_val_array.join(',');
  362. my_text = my_text_array.join(', ');
  363. }
  364. else if($this.children('.single_checkbox').length)
  365. {
  366. my_type = 'checkbox';
  367. my_clone = $this.children('.single_checkbox').clone(true);
  368. my_val = $this.find("input[type='checkbox']").is(':checked');
  369. if(my_val)
  370. my_text = 'Yes'
  371. else
  372. my_text = 'No'
  373. }
  374. else if($this.children('.radio_container').length)
  375. {
  376. my_type = 'radio';
  377. my_clone = $this.children('.radio_container').clone(true);
  378. $this.find("input[type='radio']:checked").each(function(){
  379. my_val = $(this).val();
  380. current_id = $(this).attr('id');
  381. my_text = $("label[for='"+current_id+"']").text().trim();
  382. });
  383. }
  384. else if($this.children('textarea').length)
  385. {
  386. my_type = 'textarea';
  387. my_clone = $this.children('textarea').clone(true);
  388. my_val = my_clone.text().trim();
  389. my_text = my_val;
  390. }
  391. return {type:my_type,
  392. value:my_val,
  393. my_clone:my_clone,
  394. my_text:my_text};
  395. }
  396. });
  397. };
  398. //Other FUNCTIONS witch are binds with events
  399. //Remover
  400. function remover(eve){
  401. var r = confirm('Wanna Delete this ?');
  402. if(r)
  403. {
  404. my_rank = get_rank(eve);
  405. //$(i_loading).fadeIn('fast');
  406. var promise = Global_tm_array[my_rank].Global_tm.final_settings.remove.before();
  407. promise.done(function() {
  408. $(eve).closest(Global_tm_array[my_rank].Global_tm.final_settings.remover_class).remove();
  409. //$(i_loading).fadeOut('slow');
  410. Global_tm_array[my_rank].Global_tm.final_settings.remove.after();
  411. });
  412. }
  413. }
  414. //After Ok
  415. function after_ok(rank){
  416. $tm_selector = $('.tm_editable_container[my_rank="'+rank+'"]');
  417. get_id = $tm_selector.attr('id');
  418. type = Global_tm_array[rank].Global_tm.final_settings.hunt_type['type'];
  419. $i_loading = $tm_selector.find('.i_loading');
  420. $no_edit = $tm_selector.find('.no_edit');
  421. $just_edit = $tm_selector.find('.just_edit');
  422. $tm_container = $('#'+get_id);
  423. flag_val = validate('#'+get_id);
  424. //check validation
  425. if(flag_val)
  426. {
  427. var values = get_the_values(rank);
  428. new_val_flag = values.real_value != values.shown_val ? true:false;
  429. //check old val
  430. if(new_val_flag)
  431. {
  432. $i_loading.fadeIn('fast');
  433. var promise = Global_tm_array[rank].Global_tm.final_settings.ok.before(real_val);
  434. promise.done(function() {
  435. update_it(rank,type,real_val);
  436. $i_loading.fadeOut('slow');
  437. });
  438. }
  439. else
  440. {
  441. $just_edit.slideToggle(1);
  442. $no_edit.slideToggle(100);
  443. setTimeout(function(){
  444. Global_tm_array[rank].Global_tm.final_settings.ok.after(real_val);
  445. },100);
  446. }
  447. }
  448. }
  449. //Update It
  450. function update_it(rank,type,real_val){
  451. $tm_selector = $('.tm_editable_container[my_rank="'+rank+'"]');
  452. $input_field = $tm_selector.find('.i_text');
  453. $i_loading = $tm_selector.find('.i_loading');
  454. $no_edit = $tm_selector.find('.no_edit');
  455. $just_edit = $tm_selector.find('.just_edit');
  456. switch(type)
  457. {
  458. case 'text':
  459. //if null value
  460. if(real_val == '')
  461. {
  462. real_val = 'N/A';
  463. }
  464. $input_field.text(real_val);
  465. break;
  466. case 'select':
  467. my_text = $tm_selector.find("option:selected").text();
  468. $input_field.text(my_text).attr('selected_val',real_val);
  469. break;
  470. case 'radio':
  471. $tm_selector.find("input[type='radio']:checked").each(function(){
  472. my_val = $(this).val();
  473. current_id = $(this).attr('id');
  474. my_text = $("label[for='"+current_id+"']").text().trim();
  475. })
  476. $input_field.text(my_text).attr('selected_val',real_val);
  477. break;
  478. case 'checkbox':
  479. $tm_selector.find("input[type='checkbox']").each(function(){
  480. my_val = $(this).is(':checked');
  481. my_show_val = my_val ? 'Yes':'No';
  482. current_id = $(this).attr('id');
  483. my_text = $("label[for='"+current_id+"']").text().trim();
  484. my_text = '<label>'+my_text+'</label> : '+my_show_val;
  485. })
  486. $input_field.html(my_text).attr('selected_val',real_val);
  487. break;
  488. case 'textarea':
  489. //if null value
  490. if(real_val == '')
  491. {
  492. real_val = 'N/A';
  493. }
  494. $input_field.text(real_val);
  495. break;
  496. }
  497. $just_edit.slideToggle(1);
  498. $no_edit.slideToggle(100);
  499. setTimeout(function(){
  500. Global_tm_array[rank].Global_tm.final_settings.ok.after();
  501. },100);
  502. }
  503. //cancel_update
  504. function cancel_update(rank,eve){
  505. $tm_selector = $('.tm_editable_container[my_rank="'+rank+'"]');
  506. type = Global_tm_array[rank].Global_tm.final_settings.hunt_type['type'];
  507. var values = get_the_values(rank);
  508. shown_value = values.shown_value;
  509. switch(type)
  510. {
  511. case 'text':
  512. $tm_selector.find('input').val(shown_value);
  513. break;
  514. case 'select':
  515. $tm_selector.find("select").val(shown_value);
  516. break;
  517. case 'radio':
  518. $tm_selector.find("input[type='radio'][value='"+shown_value+"']").prop('checked',true);
  519. break;
  520. case 'checkbox':
  521. if(shown_value == true || shown_value == 'true')
  522. $tm_selector.find("input[type='checkbox']").prop('checked',true);
  523. else
  524. $tm_selector.find("input[type='checkbox']").prop('checked',false);
  525. break;
  526. case 'textarea':
  527. $tm_selector.find('textarea').val(shown_value);
  528. break;
  529. }
  530. }
  531. //Get Rank
  532. function get_rank(eve)
  533. {
  534. return $(eve).closest('.has_tm_editable_container').attr('my_rank');
  535. }
  536. function realWidth(obj,container){
  537. var clone = obj.clone();
  538. clone.css("visibility","hidden");
  539. $('body '+container+':first').append(clone);
  540. var width = clone.outerWidth();
  541. clone.remove();
  542. return width;
  543. }
  544. function get_the_values(rank){
  545. $this = $('.tm_editable_container[my_rank="'+rank+'"]');
  546. type = Global_tm_array[rank].Global_tm.final_settings.hunt_type['type'];
  547. switch(type)
  548. {
  549. case 'text':
  550. real_val = $this.find('input').val().trim();
  551. shown_val = $this.find('.i_text').text().trim();
  552. break;
  553. case 'textarea':
  554. real_val = $this.find('textarea').val().trim();
  555. shown_val = $this.find('.i_text').text().trim();
  556. break;
  557. case 'select':
  558. real_val = $this.find('option:selected').val().trim();
  559. shown_val = $this.find('.i_text').attr('selected_val').trim();
  560. break;
  561. case 'radio':
  562. real_val = $this.find('input[type="radio"]:checked').val();
  563. shown_val = $this.find('.i_text').attr('selected_val').trim();
  564. break;
  565. case 'checkbox':
  566. real_val = $this.find('input[type="checkbox"]').is(':checked');
  567. shown_val = $this.find('.i_text').attr('selected_val').trim();
  568. break;
  569. }
  570. return {real_value:real_val,
  571. shown_value:shown_val};
  572. }
  573. }( jQuery ));