PageRenderTime 23ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/js/helpers/helpers.js

https://github.com/mydesignivan/guerraguerrero
JavaScript | 165 lines | 143 code | 22 blank | 0 comment | 46 complexity | 5aaa3effe28abdf1118f80718fb75e9c MD5 | raw file
  1. jQuery.fn.extend({
  2. ucFirst : function(){
  3. return this.each(function(){
  4. if( this.value ){
  5. this.value = this.value.substr(0,1).toUpperCase()+this.value.substr(1,this.value.length).toLowerCase();
  6. }
  7. });
  8. },
  9. ucTitle : function(){
  10. return this.each(function(){
  11. if( this.value ){
  12. if( this.value.length>0 ){
  13. var arr = this.value.split(" ");
  14. var t = this;
  15. this.value="";
  16. $(arr).each(function(){
  17. t.value+= this.substr(0,1).toUpperCase()+this.substr(1,this.length).toLowerCase()+" ";
  18. });
  19. t.value = t.value.substr(0, t.value.length-1);
  20. }
  21. }
  22. });
  23. },
  24. ucLower : function(){
  25. return this.each(function(){
  26. if( this.value ){
  27. this.value = this.value.toLowerCase();
  28. }
  29. });
  30. },
  31. ucUpper : function(){
  32. return this.each(function(){
  33. if( this.value ){
  34. this.value = this.value.toUpperCase();
  35. }
  36. });
  37. },
  38. convertDate : function(){
  39. return this.each(function(){
  40. if( this.value ){
  41. this.value = this.value.replace(/^(\d{2})\/(\d{2})\/(\d{4})$/, "$2/$1/$3");
  42. }
  43. });
  44. },
  45. formatURL : function(){
  46. return this.each(function(){
  47. if( this.value ){
  48. this.value = this.value.toLowerCase();
  49. if( this.value.substr(0,7)!="http://" ){
  50. this.value = "http://"+this.value.toLowerCase();
  51. }
  52. }
  53. });
  54. },
  55. setOptionOther : function(){
  56. return this.each(function(){
  57. var t = $(this);
  58. if( t.is('select') ){
  59. t.bind('change', function(){
  60. if( this.value.toLowerCase() == "otro" ){
  61. $(this).next('input').fadeIn('slow').focus();
  62. }else{
  63. $(this).next('input').fadeOut('slow').val('');
  64. }
  65. });
  66. }
  67. });
  68. }
  69. });
  70. jQuery.fn.outerHTML = function(s) {
  71. return (s) ? this.before(s).remove() : jQuery("<p>").append(this.eq(0).clone()).html();
  72. };
  73. function MessageShowHide(parent, status, t){
  74. if( status && status!='' ){
  75. if( !t ) t=5000;
  76. if( status!='' ){
  77. var div = $(parent).find(status=="success" ? "div.success" : "div.error");
  78. if( div.is(':visible') ){
  79. setTimeout(function(){
  80. div.slideUp('slow');
  81. }, t);
  82. }else{
  83. div.slideDown('slow', function(){
  84. setTimeout(function(){
  85. div.slideUp('slow');
  86. }, t);
  87. });
  88. }
  89. }
  90. }
  91. }
  92. function openPopup(anchor, options) {
  93. var args = '';
  94. if (typeof(options) == 'undefined') { var options = new Object(); }
  95. if (typeof(options.name) == 'undefined') { options.name = 'win' + Math.round(Math.random()*100000); }
  96. if (typeof(options.height) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
  97. args += "height=" + options.height + ",";
  98. }
  99. if (typeof(options.width) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
  100. args += "width=" + options.width + ",";
  101. }
  102. if (typeof(options.fullscreen) != 'undefined') {
  103. args += "width=" + screen.availWidth + ",";
  104. args += "height=" + screen.availHeight + ",";
  105. }
  106. if (typeof(options.center) == 'undefined') {
  107. options.x = 0;
  108. options.y = 0;
  109. args += "screenx=" + options.x + ",";
  110. args += "screeny=" + options.y + ",";
  111. args += "left=" + options.x + ",";
  112. args += "top=" + options.y + ",";
  113. }
  114. if (typeof(options.center) != 'undefined' && typeof(options.fullscreen) == 'undefined') {
  115. options.y=Math.floor((screen.availHeight-(options.height || screen.height))/2)-(screen.height-screen.availHeight);
  116. options.x=Math.floor((screen.availWidth-(options.width || screen.width))/2)-(screen.width-screen.availWidth);
  117. args += "screenx=" + options.x + ",";
  118. args += "screeny=" + options.y + ",";
  119. args += "left=" + options.x + ",";
  120. args += "top=" + options.y + ",";
  121. }
  122. if (typeof(options.scrollbars) != 'undefined') { args += "scrollbars=1,"; }
  123. if (typeof(options.menubar) != 'undefined') { args += "menubar=1,"; }
  124. if (typeof(options.locationbar) != 'undefined') { args += "location=1,"; }
  125. if (typeof(options.resizable) != 'undefined') { args += "resizable=1,"; }
  126. try{
  127. var win = window.open(anchor, '', args);
  128. }catch(e){
  129. var win = window.open(anchor, options.name, args);
  130. }
  131. return false;
  132. }
  133. function get_data(arr){
  134. var names = [], id = [];
  135. arr.each(function(i){
  136. id.push(this.value);
  137. names.push($(this).parent().parent().find('.link-title').text());
  138. });
  139. return {
  140. id : id,
  141. names : names
  142. }
  143. }