Skip to content

Commit a652088

Browse files
author
Wallace Breza
committed
Initial checkin. Migrated from temp project
0 parents  commit a652088

File tree

9 files changed

+410
-0
lines changed

9 files changed

+410
-0
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist/
2+
node_modules/

.jshintrc

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
{
2+
// JSHint Default Configuration File (as on JSHint website)
3+
// See http://jshint.com/docs/ for more details
4+
5+
"maxerr" : 50, // {int} Maximum error before stopping
6+
7+
// Enforcing
8+
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
9+
"camelcase" : false, // true: Identifiers must be in camelCase
10+
"curly" : true, // true: Require {} for every new block or scope
11+
"eqeqeq" : true, // true: Require triple equals (===) for comparison
12+
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
13+
"freeze" : true, // true: prohibits overwriting prototypes of native objects such as Array, Date etc.
14+
"immed" : false, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
15+
"latedef" : false, // true: Require variables/functions to be defined before being used
16+
"newcap" : false, // true: Require capitalization of all constructor functions e.g. `new F()`
17+
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
18+
"noempty" : true, // true: Prohibit use of empty blocks
19+
"nonbsp" : true, // true: Prohibit "non-breaking whitespace" characters.
20+
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
21+
"plusplus" : false, // true: Prohibit use of `++` and `--`
22+
"quotmark" : false, // Quotation mark consistency:
23+
// false : do nothing (default)
24+
// true : ensure whatever is used is consistent
25+
// "single" : require single quotes
26+
// "double" : require double quotes
27+
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
28+
"unused" : true, // Unused variables:
29+
// true : all variables, last function parameter
30+
// "vars" : all variables only
31+
// "strict" : all variables, all function parameters
32+
"strict" : true, // true: Requires all functions run in ES5 Strict Mode
33+
"maxparams" : false, // {int} Max number of formal params allowed per function
34+
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
35+
"maxstatements" : false, // {int} Max number statements per function
36+
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
37+
"maxlen" : false, // {int} Max number of characters per line
38+
"varstmt" : false, // true: Disallow any var statements. Only `let` and `const` are allowed.
39+
40+
// Relaxing
41+
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
42+
"boss" : false, // true: Tolerate assignments where comparisons would be expected
43+
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
44+
"eqnull" : false, // true: Tolerate use of `== null`
45+
"moz" : false, // true: Allow Mozilla specific syntax (extends and overrides esnext features)
46+
// (ex: `for each`, multiple try/catch, function expression…)
47+
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
48+
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
49+
"funcscope" : false, // true: Tolerate defining variables inside control statements
50+
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
51+
"iterator" : false, // true: Tolerate using the `__iterator__` property
52+
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
53+
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
54+
"laxcomma" : false, // true: Tolerate comma-first style coding
55+
"loopfunc" : false, // true: Tolerate functions being defined in loops
56+
"multistr" : false, // true: Tolerate multi-line strings
57+
"noyield" : false, // true: Tolerate generator functions with no yield statement in them.
58+
"notypeof" : false, // true: Tolerate invalid typeof operator values
59+
"proto" : false, // true: Tolerate using the `__proto__` property
60+
"scripturl" : false, // true: Tolerate script-targeted URLs
61+
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
62+
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
63+
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
64+
"validthis" : false, // true: Tolerate using this in a non-constructor function
65+
66+
// Environments
67+
"browser" : true, // Web Browser (window, document, etc)
68+
"browserify" : false, // Browserify (node.js code in the browser)
69+
"couch" : false, // CouchDB
70+
"devel" : true, // Development/debugging (alert, confirm, etc)
71+
"dojo" : false, // Dojo Toolkit
72+
"jasmine" : false, // Jasmine
73+
"jquery" : false, // jQuery
74+
"mocha" : true, // Mocha
75+
"mootools" : false, // MooTools
76+
"node" : false, // Node.js
77+
"nonstandard" : false, // Widely adopted globals (escape, unescape, etc)
78+
"phantom" : false, // PhantomJS
79+
"prototypejs" : false, // Prototype and Scriptaculous
80+
"qunit" : false, // QUnit
81+
"rhino" : false, // Rhino
82+
"shelljs" : false, // ShellJS
83+
"typed" : false, // Globals for typed array constructions
84+
"worker" : false, // Web Workers
85+
"wsh" : false, // Windows Scripting Host
86+
"yui" : false, // Yahoo User Interface
87+
88+
// Custom Globals
89+
"globals" : {} // additional predefined global variables
90+
}

