<commit_before>var settings_display = (function () {

var exports = {};

exports.set_night_mode = function (bool) {
    var night_mode = bool;
    var data = { night_mode: JSON.stringify(night_mode) };
    var context = {
        enable_text: data.night_mode === "true" ?
            i18n.t("enabled") :
            i18n.t("disabled"),
    };

    channel.patch({
        url: '/json/settings/display',
        data: data,
        success: function () {
            page_params.night_mode = night_mode;
            if (overlays.settings_open()) {
                ui_report.success(i18n.t("Night mode __enable_text__!", context),
                                  $('#display-settings-status').expectOne());
            }
        },
        error: function (xhr) {
            if (overlays.settings_open()) {
                ui_report.error(i18n.t("Error updating night mode setting."), xhr, $('#display-settings-status').expectOne());
            }
        },
    });
};

exports.set_up = function () {
    $("#display-settings-status").hide();

    $("#user_timezone").val(page_params.timezone);
    $(".emojiset_choice[value=" + page_params.emojiset + "]").prop("checked", true);

    $("#default_language_modal [data-dismiss]").click(function () {
        overlays.close_modal('default_language_modal');
    });

    $("#default_language_modal .language").click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        overlays.close_modal('default_language_modal');

        var data = {};
        var $link = $(e.target).closest("a[data-code]");
        var setting_value = $link.attr('data-code');
        data.default_language = JSON.stringify(setting_value);

        var new_language = $link.attr('data-name');
        $('#default_language_name').text(new_language);

        var context = {};
        context.lang = new_language;

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("__lang__ is now the default language!  You will need to reload the window for your changes to take effect", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating default language setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $('#default_language').on('click', function (e) {
        e.preventDefault();
        e.stopPropagation();
        overlays.open_modal('default_language_modal');
    });

    $("#high_contrast_mode").change(function () {
        var high_contrast_mode = this.checked;
        var data = {};
        data.high_contrast_mode = JSON.stringify(high_contrast_mode);
        var context = {};
        if (data.high_contrast_mode === "true") {
            context.enabled_or_disabled = i18n.t('Enabled');
        } else {
            context.enabled_or_disabled = i18n.t('Disabled');
        }

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("High contrast mode __enabled_or_disabled__!", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating high contrast setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $("#night_mode").change(function () {
        exports.set_night_mode(this.checked);
    });

    $("#left_side_userlist").change(function () {
        var left_side_userlist = this.checked;
        var data = {};
        data.left_side_userlist = JSON.stringify(left_side_userlist);
        var context = {};
        if (data.left_side_userlist === "true") {
            context.side = i18n.t('left');
        } else {
            context.side = i18n.t('right');
        }

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("User list will appear on the __side__ hand side! You will need to reload the window for your changes to take effect.", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating user list placement setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $("#emoji_alt_code").change(function () {
        var emoji_alt_code = this.checked;
        var data = {};
        data.emoji_alt_code = JSON.stringify(emoji_alt_code);
        var context = {};
        if (data.emoji_alt_code === "true") {
            context.text_or_images = i18n.t('text');
        } else {
            context.text_or_images = i18n.t('images');
        }

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("Emoji reactions will appear as __text_or_images__!", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating emoji appearance setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $("#twenty_four_hour_time").change(function () {
        var data = {};
        var setting_value = $("#twenty_four_hour_time").is(":checked");
        data.twenty_four_hour_time = JSON.stringify(setting_value);
        var context = {};
        if (data.twenty_four_hour_time === "true") {
            context.format = '24';
        } else {
            context.format = '12';
        }

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("Time will now be displayed in the __format__-hour format!", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating time format setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $("#user_timezone").change(function () {
        var data = {};
        var timezone = this.value;
        data.timezone = JSON.stringify(timezone);

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("Your time zone have been set to __timezone__", {timezone: timezone}), $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating time zone"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $(".emojiset_choice").click(function () {
        var emojiset = $(this).val();
        var data = {};
        data.emojiset = JSON.stringify(emojiset);

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                var spinner = $("#emojiset_spinner").expectOne();
                loading.make_indicator(spinner, {text: 'Changing emojiset.'});
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error changing emojiset."), xhr, $('#display-settings-status').expectOne());
            },
        });
    });
};

function _update_page() {
    $("#twenty_four_hour_time").prop('checked', page_params.twenty_four_hour_time);
    $("#left_side_userlist").prop('checked', page_params.left_side_userlist);
    $("#emoji_alt_code").prop('checked', page_params.emoji_alt_code);
    $("#default_language_name").text(page_params.default_language_name);
}

exports.update_page = function () {
    i18n.ensure_i18n(_update_page);
};

return exports;
}());

if (typeof module !== 'undefined') {
    module.exports = settings_display;
}
<commit_msg>Make dark theme toggle only run in dev mode.<commit_after>var settings_display = (function () {

var exports = {};

exports.set_night_mode = function (bool) {
    if (!page_params.development) {
        return;
    }

    var night_mode = bool;
    var data = { night_mode: JSON.stringify(night_mode) };
    var context = {
        enable_text: data.night_mode === "true" ?
            i18n.t("enabled") :
            i18n.t("disabled"),
    };

    channel.patch({
        url: '/json/settings/display',
        data: data,
        success: function () {
            page_params.night_mode = night_mode;
            if (overlays.settings_open()) {
                ui_report.success(i18n.t("Night mode __enable_text__!", context),
                                  $('#display-settings-status').expectOne());
            }
        },
        error: function (xhr) {
            if (overlays.settings_open()) {
                ui_report.error(i18n.t("Error updating night mode setting."), xhr, $('#display-settings-status').expectOne());
            }
        },
    });
};

exports.set_up = function () {
    $("#display-settings-status").hide();

    $("#user_timezone").val(page_params.timezone);
    $(".emojiset_choice[value=" + page_params.emojiset + "]").prop("checked", true);

    $("#default_language_modal [data-dismiss]").click(function () {
        overlays.close_modal('default_language_modal');
    });

    $("#default_language_modal .language").click(function (e) {
        e.preventDefault();
        e.stopPropagation();
        overlays.close_modal('default_language_modal');

        var data = {};
        var $link = $(e.target).closest("a[data-code]");
        var setting_value = $link.attr('data-code');
        data.default_language = JSON.stringify(setting_value);

        var new_language = $link.attr('data-name');
        $('#default_language_name').text(new_language);

        var context = {};
        context.lang = new_language;

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("__lang__ is now the default language!  You will need to reload the window for your changes to take effect", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating default language setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $('#default_language').on('click', function (e) {
        e.preventDefault();
        e.stopPropagation();
        overlays.open_modal('default_language_modal');
    });

    $("#high_contrast_mode").change(function () {
        var high_contrast_mode = this.checked;
        var data = {};
        data.high_contrast_mode = JSON.stringify(high_contrast_mode);
        var context = {};
        if (data.high_contrast_mode === "true") {
            context.enabled_or_disabled = i18n.t('Enabled');
        } else {
            context.enabled_or_disabled = i18n.t('Disabled');
        }

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("High contrast mode __enabled_or_disabled__!", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating high contrast setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $("#night_mode").change(function () {
        exports.set_night_mode(this.checked);
    });

    $("#left_side_userlist").change(function () {
        var left_side_userlist = this.checked;
        var data = {};
        data.left_side_userlist = JSON.stringify(left_side_userlist);
        var context = {};
        if (data.left_side_userlist === "true") {
            context.side = i18n.t('left');
        } else {
            context.side = i18n.t('right');
        }

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("User list will appear on the __side__ hand side! You will need to reload the window for your changes to take effect.", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating user list placement setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $("#emoji_alt_code").change(function () {
        var emoji_alt_code = this.checked;
        var data = {};
        data.emoji_alt_code = JSON.stringify(emoji_alt_code);
        var context = {};
        if (data.emoji_alt_code === "true") {
            context.text_or_images = i18n.t('text');
        } else {
            context.text_or_images = i18n.t('images');
        }

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("Emoji reactions will appear as __text_or_images__!", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating emoji appearance setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $("#twenty_four_hour_time").change(function () {
        var data = {};
        var setting_value = $("#twenty_four_hour_time").is(":checked");
        data.twenty_four_hour_time = JSON.stringify(setting_value);
        var context = {};
        if (data.twenty_four_hour_time === "true") {
            context.format = '24';
        } else {
            context.format = '12';
        }

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("Time will now be displayed in the __format__-hour format!", context),
                                  $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating time format setting"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $("#user_timezone").change(function () {
        var data = {};
        var timezone = this.value;
        data.timezone = JSON.stringify(timezone);

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                ui_report.success(i18n.t("Your time zone have been set to __timezone__", {timezone: timezone}), $('#display-settings-status').expectOne());
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error updating time zone"), xhr, $('#display-settings-status').expectOne());
            },
        });
    });

    $(".emojiset_choice").click(function () {
        var emojiset = $(this).val();
        var data = {};
        data.emojiset = JSON.stringify(emojiset);

        channel.patch({
            url: '/json/settings/display',
            data: data,
            success: function () {
                var spinner = $("#emojiset_spinner").expectOne();
                loading.make_indicator(spinner, {text: 'Changing emojiset.'});
            },
            error: function (xhr) {
                ui_report.error(i18n.t("Error changing emojiset."), xhr, $('#display-settings-status').expectOne());
            },
        });
    });
};

function _update_page() {
    $("#twenty_four_hour_time").prop('checked', page_params.twenty_four_hour_time);
    $("#left_side_userlist").prop('checked', page_params.left_side_userlist);
    $("#emoji_alt_code").prop('checked', page_params.emoji_alt_code);
    $("#default_language_name").text(page_params.default_language_name);
}

exports.update_page = function () {
    i18n.ensure_i18n(_update_page);
};

return exports;
}());

if (typeof module !== 'undefined') {
    module.exports = settings_display;
}
<|endoftext|>


<commit_before>/* jshint unused:false */

var TalkillaSPA = (function() {
  function TalkillaSPA(port, server) {
    this.port = port;
    this.server = server;

    this.port.on("connect", this._onConnect.bind(this));
    this.port.on("autoconnect", this._onAutoconnect.bind(this));

    this.port.on("signin", this._onSignin.bind(this));
    this.port.on("signout", this._onSignout.bind(this));
    this.port.on("call:offer", this._onCallOffer.bind(this));
    this.port.on("call:accepted", this._onCallAccepted.bind(this));
    this.port.on("call:hangup", this._onCallHangup.bind(this));
    this.port.on("presence:request", this._onPresenceRequest.bind(this));

    this.server.on("connected", this._onServerEvent.bind(this, "connected"));
    this.server.on("disconnected",
                   this._onServerEvent.bind(this, "disconnected"));
    this.server.on("message", this._onServerMessage.bind(this));
  }

  TalkillaSPA.prototype._onServerEvent = function(type, event) {
    this.port.post(type, event);
  };

  TalkillaSPA.prototype._onServerMessage = function(type, event) {
    this.port.post("message", [type, event]);
  };

  TalkillaSPA.prototype._onConnect = function(data) {
    this.server.connect(data.nick);
  };

  TalkillaSPA.prototype._onAutoconnect = function(data) {
    this.server.autoconnect(data.nick);
  };

  TalkillaSPA.prototype._onSignin = function(data) {
    this.server.signin(data.assertion, function(err, response) {
      this.port.post("signin-callback", {err: err, response: response});
    }.bind(this));
  };

  TalkillaSPA.prototype._onSignout = function(data) {
    this.server.signout(data.nick, function(err, response) {
      this.port.post("signout-callback", {err: err, response: response});
    }.bind(this));
  };

  TalkillaSPA.prototype._onCallOffer = function(data) {
    this.server.callOffer(data.data, data.nick, function(err, response) {
      this.port.post("call:offer-callback", {err: err, response: response});
    }.bind(this));
  };

  TalkillaSPA.prototype._onCallAccepted = function(data) {
    this.server.callAccepted(data.data, data.nick, function(err, response) {
      this.port.post("call:accepted-callback", {err: err, response: response});
    }.bind(this));
  };

  TalkillaSPA.prototype._onCallHangup = function(data) {
    this.server.callHangup(data.data, data.nick, function(err, response) {
      this.port.post("call:hangup-callback", {err: err, response: response});
    }.bind(this));
  };

  TalkillaSPA.prototype._onPresenceRequest = function(data) {
    this.server.presenceRequest(data.nick);
  };

  return TalkillaSPA;
}());<commit_msg>TalkillaSPA: the prototype is built via an object<commit_after>/* jshint unused:false */

var TalkillaSPA = (function() {
  function TalkillaSPA(port, server) {
    this.port = port;
    this.server = server;

    this.port.on("connect", this._onConnect.bind(this));
    this.port.on("autoconnect", this._onAutoconnect.bind(this));

    this.port.on("signin", this._onSignin.bind(this));
    this.port.on("signout", this._onSignout.bind(this));
    this.port.on("call:offer", this._onCallOffer.bind(this));
    this.port.on("call:accepted", this._onCallAccepted.bind(this));
    this.port.on("call:hangup", this._onCallHangup.bind(this));
    this.port.on("presence:request", this._onPresenceRequest.bind(this));

    this.server.on("connected", this._onServerEvent.bind(this, "connected"));
    this.server.on("disconnected",
                   this._onServerEvent.bind(this, "disconnected"));
    this.server.on("message", this._onServerMessage.bind(this));
  }

  TalkillaSPA.prototype = {
    _onServerEvent: function(type, event) {
      this.port.post(type, event);
    },

    _onServerMessage: function(type, event) {
      this.port.post("message", [type, event]);
    },

    _onConnect: function(data) {
      this.server.connect(data.nick);
    },

    _onAutoconnect: function(data) {
      this.server.autoconnect(data.nick);
    },

    _onSignin: function(data) {
      this.server.signin(data.assertion, function(err, response) {
        this.port.post("signin-callback", {err: err, response: response});
      }.bind(this));
    },

    _onSignout: function(data) {
      this.server.signout(data.nick, function(err, response) {
        this.port.post("signout-callback", {err: err, response: response});
      }.bind(this));
    },

    _onCallOffer: function(data) {
      this.server.callOffer(data.data, data.nick, function(err, response) {
        this.port.post("call:offer-callback", {err: err, response: response});
      }.bind(this));
    },

    _onCallAccepted: function(data) {
      this.server.callAccepted(data.data, data.nick, function(err, response) {
        this.port.post("call:accepted-callback", {err: err, response: response});
      }.bind(this));
    },

    _onCallHangup: function(data) {
      this.server.callHangup(data.data, data.nick, function(err, response) {
        this.port.post("call:hangup-callback", {err: err, response: response});
      }.bind(this));
    },

    _onPresenceRequest: function(data) {
      this.server.presenceRequest(data.nick);
    }
  };

  return TalkillaSPA;
}());<|endoftext|>


<commit_before>//
// Get the data for the DM app
//

$ = SMART.$
pt = {}; // Attach data properties to pt object with $.extend

var error_callback = function(e){
  alert('error '+e.status+' see console.')
  console.log(e.status);
  console.log(e.message.contentType);
  console.log(e.message.data);
  dfd.reject(e.message);
};

var ALLERGIES_get = function(){
  return $.Deferred(function(dfd){
    SMART.ALLERGIES_get()
      .success(function(r){
        var no_known_allergies_p = r.graph
          .prefix('rdf',           'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
          .prefix('sp',            'http://smartplatforms.org/terms#')
          .prefix('dcterms',       'http://purl.org/dc/terms/')
          .where('?allergy_id      rdf:type                sp:AllergyExclusion')
          .where('?allergy_id      sp:allergyExclusionName ?bn')
          .where('?bn              sp:code                 ?snomed_code_uri')
          .where('?snomed_code_uri dcterms:identifier      "1602440022"')
          .length

        $.extend(pt, {'no_known_allergies_p': no_known_allergies_p})

        dfd.resolve();
      })
      .error(error_callback);
  }).promise();
};

var DEMOGRAPHICS_get = function(){
  return $.Deferred(function(dfd){
    SMART.DEMOGRAPHICS_get()
      .success(function(demos){
        $.extend(pt, demos.graph
            .prefix('foaf', 'http://xmlns.com/foaf/0.1/')
            .prefix('v',    'http://www.w3.org/2006/vcard/ns#')
            .prefix('rdf',  'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
            .prefix('sp',   'http://smartplatforms.org/terms#')
            .where('?r      v:n           ?n')
            .where('?n      rdf:type      v:Name')
            .where('?n      v:given-name  ?given_name')
            .where('?n      v:family-name ?family_name')
            .where('?r      foaf:gender   ?gender')
            .where('?r      v:bday        ?bday')
            .get(0))

        pt.name = pt.n;
        dfd.resolve();
      })
      .error(error_callback);
  }).promise();
};

var VITAL_SIGNS_get = function(){
  return $.Deferred(function(dfd){
    SMART.VITAL_SIGNS_get()
      .success(function(r){
        var _get_bps = function(type) {
          var code = null;
          if (type === 'systolic') code = '<http://purl.bioontology.org/ontology/LNC/8480-6>';
          else if (type === 'diastolic') code = '<http://purl.bioontology.org/ontology/LNC/8462-4>';
          else alert('error: bp type not systolic or diastolic!');

          r.graph
           .prefix('rdf',      'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
           .prefix('sp',       'http://smartplatforms.org/terms#')
           .prefix('dcterms',  'http://purl.org/dc/terms/')
           .where('?bn         rdf:type         sp:VitalSign')
           .where('?bn         sp:vitalName     ?vital_name')
           .where('?bn         sp:value         ?value')
           .where('?bn         sp:unit          ?unit')
           .where('?vital_name sp:code          ' + code)
           .where('?bn2        sp:'+ type +'    ?bn')
           .where('?bn2        rdf:type         sp:BloodPressure')
           .where('?vital_id   sp:bloodPressure ?bn2')
           .where('?vital_id   dcterms:date     ?date')
           .each(function(){
             if (type === 'systolic') bp_array = pt.sbp_array;
             else bp_array = pt.dbp_array;

             bp_array.push({
               'value': this.value.value,
               'unit':  this.unit.value,
               'date':  this.date.value
             })
           })
        }

        // ruby style!
        pt.dbp_array = [];
        pt.sbp_array = [];
        _get_bps('systolic');
        _get_bps('diastolic')
        dfd.resolve();
      })
      .error(error_callback);
  }).promise();
};

// On SMART.ready, do all the data api calls and synchronize
// when they are all complete.

SMART.ready(function() {
    $.when(ALLERGIES_get()
         , DEMOGRAPHICS_get()
         , VITAL_SIGNS_get()
         // , MEDS_get()
         // , NOTES_get()
         // , PROBLEMS_get()
         // , VITAL_SIGNS_get()
         ).then(function() {

           // console.log('SMART?', SMART)
           // console.log('SMART.record.full_name?', SMART.record.full_name)
           // console.log('SMART.record.id?', SMART.record.id)

      // console.log(pt.birthday.value
      //           , pt.familyName.value
      //           , pt.gender.value
      //           , pt.givenName.value
      //           , "no_known_allergies_p?"
      //           , pt.no_known_allergies_p
      //           )
    });
});

<commit_msg>Add full name and record id from SMART object<commit_after>//
// Get the data for the DM app
//

$ = SMART.$
pt = {}; // Attach data properties to pt object with $.extend

var error_callback = function(e){
  alert('error '+e.status+' see console.')
  console.log(e.status);
  console.log(e.message.contentType);
  console.log(e.message.data);
  dfd.reject(e.message);
};

var ALLERGIES_get = function(){
  return $.Deferred(function(dfd){
    SMART.ALLERGIES_get()
      .success(function(r){
        var no_known_allergies_p = r.graph
          .prefix('rdf',           'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
          .prefix('sp',            'http://smartplatforms.org/terms#')
          .prefix('dcterms',       'http://purl.org/dc/terms/')
          .where('?allergy_id      rdf:type                sp:AllergyExclusion')
          .where('?allergy_id      sp:allergyExclusionName ?bn')
          .where('?bn              sp:code                 ?snomed_code_uri')
          .where('?snomed_code_uri dcterms:identifier      "1602440022"')
          .length

        $.extend(pt, {'no_known_allergies_p': no_known_allergies_p})

        dfd.resolve();
      })
      .error(error_callback);
  }).promise();
};

var DEMOGRAPHICS_get = function(){
  return $.Deferred(function(dfd){
    SMART.DEMOGRAPHICS_get()
      .success(function(demos){
        $.extend(pt, demos.graph
            .prefix('foaf', 'http://xmlns.com/foaf/0.1/')
            .prefix('v',    'http://www.w3.org/2006/vcard/ns#')
            .prefix('rdf',  'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
            .prefix('sp',   'http://smartplatforms.org/terms#')
            .where('?r      v:n           ?n')
            .where('?n      rdf:type      v:Name')
            .where('?n      v:given-name  ?given_name')
            .where('?n      v:family-name ?family_name')
            .where('?r      foaf:gender   ?gender')
            .where('?r      v:bday        ?bday')
            .get(0))

        pt.name = pt.n;
        dfd.resolve();
      })
      .error(error_callback);
  }).promise();
};

var VITAL_SIGNS_get = function(){
  return $.Deferred(function(dfd){
    SMART.VITAL_SIGNS_get()
      .success(function(r){
        var _get_bps = function(type) {
          var code = null;
          if (type === 'systolic') code = '<http://purl.bioontology.org/ontology/LNC/8480-6>';
          else if (type === 'diastolic') code = '<http://purl.bioontology.org/ontology/LNC/8462-4>';
          else alert('error: bp type not systolic or diastolic!');

          r.graph
           .prefix('rdf',      'http://www.w3.org/1999/02/22-rdf-syntax-ns#')
           .prefix('sp',       'http://smartplatforms.org/terms#')
           .prefix('dcterms',  'http://purl.org/dc/terms/')
           .where('?bn         rdf:type         sp:VitalSign')
           .where('?bn         sp:vitalName     ?vital_name')
           .where('?bn         sp:value         ?value')
           .where('?bn         sp:unit          ?unit')
           .where('?vital_name sp:code          ' + code)
           .where('?bn2        sp:'+ type +'    ?bn')
           .where('?bn2        rdf:type         sp:BloodPressure')
           .where('?vital_id   sp:bloodPressure ?bn2')
           .where('?vital_id   dcterms:date     ?date')
           .each(function(){
             if (type === 'systolic') bp_array = pt.sbp_array;
             else bp_array = pt.dbp_array;

             bp_array.push({
               'value': this.value.value,
               'unit':  this.unit.value,
               'date':  this.date.value
             })
           })
        }

        // ruby style!
        pt.dbp_array = [];
        pt.sbp_array = [];
        _get_bps('systolic');
        _get_bps('diastolic')
        dfd.resolve();
      })
      .error(error_callback);
  }).promise();
};

// On SMART.ready, do all the data api calls and synchronize
// when they are all complete.

SMART.ready(function() {
    $.when(ALLERGIES_get()
         , DEMOGRAPHICS_get()
         , VITAL_SIGNS_get()
         // , MEDS_get()
         // , NOTES_get()
         // , PROBLEMS_get()
         // , VITAL_SIGNS_get()
         ).then(function() {
           // some misc data
           pt.full_name = SMART.record.full_name;
           pt.record_id = SMART.record.id;

      // console.log(pt.birthday.value
      //           , pt.familyName.value
      //           , pt.gender.value
      //           , pt.givenName.value
      //           , "no_known_allergies_p?"
      //           , pt.no_known_allergies_p
      //           )
    });
});

<|endoftext|>


<commit_before>/*jslint browser: true, for: true */
/*global dashjs, flowplayer, MediaPlayer, window */

/*!

   MPEG-DASH engine plugin for Flowplayer HTML5

   Copyright (c) 2015-2017, Flowplayer Drive Oy

   Released under the MIT License:
   http://www.opensource.org/licenses/mit-license.php

   Includes hls.js
   Copyright (c) 2015 Dailymotion (http://www.dailymotion.com)
   https://github.com/dailymotion/hls.js/blob/master/LICENSE

   Requires Flowplayer HTML5 version 6.x
   $GIT_DESC$

*/
(function () {
    "use strict";
    var extension = function (dashjs, flowplayer) {
        var engineName = "dash",
            mse = window.MediaSource || window.WebKitMediaSource,
            common = flowplayer.common,
            extend = flowplayer.extend,
            version = flowplayer.version,
            coreV6 = version.indexOf("6.") === 0,
            dashconf,

            dashCanPlay = function (sourceType, dashType, dashCodecs) {
                return sourceType.toLowerCase() === "application/dash+xml" &&
                        mse.isTypeSupported(dashType + ';codecs="' + dashCodecs + '"') &&
                        // Android MSE advertises he-aac, but fails
                        (dashCodecs.indexOf("mp4a.40.5") < 0 || navigator.userAgent.indexOf("Android") < 0);
            },

            engineImpl = function dashjsEngine(player, root) {
                var bean = flowplayer.bean,
                    mediaPlayer,
                    videoTag,
                    bc,
                    has_bg,

                    engine = {
                        engineName: engineName,

                        pick: function (sources) {
                            var i,
                                source,
                                dashType,
                                dashCodecs;

                            for (i = 0; i < sources.length; i += 1) {
                                source = sources[i];
                                dashType = source.dashType || dashconf.type;
                                dashCodecs = source.dashCodecs || dashconf.codecs;
                                if (dashCanPlay(source.type, dashType, dashCodecs)) {
                                    if (typeof source.src === 'string') {
                                        source.src = common.createAbsoluteUrl(source.src);
                                    }
                                    return source;
                                }
                            }
                        },

                        load: function (video) {
                            var conf = player.conf,
                                dashUpdatedConf = extend(dashconf, conf.dash, video.dash),
                                EVENTS = {
                                    ended: "finish",
                                    loadeddata: "ready",
                                    pause: "pause",
                                    play: "resume",
                                    progress: "buffer",
                                    ratechange: "speed",
                                    seeked: "seek",
                                    timeupdate: "progress",
                                    volumechange: "volume"
                                },
                                DASHEVENTS = dashjs.MediaPlayer.events,
                                autoplay = !!video.autoplay || !!conf.autoplay,
                                posterClass = "is-poster",
                                livestartpos = 0;

                            if (!mediaPlayer) {
                                videoTag = common.findDirect("video", root)[0]
                                        || common.find(".fp-player > video", root)[0];

                                if (videoTag) {
                                    // destroy video tag
                                    // otherwise <video autoplay> continues to play
                                    common.find("source", videoTag).forEach(function (source) {
                                        source.removeAttribute("src");
                                    });
                                    videoTag.removeAttribute("src");
                                    videoTag.load();
                                    common.removeNode(videoTag);
                                }

                                // dash.js enforces preload="auto" and
                                // autoplay depending on initialization
                                // so setting the attributes here will have no effect
                                videoTag = common.createElement("video", {
                                    "class": "fp-engine " + engineName + "-engine",
                                    "volume": player.volumeLevel,
                                    "x-webkit-airplay": "allow"
                                });

                                Object.keys(EVENTS).forEach(function (key) {
                                    var flow = EVENTS[key],
                                        type = key + "." + engineName,
                                        arg;

                                    bean.on(videoTag, type, function (e) {
                                        if (conf.debug && flow.indexOf("progress") < 0) {
                                            console.log(type, "->", flow, e.originalEvent);
                                        }

                                        var vct = videoTag.currentTime,
                                            ct = (mediaPlayer.time && mediaPlayer.time()) || vct,
                                            seekable = videoTag.seekable,
                                            buffered = videoTag.buffered,
                                            buffer = 0,
                                            buffend = 0,
                                            i;

                                        switch (flow) {
                                        case "ready":
                                            arg = extend(player.video, {
                                                duration: mediaPlayer.duration(),
                                                seekable: seekable.length && seekable.end(null),
                                                width: videoTag.videoWidth,
                                                height: videoTag.videoHeight,
                                                url: player.video.src
                                            });
                                            break;
                                        case "resume":
                                            if (coreV6 && player.poster) {
                                                common.removeClass(root, posterClass);
                                                player.poster = false;
                                            }
                                            break;
                                        case "seek":
                                            arg = ct;
                                            break;
                                        case "progress":
                                            if (player.live && !player.dvr) {
                                                if (!livestartpos && vct) {
                                                    livestartpos = vct;
                                                }
                                                arg = livestartpos
                                                    ? vct - livestartpos
                                                    : 0;
                                            } else {
                                                arg = ct;
                                            }
                                            break;
                                        case "speed":
                                            // dash.js often triggers playback rate changes
                                            // when adapting bit rate
                                            // except when in debug mode, only
                                            // trigger explicit events via speed method
                                            if (!dashUpdatedConf.debug) {
                                                e.preventDefault();
                                                return;
                                            }
                                            arg = videoTag.playbackRate;
                                            break;
                                        case "volume":
                                            arg = videoTag.volume;
                                            break;
                                        case "buffer":
                                            try {
                                                buffer = buffered.length && buffered.end(null);
                                                if (!player.video.live && ct && buffer) {
                                                    // cycle through time ranges to obtain buffer
                                                    // nearest current time
                                                    for (i = buffered.length - 1; i > -1; i -= 1) {
                                                        buffend = buffered.end(i);

                                                        if (buffend >= ct) {
                                                            buffer = buffend;
                                                        }
                                                    }
                                                }
                                            } catch (ignore) {}
                                            video.buffer = buffer;
                                            arg = buffer;
                                            break;
                                        }

                                        player.trigger(flow, [player, arg]);
                                    });
                                });

                                if (coreV6 && conf.poster) {
                                    var posterHack = function (e) {
                                        if (e.type === "stop" || !autoplay) {
                                            setTimeout(function () {
                                                if (!player.poster) {
                                                    common.addClass(root, posterClass);
                                                    player.poster = true;
                                                }
                                            });
                                        }
                                    };

                                    player.one("ready." + engineName, posterHack).on("stop." + engineName, posterHack);
                                }
                                player.on("error." + engineName, function () {
                                    if (mediaPlayer) {
                                        mediaPlayer.reset();
                                        mediaPlayer = 0;
                                    }
                                });

                                mediaPlayer = dashjs.MediaPlayer().create();
                                player.engine[engineName] = mediaPlayer;

                                // new ABR algo
                                mediaPlayer.enableBufferOccupancyABR(dashUpdatedConf.bufferOccupancyABR);
                                // caching can cause failures in playlists
                                // for the moment disable entirely
                                mediaPlayer.enableLastBitrateCaching(false);
                                // for seeking in paused state
                                mediaPlayer.setScheduleWhilePaused(true);
                                mediaPlayer.getDebug().setLogToBrowserConsole(dashUpdatedConf.debug);

                                Object.keys(DASHEVENTS).forEach(function (key) {
                                    var etype = DASHEVENTS[key],
                                        fpEventType = engineName + etype.charAt(0).toUpperCase() + etype.slice(1),
                                        listeners = dashUpdatedConf.listeners,
                                        expose = listeners && listeners.indexOf(fpEventType) > -1;

                                    mediaPlayer.on(etype, function (e) {
                                        var data = extend({}, e),
                                            src = player.video.src,
                                            fperr,
                                            errobj;

                                        delete data.type;
                                        switch (key) {
                                        case "ERROR":
                                            switch (data.error) {
                                            case "download":
                                                fperr = 4;
                                                break;
                                            case "manifestError":
                                                fperr = 5;
                                                break;
                                            case "mediasource":
                                                switch (e.event) {
                                                case "MEDIA_ERR_DECODE":
                                                    fperr = 3;
                                                    break;
                                                case "MEDIA_ERR_SRC_NOT_SUPPORTED":
                                                    fperr = 5;
                                                    break;
                                                case "MEDIA_ERR_NETWORK":
                                                    fperr = 2;
                                                    break;
                                                case "MEDIA_ERR_ABORTED":
                                                    fperr = 1;
                                                    break;
                                                }
                                                break;
                                            }
                                            if (fperr) {
                                                errobj = {code: fperr};
                                                if (fperr > 2) {
                                                    errobj.video = extend(video, {
                                                        src: src,
                                                        url: data.event.url || src
                                                    });
                                                }
                                                player.trigger('error', [player, errobj]);
                                                return;
                                            }
                                            break;
                                        }

                                        if (expose) {
                                            player.trigger(fpEventType, [player, data]);
                                        }
                                    });
                                });

                                common.prepend(common.find(".fp-player", root)[0], videoTag);
                                mediaPlayer.initialize(videoTag, video.src, autoplay);

                            } else {
                                if ((player.video.src && video.src !== player.video.src) || video.index) {
                                    mediaPlayer.setAutoPlay(true);
                                }
                                mediaPlayer.attachSource(video.src);

                            }

                            // update video object before ready
                            player.video = video;

                            if (player.paused && autoplay) {
                                if (flowplayer.support.firstframe) {
                                    mediaPlayer.play();
                                } else {
                                    videoTag.play();
                                }
                            }
                        },

                        resume: function () {
                            mediaPlayer.play();
                        },

                        pause: function () {
                            mediaPlayer.pause();
                        },

                        seek: function (time) {
                            mediaPlayer.seek(time);
                        },

                        volume: function (level) {
                            if (videoTag) {
                                videoTag.volume = level;
                            }
                        },

                        speed: function (val) {
                            videoTag.playbackRate = val;
                            // see ratechange/speed event
                            player.trigger('speed', [player, val]);
                        },

                        unload: function () {
                            if (mediaPlayer) {
                                var listeners = "." + engineName;

                                mediaPlayer.reset();
                                mediaPlayer = 0;
                                player.off(listeners);
                                bean.off(root, listeners);
                                bean.off(videoTag, listeners);
                                common.removeNode(videoTag);
                                videoTag = 0;
                            }
                        }
                    };

                // pre 6.0.4: no boolean api.conf.poster and no poster with autoplay
                if (/^6\.0\.[0-3]$/.test(version) &&
                        !player.conf.splash && !player.conf.poster && !player.conf.autoplay) {
                    bc = common.css(root, 'backgroundColor');
                    // spaces in rgba arg mandatory for recognition
                    has_bg = common.css(root, 'backgroundImage') !== "none" ||
                            (bc && bc !== "rgba(0, 0, 0, 0)" && bc !== "transparent");
                    if (has_bg) {
                        player.conf.poster = true;
                    }
                }

                return engine;
            };

        if (mse && typeof mse.isTypeSupported === "function" && version.indexOf("5.") !== 0) {
            // only load engine if it can be used
            engineImpl.engineName = engineName; // must be exposed
            engineImpl.canPlay = function (type, conf) {
                /*
                  WARNING: MediaSource.isTypeSupported very inconsistent!
                  e.g. Safari ignores codecs entirely, even bogus, like codecs="XYZ"
                  example avc3 main level 3.1 + aac_he: avc3.4d401f; mp4a.40.5
                  example avc1 high level 4.1 + aac_lc: avc1.640029; mp4a.40.2
                  default: avc1 baseline level 3.0 + aac_lc
                */
                // inject dash conf at earliest opportunity
                dashconf = extend({
                    type: "video/mp4",
                    codecs: "avc1.42c01e,mp4a.40.2"
                }, conf[engineName], conf.clip[engineName]);

                return dashCanPlay(type, dashconf.type, dashconf.codecs);
            };

            // put on top of engine stack
            // so mpegedash is tested before html5
            flowplayer.engines.unshift(engineImpl);

        }

    };
    if (typeof module === 'object' && module.exports) {
        module.exports = extension.bind(undefined, require('dashjs'));
    } else if (window.dashjs && window.flowplayer) {
        extension(window.dashjs, window.flowplayer);
    }
}());
<commit_msg>Simplfy setAutoPlay on reload<commit_after>/*jslint browser: true, for: true */
/*global dashjs, flowplayer, MediaPlayer, window */

/*!

   MPEG-DASH engine plugin for Flowplayer HTML5

   Copyright (c) 2015-2017, Flowplayer Drive Oy

   Released under the MIT License:
   http://www.opensource.org/licenses/mit-license.php

   Includes hls.js
   Copyright (c) 2015 Dailymotion (http://www.dailymotion.com)
   https://github.com/dailymotion/hls.js/blob/master/LICENSE

   Requires Flowplayer HTML5 version 6.x
   $GIT_DESC$

*/
(function () {
    "use strict";
    var extension = function (dashjs, flowplayer) {
        var engineName = "dash",
            mse = window.MediaSource || window.WebKitMediaSource,
            common = flowplayer.common,
            extend = flowplayer.extend,
            version = flowplayer.version,
            coreV6 = version.indexOf("6.") === 0,
            dashconf,

            dashCanPlay = function (sourceType, dashType, dashCodecs) {
                return sourceType.toLowerCase() === "application/dash+xml" &&
                        mse.isTypeSupported(dashType + ';codecs="' + dashCodecs + '"') &&
                        // Android MSE advertises he-aac, but fails
                        (dashCodecs.indexOf("mp4a.40.5") < 0 || navigator.userAgent.indexOf("Android") < 0);
            },

            engineImpl = function dashjsEngine(player, root) {
                var bean = flowplayer.bean,
                    mediaPlayer,
                    videoTag,
                    bc,
                    has_bg,

                    engine = {
                        engineName: engineName,

                        pick: function (sources) {
                            var i,
                                source,
                                dashType,
                                dashCodecs;

                            for (i = 0; i < sources.length; i += 1) {
                                source = sources[i];
                                dashType = source.dashType || dashconf.type;
                                dashCodecs = source.dashCodecs || dashconf.codecs;
                                if (dashCanPlay(source.type, dashType, dashCodecs)) {
                                    if (typeof source.src === 'string') {
                                        source.src = common.createAbsoluteUrl(source.src);
                                    }
                                    return source;
                                }
                            }
                        },

                        load: function (video) {
                            var conf = player.conf,
                                dashUpdatedConf = extend(dashconf, conf.dash, video.dash),
                                EVENTS = {
                                    ended: "finish",
                                    loadeddata: "ready",
                                    pause: "pause",
                                    play: "resume",
                                    progress: "buffer",
                                    ratechange: "speed",
                                    seeked: "seek",
                                    timeupdate: "progress",
                                    volumechange: "volume"
                                },
                                DASHEVENTS = dashjs.MediaPlayer.events,
                                autoplay = !!video.autoplay || !!conf.autoplay,
                                posterClass = "is-poster",
                                livestartpos = 0;

                            if (!mediaPlayer) {
                                videoTag = common.findDirect("video", root)[0]
                                        || common.find(".fp-player > video", root)[0];

                                if (videoTag) {
                                    // destroy video tag
                                    // otherwise <video autoplay> continues to play
                                    common.find("source", videoTag).forEach(function (source) {
                                        source.removeAttribute("src");
                                    });
                                    videoTag.removeAttribute("src");
                                    videoTag.load();
                                    common.removeNode(videoTag);
                                }

                                // dash.js enforces preload="auto" and
                                // autoplay depending on initialization
                                // so setting the attributes here will have no effect
                                videoTag = common.createElement("video", {
                                    "class": "fp-engine " + engineName + "-engine",
                                    "volume": player.volumeLevel,
                                    "x-webkit-airplay": "allow"
                                });

                                Object.keys(EVENTS).forEach(function (key) {
                                    var flow = EVENTS[key],
                                        type = key + "." + engineName,
                                        arg;

                                    bean.on(videoTag, type, function (e) {
                                        if (conf.debug && flow.indexOf("progress") < 0) {
                                            console.log(type, "->", flow, e.originalEvent);
                                        }

                                        var vct = videoTag.currentTime,
                                            ct = (mediaPlayer.time && mediaPlayer.time()) || vct,
                                            seekable = videoTag.seekable,
                                            buffered = videoTag.buffered,
                                            buffer = 0,
                                            buffend = 0,
                                            i;

                                        switch (flow) {
                                        case "ready":
                                            arg = extend(player.video, {
                                                duration: mediaPlayer.duration(),
                                                seekable: seekable.length && seekable.end(null),
                                                width: videoTag.videoWidth,
                                                height: videoTag.videoHeight,
                                                url: player.video.src
                                            });
                                            break;
                                        case "resume":
                                            if (coreV6 && player.poster) {
                                                common.removeClass(root, posterClass);
                                                player.poster = false;
                                            }
                                            break;
                                        case "seek":
                                            arg = ct;
                                            break;
                                        case "progress":
                                            if (player.live && !player.dvr) {
                                                if (!livestartpos && vct) {
                                                    livestartpos = vct;
                                                }
                                                arg = livestartpos
                                                    ? vct - livestartpos
                                                    : 0;
                                            } else {
                                                arg = ct;
                                            }
                                            break;
                                        case "speed":
                                            // dash.js often triggers playback rate changes
                                            // when adapting bit rate
                                            // except when in debug mode, only
                                            // trigger explicit events via speed method
                                            if (!dashUpdatedConf.debug) {
                                                e.preventDefault();
                                                return;
                                            }
                                            arg = videoTag.playbackRate;
                                            break;
                                        case "volume":
                                            arg = videoTag.volume;
                                            break;
                                        case "buffer":
                                            try {
                                                buffer = buffered.length && buffered.end(null);
                                                if (!player.video.live && ct && buffer) {
                                                    // cycle through time ranges to obtain buffer
                                                    // nearest current time
                                                    for (i = buffered.length - 1; i > -1; i -= 1) {
                                                        buffend = buffered.end(i);

                                                        if (buffend >= ct) {
                                                            buffer = buffend;
                                                        }
                                                    }
                                                }
                                            } catch (ignore) {}
                                            video.buffer = buffer;
                                            arg = buffer;
                                            break;
                                        }

                                        player.trigger(flow, [player, arg]);
                                    });
                                });

                                if (coreV6 && conf.poster) {
                                    var posterHack = function (e) {
                                        if (e.type === "stop" || !autoplay) {
                                            setTimeout(function () {
                                                if (!player.poster) {
                                                    common.addClass(root, posterClass);
                                                    player.poster = true;
                                                }
                                            });
                                        }
                                    };

                                    player.one("ready." + engineName, posterHack).on("stop." + engineName, posterHack);
                                }
                                player.on("error." + engineName, function () {
                                    if (mediaPlayer) {
                                        mediaPlayer.reset();
                                        mediaPlayer = 0;
                                    }
                                });

                                mediaPlayer = dashjs.MediaPlayer().create();
                                player.engine[engineName] = mediaPlayer;

                                // new ABR algo
                                mediaPlayer.enableBufferOccupancyABR(dashUpdatedConf.bufferOccupancyABR);
                                // caching can cause failures in playlists
                                // for the moment disable entirely
                                mediaPlayer.enableLastBitrateCaching(false);
                                // for seeking in paused state
                                mediaPlayer.setScheduleWhilePaused(true);
                                mediaPlayer.getDebug().setLogToBrowserConsole(dashUpdatedConf.debug);

                                Object.keys(DASHEVENTS).forEach(function (key) {
                                    var etype = DASHEVENTS[key],
                                        fpEventType = engineName + etype.charAt(0).toUpperCase() + etype.slice(1),
                                        listeners = dashUpdatedConf.listeners,
                                        expose = listeners && listeners.indexOf(fpEventType) > -1;

                                    mediaPlayer.on(etype, function (e) {
                                        var data = extend({}, e),
                                            src = player.video.src,
                                            fperr,
                                            errobj;

                                        delete data.type;
                                        switch (key) {
                                        case "ERROR":
                                            switch (data.error) {
                                            case "download":
                                                fperr = 4;
                                                break;
                                            case "manifestError":
                                                fperr = 5;
                                                break;
                                            case "mediasource":
                                                switch (e.event) {
                                                case "MEDIA_ERR_DECODE":
                                                    fperr = 3;
                                                    break;
                                                case "MEDIA_ERR_SRC_NOT_SUPPORTED":
                                                    fperr = 5;
                                                    break;
                                                case "MEDIA_ERR_NETWORK":
                                                    fperr = 2;
                                                    break;
                                                case "MEDIA_ERR_ABORTED":
                                                    fperr = 1;
                                                    break;
                                                }
                                                break;
                                            }
                                            if (fperr) {
                                                errobj = {code: fperr};
                                                if (fperr > 2) {
                                                    errobj.video = extend(video, {
                                                        src: src,
                                                        url: data.event.url || src
                                                    });
                                                }
                                                player.trigger('error', [player, errobj]);
                                                return;
                                            }
                                            break;
                                        }

                                        if (expose) {
                                            player.trigger(fpEventType, [player, data]);
                                        }
                                    });
                                });

                                common.prepend(common.find(".fp-player", root)[0], videoTag);
                                mediaPlayer.initialize(videoTag, video.src, autoplay);

                            } else {
                                mediaPlayer.setAutoPlay(autoplay);
                                mediaPlayer.attachSource(video.src);

                            }

                            // update video object before ready
                            player.video = video;

                            if (player.paused && autoplay) {
                                if (flowplayer.support.firstframe) {
                                    mediaPlayer.play();
                                } else {
                                    videoTag.play();
                                }
                            }
                        },

                        resume: function () {
                            mediaPlayer.play();
                        },

                        pause: function () {
                            mediaPlayer.pause();
                        },

                        seek: function (time) {
                            mediaPlayer.seek(time);
                        },

                        volume: function (level) {
                            if (videoTag) {
                                videoTag.volume = level;
                            }
                        },

                        speed: function (val) {
                            videoTag.playbackRate = val;
                            // see ratechange/speed event
                            player.trigger('speed', [player, val]);
                        },

                        unload: function () {
                            if (mediaPlayer) {
                                var listeners = "." + engineName;

                                mediaPlayer.reset();
                                mediaPlayer = 0;
                                player.off(listeners);
                                bean.off(root, listeners);
                                bean.off(videoTag, listeners);
                                common.removeNode(videoTag);
                                videoTag = 0;
                            }
                        }
                    };

                // pre 6.0.4: no boolean api.conf.poster and no poster with autoplay
                if (/^6\.0\.[0-3]$/.test(version) &&
                        !player.conf.splash && !player.conf.poster && !player.conf.autoplay) {
                    bc = common.css(root, 'backgroundColor');
                    // spaces in rgba arg mandatory for recognition
                    has_bg = common.css(root, 'backgroundImage') !== "none" ||
                            (bc && bc !== "rgba(0, 0, 0, 0)" && bc !== "transparent");
                    if (has_bg) {
                        player.conf.poster = true;
                    }
                }

                return engine;
            };

        if (mse && typeof mse.isTypeSupported === "function" && version.indexOf("5.") !== 0) {
            // only load engine if it can be used
            engineImpl.engineName = engineName; // must be exposed
            engineImpl.canPlay = function (type, conf) {
                /*
                  WARNING: MediaSource.isTypeSupported very inconsistent!
                  e.g. Safari ignores codecs entirely, even bogus, like codecs="XYZ"
                  example avc3 main level 3.1 + aac_he: avc3.4d401f; mp4a.40.5
                  example avc1 high level 4.1 + aac_lc: avc1.640029; mp4a.40.2
                  default: avc1 baseline level 3.0 + aac_lc
                */
                // inject dash conf at earliest opportunity
                dashconf = extend({
                    type: "video/mp4",
                    codecs: "avc1.42c01e,mp4a.40.2"
                }, conf[engineName], conf.clip[engineName]);

                return dashCanPlay(type, dashconf.type, dashconf.codecs);
            };

            // put on top of engine stack
            // so mpegedash is tested before html5
            flowplayer.engines.unshift(engineImpl);

        }

    };
    if (typeof module === 'object' && module.exports) {
        module.exports = extension.bind(undefined, require('dashjs'));
    } else if (window.dashjs && window.flowplayer) {
        extension(window.dashjs, window.flowplayer);
    }
}());
<|endoftext|>


<commit_before>import * as colors from "../color.js";
import {clamp} from "../math.js";

//Parse a color range
let parseColorRange = function (array) {
    return array.map(function (item) {
        return colors.parseColor(item);
    });
};

//Export color scale
export function color (args) {
    let zero = args.zero === true || args.zero === "true"; //Scale should include zero
    let domain = args.domain; //Get domain reference
    if (zero === true) {
        domain[0] = Math.min(0, domain[0]); //ensure that domain start has a zero
        domain[1] = Math.max(0, domain[1]); //ensure that domain end has a zero
    }
    let range = parseColorRange(args["range"]);
    let n = range.length - 1; //Calculate the number of intervals
    //Return the scale function
    let scale = function (value) {
        let v = clamp(value, domain[0], domain[1]); //Parse value
        //Check for extreme values
        if (v === domain[0]) {
            return range[0]; //Return the first range color
        }
        else if (v === domain[1]) {
            return range[range.length - 1]; //Return the last range color
        }
        //Calculate the factor
        let factor = (v - domain[0]) / (domain[1] - domain[0]);
        let i = Math.floor(n * factor); //Get the interval
        //Interpolate the two colors
        let newColor = colors.interpolate(range[i], range[i+1], (factor * n) - i);
        //Return the HEX result color
        return colors.toHexString(newColor);
    };
    //Add scale metadata
    scale.type = "color";
    scale.range = range;
    scale.domain = domain;
    //Return the scale
    return scale;
}

<commit_msg>scales: fixed minor bug in scale color when value is in domain interval limits<commit_after>import * as colors from "../color.js";
import {clamp} from "../math.js";

//Parse a color range
let parseColorRange = function (array) {
    return array.map(function (item) {
        return colors.parseColor(item);
    });
};

//Export color scale
export function color (args) {
    let zero = args.zero === true || args.zero === "true"; //Scale should include zero
    let domain = args.domain; //Get domain reference
    if (zero === true) {
        domain[0] = Math.min(0, domain[0]); //ensure that domain start has a zero
        domain[1] = Math.max(0, domain[1]); //ensure that domain end has a zero
    }
    let range = parseColorRange(args["range"]);
    let n = range.length - 1; //Calculate the number of intervals
    //Return the scale function
    let scale = function (value) {
        let v = clamp(value, domain[0], domain[1]); //Parse value
        //Check for extreme values
        if (v === domain[0]) {
            return colors.toHexString(range[0]); //Return the first range color
        }
        else if (v === domain[1]) {
            return colors.toHexString(range[range.length - 1]); //Return the last range color
        }
        //Calculate the factor
        let factor = (v - domain[0]) / (domain[1] - domain[0]);
        let i = Math.floor(n * factor); //Get the interval
        //Interpolate the two colors
        let newColor = colors.interpolate(range[i], range[i+1], (factor * n) - i);
        //Return the HEX result color
        return colors.toHexString(newColor);
    };
    //Add scale metadata
    scale.type = "color";
    scale.range = range;
    scale.domain = domain;
    //Return the scale
    return scale;
}

<|endoftext|>