browser/devtools/styleeditor/utils.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/devtools/styleeditor/utils.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,40 @@
     1.4 +/* -*- Mode: Javascript; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
     1.5 +/* vim: set ft=javascript ts=2 et sw=2 tw=80: */
     1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.9 +
    1.10 +const {Cc, Ci, Cu, Cr} = require("chrome");
    1.11 +
    1.12 +Cu.import("resource://gre/modules/Services.jsm");
    1.13 +Cu.import("resource://gre/modules/devtools/event-emitter.js");
    1.14 +
    1.15 +exports.PREF_ORIG_SOURCES = "devtools.styleeditor.source-maps-enabled";
    1.16 +
    1.17 +/**
    1.18 + * A PreferenceObserver observes a pref branch for pref changes.
    1.19 + * It emits an event for each preference change.
    1.20 + */
    1.21 +function PrefObserver(branchName) {
    1.22 +  this.branchName = branchName;
    1.23 +  this.branch = Services.prefs.getBranch(branchName);
    1.24 +  this.branch.addObserver("", this, false);
    1.25 +
    1.26 +  EventEmitter.decorate(this);
    1.27 +}
    1.28 +
    1.29 +exports.PrefObserver = PrefObserver;
    1.30 +
    1.31 +PrefObserver.prototype = {
    1.32 +  observe: function(subject, topic, data) {
    1.33 +    if (topic == "nsPref:changed") {
    1.34 +      this.emit(this.branchName + data);
    1.35 +    }
    1.36 +  },
    1.37 +
    1.38 +  destroy: function() {
    1.39 +    if (this.branch) {
    1.40 +      this.branch.removeObserver('', this);
    1.41 +    }
    1.42 +  }
    1.43 +};
    1.44 \ No newline at end of file

mercurial