gulpfile.js

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
var gulp = require('gulp-help')(require('gulp'));
2+
var rename = require('gulp-rename'),
3+
concat = require('gulp-concat'),
4+
uglify = require('gulp-uglify'),
5+
jshint = require('gulp-jshint'),
6+
rimraf = require('rimraf');
7+
8+
var paths = {
9+
outFilename: 'powerbi.js',
10+
outMinFilename: 'powerbi.min.js',
11+
jsSource: './src/**/*.js',
12+
jsDest: './dist/'
13+
};
14+
15+
gulp.task('watch', 'Watches for changes', ['lint'], function () {
16+
gulp.watch(paths.jsSource, ['lint']);
17+
});
18+
19+
gulp.task('lint', 'Lints all files', ['lint:js']);
20+
gulp.task('build:debug', 'Runs a debug build', ['clean', 'lint:js', 'concat:js']);
21+
gulp.task('build:release', 'Runs a release build', ['clean', 'lint:js', 'concat:js', 'min:js']);
22+
23+
gulp.task('clean', function (callback) {
24+
rimraf(paths.jsDest, callback);
25+
});
26+
27+
gulp.task('lint:js', 'Lints all JavaScript', function () {
28+
return gulp.src(paths.jsSource)
29+
.pipe(jshint())
30+
.pipe(jshint.reporter('jshint-stylish'));
31+
});
32+
33+
gulp.task('concat:js', 'Combines JavaScript files into a single file', function () {
34+
return gulp.src(paths.jsSource)
35+
.pipe(concat(paths.outFilename))
36+
.pipe(gulp.dest(paths.jsDest));
37+
});
38+
39+
gulp.task('min:js', 'Createds minified JavaScript file', ['concat:js'], function () {
40+
return gulp.src(paths.jsDest + paths.outFilename)
41+
.pipe(uglify())
42+
.pipe(rename(paths.outMinFilename))
43+
.pipe(gulp.dest(paths.jsDest));
44+
});

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "powerbi-javascript",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"directories": {
7+
"test": "test"
8+
},
9+
"scripts": {
10+
"test": "echo \"Error: no test specified\" && exit 1"
11+
},
12+
"repository": {
13+
"type": "git",
14+
"url": "https://pbix.visualstudio.com/DefaultCollection/PaaS/_git/PowerBI-JavaScript"
15+
},
16+
"author": "Microsoft",
17+
"license": "ISC",
18+
"devDependencies": {
19+
"gulp": "^3.9.0",
20+
"gulp-concat": "^2.6.0",
21+
"gulp-help": "^1.6.1",
22+
"gulp-jshint": "^2.0.0",
23+
"gulp-rename": "^1.2.2",
24+
"gulp-uglify": "^1.5.1",
25+
"jshint": "^2.9.1",
26+
"jshint-stylish": "^2.1.0",
27+
"karma": "^0.13.19",
28+
"rimraf": "^2.5.1"
29+
}
30+
}

src/core.js

+79
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
(function (powerbi) {
2+
'use strict';
3+
4+
var embeds = [];
5+
6+
powerbi.get = get;
7+
powerbi.embed = embed;
8+
9+
activate();
10+
11+
//////////////////////////////////
12+
13+
function activate() {
14+
window.addEventListener('DOMContentLoaded', onLoad, false);
15+
window.addEventListener('message', onReceiveMessage, false);
16+
}
17+
18+
var componentTypes = [
19+
{ type: 'powerbi-tile', component: powerbi.Tile },
20+
{ type: 'powerbi-report', component: powerbi.Report }
21+
];
22+
23+
var EmbedEventMap = {
24+
'tileClicked': 'tile-click',
25+
'tileLoaded': 'tile-load',
26+
'reportPageLoaded': 'report-load'
27+
};
28+
29+
function onLoad() {
30+
var components = document.querySelectorAll('[powerbi-embed]');
31+
for (var i = 0; i < components.length; i++) {
32+
embed(components[i]);
33+
}
34+
}
35+
36+
function get(element) {
37+
return element.powerBIEmbed || embed(element);
38+
}
39+
40+
function embed(element) {
41+
var instance;
42+
43+
for (var j = 0; j < componentTypes.length; j++) {
44+
var componentType = componentTypes[j];
45+
46+
if (element.getAttribute(componentType.type) !== null) {
47+
instance = new componentType.component(element);
48+
element.powerBIEmbed = instance;
49+
embeds.push(instance);
50+
break;
51+
}
52+
}
53+
54+
return instance;
55+
}
56+
57+
function onReceiveMessage(event) {
58+
if (!event) {
59+
return;
60+
}
61+
62+
try {
63+
var messageData = JSON.parse(event.data);
64+
for (var i = 0; i < embeds.length; i++) {
65+
var embed = embeds[i];
66+
67+
// Only raise the event on the embed that matches the post message origin
68+
if (event.source === embed.iframe.contentWindow) {
69+
powerbi.utils.raiseCustomEvent(embed.element, EmbedEventMap[messageData.event], messageData);
70+
}
71+
}
72+
}
73+
catch (e) {
74+
if (typeof (window.powerbi.onError) === 'function') {
75+
window.powerbi.onError.call(window, e);
76+
}
77+
}
78+
}
79+
} (window.powerbi = window.powerbi || {}));

