Skip to content

Instantly share code, notes, and snippets.

@Micka33
Last active August 29, 2015 14:02
Show Gist options
  • Select an option

  • Save Micka33/a8481c4acb4f229df21e to your computer and use it in GitHub Desktop.

Select an option

Save Micka33/a8481c4acb4f229df21e to your computer and use it in GitHub Desktop.

Revisions

  1. Micka33 revised this gist Apr 29, 2015. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions angular-load-raw-datas.js
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    (function(window, angular, undefined) {'use strict';

    angular.module('loadRawData', [])
    .directive('rawData', [function() {
    .directive('rawData', ['$log', function($log) {
    return {
    restrict: 'A',
    link: function ($scope, $element, $attrs)
    @@ -13,9 +13,9 @@
    if ($attrs.rawData.toLowerCase() == 'json')
    $scope[$attrs.ngBind] = angular.fromJson(text);
    }catch(e){
    console.error(e);
    console.info('you sent:', text);
    console.info('raw-data was expecting:', $attrs.rawData);
    $log.error(e);
    $log.info('you sent:', text);
    $log.info('raw-data was expecting:', $attrs.rawData);
    }
    }
    }
  2. Micka33 revised this gist Jun 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -26,7 +26,7 @@ more `if` can be added to be able to load strings/integers/booleans.
    ```
    ...
    try{
    if ($attrs.type.toLowerCase() == 'json')
    if ($attrs.rawData.toLowerCase() == 'json')
    $scope[$attrs.ngBind] = angular.fromJson(text);
    ...
    ```
  3. Micka33 revised this gist Jun 20, 2014. 2 changed files with 4 additions and 4 deletions.
    4 changes: 2 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -8,14 +8,14 @@ So I want to embed the datas in my page on the first request to load them direct
    ```
    <div>
    <p>{{the_datas}}</p>
    <script raw-data='' ng-bind='the_datas' type='json'>{"stuff":23,"other":"data"}</script>
    <script ng-bind='the_datas' raw-data='json'>{"stuff":23,"other":"data"}</script>
    </div>
    ```

    ```
    <div>
    <p>{{the_datas}}</p>
    <scriptraw-data='' ng-bind='the_datas' type='json' initdata='{"stuff":23,"other":"data"}'></script>
    <script initdata='{"stuff":23,"other":"data"}' ng-bind='the_datas' raw-data='json'></script>
    </div>
    ```

    4 changes: 2 additions & 2 deletions angular-load-raw-datas.js
    Original file line number Diff line number Diff line change
    @@ -10,12 +10,12 @@
    {
    var text = ($attrs.initdata ? $attrs.initdata : $element.text());
    try{
    if ($attrs.type.toLowerCase() == 'json')
    if ($attrs.rawData.toLowerCase() == 'json')
    $scope[$attrs.ngBind] = angular.fromJson(text);
    }catch(e){
    console.error(e);
    console.info('you sent:', text);
    console.info('raw-data was expecting:', $attrs.type);
    console.info('raw-data was expecting:', $attrs.rawData);
    }
    }
    }
  4. Micka33 revised this gist Jun 20, 2014. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -6,16 +6,16 @@ So I want to embed the datas in my page on the first request to load them direct
    #How to use rawData

    ```
    <div class='line'>
    <div>
    <p>{{the_datas}}</p>
    <script ng-bind='the_datas' raw-data='' type='json'>{"stuff":23,"other":"data"}</script>
    <script raw-data='' ng-bind='the_datas' type='json'>{"stuff":23,"other":"data"}</script>
    </div>
    ```

    ```
    <div class='line'>
    <div>
    <p>{{the_datas}}</p>
    <script initdata='{"stuff":23,"other":"data"}' ng-bind='the_datas' raw-data='' type='json'></script>
    <scriptraw-data='' ng-bind='the_datas' type='json' initdata='{"stuff":23,"other":"data"}'></script>
    </div>
    ```

  5. Micka33 revised this gist Jun 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Why rawData (reminder)

    Because I don't want to have two request to load one page (one for the squeleton, one for the datas).
    Because I don't want to have two requests to load one page (one for the squeleton, one for the datas).
    So I want to embed the datas in my page on the first request to load them directly.

    #How to use rawData
  6. Micka33 revised this gist Jun 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #Why rawData (reminder)

    Because I don't want to have to request to load one page (one for the squeleton, one for the datas).
    Because I don't want to have two request to load one page (one for the squeleton, one for the datas).
    So I want to embed the datas in my page on the first request to load them directly.

    #How to use rawData
  7. Micka33 revised this gist Jun 20, 2014. 2 changed files with 28 additions and 3 deletions.
    29 changes: 27 additions & 2 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,33 @@
    #How to
    #Why rawData (reminder)

    Because I don't want to have to request to load one page (one for the squeleton, one for the datas).
    So I want to embed the datas in my page on the first request to load them directly.

    #How to use rawData

    ```
    <div class='line'>
    <p>{{the_datas}}</p>
    <script ng-bind='the_datas' raw-data='' type='json'>{"stuff":23,"other":"data"}</script>
    </div>
    ```

    ```
    <div class='line'>
    <p>{{the_datas}}</p>
    <script initdata='{"stuff":23,"other":"data"}' ng-bind='the_datas' raw-data='' type='json'></script>
    </div>
    ```

    # What can be added

    more `if` can be added to be able to load strings/integers/booleans.

    ```
    ...
    try{
    if ($attrs.type.toLowerCase() == 'json')
    $scope[$attrs.ngBind] = angular.fromJson(text);
    ...
    ```

    ```
    2 changes: 1 addition & 1 deletion angular-load-raw-datas.js
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    {
    if ( typeof $attrs.ngBind !== 'undefined')
    {
    var text = ($attrs.initdata ? $attrs.initdatajson : $element.text());
    var text = ($attrs.initdata ? $attrs.initdata : $element.text());
    try{
    if ($attrs.type.toLowerCase() == 'json')
    $scope[$attrs.ngBind] = angular.fromJson(text);
  8. Micka33 revised this gist Jun 20, 2014. 1 changed file with 0 additions and 5 deletions.
    5 changes: 0 additions & 5 deletions angular-load-raw-datas.js
    Original file line number Diff line number Diff line change
    @@ -1,8 +1,3 @@
    /**
    * @license AngularJS v1.2.14
    * (c) 2010-2014 Google, Inc. http://angularjs.org
    * License: MIT
    */
    (function(window, angular, undefined) {'use strict';

    angular.module('loadRawData', [])
  9. Micka33 renamed this gist Jun 20, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  10. Micka33 revised this gist Jun 20, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.rd
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    #How to

    ```html
    ```



  11. Micka33 created this gist Jun 20, 2014.
    8 changes: 8 additions & 0 deletions README.rd
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,8 @@
    #How to

    ```html




    ```
    32 changes: 32 additions & 0 deletions angular-load-raw-datas.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,32 @@
    /**
    * @license AngularJS v1.2.14
    * (c) 2010-2014 Google, Inc. http://angularjs.org
    * License: MIT
    */
    (function(window, angular, undefined) {'use strict';

    angular.module('loadRawData', [])
    .directive('rawData', [function() {
    return {
    restrict: 'A',
    link: function ($scope, $element, $attrs)
    {
    if ( typeof $attrs.ngBind !== 'undefined')
    {
    var text = ($attrs.initdata ? $attrs.initdatajson : $element.text());
    try{
    if ($attrs.type.toLowerCase() == 'json')
    $scope[$attrs.ngBind] = angular.fromJson(text);
    }catch(e){
    console.error(e);
    console.info('you sent:', text);
    console.info('raw-data was expecting:', $attrs.type);
    }
    }
    }
    }
    }]);



    })(window, window.angular);