-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Added baseview(extended from backbone view), which can further extended ... #1749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
zubair-arbi
merged 1 commit into
openedx:master
from
zubair-arbi:zub/bugfix/std823-addbaseview
Dec 20, 2013
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| define( | ||
| [ | ||
| "jquery", "underscore", | ||
| "js/utils/handle_iframe_binding", | ||
| ], | ||
| function ($, _, IframeBinding) { | ||
|
|
||
| describe("IframeBinding", function () { | ||
| var doc = document.implementation.createHTMLDocument("New Document"); | ||
| var iframe_html = '<iframe src="http://www.youtube.com/embed/NHd27UvY-lw" frameborder="0" height="350" width="618"></iframe>'; | ||
| iframe_html += '<iframe src="http://www.youtube.com/embed/NHd27UvY-lw?allowFullScreen=false" frameborder="0" height="350" width="618"></iframe>'; | ||
| iframe_html += '<embed type="application/x-shockwave-flash" src="http://www.youtube.com/embed/NHd27UvY-lw" height="315" width="560">'; | ||
| doc.body.innerHTML = iframe_html; | ||
|
|
||
| it("modifies src url of DOM iframe and embed elements when iframeBinding function is executed", function () { | ||
| expect($(doc).find("iframe")[0].src).toEqual("http://www.youtube.com/embed/NHd27UvY-lw"); | ||
| expect($(doc).find("iframe")[1].src).toEqual("http://www.youtube.com/embed/NHd27UvY-lw?allowFullScreen=false"); | ||
| expect($(doc).find("embed")[0].hasAttribute("wmode")).toBe(false); | ||
|
|
||
| IframeBinding.iframeBinding(doc); | ||
|
|
||
| //after calling iframeBinding function: src url of iframes should have "wmode=transparent" in its querystring | ||
| //and embed objects should have "wmode='transparent'" as an attribute | ||
| expect($(doc).find("iframe")[0].src).toEqual("http://www.youtube.com/embed/NHd27UvY-lw?wmode=transparent"); | ||
| expect($(doc).find("iframe")[1].src).toEqual("http://www.youtube.com/embed/NHd27UvY-lw?wmode=transparent&allowFullScreen=false"); | ||
| expect($(doc).find("embed")[0].hasAttribute("wmode")).toBe(true); | ||
|
|
||
| iframe_html = IframeBinding.iframeBindingHtml(iframe_html); | ||
|
|
||
| //after calling iframeBinding function: src url of iframes should have "wmode=transparent" in its querystring | ||
| //and embed objects should have "wmode='transparent'" as an attribute | ||
| expect(iframe_html).toEqual('<iframe src="http://www.youtube.com/embed/NHd27UvY-lw?wmode=transparent" frameborder="0" height="350" width="618"></iframe>' + | ||
| '<iframe src="http://www.youtube.com/embed/NHd27UvY-lw?wmode=transparent&allowFullScreen=false" frameborder="0" height="350" width="618"></iframe>' + | ||
| '<embed wmode="transparent" type="application/x-shockwave-flash" src="http://www.youtube.com/embed/NHd27UvY-lw" height="315" width="560">'); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| define( | ||
| [ | ||
| "jquery", "underscore", | ||
| "js/views/baseview", | ||
| "js/utils/handle_iframe_binding", | ||
| "sinon" | ||
| ], | ||
| function ($, _, BaseView, IframeBinding, sinon) { | ||
|
|
||
| describe("BaseView check", function () { | ||
| var baseView; | ||
| var iframeBinding_spy; | ||
|
|
||
| beforeEach(function () { | ||
| iframeBinding_spy = sinon.spy(IframeBinding, "iframeBinding"); | ||
| baseView = BaseView.prototype; | ||
|
|
||
| spyOn(baseView, 'initialize'); | ||
| spyOn(baseView, 'beforeRender'); | ||
| spyOn(baseView, 'render'); | ||
| spyOn(baseView, 'afterRender').andCallThrough(); | ||
| }); | ||
|
|
||
| afterEach(function () { | ||
| iframeBinding_spy.restore(); | ||
| }); | ||
|
|
||
| it('calls before and after render functions when render of baseview is called', function () { | ||
| var baseview_temp = new BaseView() | ||
| baseview_temp.render(); | ||
|
|
||
| expect(baseView.initialize).toHaveBeenCalled(); | ||
| expect(baseView.beforeRender).toHaveBeenCalled(); | ||
| expect(baseView.render).toHaveBeenCalled(); | ||
| expect(baseView.afterRender).toHaveBeenCalled(); | ||
| }); | ||
|
|
||
| it('calls iframeBinding function when afterRender of baseview is called', function () { | ||
| var baseview_temp = new BaseView() | ||
| baseview_temp.render(); | ||
| expect(baseView.afterRender).toHaveBeenCalled(); | ||
| expect(iframeBinding_spy.called).toEqual(true); | ||
|
|
||
| //check calls count of iframeBinding function | ||
| expect(iframeBinding_spy.callCount).toBe(1); | ||
| IframeBinding.iframeBinding(); | ||
| expect(iframeBinding_spy.callCount).toBe(2); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| define(["jquery"], function($) { | ||
| var iframeBinding = function (e) { | ||
| var target_element = null; | ||
| if (typeof(e) == "undefined"){ | ||
| target_element = $("iframe, embed"); | ||
| } else { | ||
| if (typeof(e.nodeName) != 'undefined'){ | ||
| target_element = $(e).find("iframe, embed"); | ||
| } else{ | ||
| target_element = e.$("iframe, embed"); | ||
| } | ||
| } | ||
| modifyTagContent(target_element); | ||
| }; | ||
|
|
||
| var modifyTagContent = function (target_element) { | ||
| target_element.each(function(){ | ||
| if ($(this).prop('tagName') == 'IFRAME'){ | ||
| var ifr_source = $(this).attr('src'); | ||
| var wmode = "wmode=transparent"; | ||
| if(ifr_source.indexOf('?') != -1) { | ||
| var getQString = ifr_source.split('?'); | ||
| if (getQString[1].search('wmode=transparent') == -1){ | ||
| var oldString = getQString[1]; | ||
| var newString = getQString[0]; | ||
| $(this).attr('src',newString+'?'+wmode+'&'+oldString); | ||
| } | ||
| } | ||
| else $(this).attr('src',ifr_source+'?'+wmode); | ||
| } | ||
| else{ | ||
| $(this).attr('wmode', 'transparent'); | ||
| } | ||
| }); | ||
| }; | ||
|
|
||
| // Modify iframe/embed tags in provided html string | ||
| // Use this method when provided data is just html sting not dom element | ||
| // This method will only modify iframe (add wmode=transparent in url querystring) and embed (add wmode=transparent as attribute) | ||
| // tags in html string so both tags will attach to dom and don't create z-index problem for other popups | ||
| // Note: embed tags should be modified before rendering as they are static objects as compared to iframes | ||
| // Note: this method can modify unintended html (invalid tags) while converting to dom object | ||
| var iframeBindingHtml = function (html_string) { | ||
| if (html_string){ | ||
| var target_element = null; | ||
| var temp_content = document.createElement('div'); | ||
| $(temp_content).html(html_string); | ||
| target_element = $(temp_content).find("iframe, embed"); | ||
| if (target_element.length > 0){ | ||
| modifyTagContent(target_element); | ||
| html_string = $(temp_content).html(); | ||
| } | ||
| } | ||
| return html_string; | ||
| }; | ||
|
|
||
| return { | ||
| iframeBinding: iframeBinding, | ||
| iframeBindingHtml: iframeBindingHtml | ||
| }; | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| define( | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add some documentation why this class should be used instead of extending Backbone.View directly. |
||
| [ | ||
| 'jquery', | ||
| 'underscore', | ||
| 'backbone', | ||
| "js/utils/handle_iframe_binding" | ||
| ], | ||
| function ($, _, Backbone, IframeUtils) { | ||
| /* This view is extended from backbone with custom functions 'beforeRender' and 'afterRender'. It allows other | ||
| views, which extend from it to access these custom functions. 'afterRender' function of BaseView calls a utility | ||
| function 'iframeBinding' which modifies iframe src urls on a page so that they are rendered as part of the DOM. | ||
| Other common functions which need to be run before/after can also be added here. | ||
| */ | ||
|
|
||
| var BaseView = Backbone.View.extend({ | ||
| //override the constructor function | ||
| constructor: function(options) { | ||
| _.bindAll(this, 'beforeRender', 'render', 'afterRender'); | ||
| var _this = this; | ||
| this.render = _.wrap(this.render, function (render) { | ||
| _this.beforeRender(); | ||
| render(); | ||
| _this.afterRender(); | ||
| return _this; | ||
| }); | ||
|
|
||
| //call Backbone's own constructor | ||
| Backbone.View.prototype.constructor.apply(this, arguments); | ||
| }, | ||
|
|
||
| beforeRender: function () { | ||
| }, | ||
|
|
||
| render: function () { | ||
| return this; | ||
| }, | ||
|
|
||
| afterRender: function () { | ||
| IframeUtils.iframeBinding(this); | ||
| } | ||
| }); | ||
|
|
||
| return BaseView; | ||
| }); | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please write a unit test for this class. These lines are currently missing coverage: 10,11,12,13,14,15,16,18.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, you can see unit test coverage by clicking on the green check mark next to your commit number, then selecting "Diff Coverage Report" on the left-hand side.