src/embed.js

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
(function (powerbi) {
2+
'use strict';
3+
4+
function Embed() { }
5+
6+
Embed.prototype = {
7+
init: function () {
8+
var embedUrl = this.getEmbedUrl();
9+
var iframeHtml = '<iframe style="width:100%;height:100%;" src="' + embedUrl + '" scrolling="no" allowfullscreen="true"></iframe>';
10+
this.element.innerHTML = iframeHtml;
11+
this.iframe = this.element.childNodes[0];
12+
this.iframe.addEventListener('load', this.load.bind(this), false);
13+
},
14+
load: function () {
15+
var computedStle = window.getComputedStyle(this.element);
16+
17+
var initEventArgs = {
18+
message: {
19+
action: this.options.loadAction,
20+
accessToken: powerbi.accessToken,
21+
width: computedStle.width,
22+
height: computedStle.height
23+
}
24+
};
25+
26+
powerbi.utils.raiseCustomEvent(this.element, 'embed-init', initEventArgs);
27+
this.iframe.contentWindow.postMessage(JSON.stringify(initEventArgs.message), '*');
28+
},
29+
getEmbedUrl: function () {
30+
return this.element.getAttribute('powerbi-embed');
31+
},
32+
fullscreen: function () {
33+
var elem = this.iframe;
34+
35+
if (elem.requestFullscreen) {
36+
elem.requestFullscreen();
37+
} else if (elem.msRequestFullscreen) {
38+
elem.msRequestFullscreen();
39+
} else if (elem.mozRequestFullScreen) {
40+
elem.mozRequestFullScreen();
41+
} else if (elem.webkitRequestFullscreen) {
42+
elem.webkitRequestFullscreen();
43+
}
44+
},
45+
exitFullscreen: function () {
46+
if (!this.isFullscreen()) {
47+
return;
48+
}
49+
50+
if (document.exitFullscreen) {
51+
document.exitFullscreen();
52+
} else if (document.mozCancelFullScreen) {
53+
document.mozCancelFullScreen();
54+
} else if (document.webkitExitFullscreen) {
55+
document.webkitExitFullscreen();
56+
} else if (document.msExitFullscreen) {
57+
document.msExitFullscreen();
58+
}
59+
},
60+
isFullscreen: function () {
61+
return document.fullscreenElement === this.iframe || document.webkitFullscreenElement === this.iframe || document.mozFullscreenScreenElement === this.iframe || document.msFullscreenElement === this.iframe;
62+
}
63+
};
64+
} (window.powerbi = window.powerbi || {}));

src/report.js

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
(function(powerbi){
2+
'use strict';
3+
4+
powerbi.Report = Report;
5+
powerbi.Report.prototype = powerbi.Embed.prototype;
6+
7+
function Report(element, options) {
8+
var me = this;
9+
10+
this.element = element;
11+
this.options = options || {};
12+
this.options.loadAction = 'loadReport';
13+
this.getEmbedUrl = getEmbedUrl;
14+
15+
this.init();
16+
17+
///////////////////////////////
18+
19+
function getEmbedUrl() {
20+
var embedUrl = powerbi.Embed.prototype.getEmbedUrl.call(me);
21+
if (!embedUrl) {
22+
var reportId = me.element.getAttribute('powerbi-report');
23+
24+
if (!reportId) {
25+
throw new Error('reportId is required');
26+
}
27+
28+
embedUrl = 'https://app.powerbi.com/reportEmbed?reportId=' + reportId;
29+
}
30+
31+
return embedUrl;
32+
}
33+
}
34+
}(window.powerbi = window.powerbi || {}));

src/tile.js

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
(function(powerbi){
2+
'use strict';
3+
4+
powerbi.Tile = Tile;
5+
powerbi.Tile.prototype = powerbi.Embed.prototyp;
6+
7+
function Tile(element, options) {
8+
var me = this;
9+
10+
this.element = element;
11+
this.options = options || {};
12+
this.options.loadAction = 'loadTile';
13+
this.getEmbedUrl = getEmbedUrl;
14+
15+
this.init();
16+
17+
///////////////////////////////
18+
19+
function getEmbedUrl() {
20+
var embedUrl = powerbi.Embed.prototype.getEmbedUrl.call(me);
21+
if (!embedUrl) {
22+
var dashboardId = me.element.getAttribute('powerbi-dashboard');
23+
var tileId = me.element.getAttribute('powerbi-tile');
24+
25+
if (!(dashboardId && tileId)) {
26+
throw new Error('dashboardId & tileId are required');
27+
}
28+
29+
embedUrl = 'https://app.powerbi.com/embed?dashboardId=' + dashboardId + '&tileId=' + tileId;
30+
}
31+
32+
return embedUrl;
33+
}
34+
}
35+
}(window.powerbi = window.powerbi || {}));

0 commit comments

Comments
 (0)