working on it ...

Filters

Explore Public Snippets

Sort by

Found 1,354 snippets matching: toggle

    public by bjf2015  144594  0  3  0

    Alternate toggle solution

    Alternate toggle solution: gistfile1.txt
    $('.shopping-list').find('.shopping-item__checked').closest("li").toggle();
    
    

    public by HeathDernovich  179052  0  4  0

    extend, toggleClass, and equals methods

    extend, toggleClass, and equals methods: objProtaddl.js
    // functional additions to the Object prototype
    
    Object.prototype.extend = function() {
      if (arguments.length === 0)
        return this;
     
      for (var i = 0; i < arguments.length; i++) {
        for (var property in arguments[i]) {
          if (arguments[i].hasOwnProperty(property))
            this[property] = arguments[i][property];
        }
      }
      return this;
    };
    
    
    Object.prototype.equals = function(x) {
      var p;
      for(p in this) {
        if (typeof(x[p]) == "undefined")
          return false;
      }
      
      for(p in this) {
        if (this[p]) {
          switch(typeof(this[p])) {
            case "object":
              if (!this[p].equals(x[p])) {
                return false;
              }
              break;
            case "function":
              if (typeof(x[p]) == "undefined" ||(p != "equals" && this[p].toString() != x[p].toString())) {
                return false;
              }
              break;
            default:
              if (this[p] != x[p]) {
                return false;
              }
          }
        }
        else {
          if (x[p]) {
            return false;
          }
        }
      }
      
      for(p in x) {
        if(typeof(this[p])=="undefined") {
          return false;
        }
      }
      
      return true;
    };
    
    
    Array.prototype.inArray = function (value) {
      for (var i = 0; i < this.length; i++) {
        if (typeof value === "object") {
        
          // If both are objects, uses the equals function
          if (typeof this[i] === "object" && value.equals(this[i])) {
              return i;
          }
        }
        else if (this[i] === value) {
          return i;
        }
      }
      
      return false;
    };
    
    
    function toggleClass(id, className) {
      var element = document.getElementById(id);
      var classes = element.className.split(/s+/);
      var length = classes.length;
      var found = classes.inArray(className);
      
      if (found !== false) {
        classes.splice(found, 1);
      }
        
      // The className is not found
      if (length === classes.length) {
        classes.push(className);
      }
        
      element.className = classes.join(" ");
    };
    
    
    
    

    public by lbottaro  89649  679  8  8

    How to collapse a div in html

    This code shows how to collapse a div using a simple Javascript method. The div display option toggles between 'none' and 'block', hiding or showing its content. In the example you can collapse the div clicking both on a link or on a div, using the onclick event.
    <!doctype html>
    <html>
    	<head>
    		<meta charset="utf-8">
    		<title>Test</title>
    		<script language="javascript"> 
    function toggle(elementId) {
    	var ele = document.getElementById(elementId);
    	if(ele.style.display == "block") {
        		ele.style.display = "none";
      	}
    	else {
    		ele.style.display = "block";
    	}
    } 
    </script>
    	</head>
    	<body>
    <div class="tree">
    <div>
    BLA BLA
    </div>	
    <a id="displayText" href="javascript:toggle('toggleText');">show</a> <== click Here
    <div onclick="javascript:toggle('toggleText');">
    <h1>Hello!</h1>
    <div id="toggleText" style="display:none; border-width:2px; border-style:solid">Hidden data...</div>
    </div>
    <div>
    BLA
    </div>	
    <div>
    BLA BLA 
    </div>	
    <div>
    BLA BLA 123
    </div>
    <a id="displayText" href="javascript:toggle('toggleText2');">show</a> <== click Here
    <div id="toggleText2" style="display: none" href="javascript:toggle();"><h1>Hide!</h1></div>	
    </div></body>
    </html>

    public by sTiLL-iLL @ SniPitz-KND  1746  0  7  18

    da JS shuffle... functional funk.. func.. Func-tion !!!

    inArray and toggle class FO YO PleasURE
    
    // functional gewdiez!
    
    Array.prototype.inArray = function (val) {
      for (var i = 0; i < this.length; i++) {
        if (typeof val === "object") {
          // if both are objkts, use the 'equals
          // function from my other snippet
          if (typeof this[i] === "object" && value.equals(this[i])) {
              return i;
          }}
        else if (this[i] === value) {
          return i;
        }}
      return false;
    };
    
    
    function classToggle(id, clsNam) {
      var el = document.getElementById(id),
          claz = element.clsNam.split(/s+/),
          len = claz.length,
          ob = claz.inArray(clsNam);
      if (ob !== false) {
        claz.splice(ob, 1);
      }
      // class-name is not found
      if (len === claz.length) {
        claz.push(clsNam);
      }
      el.clsNam = claz.join(" ");
    }
    

    public by zonaro  2201  1  6  0

    Toggle Method for Integer and Boolean Types (Extension Method)

    Allow you to use Variable.Toggle() to invert the current value of a Boolean Variable. Also works with Integer type too!
    Public Module Toggles
         
        <Extension()>
        Public Sub Toggle(ByRef Bool As Boolean)
            Bool = Not Bool
        End Sub
        
        <Extension()>
        Public Sub Toggle(ByRef Int As Integer)
            If Int > 0 Then
                Int = 0
            Else
                Int = 1
            End If
        End Sub 
    End Module

    public by boxshadow  1563  0  3  0

    This is an Autohotkey script that toggles between showing and hiding desktop icons in Windows. Website at http://www.toggleiconz.com

    This is an Autohotkey script that toggles between showing and hiding desktop icons in Windows. Website at http://www.toggleiconz.com: toggleiconz.ahk
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;UNLICENSE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ; ToggleIconz is free and unencumbered software hereby released into the public domain on September 12, 2014
    ; by the original developer, Steve Reich`r`n`r`nAnyone is free to copy`, modify`, publish`, use`, compile`, 
    ; sell`, or distribute this software`, either in source code form or as a compiled binary`, for any purpose`, 
    ; commercial or non-commercial`, and by any means.
    ;
    ; In jurisdictions that recognize copyright laws`, the author or authors of this software dedicate any and all
    ; copyright interest in the software to the public domain. We make this dedication for the benefit of the public 
    ; at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of 
    ; relinquishment in perpetuity of all present and future rights to this software under copyright law.
    ;
    ; THE SOFTWARE IS PROVIDED "AS IS"`, WITHOUT WARRANTY OF ANY KIND`, EXPRESS OR IMPLIED`, INCLUDING BUT NOT 
    ; LIMITED TO THE WARRANTIES OF MERCHANTABILITY`, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO 
    ; EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM`, DAMAGES OR OTHER LIABILITY`, WHETHER IN AN ACTION OF 
    ; CONTRACT`, TORT OR OTHERWISE`, ARISING FROM`, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 
    ; OTHER DEALINGS IN THE SOFTWARE`r`n`r`nFor more information`, please refer to http://unlicense.org
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AUTO EXEC SECTION STARTS HERE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;THIS WILL RUN UNTIL A RETUN IN ENCOUNTERED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    
    ; This Keeps a script permanently running (that is, until the user closes it or ExitApp is encountered).
    #Persistent 
    
    ; If the script is already running when a new instance is initialized, this skips the prompt dialog
    ; box and replaces the old instance automatically, which is similar in effect to the Reload command.
    ; This is seamless to the user.
    #SingleInstance force 
    
    ; Give ourselves admin rights
    RunAsAdmin()
    
    ; Set our variables.
    appName = ToggleIconz
    appVersion = v1.0
    appUrl = http://www.toggleiconz.com
    appAuthor = Steve Reich
    originalReleaseDate = September 12, 2014
    
    ; This builds the Gui that is the 'About' popup box. We are only loading it
    ; into memory at this point. We don't open it until the user asks to.
    Gui,  -MinimizeBox -Resize
    Gui, Font, S16 CDefault Bold, Sans-Serif
    Gui, Add, Text, x10 y10 w330 h30 +Center +BackgroundTrans, %appName% %appVersion%
    Gui, Font, S8 Cblue norm, Sans-Serif
    Gui, Add, Text, x5 y35 w340 h15 +Center +BackgroundTrans ggo2homepage, %appUrl%
    Gui, Font, S8 CDefault norm, Sans-Serif
    Gui, Add, Edit, x10 y60 w330 h165 +ReadOnly -Tabstop, %appName% %appVersion% is free and unencumbered software hereby released into the public domain on %originalReleaseDate% by the original developer, %appAuthor%.`r`n`r`nAnyone is free to copy`, modify`, publish`, use`, compile`, sell`, or distribute this software`, either in source code form or as a compiled binary`, for any purpose`, commercial or non-commercial`, and by any means.`r`n`r`nIn jurisdictions that recognize copyright laws`, the author or authors of this software dedicate any and all copyright interest in the software to the public domain. We make this dedication for the benefit of the public at large and to the detriment of our heirs and successors. We intend this dedication to be an overt act of relinquishment in perpetuity of all present and future rights to this software under copyright law.`r`n`r`nTHE SOFTWARE IS PROVIDED "AS IS"`, WITHOUT WARRANTY OF ANY KIND`, EXPRESS OR IMPLIED`, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY`, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM`, DAMAGES OR OTHER LIABILITY`, WHETHER IN AN ACTION OF CONTRACT`, TORT OR OTHERWISE`, ARISING FROM`, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE`r`n`r`nFor more information`, please refer to http://unlicense.org
    Gui, Add, Button, x10 y230 w330 h30 Default gGuiClose, &Close
    
    ; This is the popup menu that is accessible by right clicking on the tray icon
    ; We will initialize it to not include the AutoHotkey standard menu items. We only want ours.
    Menu, tray, NoStandard
    
    ; This is the tray tip that pops up when the user hovers over the tray icon. Let's set it to the appName and current version.
    Menu, tray, tip, %appName% %appVersion%
    
    ; This is the first menu option. It allows the user to check or uncheck the option to run this
    ; program on start up. By default, this is set to true the first time the program is run. When
    ; the user clicks on this menu item, the subroutine startUpReg is fired. We are not setting this 
    ; item to true here. We will determine the value of it after we build this menu and then set the
    ; appropriate state
    Menu, Tray, Add, Run on Startup, startUpReg
    
    ; This adds a seperator line to the menu
    Menu,tray,add
    
    ; This is the 'About...' option. When the user clicks on this menu item, the subroutine aboutHandler is fired.
    Menu,tray,add,About...,aboutHandler
    ; This sets the default action if the user single left clicks on the tray icon
    Menu,tray,Default,About...
    Menu,tray,Click, 1
    
    ; This is the 'Exit...' option. When the user clicks on this menu item, the subroutine exitHandler is fired.
    Menu,tray,add,Exit,exitHandler
    
    ; This is run the first time the user runs the application. This sets the program to run at startup as the 
    ; default. We don't want change everytime the program starts, so if the HKCU\SOFTWARE\%appName%\ExePath 
    ; variable is there and HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Run\%appName%\%A_ScriptFullPath%
    ; is not, we know the user turned it off and no to set it. Otherwise, this is the first run and we will set
    ; it by default.
    RegRead, isFirstTime, HKCU, SOFTWARE\%appName%, ExePath
    if ErrorLevel {
    	RegWrite, REG_SZ, HKCU, SOFTWARE\%appName%, ExePath, %A_ScriptFullPath%
    	RegWrite, REG_SZ, HKCU, SOFTWARE\Microsoft\Windows\CurrentVersion\Run, %appName%, %A_ScriptFullPath%
    	Menu, Tray, Check, Run on Startup
    }
    
    ; Let's check our registry entry to see if the user has changed or reset the value of the
    ; 'Run on Startup' menu option. We read (check) for the registry key. If it is there, the
    ; ErrorLevel will be 0 and we need to put the checkmark in our menue. If it's not there,
    ; the ErrorLevel be 1 and we do nothing. In this case, the user has turned it off.
    RegRead, startUp, HKCU, SOFTWARE\Microsoft\Windows\CurrentVersion\Run, %appName%
    if (ErrorLevel = 0) {
    	Menu, Tray, Check, Run on Startup
    	Send, !z
    }
    
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AUTO EXEC SECTION ENDS HERE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    return
    
    ; Subroutine to toggle setting the registry key to run program at startup. This is fired from the tray menu
    startUpReg:
    	RegRead, startUp, HKCU, SOFTWARE\Microsoft\Windows\CurrentVersion\Run, %appName%
    	if ErrorLevel {
    		RegWrite, REG_SZ, HKCU, SOFTWARE\Microsoft\Windows\CurrentVersion\Run, %appName%, %A_ScriptFullPath%
    		Menu, Tray, Check, %A_ThisMenuItem%
    	}
    	else{
    		RegDelete, HKCU, SOFTWARE\Microsoft\Windows\CurrentVersion\Run, %appName%
    		if ErrorLevel {
    			reload
    		}
    		Menu, Tray, Uncheck, %A_ThisMenuItem%
    	}
    return
    
    ; Subroutine to open default browser and go to the application homepage. This link is in the 'About' box in Gui.
    go2homepage:
    	Run %appUrl%
    	Gui, Cancel
    return
    
    ; This is the Hotkey shortcut (alt+z) that actually does what this program is suppossed to do. It toggles the showing and
    ; hiding of the desktop icons.
    !z::
    	ControlGet, HWND, Hwnd,, SysListView321, ahk_class Progman
    	If HWND =
    		ControlGet, HWND, Hwnd,, SysListView321, ahk_class WorkerW
    	If DllCall("IsWindowVisible", UInt, HWND)
    		WinHide, ahk_id %HWND%
    	Else
    		WinShow, ahk_id %HWND%
    return
    
    
    
    
    ; Function to Run as Admin
    RunAsAdmin() {
      Loop, %0%  ; For each parameter:
        {
          param := %A_Index%  ; Fetch the contents of the variable whose name is contained in A_Index.
          params .= A_Space . param
        }
      ShellExecute := A_IsUnicode ? "shell32\ShellExecute":"shell32\ShellExecuteA"
          
      if not A_IsAdmin
      {
          If A_IsCompiled
             DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_ScriptFullPath, str, params , str, A_WorkingDir, int, 1)
          Else
             DllCall(ShellExecute, uint, 0, str, "RunAs", str, A_AhkPath, str, """" . A_ScriptFullPath . """" . A_Space . params, str, A_WorkingDir, int, 1)
          ExitApp
      }
    }
    
    ; This closes the Gui (About box) when the user clicks the X or the Close button.
    GuiClose:
    	Gui, Cancel
    return
    
    ; This shows the Gui (About box) when the user clicks that menu item in the tray menu
    aboutHandler:
    	Gui, Show, w350 h270, About %appName%
    return
    
    ; This exits the application and is called from the 'Exit' tray menu option
    exitHandler:
    	ControlGet, HWND, Hwnd,, SysListView321, ahk_class Progman
    	If HWND =
    		ControlGet, HWND, Hwnd,, SysListView321, ahk_class WorkerW
    	If NOT DllCall("IsWindowVisible", UInt, HWND)
    		WinShow, ahk_id %HWND%
    	ExitApp
    
    

    public by sTiLL-iLL @ SniPitz-KND  2327  3  7  15

    extend, toggleClass, equals, inArray.... functional javascript prototypes

    // functional additions to the Object prototype
     
    Object.prototype.extend = function() {
      if (arguments.length === 0)
        return this;
     
      for (var i = 0; i < arguments.length; i++) {
        for (var property in arguments[i]) {
          if (arguments[i].hasOwnProperty(property))
            this[property] = arguments[i][property];
        }
      }
      return this;
    };
     
     
    Object.prototype.equals = function(x) {
      var p;
      for(p in this) {
        if (typeof(x[p]) == "undefined")
          return false;
      }
      
      for(p in this) {
        if (this[p]) {
          switch(typeof(this[p])) {
            case "object":
              if (!this[p].equals(x[p])) {
                return false;
              }
              break;
            case "function":
              if (typeof(x[p]) == "undefined" ||(p != "equals" && this[p].toString() != x[p].toString())) {
                return false;
              }
              break;
            default:
              if (this[p] != x[p]) {
                return false;
              }
          }
        }
        else {
          if (x[p]) {
            return false;
          }
        }
      }
      
      for(p in x) {
        if(typeof(this[p])=="undefined") {
          return false;
        }
      }
      
      return true;
    };
     
     
    Array.prototype.inArray = function (value) {
      for (var i = 0; i < this.length; i++) {
        if (typeof value === "object") {
        
          // If both are objects, uses the equals function
          if (typeof this[i] === "object" && value.equals(this[i])) {
              return i;
          }
        }
        else if (this[i] === value) {
          return i;
        }
      }
      
      return false;
    };
     
     
    function toggleClass(id, className) {
      var element = document.getElementById(id);
      var classes = element.className.split(/s+/);
      var length = classes.length;
      var found = classes.inArray(className);
      
      if (found !== false) {
        classes.splice(found, 1);
      }
        
      // The className is not found
      if (length === classes.length) {
        classes.push(className);
      }
        
      element.className = classes.join(" ");
    };

    public by heath D  3005  1  6  8

    extend, toggleClass, and equals methods

    extend, toggleClass, and equals methods: objProtaddl.js
    // functional additions to the Object prototype
    
    Object.prototype.extend = function() {
      if (arguments.length === 0)
        return this;
     
      for (var i = 0; i < arguments.length; i++) {
        for (var property in arguments[i]) {
          if (arguments[i].hasOwnProperty(property))
            this[property] = arguments[i][property];
        }
      }
      return this;
    };
    
    
    Object.prototype.equals = function(x) {
      var p;
      for(p in this) {
        if (typeof(x[p]) == "undefined")
          return false;
      }
      
      for(p in this) {
        if (this[p]) {
          switch(typeof(this[p])) {
            case "object":
              if (!this[p].equals(x[p])) {
                return false;
              }
              break;
            case "function":
              if (typeof(x[p]) == "undefined" ||(p != "equals" && this[p].toString() != x[p].toString())) {
                return false;
              }
              break;
            default:
              if (this[p] != x[p]) {
                return false;
              }
          }
        }
        else {
          if (x[p]) {
            return false;
          }
        }
      }
      
      for(p in x) {
        if(typeof(this[p])=="undefined") {
          return false;
        }
      }
      
      return true;
    };
    
    
    Array.prototype.inArray = function (value) {
      for (var i = 0; i < this.length; i++) {
        if (typeof value === "object") {
        
          // If both are objects, uses the equals function
          if (typeof this[i] === "object" && value.equals(this[i])) {
              return i;
          }
        }
        else if (this[i] === value) {
          return i;
        }
      }
      
      return false;
    };
    
    
    function toggleClass(id, className) {
      var element = document.getElementById(id);
      var classes = element.className.split(/s+/);
      var length = classes.length;
      var found = classes.inArray(className);
      
      if (found !== false) {
        classes.splice(found, 1);
      }
        
      // The className is not found
      if (length === classes.length) {
        classes.push(className);
      }
        
      element.className = classes.join(" ");
    };
    
    
    
    

    public by MorseCode  2048  1  4  0

    MapKit map type three way toggle.

    MapKit map type three way toggle. : ToggleMapType.m
    - (IBAction)toggleMapType:(id)sender
    {
        NSLog(@"toggleMapType");
    
        mapType = (mapType + 1) % 3;
    
        if (mapType == 0) {
            self.dangerMap.mapType = MKMapTypeStandard;
        }
        else if (mapType == 1) {
            self.dangerMap.mapType = MKMapTypeHybrid;
        }
        else if (mapType == 2) {
            self.dangerMap.mapType = MKMapTypeSatellite;
        }
        else
        {
            self.dangerMap.mapType = MKMapTypeStandard;
            mapType = 0;
        }
    
    }
    
    
    

    public by Steve Reich  2073  0  3  0

    This file will enable/disable the Windows built-in administrator account. This account is disabled by default, but is sometimes needed in order to have certain permissions. Be sure you run this file as administrator or assign the appropriate permission...

    This file will enable/disable the Windows built-in administrator account. This account is disabled by default, but is sometimes needed in order to have certain permissions. Be sure you run this file as administrator or assign the appropriate permissions to execute it.: toggleAdministratorAccount.bat
    :: This will enable/disable the Windows built-in administrator account.
    :: Run this file as "Run as administrator", and then at the prompt, enter
    :: one of the following options: y | n | yes | no ... the /i flag makes the
    :: options case insensitive, so either capital or lower case is accepted. 
    :: Enter any other value, or no value at all, will return an error message
    :: and not run the command.
    ECHO OFF
    SETLOCAL
    SET /P doAdmin="Enable Windows built-in administrator account? (y/n) "
    IF /i "%doAdmin%" EQU "n" SET doAdmin=no
    IF /i "%doAdmin%" EQU "y" SET doAdmin=yes
    IF NOT DEFINED doAdmin (
    	ECHO No action was taken. User input is required.
    	PAUSE
    	EXIT
    ) ELSE (
    	IF /i "%doAdmin%" EQU "no" (
    		SET domainLabel=disabled
    		net user administrator /active:%doAdmin%
    		GOTO runAdmin
    	)
    	IF /i "%doAdmin%" EQU "yes" (
    		SET domainLabel=enabled
    		net user administrator /active:%doAdmin%
    		GOTO runAdmin
    	)
    	ECHO No action was taken. "%doAdmin%" is not a valid option.
    	PAUSE
    	EXIT
    )
    :runAdmin
    	ECHO The built in administrator has been %domainLabel%
    	PAUSE
    ENDLOCAL
    EXIT
    
    
    • Public Snippets
    • Channels Snippets