How to use the ko.observable function in ko

To help you get started, we’ve selected a few ko examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github berrberr / streamkeys / code / js / popup / popup.js View on Github external
var PopupViewModel = function PopupViewModel() {
  var self = this;

  self.totalMusicTabs = ko.observable(1);
  self.musicTabsLoaded = ko.observable(0);
  self.musicTabs = ko.observableArray([]);

  // Tabs from disabled music sites to show in disabled list toggle
  self.disabledMusicTabs = ko.observableArray([]);
  self.disabledSitesOpen = ko.observable(false);

  // Filter hidden players and sort by priority -> siteName -> tabId
  self.sortedMusicTabs = ko.pureComputed(function() {
    var filteredGrouped = _.groupBy(
      _.filter(self.musicTabs(), function(tab) {
        return (tab.canPlayPause() || !tab.hidePlayer);
      }),
      function(tab) { return tab.priority(); }
    );
github BladeRunnerJS / brjs / brjs-sdk / apps / it-app / itbladeset-bladeset / blades / keybinds / src / KeybindsViewModel.js View on Github external
function KeybindsViewModel() {
	this.keyBindMessage = ko.observable('Press Shift+V to switch vegetables: ');
	this.keyBoundVegetable = ko.observable('Carrot');
	
	var self = this;
	keybindingService.registerAction('itapp.a-key-binding', function() {
			self.switchVeg();
		});

	keybindingService.bindAction('itapp.a-key-binding', 'shift+v');
}
github berrberr / streamkeys / code / js / popup / popup.js View on Github external
_.assign(this, attributes);

    /** Override observables **/
    _.forEach(this.observableProperties, (function(property) {
      this[property] = ko.observable(typeof attributes[property] !== "undefined" ? attributes[property] : null);
    }).bind(this));

    /** Popup specific observables **/
    this.songArtistText = ko.pureComputed(function() {
      if(!this.song()) return "";

      return (this.artist()) ? this.artist() + " - " + this.song() : this.song();
    }, this);

    this.settingsOpen = ko.observable(false);

    this.priority.subscribe(function(priority) {
      chrome.runtime.sendMessage({
        action: "update_site_settings",
        siteKey: self.siteKey,
        siteState: {
          priority: priority
        }
      });
    });

    this.sendAction = function(action) {
      chrome.runtime.sendMessage({
        action: "command",
        command: action,
        tab_target: this.tabId
github berrberr / streamkeys / code / js / options.js View on Github external
chrome.storage.sync.get(function(obj) {
    self.openOnUpdate = ko.observable(obj["hotkey-open_on_update"]);
    self.openOnUpdate.subscribe(function(value) {
      chrome.storage.sync.set({ "hotkey-open_on_update": value });
    });

    self.useMPRIS = ko.observable(obj["hotkey-use_mpris"]);
    self.useMPRIS.subscribe(function(value) {
      if (value) {
        chrome.permissions.contains({
          permissions: ["nativeMessaging"],
        }, function (alreadyHaveNativeMessagingPermissions) {
          if (alreadyHaveNativeMessagingPermissions) {
            chrome.storage.sync.set({ "hotkey-use_mpris": value });
          }
          else {
            chrome.permissions.request({
            permissions: ["nativeMessaging"],
            }, function (granted) {
                chrome.storage.sync.set({ "hotkey-use_mpris": granted });
            });
          }
        });
github berrberr / streamkeys / code / js / options.js View on Github external
function MusicSite(attributes) {
    var self = this;

    self.id = attributes.id;
    self.sanitizedId = attributes.id.replace(/[\.,"']/g, "");
    self.name = attributes.name;
    self.enabled = ko.observable(attributes.enabled);
    self.priority = ko.observable(attributes.priority);
    self.alias = ko.observableArray(attributes.alias || []);
    self.showNotifications = ko.observable(attributes.showNotifications);
    self.removedAlias = [];
    self.aliasText = ko.observable("");

    self.toggleSite = function() {
      self.enabled(!self.enabled.peek());
    };

    self.toggleNotifications = function() {
      var internalToggleNotifications = function() {
        self.showNotifications(!self.showNotifications.peek());
      };

      chrome.permissions.contains({
        permissions: ["notifications"],
github berrberr / streamkeys / code / js / options.js View on Github external
function MusicSite(attributes) {
    var self = this;

    self.id = attributes.id;
    self.sanitizedId = attributes.id.replace(/[\.,"']/g, "");
    self.name = attributes.name;
    self.enabled = ko.observable(attributes.enabled);
    self.priority = ko.observable(attributes.priority);
    self.alias = ko.observableArray(attributes.alias || []);
    self.showNotifications = ko.observable(attributes.showNotifications);
    self.removedAlias = [];
    self.aliasText = ko.observable("");

    self.toggleSite = function() {
      self.enabled(!self.enabled.peek());
    };

    self.toggleNotifications = function() {
      var internalToggleNotifications = function() {
        self.showNotifications(!self.showNotifications.peek());
      };

      chrome.permissions.contains({
github berrberr / streamkeys / code / js / options.js View on Github external
}, function (granted) {
                chrome.storage.sync.set({ "hotkey-use_mpris": granted });
            });
          }
        });
      } else {
        chrome.storage.sync.set({ "hotkey-use_mpris": value });
      }
    });

    self.youtubeRestart = ko.observable(obj["hotkey-youtube_restart"]);
    self.youtubeRestart.subscribe(function(value) {
      chrome.storage.sync.set({ "hotkey-youtube_restart": value });
    });

    self.singlePlayerMode = ko.observable(obj["hotkey-single_player_mode"]);
    self.singlePlayerMode.subscribe(function(value) {
      chrome.storage.sync.set({ "hotkey-single_player_mode": value });
      if (!value) self.useMPRIS(false);
    });

    self.settingsInitialized(true);
  });
github berrberr / streamkeys / code / js / options.js View on Github external
chrome.storage.sync.set({ "hotkey-use_mpris": value });
          }
          else {
            chrome.permissions.request({
            permissions: ["nativeMessaging"],
            }, function (granted) {
                chrome.storage.sync.set({ "hotkey-use_mpris": granted });
            });
          }
        });
      } else {
        chrome.storage.sync.set({ "hotkey-use_mpris": value });
      }
    });

    self.youtubeRestart = ko.observable(obj["hotkey-youtube_restart"]);
    self.youtubeRestart.subscribe(function(value) {
      chrome.storage.sync.set({ "hotkey-youtube_restart": value });
    });

    self.singlePlayerMode = ko.observable(obj["hotkey-single_player_mode"]);
    self.singlePlayerMode.subscribe(function(value) {
      chrome.storage.sync.set({ "hotkey-single_player_mode": value });
      if (!value) self.useMPRIS(false);
    });

    self.settingsInitialized(true);
  });
github berrberr / streamkeys / code / js / popup / popup.js View on Github external
_.forEach(this.observableProperties, (function(property) {
      this[property] = ko.observable(typeof attributes[property] !== "undefined" ? attributes[property] : null);
    }).bind(this));
github berrberr / streamkeys / code / js / options.js View on Github external
function MusicSite(attributes) {
    var self = this;

    self.id = attributes.id;
    self.sanitizedId = attributes.id.replace(/[\.,"']/g, "");
    self.name = attributes.name;
    self.enabled = ko.observable(attributes.enabled);
    self.priority = ko.observable(attributes.priority);
    self.alias = ko.observableArray(attributes.alias || []);
    self.showNotifications = ko.observable(attributes.showNotifications);
    self.removedAlias = [];
    self.aliasText = ko.observable("");

    self.toggleSite = function() {
      self.enabled(!self.enabled.peek());
    };

    self.toggleNotifications = function() {
      var internalToggleNotifications = function() {
        self.showNotifications(!self.showNotifications.peek());
      };

      chrome.permissions.contains({
        permissions: ["notifications"],
        origins: ["http://*/*", "https://*/*"]
      }, function (alreadyHaveNotificationsPermissions) {
        if (alreadyHaveNotificationsPermissions) {
          internalToggleNotifications();