Advertisement
Guest User

main.js

a guest
Jul 23rd, 2014
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*  
  2.     Your Project Title
  3.     Author: You
  4. */
  5.  
  6. (function($){
  7.  
  8.  
  9.     /*
  10.     ===============================================
  11.     ========================= APPLICATION FUNCTIONS
  12.     */
  13.    
  14.    
  15.     var checkLoginState = function(){
  16.         $.ajax({
  17.             url: 'xhr/check_login.php',
  18.             type: 'get',
  19.             dataType: 'json',
  20.             success: function(response){
  21.                 // if user, loadApp()
  22.                 // if error, loadLanding()
  23.             }
  24.         });
  25.     };
  26.    
  27.    
  28.  
  29.     //  ============================================
  30.     //  SETUP FOR INIT
  31.        
  32.     var init = function(){
  33.    
  34.         checkLoginState();
  35.     };
  36.    
  37.    
  38.     init();
  39.    
  40.        
  41.     /*
  42.     ===============================================
  43.     ======================================== MODALS
  44.     */
  45.     $("#registerBtn").click(function(){
  46.         $("#overlay").fadeIn({queue: false, duration: 500});
  47.         $("#registerModal").fadeIn({queue: false, duration: 500});
  48.         $("#registerModal").animate({'top': '20px'}, 500);
  49.         return false;
  50.     });
  51.  
  52.     $("#newProject").click(function() {
  53.         $("#overlay").fadeIn({queue: false, duration: 500});
  54.         $("#newProjectModal").fadeIn({queue: false, duration: 500});
  55.         $("#newProjectModal").animate({'top': '20px'}, 500);
  56.         return false;
  57.     });
  58.  
  59.     $(".close").click(function(){
  60.         $("#overlay").fadeOut({queue: false, duration: 500});
  61.  
  62.         if($("#registerModal")){
  63.             $('#registerModal').fadeOut({queue: false, duration: 350});
  64.             $("#registerModal").animate({'top': '-575px'}, 500);
  65.         }
  66.  
  67.         if($("#newProjectModal")){
  68.             $('#newProjectModal').fadeOut({queue: false, duration: 350});
  69.             $("#newProjectModal").animate({'top': '-575px'}, 500);
  70.  
  71.             populateModal();
  72.         }
  73.     });
  74.  
  75.  
  76.     /*
  77.     ===============================================
  78.     ========================================== TABS
  79.     */
  80.     $("#dashboardContentArea .wrapper:not(:nth-child(1))").hide();
  81.  
  82.     $("#menubar li").click(function(e) {
  83.         e.preventDefault();
  84.         $("#dashboardContentArea .wrapper").hide();
  85.  
  86.         $("#menubar .active").removeClass("active");
  87.         $(this).addClass("active");
  88.         var clicked = $(this).find("a:first").attr("href");
  89.  
  90.         $(clicked).fadeIn("fast");
  91.     }).eq(0).addClass("active");
  92.  
  93.     /*
  94.     ===============================================
  95.     ======================================= TOOLTIP
  96.     */
  97.     $(".masterTooltip").hover(function(){
  98.         //Hover over code
  99.         var title = $(this).attr("title");
  100.         $(this).data("tipText", title).removeAttr("title");
  101.  
  102.         $("<p class=\"tooltip\"></p>")
  103.             .text(title)
  104.             .insertAfter($(this))
  105.             .fadeIn("slow");
  106.  
  107.         $(".tooltip").css({
  108.             top: $(this).height() / 2 - $(".tooltip").height() / 2 + $(this).position().top,
  109.             left: $(this).width() + 30,
  110.             zIndex: 115
  111.         });
  112.     }, function() {
  113.         // Hover out code
  114.         $(this).attr("title", $(this).data("tipText"));
  115.         $(".tooltip").remove();
  116.     });
  117.  
  118.  
  119.     $(".loginTooltip").focus(function(){
  120.         //Hover over code
  121.         var title = $(this).attr("title");
  122.         $(this).data("tipText", title).removeAttr("title");
  123.  
  124.         $("<p class=\"userpassTooltip\"></p>")
  125.             .text(title)
  126.             .insertAfter($(this))
  127.             .fadeIn("slow");
  128.  
  129.         $(".userpassTooltip").css({
  130.             top: $(".loginTooltip").height() + 15,
  131.             left: ($(".loginTooltip").width() - $(".userpassTooltip").width()) / 2 + $(this).position().left
  132.         });
  133.     });
  134.  
  135.     $(document).ready(function() {
  136.         $(".loginTooltip").focusout(function() {
  137.             $(this).attr("title", $(this).data("tipText"));
  138.             $(".userpassTooltip").remove();
  139.         });
  140.     });
  141.     /*
  142.     ===============================================
  143.     ====================================== DROPDOWN
  144.     */
  145.  
  146.  
  147.  
  148.     function DropDown(el) {
  149.         this.dd = el;
  150.         this.placeholder = this.dd.children('span');
  151.         this.opts = this.dd.find('ul.dropdown > li');
  152.         this.val = '';
  153.         this.index = -1;
  154.         this.initEvents();
  155.     }
  156.  
  157.     DropDown.prototype = {
  158.         initEvents : function() {
  159.             var obj = this;
  160.  
  161.             obj.dd.on('click', function(event){
  162.                 $(this).toggleClass('active');
  163.                 return false;
  164.             });
  165.  
  166.             obj.opts.on('click',function(){
  167.                 var opt = $(this);
  168.                 obj.val = opt.text();
  169.                 obj.index = opt.index();
  170.                 obj.placeholder.text(obj.val);
  171.  
  172.                 $("#productName").val(obj.val.toString());
  173.                 $("#productNamePreview").html($("#productName").val());
  174.                 $(".wrapper-dropdown span").css({
  175.                     color: "#444",
  176.                     fontStyle: "normal",
  177.                     fontWeight: 500
  178.                 });
  179.             });
  180.         },
  181.         getValue : function() {
  182.             return this.val;
  183.         },
  184.         getIndex : function() {
  185.             return this.index;
  186.         }
  187.     };
  188.  
  189.     $(function() {
  190.  
  191.         var dd = new DropDown( $('#dd') );
  192.  
  193.         $(document).click(function() {
  194.             // all dropdowns
  195.             $('.wrapper-dropdown').removeClass('active');
  196.         });
  197.  
  198.     });
  199.  
  200.  
  201.     /*
  202.     ===============================================
  203.     =============================== PROJECT PREVIEW
  204.     */
  205.     $("#projectName").on("input", function(){
  206.         $("#projectNamePreview").html($("#projectName").val());
  207.     });
  208.  
  209.  
  210.     $("#description").on("input", function(){
  211.         var text = $("#description").val();
  212.         text = text.replace(/\r?\n/g, '<br />');
  213.         $("#descriptionContent").html(text);
  214.     });
  215.  
  216.     $("#deadline").on("input", function(){
  217.         $("#deadlinePreview").html($("#deadline").val());
  218.     });
  219.  
  220.     $("#budget").on("input", function(){
  221.         $("#budgetPreview").html($("#budget").val());
  222.     });
  223.  
  224.     $("#statusPreview").html($("input:radio[name=status]:checked").val());
  225.     setUrgencyColor();
  226.  
  227.     $("input:radio[name=status]").click(function () {
  228.         $("#statusPreview").html($("input:radio[name=status]:checked").val());
  229.         setUrgencyColor();
  230.     });
  231.  
  232.     var months = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
  233.     var date = new Date();
  234.     $("#datePreview").html(months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear());
  235.  
  236.  
  237.     function populateModal() {
  238.         $("#projectNamePreview").html($("#projectName").val());
  239.         var description = $("#description").val();
  240.         description = description.replace(/\r?\n/g, '<br />');
  241.         $("#descriptionContent").html(description);
  242.         $("#deadlinePreview").html($("#deadline").val());
  243.         $("#budgetPreview").html($("#budget").val());
  244.         $("#datePreview").html(months[date.getMonth()] + " " + date.getDate() + ", " + date.getFullYear());
  245.         $("#statusPreview").html($("input:radio[name=status]:checked").val());
  246.         setUrgencyColor();
  247.     }
  248.  
  249.     function setUrgencyColor() {
  250.         if($("input:radio[name=status]:checked").val() == "Normal") {
  251.             $("#urgency").css({
  252.                 color: "#11b945"
  253.             });
  254.         }else{
  255.             $("#urgency").css({
  256.                 color: "#b92511"
  257.             });
  258.         }
  259.     }
  260.  
  261.     /*
  262.     =====================================
  263.     =============================== LOGIN
  264.     */
  265.  
  266.     $("#signinButton").click(function(e){
  267.         e.preventDefault(true);
  268.         var user = $("#user").val();
  269.         var pass = $("#pass").val();
  270.         console.log("Password working!");
  271.  
  272.         $.ajax({
  273.             url: "xhr/login.php",
  274.             type: "post",
  275.             dataType: "json",
  276.             data: {
  277.                 username: user,
  278.                 password: pass
  279.             },
  280.             success: function(response){
  281.                 console.log("Test User");
  282.                 if(response.error){
  283.                     alert(response.error);
  284.                 }else{
  285.                     window.location.assign("dashboard.html");
  286.                 }
  287.             }
  288.         });
  289.  
  290.         /*
  291.         ======================================
  292.         =============================== LOGOUT
  293.         */
  294.         $("#logOut").click(function(e){
  295.             e.preventDefault(true);
  296.             $.get("xhr/logout.php", function(){
  297.                 window.location.assign("index.html")
  298.             });
  299.         });
  300.  
  301.  
  302.         /*
  303.         ========================================
  304.         =============================== REGISTER
  305.         */
  306.         $(document).ready(function(){
  307.             $("#register").on("click", function(e){
  308.                 e.preventDefault();
  309.                 alert("Hello!");
  310.             });
  311.         });
  312.  
  313.  
  314.     });
  315.  
  316. })(jQuery); // end private scope
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement